forked from scaleway/scaleway-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaccount_cli.go
274 lines (254 loc) · 6.25 KB
/
account_cli.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
// This file was automatically generated. DO NOT EDIT.
// If you have any remark or suggestion do not hesitate to open an issue.
package account
import (
"context"
"reflect"
"github.com/scaleway/scaleway-cli/internal/core"
"github.com/scaleway/scaleway-sdk-go/api/account/v2alpha1"
"github.com/scaleway/scaleway-sdk-go/scw"
)
// always import dependencies
var (
_ = scw.RegionFrPar
)
func GetGeneratedCommands() *core.Commands {
return core.NewCommands(
accountRoot(),
accountSSHKey(),
accountSSHKeyList(),
accountSSHKeyAdd(),
accountSSHKeyGet(),
accountSSHKeyUpdate(),
accountSSHKeyRemove(),
)
}
func accountRoot() *core.Command {
return &core.Command{
Short: `Account API`,
Long: ``,
Namespace: "account",
}
}
func accountSSHKey() *core.Command {
return &core.Command{
Short: `SSH keys management commands`,
Long: `SSH keys management commands.`,
Namespace: "account",
Resource: "ssh-key",
}
}
func accountSSHKeyList() *core.Command {
return &core.Command{
Short: `List all SSH keys of your project`,
Long: `List all SSH keys of your project.`,
Namespace: "account",
Resource: "ssh-key",
Verb: "list",
ArgsType: reflect.TypeOf(account.ListSSHKeysRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "order-by",
Required: false,
Positional: false,
EnumValues: []string{"created_at_asc", "created_at_desc", "updated_at_asc", "updated_at_desc", "name_asc", "name_desc"},
},
{
Name: "name",
Required: false,
Positional: false,
},
{
Name: "project-id",
Required: false,
Positional: false,
},
{
Name: "organization-id",
Required: false,
Positional: false,
},
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*account.ListSSHKeysRequest)
client := core.ExtractClient(ctx)
api := account.NewAPI(client)
resp, err := api.ListSSHKeys(request, scw.WithAllPages())
if err != nil {
return nil, err
}
return resp.SSHKeys, nil
},
View: &core.View{Fields: []*core.ViewField{
{
FieldName: "ID",
},
{
FieldName: "Name",
},
{
FieldName: "CreatedAt",
},
{
FieldName: "UpdatedAt",
},
{
FieldName: "ProjectID",
},
{
FieldName: "CreationInfo.Address",
},
{
FieldName: "CreationInfo.CountryCode",
},
{
FieldName: "CreationInfo.UserAgent",
},
{
FieldName: "OrganizationID",
},
}},
}
}
func accountSSHKeyAdd() *core.Command {
return &core.Command{
Short: `Add an SSH key to your project`,
Long: `Add an SSH key to your project.`,
Namespace: "account",
Resource: "ssh-key",
Verb: "add",
ArgsType: reflect.TypeOf(account.CreateSSHKeyRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "name",
Short: `The name of the SSH key`,
Required: false,
Positional: false,
},
{
Name: "public-key",
Short: `SSH public key. Currently ssh-rsa, ssh-dss (DSA), ssh-ed25519 and ecdsa keys with NIST curves are supported`,
Required: true,
Positional: false,
},
{
Name: "project-id",
Short: `Project owning the resource`,
Required: false,
Positional: false,
},
core.OrganizationIDArgSpec(),
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*account.CreateSSHKeyRequest)
client := core.ExtractClient(ctx)
api := account.NewAPI(client)
return api.CreateSSHKey(request)
},
Examples: []*core.Example{
{
Short: "Add a given ssh key",
Raw: `scw account ssh-key add name=foobar public-key="$(cat <path/to/your/public/key>)"`,
},
},
SeeAlsos: []*core.SeeAlso{
{
Command: "scw account ssh-key list",
Short: "List all SSH keys",
},
{
Command: "scw account ssh-key remove",
Short: "Remove an SSH key",
},
},
}
}
func accountSSHKeyGet() *core.Command {
return &core.Command{
Short: `Get an SSH key from your project`,
Long: `Get an SSH key from your project.`,
Namespace: "account",
Resource: "ssh-key",
Verb: "get",
ArgsType: reflect.TypeOf(account.GetSSHKeyRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "ssh-key-id",
Short: `The ID of the SSH key`,
Required: true,
Positional: true,
},
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*account.GetSSHKeyRequest)
client := core.ExtractClient(ctx)
api := account.NewAPI(client)
return api.GetSSHKey(request)
},
}
}
func accountSSHKeyUpdate() *core.Command {
return &core.Command{
Short: `Update an SSH key on your project`,
Long: `Update an SSH key on your project.`,
Namespace: "account",
Resource: "ssh-key",
Verb: "update",
ArgsType: reflect.TypeOf(account.UpdateSSHKeyRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "ssh-key-id",
Required: true,
Positional: true,
},
{
Name: "name",
Short: `Name of the SSH key`,
Required: false,
Positional: false,
},
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*account.UpdateSSHKeyRequest)
client := core.ExtractClient(ctx)
api := account.NewAPI(client)
return api.UpdateSSHKey(request)
},
}
}
func accountSSHKeyRemove() *core.Command {
return &core.Command{
Short: `Remove an SSH key from your project`,
Long: `Remove an SSH key from your project.`,
Namespace: "account",
Resource: "ssh-key",
Verb: "remove",
ArgsType: reflect.TypeOf(account.DeleteSSHKeyRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "ssh-key-id",
Required: true,
Positional: true,
},
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*account.DeleteSSHKeyRequest)
client := core.ExtractClient(ctx)
api := account.NewAPI(client)
e = api.DeleteSSHKey(request)
if e != nil {
return nil, e
}
return &core.SuccessResult{
Resource: "ssh-key",
Verb: "remove",
}, nil
},
Examples: []*core.Example{
{
Short: "Remove a given SSH key",
ArgsJSON: `{"ssh_key_id":"11111111-1111-1111-1111-111111111111"}`,
},
},
}
}