-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkspace_config_files.go
More file actions
51 lines (43 loc) · 1.53 KB
/
workspace_config_files.go
File metadata and controls
51 lines (43 loc) · 1.53 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
package api
import (
"context"
"fmt"
"gopkg.in/nullstone-io/go-api-client.v0/response"
"io"
"net/http"
)
type WorkspaceConfigFiles struct {
Client *Client
}
func (w WorkspaceConfigFiles) configPath(stackId, blockId, envId int64) string {
return fmt.Sprintf("orgs/%s/stacks/%d/blocks/%d/envs/%d/config", w.Client.Config.OrgName, stackId, blockId, envId)
}
func (w WorkspaceConfigFiles) overridesPath(stackId, blockId, envId int64) string {
return fmt.Sprintf("orgs/%s/stacks/%d/blocks/%d/envs/%d/config_variables", w.Client.Config.OrgName, stackId, blockId, envId)
}
// GetConfigFile - GET /orgs/:orgName/stacks/:stackId/blocks/:blockId/envs/:envId/config
func (w WorkspaceConfigFiles) GetConfigFile(ctx context.Context, stackId, blockId, envId int64, file io.Writer) error {
res, err := w.Client.Do(ctx, http.MethodGet, w.configPath(stackId, blockId, envId), nil, nil, nil)
if err != nil {
return err
}
if err := response.ReadFile(res, file); response.IsNotFoundError(err) {
return nil
} else if err != nil {
return err
}
return nil
}
// GetOverridesFile - GET /orgs/:orgName/stacks/:stackId/blocks/:blockId/envs/:envId/config_variables
func (w WorkspaceConfigFiles) GetOverridesFile(ctx context.Context, stackId, blockId, envId int64, file io.Writer) error {
res, err := w.Client.Do(ctx, http.MethodGet, w.overridesPath(stackId, blockId, envId), nil, nil, nil)
if err != nil {
return err
}
if err := response.ReadFile(res, file); response.IsNotFoundError(err) {
return nil
} else if err != nil {
return err
}
return nil
}