Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/wbctl create job.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Aliases:

Flags:
-a, --application string The application to run in the job. Not required if at least one service is specified.
--capability strings Capabilit(y|ies) to include in the job.
-c, --command string The command to run in the job.
--context string The context (volume, snapshot, or s3 bucket) for the job.
--dataplane string The ID of the dataplane where the job will be created. If only one dataplane is available, this flag can be omitted.
Expand Down
1 change: 1 addition & 0 deletions doc/wbctl create workbench.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Aliases:

Flags:
-a, --application string The application to run in the workbench. Not required if at least one service is specified.
--capability strings Capabilit(y|ies) to include in the workbench.
--dataplane string The ID of the dataplane where the workbench will be created. If only one dataplane is available, this flag can be omitted.
--desired-state string The desired state of the workbench (e.g., RUNNING, STOPPED).
-d, --dry-run Only print the object that would be sent, without sending it.
Expand Down
23 changes: 23 additions & 0 deletions doc/wbctl get capabilities.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<pre>
Print a table of basic information about the Capability resources identified by an optional list of resource ids. All resources printed if no ids provided.

Usage:
wbctl get capabilities [flags]

Aliases:
capabilities, capability

Flags:
-h, --help help for capabilities
-o, --output string The output format. One of: json, text. (default "text")
--sort string The sort column. Direction specified by appending '.asc' or '.desc' to the column name.

Global Flags:
-m, --auth-mode string Authentication mode. One of: device, pkce. (default "device")
-e, --endpoint string The Workbench API endpoint URL.
--ignore-token-cache Ignore token cache.
--no-listen Do not open a local port to listen for PKCE authentication.
--organization string The organization to authenticate with the Workbench API.
-p, --profile string The configuration profile to use. (default "Default")
-v, --verbose Log verbosity. Repeat option for increased levels of verbose output (-v, -vv, or -vvv).
</pre>
1 change: 1 addition & 0 deletions doc/wbctl get.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Usage:

Available Commands:
<a href='wbctl get applications.md'>applications</a> Get one or many Application resources
<a href='wbctl get capabilities.md'>capabilities</a> Get one or many Capability resources
<a href='wbctl get dataplanes.md'>dataplanes</a> Get one or many Dataplane resources
<a href='wbctl get events.md'>events</a> Get one or many Event resources
<a href='wbctl get image-builds.md'>image-builds</a> Get one or many Image-Build resources
Expand Down
18 changes: 18 additions & 0 deletions doc/wbctl profile init.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<pre>
Creates or replaces a named profile in the config file, prompting for the profile name, endpoint, and organization

Usage:
wbctl profile init [flags]

Flags:
-h, --help help for init

Global Flags:
-m, --auth-mode string Authentication mode. One of: device, pkce. (default "device")
-e, --endpoint string The Workbench API endpoint URL.
--ignore-token-cache Ignore token cache.
--no-listen Do not open a local port to listen for PKCE authentication.
--organization string The organization to authenticate with the Workbench API.
-p, --profile string The configuration profile to use. (default "Default")
-v, --verbose Log verbosity. Repeat option for increased levels of verbose output (-v, -vv, or -vvv).
</pre>
18 changes: 18 additions & 0 deletions doc/wbctl profile list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<pre>
List the profiles available in the current config file.

Usage:
wbctl profile list [flags]

Flags:
-h, --help help for list

Global Flags:
-m, --auth-mode string Authentication mode. One of: device, pkce. (default "device")
-e, --endpoint string The Workbench API endpoint URL.
--ignore-token-cache Ignore token cache.
--no-listen Do not open a local port to listen for PKCE authentication.
--organization string The organization to authenticate with the Workbench API.
-p, --profile string The configuration profile to use. (default "Default")
-v, --verbose Log verbosity. Repeat option for increased levels of verbose output (-v, -vv, or -vvv).
</pre>
19 changes: 19 additions & 0 deletions doc/wbctl profile show.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<pre>
Show the values of the current profile

Usage:
wbctl profile show [flags]

