mirror of
https://github.com/cirruslabs/orchard.git
synced 2026-09-29 19:41:15 +02:00
Support port-forwarding directly to Tart Guest Agent (#489)
This commit is contained in:
@@ -13,6 +13,21 @@ import (
|
||||
"github.com/coder/websocket"
|
||||
)
|
||||
|
||||
type PortForwardTarget string
|
||||
|
||||
const (
|
||||
PortForwardTargetTartGuestAgent PortForwardTarget = "tart-guest-agent"
|
||||
)
|
||||
|
||||
func (target PortForwardTarget) Validate() error {
|
||||
switch target {
|
||||
case PortForwardTargetTartGuestAgent:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("unsupported port-forward target %q", target)
|
||||
}
|
||||
}
|
||||
|
||||
type VMsService struct {
|
||||
client *Client
|
||||
}
|
||||
@@ -182,6 +197,19 @@ func (service *VMsService) PortForwardHostProcess(
|
||||
})
|
||||
}
|
||||
|
||||
func (service *VMsService) PortForwardTarget(
|
||||
ctx context.Context,
|
||||
name string,
|
||||
target PortForwardTarget,
|
||||
waitSeconds uint16,
|
||||
) (net.Conn, error) {
|
||||
return service.client.wsRequest(ctx, fmt.Sprintf("vms/%s/port-forward", url.PathEscape(name)),
|
||||
map[string]string{
|
||||
"target": string(target),
|
||||
"wait": strconv.FormatUint(uint64(waitSeconds), 10),
|
||||
})
|
||||
}
|
||||
|
||||
func (service *VMsService) Exec(
|
||||
ctx context.Context,
|
||||
name string,
|
||||
|
||||
@@ -10,13 +10,14 @@ var ErrUnsupportedServiceAccountRole = errors.New("unsupported service account r
|
||||
type ServiceAccountRole string
|
||||
|
||||
const (
|
||||
ServiceAccountRoleComputeRead ServiceAccountRole = "compute:read"
|
||||
ServiceAccountRoleComputeWrite ServiceAccountRole = "compute:write"
|
||||
ServiceAccountRoleComputeConnect ServiceAccountRole = "compute:connect"
|
||||
ServiceAccountRoleHostProcessWrite ServiceAccountRole = "host-process:write"
|
||||
ServiceAccountRoleHostProcessConnect ServiceAccountRole = "host-process:connect"
|
||||
ServiceAccountRoleAdminRead ServiceAccountRole = "admin:read"
|
||||
ServiceAccountRoleAdminWrite ServiceAccountRole = "admin:write"
|
||||
ServiceAccountRoleComputeRead ServiceAccountRole = "compute:read"
|
||||
ServiceAccountRoleComputeWrite ServiceAccountRole = "compute:write"
|
||||
ServiceAccountRoleComputeConnect ServiceAccountRole = "compute:connect"
|
||||
ServiceAccountRoleComputeConnectTartGuestAgent ServiceAccountRole = "compute:connect:tart-guest-agent"
|
||||
ServiceAccountRoleHostProcessWrite ServiceAccountRole = "host-process:write"
|
||||
ServiceAccountRoleHostProcessConnect ServiceAccountRole = "host-process:connect"
|
||||
ServiceAccountRoleAdminRead ServiceAccountRole = "admin:read"
|
||||
ServiceAccountRoleAdminWrite ServiceAccountRole = "admin:write"
|
||||
)
|
||||
|
||||
func NewServiceAccountRole(name string) (ServiceAccountRole, error) {
|
||||
@@ -27,6 +28,8 @@ func NewServiceAccountRole(name string) (ServiceAccountRole, error) {
|
||||
return ServiceAccountRoleComputeWrite, nil
|
||||
case string(ServiceAccountRoleComputeConnect):
|
||||
return ServiceAccountRoleComputeConnect, nil
|
||||
case string(ServiceAccountRoleComputeConnectTartGuestAgent):
|
||||
return ServiceAccountRoleComputeConnectTartGuestAgent, nil
|
||||
case string(ServiceAccountRoleHostProcessWrite):
|
||||
return ServiceAccountRoleHostProcessWrite, nil
|
||||
case string(ServiceAccountRoleHostProcessConnect):
|
||||
@@ -45,6 +48,7 @@ func AllServiceAccountRoles() []ServiceAccountRole {
|
||||
ServiceAccountRoleComputeRead,
|
||||
ServiceAccountRoleComputeWrite,
|
||||
ServiceAccountRoleComputeConnect,
|
||||
ServiceAccountRoleComputeConnectTartGuestAgent,
|
||||
ServiceAccountRoleHostProcessWrite,
|
||||
ServiceAccountRoleHostProcessConnect,
|
||||
ServiceAccountRoleAdminRead,
|
||||
|
||||
@@ -15,7 +15,8 @@ type PortForwardAction struct {
|
||||
}
|
||||
|
||||
type PortForwardTarget struct {
|
||||
HostProcess *PortForwardTargetHostProcess `json:"hostProcess,omitempty"`
|
||||
HostProcess *PortForwardTargetHostProcess `json:"hostProcess,omitempty"`
|
||||
TartGuestAgent *PortForwardTargetTartGuestAgent `json:"tartGuestAgent,omitempty"`
|
||||
}
|
||||
|
||||
type PortForwardTargetHostProcess struct {
|
||||
@@ -23,6 +24,10 @@ type PortForwardTargetHostProcess struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type PortForwardTargetTartGuestAgent struct {
|
||||
VMUID string `json:"vmUID"`
|
||||
}
|
||||
|
||||
type SyncVMsAction struct {
|
||||
// nothing for now
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user