"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[4196],{9699:(le,u,n)=>{n.r(u),n.d(u,{ApiKeysPageUnconnected:()=>C,MigrationSummary:()=>E,default:()=>ae});var e=n(74848),x=n(96540),D=n(71468),m=n(14186),T=n(15292),k=n(69529),j=n(37390),p=n(55852),f=n(21780),A=n(10096),w=n(8484),F=n(32901),v=n(31678),N=n(67647);const R=({searchQuery:s,disabled:t,onSearchChange:i})=>(0,e.jsx)("div",{className:"page-action-bar",children:(0,e.jsx)(m.I,{grow:!0,children:(0,e.jsx)(N.Z,{placeholder:"Search keys",value:s,onChange:i})})});var d=n(32196),I=n(72724),K=n(40845),b=n(56034),B=n(14578),$=n(67061),Q=n(91605);const L=({apiKeys:s,timeZone:t,onDelete:i,onMigrate:r})=>{const l=(0,K.$j)(),o=z(l);return(0,e.jsxs)("table",{className:"filter-table",children:[(0,e.jsx)("thead",{children:(0,e.jsxs)("tr",{children:[(0,e.jsx)("th",{children:"Name"}),(0,e.jsx)("th",{children:"Role"}),(0,e.jsx)("th",{children:"Expires"}),(0,e.jsx)("th",{children:"Last used at"}),(0,e.jsx)("th",{style:{width:"34px"}})]})}),s.length>0?(0,e.jsx)("tbody",{children:s.map(a=>{const c=!!(a.expiration&&Date.now()>new Date(a.expiration).getTime());return(0,e.jsxs)("tr",{className:o.tableRow(c),children:[(0,e.jsx)("td",{children:a.name}),(0,e.jsx)("td",{children:a.role}),(0,e.jsxs)("td",{children:[W(a.expiration,t),c&&(0,e.jsx)("span",{className:o.tooltipContainer,children:(0,e.jsx)(b.m,{content:"This API key has expired.",children:(0,e.jsx)(B.I,{name:"exclamation-triangle"})})})]}),(0,e.jsx)("td",{children:O(t,a.lastUsedAt)}),(0,e.jsx)("td",{children:(0,e.jsxs)($.B,{justifyContent:"flex-end",children:[(0,e.jsx)(p.$n,{size:"sm",onClick:()=>r(a),children:"Migrate to service account"}),(0,e.jsx)(Q.e,{"aria-label":"Delete API key",size:"sm",onConfirm:()=>i(a),disabled:!A.TP.hasPermissionInMetadata(v.AccessControlAction.ActionAPIKeysDelete,a)})]})})]},a.id)})}):null]})};function O(s,t){return t?(0,I.LE)(t,{timeZone:s}):"Never"}function W(s,t){return s?(0,I.LE)(s,{timeZone:t}):"No expiration date"}const z=s=>({tableRow:t=>(0,d.css)`
    color: ${t?s.colors.text.secondary:s.colors.text.primary};
  `,tooltipContainer:(0,d.css)`
    margin-left: ${s.spacing(1)};
  `});var P=n(42418),U=n(96374);const V=({onMigrate:s,apikeysCount:t,disabled:i})=>{const[r,l]=(0,x.useState)(!1),o=(0,K.of)(Y),a=(0,e.jsx)("a",{className:"external-link",href:"https://grafana.com/docs/grafana/latest/administration/service-accounts/migrate-api-keys/)",target:"_blank",rel:"noopener noreferrer",children:"Find out more about the migration here."}),c=(0,e.jsxs)("span",{children:["Migrating all API keys will hide the API keys tab.",(0,e.jsx)("br",{}),(0,e.jsx)("br",{}),"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(0,e.jsxs)(e.Fragment,{children:[t>0&&(0,e.jsxs)(P.F,{title:"Switch from API keys to service accounts",severity:"warning",children:[(0,e.jsxs)("div",{className:o.text,children:["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. ",a]}),(0,e.jsxs)("div",{className:o.actionRow,children:[(0,e.jsx)(p.$n,{className:o.actionButton,onClick:()=>l(!0),children:"Migrate all service accounts"}),(0,e.jsx)(U.u,{title:"Migrate API keys to Service accounts",isOpen:r,body:c,confirmText:"Yes, migrate now",onConfirm:s,onDismiss:()=>l(!1),confirmVariant:"primary",confirmButtonVariant:"primary"})]})]}),t===0&&(0,e.jsx)(e.Fragment,{children:(0,e.jsx)(P.F,{title:"No API keys found",severity:"warning",children:(0,e.jsx)("div",{className:o.text,children:"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."})})})]})},Y=s=>({text:(0,d.css)`
    margin-bottom: ${s.spacing(2)};
  `,actionRow:(0,d.css)`
    display: flex;
    align-items: center;
  `,actionButton:(0,d.css)`
    margin-right: ${s.spacing(2)};
  `});var h=n(27677),g=n(93584);function y(){return async s=>{s((0,g.h8)());const[t,i]=await Promise.all([(0,h.AI)().get("/api/auth/keys?includeExpired=false&accesscontrol=true"),(0,h.AI)().get("/api/auth/keys?includeExpired=true&accesscontrol=true")]);s((0,g.Sf)({keys:t,keysIncludingExpired:i}))}}function Z(s){return async t=>{(0,h.AI)().delete(`/api/auth/keys/${s}`).then(()=>t(y()))}}function G(s){return async t=>{try{await(0,h.AI)().post(`/api/serviceaccounts/migrate/${s}`)}finally{t(y())}}}function H(){return async s=>{try{const t=await(0,h.AI)().post("/api/serviceaccounts/migrate");s((0,g.QB)(t))}finally{s(y())}}}function J(){return s=>{s((0,g.cV)())}}const X=s=>s.includeExpired?s.keysIncludingExpired.length:s.keys.length,q=s=>{const t=RegExp(s.searchQuery,"i");return(s.includeExpired?s.keysIncludingExpired:s.keys).filter(r=>t.test(r.name)||t.test(r.role))},_=s=>s.includeExpired,ee=s=>s.keys.length===0&&s.keysIncludingExpired.length>0;function se(s){const t=A.TP.hasPermission(v.AccessControlAction.ActionAPIKeysCreate);return{apiKeys:q(s.apiKeys),searchQuery:s.apiKeys.searchQuery,apiKeysCount:X(s.apiKeys),hasFetched:s.apiKeys.hasFetched,timeZone:(0,F.O)(s.user),includeExpired:_(s.apiKeys),includeExpiredDisabled:ee(s.apiKeys),canCreate:t,migrationResult:s.apiKeys.migrationResult}}const te={navId:"apikeys"},ne={loadApiKeys:y,deleteApiKey:Z,migrateApiKey:G,migrateAll:H,setSearchQuery:g.Ri,toggleIncludeExpired:J},ie=(0,D.connect)(se,ne);class C extends x.PureComponent{constructor(t){super(t),this.onDeleteApiKey=i=>{this.props.deleteApiKey(i.id)},this.onMigrateApiKey=i=>{this.props.migrateApiKey(i.id)},this.onSearchQueryChange=i=>{this.props.setSearchQuery(i)},this.onIncludeExpiredChange=i=>{this.props.toggleIncludeExpired()},this.onMigrateApiKeys=async()=>{try{await this.props.migrateAll(),this.setState({showMigrationResult:!0})}catch(i){console.error(i)}},this.dismissModal=async()=>{this.setState({showMigrationResult:!1})},this.state={showMigrationResult:!1}}componentDidMount(){this.fetchApiKeys()}async fetchApiKeys(){await this.props.loadApiKeys()}render(){const{hasFetched:t,apiKeysCount:i,apiKeys:r,searchQuery:l,timeZone:o,includeExpired:a,includeExpiredDisabled:c,canCreate:re,migrationResult:S}=this.props,oe=i>0;return(0,e.jsxs)(f.YW,{...te,children:[(0,e.jsxs)(f.YW.Contents,{isLoading:!t,children:[(0,e.jsx)(V,{onMigrate:this.onMigrateApiKeys,apikeysCount:i}),oe?(0,e.jsx)(R,{searchQuery:l,disabled:!re,onSearchChange:this.onSearchQueryChange}):null,(0,e.jsx)(m.I,{disabled:c,label:"Include expired keys",children:(0,e.jsx)(T.K,{id:"showExpired",value:a,onChange:this.onIncludeExpiredChange})}),r.length>0?(0,e.jsx)(L,{apiKeys:r,timeZone:o,onMigrate:this.onMigrateApiKey,onDelete:this.onDeleteApiKey}):(0,e.jsx)(k.p,{variant:"not-found",message:(0,w.t)("api-keys.empty-state.message","No API keys found")})]}),S&&(0,e.jsx)(E,{visible:this.state.showMigrationResult,data:S,onDismiss:this.dismissModal})]})}}const M={migrationSummary:{padding:"20px"},infoText:{color:"#007bff"},summaryDetails:{marginTop:"20px"},summaryParagraph:{margin:"10px 0"}},E=({visible:s,data:t,onDismiss:i})=>(0,e.jsxs)(j.a,{title:"Migration summary",isOpen:s,closeOnBackdropClick:!0,onDismiss:i,children:[t.failedApikeyIDs.length===0&&(0,e.jsxs)("div",{style:M.migrationSummary,children:[(0,e.jsx)("p",{children:"Migration Successful!"}),(0,e.jsxs)("p",{children:[(0,e.jsx)("strong",{children:"Total: "}),t.total]}),(0,e.jsxs)("p",{children:[(0,e.jsx)("strong",{children:"Migrated: "}),t.migrated]})]}),t.failedApikeyIDs.length!==0&&(0,e.jsxs)("div",{style:M.migrationSummary,children:[(0,e.jsx)("p",{children:"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."}),(0,e.jsx)("hr",{}),(0,e.jsxs)("p",{children:[(0,e.jsx)("strong",{children:"Total: "}),t.total]}),(0,e.jsxs)("p",{children:[(0,e.jsx)("strong",{children:"Migrated: "}),t.migrated]}),(0,e.jsxs)("p",{children:[(0,e.jsx)("strong",{children:"Failed: "}),t.failed]}),(0,e.jsxs)("p",{children:[(0,e.jsx)("strong",{children:"Failed Api Key IDs: "}),t.failedApikeyIDs.join(", ")]}),(0,e.jsxs)("p",{children:[(0,e.jsx)("strong",{children:"Failed Details: "}),t.failedDetails.join(", ")]})]}),(0,e.jsx)(j.a.ButtonRow,{children:(0,e.jsx)(p.$n,{variant:"secondary",onClick:i,children:"Close"})})]}),ae=ie(C)}}]);

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