Flags:
-h, --help help for show
-o, --output string The output format. One of: json, text. (default "text")

Global Flags:
-m, --auth-mode string Authentication mode. One of: device, pkce. (default "device")
-e, --endpoint string The Workbench API endpoint URL.
--ignore-token-cache Ignore token cache.
--no-listen Do not open a local port to listen for PKCE authentication.
--organization string The organization to authenticate with the Workbench API.
-p, --profile string The configuration profile to use. (default "Default")
-v, --verbose Log verbosity. Repeat option for increased levels of verbose output (-v, -vv, or -vvv).
</pre>
28 changes: 28 additions & 0 deletions doc/wbctl profile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<pre>
Manages named profiles stored in the config file

Usage:
wbctl profile [command]

Aliases:
profile, prof

Available Commands:
<a href='wbctl profile init.md'>init</a> Create or replace a profile
<a href='wbctl profile list.md'>list</a> List the available profiles
<a href='wbctl profile show.md'>show</a> Show current profile

Flags:
-h, --help help for profile

Global Flags:
-m, --auth-mode string Authentication mode. One of: device, pkce. (default "device")
-e, --endpoint string The Workbench API endpoint URL.
--ignore-token-cache Ignore token cache.
--no-listen Do not open a local port to listen for PKCE authentication.
--organization string The organization to authenticate with the Workbench API.
-p, --profile string The configuration profile to use. (default "Default")
-v, --verbose Log verbosity. Repeat option for increased levels of verbose output (-v, -vv, or -vvv).

Use "wbctl profile [command] --help" for more information about a command.
</pre>
13 changes: 12 additions & 1 deletion internal/cmd/create/job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func CreateCommand(
flags.AddApplicationFlag(cmd, constants.JobType)
flags.AddServiceFlag(cmd, constants.JobType)
flags.AddEnvironmentFlag(cmd, constants.JobType)
flags.AddCapabilityFlag(cmd, constants.JobType)
return cmd
}

Expand Down Expand Up @@ -210,7 +211,7 @@ func getJobRequestBody(
}
services := v.GetStringSlice(constants.ServiceFlag)
envs := v.GetStringSlice(constants.EnvironmentFlag)

