Skip to content

Commit 2e168d2

Browse files
committed
feat(cli): Add ps and up
1 parent 811565e commit 2e168d2

53 files changed

Lines changed: 3827 additions & 912 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.mockery.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ formatter: gofmt
99
log-level: info
1010
structname: "{{.Mock}}{{.InterfaceName}}"
1111
pkgname: "{{.SrcPackageName}}"
12-
recursive: false
12+
recursive: true
1313
require-template-schema-exists: true
1414
template: testify
1515
template-schema: "{{.Template}}.schema.json"
@@ -30,6 +30,10 @@ packages:
3030
config:
3131
all: true
3232
interfaces:
33+
github.com/codesphere-cloud/cs-go/pkg/cs:
34+
config:
35+
all: true
36+
interfaces:
3337
github.com/codesphere-cloud/cs-go/pkg/io:
3438
config:
3539
all: true

api/client.go

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,34 @@ import (
77
"context"
88
"net/http"
99
"net/url"
10+
"time"
1011

1112
"github.com/codesphere-cloud/cs-go/api/errors"
1213
"github.com/codesphere-cloud/cs-go/api/openapi_client"
1314
)
1415

15-
type Client struct {
16+
type Client interface {
17+
ListTeams() ([]Team, error)
18+
ListWorkspaces(teamId int) ([]Workspace, error)
19+
ListBaseimages() ([]Baseimage, error)
20+
GetWorkspace(workspaceId int) (Workspace, error)
21+
WorkspaceStatus(workspaceId int) (*WorkspaceStatus, error)
22+
WaitForWorkspaceRunning(workspace *Workspace, timeout time.Duration) error
23+
ScaleWorkspace(wsId int, replicas int) error
24+
ScaleLandscapeServices(wsId int, services map[string]int) error
25+
SetEnvVarOnWorkspace(workspaceId int, vars map[string]string) error
26+
ExecCommand(workspaceId int, command string, workdir string, env map[string]string) (string, string, error)
27+
ListWorkspacePlans() ([]WorkspacePlan, error)
28+
DeployWorkspace(args DeployWorkspaceArgs) (*Workspace, error)
29+
DeleteWorkspace(wsId int) error
30+
StartPipelineStage(wsId int, profile string, stage string) error
31+
GetPipelineState(wsId int, stage string) ([]PipelineStatus, error)
32+
GitPull(wsId int, remote string, branch string) error
33+
DeployLandscape(wsId int, profile string) error
34+
WakeUpWorkspace(wsId int, token string, profile string, timeout time.Duration) error
35+
}
36+
37+
type RealClient struct {
1638
ctx context.Context
1739
api *openapi_client.APIClient
1840
time Time
@@ -41,15 +63,15 @@ func (c Configuration) GetApiUrl() *url.URL {
4163
}
4264

4365
// For use in tests
44-
func NewClientWithCustomDeps(ctx context.Context, opts Configuration, api *openapi_client.APIClient, time Time) *Client {
45-
return &Client{
66+
func NewClientWithCustomDeps(ctx context.Context, opts Configuration, api *openapi_client.APIClient, time Time) *RealClient {
67+
return &RealClient{
4668
ctx: context.WithValue(ctx, openapi_client.ContextAccessToken, opts.Token),
4769
api: api,
4870
time: time,
4971
}
5072
}
5173

52-
func NewClient(ctx context.Context, opts Configuration) *Client {
74+
func NewClient(ctx context.Context, opts Configuration) *RealClient {
5375
cfg := openapi_client.NewConfiguration()
5476
cfg.HTTPClient = NewHttpClient()
5577
cfg.Servers = []openapi_client.ServerConfiguration{{
@@ -81,32 +103,32 @@ func NewHttpClient() *http.Client {
81103
}
82104
}
83105

84-
func (c *Client) ListDataCenters() ([]DataCenter, error) {
106+
func (c *RealClient) ListDataCenters() ([]DataCenter, error) {
85107
datacenters, r, err := c.api.MetadataAPI.MetadataGetDatacenters(c.ctx).Execute()
86108
return datacenters, errors.FormatAPIError(r, err)
87109
}
88110

89-
func (c *Client) ListDomains(teamId int) ([]Domain, error) {
111+
func (c *RealClient) ListDomains(teamId int) ([]Domain, error) {
90112
domains, r, err := c.api.DomainsAPI.DomainsListDomains(c.ctx, float32(teamId)).Execute()
91113
return domains, errors.FormatAPIError(r, err)
92114
}
93115

94-
func (c *Client) GetDomain(teamId int, domainName string) (*Domain, error) {
116+
func (c *RealClient) GetDomain(teamId int, domainName string) (*Domain, error) {
95117
domain, r, err := c.api.DomainsAPI.DomainsGetDomain(c.ctx, float32(teamId), domainName).Execute()
96118
return domain, errors.FormatAPIError(r, err)
97119
}
98120

99-
func (c *Client) CreateDomain(teamId int, domainName string) (*Domain, error) {
121+
func (c *RealClient) CreateDomain(teamId int, domainName string) (*Domain, error) {
100122
domain, r, err := c.api.DomainsAPI.DomainsCreateDomain(c.ctx, float32(teamId), domainName).Execute()
101123
return domain, errors.FormatAPIError(r, err)
102124
}
103125

104-
func (c *Client) DeleteDomain(teamId int, domainName string) error {
126+
func (c *RealClient) DeleteDomain(teamId int, domainName string) error {
105127
r, err := c.api.DomainsAPI.DomainsDeleteDomain(c.ctx, float32(teamId), domainName).Execute()
106128
return errors.FormatAPIError(r, err)
107129
}
108130

109-
func (c *Client) UpdateDomain(
131+
func (c *RealClient) UpdateDomain(
110132
teamId int, domainName string, args UpdateDomainArgs,
111133
) (*Domain, error) {
112134
domain, r, err := c.api.DomainsAPI.
@@ -116,15 +138,15 @@ func (c *Client) UpdateDomain(
116138
return domain, errors.FormatAPIError(r, err)
117139
}
118140

119-
func (c *Client) VerifyDomain(
141+
func (c *RealClient) VerifyDomain(
120142
teamId int, domainName string,
121143
) (*DomainVerificationStatus, error) {
122144
status, r, err := c.api.DomainsAPI.
123145
DomainsVerifyDomain(c.ctx, float32(teamId), domainName).Execute()
124146
return status, errors.FormatAPIError(r, err)
125147
}
126148

127-
func (c *Client) UpdateWorkspaceConnections(
149+
func (c *RealClient) UpdateWorkspaceConnections(
128150
teamId int, domainName string, connections PathToWorkspaces,
129151
) (*Domain, error) {
130152
req := make(map[string][]int)
@@ -141,7 +163,7 @@ func (c *Client) UpdateWorkspaceConnections(
141163
return domain, errors.FormatAPIError(r, err)
142164
}
143165

144-
func (c *Client) ListBaseimages() ([]Baseimage, error) {
166+
func (c *RealClient) ListBaseimages() ([]Baseimage, error) {
145167
baseimages, r, err := c.api.MetadataAPI.MetadataGetWorkspaceBaseImages(c.ctx).Execute()
146168
return baseimages, errors.FormatAPIError(r, err)
147169
}

api/errors/errors.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,11 @@ func IsRetryable(err error) bool {
108108
}
109109
return false
110110
}
111+
112+
func IsNotFound(err error) bool {
113+
if err == nil {
114+
return false
115+
}
116+
msg := err.Error()
117+
return strings.Contains(msg, "error 404")
118+
}

0 commit comments

Comments
 (0)