"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[687],{83896:(Ee,$,a)=>{a.r($),a.d($,{ServiceAccountPageUnconnected:()=>pe,default:()=>Me});var e=a(65237),s=a(37149),M=a(1286),A=a(6741),S=a(48389),p=a(22324),m=a(38992),d=a(63969),D=a(3315),g=a(60336),N=a(96237);const W=t=>{const n=N.Vt.hasPermissionInMetadata(D.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(97971),u=a(60234),b=a(25641),h=a(93048),f=a(87577),C=a(42505),c=a(96682),l=a(18899);const P=({label:t,value:n,inputType:o,disabled:r,onChange:E})=>{const T=(0,e.useRef)(null),[i,L]=(0,e.useState)(n),[x,w]=(0,e.useState)(!1),ae=(0,h.wW)(v),X=`${t}-input`;(0,e.useEffect)(()=>{x&&de()},[x]);const re=()=>{w(!0)},oe=()=>{w(!1),L(n||"")},ie=(H,G)=>{G!==f.G.Invalid&&L(H.target.value)},se=(H,G)=>{G!==f.G.Invalid&&L(H.target.value)},de=()=>{T?.current?.focus()},ue=()=>{w(!1),E&&E(i)};return e.createElement("tr",null,e.createElement("td",null,e.createElement(C._,{htmlFor:X},t)),e.createElement("td",{className:"width-25",colSpan:2},!r&&x?e.createElement(c.I,{id:X,type:o,defaultValue:n,onBlur:se,onChange:ie,ref:T,width:30}):e.createElement("span",{className:(0,u.cx)({[ae.disabled]:r})},n)),e.createElement("td",null,E&&e.createElement(l.p,{closeOnConfirm:!0,confirmText:"Save",onConfirm:ue,onClick:re,onCancel:oe,disabled:r},"Edit")))},v=t=>({disabled:u.css`
      color: ${t.colors.text.secondary};
    `});var y=a(27681),U=a(54279);const B=({label:t,serviceAccount:n,roleOptions:o,onRoleChange:r})=>{const E=`${t}-input`,T=d.Vt.hasPermissionInMetadata(D.AccessControlAction.ServiceAccountsWrite,n);return e.createElement("tr",null,e.createElement("td",null,e.createElement(C._,{htmlFor:E},t)),d.Vt.licensedAccessControlEnabled()?e.createElement("td",{colSpan:3},e.createElement(y.R,{userId:n.id,orgId:n.orgId,basicRole:n.role,onBasicRoleChange:r,roleOptions:o,basicRoleDisabled:!T,disabled:n.isDisabled})):e.createElement(e.Fragment,null,e.createElement("td",null,e.createElement(U.A,{width:24,inputId:E,"aria-label":"Role",value:n.role,disabled:n.isDisabled,onChange:r})),e.createElement("td",{colSpan:2})))};function k({serviceAccount:t,timeZone:n,roleOptions:o,onChange:r}){const E=(0,h.wW)(Y),T=d.Vt.hasPermission(D.AccessControlAction.ServiceAccountsWrite),i=x=>{r({...t,role:x})},L=x=>{r({...t,name:x})};return e.createElement("div",{className:E.section},e.createElement("h3",null,"Information"),e.createElement("table",{className:"filter-table"},e.createElement("tbody",null,e.createElement(P,{label:"Name",value:t.name,onChange:L,disabled:!T||t.isDisabled}),e.createElement(P,{label:"ID",value:t.login,disabled:t.isDisabled}),e.createElement(B,{label:"Roles",serviceAccount:t,onRoleChange:i,roleOptions:o}),e.createElement(P,{label:"Creation date",value:(0,b.dq)(t.createdAt,{timeZone:n}),disabled:t.isDisabled}))))}const Y=t=>({section:u.css`
    margin-bottom: ${t.spacing(4)};
  `});var q=a(25134),O=a(89050),J=a(6335);const V=({tokens:t,timeZone:n,tokenActionsDisabled:o,onDelete:r})=>{const E=(0,h.l4)(),T=Z(E);return e.createElement("table",{className:(0,u.cx)(T.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:T.tableRow(i.hasExpired||i.isRevoked)},e.createElement("td",null,i.name),e.createElement("td",null,e.createElement(ce,{timeZone:n,token:i})),e.createElement("td",null,ee(n,i.created)),e.createElement("td",null,_(n,i.lastUsedAt)),e.createElement("td",{className:"width-1 text-center"},i.isRevoked&&e.createElement(K,null)),e.createElement("td",null,e.createElement(q.m,{"aria-label":`Delete service account token ${i.name}`,size:"sm",onConfirm:()=>r(i),disabled:o}))))))};function _(t,n){return n?(0,b.dq)(n,{timeZone:t}):"Never"}function ee(t,n){return n?(0,b.dq)(n,{timeZone:t}):"No expiration date"}function te(t){const n=Math.ceil(t/86400);return`Expires in ${n>1?`${n} days`:`${n} day`}`}const K=()=>{const t=(0,h.wW)(Z);return e.createElement("span",{className:t.hasExpired},"Revoked",e.createElement("span",{className:t.tooltipContainer},e.createElement(O.u,{content:"This token has been publicly exposed. Please rotate this token"},e.createElement(J.J,{name:"exclamation-triangle",className:t.toolTipIcon}))))},ce=({timeZone:t,token:n})=>{const o=(0,h.wW)(Z);return n.expiration?n.secondsUntilExpiration?e.createElement("span",{className:o.secondsUntilExpiration},te(n.secondsUntilExpiration)):n.hasExpired?e.createElement("span",{className:o.hasExpired},"Expired",e.createElement("span",{className:o.tooltipContainer},e.createElement(O.u,{content:"This token has expired"},e.createElement(J.J,{name:"exclamation-triangle",className:o.toolTipIcon})))):e.createElement("span",null,ee(t,n.expiration)):e.createElement("span",{className:o.neverExpire},"Never")},Z=t=>({tableRow:n=>u.css`
    color: ${n?t.colors.text.secondary:t.colors.text.primary};
  `,tooltipContainer:u.css`
    margin-left: ${t.spacing(1)};
  `,toolTipIcon:u.css`
    color: ${t.colors.error.text};
  `,secondsUntilExpiration:u.css`
    color: ${t.colors.warning.text};
  `,hasExpired:u.css`
    color: ${t.colors.error.text};
  `,neverExpire:u.css`
    color: ${t.colors.text.secondary};
  `,section:u.css`
    margin-bottom: ${t.spacing(4)};
  `});var Q=a(55409),R=a(55041),F=a(38002),ve=a(98967),ne=a(88843);const z="/api/serviceaccounts";function fe(t){return async n=>{n((0,ne.s3)());try{const o=await(0,R.i)().get(`${z}/${t}`,(0,ve.y)());n((0,ne.P4)(o))}catch(o){console.error(o)}finally{n((0,ne.LA)())}}}function Ae(t){return async n=>{await(0,R.i)().patch(`${z}/${t.id}?accesscontrol=true`,{...t}),n(fe(t.id))}}function Se(t){return async()=>{await(0,R.i)().delete(`${z}/${t}`),F.E1.push("/org/serviceaccounts")}}function ye(t,n,o){return async r=>{const E=await(0,R.i)().post(`${z}/${t}/tokens`,n);o(E.key),r(le(t))}}function he(t,n){return async o=>{await(0,R.i)().delete(`${z}/${t}/tokens/${n}`),o(le(t))}}function le(t){return async n=>{try{const o=await(0,R.i)().get(`${z}/${t}/tokens`);n((0,ne.e7)(o))}catch(o){console.error(o)}}}function Pe(t){return{serviceAccount:t.serviceAccountProfile.serviceAccount,tokens:t.serviceAccountProfile.tokens,isLoading:t.serviceAccountProfile.isLoading,roleOptions:t.serviceAccounts.roleOptions,timezone:(0,M.Z)(t.user)}}const xe={createServiceAccountToken:ye,deleteServiceAccount:Se,deleteServiceAccountToken:he,loadServiceAccount:fe,loadServiceAccountTokens:le,updateServiceAccount:Ae},Ie=(0,s.connect)(Pe,xe),pe=({match:t,serviceAccount:n,tokens:o,timezone:r,isLoading:E,roleOptions:T,createServiceAccountToken:i,deleteServiceAccount:L,deleteServiceAccountToken:x,loadServiceAccount:w,loadServiceAccountTokens:ae,updateServiceAccount:X})=>{const[re,oe]=(0,e.useState)(""),[ie,se]=(0,e.useState)(!1),[de,ue]=(0,e.useState)(!1),[H,G]=(0,e.useState)(!1),me=parseInt(t.params.id,10),De=!d.Vt.hasPermission(D.AccessControlAction.ServiceAccountsWrite)||n.isDisabled,ge=d.Vt.hasPermission(D.AccessControlAction.ServiceAccountsWrite),Oe=d.Vt.hasAccessInMetadata(D.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)(()=>{w(me),ae(me),d.Vt.licensedAccessControlEnabled()&&(0,Q.bX)()},[w,ae,me]);const be=I=>{X(I)},Ce=I=>()=>{ue(I)},Te=I=>()=>{G(I)},Le=()=>{L(n.id)},$e=()=>{X({...n,isDisabled:!0}),G(!1)},Ne=()=>{X({...n,isDisabled:!1})},We=I=>{x(n?.id,I.id)},Ue=I=>{i(n?.id,I,oe)},Be=()=>{se(!1),oe("")};return e.createElement(m.T,{navId:"serviceaccounts",pageNav:Re},e.createElement(m.T.Contents,{isLoading:E},e.createElement("div",null,n&&e.createElement(A.Lh,{spacing:"md",height:"auto",justify:"flex-end"},e.createElement(S.zx,{type:"button",variant:"destructive",onClick:Ce(!0),disabled:!d.Vt.hasPermission(D.AccessControlAction.ServiceAccountsDelete)},"Delete service account"),n.isDisabled?e.createElement(S.zx,{type:"button",variant:"secondary",onClick:Ne,disabled:!ge},"Enable service account"):e.createElement(S.zx,{type:"button",variant:"secondary",onClick:Te(!0),disabled:!ge},"Disable service account")),n&&e.createElement(k,{serviceAccount:n,timeZone:r,roleOptions:T,onChange:be}),e.createElement(A.Lh,{justify:"space-between",height:"auto"},e.createElement("h3",null,"Tokens"),e.createElement(S.zx,{onClick:()=>se(!0),disabled:De},"Add service account token")),o&&e.createElement(V,{tokens:o,timeZone:r,onDelete:We,tokenActionsDisabled:De}),Oe&&e.createElement(W,{serviceAccount:n})),e.createElement(p.s,{isOpen:de,title:"Delete service account",body:"Are you sure you want to delete this service account?",confirmText:"Delete service account",onConfirm:Le,onDismiss:Ce(!1)}),e.createElement(p.s,{isOpen:H,title:"Disable service account",body:"Are you sure you want to disable this service account?",confirmText:"Disable service account",onConfirm:$e,onDismiss:Te(!1)}),e.createElement(j.m,{isOpen:ie,token:re,serviceAccountLogin:n.login,onCreateToken:Ue,onClose:Be})))},Me=Ie(pe)},97971:(Ee,$,a)=>{a.d($,{m:()=>u});var e=a(60234),s=a(65237),M=a(66117),A=a(49784),S=a(93048),p=a(90931),m=a(5263),d=a(96682),D=a(12007),g=a(55798),N=a(48389),W=a(44840);const j=[{label:"No expiration",value:!1},{label:"Set expiration date",value:!0}],u=({isOpen:f,token:C,serviceAccountLogin:c,onCreateToken:l,onClose:P})=>{const v=new Date;v.setDate(v.getDate()+1);const y=new Date;A.v.tokenExpirationDayLimit!==void 0&&A.v.tokenExpirationDayLimit>-1?y.setDate(y.getDate()+A.v.tokenExpirationDayLimit+1):y.setDate(864e13);const U=A.v.tokenExpirationDayLimit!==void 0&&A.v.tokenExpirationDayLimit>0,[B,k]=(0,s.useState)(""),[Y,q]=(0,s.useState)(""),[O,J]=(0,s.useState)(U),[V,_]=(0,s.useState)(v),[ee,te]=(0,s.useState)(V!==""),K=(0,S.wW)(h);(0,s.useEffect)(()=>{f&&k(`${c}-${(0,M.Z)()}`)},[c,f]);const ce=F=>{te(F!==""),_(F)},Z=()=>{l({name:Y||B,secondsToLive:O?b(V):void 0})},Q=()=>{q(""),k(""),J(U),_(v),te(V!==""),P()},R=C?"Service account token created":"Add service account token";return s.createElement(p.u,{isOpen:f,title:R,onDismiss:Q,className:K.modal,contentClassName:K.modalContent},C?s.createElement(s.Fragment,null,s.createElement(m.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:K.modalTokenRow},s.createElement(d.I,{name:"tokenValue",value:C,readOnly:!0}),s.createElement(W.m,{className:K.modalCopyToClipboardButton,variant:"primary",size:"md",icon:"copy",getText:()=>C},"Copy clipboard"))),s.createElement(p.u.ButtonRow,null,s.createElement(W.m,{variant:"primary",getText:()=>C,onClipboardCopy:Q},"Copy to clipboard and close"),s.createElement(N.zx,{variant:"secondary",onClick:Q},"Close"))):s.createElement("div",null,s.createElement(m.g,{label:"Display name",description:"Name to easily identify the token",required:!0},s.createElement(d.I,{name:"tokenName",value:Y,placeholder:B,onChange:F=>{q(F.currentTarget.value)}})),!O&&s.createElement(m.g,{label:"Expiration"},s.createElement(D.S,{options:j,value:O,onChange:J,size:"md"})),O&&s.createElement(m.g,{label:"Expiration date"},s.createElement(g.d,{onChange:ce,value:V,placeholder:"",minDate:v,maxDate:y})),s.createElement(p.u.ButtonRow,null,s.createElement(N.zx,{onClick:Z,disabled:O&&!ee},"Generate token"))))},b=f=>{const C=new Date(f),c=new Date;return Math.ceil((C.getTime()-c.getTime())/1e3)},h=f=>({modal:e.css`
      width: 550px;
    `,modalContent:e.css`
      overflow: visible;
    `,modalTokenRow:e.css`
      display: flex;
    `,modalCopyToClipboardButton:e.css`
      margin-left: ${f.spacing(.5)};
    `})},55409:(Ee,$,a)=>{a.d($,{R5:()=>h,TL:()=>W,XE:()=>f,Xd:()=>g,bX:()=>D,fT:()=>u,yN:()=>j});var e=a(89949),s=a.n(e),M=a(55041),A=a(11563),S=a(96237),p=a(3315),m=a(88843);const d="/api/serviceaccounts";function D(){return async c=>{try{if(S.Vt.licensedAccessControlEnabled()&&S.Vt.hasPermission(p.AccessControlAction.ActionRolesList)){const l=await(0,A.ul)();c((0,m.Dn)(l))}}catch(l){console.error(l)}}}function g({withLoadingIndicator:c}={withLoadingIndicator:!1}){return async(l,P)=>{try{if(S.Vt.hasPermission(p.AccessControlAction.ServiceAccountsRead)){c&&l((0,m.pN)());const{perPage:v,page:y,query:U,serviceAccountStateFilter:B}=P().serviceAccounts,k=await(0,M.i)().get(`/api/serviceaccounts/search?perpage=${v}&page=${y}&query=${U}${b(B)}&accesscontrol=true`);l((0,m.Ub)(k))}}catch(v){console.error(v)}finally{l((0,m.dt)())}}}const N=(0,e.debounce)(c=>c(g()),500,{leading:!0});function W(c){return async l=>{await(0,M.i)().patch(`${d}/${c.id}?accesscontrol=true`,{...c}),l(g())}}function j(c){return async l=>{await(0,M.i)().delete(`${d}/${c}`),l(g())}}function u(c,l,P){return async v=>{const y=await(0,M.i)().post(`${d}/${c}/tokens`,l);P(y.key),v(g())}}const b=c=>{switch(c){case p.ServiceAccountStateFilter.WithExpiredTokens:return"&expiredTokens=true";case p.ServiceAccountStateFilter.Disabled:return"&disabled=true";default:return""}};function h(c){return async l=>{l((0,m.aj)(c)),N(l)}}function f(c){return async l=>{l((0,m.M4)(c)),l(g())}}function C(c){return async l=>{l(pageChanged(c)),l(g())}}}}]);

//# sourceMappingURL=ServiceAccountPage.9acd32949d797aab2c8a.js.map