Skip to content

Commit dd3ef27

Browse files
Monitobscaleway-botCodelax
authored
feat(iam): replace account on init command (#2778)
Co-authored-by: Scaleway Bot <[email protected]> Co-authored-by: Jules Casteran <[email protected]>
1 parent d628a49 commit dd3ef27

File tree

48 files changed

+1208
-770
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1208
-770
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ To enable beta features, you can set `SCW_ENABLE_BETA=1` in your environment.
116116

117117
| Namespace | Description | Documentation |
118118
|----------------|-----------------------------------------|-----------------------------------------------------------------------------------------------------------------|
119-
| `account` | Account API | [CLI](./docs/commands/account.md) |
119+
| `account` | User related data | [CLI](./docs/commands/account.md) / [API](https://developers.scaleway.com/en/products/account/api/v2/) |
120120
| `applesilicon` | Apple silicon API | [CLI](./docs/commands/apple-silicon.md) / [API](https://developers.scaleway.com/en/products/apple-silicon/api/) |
121121
| `autocomplete` | Autocomplete related commands | [CLI](./docs/commands/autocomplete.md) |
122122
| `baremetal` | Baremetal API | [CLI](./docs/commands/baremetal.md) / [API](https://developers.scaleway.com/en/products/baremetal/api/) |

cmd/scw/testdata/test-all-usage-account-usage.golden

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
22
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3-
Account API
3+
This API allows you to manage projects.
44

55
USAGE:
66
scw account <command>
77

88
AVAILABLE COMMANDS:
99
project Project management commands
10-
ssh-key SSH keys management commands
1110

1211
FLAGS:
1312
-h, --help help for account
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Initialize SSH key.
4+
5+
USAGE:
6+
scw iam ssh-key init
7+
8+
FLAGS:
9+
-h, --help help for init
10+
11+
GLOBAL FLAGS:
12+
-c, --config string The path to the config file
13+
-D, --debug Enable debug mode
14+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
15+
-p, --profile string The config profile to use

cmd/scw/testdata/test-all-usage-iam-ssh-key-usage.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ AVAILABLE COMMANDS:
99
create Create an SSH key
1010
delete Delete an SSH key
1111
get Get an SSH key
12+
init Initialize SSH key
1213
list List SSH keys
1314
update Update an SSH key
1415

cmd/scw/testdata/test-main-usage-usage.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ USAGE:
44
scw <command>
55

66
AVAILABLE COMMANDS:
7-
account Account API
7+
account User related data
88
apple-silicon Apple silicon API
99
autocomplete Autocomplete related commands
1010
baremetal Elastic metal API

docs/commands/account.md

Lines changed: 0 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ This API allows you to manage projects.
88
- [Get project](#get-project)
99
- [List projects](#list-projects)
1010
- [Update project](#update-project)
11-
- [SSH keys management commands](#ssh-keys-management-commands)
12-
- [Add an SSH key to your project](#add-an-ssh-key-to-your-project)
13-
- [Get an SSH key from your project](#get-an-ssh-key-from-your-project)
14-
- [Initialize SSH key](#initialize-ssh-key)
15-
- [List all SSH keys of your project](#list-all-ssh-keys-of-your-project)
16-
- [Remove an SSH key from your project](#remove-an-ssh-key-from-your-project)
17-
- [Update an SSH key on your project](#update-an-ssh-key-on-your-project)
1811

1912

2013
## Project management commands
@@ -124,142 +117,3 @@ scw account project update [arg=value ...]
124117

125118

126119

127-
## SSH keys management commands
128-
129-
SSH keys management commands.
130-
131-
132-
### Add an SSH key to your project
133-
134-
Add an SSH key to your project.
135-
136-
**Usage:**
137-
138-
```
139-
scw account ssh-key add [arg=value ...]
140-
```
141-
142-
143-
**Args:**
144-
145-
| Name | | Description |
146-
|------|---|-------------|
147-
| name | | The name of the SSH key |
148-
| public-key | Required | SSH public key. Currently ssh-rsa, ssh-dss (DSA), ssh-ed25519 and ecdsa keys with NIST curves are supported |
149-
| project-id | | Project ID to use. If none is passed the default project ID will be used |
150-
| organization-id | | Organization ID to use. If none is passed the default organization ID will be used |
151-
152-
153-
**Examples:**
154-
155-
156-
Add a given ssh key
157-
```
158-
scw account ssh-key add name=foobar public-key="$(cat <path/to/your/public/key>)"
159-
```
160-
161-
162-
163-
164-
### Get an SSH key from your project
165-
166-
Get an SSH key from your project.
167-
168-
**Usage:**
169-
170-
```
171-
scw account ssh-key get <ssh-key-id ...> [arg=value ...]
172-
```
173-
174-
175-
**Args:**
176-
177-
| Name | | Description |
178-
|------|---|-------------|
179-
| ssh-key-id | Required | The ID of the SSH key |
180-
181-
182-
183-
### Initialize SSH key
184-
185-
Initialize SSH key.
186-
187-
**Usage:**
188-
189-
```
190-
scw account ssh-key init
191-
```
192-
193-
194-
195-
### List all SSH keys of your project
196-
197-
List all SSH keys of your project.
198-
199-
**Usage:**
200-
201-
```
202-
scw account ssh-key list [arg=value ...]
203-
```
204-
205-
206-
**Args:**
207-
208-
| Name | | Description |
209-
|------|---|-------------|
210-
| order-by | One of: `created_at_asc`, `created_at_desc`, `updated_at_asc`, `updated_at_desc`, `name_asc`, `name_desc` | |
211-
| name | | |
212-
| project-id | | |
213-
| organization-id | | |
214-
215-
216-
217-
### Remove an SSH key from your project
218-
219-
Remove an SSH key from your project.
220-
221-
**Usage:**
222-
223-
```
224-
scw account ssh-key remove <ssh-key-id ...> [arg=value ...]
225-
```
226-
227-
228-
**Args:**
229-
230-
| Name | | Description |
231-
|------|---|-------------|
232-
| ssh-key-id | Required | |
233-
234-
235-
**Examples:**
236-
237-
238-
Remove a given SSH key
239-
```
240-
scw account ssh-key remove 11111111-1111-1111-1111-111111111111
241-
```
242-
243-
244-
245-
246-
### Update an SSH key on your project
247-
248-
Update an SSH key on your project.
249-
250-
**Usage:**
251-
252-
```
253-
scw account ssh-key update <ssh-key-id ...> [arg=value ...]
254-
```
255-
256-
257-
**Args:**
258-
259-
| Name | | Description |
260-
|------|---|-------------|
261-
| ssh-key-id | Required | |
262-
| name | | Name of the SSH key |
263-
264-
265-

docs/commands/iam.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ IAM API
3737
- [Create an SSH key](#create-an-ssh-key)
3838
- [Delete an SSH key](#delete-an-ssh-key)
3939
- [Get an SSH key](#get-an-ssh-key)
40+
- [Initialize SSH key](#initialize-ssh-key)
4041
- [List SSH keys](#list-ssh-keys)
4142
- [Update an SSH key](#update-an-ssh-key)
4243
- [Users management commands](#users-management-commands)
@@ -736,6 +737,18 @@ scw iam ssh-key get <ssh-key-id ...> [arg=value ...]
736737

737738

738739

740+
### Initialize SSH key
741+
742+
Initialize SSH key.
743+
744+
**Usage:**
745+
746+
```
747+
scw iam ssh-key init
748+
```
749+
750+
751+
739752
### List SSH keys
740753

741754
List SSH keys.

internal/account/account.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
package account
22

3-
import (
4-
"context"
5-
"encoding/json"
6-
"fmt"
7-
"io"
8-
"net/http"
9-
)
10-
113
// Token represents a Token
124
type Token struct {
135
ID string `json:"id"`
@@ -31,32 +23,3 @@ type LoginRequest struct {
3123
Description string `json:"description,omitempty"`
3224
Expires bool `json:"expires"`
3325
}
34-
35-
var (
36-
accountURL = "https://api.scaleway.com/account/v1"
37-
)
38-
39-
func GetAPIKey(ctx context.Context, secretKey string) (*Token, error) {
40-
resp, err := extractHTTPClient(ctx).Get(accountURL + "/tokens/" + secretKey)
41-
if err != nil {
42-
return nil, err
43-
}
44-
defer resp.Body.Close()
45-
46-
if resp.StatusCode != http.StatusOK {
47-
return nil, fmt.Errorf("could not get token")
48-
}
49-
50-
token := &LoginResponse{}
51-
b, err := io.ReadAll(resp.Body)
52-
if err != nil {
53-
return nil, err
54-
}
55-
56-
err = json.Unmarshal(b, token)
57-
if err != nil {
58-
return nil, err
59-
}
60-
61-
return token.Token, err
62-
}

internal/account/test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,3 @@ var contextKey = contextKeyType{}
1616
func InjectHTTPClient(ctx context.Context, httpClient *http.Client) context.Context {
1717
return context.WithValue(ctx, contextKey, httpClient)
1818
}
19-
20-
func extractHTTPClient(ctx context.Context) *http.Client {
21-
httpClient, isHTTPClient := ctx.Value(contextKey).(*http.Client)
22-
if httpClient != nil && isHTTPClient {
23-
return httpClient
24-
}
25-
return http.DefaultClient
26-
}

internal/core/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func ExtractProfileFlag(ctx context.Context) string {
177177
return extractMeta(ctx).ProfileFlag
178178
}
179179

180-
// GetDocGenContext reuturn a minimal context that can be used by scw-doc-gen
180+
// GetDocGenContext returns a minimal context that can be used by scw-doc-gen
181181
func GetDocGenContext() context.Context {
182182
ctx := context.Background()
183183
client, _ := scw.NewClient(

0 commit comments

Comments
 (0)