"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[687],{2552:(me,B,a)=>{a.r(B),a.d(B,{ServiceAccountPageUnconnected:()=>fe,default:()=>Me});var e=a(27702),s=a(27173),M=a(31317),h=a(64022),y=a(66670),D=a(3613),E=a(44644),r=a(66574),f=a(18771),g=a(1541),k=a(91368);const K=t=>{const n=k.contextSrv.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(99442),d=a(42844),L=a(60956),x=a(66310),C=a(11349),T=a(83670),c=a(79978),l=a(1128),b=a(55205);const u=({label:t,value:n,inputType:o,disabled:m,onChange:v})=>{const A=(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=()=>{A?.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:A,width:30}):e.createElement("span",{className:(0,d.cx)({[R.disabled]:m})},n)),e.createElement("td",null,v&&e.createElement(b.p,{closeOnConfirm:!0,confirmText:"Save",onConfirm:ue,onClick:te,onCancel:re,disabled:m},"Edit")))},P=t=>({disabled:(0,d.css)`
      color: ${t.colors.text.secondary};
    `});var V=a(75574),F=a(8237);const z=({label:t,serviceAccount:n,roleOptions:o,onRoleChange:m})=>{const v=`${t}-input`,A=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(V.R,{userId:n.id,orgId:n.orgId,basicRole:n.role,onBasicRoleChange:m,roleOptions:o,basicRoleDisabled:!A,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),[A,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:A}),e.createElement(u,{label:"Creation date",value:(0,L.dq)(t.createdAt,{timeZone:n}),disabled:t.isDisabled}))))}const Y=t=>({section:(0,d.css)`
    margin-bottom: ${t.spacing(4)};
  `});var w=a(15202),Z=a(80011),$=a(73453);const q=({tokens:t,timeZone:n,tokenActionsDisabled:o,onDelete:m})=>{const v=(0,x.l4)(),A=N(v);return e.createElement("table",{className:(0,d.cx)(A.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:A.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,L.dq)(n,{timeZone:t}):"Never"}function Q(t,n){return n?(0,L.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=>(0,d.css)`
    color: ${n?t.colors.text.secondary:t.colors.text.primary};
  `,tooltipContainer:(0,d.css)`
    margin-left: ${t.spacing(1)};
  `,toolTipIcon:(0,d.css)`
    color: ${t.colors.error.text};
  `,secondsUntilExpiration:(0,d.css)`
    color: ${t.colors.warning.text};
  `,hasExpired:(0,d.css)`
    color: ${t.colors.error.text};
  `,neverExpire:(0,d.css)`
    color: ${t.colors.text.secondary};
  `,section:(0,d.css)`
    margin-bottom: ${t.spacing(4)};
  `});var ce=a(55765),S=a(73289),Ee=a(26129),Te=a(92317),_=a(21502);const G="/api/serviceaccounts";function ve(t){return async n=>{n((0,_.s3)());try{const o=await(0,S.i)().get(`${G}/${t}`,(0,Te.y)());n((0,_.P4)(o))}catch(o){console.error(o)}finally{n((0,_.LA)())}}}function Se(t){return async n=>{await(0,S.i)().patch(`${G}/${t.id}?accesscontrol=true`,{...t}),n(ve(t.id))}}function Ae(t){return async()=>{await(0,S.i)().delete(`${G}/${t}`),Ee.E1.push("/org/serviceaccounts")}}function he(t,n,o){return async m=>{const v=await(0,S.i)().post(`${G}/${t}/tokens`,n);o(v.key),m(le(t))}}function ye(t,n){return async o=>{await(0,S.i)().delete(`${G}/${t}/tokens/${n}`),o(le(t))}}function le(t){return async n=>{try{const o=await(0,S.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:Ae,deleteServiceAccountToken:ye,loadServiceAccount:ve,loadServiceAccountTokens:le,updateServiceAccount:Se},Ie=(0,s.connect)(Pe,xe),fe=({match:t,serviceAccount:n,tokens:o,timezone:m,isLoading:v,createServiceAccountToken:A,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,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 Le=I=>{R(I)},ge=I=>()=>{de(I)},Ce=I=>()=>{j(I)},be=()=>{i(n.id)},$e=()=>{R({...n,isDisabled:!0}),j(!1)},Ne=()=>{R({...n,isDisabled:!1})},We=I=>{W(n?.id,I.id)},Ue=I=>{A(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:Le}),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:be,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)},99442:(me,B,a)=>{a.d(B,{m:()=>d});var e=a(42844),s=a(27702),M=a(66117),h=a(34667),y=a(66310),D=a(13741),E=a(22209),r=a(1128),f=a(40705),g=a(37691),k=a(66670),K=a(71585);const J=[{label:"No expiration",value:!1},{label:"Set expiration date",value:!0}],d=({isOpen:C,token:T,serviceAccountLogin:c,onCreateToken:l,onClose:b})=>{const u=new Date;u.setDate(u.getDate()+1);const P=new Date;h.config.tokenExpirationDayLimit!==void 0&&h.config.tokenExpirationDayLimit>-1?P.setDate(P.getDate()+h.config.tokenExpirationDayLimit+1):P.setDate(864e13);const V=h.config.tokenExpirationDayLimit!==void 0&&h.config.tokenExpirationDayLimit>0,[F,z]=(0,s.useState)(""),[H,Y]=(0,s.useState)(""),[w,Z]=(0,s.useState)(V),[$,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=S=>{Q(S!==""),q(S)},se=()=>{l({name:H||F,secondsToLive:w?L($):void 0})},N=()=>{Y(""),z(""),Z(V),q(u),Q($!==""),b()},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(k.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:S=>{Y(S.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(k.zx,{onClick:se,disabled:w&&!ae},"Generate token"))))},L=C=>{const T=new Date(C),c=new Date;return Math.ceil((T.getTime()-c.getTime())/1e3)},x=C=>({modal:(0,e.css)`
      width: 550px;
    `,modalContent:(0,e.css)`
      overflow: visible;
    `,modalTokenRow:(0,e.css)`
      display: flex;
    `,modalCopyToClipboardButton:(0,e.css)`
      margin-left: ${C.spacing(.5)};
    `})},55765:(me,B,a)=>{a.d(B,{R5:()=>x,TL:()=>K,XE:()=>C,Xd:()=>g,bX:()=>f,fT:()=>d,yN:()=>J});var e=a(89949),s=a.n(e),M=a(73289),h=a(11349),y=a(91368),D=a(18771),E=a(21502);const r="/api/serviceaccounts";function f(){return async c=>{try{if(y.contextSrv.licensedAccessControlEnabled()&&y.contextSrv.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,b)=>{try{if(y.contextSrv.hasPermission(D.AccessControlAction.ServiceAccountsRead)){c&&l((0,E.pN)());const{perPage:u,page:P,query:V,serviceAccountStateFilter:F}=b().serviceAccounts,z=await(0,M.i)().get(`/api/serviceaccounts/search?perpage=${u}&page=${P}&query=${V}${L(F)}&accesscontrol=true`);l((0,E.Ub)(z))}}catch(u){console.error(u)}finally{l((0,E.dt)())}}}const k=(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,b){return async u=>{const P=await(0,M.i)().post(`${r}/${c}/tokens`,l);b(P.key),u(g())}}const L=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)),k(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.dc79e54dbd194a1157d6.js.map