Your IP : 216.73.216.52


Current Path : /snap/lxd/current/share/lxd-ui/assets/
Upload File :
Current File : //snap/lxd/current/share/lxd-ui/assets/NetworkAclDetail-CEuozOs0.js

import{u as T,au as k,d as o,v as S,r as b,c as w,H as v,j as e,s as E,z as L,x as N,R as x,f as O,h as B,a9 as Y,k as F,w as $,L as _,a6 as g,C as q,bm as H}from"./index-BsQN_SZU.js";import{R as M}from"./RenameHeader-BdCO5Nid.js";import{d as K,f as V,r as G,u as P}from"./network-acls-bpCzo6oH.js";import{G as j,Y as C}from"./NetworkFormMenu-jasNljC3.js";import{F as Q}from"./FormFooterLayout-CcbL_-PB.js";import{y as z,Y as J,o as W}from"./YamlSwitch-BStSXJFs.js";import{F as X}from"./FormSubmitBtn-DEfKgZu7.js";import{t as A,N as Z}from"./NetworkAclForm-DkZJlYVE.js";import{u as ee}from"./useNetworkAcls-Bl3lzJua.js";import"./SshKeyForm-BNz7yPwa.js";import"./limits-yeXZOxhv.js";import"./AutoExpandingTextArea-Bd-45rZK.js";import"./formFields-DzJouV_d.js";import"./scroll-Dc7Cgzms.js";import"./ProjectRichChip-DZzjTfq6.js";import"./ConfigFieldDescription-CjXKAIpa.js";import"./snapshots-LtzKNDw1.js";import"./formChangeCount-Kjdextdt.js";import"./UsedByRow-DlstYIKs.js";import"./UsedByItem-DYTdOZkC.js";import"./ExpandableList-DsGr0BpD.js";const R=()=>{const{isFineGrained:t}=T();return{canDeleteNetworkAcl:i=>k(t,"can_delete",i?.access_entitlements),canEditNetworkAcl:i=>k(t,"can_edit",i?.access_entitlements)}},te=({networkAcl:t,project:s})=>{const n=o.useNotify(),i=o.useToastNotification(),m=S(),[r,u]=b.useState(!1),p=w(),f=v(),{canDeleteNetworkAcl:c}=R(),a=()=>{u(!0),K(t.name,s).then(()=>{m.invalidateQueries({predicate:l=>l.queryKey[0]===N.projects&&l.queryKey[1]===s&&l.queryKey[2]===N.networkAcls}),p(`${x}/ui/project/${encodeURIComponent(s)}/network-acls`),i.success(e.jsxs(e.Fragment,{children:["Network ACL"," ",e.jsx(L,{bold:!0,type:"network-acl",value:t.name})," ","deleted."]}))}).catch(l=>{u(!1),n.failure("ACL deletion failed",l)})},h=(t.used_by?.length??0)>0,d=()=>c(t)?h?"Can not delete, ACL is currently in use":"":"You do not have permission to delete this ACL";return e.jsxs(o.ConfirmationButton,{onHoverText:d(),confirmationModalProps:{title:"Confirm delete",confirmButtonAppearance:"negative",confirmButtonLabel:"Delete",children:e.jsxs("p",{children:["Are you sure you want to delete the ACL"," ",e.jsx(L,{type:"network-acl",value:t.name,bold:!0}),"?",e.jsx("br",{}),"This action cannot be undone, and can result in data loss."]}),onConfirm:a},className:E("u-no-margin--bottom",{"has-icon":!f}),loading:r,disabled:!c(t)||h||r,shiftClickEnabled:!0,showShiftClickHint:!0,children:[!f&&e.jsx(o.Icon,{name:"delete"}),e.jsx("span",{children:"Delete ACL"})]})},se=({networkAcl:t,project:s})=>{const n=v(),i=o.useToastNotification(),m=()=>{V(t.name,s).then(r=>{const u=new Blob([r],{type:"text/plain"}),p=URL.createObjectURL(u),f=new Date().toISOString().replaceAll(":","-").split(".")[0],c=`${t.name}-${f}.log`,a=document.createElement("a");a.href=p,a.download=c,a.click(),window.URL.revokeObjectURL(p),i.success(e.jsxs(e.Fragment,{children:["Logs download for ACL"," ",e.jsx(L,{bold:!0,type:"network-acl",value:t.name})," ","started."]}))}).catch(r=>{i.failure(`Failed to download logs for ACL ${t.name}`,r)})};return e.jsxs(o.Button,{appearance:"",type:"button",onClick:m,hasIcon:!0,children:[!n&&e.jsx(o.Icon,{name:"begin-downloading"}),e.jsx("span",{children:"Download logs"})]})},ne=({name:t,networkAcl:s,project:n})=>{const i=w(),m=o.useNotify(),r=o.useToastNotification(),u=b.useState(null),{canEditNetworkAcl:p}=R(),f=O().shape({name:B().test("deduplicate","An ACL with this name already exists",async d=>s?.name===d||Y(d,n,u,"network-acls")).required("ACL name is required")}),c=F({initialValues:{name:t,isRenaming:!1},validationSchema:f,onSubmit:d=>{if(t===d.name){c.setFieldValue("isRenaming",!1),c.setSubmitting(!1);return}G(t,d.name,n).then(()=>{const l=`${x}/ui/project/${encodeURIComponent(n)}/network-acl/${encodeURIComponent(d.name)}`;i(l),r.success(e.jsxs(e.Fragment,{children:["Network ACL ",e.jsx("strong",{children:t})," renamed to"," ",e.jsx($,{type:"network-acl",value:d.name,to:l}),"."]})),c.setFieldValue("isRenaming",!1)}).catch(l=>{m.failure("Renaming failed",l)}).finally(()=>{c.setSubmitting(!1)})}}),a=(s?.used_by?.length??0)>0,h=()=>{if(!p(s))return"You do not have permission to rename this ACL";if(a)return"Can not rename, ACL is currently in use."};return e.jsx(M,{name:t,parentItems:[e.jsx(_,{to:`${x}/ui/project/${encodeURIComponent(n)}/network-acls`,children:"Network Access Control Lists"},1)],renameDisabledReason:h(),controls:s&&e.jsxs(e.Fragment,{children:[e.jsx(se,{networkAcl:s,project:n}),e.jsx(te,{networkAcl:s,project:n})]}),isLoaded:!!s,formik:c})},ae=({networkAcl:t,project:s})=>{const n=w(),i=o.useNotify(),m=o.useToastNotification(),[r,u]=b.useState(g(j)),{canEditNetworkAcl:p}=R(),f=S(),c={readOnly:!0,isCreating:!1,name:t.name,description:t.description,egress:t.egress,ingress:t.ingress,bareAcl:t,entityType:"network-acl",editRestriction:p(t)?void 0:"You do not have permission to edit this ACL"},a=F({initialValues:c,enableReinitialize:!0,onSubmit:y=>{const I=y.yaml?z(y.yaml):A(a.values,t);P(I,s).then(()=>{f.invalidateQueries({queryKey:[N.projects,s,N.networkAcls,t.name]}),m.success(e.jsxs(e.Fragment,{children:["Network ACL"," ",e.jsx($,{type:"network-acl",value:t.name,to:`${x}/ui/project/${encodeURIComponent(s)}/network-acl/${encodeURIComponent(t.name)}`})," ","updated."]}))}).catch(U=>{i.failure("ACL update failed",U)}).finally(()=>{a.setSubmitting(!1)})}}),h=`${x}/ui/project/${encodeURIComponent(s)}/network-acl/${encodeURIComponent(t.name)}`,d=y=>{n(y===j?h:`${h}/#${g(y)}`),u(g(y))},l=()=>{const y=A(a.values,t);return W(y)},D=a.values.readOnly;return e.jsxs(e.Fragment,{children:[e.jsx(Z,{formik:a,section:r,getYaml:l}),e.jsxs(Q,{children:[e.jsx(J,{formik:a,section:r,setSection:()=>{d(r===g(C)?j:C)}}),D?null:e.jsxs(e.Fragment,{children:[e.jsx(o.Button,{appearance:"base",onClick:()=>{a.setValues(c)},children:"Cancel"}),e.jsx(X,{formik:a,baseUrl:h,disabled:!1,isYaml:r===g(C)})]})]})]})},ke=()=>{const{name:t,project:s}=q();if(!t)return e.jsx(e.Fragment,{children:"Missing name"});if(!s)return e.jsx(e.Fragment,{children:"Missing project"});const{data:n,error:i,isLoading:m}=ee(t,s);return m?e.jsx(o.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0}):e.jsxs(o.CustomLayout,{header:e.jsx(ne,{networkAcl:n,project:s,name:t}),contentClassName:"edit-network-acl",children:[!m&&!n&&e.jsx(H,{entityType:"network-acl",entityName:t,errorMessage:i?.message}),!m&&n&&e.jsx(o.Row,{children:e.jsx(ae,{networkAcl:n,project:s})})]})};export{ke as default};