-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmachine.go
311 lines (268 loc) · 9.39 KB
/
machine.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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package nestri
import (
"context"
"errors"
"fmt"
"net/http"
"reflect"
"github.com/nestrilabs/nestri-go-sdk/internal/apijson"
"github.com/nestrilabs/nestri-go-sdk/internal/requestconfig"
"github.com/nestrilabs/nestri-go-sdk/option"
"github.com/nestrilabs/nestri-go-sdk/shared"
"github.com/tidwall/gjson"
)
// MachineService contains methods and other services that help with interacting
// with the nestri 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 [NewMachineService] method instead.
type MachineService struct {
Options []option.RequestOption
}
// NewMachineService 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 NewMachineService(opts ...option.RequestOption) (r *MachineService) {
r = &MachineService{}
r.Options = opts
return
}
// Associates a machine with the currently authenticated user's account, enabling
// them to manage and control the machine
func (r *MachineService) New(ctx context.Context, fingerprint string, opts ...option.RequestOption) (res *MachineNewResponse, err error) {
opts = append(r.Options[:], opts...)
if fingerprint == "" {
err = errors.New("missing required fingerprint parameter")
return
}
path := fmt.Sprintf("machines/%s", fingerprint)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
return
}
// Fetches detailed information about a specific machine using its unique
// fingerprint derived from the Linux machine ID
func (r *MachineService) Get(ctx context.Context, fingerprint string, opts ...option.RequestOption) (res *MachineGetResponse, err error) {
opts = append(r.Options[:], opts...)
if fingerprint == "" {
err = errors.New("missing required fingerprint parameter")
return
}
path := fmt.Sprintf("machines/%s", fingerprint)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Returns a list of all machines registered to the authenticated user in the
// Nestri network
func (r *MachineService) List(ctx context.Context, opts ...option.RequestOption) (res *MachineListResponse, err error) {
opts = append(r.Options[:], opts...)
path := "machines"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Removes the association between a machine and the authenticated user's account.
// This does not delete the machine itself, but removes the user's ability to
// manage it
func (r *MachineService) Delete(ctx context.Context, fingerprint string, opts ...option.RequestOption) (res *MachineDeleteResponse, err error) {
opts = append(r.Options[:], opts...)
if fingerprint == "" {
err = errors.New("missing required fingerprint parameter")
return
}
path := fmt.Sprintf("machines/%s", fingerprint)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return
}
type MachineNewResponse struct {
Data MachineNewResponseData `json:"data,required"`
JSON machineNewResponseJSON `json:"-"`
}
// machineNewResponseJSON contains the JSON metadata for the struct
// [MachineNewResponse]
type machineNewResponseJSON struct {
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *MachineNewResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r machineNewResponseJSON) RawJSON() string {
return r.raw
}
type MachineNewResponseData string
const (
MachineNewResponseDataOk MachineNewResponseData = "ok"
)
func (r MachineNewResponseData) IsKnown() bool {
switch r {
case MachineNewResponseDataOk:
return true
}
return false
}
type MachineGetResponse struct {
// Represents a physical or virtual machine connected to the Nestri network..
Data MachineGetResponseData `json:"data,required"`
JSON machineGetResponseJSON `json:"-"`
}
// machineGetResponseJSON contains the JSON metadata for the struct
// [MachineGetResponse]
type machineGetResponseJSON struct {
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *MachineGetResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r machineGetResponseJSON) RawJSON() string {
return r.raw
}
// Represents a physical or virtual machine connected to the Nestri network..
type MachineGetResponseData struct {
// Unique object identifier. The format and length of IDs may change over time.
ID string `json:"id,required"`
// Represents a machine running on the Nestri network, containing its identifying
// information and metadata.
CreatedAt MachineGetResponseDataCreatedAtUnion `json:"createdAt,required"`
// A unique identifier derived from the machine's Linux machine ID.
Fingerprint string `json:"fingerprint,required"`
// The Linux hostname that identifies this machine
Hostname string `json:"hostname,required"`
JSON machineGetResponseDataJSON `json:"-"`
}
// machineGetResponseDataJSON contains the JSON metadata for the struct
// [MachineGetResponseData]
type machineGetResponseDataJSON struct {
ID apijson.Field
CreatedAt apijson.Field
Fingerprint apijson.Field
Hostname apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *MachineGetResponseData) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r machineGetResponseDataJSON) RawJSON() string {
return r.raw
}
// Represents a machine running on the Nestri network, containing its identifying
// information and metadata.
//
// Union satisfied by [shared.UnionString] or [shared.UnionFloat].
type MachineGetResponseDataCreatedAtUnion interface {
ImplementsMachineGetResponseDataCreatedAtUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*MachineGetResponseDataCreatedAtUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionFloat(0)),
},
)
}
type MachineListResponse struct {
// A list of machines associated with the user
Data []MachineListResponseData `json:"data,required"`
JSON machineListResponseJSON `json:"-"`
}
// machineListResponseJSON contains the JSON metadata for the struct
// [MachineListResponse]
type machineListResponseJSON struct {
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *MachineListResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r machineListResponseJSON) RawJSON() string {
return r.raw
}
// Represents a physical or virtual machine connected to the Nestri network..
type MachineListResponseData struct {
// Unique object identifier. The format and length of IDs may change over time.
ID string `json:"id,required"`
// Represents a machine running on the Nestri network, containing its identifying
// information and metadata.
CreatedAt MachineListResponseDataCreatedAtUnion `json:"createdAt,required"`
// A unique identifier derived from the machine's Linux machine ID.
Fingerprint string `json:"fingerprint,required"`
// The Linux hostname that identifies this machine
Hostname string `json:"hostname,required"`
JSON machineListResponseDataJSON `json:"-"`
}
// machineListResponseDataJSON contains the JSON metadata for the struct
// [MachineListResponseData]
type machineListResponseDataJSON struct {
ID apijson.Field
CreatedAt apijson.Field
Fingerprint apijson.Field
Hostname apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *MachineListResponseData) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r machineListResponseDataJSON) RawJSON() string {
return r.raw
}
// Represents a machine running on the Nestri network, containing its identifying
// information and metadata.
//
// Union satisfied by [shared.UnionString] or [shared.UnionFloat].
type MachineListResponseDataCreatedAtUnion interface {
ImplementsMachineListResponseDataCreatedAtUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*MachineListResponseDataCreatedAtUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionFloat(0)),
},
)
}
type MachineDeleteResponse struct {
Data MachineDeleteResponseData `json:"data,required"`
JSON machineDeleteResponseJSON `json:"-"`
}
// machineDeleteResponseJSON contains the JSON metadata for the struct
// [MachineDeleteResponse]
type machineDeleteResponseJSON struct {
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *MachineDeleteResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r machineDeleteResponseJSON) RawJSON() string {
return r.raw
}
type MachineDeleteResponseData string
const (
MachineDeleteResponseDataOk MachineDeleteResponseData = "ok"
)
func (r MachineDeleteResponseData) IsKnown() bool {
switch r {
case MachineDeleteResponseDataOk:
return true
}
return false
}