"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[3082],{91948:(re,h,a)=>{a.r(h),a.d(h,{ApiKeysPageUnconnected:()=>C,MigrationSummary:()=>D,default:()=>ae});var e=a(66111),T=a(67948),E=a(52081),k=a(81764),b=a(8944),f=a(35029),p=a(31403),g=a(8412),A=a(77582),F=a(25405),v=a(27876),N=a(14747);const R=({searchQuery:t,disabled:n,onSearchChange:l})=>e.createElement("div",{className:"page-action-bar"},e.createElement("div",{className:"gf-form gf-form--grow"},e.createElement(N.H,{placeholder:"Search keys",value:t,onChange:l})));var m=a(9892),x=a(77258),I=a(72648),B=a(61860),Q=a(39904),L=a(13626);const $=({apiKeys:t,timeZone:n,onDelete:l,onMigrate:s})=>{const o=(0,I.l4)(),i=j(o);return e.createElement("table",{className:"filter-table"},e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null,"Name"),e.createElement("th",null,"Role"),e.createElement("th",null,"Expires"),e.createElement("th",null,"Last used at"),e.createElement("th",{style:{width:"34px"}}))),t.length>0?e.createElement("tbody",null,t.map(r=>{const c=Boolean(r.expiration&&Date.now()>new Date(r.expiration).getTime());return e.createElement("tr",{key:r.id,className:i.tableRow(c)},e.createElement("td",null,r.name),e.createElement("td",null,r.role),e.createElement("td",null,O(r.expiration,n),c&&e.createElement("span",{className:i.tooltipContainer},e.createElement(B.u,{content:"This API key has expired."},e.createElement(Q.J,{name:"exclamation-triangle"})))),e.createElement("td",null,z(n,r.lastUsedAt)),e.createElement("td",null,e.createElement(E.Lh,{justify:"flex-end"},e.createElement(p.zx,{size:"sm",onClick:()=>s(r)},"Migrate to service account"),e.createElement(L.m,{"aria-label":"Delete API key",size:"sm",onConfirm:()=>l(r),disabled:!A.Vt.hasPermissionInMetadata(v.AccessControlAction.ActionAPIKeysDelete,r)}))))})):null)};function z(t,n){return n?(0,x.dq)(n,{timeZone:t}):"Never"}function O(t,n){return t?(0,x.dq)(t,{timeZone:n}):"No expiration date"}const j=t=>({tableRow:n=>m.css`
    color: ${n?t.colors.text.secondary:t.colors.text.primary};
  `,tooltipContainer:m.css`
    margin-left: ${t.spacing(1)};
  `});var K=a(45253),V=a(98102);const U=({onMigrate:t,apikeysCount:n,disabled:l})=>{const[s,o]=(0,e.useState)(!1),i=(0,I.wW)(W),r=e.createElement("a",{className:"external-link",href:"https://grafana.com/docs/grafana/latest/administration/api-keys/#migrate-api-keys-to-grafana-service-accounts",target:"_blank",rel:"noopener noreferrer"},"Find out more about the migration here."),c=e.createElement("span",null,"Migrating all API keys will hide the API keys tab.",e.createElement("br",null),e.createElement("br",null),"The API keys API will remain available for you to create new API keys, but we strongly encourage you to use Service accounts instead.");return e.createElement(e.Fragment,null,n>0&&e.createElement(K.b,{title:"Switch from API keys to service accounts",severity:"warning"},e.createElement("div",{className:i.text},"We will soon deprecate API keys. Each API key will be migrated into a service account with a token and will continue to work as they were. We encourage you to migrate your API keys to service accounts now. ",r),e.createElement("div",{className:i.actionRow},e.createElement(p.zx,{className:i.actionButton,onClick:()=>o(!0)},"Migrate all service accounts"),e.createElement(V.s,{title:"Migrate API keys to Service accounts",isOpen:s,body:c,confirmText:"Yes, migrate now",onConfirm:t,onDismiss:()=>o(!1),confirmVariant:"primary",confirmButtonVariant:"primary"}))),n===0&&e.createElement(e.Fragment,null,e.createElement(K.b,{title:"No API keys found",severity:"warning"},e.createElement("div",{className:i.text},"No API keys were found. If you reload the browser, this tab will be not available. If any API keys are created, this tab will appear again."))))},W=t=>({text:m.css`
    margin-bottom: ${t.spacing(2)};
  `,actionRow:m.css`
    display: flex;
    align-items: center;
  `,actionButton:m.css`
    margin-right: ${t.spacing(2)};
  `});var u=a(29930),d=a(56777);function y(){return async t=>{t((0,d.dF)());const[n,l]=await Promise.all([(0,u.i)().get("/api/auth/keys?includeExpired=false&accesscontrol=true"),(0,u.i)().get("/api/auth/keys?includeExpired=true&accesscontrol=true")]);t((0,d.iK)({keys:n,keysIncludingExpired:l}))}}function Z(t){return async n=>{(0,u.i)().delete(`/api/auth/keys/${t}`).then(()=>n(y()))}}function H(t){return async n=>{try{await(0,u.i)().post(`/api/serviceaccounts/migrate/${t}`)}finally{n(y())}}}function J(){return async t=>{try{const n=await(0,u.i)().post("/api/serviceaccounts/migrate");t((0,d.nQ)(n))}finally{t(y())}}}function Y(){return t=>{t((0,d.j4)())}}const G=t=>t.includeExpired?t.keysIncludingExpired.length:t.keys.length,X=t=>{const n=RegExp(t.searchQuery,"i");return(t.includeExpired?t.keysIncludingExpired:t.keys).filter(s=>n.test(s.name)||n.test(s.role))},q=t=>t.includeExpired,_=t=>t.keys.length===0&&t.keysIncludingExpired.length>0;function ee(t){const n=A.Vt.hasAccess(v.AccessControlAction.ActionAPIKeysCreate,!0);return{apiKeys:X(t.apiKeys),searchQuery:t.apiKeys.searchQuery,apiKeysCount:G(t.apiKeys),hasFetched:t.apiKeys.hasFetched,timeZone:(0,F.Z)(t.user),includeExpired:q(t.apiKeys),includeExpiredDisabled:_(t.apiKeys),canCreate:n,migrationResult:t.apiKeys.migrationResult}}const P={navId:"apikeys"},te={loadApiKeys:y,deleteApiKey:Z,migrateApiKey:H,migrateAll:J,setSearchQuery:d.ql,toggleIncludeExpired:Y},ne=(0,T.connect)(ee,te);class C extends e.PureComponent{constructor(n){super(n),this.onDeleteApiKey=l=>{this.props.deleteApiKey(l.id)},this.onMigrateApiKey=l=>{this.props.migrateApiKey(l.id)},this.onSearchQueryChange=l=>{this.props.setSearchQuery(l)},this.onIncludeExpiredChange=l=>{this.props.toggleIncludeExpired()},this.onMigrateApiKeys=async()=>{try{await this.props.migrateAll(),this.setState({showMigrationResult:!0})}catch(l){console.error(l)}},this.dismissModal=async()=>{this.setState({showMigrationResult:!1})},this.state={showMigrationResult:!1}}componentDidMount(){this.fetchApiKeys()}async fetchApiKeys(){await this.props.loadApiKeys()}render(){const{hasFetched:n,apiKeysCount:l,apiKeys:s,searchQuery:o,timeZone:i,includeExpired:r,includeExpiredDisabled:c,canCreate:le,migrationResult:S}=this.props;if(!n)return e.createElement(g.T,{...P},e.createElement(g.T.Contents,{isLoading:!0}));const w=l>0;return e.createElement(g.T,{...P},e.createElement(g.T.Contents,{isLoading:!1},e.createElement(e.Fragment,null,e.createElement(U,{onMigrate:this.onMigrateApiKeys,apikeysCount:l}),w?e.createElement(R,{searchQuery:o,disabled:!le,onSearchChange:this.onSearchQueryChange}):null,w?e.createElement(E.wc,null,e.createElement(k._,{disabled:c,label:"Include expired keys"},e.createElement(b.x,{id:"showExpired",value:r,onChange:this.onIncludeExpiredChange})),e.createElement($,{apiKeys:s,timeZone:i,onMigrate:this.onMigrateApiKey,onDelete:this.onDeleteApiKey})):null)),S&&e.createElement(D,{visible:this.state.showMigrationResult,data:S,onDismiss:this.dismissModal}))}}const M={migrationSummary:{padding:"20px"},infoText:{color:"#007bff"},summaryDetails:{marginTop:"20px"},summaryParagraph:{margin:"10px 0"}},D=({visible:t,data:n,onDismiss:l})=>e.createElement(f.u,{title:"Migration summary",isOpen:t,closeOnBackdropClick:!0,onDismiss:l},n.failedApikeyIDs.length===0&&e.createElement("div",{style:M.migrationSummary},e.createElement("p",null,"Migration Successful!"),e.createElement("p",null,e.createElement("strong",null,"Total: "),n.total),e.createElement("p",null,e.createElement("strong",null,"Migrated: "),n.migrated)),n.failedApikeyIDs.length!==0&&e.createElement("div",{style:M.migrationSummary},e.createElement("p",null,"Migration Complete! Please note, while there might be a few API keys flagged as `failed migrations`, rest assured, all of your API keys are fully functional and operational. Please try again or contact support."),e.createElement("hr",null),e.createElement("p",null,e.createElement("strong",null,"Total: "),n.total),e.createElement("p",null,e.createElement("strong",null,"Migrated: "),n.migrated),e.createElement("p",null,e.createElement("strong",null,"Failed: "),n.failed),e.createElement("p",null,e.createElement("strong",null,"Failed Api Key IDs: "),n.failedApikeyIDs.join(", ")),e.createElement("p",null,e.createElement("strong",null,"Failed Details: "),n.failedDetails.join(", "))),e.createElement(f.u.ButtonRow,null,e.createElement(p.zx,{variant:"secondary",onClick:l},"Close"))),ae=ne(C)}}]);

//# sourceMappingURL=ApiKeysPage.c5807a11f68ff55d0bfd.js.map