"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[1337],{71911:(J,O,n)=>{n.r(O),n.d(O,{ServiceAccountsListPageUnconnected:()=>M,default:()=>Z,getStyles:()=>X});var a=n(42844),o=n(6772),y=n.n(o),e=n(27702),A=n(27173),v=n(66310),m=n(48024),C=n(33716),V=n(40705),d=n(66670),P=n(3613),R=n(66970),k=n(44644),z=n(95685),r=n(66574),i=n(18771),f=n(99442),p=n(73453),s=n(64022),l=n(67437),x=n(75574),u=n(8237);const E=t=>`Edit service account's ${t} details`,I=(0,e.memo)(({serviceAccount:t,onRoleChange:h,roleOptions:w,onRemoveButtonClick:S,onDisable:W,onEnable:T,onAddTokenClick:U})=>{const L=`org/serviceaccounts/${t.id}`,b=(0,v.wW)($),K=r.Vt.hasPermissionInMetadata(i.AccessControlAction.ServiceAccountsWrite,t),H=r.Vt.hasPermission(i.AccessControlAction.ActionRolesList)&&r.Vt.hasPermission(i.AccessControlAction.ActionUserRolesList);return e.createElement("tr",{key:t.id,className:(0,a.cx)({[b.disabled]:t.isDisabled})},e.createElement("td",{className:"width-4 text-center link-td"},e.createElement("a",{href:L,"aria-label":E(t.name)},e.createElement("img",{className:"filter-table__avatar",src:t.avatarUrl,alt:`Avatar for user ${t.name}`}))),e.createElement("td",{className:"link-td max-width-10"},e.createElement("a",{className:"ellipsis",href:L,title:t.name,"aria-label":E(t.name)},t.name)),e.createElement("td",{className:"link-td max-width-10"},e.createElement("a",{className:b.accountId,href:L,title:t.login,"aria-label":E(t.name)},t.login)),r.Vt.licensedAccessControlEnabled()?e.createElement("td",null,H&&e.createElement(x.R,{userId:t.id,orgId:t.orgId,basicRole:t.role,onBasicRoleChange:Q=>h(Q,t),roleOptions:w,basicRoleDisabled:!K,disabled:t.isDisabled})):e.createElement("td",null,e.createElement(u.A,{"aria-label":"Role",value:t.role,disabled:!K||t.isDisabled,onChange:Q=>h(Q,t)})),e.createElement("td",{className:"link-td max-width-10"},e.createElement("a",{className:"ellipsis",href:L,title:"Tokens","aria-label":E(t.name)},e.createElement("div",{className:(0,a.cx)(b.tokensInfo,{[b.tokensInfoSecondary]:!t.tokens})},e.createElement("span",null,e.createElement(p.J,{name:"key-skeleton-alt"})),t.tokens||"No tokens"))),e.createElement("td",null,e.createElement(s.Lh,{justify:"flex-end"},r.Vt.hasPermission(i.AccessControlAction.ServiceAccountsWrite)&&!t.tokens&&e.createElement(d.zx,{onClick:()=>U(t),disabled:t.isDisabled},"Add token"),r.Vt.hasPermissionInMetadata(i.AccessControlAction.ServiceAccountsWrite,t)&&(t.isDisabled?e.createElement(d.zx,{variant:"primary",onClick:()=>T(t)},"Enable"):e.createElement(d.zx,{variant:"secondary",onClick:()=>W(t)},"Disable")),r.Vt.hasPermissionInMetadata(i.AccessControlAction.ServiceAccountsDelete,t)&&e.createElement(l.h,{className:b.deleteButton,name:"trash-alt",size:"md",onClick:()=>S(t),tooltip:`Delete service account ${t.name}`}))))});I.displayName="ServiceAccountListItem";const $=t=>({iconRow:(0,a.css)`
      svg {
        margin-left: ${t.spacing(.5)};
      }
    `,accountId:(0,a.cx)("ellipsis",(0,a.css)`
        color: ${t.colors.text.secondary};
      `),deleteButton:(0,a.css)`
      color: ${t.colors.text.secondary};
    `,tokensInfo:(0,a.css)`
      span {
        margin-right: ${t.spacing(1)};
      }
    `,tokensInfoSecondary:(0,a.css)`
      color: ${t.colors.text.secondary};
    `,disabled:(0,a.css)`
      td a {
        color: ${t.colors.text.secondary};
      }
    `}),N=I;var D=n(55765);function G(t){return{...t.serviceAccounts}}const B={changeQuery:D.R5,fetchACOptions:D.bX,fetchServiceAccounts:D.Xd,deleteServiceAccount:D.yN,updateServiceAccount:D.TL,changeStateFilter:D.XE,createServiceAccountToken:D.fT},j=(0,A.connect)(G,B),M=({serviceAccounts:t,isLoading:h,roleOptions:w,query:S,serviceAccountStateFilter:W,changeQuery:T,fetchACOptions:U,fetchServiceAccounts:L,deleteServiceAccount:b,updateServiceAccount:K,changeStateFilter:H,createServiceAccountToken:Q})=>{const _=(0,v.wW)(X),[le,q]=(0,e.useState)(!1),[ce,ee]=(0,e.useState)(!1),[ie,te]=(0,e.useState)(!1),[re,ne]=(0,e.useState)(""),[g,F]=(0,e.useState)(null);(0,e.useEffect)(()=>{L({withLoadingIndicator:!0}),r.Vt.licensedAccessControlEnabled()&&U()},[U,L]);const ae=t.length===0&&W===i.ServiceAccountStateFilter.All&&!S,de=async(c,Te)=>{const Ae={...Te,role:c};K(Ae),r.Vt.licensedAccessControlEnabled()&&U()},me=c=>{T(c)},ue=c=>{H(c)},Ee=c=>{F(c),ee(!0)},ge=async()=>{g&&b(g.id),oe()},ve=c=>{F(c),te(!0)},fe=()=>{g&&K({...g,isDisabled:!0}),se()},pe=c=>{K({...c,isDisabled:!1})},De=c=>{F(c),q(!0)},ye=async c=>{g&&Q(g.id,c,ne)},Ce=()=>{q(!1),F(null),ne("")},oe=()=>{ee(!1),F(null)},se=()=>{te(!1),F(null)},he=e.createElement("a",{className:"external-link",href:"https://grafana.com/docs/grafana/latest/administration/service-accounts/",target:"_blank",rel:"noopener noreferrer"},"documentation."),Se=e.createElement("span",null,"Service accounts and their tokens can be used to authenticate against the Grafana API. Find out more in our"," ",he);return e.createElement(k.T,{navId:"serviceaccounts",subTitle:Se},e.createElement(k.T.Contents,null,e.createElement("div",{className:"page-action-bar"},e.createElement(m._,{grow:!0},e.createElement(C.H,{placeholder:"Search service account by name",value:S,onChange:me,width:50})),e.createElement(V.S,{options:[{label:"All",value:i.ServiceAccountStateFilter.All},{label:"With expired tokens",value:i.ServiceAccountStateFilter.WithExpiredTokens},{label:"Disabled",value:i.ServiceAccountStateFilter.Disabled}],onChange:ue,value:W,className:_.filter}),!ae&&r.Vt.hasPermission(i.AccessControlAction.ServiceAccountsCreate)&&e.createElement(d.Qj,{href:"org/serviceaccounts/create",variant:"primary"},"Add service account")),h&&e.createElement(z.Z,null),!h&&ae&&e.createElement(e.Fragment,null,e.createElement(R.Z,{title:"You haven't created any service accounts yet.",buttonIcon:"key-skeleton-alt",buttonLink:"org/serviceaccounts/create",buttonTitle:"Add service account",buttonDisabled:!r.Vt.hasPermission(i.AccessControlAction.ServiceAccountsCreate),proTip:"Remember, you can provide specific permissions for API access to other applications.",proTipLink:"",proTipLinkTitle:"",proTipTarget:"_blank"})),!h&&t.length!==0&&e.createElement(e.Fragment,null,e.createElement("div",{className:(0,a.cx)(_.table,"admin-list-table")},e.createElement("table",{className:"filter-table filter-table--hover"},e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null),e.createElement("th",null,"Account"),e.createElement("th",null,"ID"),e.createElement("th",null,"Roles"),e.createElement("th",null,"Tokens"),e.createElement("th",{style:{width:"34px"}}))),e.createElement("tbody",null,t.map(c=>e.createElement(N,{serviceAccount:c,key:c.id,roleOptions:w,onRoleChange:de,onRemoveButtonClick:Ee,onDisable:ve,onEnable:pe,onAddTokenClick:De})))))),g&&e.createElement(e.Fragment,null,e.createElement(P.s,{isOpen:ce,body:`Are you sure you want to delete '${g.name}'${g.tokens?` and ${g.tokens} accompanying ${y()("token",g.tokens)}`:""}?`,confirmText:"Delete",title:"Delete service account",onConfirm:ge,onDismiss:oe}),e.createElement(P.s,{isOpen:ie,title:"Disable service account",body:`Are you sure you want to disable '${g.name}'?`,confirmText:"Disable service account",onConfirm:fe,onDismiss:se}),e.createElement(f.m,{isOpen:le,token:re,serviceAccountLogin:g.login,onCreateToken:ye,onClose:Ce}))))},X=t=>({table:(0,a.css)`
      margin-top: ${t.spacing(3)};
    `,filter:(0,a.css)`
      margin: 0 ${t.spacing(1)};
    `,row:(0,a.css)`
      display: flex;
      align-items: center;
      height: 100% !important;

      a {
        padding: ${t.spacing(.5)} 0 !important;
      }
    `,unitTooltip:(0,a.css)`
      display: flex;
      flex-direction: column;
    `,unitItem:(0,a.css)`
      cursor: pointer;
      padding: ${t.spacing(.5)} 0;
      margin-right: ${t.spacing(1)};
    `,disabled:(0,a.css)`
      color: ${t.colors.text.disabled};
    `,link:(0,a.css)`
      color: inherit;
      cursor: pointer;
      text-decoration: underline;
    `,pageHeader:(0,a.css)`
      display: flex;
      margin-bottom: ${t.spacing(2)};
    `,apiKeyInfoLabel:(0,a.css)`
      margin-left: ${t.spacing(1)};
      line-height: 2.2;
      flex-grow: 1;
      color: ${t.colors.text.secondary};

      span {
        padding: ${t.spacing(.5)};
      }
    `,filterDelimiter:(0,a.css)`
      flex-grow: 1;
    `}),Z=j(M)},99442:(J,O,n)=>{n.d(O,{m:()=>z});var a=n(42844),o=n(27702),y=n(66117),e=n(34667),A=n(66310),v=n(13741),m=n(22209),C=n(1128),V=n(40705),d=n(37691),P=n(66670),R=n(71585);const k=[{label:"No expiration",value:!1},{label:"Set expiration date",value:!0}],z=({isOpen:f,token:p,serviceAccountLogin:s,onCreateToken:l,onClose:x})=>{const u=new Date;u.setDate(u.getDate()+1);const E=new Date;e.config.tokenExpirationDayLimit!==void 0&&e.config.tokenExpirationDayLimit>-1?E.setDate(E.getDate()+e.config.tokenExpirationDayLimit+1):E.setDate(864e13);const I=e.config.tokenExpirationDayLimit!==void 0&&e.config.tokenExpirationDayLimit>0,[$,N]=(0,o.useState)(""),[D,G]=(0,o.useState)(""),[B,j]=(0,o.useState)(I),[M,X]=(0,o.useState)(u),[Y,Z]=(0,o.useState)(M!==""),t=(0,A.wW)(i);(0,o.useEffect)(()=>{f&&N(`${s}-${(0,y.Z)()}`)},[s,f]);const h=T=>{Z(T!==""),X(T)},w=()=>{l({name:D||$,secondsToLive:B?r(M):void 0})},S=()=>{G(""),N(""),j(I),X(u),Z(M!==""),x()},W=p?"Service account token created":"Add service account token";return o.createElement(v.u,{isOpen:f,title:W,onDismiss:S,className:t.modal,contentClassName:t.modalContent},p?o.createElement(o.Fragment,null,o.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."},o.createElement("div",{className:t.modalTokenRow},o.createElement(C.I,{name:"tokenValue",value:p,readOnly:!0}),o.createElement(R.m,{className:t.modalCopyToClipboardButton,variant:"primary",size:"md",icon:"copy",getText:()=>p},"Copy clipboard"))),o.createElement(v.u.ButtonRow,null,o.createElement(R.m,{variant:"primary",getText:()=>p,onClipboardCopy:S},"Copy to clipboard and close"),o.createElement(P.zx,{variant:"secondary",onClick:S},"Close"))):o.createElement("div",null,o.createElement(m.g,{label:"Display name",description:"Name to easily identify the token",required:!0},o.createElement(C.I,{name:"tokenName",value:D,placeholder:$,onChange:T=>{G(T.currentTarget.value)}})),o.createElement(m.g,{label:"Expiration"},o.createElement(V.S,{options:k,value:B,onChange:j,size:"md"})),B&&o.createElement(m.g,{label:"Expiration date"},o.createElement(d.d,{onChange:h,value:M,placeholder:"",minDate:u,maxDate:E})),o.createElement(v.u.ButtonRow,null,o.createElement(P.zx,{onClick:w,disabled:B&&!Y},"Generate token"))))},r=f=>{const p=new Date(f),s=new Date;return Math.ceil((p.getTime()-s.getTime())/1e3)},i=f=>({modal:(0,a.css)`
      width: 550px;
    `,modalContent:(0,a.css)`
      overflow: visible;
    `,modalTokenRow:(0,a.css)`
      display: flex;
    `,modalCopyToClipboardButton:(0,a.css)`
      margin-left: ${f.spacing(.5)};
    `})},55765:(J,O,n)=>{n.d(O,{R5:()=>i,TL:()=>R,XE:()=>f,Xd:()=>d,bX:()=>V,fT:()=>z,yN:()=>k});var a=n(89949),o=n.n(a),y=n(73289),e=n(11349),A=n(91368),v=n(18771),m=n(21502);const C="/api/serviceaccounts";function V(){return async s=>{try{if(A.contextSrv.licensedAccessControlEnabled()&&A.contextSrv.hasPermission(v.AccessControlAction.ActionRolesList)){const l=await(0,e.ul)();s((0,m.Dn)(l))}}catch(l){console.error(l)}}}function d({withLoadingIndicator:s}={withLoadingIndicator:!1}){return async(l,x)=>{try{if(A.contextSrv.hasPermission(v.AccessControlAction.ServiceAccountsRead)){s&&l((0,m.pN)());const{perPage:u,page:E,query:I,serviceAccountStateFilter:$}=x().serviceAccounts,N=await(0,y.i)().get(`/api/serviceaccounts/search?perpage=${u}&page=${E}&query=${I}${r($)}&accesscontrol=true`);l((0,m.Ub)(N))}}catch(u){console.error(u)}finally{l((0,m.dt)())}}}const P=(0,a.debounce)(s=>s(d()),500,{leading:!0});function R(s){return async l=>{await(0,y.i)().patch(`${C}/${s.id}?accesscontrol=true`,{...s}),l(d())}}function k(s){return async l=>{await(0,y.i)().delete(`${C}/${s}`),l(d())}}function z(s,l,x){return async u=>{const E=await(0,y.i)().post(`${C}/${s}/tokens`,l);x(E.key),u(d())}}const r=s=>{switch(s){case v.ServiceAccountStateFilter.WithExpiredTokens:return"&expiredTokens=true";case v.ServiceAccountStateFilter.Disabled:return"&disabled=true";default:return""}};function i(s){return async l=>{l((0,m.aj)(s)),P(l)}}function f(s){return async l=>{l((0,m.M4)(s)),l(d())}}function p(s){return async l=>{l(pageChanged(s)),l(d())}}}}]);

//# sourceMappingURL=ServiceAccountsPage.3e0ccd9d867fa70f1bd1.js.map