"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[3082],{13464:(re,h,a)=>{a.r(h),a.d(h,{ApiKeysPageUnconnected:()=>M,MigrationSummary:()=>S,default:()=>ae});var e=a(27702),k=a(27173),E=a(64022),f=a(48024),b=a(42074),A=a(13741),p=a(66670),g=a(44644),v=a(66574),F=a(6327),x=a(18771),N=a(33716);const R=({searchQuery:t,disabled:n,onSearchChange:l})=>e.createElement("div",{className:"page-action-bar"},e.createElement(f._,{grow:!0},e.createElement(N.H,{placeholder:"Search keys",value:t,onChange:l})));var m=a(42844),I=a(60956),K=a(66310),B=a(80011),Q=a(73453),L=a(15202);const $=({apiKeys:t,timeZone:n,onDelete:l,onMigrate:s})=>{const o=(0,K.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=!!(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:!v.Vt.hasPermissionInMetadata(x.AccessControlAction.ActionAPIKeysDelete,r)}))))})):null)};function z(t,n){return n?(0,I.dq)(n,{timeZone:t}):"Never"}function O(t,n){return t?(0,I.dq)(t,{timeZone:n}):"No expiration date"}const j=t=>({tableRow:n=>(0,m.css)`
    color: ${n?t.colors.text.secondary:t.colors.text.primary};
  `,tooltipContainer:(0,m.css)`
    margin-left: ${t.spacing(1)};
  `});var P=a(63439),V=a(3613);const U=({onMigrate:t,apikeysCount:n,disabled:l})=>{const[s,o]=(0,e.useState)(!1),i=(0,K.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(P.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(P.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:(0,m.css)`
    margin-bottom: ${t.spacing(2)};
  `,actionRow:(0,m.css)`
    display: flex;
    align-items: center;
  `,actionButton:(0,m.css)`
    margin-right: ${t.spacing(2)};
  `});var u=a(45937),d=a(59273);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=v.Vt.hasAccess(x.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 C={navId:"apikeys"},te={loadApiKeys:y,deleteApiKey:Z,migrateApiKey:H,migrateAll:J,setSearchQuery:d.ql,toggleIncludeExpired:Y},ne=(0,k.connect)(ee,te);class M 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:w}=this.props;if(!n)return e.createElement(g.T,{...C},e.createElement(g.T.Contents,{isLoading:!0}));const T=l>0;return e.createElement(g.T,{...C},e.createElement(g.T.Contents,{isLoading:!1},e.createElement(e.Fragment,null,e.createElement(U,{onMigrate:this.onMigrateApiKeys,apikeysCount:l}),T?e.createElement(R,{searchQuery:o,disabled:!le,onSearchChange:this.onSearchQueryChange}):null,T?e.createElement(E.wc,null,e.createElement(f._,{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)),w&&e.createElement(S,{visible:this.state.showMigrationResult,data:w,onDismiss:this.dismissModal}))}}const D={migrationSummary:{padding:"20px"},infoText:{color:"#007bff"},summaryDetails:{marginTop:"20px"},summaryParagraph:{margin:"10px 0"}},S=({visible:t,data:n,onDismiss:l})=>e.createElement(A.u,{title:"Migration summary",isOpen:t,closeOnBackdropClick:!0,onDismiss:l},n.failedApikeyIDs.length===0&&e.createElement("div",{style:D.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:D.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(A.u.ButtonRow,null,e.createElement(p.zx,{variant:"secondary",onClick:l},"Close"))),ae=ne(M)}}]);

//# sourceMappingURL=ApiKeysPage.21ac181955f203c61a0b.js.map