| Current Path : /snap/lxd/38450/share/lxd-ui/assets/ |
| Current File : //snap/lxd/38450/share/lxd-ui/assets/NetworkAclForm-DkZJlYVE.js |
import{k as M,j as e,d as s,P as R,C as B,r as A,a6 as S}from"./index-BsQN_SZU.js";import{A as w}from"./AutoExpandingTextArea-Bd-45rZK.js";import{J as x,l as U}from"./SshKeyForm-BNz7yPwa.js";import{Y as E}from"./NetworkFormMenu-jasNljC3.js";import{U as j}from"./UsedByRow-DlstYIKs.js";const V=({direction:t,onClose:a,onAdd:r,editRule:i})=>{const l=M({initialValues:i||{protocol:"tcp",action:"allow",state:"enabled"},enableReinitialize:!0,onSubmit:n=>{r(n)}});return e.jsx(s.Modal,{close:a,title:i?`Update ${t} rule`:`Add ${t} rule`,buttonRow:e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{className:"u-no-margin--bottom",onClick:a,children:"Cancel"}),e.jsx(s.Button,{appearance:"positive",className:"u-no-margin--bottom",onClick:l.submitForm,children:i?"Update rule":"Add rule"})]}),children:e.jsxs(s.Form,{onSubmit:l.handleSubmit,children:[e.jsx(s.Input,{type:"submit",hidden:!0,value:"Hidden input"}),e.jsx(s.Select,{id:"action",label:"Action",options:[{label:"Allow",value:"allow"},{label:"Reject",value:"reject"},{label:"Drop",value:"drop"}],...l.getFieldProps("action")}),e.jsx(s.Select,{id:"state",label:"State",options:[{label:"Enabled",value:"enabled"},{label:"Disabled",value:"disabled"},{label:"Logged",value:"logged"}],help:"Possible values are enabled, disabled, and logged.",...l.getFieldProps("state")}),e.jsx(s.Input,{id:"description",label:"Description",type:"text",placeholder:"Enter description",...l.getFieldProps("description")}),e.jsx(s.Select,{id:"protocol",label:"Protocol",options:[{label:"Any",value:""},{label:"ICMP4",value:"icmp4"},{label:"ICMP6",value:"icmp6"},{label:"TCP",value:"tcp"},{label:"UDP",value:"udp"}],onBlur:l.handleBlur,onChange:n=>{n.target.value!=="tcp"&&n.target.value!=="udp"&&(l.setFieldValue("source_port",void 0),l.setFieldValue("destination_port",void 0)),n.target.value!=="icmp4"&&n.target.value!=="icmp6"&&(l.setFieldValue("icmp_code",void 0),l.setFieldValue("icmp_type",void 0)),l.handleChange(n)},value:l.values.protocol}),e.jsx(s.Input,{id:"source",label:"Source",placeholder:"Enter source",type:"text",help:"Sources can be specified as CIDR or IP ranges, source subject name selectors (for ingress rules), or be left empty for any.",...l.getFieldProps("source")}),["tcp","udp"].includes(l.values.protocol??"")&&e.jsx(s.Input,{id:"source_port",label:"Source port",placeholder:"Enter source port",type:"text",help:"Specify a comma-separated list of ports or port ranges (start-end inclusive), or leave the value empty for any.",...l.getFieldProps("source_port")}),e.jsx(s.Input,{id:"destination",label:"Destination",placeholder:"Enter destination",type:"text",help:"Destinations can be specified as CIDR or IP ranges, destination subject name selectors (for egress rules), or be left empty for any.",...l.getFieldProps("destination")}),["tcp","udp"].includes(l.values.protocol??"")&&e.jsx(s.Input,{id:"destination_port",label:"Destination port",placeholder:"Enter destination port",type:"text",help:"Specify a comma-separated list of ports or port ranges (start-end inclusive), or leave the value empty for any.",...l.getFieldProps("destination_port")}),["icmp4","icmp6"].includes(l.values.protocol??"")&&e.jsxs(e.Fragment,{children:[e.jsx(s.Input,{id:"icmp_code",label:"ICMP code",placeholder:"Enter ICMP code",type:"text",help:"Specify the ICMP code number, or leave the value empty for any.",...l.getFieldProps("icmp_code")}),e.jsx(s.Input,{id:"icmp_type",label:"ICMP type",placeholder:"Enter ICMP type",type:"text",help:"Specify the ICMP type number, or leave the value empty for any.",...l.getFieldProps("icmp_type")})]})]})})},_=({editRestriction:t,onEdit:a,onRemove:r,rules:i})=>{const l=(n,c)=>c?`${n??"*"}:${c}`:`${n??"*"}`;return e.jsx(s.MainTable,{sortable:!0,headers:[{content:"Action",sortKey:"action"},{content:"Protocol",sortKey:"protocol"},{content:"State",sortKey:"state"},{content:"Description",sortKey:"description"},{content:"Source",sortKey:"source"},{content:"Destination",sortKey:"destination"},{content:""}],rows:i.map((n,c)=>{const h=l(n.source,n.source_port),b=l(n.destination,n.destination_port);return{columns:[{content:R(n.action??""),role:"rowheader","aria-label":"Action"},{content:`${(n.protocol??"").length===0?"Any":n.protocol?.toUpperCase()}`,role:"cell","aria-label":"Protocol"},{content:R(n.state??""),role:"cell","aria-label":"State"},{content:n.description,role:"cell","aria-label":"Description"},{content:h,role:"cell","aria-label":"Source"},{content:b,role:"cell","aria-label":"Destination"},{content:e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{onClick:()=>{a(c)},dense:!0,type:"button",hasIcon:!0,appearance:"base",disabled:!!t,title:"Edit rule"+(t?` - ${t}`:""),children:e.jsx(s.Icon,{name:"edit"})}),e.jsx(s.Button,{onClick:()=>{r(c)},dense:!0,type:"button",hasIcon:!0,appearance:"base",disabled:!!t,title:"Remove rule"+(t?` - ${t}`:""),children:e.jsx(s.Icon,{name:"delete"})})]}),role:"cell",className:"actions u-align--right"}],sortData:{action:n.action,protocol:n.protocol,state:n.state,description:n.description,source:h,destination:b}}})})},T=({networkAcl:t})=>{const{project:a}=B();return a?e.jsx("table",{className:"network-acl-used-by-table",children:e.jsxs("tbody",{children:[e.jsx(j,{entityType:"instance",usedBy:t.used_by}),e.jsx(j,{entityType:"profile",usedBy:t.used_by}),e.jsx(j,{entityType:"network",usedBy:t.used_by})]})}):null},Y=(t,a)=>{const r={name:t.name,description:t.description,egress:t.egress,ingress:t.ingress};return a?.config&&(r.config=a.config),r},z=({formik:t,getYaml:a,section:r})=>{const i=s.useNotify(),{openPortal:l,closePortal:n,isOpen:c,Portal:h}=s.usePortal(),[b,m]=A.useState(null),[g,F]=A.useState("ingress"),v=o=>o==="ingress"?t.values.ingress:t.values.egress,N=({index:o,...d})=>{const y=v(g);if(o===void 0)t.setFieldValue(g,[...y,d]);else{const u=[...y];u[o]=d,t.setFieldValue(g,u)}x(t),n(),m(null)},P=o=>{F(o),l()},I=(o,d)=>{const u=[...v(o)];u.splice(d,1),t.setFieldValue(o,u),x(t)},C=(o,d)=>{const u=v(o)[d];F(o),m({...u,index:d}),l()},D=()=>{n(),m(null)},p=!!t.values.editRestriction;return e.jsxs(e.Fragment,{children:[c&&e.jsx(h,{children:e.jsx(V,{onClose:D,onAdd:N,editRule:b,direction:g})}),e.jsx(s.ScrollableContainer,{dependencies:[i.notification],belowIds:["form-footer","status-bar"],children:e.jsxs(s.Form,{onSubmit:t.handleSubmit,children:[r!==S(E)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bare-inputs",children:[e.jsx(s.Input,{type:"submit",hidden:!0,value:"Hidden input"}),e.jsx(s.Input,{id:"name",type:"text",label:"Name",placeholder:"Enter name",required:!0,autoFocus:!0,disabled:!t.values.isCreating||p,title:t.values.editRestriction,help:t.values.isCreating?"":"Click the ACL name in the header to rename the ACL",...t.getFieldProps("name"),error:t.touched.name?t.errors.name:null}),e.jsx(w,{id:"description",name:"description",label:"Description",placeholder:"Enter description",onBlur:t.handleBlur,onChange:o=>{x(t),t.handleChange(o)},value:t.values.description,disabled:p,title:t.values.editRestriction})]}),t.values.ingress.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"p-heading--4",children:"Ingress rules"}),e.jsx(_,{rules:t.values.ingress,onRemove:o=>{I("ingress",o)},onEdit:o=>{C("ingress",o)},editRestriction:t.values.editRestriction})]}),e.jsx("div",{children:e.jsxs(s.Button,{hasIcon:!0,onClick:()=>{P("ingress")},type:"button",disabled:p,title:t.values.editRestriction,children:[e.jsx(s.Icon,{name:"plus"}),e.jsx("span",{children:"Add ingress rule"})]})}),t.values.egress.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"p-heading--4",children:"Egress rules"}),e.jsx(_,{rules:t.values.egress,onRemove:o=>{I("egress",o)},onEdit:o=>{C("egress",o)},editRestriction:t.values.editRestriction})]}),e.jsx("div",{children:e.jsxs(s.Button,{hasIcon:!0,onClick:()=>{P("egress")},type:"button",disabled:p,title:t.values.editRestriction,children:[e.jsx(s.Icon,{name:"plus"}),e.jsx("span",{children:"Add egress rule"})]})}),t.values.bareAcl?.used_by&&e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"p-heading--4",children:"Used by"}),e.jsx(T,{networkAcl:t.values.bareAcl})]})]}),r===S(E)&&e.jsx(U,{yaml:a(),setYaml:o=>{x(t),t.setFieldValue("yaml",o)},readOnly:p,readOnlyMessage:t.values.editRestriction})]})})]})};export{z as N,Y as t};