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/CertificateAdd-WcUVcX-t.js

import{b as L,u as p,c as k,j as e,d as t,R as l,A as g,e as F,r as f,f as R,h as E,k as G,i as j,N as h,l as B,m as I,n as $,o as M,p as _}from"./index-BFGypnt-.js";import{G as q}from"./GroupSelection-sYtH6Ve5.js";import{u as z}from"./useAuthGroups-3GAYR02a.js";import{N as P}from"./NameWithGroupForm-D6xMGnkA.js";import{C as W}from"./CodeSnippetWithCopyButton-DAE09ff3.js";import"./PermissionGroupsFilter-BWepc9mD.js";import"./SelectableMainTable-BZaSR8Vv.js";import"./useSortTableData-DMPSUVcX.js";const C=()=>{const{data:r}=L(),{authMethod:a}=p(),o=r?.client_certificate,i=a===g.BEARER,d=k();return e.jsxs(e.Fragment,{children:[!i&&e.jsx(t.Notification,{title:"Identity trust token",severity:"information",children:"In order for your browser certificate to be added to the server’s trust store, you must present an identity trust token generated by the server."}),i&&e.jsx(t.Notification,{title:"TLS identity",severity:"information",children:"Confirm the name and auth groups for your permanent access."}),o===!1&&e.jsx(t.Notification,{severity:"caution",title:"Missing client certificate",actions:[{label:"Go back to step 1",onClick:()=>{d(`${l}/ui/login/certificate-generate`)}}],children:"You are missing an installed client certificate. You may not be able to authenticate."})]})},D=()=>{const{isAuthenticated:r,isAuthLoading:a,authMethod:o}=p(),i=t.useNotify(),d=k(),{data:u=[],error:y}=z(),{data:x=[],error:b}=F(),v=o===g.BEARER,w=f.useCallback(n=>{const c=x.map(S=>S.name);if(!c.includes(n))return n;let m=2;for(;c.includes(`${n}-${m}`);)m++;return`${n}-${m}`},[x]),N=f.useMemo(()=>u.find(c=>c.name==="admins")?["admins"]:[],[u]);y&&i.failure("Loading details failed",y),b&&i.failure("Loading identities failed",b);const T=n=>{I(n.name,n.groups??[],!1).then(()=>{$()}).catch(c=>{s.setSubmitting(!1),i.failure("Identity creation failed",c)})},A=R().shape({name:E().required("Identity name is required").test("unique-name","An identity with this name already exists",function(n){return n?!x.map(m=>m.name).includes(n):!0})}),s=G({initialValues:{name:w("lxd-ui"),groups:N},validationSchema:A,onSubmit:T,enableReinitialize:!0});return a?e.jsx(t.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0}):r&&j(o)?e.jsx(h,{to:`${l}/ui`,replace:!0}):!r||!v?e.jsx(h,{to:`${l}/ui/login`,replace:!0}):e.jsx(t.CustomLayout,{mainClassName:"certificates-with-bearer-token",children:e.jsxs(t.Row,{children:[e.jsx(B,{variant:"horizontal",step2Name:"Create TLS identity"}),i.notification?e.jsx(t.NotificationConsumer,{}):e.jsx(C,{}),e.jsx(P,{formik:s}),e.jsx("p",{children:"Auth groups"}),e.jsx(q,{groups:u,modifiedGroups:new Set(s.values.groups),parentItemName:"",selectedGroups:new Set(s.values.groups),setSelectedGroups:n=>{s.setFieldValue("groups",n)},toggleGroup:n=>{},scrollDependencies:[u,s.values.groups?.length,i.notification,s],belowIds:["create-tls-identity-with-bearer-token-footer","status-bar"],disabled:!0}),e.jsxs("div",{id:"create-tls-identity-with-bearer-token-footer",className:"u-flex create-tls-identity-with-bearer-token-footer",children:[e.jsx(t.Button,{appearance:"base",onClick:()=>{d(`${l}/ui/login/certificate-generate`)},className:"u-no-margin--bottom",children:"Cancel"}),e.jsx(t.ActionButton,{appearance:"positive",onClick:()=>{s.submitForm()},disabled:!s.isValid||s.isSubmitting||!s.values.name,loading:s.isSubmitting,className:"u-no-margin--bottom",children:"Create identity"})]})]})})},H=()=>{const r=t.useNotify(),[a,o]=f.useState(""),i=()=>{const d=a.trim().split(/\r?\n|\r|\n/g).at(-1)??"";M(d).then(()=>{location.reload()}).catch(u=>r.failure("Error using token",u))};return e.jsxs(t.Form,{children:[e.jsx(t.Textarea,{id:"token",name:"token",label:"Paste the identity trust token below:",placeholder:"Enter identity trust token",rows:5,onChange:d=>{o(d.target.value)}}),e.jsx(t.Button,{appearance:"positive",disabled:a.length<1,type:"button",onClick:i,children:"Connect"})]})},O=()=>{const{isAuthenticated:r,isAuthLoading:a,authMethod:o}=p(),i=t.useNotify(),d="if ! lxc auth group show admins >/dev/null 2>&1; then lxc auth group create admins && lxc auth group permission add admins server admin; fi; lxc auth identity create tls/lxd-ui --group admins";return a?e.jsx(t.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0}):r&&j(o)?e.jsx(h,{to:`${l}/ui`,replace:!0}):e.jsx(t.CustomLayout,{mainClassName:"certificate-generate",children:e.jsxs(t.Row,{children:[e.jsx(t.Col,{size:2}),e.jsxs(t.Col,{size:8,children:[i.notification?e.jsx(_,{}):e.jsx(t.Row,{children:e.jsx(C,{})}),e.jsxs("div",{className:"p-stepped-list__content",children:[e.jsx("p",{children:"Paste the following commands into the console of the machine where LXD is running:"}),e.jsx(W,{code:d}),e.jsx(t.Accordion,{sections:[{title:e.jsx(e.Fragment,{children:"What does this command do?"}),content:e.jsxs(e.Fragment,{children:[e.jsx("p",{children:"The above command is a one-line equivalent for the following steps:"}),e.jsxs("div",{children:["First, the command checks to see if there is an auth group ",e.jsx("code",{children:"admins"}),". The"," ",e.jsx("code",{children:">/dev/null 2>&1"})," part ensures that if the group is missing, no error is shown."]}),e.jsx(t.CodeSnippet,{blocks:[{code:"if ! lxc auth group show admins >/dev/null 2>&1;",wrapLines:!0}]}),e.jsxs("div",{children:["If there is no group ",e.jsx("code",{children:"admins"}),", it is created."]}),e.jsx(t.CodeSnippet,{blocks:[{code:"lxc auth group create admins",wrapLines:!0}]}),e.jsxs("div",{children:["The new group ",e.jsx("code",{children:"admins"})," is given server admin permissions."]}),e.jsx(t.CodeSnippet,{blocks:[{code:"lxc auth group permission add admins server admin",wrapLines:!0}]}),e.jsxs("div",{children:["Finally, a new identity ",e.jsx("code",{children:"lxd-ui"})," is created and added to the group ",e.jsx("code",{children:"admins"}),". This command returns the identity trust token which should be pasted below."]}),e.jsx(t.CodeSnippet,{blocks:[{code:"lxc auth identity create tls/lxd-ui --group admins",wrapLines:!0}]})]})}]}),e.jsx(t.Accordion,{sections:[{title:e.jsx(e.Fragment,{children:"I already have an identity trust token"}),content:e.jsx(e.Fragment,{children:e.jsx("p",{children:"If you received an identity trust token or created a TLS identity, use it below. No extra steps needed."})})}]})]}),e.jsxs("div",{className:"p-stepped-list__content",children:[e.jsx("br",{}),e.jsx(H,{})]})]})]})})},ee=()=>{const{isAuthenticated:r,isAuthLoading:a,authMethod:o}=p(),i=o===g.BEARER;return a?e.jsx(t.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0}):r&&j(o)?e.jsx(h,{to:`${l}/ui`,replace:!0}):r&&i?e.jsx(D,{}):e.jsx(O,{})};export{ee as default};