/
snap
/
lxd
/
current
/
share
/
lxd-ui
/
assets
/
File Upload :
llllll
Current File: //snap/lxd/current/share/lxd-ui/assets/NetworkAclDetail-BihAfR4i.js
import{u as E,af as S,d as i,l as F,r as j,c as R,x as k,j as e,t as $,m 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,o as q,e as _}from"./index-dL2n30-Z.js";import{R as V}from"./RenameHeader-BZc6vaTG.js";import{d as H,f as K,r as M,u as G}from"./network-acls-DIVFiLIx.js";import{G as C,Y as L}from"./NetworkFormMenu-BKrf9oEV.js";import{F as Q}from"./FormFooterLayout-Bmq4RXkd.js";import{y as P,c as z,o as J}from"./YamlSwitch-BRMLXARm.js";import{F as W}from"./FormSubmitBtn-D3jUuO6-.js";import{t as v,N as X}from"./NetworkAclForm-Dr-zuoOV.js";import{u as Z}from"./useNetworkAcls-ySbcb7T6.js";import"./FormMenuItem-DRePjRCl.js";import"./limits-CLEFMbq-.js";import"./AutoExpandingTextArea-CQuEMXHF.js";import"./scroll-Dmr9Jl9h.js";import"./instanceOptions-D4bz_1Ev.js";import"./ConfigFieldDescription-B5-bOr1x.js";import"./ScrollableTable-CQDmfMtz.js";import"./snapshots-AS6hXv2C.js";import"./ScrollableContainer-ceiHesUW.js";import"./ExpandableList-Cjp4v1_P.js";import"./UsedByItem-Ber64JUd.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 o=i.useNotify(),n=i.useToastNotification(),m=F(),[r,u]=j.useState(!1),f=R(),p=k(),{canDeleteNetworkAcl:c}=w(),a=()=>{u(!0),H(t.name,s).then(()=>{m.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=>{u(!1),o.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:a},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 o=k(),n=i.useToastNotification(),m=()=>{K(t.name,s).then(r=>{const u=new Blob([r],{type:"text/plain"}),f=URL.createObjectURL(u),p=new Date().toISOString().replaceAll(":","-").split(".")[0],c=`${t.name}-${p}.log`,a=document.createElement("a");a.href=f,a.download=c,a.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:m,hasIcon:!0,children:[!o&&e.jsx(i.Icon,{name:"begin-downloading"}),e.jsx("span",{children:"Download logs"})]})},se=({name:t,networkAcl:s,project:o})=>{var g;const n=R(),m=i.useNotify(),r=i.useToastNotification(),u=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,o,u,"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,o).then(()=>{const d=`/ui/project/${encodeURIComponent(o)}/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=>{m.failure("Renaming failed",d)}).finally(()=>{c.setSubmitting(!1)})}}),a=(((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(a)return"Can not rename, ACL is currently in use."};return e.jsx(V,{name:t,parentItems:[e.jsx(Y,{to:`/ui/project/${encodeURIComponent(o)}/network-acls`,children:"Network ACLs"},1)],renameDisabledReason:h(),controls:s&&e.jsxs(e.Fragment,{children:[e.jsx(te,{networkAcl:s,project:o}),e.jsx(ee,{networkAcl:s,project:o})]}),isLoaded:!!s,formik:c})},ne=({networkAcl:t,project:s})=>{const o=R(),n=i.useNotify(),m=i.useToastNotification(),[r,u]=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"},a=A({initialValues:c,enableReinitialize:!0,onSubmit:y=>{const I=y.yaml?P(y.yaml):v(a.values,t);G(I,s).then(()=>{p.invalidateQueries({queryKey:[N.projects,s,N.networkAcls,t.name]}),m.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(()=>{a.setSubmitting(!1)})}}),h=`/ui/project/${encodeURIComponent(s)}/network-acl/${encodeURIComponent(t.name)}`,g=y=>{o(y===C?h:`${h}/#${x(y)}`),u(x(y))},l=()=>{const y=v(a.values,t);return J(y)},d=a.values.readOnly;return e.jsxs(e.Fragment,{children:[e.jsx(X,{formik:a,section:r,getYaml:l}),e.jsxs(Q,{children:[e.jsx(z,{formik:a,section:r,setSection:()=>{g(r===x(L)?C:L)}}),d?null:e.jsxs(e.Fragment,{children:[e.jsx(i.Button,{appearance:"base",onClick:()=>{a.setValues(c)},children:"Cancel"}),e.jsx(W,{formik:a,baseUrl:h,disabled:!1,isYaml:r===x(L)})]})]})]})},Re=()=>{const t=i.useNotify(),{name:s,project:o}=q();if(!s)return e.jsx(e.Fragment,{children:"Missing name"});if(!o)return e.jsx(e.Fragment,{children:"Missing project"});const{data:n,error:m,isLoading:r}=Z(s,o);return j.useEffect(()=>{m&&t.failure("Loading ACL failed",m)},[m]),r?e.jsx(i.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0}):e.jsx(i.CustomLayout,{header:e.jsx(se,{networkAcl:n,project:o,name:s}),contentClassName:"edit-network-acl",children:e.jsxs(i.Row,{children:[e.jsx(_,{}),n&&e.jsx(ne,{networkAcl:n,project:o})]})})};export{Re as default};
Copyright ©2k19 -
Hexid
|
Tex7ure