-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient.go
More file actions
38 lines (32 loc) · 918 Bytes
/
client.go
File metadata and controls
38 lines (32 loc) · 918 Bytes
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
// Copyright (c) Codesphere Inc.
// SPDX-License-Identifier: Apache-2.0
package cmd
//go:generate mockery
import (
"context"
"fmt"
"net/url"
"github.com/codesphere-cloud/cs-go/api"
"github.com/codesphere-cloud/cs-go/pkg/cs"
)
type Client interface {
ListTeams() ([]api.Team, error)
ListWorkspaces(teamId int) ([]api.Workspace, error)
StartPipelines(workspaceId int, pipelineStage string) error
SetEnvVarOnWorkspace(workspaceId int, vars map[string]string) error
}
func NewClient(opts GlobalOptions) (Client, error) {
token, err := cs.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,
})
return client, nil
}