Skip to content
Open
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
6 changes: 5 additions & 1 deletion .mockery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ formatter: gofmt
log-level: info
structname: "{{.Mock}}{{.InterfaceName}}"
pkgname: "{{.SrcPackageName}}"
recursive: false
recursive: true
require-template-schema-exists: true
template: testify
template-schema: "{{.Template}}.schema.json"
Expand All @@ -30,6 +30,10 @@ packages:
config:
all: true
interfaces:
github.com/codesphere-cloud/cs-go/pkg/cs:
config:
all: true
interfaces:
github.com/codesphere-cloud/cs-go/pkg/io:
config:
all: true
Expand Down
20 changes: 10 additions & 10 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.23.2
Version: v0.24.1
License: MIT
License URL: https://gitea.com/gitea/go-sdk/src/tag/gitea/v0.23.2/gitea/LICENSE
License URL: https://gitea.com/gitea/go-sdk/src/tag/gitea/v0.24.1/gitea/LICENSE

----------
Module: dario.cat/mergo
Expand All @@ -17,9 +17,9 @@ License URL: https://github.com/imdario/mergo/blob/v1.0.2/LICENSE

----------
Module: github.com/42wim/httpsig
Version: v1.2.3
Version: v1.2.4
License: BSD-3-Clause
License URL: https://github.com/42wim/httpsig/blob/v1.2.3/LICENSE
License URL: https://github.com/42wim/httpsig/blob/v1.2.4/LICENSE

----------
Module: github.com/Masterminds/semver/v3
Expand All @@ -29,9 +29,9 @@ License URL: https://github.com/Masterminds/semver/blob/v3.4.0/LICENSE.txt

----------
Module: github.com/ProtonMail/go-crypto
Version: v1.3.0
Version: v1.4.0
License: BSD-3-Clause
License URL: https://github.com/ProtonMail/go-crypto/blob/v1.3.0/LICENSE
License URL: https://github.com/ProtonMail/go-crypto/blob/v1.4.0/LICENSE

----------
Module: github.com/beorn7/perks/quantile
Expand Down Expand Up @@ -125,9 +125,9 @@ License URL: https://github.com/go-git/go-billy/blob/v5.8.0/LICENSE

----------
Module: github.com/go-git/go-git/v5
Version: v5.17.0
Version: v5.17.1
License: Apache-2.0
License URL: https://github.com/go-git/go-git/blob/v5.17.0/LICENSE
License URL: https://github.com/go-git/go-git/blob/v5.17.1/LICENSE

----------
Module: github.com/go-logr/logr
Expand Down Expand Up @@ -395,9 +395,9 @@ License URL: https://cs.opensource.google/go/x/net/+/v0.52.0:LICENSE

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

----------
Module: golang.org/x/sync/errgroup
Expand Down
48 changes: 35 additions & 13 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,34 @@ import (
"context"
"net/http"
"net/url"
"time"

"github.com/codesphere-cloud/cs-go/api/errors"
"github.com/codesphere-cloud/cs-go/api/openapi_client"
)

type Client struct {
type Client interface {
ListTeams() ([]Team, error)
ListWorkspaces(teamId int) ([]Workspace, error)
ListBaseimages() ([]Baseimage, error)
GetWorkspace(workspaceId int) (Workspace, error)
WorkspaceStatus(workspaceId int) (*WorkspaceStatus, error)
WaitForWorkspaceRunning(workspace *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() ([]WorkspacePlan, error)
DeployWorkspace(args DeployWorkspaceArgs) (*Workspace, error)
DeleteWorkspace(wsId int) error
StartPipelineStage(wsId int, profile string, stage string) error
GetPipelineState(wsId int, stage string) ([]PipelineStatus, error)
GitPull(wsId int, remote string, branch string) error
DeployLandscape(wsId int, profile string) error
WakeUpWorkspace(wsId int, token string, profile string, timeout time.Duration) error
}

type RealClient struct {
ctx context.Context
api *openapi_client.APIClient
time Time
Expand Down Expand Up @@ -41,15 +63,15 @@ func (c Configuration) GetApiUrl() *url.URL {
}

// For use in tests
func NewClientWithCustomDeps(ctx context.Context, opts Configuration, api *openapi_client.APIClient, time Time) *Client {
return &Client{
func NewClientWithCustomDeps(ctx context.Context, opts Configuration, api *openapi_client.APIClient, time Time) *RealClient {
return &RealClient{
ctx: context.WithValue(ctx, openapi_client.ContextAccessToken, opts.Token),
api: api,
time: time,
}
}

func NewClient(ctx context.Context, opts Configuration) *Client {
func NewClient(ctx context.Context, opts Configuration) *RealClient {
cfg := openapi_client.NewConfiguration()
cfg.HTTPClient = NewHttpClient()
cfg.Servers = []openapi_client.ServerConfiguration{{
Expand Down Expand Up @@ -81,32 +103,32 @@ func NewHttpClient() *http.Client {
}
}

func (c *Client) ListDataCenters() ([]DataCenter, error) {
func (c *RealClient) ListDataCenters() ([]DataCenter, error) {
datacenters, r, err := c.api.MetadataAPI.MetadataGetDatacenters(c.ctx).Execute()
return datacenters, errors.FormatAPIError(r, err)
}

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

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

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

func (c *Client) DeleteDomain(teamId int, domainName string) error {
func (c *RealClient) DeleteDomain(teamId int, domainName string) error {
r, err := c.api.DomainsAPI.DomainsDeleteDomain(c.ctx, float32(teamId), domainName).Execute()
return errors.FormatAPIError(r, err)
}

func (c *Client) UpdateDomain(
func (c *RealClient) UpdateDomain(
teamId int, domainName string, args UpdateDomainArgs,
) (*Domain, error) {
domain, r, err := c.api.DomainsAPI.
Expand All @@ -116,15 +138,15 @@ func (c *Client) UpdateDomain(
return domain, errors.FormatAPIError(r, err)
}

func (c *Client) VerifyDomain(
func (c *RealClient) VerifyDomain(
teamId int, domainName string,
) (*DomainVerificationStatus, error) {
status, r, err := c.api.DomainsAPI.
DomainsVerifyDomain(c.ctx, float32(teamId), domainName).Execute()
return status, errors.FormatAPIError(r, err)
}

func (c *Client) UpdateWorkspaceConnections(
func (c *RealClient) UpdateWorkspaceConnections(
teamId int, domainName string, connections PathToWorkspaces,
) (*Domain, error) {
req := make(map[string][]int)
Expand All @@ -141,7 +163,7 @@ func (c *Client) UpdateWorkspaceConnections(
return domain, errors.FormatAPIError(r, err)
}

func (c *Client) ListBaseimages() ([]Baseimage, error) {
func (c *RealClient) ListBaseimages() ([]Baseimage, error) {
baseimages, r, err := c.api.MetadataAPI.MetadataGetWorkspaceBaseImages(c.ctx).Execute()
return baseimages, errors.FormatAPIError(r, err)
}
8 changes: 8 additions & 0 deletions api/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,11 @@ func IsRetryable(err error) bool {
}
return false
}

func IsNotFound(err error) bool {
if err == nil {
return false
}
msg := err.Error()
return strings.Contains(msg, "error 404")
}
Loading
Loading