-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvironmentautomation.go
210 lines (184 loc) · 8.54 KB
/
environmentautomation.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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package gitpod
import (
"context"
"net/http"
"github.com/gitpod-io/gitpod-sdk-go/internal/apijson"
"github.com/gitpod-io/gitpod-sdk-go/internal/param"
"github.com/gitpod-io/gitpod-sdk-go/internal/requestconfig"
"github.com/gitpod-io/gitpod-sdk-go/option"
"github.com/gitpod-io/gitpod-sdk-go/shared"
)
// EnvironmentAutomationService contains methods and other services that help with
// interacting with the gitpod API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewEnvironmentAutomationService] method instead.
type EnvironmentAutomationService struct {
Options []option.RequestOption
Services *EnvironmentAutomationServiceService
Tasks *EnvironmentAutomationTaskService
}
// NewEnvironmentAutomationService generates a new service that applies the given
// options to each request. These options are applied after the parent client's
// options (if there is one), and before any request-specific options.
func NewEnvironmentAutomationService(opts ...option.RequestOption) (r *EnvironmentAutomationService) {
r = &EnvironmentAutomationService{}
r.Options = opts
r.Services = NewEnvironmentAutomationServiceService(opts...)
r.Tasks = NewEnvironmentAutomationTaskService(opts...)
return
}
// Upserts the automations file for the given environment.
//
// Use this method to:
//
// - Configure environment automations
// - Update automation settings
// - Manage automation files
//
// ### Examples
//
// - Update automations file:
//
// Updates or creates the automations configuration.
//
// ```yaml
// environmentId: "07e03a28-65a5-4d98-b532-8ea67b188048"
// automationsFile:
// services:
// web-server:
// name: "Web Server"
// description: "Development web server"
// commands:
// start: "npm run dev"
// ready: "curl -s http://localhost:3000"
// triggeredBy:
// - postDevcontainerStart
// tasks:
// build:
// name: "Build Project"
// description: "Builds the project artifacts"
// command: "npm run build"
// triggeredBy:
// - postEnvironmentStart
// ```
func (r *EnvironmentAutomationService) Upsert(ctx context.Context, body EnvironmentAutomationUpsertParams, opts ...option.RequestOption) (res *EnvironmentAutomationUpsertResponse, err error) {
opts = append(r.Options[:], opts...)
path := "gitpod.v1.EnvironmentAutomationService/UpsertAutomationsFile"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// WARN: Do not remove any field here, as it will break reading automation yaml
// files. We error if there are any unknown fields in the yaml (to ensure the yaml
// is correct), but would break if we removed any fields. This includes marking a
// field as "reserved" in the proto file, this will also break reading the yaml.
type AutomationsFileParam struct {
Services param.Field[map[string]AutomationsFileServiceParam] `json:"services"`
Tasks param.Field[map[string]AutomationsFileTaskParam] `json:"tasks"`
}
func (r AutomationsFileParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type AutomationsFileServiceParam struct {
Commands param.Field[AutomationsFileServicesCommandsParam] `json:"commands"`
Description param.Field[string] `json:"description"`
Name param.Field[string] `json:"name"`
RunsOn param.Field[shared.RunsOnParam] `json:"runsOn"`
TriggeredBy param.Field[[]AutomationsFileServicesTriggeredBy] `json:"triggeredBy"`
}
func (r AutomationsFileServiceParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type AutomationsFileServicesCommandsParam struct {
// ready is an optional command that is run repeatedly until it exits with a zero
// exit code. If set, the service will first go into a Starting phase, and then
// into a Running phase once the ready command exits with a zero exit code.
Ready param.Field[string] `json:"ready"`
// start is the command to start and run the service. If start exits, the service
// will transition to the following phase:
//
// - Stopped: if the exit code is 0
// - Failed: if the exit code is not 0 If the stop command is not set, the start
// command will receive a SIGTERM signal when the service is requested to stop.
// If it does not exit within 2 minutes, it will receive a SIGKILL signal.
Start param.Field[string] `json:"start"`
// stop is an optional command that runs when the service is requested to stop. If
// set, instead of sending a SIGTERM signal to the start command, the stop command
// will be run. Once the stop command exits, the start command will receive a
// SIGKILL signal. If the stop command exits with a non-zero exit code, the service
// will transition to the Failed phase. If the stop command does not exit within 2
// minutes, a SIGKILL signal will be sent to both the start and stop commands.
Stop param.Field[string] `json:"stop"`
}
func (r AutomationsFileServicesCommandsParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type AutomationsFileServicesTriggeredBy string
const (
AutomationsFileServicesTriggeredByManual AutomationsFileServicesTriggeredBy = "manual"
AutomationsFileServicesTriggeredByPostEnvironmentStart AutomationsFileServicesTriggeredBy = "postEnvironmentStart"
AutomationsFileServicesTriggeredByPostDevcontainerStart AutomationsFileServicesTriggeredBy = "postDevcontainerStart"
)
func (r AutomationsFileServicesTriggeredBy) IsKnown() bool {
switch r {
case AutomationsFileServicesTriggeredByManual, AutomationsFileServicesTriggeredByPostEnvironmentStart, AutomationsFileServicesTriggeredByPostDevcontainerStart:
return true
}
return false
}
type AutomationsFileTaskParam struct {
Command param.Field[string] `json:"command"`
DependsOn param.Field[[]string] `json:"dependsOn"`
Description param.Field[string] `json:"description"`
Name param.Field[string] `json:"name"`
RunsOn param.Field[shared.RunsOnParam] `json:"runsOn"`
TriggeredBy param.Field[[]AutomationsFileTasksTriggeredBy] `json:"triggeredBy"`
}
func (r AutomationsFileTaskParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type AutomationsFileTasksTriggeredBy string
const (
AutomationsFileTasksTriggeredByManual AutomationsFileTasksTriggeredBy = "manual"
AutomationsFileTasksTriggeredByPostEnvironmentStart AutomationsFileTasksTriggeredBy = "postEnvironmentStart"
AutomationsFileTasksTriggeredByPostDevcontainerStart AutomationsFileTasksTriggeredBy = "postDevcontainerStart"
)
func (r AutomationsFileTasksTriggeredBy) IsKnown() bool {
switch r {
case AutomationsFileTasksTriggeredByManual, AutomationsFileTasksTriggeredByPostEnvironmentStart, AutomationsFileTasksTriggeredByPostDevcontainerStart:
return true
}
return false
}
type EnvironmentAutomationUpsertResponse struct {
UpdatedServiceIDs []string `json:"updatedServiceIds"`
UpdatedTaskIDs []string `json:"updatedTaskIds"`
JSON environmentAutomationUpsertResponseJSON `json:"-"`
}
// environmentAutomationUpsertResponseJSON contains the JSON metadata for the
// struct [EnvironmentAutomationUpsertResponse]
type environmentAutomationUpsertResponseJSON struct {
UpdatedServiceIDs apijson.Field
UpdatedTaskIDs apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *EnvironmentAutomationUpsertResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r environmentAutomationUpsertResponseJSON) RawJSON() string {
return r.raw
}
type EnvironmentAutomationUpsertParams struct {
// WARN: Do not remove any field here, as it will break reading automation yaml
// files. We error if there are any unknown fields in the yaml (to ensure the yaml
// is correct), but would break if we removed any fields. This includes marking a
// field as "reserved" in the proto file, this will also break reading the yaml.
AutomationsFile param.Field[AutomationsFileParam] `json:"automationsFile"`
EnvironmentID param.Field[string] `json:"environmentId" format:"uuid"`
}
func (r EnvironmentAutomationUpsertParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}