capabilities := v.GetStringSlice(constants.CapabilityFlag)
workspaceRequests, err := workbench.GetValidWorkspaceRequests(ctx, svc, volumes)
if err != nil {
return types.Job{}, err
Expand Down Expand Up @@ -247,6 +248,16 @@ func getJobRequestBody(
"folderName": workspaceRequests[0].MountName,
}
}
if len(capabilities) > 0 {
job.Mounts = make([]types.MountRequest, 0, len(capabilities))
for _, capability := range capabilities {
job.Mounts = append(job.Mounts, types.MountRequest{
Capability: &types.CapabilityRequest{
ID: capability,
},
})
}
}
job.Properties = properties
return job, nil
}
Expand Down
132 changes: 118 additions & 14 deletions internal/cmd/create/job/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,70 @@ const (
}
}
}
`
expectedCreateJobRequestBodyWithCapabilities = `
{
"param": {
"dataplane_id": "123e4567-e89b-12d3-a456-426614174000",
"description": "job desc",
"name": "job-2",
"nodepool": "np-2",
"services": [
{
"id": "service-1",
"env": {
"DEFAULT_MOUNTNAME": "data"
}
},
{
"id": "service-2",
"env": {
"DEFAULT_MOUNTNAME": "data"
}
}
],
"spec": {
"tasks": {
"default": {
"cmds": [
"run.sh"
]
}
},
"version": "3"
},
"workspaces": [
{
"id": "ctrl-home",
"mountName": "sas"
},
{
"id": "ctrl-data",
"mountName": "data"
}
],
"mounts": [
{
"capability": {
"id": "capability1"
}
},
{
"capability": {
"id": "capability2"
}
}
],
"properties": {
"isWorkbenchAppCreated": true,
"primaryVolume": {
"controller_id": "ctrl-home",
"folderName": "sas",
"id": "ws-home"
}
}
}
}
`
expectedUpdateJobDryRunOutput = `{
"ids": [
Expand Down Expand Up @@ -405,20 +469,21 @@ const (
)

type createInput struct {
endpoint string
filename string
fileContent string
dryRun bool
dataplane string
name string
description string
context string
command string
application string
services []string
nodepool string
subPath string
workspaces []string
endpoint string
filename string
fileContent string
dryRun bool
dataplane string
name string
description string
context string
command string
application string
services []string
nodepool string
subPath string
workspaces []string
capabilities []string
}

type createExpected struct {
Expand Down Expand Up @@ -598,6 +663,42 @@ func TestCreateJobCommand(t *testing.T) {
workspacesCalls: 2,
},
},
{
name: "create success with capabilities",
input: createInput{
dataplane: "123e4567-e89b-12d3-a456-426614174000",
name: "job-2",
description: "job desc",
command: "run.sh",
services: []string{"service-1", "service-2"},
nodepool: "np-2",
workspaces: []string{"ws-home", "ws-data"},
capabilities: []string{"capability1", "capability2"},
},
mockEndpoints: getCreateJobEndpoints(jobEndpointsConfig{
dataplaneConfig: stubs.StubHTTPPartialGetConfig{
ExpectedQuery: expectedDataplaneQuery,
ResponseBody: `[{"id":"123e4567-e89b-12d3-a456-426614174000"}]`,
ResponseStatus: http.StatusOK,
},
servicesConfig: stubs.StubHTTPPartialGetConfig{
ResponseBody: expectedServicesResponseBody,
ResponseStatus: http.StatusOK,
},
jobConfig: stubs.StubHTTPPartialPostConfig{
ExpectedRequestBody: expectedCreateJobRequestBodyWithCapabilities,
ResponseBody: `{"id":"job-1"}`,
ResponseStatus: http.StatusOK,
},
}),
expected: createExpected{
displays: []string{stubs.ExpectedDeviceAuthDisplay, expectedCreateJobID},
createCalls: 1,
dataplanesCalls: 1,
servicesCalls: 1,
workspacesCalls: 2,
},
},
{
name: "create error",
input: createInput{
Expand Down Expand Up @@ -1303,6 +1404,9 @@ func getCreateArgs(
for _, workspaceID := range tt.input.workspaces {
args = append(args, "--"+constants.WorkspaceFlag, workspaceID)
}
for _, capabilityID := range tt.input.capabilities {
args = append(args, "--"+constants.CapabilityFlag, capabilityID)
}
return args
}

Expand Down
12 changes: 12 additions & 0 deletions internal/cmd/create/workbench/workbench.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func CreateCommand(
flags.AddApplicationFlag(cmd, constants.WorkbenchType)
flags.AddServiceFlag(cmd, constants.WorkbenchType)
flags.AddDesiredStateFlag(cmd, constants.WorkbenchType)
flags.AddCapabilityFlag(cmd, constants.WorkbenchType)
return cmd
}

Expand Down Expand Up @@ -193,6 +194,7 @@ func getWorkbenchRequestBody(
volumes = v.GetStringSlice(constants.WorkspaceFlag)
}
services := v.GetStringSlice(constants.ServiceFlag)
capabilities := v.GetStringSlice(constants.CapabilityFlag)

serviceRequests, err := workbench.GetServiceRequests(ctx, svc, application, services)
if err != nil {
Expand All @@ -212,6 +214,16 @@ func getWorkbenchRequestBody(
ApplicationID: application,
}
setWorkspaceRequests(&wkbnch, workspaceRequests)
if len(capabilities) > 0 {
wkbnch.Mounts = make([]types.MountRequest, 0, len(capabilities))
for _, capability := range capabilities {
wkbnch.Mounts = append(wkbnch.Mounts, types.MountRequest{
Capability: &types.CapabilityRequest{
ID: capability,
},
})
}
}
return wkbnch, nil
}

Expand Down
Loading
Loading