Your IP : 216.73.216.189


Current Path : /proc/thread-self/root/snap/lxd/current/share/lxd-ui/assets/
Upload File :
Current File : //proc/thread-self/root/snap/lxd/current/share/lxd-ui/assets/NetworkAclForm-Co7VPReH.js

import{k as B,j as e,d as s,H as A,I as M,r as R,a5 as E}from"./index-BFGypnt-.js";import{A as f}from"./AutoExpandingTextArea-WEdimI5c.js";import{e as x}from"./FormMenuItem-fhYfVpHc.js";import{Y as N}from"./NetworkFormMenu-CXUwfE9b.js";import{c as V}from"./YamlSwitch-BQqYYI1i.js";import{U as v}from"./UsedByRow-oKHc8A5r.js";const U=({direction:t,onClose:r,onAdd:i,editRule:c})=>{const l=B({initialValues:c||{protocol:"tcp",action:"allow",state:"enabled"},enableReinitialize:!0,onSubmit:o=>{i(o)}}),a=(o,p)=>e.jsxs("div",{className:"label acl-action-label",children:[e.jsx("span",{className:"name",children:o}),e.jsx("span",{className:"members u-text--muted",children:p})]});return e.jsx(s.Modal,{close:r,title:c?`Update ${t} rule`:`Add ${t} rule`,buttonRow:e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{className:"u-no-margin--bottom",onClick:r,children:"Cancel"}),e.jsx(s.Button,{appearance:"positive",className:"u-no-margin--bottom",onClick:l.submitForm,children:c?"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.CustomSelect,{id:"action",label:"Action",wrapperClassName:"select-input",dropdownClassName:"acl-action-dropdown",value:l.values.action,onChange:o=>{l.setFieldValue("action",o)},options:[{label:a("Allow","Accepts the traffic."),text:"Allow",value:"allow"},{label:a("Reject","Blocks the traffic and notifies sender."),text:"Reject",value:"reject"},{label:a("Drop","Blocks the traffic without response."),text:"Drop",value:"drop"}]}),e.jsx(s.Select,{id:"state",label:"State",options:[{label:"Enabled",value:"enabled"},{label:"Enabled (Logged)",value:"logged"},{label:"Disabled",value:"disabled"}],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:o=>{o.target.value!=="tcp"&&o.target.value!=="udp"&&(l.setFieldValue("source_port",void 0),l.setFieldValue("destination_port",void 0)),o.target.value!=="icmp4"&&o.target.value!=="icmp6"&&(l.setFieldValue("icmp_code",void 0),l.setFieldValue("icmp_type",void 0)),l.handleChange(o)},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")})]})]})})},S=({editRestriction:t,onEdit:r,onRemove:i,rules:c})=>{const l=(a,o)=>o?`${a??"*"}:${o}`:`${a??"*"}`;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:c.map((a,o)=>{const p=l(a.source,a.source_port),b=l(a.destination,a.destination_port);return{columns:[{content:A(a.action??""),role:"rowheader","aria-label":"Action"},{content:`${(a.protocol??"").length===0?"Any":a.protocol?.toUpperCase()}`,role:"cell","aria-label":"Protocol"},{content:A(a.state??""),role:"cell","aria-label":"State"},{content:a.description,role:"cell","aria-label":"Description"},{content:p,role:"cell","aria-label":"Source"},{content:b,role:"cell","aria-label":"Destination"},{content:e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{onClick:()=>{r(o)},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:()=>{i(o)},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:a.action,protocol:a.protocol,state:a.state,description:a.description,source:p,destination:b}}})})},T=({networkAcl:t})=>{const{project:r}=M();return r?e.jsx("table",{className:"network-acl-used-by-table",children:e.jsxs("tbody",{children:[e.jsx(v,{entityType:"instance",usedBy:t.used_by}),e.jsx(v,{entityType:"profile",usedBy:t.used_by}),e.jsx(v,{entityType:"network",usedBy:t.used_by})]})}):null},z=(t,r)=>{const i={name:t.name,description:t.description,egress:t.egress,ingress:t.ingress};return r?.config&&(i.config=r.config),i},q=({formik:t,getYaml:r,section:i})=>{const c=s.useNotify(),{openPortal:l,closePortal:a,isOpen:o,Portal:p}=s.usePortal(),[b,y]=R.useState(null),[m,F]=R.useState("ingress"),w=!t.values.isCreating,j=n=>n==="ingress"?t.values.ingress:t.values.egress,_=({index:n,...d})=>{const g=j(m);if(n===void 0)t.setFieldValue(m,[...g,d]);else{const u=[...g];u[n]=d,t.setFieldValue(m,u)}x(t),a(),y(null)},I=n=>{F(n),l()},C=(n,d)=>{const u=[...j(n)];u.splice(d,1),t.setFieldValue(n,u),x(t)},P=(n,d)=>{const u=j(n)[d];F(n),y({...u,index:d}),l()},D=()=>{a(),y(null)},h=!!t.values.editRestriction;return e.jsxs(e.Fragment,{children:[o&&e.jsx(p,{children:e.jsx(U,{onClose:D,onAdd:_,editRule:b,direction:m})}),e.jsx(s.ScrollableContainer,{dependencies:[c.notification],belowIds:["form-footer","status-bar"],children:e.jsxs(s.Form,{onSubmit:t.handleSubmit,children:[i!==E(N)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bare-inputs",children:[e.jsx(s.Input,{type:"submit",hidden:!0,value:"Hidden input"}),w?e.jsx(s.OutputField,{id:"name",label:"Name",value:t.values.name,help:"Click the name in the header to rename the network ACL."}):e.jsx(s.Input,{id:"name",type:"text",label:"Name",placeholder:"Enter name",required:!0,autoFocus:!0,disabled:h,title:t.values.editRestriction,...t.getFieldProps("name"),error:t.touched.name?t.errors.name:null}),e.jsx(f,{id:"description",name:"description",label:"Description",placeholder:"Enter description",onBlur:t.handleBlur,onChange:n=>{x(t),t.handleChange(n)},value:t.values.description,disabled:h,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(S,{rules:t.values.ingress,onRemove:n=>{C("ingress",n)},onEdit:n=>{P("ingress",n)},editRestriction:t.values.editRestriction})]}),e.jsx("div",{children:e.jsxs(s.Button,{hasIcon:!0,onClick:()=>{I("ingress")},type:"button",disabled:h,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(S,{rules:t.values.egress,onRemove:n=>{C("egress",n)},onEdit:n=>{P("egress",n)},editRestriction:t.values.editRestriction})]}),e.jsx("div",{children:e.jsxs(s.Button,{hasIcon:!0,onClick:()=>{I("egress")},type:"button",disabled:h,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})]})]}),i===E(N)&&e.jsx(V,{yaml:r(),setYaml:n=>{x(t),t.setFieldValue("yaml",n)},readOnly:h,readOnlyMessage:t.values.editRestriction})]})})]})};export{q as N,z as t};