"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[687],{66446:(me,B,a)=>{a.r(B),a.d(B,{ServiceAccountPageUnconnected:()=>fe,default:()=>Me});var e=a(66111),s=a(67948),M=a(10753),h=a(52081),y=a(31403),D=a(98102),E=a(8412),r=a(77582),f=a(27876),g=a(73546),V=a(82002);const k=t=>{const n=V.Vt.hasPermissionInMetadata(f.AccessControlAction.ServiceAccountsPermissionsWrite,t.serviceAccount);return e.createElement(g.P,{title:"Permissions",addPermissionTitle:"Add permission",buttonLabel:"Add permission",resource:"serviceaccounts",resourceId:t.serviceAccount.id,canSetPermissions:n})};var J=a(14377),d=a(9892),b=a(77258),x=a(72648),C=a(11630),T=a(50869),c=a(64353),l=a(46967),L=a(71657);const u=({label:t,value:n,inputType:o,disabled:m,onChange:v})=>{const S=(0,e.useRef)(null),[i,W]=(0,e.useState)(n),[O,p]=(0,e.useState)(!1),R=(0,x.wW)(P),ee=`${t}-input`;(0,e.useEffect)(()=>{O&&de()},[O]);const te=()=>{p(!0)},re=()=>{p(!1),W(n||"")},ne=(j,U)=>{U!==T.G.Invalid&&W(j.target.value)},ie=(j,U)=>{U!==T.G.Invalid&&W(j.target.value)},de=()=>{S?.current?.focus()},ue=()=>{p(!1),v&&v(i)};return e.createElement("tr",null,e.createElement("td",null,e.createElement(c._,{htmlFor:ee},t)),e.createElement("td",{className:"width-25",colSpan:2},!m&&O?e.createElement(l.I,{id:ee,type:o,defaultValue:n,onBlur:ie,onChange:ne,ref:S,width:30}):e.createElement("span",{className:(0,d.cx)({[R.disabled]:m})},n)),e.createElement("td",null,v&&e.createElement(L.p,{closeOnConfirm:!0,confirmText:"Save",onConfirm:ue,onClick:te,onCancel:re,disabled:m},"Edit")))},P=t=>({disabled:d.css`
      color: ${t.colors.text.secondary};
    `});var K=a(66226),F=a(65135);const z=({label:t,serviceAccount:n,roleOptions:o,onRoleChange:m})=>{const v=`${t}-input`,S=r.Vt.hasPermissionInMetadata(f.AccessControlAction.ServiceAccountsWrite,n);return e.createElement("tr",null,e.createElement("td",null,e.createElement(c._,{htmlFor:v},t)),r.Vt.licensedAccessControlEnabled()?e.createElement("td",{colSpan:3},e.createElement(K.R,{userId:n.id,orgId:n.orgId,basicRole:n.role,onBasicRoleChange:m,roleOptions:o,basicRoleDisabled:!S,disabled:n.isDisabled})):e.createElement(e.Fragment,null,e.createElement("td",null,e.createElement(F.A,{width:24,inputId:v,"aria-label":"Role",value:n.role,disabled:n.isDisabled,onChange:m})),e.createElement("td",{colSpan:2})))};function H({serviceAccount:t,timeZone:n,onChange:o}){const m=(0,x.wW)(Y),v=r.Vt.hasPermission(f.AccessControlAction.ServiceAccountsWrite),[S,i]=e.useState([]),W=p=>{o({...t,role:p})},O=p=>{o({...t,name:p})};return e.useEffect(()=>{async function p(){try{if(r.Vt.hasPermission(f.AccessControlAction.ActionRolesList)){let R=await(0,C.ul)(t.orgId);i(R)}}catch{console.error("Error loading options for service account")}}r.Vt.licensedAccessControlEnabled()&&p()},[t.orgId]),e.createElement("div",{className:m.section},e.createElement("h3",null,"Information"),e.createElement("table",{className:"filter-table"},e.createElement("tbody",null,e.createElement(u,{label:"Name",value:t.name,onChange:O,disabled:!v||t.isDisabled}),e.createElement(u,{label:"ID",value:t.login,disabled:t.isDisabled}),e.createElement(z,{label:"Roles",serviceAccount:t,onRoleChange:W,roleOptions:S}),e.createElement(u,{label:"Creation date",value:(0,b.dq)(t.createdAt,{timeZone:n}),disabled:t.isDisabled}))))}const Y=t=>({section:d.css`
    margin-bottom: ${t.spacing(4)};
  `});var w=a(13626),Z=a(61860),$=a(39904);const q=({tokens:t,timeZone:n,tokenActionsDisabled:o,onDelete:m})=>{const v=(0,x.l4)(),S=N(v);return e.createElement("table",{className:(0,d.cx)(S.section,"filter-table")},e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null,"Name"),e.createElement("th",null,"Expires"),e.createElement("th",null,"Created"),e.createElement("th",null,"Last used at"),e.createElement("th",null),e.createElement("th",null))),e.createElement("tbody",null,t.map(i=>e.createElement("tr",{key:i.id,className:S.tableRow(i.hasExpired||i.isRevoked)},e.createElement("td",null,i.name),e.createElement("td",null,e.createElement(se,{timeZone:n,token:i})),e.createElement("td",null,Q(n,i.created)),e.createElement("td",null,ae(n,i.lastUsedAt)),e.createElement("td",{className:"width-1 text-center"},i.isRevoked&&e.createElement(oe,null)),e.createElement("td",null,e.createElement(w.m,{"aria-label":`Delete service account token ${i.name}`,size:"sm",onConfirm:()=>m(i),disabled:o}))))))};function ae(t,n){return n?(0,b.dq)(n,{timeZone:t}):"Never"}function Q(t,n){return n?(0,b.dq)(n,{timeZone:t}):"No expiration date"}function X(t){const n=Math.ceil(t/86400);return`Expires in ${n>1?`${n} days`:`${n} day`}`}const oe=()=>{const t=(0,x.wW)(N);return e.createElement("span",{className:t.hasExpired},"Revoked",e.createElement("span",{className:t.tooltipContainer},e.createElement(Z.u,{content:"This token has been publicly exposed. Please rotate this token"},e.createElement($.J,{name:"exclamation-triangle",className:t.toolTipIcon}))))},se=({timeZone:t,token:n})=>{const o=(0,x.wW)(N);return n.expiration?n.secondsUntilExpiration?e.createElement("span",{className:o.secondsUntilExpiration},X(n.secondsUntilExpiration)):n.hasExpired?e.createElement("span",{className:o.hasExpired},"Expired",e.createElement("span",{className:o.tooltipContainer},e.createElement(Z.u,{content:"This token has expired"},e.createElement($.J,{name:"exclamation-triangle",className:o.toolTipIcon})))):e.createElement("span",null,Q(t,n.expiration)):e.createElement("span",{className:o.neverExpire},"Never")},N=t=>({tableRow:n=>d.css`
    color: ${n?t.colors.text.secondary:t.colors.text.primary};
  `,tooltipContainer:d.css`
    margin-left: ${t.spacing(1)};
  `,toolTipIcon:d.css`
    color: ${t.colors.error.text};
  `,secondsUntilExpiration:d.css`
    color: ${t.colors.warning.text};
  `,hasExpired:d.css`
    color: ${t.colors.error.text};
  `,neverExpire:d.css`
    color: ${t.colors.text.secondary};
  `,section:d.css`
    margin-bottom: ${t.spacing(4)};
  `});var ce=a(50655),A=a(54899),Ee=a(37932),Te=a(95156),_=a(45003);const G="/api/serviceaccounts";function ve(t){return async n=>{n((0,_.s3)());try{const o=await(0,A.i)().get(`${G}/${t}`,(0,Te.y)());n((0,_.P4)(o))}catch(o){console.error(o)}finally{n((0,_.LA)())}}}function Ae(t){return async n=>{await(0,A.i)().patch(`${G}/${t.id}?accesscontrol=true`,{...t}),n(ve(t.id))}}function Se(t){return async()=>{await(0,A.i)().delete(`${G}/${t}`),Ee.E1.push("/org/serviceaccounts")}}function he(t,n,o){return async m=>{const v=await(0,A.i)().post(`${G}/${t}/tokens`,n);o(v.key),m(le(t))}}function ye(t,n){return async o=>{await(0,A.i)().delete(`${G}/${t}/tokens/${n}`),o(le(t))}}function le(t){return async n=>{try{const o=await(0,A.i)().get(`${G}/${t}/tokens`);n((0,_.e7)(o))}catch(o){console.error(o)}}}function Pe(t){return{serviceAccount:t.serviceAccountProfile.serviceAccount,tokens:t.serviceAccountProfile.tokens,isLoading:t.serviceAccountProfile.isLoading,timezone:(0,M.Z)(t.user)}}const xe={createServiceAccountToken:he,deleteServiceAccount:Se,deleteServiceAccountToken:ye,loadServiceAccount:ve,loadServiceAccountTokens:le,updateServiceAccount:Ae},Ie=(0,s.connect)(Pe,xe),fe=({match:t,serviceAccount:n,tokens:o,timezone:m,isLoading:v,createServiceAccountToken:S,deleteServiceAccount:i,deleteServiceAccountToken:W,loadServiceAccount:O,loadServiceAccountTokens:p,updateServiceAccount:R})=>{const[ee,te]=(0,e.useState)(""),[re,ne]=(0,e.useState)(!1),[ie,de]=(0,e.useState)(!1),[ue,j]=(0,e.useState)(!1),U=parseInt(t.params.id,10),pe=!r.Vt.hasPermission(f.AccessControlAction.ServiceAccountsWrite)||n.isDisabled,De=r.Vt.hasPermission(f.AccessControlAction.ServiceAccountsWrite),Oe=r.Vt.hasAccessInMetadata(f.AccessControlAction.ServiceAccountsPermissionsRead,n,!1),Re={text:n.name,img:n.avatarUrl,breadcrumbs:[{title:"Service accounts",url:"org/serviceaccounts"}],subTitle:"Manage settings for an individual service account."};(0,e.useEffect)(()=>{O(U),p(U),r.Vt.licensedAccessControlEnabled()&&(0,ce.bX)()},[O,p,U]);const be=I=>{R(I)},ge=I=>()=>{de(I)},Ce=I=>()=>{j(I)},Le=()=>{i(n.id)},$e=()=>{R({...n,isDisabled:!0}),j(!1)},Ne=()=>{R({...n,isDisabled:!1})},We=I=>{W(n?.id,I.id)},Ue=I=>{S(n?.id,I,te)},Be=()=>{ne(!1),te("")};return e.createElement(E.T,{navId:"serviceaccounts",pageNav:Re},e.createElement(E.T.Contents,{isLoading:v},e.createElement("div",null,n&&e.createElement(h.Lh,{spacing:"md",height:"auto",justify:"flex-end"},e.createElement(y.zx,{type:"button",variant:"destructive",onClick:ge(!0),disabled:!r.Vt.hasPermission(f.AccessControlAction.ServiceAccountsDelete)},"Delete service account"),n.isDisabled?e.createElement(y.zx,{type:"button",variant:"secondary",onClick:Ne,disabled:!De},"Enable service account"):e.createElement(y.zx,{type:"button",variant:"secondary",onClick:Ce(!0),disabled:!De},"Disable service account")),n&&e.createElement(H,{serviceAccount:n,timeZone:m,onChange:be}),e.createElement(h.Lh,{justify:"space-between",height:"auto"},e.createElement("h3",null,"Tokens"),e.createElement(y.zx,{onClick:()=>ne(!0),disabled:pe},"Add service account token")),o&&e.createElement(q,{tokens:o,timeZone:m,onDelete:We,tokenActionsDisabled:pe}),Oe&&e.createElement(k,{serviceAccount:n})),e.createElement(D.s,{isOpen:ie,title:"Delete service account",body:"Are you sure you want to delete this service account?",confirmText:"Delete service account",onConfirm:Le,onDismiss:ge(!1)}),e.createElement(D.s,{isOpen:ue,title:"Disable service account",body:"Are you sure you want to disable this service account?",confirmText:"Disable service account",onConfirm:$e,onDismiss:Ce(!1)}),e.createElement(J.m,{isOpen:re,token:ee,serviceAccountLogin:n.login,onCreateToken:Ue,onClose:Be})))},Me=Ie(fe)},14377:(me,B,a)=>{a.d(B,{m:()=>d});var e=a(9892),s=a(66111),M=a(44288),h=a(35645),y=a(72648),D=a(35029),E=a(24799),r=a(46967),f=a(2594),g=a(86348),V=a(31403),k=a(94599);const J=[{label:"No expiration",value:!1},{label:"Set expiration date",value:!0}],d=({isOpen:C,token:T,serviceAccountLogin:c,onCreateToken:l,onClose:L})=>{const u=new Date;u.setDate(u.getDate()+1);const P=new Date;h.v.tokenExpirationDayLimit!==void 0&&h.v.tokenExpirationDayLimit>-1?P.setDate(P.getDate()+h.v.tokenExpirationDayLimit+1):P.setDate(864e13);const K=h.v.tokenExpirationDayLimit!==void 0&&h.v.tokenExpirationDayLimit>0,[F,z]=(0,s.useState)(""),[H,Y]=(0,s.useState)(""),[w,Z]=(0,s.useState)(K),[$,q]=(0,s.useState)(u),[ae,Q]=(0,s.useState)($!==""),X=(0,y.wW)(x);(0,s.useEffect)(()=>{C&&z(`${c}-${(0,M.Z)()}`)},[c,C]);const oe=A=>{Q(A!==""),q(A)},se=()=>{l({name:H||F,secondsToLive:w?b($):void 0})},N=()=>{Y(""),z(""),Z(K),q(u),Q($!==""),L()},ce=T?"Service account token created":"Add service account token";return s.createElement(D.u,{isOpen:C,title:ce,onDismiss:N,className:X.modal,contentClassName:X.modalContent},T?s.createElement(s.Fragment,null,s.createElement(E.g,{label:"Token",description:"Copy the token now as you will not be able to see it again. Losing a token requires creating a new one."},s.createElement("div",{className:X.modalTokenRow},s.createElement(r.I,{name:"tokenValue",value:T,readOnly:!0}),s.createElement(k.m,{className:X.modalCopyToClipboardButton,variant:"primary",size:"md",icon:"copy",getText:()=>T},"Copy clipboard"))),s.createElement(D.u.ButtonRow,null,s.createElement(k.m,{variant:"primary",getText:()=>T,onClipboardCopy:N},"Copy to clipboard and close"),s.createElement(V.zx,{variant:"secondary",onClick:N},"Close"))):s.createElement("div",null,s.createElement(E.g,{label:"Display name",description:"Name to easily identify the token",required:!0},s.createElement(r.I,{name:"tokenName",value:H,placeholder:F,onChange:A=>{Y(A.currentTarget.value)}})),s.createElement(E.g,{label:"Expiration"},s.createElement(f.S,{options:J,value:w,onChange:Z,size:"md"})),w&&s.createElement(E.g,{label:"Expiration date"},s.createElement(g.d,{onChange:oe,value:$,placeholder:"",minDate:u,maxDate:P})),s.createElement(D.u.ButtonRow,null,s.createElement(V.zx,{onClick:se,disabled:w&&!ae},"Generate token"))))},b=C=>{const T=new Date(C),c=new Date;return Math.ceil((T.getTime()-c.getTime())/1e3)},x=C=>({modal:e.css`
      width: 550px;
    `,modalContent:e.css`
      overflow: visible;
    `,modalTokenRow:e.css`
      display: flex;
    `,modalCopyToClipboardButton:e.css`
      margin-left: ${C.spacing(.5)};
    `})},50655:(me,B,a)=>{a.d(B,{R5:()=>x,TL:()=>k,XE:()=>C,Xd:()=>g,bX:()=>f,fT:()=>d,yN:()=>J});var e=a(82897),s=a.n(e),M=a(54899),h=a(11630),y=a(82002),D=a(27876),E=a(45003);const r="/api/serviceaccounts";function f(){return async c=>{try{if(y.Vt.licensedAccessControlEnabled()&&y.Vt.hasPermission(D.AccessControlAction.ActionRolesList)){const l=await(0,h.ul)();c((0,E.Dn)(l))}}catch(l){console.error(l)}}}function g({withLoadingIndicator:c}={withLoadingIndicator:!1}){return async(l,L)=>{try{if(y.Vt.hasPermission(D.AccessControlAction.ServiceAccountsRead)){c&&l((0,E.pN)());const{perPage:u,page:P,query:K,serviceAccountStateFilter:F}=L().serviceAccounts,z=await(0,M.i)().get(`/api/serviceaccounts/search?perpage=${u}&page=${P}&query=${K}${b(F)}&accesscontrol=true`);l((0,E.Ub)(z))}}catch(u){console.error(u)}finally{l((0,E.dt)())}}}const V=(0,e.debounce)(c=>c(g()),500,{leading:!0});function k(c){return async l=>{await(0,M.i)().patch(`${r}/${c.id}?accesscontrol=true`,{...c}),l(g())}}function J(c){return async l=>{await(0,M.i)().delete(`${r}/${c}`),l(g())}}function d(c,l,L){return async u=>{const P=await(0,M.i)().post(`${r}/${c}/tokens`,l);L(P.key),u(g())}}const b=c=>{switch(c){case D.ServiceAccountStateFilter.WithExpiredTokens:return"&expiredTokens=true";case D.ServiceAccountStateFilter.Disabled:return"&disabled=true";default:return""}};function x(c){return async l=>{l((0,E.aj)(c)),V(l)}}function C(c){return async l=>{l((0,E.M4)(c)),l(g())}}function T(c){return async l=>{l(pageChanged(c)),l(g())}}}}]);

//# sourceMappingURL=ServiceAccountPage.cd246b7522fa59c0e749.js.map