-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient.go
More file actions
58 lines (51 loc) · 1.86 KB
/
client.go
File metadata and controls
58 lines (51 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) Codesphere Inc.
// SPDX-License-Identifier: Apache-2.0
package cmd
//go:generate go tool mockery
import (
"context"
"fmt"
"io"
"net/url"
"time"
"github.com/codesphere-cloud/cs-go/api"
)
type Client interface {
ListTeams() ([]api.Team, error)
ListWorkspaces(teamId int) ([]api.Workspace, error)
ListBaseimages() ([]api.Baseimage, error)
GetWorkspace(workspaceId int) (api.Workspace, error)
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)
DeployWorkspace(args api.DeployWorkspaceArgs) (*api.Workspace, error)
DeleteWorkspace(wsId int) error
StartPipelineStage(wsId int, profile string, stage string) error
GetPipelineState(wsId int, stage string) ([]api.PipelineStatus, error)
GitPull(wsId int, remote string, branch string) error
DeployLandscape(wsId int, profile string) error
}
// CommandExecutor abstracts command execution for testing
type CommandExecutor interface {
Execute(ctx context.Context, name string, args []string, stdout, stderr io.Writer) error
}
func NewClient(opts GlobalOptions) (Client, error) {
token, err := opts.Env.GetApiToken()
if err != nil {
return nil, fmt.Errorf("failed to get API token: %w", err)
}
apiUrl, err := url.Parse(opts.GetApiUrl())
if err != nil {
return nil, fmt.Errorf("failed to parse URL '%s': %w", opts.GetApiUrl(), err)
}
client := api.NewClient(context.Background(), api.Configuration{
BaseUrl: apiUrl,
Token: token,
Verbose: opts.Verbose,
})
return client, nil
}