| Current Path : /snap/lxd/38768/share/lxd-ui/assets/ |
| Current File : //snap/lxd/38768/share/lxd-ui/assets/StorageBucketDetail-3f6oIuMe.js |
import{j as e,L as q,R as A,H as M,S as C,d as a,r as N,v,z as L,x as h,T as S,w as B,ec as w,ax as $,P as H,b2 as Q,p as E,b3 as U,f as V,h as Y,el as z,k as R,C as _,bm as O}from"./index-BsQN_SZU.js";import{e as J,u as D,f as G,g as W,a as X,h as Z,i as ee,j as te,k as ae,E as se}from"./EditStorageBucketPanel-CAwD6Ilg.js";import{R as ne}from"./RenameHeader-BdCO5Nid.js";import{S as oe}from"./SelectableMainTable-DBx4rRiq.js";import{S as re}from"./SelectedTableNotification-BpePAhdG.js";import{u as ie}from"./useSortTableData-DkMx8bMp.js";import{u as le}from"./projects-CczQ3aFg.js";import{u as K,p as F}from"./usePanelParams-CNAJZsSX.js";import{B as ce}from"./BulkDeleteButton-DbqPCHnz.js";import{u as de}from"./useBulkDetails-ydqvQ5wa.js";import{A as ue}from"./AutoExpandingTextArea-Bd-45rZK.js";import"./StoragePoolSelector-Bvqvds5t.js";import"./StoragePoolSize-BNbqTfwA.js";import"./Meter-cq8smrSm.js";import"./DiskSizeSelector-C9kWj54D.js";import"./limits-yeXZOxhv.js";const me=({bucket:t,project:s})=>e.jsx(ne,{name:t.name,parentItems:[e.jsx(q,{to:`${A}/ui/project/${encodeURIComponent(s)}/storage/buckets`,children:"Storage buckets"},1)],controls:t?e.jsx(J,{bucket:t,isDetailPage:!0}):null,isLoaded:!0,renameDisabledReason:"Storage buckets cannot be renamed"}),T=({className:t})=>{const s=M(),{canCreateStorageBuckets:i}=le(),{project:r}=C(),n=K();return e.jsxs(a.Button,{appearance:"positive",hasIcon:!s,onClick:()=>{n.openCreateStorageBucketKey(r?.name||"")},className:t,disabled:!i(r),title:i(r)?"Create bucket key":"You do not have permission to create keys for this bucket",children:[!s&&e.jsx(a.Icon,{name:"plus",light:!0}),e.jsx("span",{children:"Create key"})]})},pe=({bucket:t,bucketKey:s})=>{const i=a.useNotify(),[r,n]=N.useState(!1),u=v(),{canEditBucket:d}=D(),{project:p}=C(),c=p?.name||"",y=a.useToastNotification(),x=()=>{y.success(e.jsxs(e.Fragment,{children:["Key ",e.jsx(L,{bold:!0,type:"bucket-key",value:s.name})," ","deleted for storage bucket"," ",e.jsx(L,{bold:!0,type:"bucket",value:t.name}),"."]}))},m=()=>{n(!0),G(t.name,s.name,t.pool,c).then(x).catch(l=>{i.failure("Key deletion failed",l)}).finally(()=>{n(!1),u.invalidateQueries({queryKey:[h.storage,t.pool,p?.name??"",h.buckets,t.name,h.keys]})})};return e.jsx(a.ConfirmationButton,{loading:r,confirmationModalProps:{title:"Confirm delete",children:e.jsxs("p",{children:["This will permanently delete key"," ",e.jsx(L,{type:"bucket-key",value:s.name,bold:!0}),".",e.jsx("br",{}),"This action cannot be undone, and can result in data loss."]}),confirmButtonLabel:"Delete",onConfirm:m},appearance:"base",className:"has-icon",shiftClickEnabled:!0,showShiftClickHint:!0,disabled:!d(t),onHoverText:d(t)?"Delete key":"You do not have permission to delete this key.",children:e.jsx(a.Icon,{name:"delete"})})},ye=({bucket:t,bucketKey:s})=>{const i=K(),{canEditBucket:r}=D();return e.jsx(a.Button,{className:"has-icon",appearance:"base",hasIcon:!0,onClick:()=>{i.openEditStorageBucketKey(s.name)},title:r(t)?"Edit bucket key":"You do not have permission to edit this bucket key",children:e.jsx(a.Icon,{name:"edit"})})},ge=({bucketKey:t,bucket:s})=>{const i=[e.jsx(ye,{bucketKey:t,bucket:s},"edit"),e.jsx(pe,{bucketKey:t,bucket:s},"delete")];return e.jsx(a.List,{inline:!0,className:"u-no-margin--bottom actions-list",items:i})},he=({keys:t,bucket:s,onStart:i,onFinish:r})=>{const n=a.useToastNotification(),u=v(),[d,p]=N.useState(!1),c=de(),{project:y}=C(),x=y?.name||"",m=t.length,l=`Delete ${t.length} ${S("key",t.length)}`,k=()=>{p(!0),i();const g=e.jsxs(e.Fragment,{children:[t.length," ",S("key",t.length)," deleted for bucket"," ",e.jsx(B,{type:"bucket",value:s.name,to:w(s.name,s.pool,y?.name??"")}),"."]});W(s,t,x).then(j=>{const{fulfilledCount:f,rejectedCount:o}=$(j);f===m?n.success(g,c(j)):o===m?n.failure("Key bulk deletion failed",void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:m})," ",S("key",m)," could not be deleted."]}),c(j)):n.failure("Key bulk deletion partially failed",void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:f})," ",S("key",f)," ","deleted.",e.jsx("br",{}),e.jsx("b",{children:o})," ",S("key",o)," could not be deleted."]}),c(j)),u.invalidateQueries({queryKey:[h.storage,s.pool,y?.name??"",h.buckets,s.name,h.keys]}),p(!1),r()}).catch(j=>{p(!1),n.failure(`Key bulk deletion failed for storage bucket ${s.name}`,j)})};return e.jsx(ce,{entities:t,deletableEntities:t,entityType:"key",onDelete:k,disabledReason:m===0?`You do not have permission to delete the selected ${S("key",t.length)}`:void 0,confirmationButtonProps:{disabled:d||m===0,loading:d},buttonLabel:l})},je=({bucket:t})=>{const[s,i]=N.useState(""),r=a.useNotify(),[n,u]=N.useState([]),[d,p]=N.useState([]),{project:c}=C(),{data:y=[]}=X(t,c?.name??"");N.useEffect(()=>{const o=new Set(y?.map(P=>P.name)),b=n.filter(P=>o.has(P));b.length!==n.length&&u(b)},[y]);const x=y?.filter(o=>{if(s){const b=s.toLowerCase();return o.name.toLowerCase().includes(b)||o.role.toLowerCase().includes(b)||o.description.toLowerCase().includes(b)||o["access-key"].toLowerCase().includes(b)||o["secret-key"].toLowerCase().includes(b)}return!0})??[],m=y&&y.length>0,l=[{content:"Name",sortKey:"name",className:"name"},{content:"Role",sortKey:"role",className:"role"},{content:"Description",sortKey:"description",className:"description"},{content:"Access key",className:"key-field",sortKey:"access-key"},{content:"Secret key",className:"key-field",sortKey:"secret-key"},{"aria-label":"Actions",className:"actions"}],k=x.map(o=>({key:o.name,className:"u-row",name:o.name,columns:[{content:e.jsx("div",{className:"u-truncate",title:`Key ${o.name}`,children:e.jsx(Q,{item:o})}),role:"rowheader","aria-label":"Name",className:"name"},{content:H(o.role),role:"cell","aria-label":"Role",className:"role"},{content:o.description||"-",title:o.description,role:"cell","aria-label":"Description",className:"description u-truncate"},{content:o["access-key"],role:"cell","aria-label":"Access key",className:"key-field"},{content:o["secret-key"],role:"cell","aria-label":"Secret key",className:"key-field"},{content:e.jsx(ge,{bucketKey:o,bucket:t}),role:"cell","aria-label":"Actions",className:"u-align--right actions"}],sortData:{name:o.name.toLowerCase(),role:o.role,description:o.description.toLowerCase(),"access-key":o["access-key"],"secret-key":o["secret-key"]}})),g=y.filter(o=>n.includes(o.name)),{rows:j,updateSort:f}=ie({rows:k,defaultSort:"name",defaultSortDirection:"ascending"});return e.jsxs("div",{className:"storage-bucket-key-list",children:[m&&e.jsx("div",{className:"upper-controls-bar",children:n.length===0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"search-box-wrapper",children:e.jsx(a.SearchBox,{name:"search-snapshot",className:"search-box margin-right",type:"text",onChange:o=>{i(o)},placeholder:"Search for keys",value:s,"aria-label":"Search for keys"})}),e.jsx(T,{})]}):e.jsx("div",{className:"p-panel__controls",children:e.jsx(he,{keys:g,bucket:t,onStart:()=>{p(n)},onFinish:()=>{p([])}})})}),e.jsx(E,{}),m?e.jsx(e.Fragment,{children:e.jsx(a.ScrollableTable,{dependencies:[x,r.notification],tableId:"buckets-key-table",belowIds:["status-bar"],children:e.jsx(a.TablePagination,{data:j,id:"pagination",itemName:"key",className:"u-no-margin--top","aria-label":"Table pagination control",description:n.length>0&&e.jsx(re,{totalCount:y?.length??0,itemName:"key",parentName:"bucket",selectedNames:n,setSelectedNames:u,filteredNames:x.map(o=>o.name)}),children:e.jsx(oe,{id:"buckets-key-table",headers:l,rows:j,sortable:!0,emptyStateMsg:"No key found matching this search",itemName:"key",parentName:"bucket",selectedNames:n,setSelectedNames:u,disabledNames:d,filteredNames:x.map(o=>o.name),onUpdateSort:f,defaultSort:"name",defaultSortDirection:"ascending",responsive:!0})})})}):e.jsxs(a.EmptyState,{className:"empty-state",image:e.jsx(a.Icon,{name:"private-key",className:"empty-state-icon"}),title:"No keys",children:[e.jsx("p",{children:"This storage bucket does not contain any keys."}),e.jsx("p",{children:e.jsx(U,{docPath:"/howto/storage_buckets/#manage-storage-bucket-keys",hasExternalIcon:!0,children:"Learn how to manage storage bucket keys"})}),e.jsx(T,{})]})]})},I=({formik:t,bucket:s})=>{const{canEditBucket:i}=D(),r=d=>({id:d,name:d,onBlur:t.handleBlur,onChange:t.handleChange,value:t.values[d]??"",error:t.touched[d]?t.errors[d]:null,placeholder:`Enter ${d.replaceAll("-"," ")}`}),n=!!s,u=!n||i(s)?"":"You do not have permission to edit this bucket";return e.jsxs(a.Form,{onSubmit:t.handleSubmit,className:"bucket-create-form",children:[e.jsx(a.Input,{type:"submit",hidden:!0,value:"Hidden input"}),e.jsx(a.Input,{...r("name"),type:"text",label:"Name",required:!0,autoFocus:!0,disabled:!!u||n,title:u}),e.jsx(a.Select,{id:"bucketKey",label:"Role",onChange:d=>{t.setFieldValue("role",d.target.value)},value:t.values.role,options:[{label:"Admin",value:"admin"},{label:"Read-only",value:"read-only"}]}),e.jsx(ue,{...r("description"),label:"Description",disabled:!!u,title:u}),e.jsx(a.Input,{...r("access-key"),type:"text",label:"Access Key",disabled:!!u,title:u}),e.jsx(a.Input,{...r("secret-key"),type:"text",label:"Secret Key",disabled:!!u,title:u})]})},xe=({bucket:t})=>{const s=K(),{project:i}=C(),r=a.useNotify(),n=a.useToastNotification(),u=v(),d=N.useState(null),p=()=>{s.clear(),r.clear()},c=w(t.name,t.pool,i?.name??""),y=V().shape({name:Y().test(...z(s.project,t,d)).required("Key name is required")}),x=l=>{n.success(e.jsxs(e.Fragment,{children:["Key ",e.jsx(B,{type:"bucket-key",value:l,to:c})," ","created for storage bucket"," ",e.jsx(B,{type:"bucket",value:t.name,to:c}),"."]})),p()},m=R({initialValues:{name:"",role:"read-only"},validationSchema:y,onSubmit:l=>{const k={name:l.name,role:l.role,description:l.description,"access-key":l["access-key"],"secret-key":l["secret-key"]};Z(JSON.stringify(k),s.project,t.pool,t.name).then(()=>{u.invalidateQueries({queryKey:[h.storage,t.pool,s.project,h.buckets,t.name,h.keys]}),x(l.name)}).catch(g=>{m.setSubmitting(!1),r.failure("Key creation failed",g)})}});return e.jsx(e.Fragment,{children:e.jsxs(a.SidePanel,{children:[e.jsx(a.SidePanel.Header,{children:e.jsx(a.SidePanel.HeaderTitle,{children:"Create key"})}),e.jsx(E,{className:"u-no-padding"}),e.jsx(a.SidePanel.Content,{className:"u-no-padding",children:e.jsx(a.ScrollableContainer,{dependencies:[r.notification],belowIds:["panel-footer"],children:e.jsx(I,{formik:m})})}),e.jsxs(a.SidePanel.Footer,{className:"u-align--right",children:[e.jsx(a.Button,{appearance:"base",onClick:p,className:"u-no-margin--bottom",children:"Cancel"}),e.jsx(a.ActionButton,{appearance:"positive",loading:m.isSubmitting,onClick:()=>{m.submitForm()},className:"u-no-margin--bottom",disabled:!m.isValid||m.isSubmitting||!m.values.name,children:"Create key"})]})]})})},ke=({bucket:t})=>{const s=K(),{project:i,key:r}=s,n=a.useNotify(),u=a.useToastNotification(),d=v(),p=()=>{s.clear(),n.clear()},{data:c,error:y,isLoading:x}=ee(t,r??"",i),m=g=>{const j=w(g.name,g.pool,i);u.success(e.jsxs(e.Fragment,{children:["Key"," ",e.jsx(B,{type:"bucket-key",value:c?.name??"",to:j})," ","updated for storage bucket"," ",e.jsx(B,{type:"bucket",value:g?.name??"",to:j}),"."]})),p()},l=R({initialValues:{name:c?.name??"",role:c?.role,description:c?.description,"access-key":c?.["access-key"]??"","secret-key":c?.["secret-key"]??""},enableReinitialize:!0,onSubmit:g=>{const j={name:g.name,role:g.role,description:g.description,"access-key":g["access-key"],"secret-key":g["secret-key"]};te(t.name,j,t.pool,i||"").then(()=>{d.invalidateQueries({queryKey:[h.storage,t.pool,i,h.buckets,t.name,h.keys]}),d.invalidateQueries({queryKey:[h.storage,t.pool,i,h.buckets,t.name,h.keys,c?.name]}),m(t)}).catch(f=>{l.setSubmitting(!1),n.failure("Key update failed",f)})}});if(!i)return e.jsx(e.Fragment,{children:"Missing project"});if(!r)return e.jsx(e.Fragment,{children:"Missing key"});if(y&&n.failure("Loading key failed",y),x)return e.jsx(a.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0});if(!c)return e.jsx(e.Fragment,{children:"Loading key failed"});const k=(l.values.description!==c.description?1:0)+(l.values.role!==c.role?1:0)+(l.values["access-key"]!==c["access-key"]?1:0)+(l.values["secret-key"]!==c["secret-key"]?1:0);return e.jsx(e.Fragment,{children:e.jsxs(a.SidePanel,{children:[e.jsx(a.SidePanel.Header,{children:e.jsxs(a.SidePanel.HeaderTitle,{children:["Edit key ",c.name]})}),e.jsx(E,{className:"u-no-padding"}),e.jsx(a.SidePanel.Content,{className:"u-no-padding",children:e.jsx(a.ScrollableContainer,{dependencies:[n.notification],belowIds:["panel-footer"],children:e.jsx(I,{formik:l,bucket:t})})}),e.jsxs(a.SidePanel.Footer,{className:"u-align--right",children:[e.jsx(a.Button,{appearance:"base",onClick:p,className:"u-no-margin--bottom",children:"Cancel"}),e.jsx(a.ActionButton,{appearance:"positive",loading:l.isSubmitting,onClick:()=>{l.submitForm()},className:"u-no-margin--bottom",disabled:!l.isValid||l.isSubmitting||k===0,children:k===0?"Save changes":`Save ${k} ${S("change",k)}`})]})]})})},Ie=()=>{const{pool:t,project:s,member:i,bucket:r}=_();if(!t)return e.jsx(e.Fragment,{children:"Missing storage pool"});if(!s)return e.jsx(e.Fragment,{children:"Missing project"});if(!r)return e.jsx(e.Fragment,{children:"Missing bucket"});const{data:n,error:u,isLoading:d}=ae(r,t,s,i),p=K();return d?e.jsx(a.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0}):n?e.jsxs(e.Fragment,{children:[e.jsx(a.CustomLayout,{header:e.jsx(me,{bucket:n,project:s}),contentClassName:"detail-page u-no-padding--bottom",children:e.jsx(a.Row,{children:e.jsx(je,{bucket:n})})}),p.panel===F.editStorageBucket&&e.jsx(se,{bucket:n}),p.panel===F.createStorageBucketKey&&e.jsx(xe,{bucket:n}),p.panel===F.editStorageBucketKey&&e.jsx(ke,{bucket:n})]}):e.jsx(O,{entityType:"bucket",entityName:r,errorMessage:u?.message})};export{Ie as default};