"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[6576],{82936:(Ee,k,a)=>{a.r(k),a.d(k,{ServiceAccountPageUnconnected:()=>pe,default:()=>Re});var e=a(96540),s=a(63329),h=a(1933),C=a(66864),p=a(55852),g=a(29158),i=a(96374),S=a(17205),f=a(10096),c=a(31678),K=a(5108),F=a(16233);const Q=t=>{const n=F.TP.hasPermissionInMetadata(c.AccessControlAction.ServiceAccountsPermissionsWrite,t.serviceAccount);return e.createElement(K.x,{title:"Permissions",addPermissionTitle:"Add permission",buttonLabel:"Add permission",resource:"serviceaccounts",resourceId:t.serviceAccount.id,canSetPermissions:n})};var X=a(98788),u=a(32196),B=a(72724),m=a(40845),D=a(60029),r=a(72109),l=a(85927),O=a(91634),T=a(10354),A=a(82702);const R=({label:t,value:n,inputType:o,disabled:E,onChange:v})=>{const y=(0,e.useRef)(null),[d,U]=(0,e.useState)(n),[b,P]=(0,e.useState)(!1),N=(0,m.of)(V),ae=`${t}-input`;(0,e.useEffect)(()=>{b&&ue()},[b]);const oe=()=>{P(!0)},ie=()=>{P(!1),U(n||"")},se=(w,W)=>{W!==O.O.Invalid&&U(w.target.value)},de=(w,W)=>{W!==O.O.Invalid&&U(w.target.value)},ue=()=>{y?.current?.focus()},me=()=>{P(!1),v&&v(d)};return e.createElement("tr",null,e.createElement("td",null,e.createElement(D.J,{htmlFor:ae},t)),e.createElement("td",{className:"width-25",colSpan:2},!E&&b?e.createElement(T.p,{id:ae,type:o,defaultValue:n,onBlur:de,onChange:se,ref:y,width:30}):e.createElement("span",{className:(0,u.cx)({[N.disabled]:E})},n)),e.createElement("td",null,v&&e.createElement(A.Z,{closeOnConfirm:!0,confirmText:"Save",onConfirm:me,onClick:oe,onCancel:ie,disabled:E},"Edit")))},V=t=>({disabled:(0,u.css)`
      color: ${t.colors.text.secondary};
    `});var $=a(89062),z=a(5133);const J=({label:t,serviceAccount:n,roleOptions:o,onRoleChange:E})=>{const v=`${t}-input`,y=f.TP.hasPermissionInMetadata(c.AccessControlAction.ServiceAccountsWrite,n);return e.createElement("tr",null,e.createElement("td",null,e.createElement(D.J,{htmlFor:v},t)),f.TP.licensedAccessControlEnabled()?e.createElement("td",{colSpan:3},e.createElement($.y,{userId:n.id,orgId:n.orgId,basicRole:n.role,onBasicRoleChange:E,roleOptions:o,basicRoleDisabled:!y,disabled:n.isExternal||n.isDisabled})):e.createElement(e.Fragment,null,e.createElement("td",null,e.createElement(z.r,{width:24,inputId:v,"aria-label":"Role",value:n.role,disabled:n.isExternal||n.isDisabled,onChange:E})),e.createElement("td",{colSpan:2})))};function x({serviceAccount:t,timeZone:n,onChange:o}){const E=(0,m.of)(I),v=f.TP.hasPermission(c.AccessControlAction.ServiceAccountsWrite),[y,d]=e.useState([]),U=P=>{o({...t,role:P})},b=P=>{o({...t,name:P})};return e.useEffect(()=>{async function P(){try{if(f.TP.hasPermission(c.AccessControlAction.ActionRolesList)){let N=await(0,l.RL)(t.orgId);d(N)}}catch{console.error("Error loading options for service account")}}f.TP.licensedAccessControlEnabled()&&P()},[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:b,disabled:!v||t.isDisabled}),e.createElement(R,{label:"ID",value:t.login,disabled:t.isDisabled}),e.createElement(J,{label:"Roles",serviceAccount:t,onRoleChange:U,roleOptions:y}),e.createElement(R,{label:"Creation date",value:(0,B.LE)(t.createdAt,{timeZone:n}),disabled:t.isDisabled}),t.isExternal&&t.requiredBy&&e.createElement("tr",null,e.createElement("td",null,e.createElement(D.J,null,"Used by")),e.createElement("td",null,e.createElement(r.Y,{href:`/plugins/${t.requiredBy}`},t.requiredBy))))))}const I=t=>({section:(0,u.css)`
    margin-bottom: ${t.spacing(4)};
  `});var G=a(91605),Z=a(56034),_=a(14578);const ee=({tokens:t,timeZone:n,tokenActionsDisabled:o,onDelete:E})=>{const v=(0,m.$j)(),y=L(v);return e.createElement("table",{className:(0,u.cx)(y.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:y.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,H(n,d.lastUsedAt)),e.createElement("td",{className:"width-1 text-center"},d.isRevoked&&e.createElement(q,null)),e.createElement("td",null,e.createElement(G.e,{"aria-label":`Delete service account token ${d.name}`,size:"sm",onConfirm:()=>E(d),disabled:o}))))))};function H(t,n){return n?(0,B.LE)(n,{timeZone:t}):"Never"}function te(t,n){return n?(0,B.LE)(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.of)(L);return e.createElement("span",{className:t.hasExpired},"Revoked",e.createElement("span",{className:t.tooltipContainer},e.createElement(Z.m,{content:"This token has been publicly exposed. Please rotate this token"},e.createElement(_.I,{name:"exclamation-triangle",className:t.toolTipIcon}))))},re=({timeZone:t,token:n})=>{const o=(0,m.of)(L);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(Z.m,{content:"This token has expired"},e.createElement(_.I,{name:"exclamation-triangle",className:o.toolTipIcon})))):e.createElement("span",null,te(t,n.expiration)):e.createElement("span",{className:o.neverExpire},"Never")},L=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 fe=a(12966),j=a(17172),Ce=a(12131),ye=a(80714),ne=a(1936);const Y="/api/serviceaccounts";function ve(t){return async n=>{n((0,ne.G3)());try{const o=await(0,j.AI)().get(`${Y}/${t}`,(0,ye.F)());n((0,ne.QM)(o))}catch(o){console.error(o)}finally{n((0,ne.aD)())}}}function Ae(t){return async n=>{await(0,j.AI)().patch(`${Y}/${t.id}?accesscontrol=true`,{...t}),n(ve(t.id))}}function he(t){return async()=>{await(0,j.AI)().delete(`${Y}/${t}`),Ce.Ny.push("/org/serviceaccounts")}}function Se(t,n,o){return async E=>{const v=await(0,j.AI)().post(`${Y}/${t}/tokens`,n);o(v.key),E(ce(t))}}function xe(t,n){return async o=>{await(0,j.AI)().delete(`${Y}/${t}/tokens/${n}`),o(ce(t))}}function ce(t){return async n=>{try{const o=await(0,j.AI)().get(`${Y}/${t}/tokens`);n((0,ne.ch)(o))}catch(o){console.error(o)}}}function Ie(t){return{serviceAccount:t.serviceAccountProfile.serviceAccount,tokens:t.serviceAccountProfile.tokens,isLoading:t.serviceAccountProfile.isLoading,timezone:(0,h.O)(t.user)}}const Me={createServiceAccountToken:Se,deleteServiceAccount:he,deleteServiceAccountToken:xe,loadServiceAccount:ve,loadServiceAccountTokens:ce,updateServiceAccount:Ae},Oe=(0,s.connect)(Ie,Me),pe=({match:t,serviceAccount:n,tokens:o,timezone:E,isLoading:v,createServiceAccountToken:y,deleteServiceAccount:d,deleteServiceAccountToken:U,loadServiceAccount:b,loadServiceAccountTokens:P,updateServiceAccount:N})=>{const[ae,oe]=(0,e.useState)(""),[ie,se]=(0,e.useState)(!1),[de,ue]=(0,e.useState)(!1),[me,w]=(0,e.useState)(!1),W=parseInt(t.params.id,10),De=n.isDisabled||n.isExternal||!f.TP.hasPermission(c.AccessControlAction.ServiceAccountsWrite),Te=f.TP.hasPermission(c.AccessControlAction.ServiceAccountsWrite),$e=f.TP.hasPermissionInMetadata(c.AccessControlAction.ServiceAccountsPermissionsRead,n),Le={text:n.name,img:n.avatarUrl,subTitle:"Manage settings for an individual service account."};(0,e.useEffect)(()=>{b(W),P(W),f.TP.licensedAccessControlEnabled()&&(0,fe.pJ)()},[b,P,W]);const be=M=>{N(M)},ge=M=>()=>{ue(M)},Pe=M=>()=>{w(M)},Ne=()=>{d(n.id)},Be=()=>{N({...n,isDisabled:!0}),w(!1)},Ue=()=>{N({...n,isDisabled:!1})},We=M=>{U(n?.id,M.id)},ke=M=>{y(n?.id,M,oe)},Ke=()=>{se(!1),oe("")};return e.createElement(S.Y,{navId:"serviceaccounts",pageNav:Le},e.createElement(S.Y.Contents,{isLoading:v},e.createElement("div",null,n&&!n.isExternal&&e.createElement(C.Gy,{spacing:"md",height:"auto",justify:"flex-end"},e.createElement(p.$n,{type:"button",variant:"destructive",onClick:ge(!0),disabled:!f.TP.hasPermission(c.AccessControlAction.ServiceAccountsDelete)},"Delete service account"),n.isDisabled?e.createElement(p.$n,{type:"button",variant:"secondary",onClick:Ue,disabled:!Te},"Enable service account"):e.createElement(p.$n,{type:"button",variant:"secondary",onClick:Pe(!0),disabled:!Te},"Disable service account")),n&&n.isExternal&&e.createElement(C.Gy,{spacing:"md",height:"auto",justify:"flex-end"},e.createElement(g.K,{disabled:!0,name:"lock",size:"md",tooltip:"This is a managed service account and cannot be modified."})),n&&e.createElement(x,{serviceAccount:n,timeZone:E,onChange:be}),e.createElement(C.Gy,{justify:"space-between",height:"auto"},e.createElement("h3",null,"Tokens"),!n.isExternal&&e.createElement(p.$n,{onClick:()=>se(!0),disabled:De},"Add service account token")),o&&e.createElement(ee,{tokens:o,timeZone:E,onDelete:We,tokenActionsDisabled:De}),!n.isExternal&&$e&&e.createElement(Q,{serviceAccount:n})),e.createElement(i.u,{isOpen:de,title:"Delete service account",body:"Are you sure you want to delete this service account?",confirmText:"Delete service account",onConfirm:Ne,onDismiss:ge(!1)}),e.createElement(i.u,{isOpen:me,title:"Disable service account",body:"Are you sure you want to disable this service account?",confirmText:"Disable service account",onConfirm:Be,onDismiss:Pe(!1)}),e.createElement(X.z,{isOpen:ie,token:ae,serviceAccountLogin:n.login,onCreateToken:ke,onClose:Ke})))},Re=Oe(pe)},98788:(Ee,k,a)=>{a.d(k,{z:()=>X});var e=a(32196),s=a(96540),h=a(62938),C=a(32264),p=a(40845),g=a(37390),i=a(88575),S=a(10354),f=a(94354),c=a(98239),K=a(55852),F=a(10534);const Q=[{label:"No expiration",value:!1},{label:"Set expiration date",value:!0}],X=({isOpen:m,token:D,serviceAccountLogin:r,onCreateToken:l,onClose:O})=>{const T=new Date;T.setDate(T.getDate()+1);const A=new Date;C.$.tokenExpirationDayLimit!==void 0&&C.$.tokenExpirationDayLimit>-1?A.setDate(A.getDate()+C.$.tokenExpirationDayLimit+1):A.setDate(864e13);const R=C.$.tokenExpirationDayLimit!==void 0&&C.$.tokenExpirationDayLimit>0,[V,$]=(0,s.useState)(""),[z,J]=(0,s.useState)(""),[x,I]=(0,s.useState)(R),[G,Z]=(0,s.useState)(T),[_,ee]=(0,s.useState)(G!==""),H=(0,p.of)(B);(0,s.useEffect)(()=>{m&&$(`${r}-${(0,h.A)()}`)},[r,m]);const te=L=>{ee(L!==""),Z(L)},le=()=>{l({name:z||V,secondsToLive:x?u(G):void 0})},q=()=>{J(""),$(""),I(R),Z(T),ee(G!==""),O()},re=D?"Service account token created":"Add service account token";return s.createElement(g.a,{isOpen:m,title:re,onDismiss:q,className:H.modal},D?s.createElement(s.Fragment,null,s.createElement(i.D,{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:H.modalTokenRow},s.createElement(S.p,{name:"tokenValue",value:D,readOnly:!0}),s.createElement(F.b,{className:H.modalCopyToClipboardButton,variant:"primary",size:"md",icon:"copy",getText:()=>D},"Copy clipboard"))),s.createElement(g.a.ButtonRow,null,s.createElement(F.b,{variant:"primary",getText:()=>D,onClipboardCopy:q},"Copy to clipboard and close"),s.createElement(K.$n,{variant:"secondary",onClick:q},"Close"))):s.createElement("div",null,s.createElement(i.D,{label:"Display name",description:"Name to easily identify the token",required:!0},s.createElement(S.p,{name:"tokenName",value:z,placeholder:V,onChange:L=>{J(L.currentTarget.value)}})),s.createElement(i.D,{label:"Expiration"},s.createElement(f.z,{options:Q,value:x,onChange:I,size:"md"})),x&&s.createElement(i.D,{label:"Expiration date"},s.createElement(c.l,{onChange:te,value:G,placeholder:"",minDate:T,maxDate:A})),s.createElement(g.a.ButtonRow,null,s.createElement(K.$n,{onClick:le,disabled:x&&!_},"Generate token"))))},u=m=>{const D=new Date(m),r=new Date;return Math.ceil((D.getTime()-r.getTime())/1e3)},B=m=>({modal:(0,e.css)({width:"550px"}),modalTokenRow:(0,e.css)({display:"flex"}),modalCopyToClipboardButton:(0,e.css)({marginLeft:m.spacing(.5)})})},12966:(Ee,k,a)=>{a.d(k,{W4:()=>Q,iJ:()=>c,mV:()=>F,nM:()=>B,pJ:()=>f,qS:()=>m,yC:()=>X,yd:()=>D});var e=a(2543),s=a.n(e),h=a(17172),C=a(85927),p=a(16233),g=a(31678),i=a(1936);const S="/api/serviceaccounts";function f(){return async r=>{try{if(p.TP.licensedAccessControlEnabled()&&p.TP.hasPermission(g.AccessControlAction.ActionRolesList)){const l=await(0,C.RL)();r((0,i.ew)(l))}}catch(l){console.error(l)}}}function c({withLoadingIndicator:r}={withLoadingIndicator:!1}){return async(l,O)=>{try{if(p.TP.hasPermission(g.AccessControlAction.ServiceAccountsRead)){r&&l((0,i.FW)());const{perPage:T,page:A,query:R,serviceAccountStateFilter:V}=O().serviceAccounts,$=await(0,h.AI)().get(`/api/serviceaccounts/search?perpage=${T}&page=${A}&query=${R}${u(V)}&accesscontrol=true`);if(p.TP.licensedAccessControlEnabled()&&p.TP.hasPermission(g.AccessControlAction.ActionUserRolesList)){l((0,i.dJ)());const z=p.TP.user.orgId,J=$?.serviceAccounts.map(I=>I.id),x=await(0,h.AI)().post("/api/access-control/users/roles/search",{userIds:J,orgId:z});$.serviceAccounts.forEach(I=>{I.roles=x?x[I.id]||[]:[]}),l((0,i.jE)())}l((0,i.zh)($))}}catch(T){console.error(T)}finally{l((0,i.Yh)())}}}const K=(0,e.debounce)(r=>r(c()),500,{leading:!0});function F(r){return async l=>{await(0,h.AI)().patch(`${S}/${r.id}?accesscontrol=true`,{...r}),l(c())}}function Q(r){return async l=>{await(0,h.AI)().delete(`${S}/${r}`),l(c())}}function X(r,l,O){return async T=>{const A=await(0,h.AI)().post(`${S}/${r}/tokens`,l);O(A.key),T(c())}}const u=r=>{switch(r){case g.ServiceAccountStateFilter.WithExpiredTokens:return"&expiredTokens=true";case g.ServiceAccountStateFilter.Disabled:return"&disabled=true";case g.ServiceAccountStateFilter.External:return"&external=true";default:return""}};function B(r){return async l=>{l((0,i.L5)(r)),K(l)}}function m(r){return async l=>{l((0,i.c3)(r)),l(c())}}function D(r){return async l=>{l((0,i.EC)(r)),l(c())}}}}]);

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