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