-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
212 lines (202 loc) · 5.62 KB
/
client.go
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package api
import (
"bytes"
"context"
"encoding/json"
"fmt"
"gopkg.in/nullstone-io/go-api-client.v0/auth"
"io"
"net/http"
"net/url"
)
type Client struct {
Config Config
}
// Org
// Deprecated
func (c *Client) Org(orgName string) *Client {
clone := &Client{Config: c.Config}
clone.Config.OrgName = orgName
return clone
}
// WithApiKey
// Deprecated
func (c *Client) WithApiKey(apiKey string) *Client {
clone := &Client{Config: c.Config}
clone.Config.AccessTokenSource = auth.RawAccessTokenSource{AccessToken: apiKey}
return clone
}
func (c *Client) CurrentUser() CurrentUser {
return CurrentUser{Client: c}
}
func (c *Client) Organizations() Organizations {
return Organizations{Client: c}
}
func (c *Client) Stacks() Stacks {
return Stacks{Client: c}
}
func (c *Client) StacksByName() StacksByName {
return StacksByName{Client: c}
}
func (c *Client) Environments() Environments {
return Environments{Client: c}
}
func (c *Client) PreviewEnvs() PreviewEnvs {
return PreviewEnvs{Client: c}
}
func (c *Client) EnvironmentsByName() EnvironmentsByName {
return EnvironmentsByName{Client: c}
}
func (c *Client) EnvInfraConfigurations() EnvInfraConfigurations {
return EnvInfraConfigurations{Client: c}
}
func (c *Client) PipelineInfraConfigurations() PipelineInfraConfigurations {
return PipelineInfraConfigurations{Client: c}
}
func (c *Client) EnvRuns() EnvRuns {
return EnvRuns{Client: c}
}
func (c *Client) Providers() Providers {
return Providers{Client: c}
}
func (c *Client) ProviderCredentials() ProviderCredentials {
return ProviderCredentials{Client: c}
}
func (c *Client) Blocks() Blocks {
return Blocks{Client: c}
}
func (c *Client) BlockSyncs() BlockSyncs {
return BlockSyncs{Client: c}
}
func (c *Client) PipelineBlockSyncs() PipelineBlockSyncs {
return PipelineBlockSyncs{Client: c}
}
func (c *Client) Apps() Apps {
return Apps{Client: c}
}
func (c *Client) AppCapabilities() AppCapabilities {
return AppCapabilities{Client: c}
}
func (c *Client) AppPipelineCapabilities() AppPipelineCapabilities {
return AppPipelineCapabilities{Client: c}
}
func (c *Client) AppEnvs() AppEnvs {
return AppEnvs{Client: c}
}
func (c *Client) EnvVariables() EnvVariables {
return EnvVariables{Client: c}
}
func (c *Client) Builds() Builds { return Builds{Client: c} }
func (c *Client) BuildLogs() BuildLogs { return BuildLogs{Client: c} }
func (c *Client) Deploys() Deploys {
return Deploys{Client: c}
}
func (c *Client) DeployLogs() DeployLogs {
return DeployLogs{Client: c}
}
func (c *Client) Workspaces() Workspaces {
return Workspaces{Client: c}
}
func (c *Client) WorkspaceDetails() WorkspaceDetails {
return WorkspaceDetails{Client: c}
}
func (c *Client) WorkspaceChanges() WorkspaceChanges {
return WorkspaceChanges{Client: c}
}
func (c *Client) WorkspaceModule() WorkspaceModule {
return WorkspaceModule{Client: c}
}
func (c *Client) WorkspaceConfigs() WorkspaceConfigs {
return WorkspaceConfigs{Client: c}
}
func (c *Client) WorkspaceConfigFiles() WorkspaceConfigFiles {
return WorkspaceConfigFiles{Client: c}
}
func (c *Client) WorkspaceOutputs() WorkspaceOutputs {
return WorkspaceOutputs{Client: c}
}
func (c *Client) WorkspaceOutputCredentials() WorkspaceOutputCredentials {
return WorkspaceOutputCredentials{Client: c}
}
func (c *Client) WorkspaceVariables() WorkspaceVariables {
return WorkspaceVariables{Client: c}
}
func (c *Client) IntentWorkflows() IntentWorkflows {
return IntentWorkflows{Client: c}
}
func (c *Client) WorkspaceWorkflows() WorkspaceWorkflows { return WorkspaceWorkflows{Client: c} }
func (c *Client) Runs() Runs {
return Runs{Client: c}
}
func (c *Client) RunConfigs() RunConfigs {
return RunConfigs{Client: c}
}
func (c *Client) PromotionConfigs() PromotionConfigs {
return PromotionConfigs{Client: c}
}
func (c *Client) RunLogs() RunLogs {
return RunLogs{Client: c}
}
func (c *Client) AutogenSubdomain() AutogenSubdomain {
return AutogenSubdomain{Client: c}
}
func (c *Client) AutogenSubdomainDelegation() AutogenSubdomainDelegation {
return AutogenSubdomainDelegation{Client: c}
}
func (c *Client) Domains() Domains {
return Domains{Client: c}
}
func (c *Client) Subdomains() Subdomains {
return Subdomains{Client: c}
}
func (c *Client) SubdomainWorkspaces() SubdomainWorkspaces {
return SubdomainWorkspaces{Client: c}
}
func (c *Client) Modules() Modules {
return Modules{Client: c}
}
func (c *Client) ModuleVersions() ModuleVersions {
return ModuleVersions{Client: c}
}
func (c *Client) Integrations() Integrations {
return Integrations{Client: c}
}
func (c *Client) EnvEvents() EnvEvents {
return EnvEvents{Client: c}
}
func (c *Client) Do(ctx context.Context, method string, relativePath string, query url.Values, headers map[string]string, body interface{}) (*http.Response, error) {
var bodyReader io.Reader
if jrm, ok := body.(json.RawMessage); ok {
bodyReader = bytes.NewReader(jrm)
if headers == nil {
headers = map[string]string{}
}
if headers["Content-Type"] == "" {
headers["Content-Type"] = "application/json"
}
} else {
bodyReader, _ = body.(io.Reader)
}
u, err := c.Config.ConstructUrl(relativePath, query)
if err != nil {
return nil, fmt.Errorf("invalid request url: %w", err)
}
req, err := http.NewRequestWithContext(ctx, method, u.String(), bodyReader)
if err != nil {
return nil, fmt.Errorf("error creating request: %w", err)
}
for k, v := range headers {
req.Header.Set(k, v)
}
if err := c.Config.AddAuthorizationHeader(req.Context(), req.Header); err != nil {
return nil, err
}
httpClient := &http.Client{
Transport: c.Config.CreateTransport(),
}
res, err := httpClient.Do(req)
if err != nil {
return nil, fmt.Errorf("error issuing request: %w", err)
}
return res, nil
}