mirror of
https://github.com/khairul169/vaulterm.git
synced 2025-05-15 08:59:37 +07:00
feat: add incus user option
This commit is contained in:
parent
d931235fb3
commit
3ef0c93c8f
@ -172,9 +172,18 @@ const IncusFormFields = ({ form }: MiscFormFieldProps) => {
|
|||||||
/>
|
/>
|
||||||
</FormField>
|
</FormField>
|
||||||
{type === "lxc" && (
|
{type === "lxc" && (
|
||||||
<FormField label="Shell">
|
<>
|
||||||
<InputField form={form} name="metadata.shell" placeholder="bash" />
|
<FormField label="User ID">
|
||||||
</FormField>
|
<InputField
|
||||||
|
form={form}
|
||||||
|
keyboardType="number-pad"
|
||||||
|
name="metadata.user"
|
||||||
|
/>
|
||||||
|
</FormField>
|
||||||
|
<FormField label="Shell">
|
||||||
|
<InputField form={form} name="metadata.shell" placeholder="bash" />
|
||||||
|
</FormField>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
@ -44,6 +44,7 @@ const incusSchema = hostSchema.merge(
|
|||||||
metadata: z.object({
|
metadata: z.object({
|
||||||
type: z.enum(["lxc", "qemu"]),
|
type: z.enum(["lxc", "qemu"]),
|
||||||
instance: z.string().min(1, { message: "Instance name is required" }),
|
instance: z.string().min(1, { message: "Instance name is required" }),
|
||||||
|
user: z.coerce.number().nullish(),
|
||||||
shell: z.string().nullish(),
|
shell: z.string().nullish(),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
type IncusWebsocketSession struct {
|
type IncusWebsocketSession struct {
|
||||||
Type string `json:"type"` // "qemu" | "lxc"
|
Type string `json:"type"` // "qemu" | "lxc"
|
||||||
Instance string `json:"instance"`
|
Instance string `json:"instance"`
|
||||||
|
User *int `json:"user"`
|
||||||
Shell string `json:"shell"`
|
Shell string `json:"shell"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,7 +24,10 @@ func (i *IncusWebsocketSession) NewTerminal(c *websocket.Conn, incus *lib.IncusS
|
|||||||
i.Shell = "/bin/sh"
|
i.Shell = "/bin/sh"
|
||||||
}
|
}
|
||||||
|
|
||||||
exec, err := incus.InstanceExec(i.Instance, []string{i.Shell}, true)
|
exec, err := incus.InstanceExec(i.Instance, []string{i.Shell}, &lib.IncusInstanceExecOptions{
|
||||||
|
Interactive: true,
|
||||||
|
User: i.User,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,11 @@ func (i *IncusServer) Fetch(method string, url string, cfg *IncusFetchConfig) ([
|
|||||||
return io.ReadAll(resp.Body)
|
return io.ReadAll(resp.Body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type IncusInstanceExecOptions struct {
|
||||||
|
Interactive bool
|
||||||
|
User *int
|
||||||
|
}
|
||||||
|
|
||||||
type IncusInstanceExecRes struct {
|
type IncusInstanceExecRes struct {
|
||||||
ID string
|
ID string
|
||||||
Operation string
|
Operation string
|
||||||
@ -74,17 +79,23 @@ type IncusInstanceExecRes struct {
|
|||||||
Secret string
|
Secret string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *IncusServer) InstanceExec(instance string, command []string, interactive bool) (*IncusInstanceExecRes, error) {
|
func (i *IncusServer) InstanceExec(instance string, command []string, options *IncusInstanceExecOptions) (*IncusInstanceExecRes, error) {
|
||||||
url := fmt.Sprintf("/1.0/instances/%s/exec?project=default", instance)
|
url := fmt.Sprintf("/1.0/instances/%s/exec?project=default", instance)
|
||||||
|
|
||||||
|
var user *int
|
||||||
|
if options != nil && options.User != nil {
|
||||||
|
user = options.User
|
||||||
|
}
|
||||||
|
|
||||||
body, err := i.Fetch("POST", url, &IncusFetchConfig{
|
body, err := i.Fetch("POST", url, &IncusFetchConfig{
|
||||||
Body: map[string]interface{}{
|
Body: map[string]interface{}{
|
||||||
"command": command,
|
"command": command,
|
||||||
"interactive": interactive,
|
"interactive": options != nil && options.Interactive,
|
||||||
"wait-for-websocket": true,
|
"wait-for-websocket": true,
|
||||||
"environment": map[string]string{
|
"environment": map[string]string{
|
||||||
"TERM": "xterm-256color",
|
"TERM": "xterm-256color",
|
||||||
},
|
},
|
||||||
|
"user": user,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user