/
snap
/
lxd
/
current
/
share
/
lxd-ui
/
assets
/
File Upload :
llllll
Current File: //snap/lxd/current/share/lxd-ui/assets/NetworkAclDetail-BD8R1T48.js
import{u as E,ah as S,d as i,l as F,r as j,c as R,y as k,j as e,v as $,n as b,q as N,f as T,g as B,Y as O,i as A,R as D,L as Y,V as x,p as q,e as _}from"./index-B3cgCbnJ.js";import{R as V}from"./RenameHeader-7HM7rJrm.js";import{d as H,f as K,r as M,u as G}from"./network-acls-BrbgJ988.js";import{G as C,Y as L}from"./NetworkFormMenu-BjwriKKk.js";import{F as Q}from"./FormFooterLayout-ChlQYZN0.js";import{y as P,c as z,o as J}from"./YamlSwitch-Bng19N-X.js";import{F as W}from"./FormSubmitBtn-CI9Q_IyH.js";import{t as v,N as X}from"./NetworkAclForm-Rp-Xe9Jc.js";import{u as Z}from"./useNetworkAcls-n0o7vmIP.js";import"./FormMenuItem-BwEOqt61.js";import"./limits-CLEFMbq-.js";import"./AutoExpandingTextArea-BmFqLvbw.js";import"./scroll-BEbDVMxI.js";import"./instanceOptions-D4bz_1Ev.js";import"./ConfigFieldDescription-C9KDhW5s.js";import"./snapshots-Bt9cFkFc.js";import"./ExpandableList-DwC4iUKg.js";import"./UsedByItem-BtsI6fTe.js";const w=()=>{const{isFineGrained:t}=E();return{canDeleteNetworkAcl:n=>S(t,"can_delete",n==null?void 0:n.access_entitlements),canEditNetworkAcl:n=>S(t,"can_edit",n==null?void 0:n.access_entitlements)}},ee=({networkAcl:t,project:s})=>{var l;const a=i.useNotify(),n=i.useToastNotification(),u=F(),[r,m]=j.useState(!1),f=R(),p=k(),{canDeleteNetworkAcl:c}=w(),o=()=>{m(!0),H(t.name,s).then(()=>{u.invalidateQueries({predicate:d=>d.queryKey[0]===N.projects&&d.queryKey[1]===s&&d.queryKey[2]===N.networkAcls}),f(`/ui/project/${encodeURIComponent(s)}/network-acls`),n.success(e.jsxs(e.Fragment,{children:["Network ACL"," ",e.jsx(b,{bold:!0,type:"network-acl",value:t.name})," ","deleted."]}))}).catch(d=>{m(!1),a.failure("ACL deletion failed",d)})},h=(((l=t.used_by)==null?void 0:l.length)??0)>0,g=()=>c(t)?h?"Can not delete, ACL is currently in use":"":"You do not have permission to delete this ACL";return e.jsxs(i.ConfirmationButton,{onHoverText:g(),confirmationModalProps:{title:"Confirm delete",confirmButtonAppearance:"negative",confirmButtonLabel:"Delete",children:e.jsxs("p",{children:["Are you sure you want to delete the ACL"," ",e.jsx(b,{type:"network-acl",value:t.name,bold:!0}),"?",e.jsx("br",{}),"This action cannot be undone, and can result in data loss."]}),onConfirm:o},className:$("u-no-margin--bottom",{"has-icon":!p}),loading:r,disabled:!c(t)||h||r,shiftClickEnabled:!0,showShiftClickHint:!0,children:[!p&&e.jsx(i.Icon,{name:"delete"}),e.jsx("span",{children:"Delete ACL"})]})},te=({networkAcl:t,project:s})=>{const a=k(),n=i.useToastNotification(),u=()=>{K(t.name,s).then(r=>{const m=new Blob([r],{type:"text/plain"}),f=URL.createObjectURL(m),p=new Date().toISOString().replaceAll(":","-").split(".")[0],c=`${t.name}-${p}.log`,o=document.createElement("a");o.href=f,o.download=c,o.click(),window.URL.revokeObjectURL(f),n.success(e.jsxs(e.Fragment,{children:["Logs download for ACL"," ",e.jsx(b,{bold:!0,type:"network-acl",value:t.name})," ","started."]}))}).catch(r=>{n.failure(`Failed to download logs for ACL ${t.name}`,r)})};return e.jsxs(i.Button,{appearance:"",type:"button",onClick:u,hasIcon:!0,children:[!a&&e.jsx(i.Icon,{name:"begin-downloading"}),e.jsx("span",{children:"Download logs"})]})},se=({name:t,networkAcl:s,project:a})=>{var g;const n=R(),u=i.useNotify(),r=i.useToastNotification(),m=j.useState(null),{canEditNetworkAcl:f}=w(),p=T().shape({name:B().test("deduplicate","An ACL with this name already exists",async l=>(s==null?void 0:s.name)===l||O(l,a,m,"network-acls")).required("ACL name is required")}),c=A({initialValues:{name:t,isRenaming:!1},validationSchema:p,onSubmit:l=>{if(t===l.name){c.setFieldValue("isRenaming",!1),c.setSubmitting(!1);return}M(t,l.name,a).then(()=>{const d=`/ui/project/${encodeURIComponent(a)}/network-acl/${encodeURIComponent(l.name)}`;n(d),r.success(e.jsxs(e.Fragment,{children:["Network ACL ",e.jsx("strong",{children:t})," renamed to"," ",e.jsx(D,{type:"network-acl",value:l.name,to:d}),"."]})),c.setFieldValue("isRenaming",!1)}).catch(d=>{u.failure("Renaming failed",d)}).finally(()=>{c.setSubmitting(!1)})}}),o=(((g=s==null?void 0:s.used_by)==null?void 0:g.length)??0)>0,h=()=>{if(!f(s))return"You do not have permission to rename this ACL";if(o)return"Can not rename, ACL is currently in use."};return e.jsx(V,{name:t,parentItems:[e.jsx(Y,{to:`/ui/project/${encodeURIComponent(a)}/network-acls`,children:"Network ACLs"},1)],renameDisabledReason:h(),controls:s&&e.jsxs(e.Fragment,{children:[e.jsx(te,{networkAcl:s,project:a}),e.jsx(ee,{networkAcl:s,project:a})]}),isLoaded:!!s,formik:c})},ne=({networkAcl:t,project:s})=>{const a=R(),n=i.useNotify(),u=i.useToastNotification(),[r,m]=j.useState(x(C)),{canEditNetworkAcl:f}=w(),p=F(),c={readOnly:!0,isCreating:!1,name:t.name,description:t.description,egress:t.egress,ingress:t.ingress,bareAcl:t,entityType:"network-acl",editRestriction:f(t)?void 0:"You do not have permission to edit this ACL"},o=A({initialValues:c,enableReinitialize:!0,onSubmit:y=>{const I=y.yaml?P(y.yaml):v(o.values,t);G(I,s).then(()=>{p.invalidateQueries({queryKey:[N.projects,s,N.networkAcls,t.name]}),u.success(e.jsxs(e.Fragment,{children:["Network ACL"," ",e.jsx(D,{type:"network-acl",value:t.name,to:`/ui/project/${encodeURIComponent(s)}/network-acl/${encodeURIComponent(t.name)}`})," ","updated."]}))}).catch(U=>{n.failure("ACL update failed",U)}).finally(()=>{o.setSubmitting(!1)})}}),h=`/ui/project/${encodeURIComponent(s)}/network-acl/${encodeURIComponent(t.name)}`,g=y=>{a(y===C?h:`${h}/#${x(y)}`),m(x(y))},l=()=>{const y=v(o.values,t);return J(y)},d=o.values.readOnly;return e.jsxs(e.Fragment,{children:[e.jsx(X,{formik:o,section:r,getYaml:l}),e.jsxs(Q,{children:[e.jsx(z,{formik:o,section:r,setSection:()=>{g(r===x(L)?C:L)}}),d?null:e.jsxs(e.Fragment,{children:[e.jsx(i.Button,{appearance:"base",onClick:()=>{o.setValues(c)},children:"Cancel"}),e.jsx(W,{formik:o,baseUrl:h,disabled:!1,isYaml:r===x(L)})]})]})]})},Le=()=>{const t=i.useNotify(),{name:s,project:a}=q();if(!s)return e.jsx(e.Fragment,{children:"Missing name"});if(!a)return e.jsx(e.Fragment,{children:"Missing project"});const{data:n,error:u,isLoading:r}=Z(s,a);return j.useEffect(()=>{u&&t.failure("Loading ACL failed",u)},[u]),r?e.jsx(i.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0}):e.jsx(i.CustomLayout,{header:e.jsx(se,{networkAcl:n,project:a,name:s}),contentClassName:"edit-network-acl",children:e.jsxs(i.Row,{children:[e.jsx(_,{}),n&&e.jsx(ne,{networkAcl:n,project:a})]})})};export{Le as default};
Copyright ©2k19 -
Hexid
|
Tex7ure