"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[687],{21906:(Ee,k,a)=>{a.r(k),a.d(k,{ServiceAccountPageUnconnected:()=>pe,default:()=>Re});var e=a(85960),s=a(36752),y=a(58715),x=a(74042),p=a(29165),C=a(75064),i=a(77980),P=a(20989),v=a(49683),c=a(95162),K=a(88879),V=a(41879);const Q=t=>{const n=V.contextSrv.hasPermissionInMetadata(c.AccessControlAction.ServiceAccountsPermissionsWrite,t.serviceAccount);return e.createElement(K.P,{title:"Permissions",addPermissionTitle:"Add permission",buttonLabel:"Add permission",resource:"serviceaccounts",resourceId:t.serviceAccount.id,canSetPermissions:n})};var H=a(39042),u=a(66681),B=a(12537),m=a(47257),g=a(57445),r=a(79055),l=a(80932),O=a(56152),D=a(24956),h=a(16783);const R=({label:t,value:n,inputType:o,disabled:E,onChange:f})=>{const T=(0,e.useRef)(null),[d,U]=(0,e.useState)(n),[$,S]=(0,e.useState)(!1),N=(0,m.wW)(F),ae=`${t}-input`;(0,e.useEffect)(()=>{$&&ue()},[$]);const oe=()=>{S(!0)},ie=()=>{S(!1),U(n||"")},se=(Z,W)=>{W!==O.G.Invalid&&U(Z.target.value)},de=(Z,W)=>{W!==O.G.Invalid&&U(Z.target.value)},ue=()=>{T?.current?.focus()},me=()=>{S(!1),f&&f(d)};return e.createElement("tr",null,e.createElement("td",null,e.createElement(g._,{htmlFor:ae},t)),e.createElement("td",{className:"width-25",colSpan:2},!E&&$?e.createElement(D.I,{id:ae,type:o,defaultValue:n,onBlur:de,onChange:se,ref:T,width:30}):e.createElement("span",{className:(0,u.cx)({[N.disabled]:E})},n)),e.createElement("td",null,f&&e.createElement(h.p,{closeOnConfirm:!0,confirmText:"Save",onConfirm:me,onClick:oe,onCancel:ie,disabled:E},"Edit")))},F=t=>({disabled:(0,u.css)`
      color: ${t.colors.text.secondary};
    `});var L=a(84184),z=a(95831);const w=({label:t,serviceAccount:n,roleOptions:o,onRoleChange:E})=>{const f=`${t}-input`,T=v.Vt.hasPermissionInMetadata(c.AccessControlAction.ServiceAccountsWrite,n);return e.createElement("tr",null,e.createElement("td",null,e.createElement(g._,{htmlFor:f},t)),v.Vt.licensedAccessControlEnabled()?e.createElement("td",{colSpan:3},e.createElement(L.R,{userId:n.id,orgId:n.orgId,basicRole:n.role,onBasicRoleChange:E,roleOptions:o,basicRoleDisabled:!T,disabled:n.isExternal||n.isDisabled})):e.createElement(e.Fragment,null,e.createElement("td",null,e.createElement(z.A,{width:24,inputId:f,"aria-label":"Role",value:n.role,disabled:n.isExternal||n.isDisabled,onChange:E})),e.createElement("td",{colSpan:2})))};function A({serviceAccount:t,timeZone:n,onChange:o}){const E=(0,m.wW)(I),f=v.Vt.hasPermission(c.AccessControlAction.ServiceAccountsWrite),[T,d]=e.useState([]),U=S=>{o({...t,role:S})},$=S=>{o({...t,name:S})};return e.useEffect(()=>{async function S(){try{if(v.Vt.hasPermission(c.AccessControlAction.ActionRolesList)){let N=await(0,l.ul)(t.orgId);d(N)}}catch{console.error("Error loading options for service account")}}v.Vt.licensedAccessControlEnabled()&&S()},[t.orgId]),e.createElement("div",{className:E.section},e.createElement("h3",null,"Information"),e.createElement("table",{className:"filter-table"},e.createElement("tbody",null,e.createElement(R,{label:"Name",value:t.name,onChange:t.isExternal?void 0:$,disabled:!f||t.isDisabled}),e.createElement(R,{label:"ID",value:t.login,disabled:t.isDisabled}),e.createElement(w,{label:"Roles",serviceAccount:t,onRoleChange:U,roleOptions:T}),e.createElement(R,{label:"Creation date",value:(0,B.dq)(t.createdAt,{timeZone:n}),disabled:t.isDisabled}),t.isExternal&&t.requiredBy&&e.createElement("tr",null,e.createElement("td",null,e.createElement(g._,null,"Used by")),e.createElement("td",null,e.createElement(r.h,{href:`/plugins/${t.requiredBy}`},t.requiredBy))))))}const I=t=>({section:(0,u.css)`
    margin-bottom: ${t.spacing(4)};
  `});var X=a(81573),Y=a(14607),_=a(97666);const ee=({tokens:t,timeZone:n,tokenActionsDisabled:o,onDelete:E})=>{const f=(0,m.l4)(),T=b(f);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(d=>e.createElement("tr",{key:d.id,className:T.tableRow(d.hasExpired||d.isRevoked)},e.createElement("td",null,d.name),e.createElement("td",null,e.createElement(re,{timeZone:n,token:d})),e.createElement("td",null,te(n,d.created)),e.createElement("td",null,j(n,d.lastUsedAt)),e.createElement("td",{className:"width-1 text-center"},d.isRevoked&&e.createElement(q,null)),e.createElement("td",null,e.createElement(X.m,{"aria-label":`Delete service account token ${d.name}`,size:"sm",onConfirm:()=>E(d),disabled:o}))))))};function j(t,n){return n?(0,B.dq)(n,{timeZone:t}):"Never"}function te(t,n){return n?(0,B.dq)(n,{timeZone:t}):"No expiration date"}function le(t){const n=Math.ceil(t/86400);return`Expires in ${n>1?`${n} days`:`${n} day`}`}const q=()=>{const t=(0,m.wW)(b);return e.createElement("span",{className:t.hasExpired},"Revoked",e.createElement("span",{className:t.tooltipContainer},e.createElement(Y.u,{content:"This token has been publicly exposed. Please rotate this token"},e.createElement(_.J,{name:"exclamation-triangle",className:t.toolTipIcon}))))},re=({timeZone:t,token:n})=>{const o=(0,m.wW)(b);return n.expiration?n.secondsUntilExpiration?e.createElement("span",{className:o.secondsUntilExpiration},le(n.secondsUntilExpiration)):n.hasExpired?e.createElement("span",{className:o.hasExpired},"Expired",e.createElement("span",{className:o.tooltipContainer},e.createElement(Y.u,{content:"This token has expired"},e.createElement(_.J,{name:"exclamation-triangle",className:o.toolTipIcon})))):e.createElement("span",null,te(t,n.expiration)):e.createElement("span",{className:o.neverExpire},"Never")},b=t=>({tableRow:n=>(0,u.css)`
    color: ${n?t.colors.text.secondary:t.colors.text.primary};
  `,tooltipContainer:(0,u.css)`
    margin-left: ${t.spacing(1)};
  `,toolTipIcon:(0,u.css)`
    color: ${t.colors.error.text};
  `,secondsUntilExpiration:(0,u.css)`
    color: ${t.colors.warning.text};
  `,hasExpired:(0,u.css)`
    color: ${t.colors.error.text};
  `,neverExpire:(0,u.css)`
    color: ${t.colors.text.secondary};
  `,section:(0,u.css)`
    margin-bottom: ${t.spacing(4)};
  `});var ve=a(66585),G=a(85445),xe=a(91),Te=a(78105),ne=a(28970);const J="/api/serviceaccounts";function fe(t){return async n=>{n((0,ne.s3)());try{const o=await(0,G.i)().get(`${J}/${t}`,(0,Te.y)());n((0,ne.P4)(o))}catch(o){console.error(o)}finally{n((0,ne.LA)())}}}function he(t){return async n=>{await(0,G.i)().patch(`${J}/${t.id}?accesscontrol=true`,{...t}),n(fe(t.id))}}function ye(t){return async()=>{await(0,G.i)().delete(`${J}/${t}`),xe.E1.push("/org/serviceaccounts")}}function Pe(t,n,o){return async E=>{const f=await(0,G.i)().post(`${J}/${t}/tokens`,n);o(f.key),E(ce(t))}}function Ae(t,n){return async o=>{await(0,G.i)().delete(`${J}/${t}/tokens/${n}`),o(ce(t))}}function ce(t){return async n=>{try{const o=await(0,G.i)().get(`${J}/${t}/tokens`);n((0,ne.e7)(o))}catch(o){console.error(o)}}}function Ie(t){return{serviceAccount:t.serviceAccountProfile.serviceAccount,tokens:t.serviceAccountProfile.tokens,isLoading:t.serviceAccountProfile.isLoading,timezone:(0,y.Z)(t.user)}}const Me={createServiceAccountToken:Pe,deleteServiceAccount:ye,deleteServiceAccountToken:Ae,loadServiceAccount:fe,loadServiceAccountTokens:ce,updateServiceAccount:he},Oe=(0,s.connect)(Ie,Me),pe=({match:t,serviceAccount:n,tokens:o,timezone:E,isLoading:f,createServiceAccountToken:T,deleteServiceAccount:d,deleteServiceAccountToken:U,loadServiceAccount:$,loadServiceAccountTokens:S,updateServiceAccount:N})=>{const[ae,oe]=(0,e.useState)(""),[ie,se]=(0,e.useState)(!1),[de,ue]=(0,e.useState)(!1),[me,Z]=(0,e.useState)(!1),W=parseInt(t.params.id,10),ge=n.isDisabled||n.isExternal||!v.Vt.hasPermission(c.AccessControlAction.ServiceAccountsWrite),De=v.Vt.hasPermission(c.AccessControlAction.ServiceAccountsWrite),Le=v.Vt.hasPermissionInMetadata(c.AccessControlAction.ServiceAccountsPermissionsRead,n),be={text:n.name,img:n.avatarUrl,subTitle:"Manage settings for an individual service account."};(0,e.useEffect)(()=>{$(W),S(W),v.Vt.licensedAccessControlEnabled()&&(0,ve.bX)()},[$,S,W]);const $e=M=>{N(M)},Ce=M=>()=>{ue(M)},Se=M=>()=>{Z(M)},Ne=()=>{d(n.id)},Be=()=>{N({...n,isDisabled:!0}),Z(!1)},Ue=()=>{N({...n,isDisabled:!1})},We=M=>{U(n?.id,M.id)},ke=M=>{T(n?.id,M,oe)},Ke=()=>{se(!1),oe("")};return e.createElement(P.T,{navId:"serviceaccounts",pageNav:be},e.createElement(P.T.Contents,{isLoading:f},e.createElement("div",null,n&&!n.isExternal&&e.createElement(x.Lh,{spacing:"md",height:"auto",justify:"flex-end"},e.createElement(p.zx,{type:"button",variant:"destructive",onClick:Ce(!0),disabled:!v.Vt.hasPermission(c.AccessControlAction.ServiceAccountsDelete)},"Delete service account"),n.isDisabled?e.createElement(p.zx,{type:"button",variant:"secondary",onClick:Ue,disabled:!De},"Enable service account"):e.createElement(p.zx,{type:"button",variant:"secondary",onClick:Se(!0),disabled:!De},"Disable service account")),n&&n.isExternal&&e.createElement(x.Lh,{spacing:"md",height:"auto",justify:"flex-end"},e.createElement(C.h,{disabled:!0,name:"lock",size:"md",tooltip:"This is a managed service account and cannot be modified."})),n&&e.createElement(A,{serviceAccount:n,timeZone:E,onChange:$e}),e.createElement(x.Lh,{justify:"space-between",height:"auto"},e.createElement("h3",null,"Tokens"),!n.isExternal&&e.createElement(p.zx,{onClick:()=>se(!0),disabled:ge},"Add service account token")),o&&e.createElement(ee,{tokens:o,timeZone:E,onDelete:We,tokenActionsDisabled:ge}),!n.isExternal&&Le&&e.createElement(Q,{serviceAccount:n})),e.createElement(i.s,{isOpen:de,title:"Delete service account",body:"Are you sure you want to delete this service account?",confirmText:"Delete service account",onConfirm:Ne,onDismiss:Ce(!1)}),e.createElement(i.s,{isOpen:me,title:"Disable service account",body:"Are you sure you want to disable this service account?",confirmText:"Disable service account",onConfirm:Be,onDismiss:Se(!1)}),e.createElement(H.m,{isOpen:ie,token:ae,serviceAccountLogin:n.login,onCreateToken:ke,onClose:Ke})))},Re=Oe(pe)},39042:(Ee,k,a)=>{a.d(k,{m:()=>H});var e=a(66681),s=a(85960),y=a(90308),x=a(90857),p=a(47257),C=a(7288),i=a(20519),P=a(24956),v=a(5106),c=a(68594),K=a(29165),V=a(55855);const Q=[{label:"No expiration",value:!1},{label:"Set expiration date",value:!0}],H=({isOpen:m,token:g,serviceAccountLogin:r,onCreateToken:l,onClose:O})=>{const D=new Date;D.setDate(D.getDate()+1);const h=new Date;x.config.tokenExpirationDayLimit!==void 0&&x.config.tokenExpirationDayLimit>-1?h.setDate(h.getDate()+x.config.tokenExpirationDayLimit+1):h.setDate(864e13);const R=x.config.tokenExpirationDayLimit!==void 0&&x.config.tokenExpirationDayLimit>0,[F,L]=(0,s.useState)(""),[z,w]=(0,s.useState)(""),[A,I]=(0,s.useState)(R),[X,Y]=(0,s.useState)(D),[_,ee]=(0,s.useState)(X!==""),j=(0,p.wW)(B);(0,s.useEffect)(()=>{m&&L(`${r}-${(0,y.Z)()}`)},[r,m]);const te=b=>{ee(b!==""),Y(b)},le=()=>{l({name:z||F,secondsToLive:A?u(X):void 0})},q=()=>{w(""),L(""),I(R),Y(D),ee(X!==""),O()},re=g?"Service account token created":"Add service account token";return s.createElement(C.u,{isOpen:m,title:re,onDismiss:q,className:j.modal,contentClassName:j.modalContent},g?s.createElement(s.Fragment,null,s.createElement(i.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:j.modalTokenRow},s.createElement(P.I,{name:"tokenValue",value:g,readOnly:!0}),s.createElement(V.m,{className:j.modalCopyToClipboardButton,variant:"primary",size:"md",icon:"copy",getText:()=>g},"Copy clipboard"))),s.createElement(C.u.ButtonRow,null,s.createElement(V.m,{variant:"primary",getText:()=>g,onClipboardCopy:q},"Copy to clipboard and close"),s.createElement(K.zx,{variant:"secondary",onClick:q},"Close"))):s.createElement("div",null,s.createElement(i.g,{label:"Display name",description:"Name to easily identify the token",required:!0},s.createElement(P.I,{name:"tokenName",value:z,placeholder:F,onChange:b=>{w(b.currentTarget.value)}})),s.createElement(i.g,{label:"Expiration"},s.createElement(v.S,{options:Q,value:A,onChange:I,size:"md"})),A&&s.createElement(i.g,{label:"Expiration date"},s.createElement(c.d,{onChange:te,value:X,placeholder:"",minDate:D,maxDate:h})),s.createElement(C.u.ButtonRow,null,s.createElement(K.zx,{onClick:le,disabled:A&&!_},"Generate token"))))},u=m=>{const g=new Date(m),r=new Date;return Math.ceil((g.getTime()-r.getTime())/1e3)},B=m=>({modal:(0,e.css)`
      width: 550px;
    `,modalContent:(0,e.css)`
      overflow: visible;
    `,modalTokenRow:(0,e.css)`
      display: flex;
    `,modalCopyToClipboardButton:(0,e.css)`
      margin-left: ${m.spacing(.5)};
    `})},66585:(Ee,k,a)=>{a.d(k,{R5:()=>B,TL:()=>V,XE:()=>m,Xd:()=>c,bX:()=>v,fT:()=>H,oO:()=>g,yN:()=>Q});var e=a(56375),s=a.n(e),y=a(85445),x=a(80932),p=a(41879),C=a(95162),i=a(28970);const P="/api/serviceaccounts";function v(){return async r=>{try{if(p.contextSrv.licensedAccessControlEnabled()&&p.contextSrv.hasPermission(C.AccessControlAction.ActionRolesList)){const l=await(0,x.ul)();r((0,i.Dn)(l))}}catch(l){console.error(l)}}}function c({withLoadingIndicator:r}={withLoadingIndicator:!1}){return async(l,O)=>{try{if(p.contextSrv.hasPermission(C.AccessControlAction.ServiceAccountsRead)){r&&l((0,i.pN)());const{perPage:D,page:h,query:R,serviceAccountStateFilter:F}=O().serviceAccounts,L=await(0,y.i)().get(`/api/serviceaccounts/search?perpage=${D}&page=${h}&query=${R}${u(F)}&accesscontrol=true`);if(p.contextSrv.licensedAccessControlEnabled()&&p.contextSrv.hasPermission(C.AccessControlAction.ActionUserRolesList)){l((0,i.Fy)());const z=p.contextSrv.user.orgId,w=L?.serviceAccounts.map(I=>I.id),A=await(0,y.i)().post("/api/access-control/users/roles/search",{userIds:w,orgId:z});L.serviceAccounts.forEach(I=>{I.roles=A?A[I.id]||[]:[]}),l((0,i.BR)())}l((0,i.Ub)(L))}}catch(D){console.error(D)}finally{l((0,i.dt)())}}}const K=(0,e.debounce)(r=>r(c()),500,{leading:!0});function V(r){return async l=>{await(0,y.i)().patch(`${P}/${r.id}?accesscontrol=true`,{...r}),l(c())}}function Q(r){return async l=>{await(0,y.i)().delete(`${P}/${r}`),l(c())}}function H(r,l,O){return async D=>{const h=await(0,y.i)().post(`${P}/${r}/tokens`,l);O(h.key),D(c())}}const u=r=>{switch(r){case C.ServiceAccountStateFilter.WithExpiredTokens:return"&expiredTokens=true";case C.ServiceAccountStateFilter.Disabled:return"&disabled=true";case C.ServiceAccountStateFilter.External:return"&external=true";default:return""}};function B(r){return async l=>{l((0,i.aj)(r)),K(l)}}function m(r){return async l=>{l((0,i.M4)(r)),l(c())}}function g(r){return async l=>{l((0,i.PJ)(r)),l(c())}}}}]);

//# sourceMappingURL=ServiceAccountPage.7f67e895054954c9726b.js.map