-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
251 lines (207 loc) · 12.6 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
package nuon
import (
"context"
"fmt"
"net/http"
"net/url"
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-playground/validator/v10"
genclient "github.com/nuonco/nuon-go/client"
"github.com/nuonco/nuon-go/models"
)
//
//go:generate -command swagger go run github.com/go-swagger/go-swagger/cmd/swagger
//go:generate swagger generate client --skip-tag-packages -f $NUON_API_URL/docs/doc.json
//go:generate -command mockgen go run github.com/golang/mock/mockgen
//go:generate mockgen -destination=mock.go -source=client.go -package=nuon
type Client interface {
SetOrgID(orgID string)
// get / create org
GetOrgs(ctx context.Context) ([]*models.AppOrg, error)
CreateOrg(ctx context.Context, req *models.ServiceCreateOrgRequest) (*models.AppOrg, error)
// current org
GetOrg(ctx context.Context) (*models.AppOrg, error)
GetOrgHealthChecks(ctx context.Context, limit *int64) ([]*models.AppOrgHealthCheck, error)
UpdateOrg(ctx context.Context, req *models.ServiceUpdateOrgRequest) (*models.AppOrg, error)
DeleteOrg(ctx context.Context) (bool, error)
// org invites and users
CreateOrgInvite(ctx context.Context, req *models.ServiceCreateOrgInviteRequest) (*models.AppOrgInvite, error)
GetOrgInvites(ctx context.Context, limit *int64) ([]*models.AppOrgInvite, error)
// app methods
GetApp(ctx context.Context, appID string) (*models.AppApp, error)
GetApps(ctx context.Context) ([]*models.AppApp, error)
CreateApp(ctx context.Context, req *models.ServiceCreateAppRequest) (*models.AppApp, error)
UpdateApp(ctx context.Context, appID string, req *models.ServiceUpdateAppRequest) (*models.AppApp, error)
DeleteApp(ctx context.Context, appID string) (bool, error)
// app sandbox config methods
CreateAppSandboxConfig(ctx context.Context, appID string, req *models.ServiceCreateAppSandboxConfigRequest) (*models.AppAppSandboxConfig, error)
GetAppSandboxLatestConfig(ctx context.Context, appID string) (*models.AppAppSandboxConfig, error)
GetAppSandboxConfigs(ctx context.Context, appID string) ([]*models.AppAppSandboxConfig, error)
// app runner config methods
CreateAppRunnerConfig(ctx context.Context, appID string, req *models.ServiceCreateAppRunnerConfigRequest) (*models.AppAppRunnerConfig, error)
GetAppRunnerLatestConfig(ctx context.Context, appID string) (*models.AppAppRunnerConfig, error)
GetAppRunnerConfigs(ctx context.Context, appID string) ([]*models.AppAppRunnerConfig, error)
// app config methods
GetAppConfigTemplate(ctx context.Context, appID string, typ models.ServiceAppConfigTemplateType) (*models.ServiceAppConfigTemplate, error)
CreateAppConfig(ctx context.Context, appID string, req *models.ServiceCreateAppConfigRequest) (*models.AppAppConfig, error)
GetAppConfig(ctx context.Context, appID, appConfigID string) (*models.AppAppConfig, error)
GetAppLatestConfig(ctx context.Context, appID string) (*models.AppAppConfig, error)
GetAppConfigs(ctx context.Context, appID string) ([]*models.AppAppConfig, error)
UpdateAppConfig(ctx context.Context, appID, appConfigID string, req *models.ServiceUpdateAppConfigRequest) (*models.AppAppConfig, error)
// app input config methods
CreateAppInputConfig(ctx context.Context, appID string, req *models.ServiceCreateAppInputConfigRequest) (*models.AppAppInputConfig, error)
GetAppInputLatestConfig(ctx context.Context, appID string) (*models.AppAppInputConfig, error)
GetAppInputConfigs(ctx context.Context, appID string) ([]*models.AppAppInputConfig, error)
// app secret methods
CreateAppSecret(ctx context.Context, appID string, req *models.ServiceCreateAppSecretRequest) (*models.AppAppSecret, error)
GetAppSecrets(ctx context.Context, appID string) ([]*models.AppAppSecret, error)
DeleteAppSecret(ctx context.Context, appID, secretID string) (bool, error)
// app installer methods
CreateInstaller(ctx context.Context, req *models.ServiceCreateInstallerRequest) (*models.AppInstaller, error)
UpdateInstaller(ctx context.Context, installerID string, req *models.ServiceUpdateInstallerRequest) (*models.AppInstaller, error)
DeleteInstaller(ctx context.Context, installerID string) (bool, error)
GetInstaller(ctx context.Context, installerID string) (*models.AppInstaller, error)
GetInstallers(ctx context.Context) ([]*models.AppInstaller, error)
RenderInstaller(ctx context.Context, installerID string) (*models.ServiceRenderedInstaller, error)
// general methods
GetCLIConfig(ctx context.Context) (*models.ServiceCLIConfig, error)
GetCurrentUser(ctx context.Context) (*models.AppAccount, error)
GetCloudPlatformRegions(ctx context.Context, cloudPlatform string) ([]*models.AppCloudPlatformRegion, error)
// vcs connections
CreateVCSConnection(ctx context.Context, req *models.ServiceCreateConnectionRequest) (*models.AppVCSConnection, error)
CreateVCSConnectionCallback(ctx context.Context, req *models.ServiceCreateConnectionCallbackRequest) (*models.AppVCSConnection, error)
GetVCSConnections(ctx context.Context) ([]*models.AppVCSConnection, error)
GetVCSConnection(ctx context.Context, connID string) (*models.AppVCSConnection, error)
GetAllVCSConnectedRepos(ctx context.Context) ([]*models.ServiceRepository, error)
// installs
CreateInstall(ctx context.Context, appID string, req *models.ServiceCreateInstallRequest) (*models.AppInstall, error)
GetAppInstalls(ctx context.Context, appID string) ([]*models.AppInstall, error)
GetAllInstalls(ctx context.Context) ([]*models.AppInstall, error)
GetInstall(ctx context.Context, installID string) (*models.AppInstall, error)
UpdateInstall(ctx context.Context, installID string, req *models.ServiceUpdateInstallRequest) (*models.AppInstall, error)
DeleteInstall(ctx context.Context, installID string) (bool, error)
ReprovisionInstall(ctx context.Context, installID string) error
DeprovisionInstall(ctx context.Context, installID string) error
// install deploys
GetInstallDeploys(ctx context.Context, installID string) ([]*models.AppInstallDeploy, error)
CreateInstallDeploy(ctx context.Context, installID string, req *models.ServiceCreateInstallDeployRequest) (*models.AppInstallDeploy, error)
GetInstallDeploy(ctx context.Context, installID, deployID string) (*models.AppInstallDeploy, error)
GetInstallLatestDeploy(ctx context.Context, installID string) (*models.AppInstallDeploy, error)
// install components
GetInstallComponents(ctx context.Context, installID string) ([]*models.AppInstallComponent, error)
TeardownInstallComponent(ctx context.Context, installID, componentID string) (*models.AppInstallDeploy, error)
TeardownInstallComponents(ctx context.Context, installID string) error
DeployInstallComponents(ctx context.Context, installID string) error
GetInstallComponentDeploys(ctx context.Context, installID, componentID string) ([]*models.AppInstallDeploy, error)
GetInstallComponentLatestDeploy(ctx context.Context, installID, componentID string) (*models.AppInstallDeploy, error)
// install sandbox runs
GetInstallSandboxRuns(ctx context.Context, installID string) ([]*models.AppInstallSandboxRun, error)
// install inputs
GetInstallInputs(ctx context.Context, installID string) ([]*models.AppInstallInputs, error)
GetInstallCurrentInputs(ctx context.Context, installID string) (*models.AppInstallInputs, error)
CreateInstallInputs(ctx context.Context, installID string, req *models.ServiceCreateInstallInputsRequest) (*models.AppInstallInputs, error)
// components
GetAllComponents(ctx context.Context) ([]*models.AppComponent, error)
GetAppComponents(ctx context.Context, appID string) ([]*models.AppComponent, error)
GetAppComponent(ctx context.Context, appID, componentNameOrID string) (*models.AppComponent, error)
CreateComponent(ctx context.Context, appID string, req *models.ServiceCreateComponentRequest) (*models.AppComponent, error)
GetComponent(ctx context.Context, componentID string) (*models.AppComponent, error)
UpdateComponent(ctx context.Context, componentID string, req *models.ServiceUpdateComponentRequest) (*models.AppComponent, error)
DeleteComponent(ctx context.Context, componentID string) (bool, error)
// component configs
CreateTerraformModuleComponentConfig(ctx context.Context, componentID string, req *models.ServiceCreateTerraformModuleComponentConfigRequest) (*models.AppTerraformModuleComponentConfig, error)
CreateHelmComponentConfig(ctx context.Context, componentID string, req *models.ServiceCreateHelmComponentConfigRequest) (*models.AppHelmComponentConfig, error)
CreateDockerBuildComponentConfig(ctx context.Context, componentID string, req *models.ServiceCreateDockerBuildComponentConfigRequest) (*models.AppDockerBuildComponentConfig, error)
CreateExternalImageComponentConfig(ctx context.Context, componentID string, req *models.ServiceCreateExternalImageComponentConfigRequest) (*models.AppExternalImageComponentConfig, error)
CreateJobComponentConfig(ctx context.Context, componentID string, req *models.ServiceCreateJobComponentConfigRequest) (*models.AppJobComponentConfig, error)
GetComponentConfigs(ctx context.Context, componentID string) ([]*models.AppComponentConfigConnection, error)
GetComponentLatestConfig(ctx context.Context, componentID string) (*models.AppComponentConfigConnection, error)
// builds
CreateComponentBuild(ctx context.Context, componentID string, req *models.ServiceCreateComponentBuildRequest) (*models.AppComponentBuild, error)
GetComponentBuilds(ctx context.Context, componentID, appID string, limit *int64) ([]*models.AppComponentBuild, error)
GetComponentLatestBuild(ctx context.Context, componentID string) (*models.AppComponentBuild, error)
GetComponentBuild(ctx context.Context, componentID, buildID string) (*models.AppComponentBuild, error)
GetBuild(ctx context.Context, buildID string) (*models.AppComponentBuild, error)
// component releases
GetAppReleases(ctx context.Context, appID string) ([]*models.AppComponentRelease, error)
GetComponentReleases(ctx context.Context, componentID string) ([]*models.AppComponentRelease, error)
CreateComponentRelease(ctx context.Context, componentID string, req *models.ServiceCreateComponentReleaseRequest) (*models.AppComponentRelease, error)
GetRelease(ctx context.Context, releaseID string) (*models.AppComponentRelease, error)
GetReleaseSteps(ctx context.Context, releaseID string) ([]*models.AppComponentReleaseStep, error)
// actions
GetActionWorkflows(ctx context.Context, appID string) ([]*models.AppActionWorkflow, error)
GetActionWorkflow(ctx context.Context, actionWorkflowID string) (*models.AppActionWorkflow, error)
CreateActionWorkflow(ctx context.Context, appID string, req *models.ServiceCreateAppActionWorkflowRequest) (*models.AppActionWorkflow, error)
UpdateActionWorkflow(ctx context.Context, actionWorkflowID string, req *models.ServiceUpdateActionWorkflowRequest) (*models.AppActionWorkflow, error)
DeleteActionWorkflow(ctx context.Context, actionWorkflowID string) error
GetActionWorkflowConfigs(ctx context.Context, actionWorkflowID string) ([]*models.AppActionWorkflowConfig, error)
GetActionWorkflowConfig(ctx context.Context, actionWorkflowConfigID string) (*models.AppActionWorkflowConfig, error)
CreateActionWorkflowConfig(ctx context.Context, actionWorkflowID string, req *models.ServiceCreateActionWorkflowConfigRequest) (*models.AppActionWorkflowConfig, error)
}
var _ Client = (*client)(nil)
type client struct {
v *validator.Validate
APIURL string `validate:"required"`
APIToken string
OrgID string
genClient *genclient.Nuon
appTransport *appTransport
}
type clientOption func(*client) error
func New(opts ...clientOption) (*client, error) {
c := &client{}
for _, opt := range opts {
if err := opt(c); err != nil {
return nil, err
}
}
if c.v == nil {
c.v = validator.New()
}
if err := c.v.Struct(c); err != nil {
return nil, err
}
apiURL, err := url.Parse(c.APIURL)
if err != nil {
return nil, fmt.Errorf("unable to parse api url: %w", err)
}
transport := httptransport.New(apiURL.Host, "", []string{apiURL.Scheme})
appTransport := &appTransport{
authToken: c.APIToken,
orgID: c.OrgID,
transport: http.DefaultTransport,
}
c.appTransport = appTransport
transport.Transport = appTransport
genClient := genclient.New(transport, nil)
c.genClient = genClient
return c, nil
}
// WithAuthToken specifies the auth token to use
func WithAuthToken(token string) clientOption {
return func(c *client) error {
c.APIToken = token
return nil
}
}
// WithURL specifies the url to use
func WithURL(url string) clientOption {
return func(c *client) error {
c.APIURL = url
return nil
}
}
// WithOrgID specifies the org id to use
func WithOrgID(orgID string) clientOption {
return func(c *client) error {
c.OrgID = orgID
return nil
}
}
// WithValidator specifies a validator to use
func WithValidator(v *validator.Validate) clientOption {
return func(c *client) error {
c.v = v
return nil
}
}