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
12 changes: 6 additions & 6 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ This project includes code licensed under the following terms:

----------
Module: code.gitea.io/sdk/gitea
Version: v0.22.1
Version: v0.23.2
License: MIT
License URL: https://gitea.com/gitea/go-sdk/src/tag/gitea/v0.22.1/gitea/LICENSE
License URL: https://gitea.com/gitea/go-sdk/src/tag/gitea/v0.23.2/gitea/LICENSE

----------
Module: dario.cat/mergo
Expand Down Expand Up @@ -365,9 +365,9 @@ License URL: https://github.com/xanzy/ssh-agent/blob/v0.3.3/LICENSE

----------
Module: gitlab.com/gitlab-org/api/client-go
Version: v1.11.0
Version: v1.39.0
License: Apache-2.0
License URL: https://gitlab.com/gitlab-org/api/blob/client-go/v1.11.0/client-go/LICENSE
License URL: https://gitlab.com/gitlab-org/api/blob/client-go/v1.39.0/client-go/LICENSE

----------
Module: go.yaml.in/yaml/v2
Expand Down Expand Up @@ -401,9 +401,9 @@ License URL: https://cs.opensource.google/go/x/net/+/v0.50.0:LICENSE

----------
Module: golang.org/x/oauth2
Version: v0.34.0
Version: v0.35.0
License: BSD-3-Clause
License URL: https://cs.opensource.google/go/x/oauth2/+/v0.34.0:LICENSE
License URL: https://cs.opensource.google/go/x/oauth2/+/v0.35.0:LICENSE

----------
Module: golang.org/x/sync/errgroup
Expand Down
9 changes: 9 additions & 0 deletions api/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ func (c *Client) ScaleWorkspace(wsId int, replicas int) error {
return errors.FormatAPIError(r, err)
}

// ScaleLandscapeServices scales landscape services by name.
// The services map contains service name -> replica count.
func (c *Client) ScaleLandscapeServices(wsId int, services map[string]int) error {
req := c.api.WorkspacesAPI.WorkspacesScaleLandscapeServices(c.ctx, float32(wsId)).
RequestBody(services)
resp, err := req.Execute()
return errors.FormatAPIError(resp, err)
}

// Waits for a given workspace to be running.
//
// Returns [TimedOut] error if the workspace does not become running in time.
Expand Down
1 change: 1 addition & 0 deletions cli/cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Client interface {
WorkspaceStatus(workspaceId int) (*api.WorkspaceStatus, error)
WaitForWorkspaceRunning(workspace *api.Workspace, timeout time.Duration) error
ScaleWorkspace(wsId int, replicas int) error
ScaleLandscapeServices(wsId int, services map[string]int) error
SetEnvVarOnWorkspace(workspaceId int, vars map[string]string) error
ExecCommand(workspaceId int, command string, workdir string, env map[string]string) (string, string, error)
ListWorkspacePlans() ([]api.WorkspacePlan, error)
Expand Down
21 changes: 16 additions & 5 deletions cli/cmd/curl.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"log"
"os"
"os/exec"
"strings"
"time"

io_pkg "github.com/codesphere-cloud/cs-go/pkg/io"
Expand Down Expand Up @@ -53,8 +54,17 @@ func (c *CurlCmd) RunE(_ *cobra.Command, args []string) error {
return fmt.Errorf("failed to get API token: %w", err)
}

path := args[0]
curlArgs := args[1:]
path := "/"
var curlArgs []string

if len(args) > 0 {
if strings.HasPrefix(args[0], "/") {
path = args[0]
curlArgs = args[1:]
} else {
curlArgs = args
}
}

return c.CurlWorkspace(client, wsId, token, path, curlArgs)
}
Expand All @@ -70,9 +80,10 @@ func AddCurlCmd(rootCmd *cobra.Command, opts *GlobalOptions) {
{Cmd: "/api/health -w 1234", Desc: "GET request to health endpoint"},
{Cmd: "/api/data -w 1234 -- -XPOST -d '{\"key\":\"value\"}'", Desc: "POST request with data"},
{Cmd: "/api/endpoint -w 1234 -- -v", Desc: "verbose output"},
{Cmd: "-w 1234 -- -v", Desc: "verbose request to workspace root"},
{Cmd: "/ -- -k", Desc: "skip TLS verification"}, {Cmd: "/ -- -I", Desc: "HEAD request using workspace from env var"},
}),
Args: cobra.MinimumNArgs(1),
Args: cobra.ArbitraryArgs,
},
Opts: CurlOptions{
GlobalOptions: opts,
Expand Down Expand Up @@ -104,8 +115,8 @@ func (c *CurlCmd) CurlWorkspace(client Client, wsId int, token string, path stri
ctx, cancel := context.WithTimeout(context.Background(), c.Opts.Timeout)
defer cancel()

// Build curl command with authentication header
cmdArgs := []string{"curl", "-H", fmt.Sprintf("x-forward-security: %s", token)}
// Build curl command with authentication header and -L to follow redirects
cmdArgs := []string{"curl", "-L", "-H", fmt.Sprintf("X-CS-Authorization: Bearer %s", token)}

cmdArgs = append(cmdArgs, curlArgs...)
cmdArgs = append(cmdArgs, url)
Expand Down
20 changes: 14 additions & 6 deletions cli/cmd/curl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,16 @@ var _ = Describe("Curl", func() {
mock.Anything,
"curl",
mock.MatchedBy(func(args []string) bool {
// Verify the args contain the expected header, flag, and URL
// Verify the args contain the expected header, flag, -L and URL
hasFollowRedirects := false
hasHeader := false
hasFlag := false
hasURL := false
for i, arg := range args {
if arg == "-H" && i+1 < len(args) && args[i+1] == fmt.Sprintf("x-forward-security: %s", token) {
if arg == "-L" {
hasFollowRedirects = true
}
if arg == "-H" && i+1 < len(args) && args[i+1] == fmt.Sprintf("X-CS-Authorization: Bearer %s", token) {
hasHeader = true
}
if arg == "-I" {
Expand All @@ -76,7 +80,7 @@ var _ = Describe("Curl", func() {
hasURL = true
}
}
return hasHeader && hasFlag && hasURL
return hasFollowRedirects && hasHeader && hasFlag && hasURL
}),
mock.Anything,
mock.Anything,
Expand All @@ -93,18 +97,22 @@ var _ = Describe("Curl", func() {
mock.Anything,
"curl",
mock.MatchedBy(func(args []string) bool {
// Verify the URL contains the custom path
// Verify the URL contains the custom path and -L flag
hasFollowRedirects := false
hasHeader := false
hasURL := false
for i, arg := range args {
if arg == "-H" && i+1 < len(args) && args[i+1] == fmt.Sprintf("x-forward-security: %s", token) {
if arg == "-L" {
hasFollowRedirects = true
}
if arg == "-H" && i+1 < len(args) && args[i+1] == fmt.Sprintf("X-CS-Authorization: Bearer %s", token) {
hasHeader = true
}
if arg == "https://42-3000.dev.5.codesphere.com/custom/path" {
hasURL = true
}
}
return hasHeader && hasURL
return hasFollowRedirects && hasHeader && hasURL
}),
mock.Anything,
mock.Anything,
Expand Down
57 changes: 57 additions & 0 deletions cli/cmd/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading