-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(iam): replace account on init command #2778
Changes from all commits
8cde11a
bbbc3b1
a8fa18f
403a4be
2cde21d
50b1029
fcd27e7
e9c72c5
b5c7f32
305e3be
0d70000
d67f66c
58be345
0a8a158
0723af1
b8fc08c
6d8dedc
38efd30
97449f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 | ||
🟥🟥🟥 STDERR️️ 🟥🟥🟥️ | ||
Initialize SSH key. | ||
|
||
USAGE: | ||
scw iam ssh-key init | ||
|
||
FLAGS: | ||
-h, --help help for init | ||
|
||
GLOBAL FLAGS: | ||
-c, --config string The path to the config file | ||
-D, --debug Enable debug mode | ||
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human") | ||
-p, --profile string The config profile to use |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ AVAILABLE COMMANDS: | |
create Create an SSH key | ||
delete Delete an SSH key | ||
get Get an SSH key | ||
init Initialize SSH key | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't mean anything. Could you rephrase to something like, scan for ssh keys on your local machine and send them to your scaleway account. |
||
list List SSH keys | ||
update Update an SSH key | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ USAGE: | |
scw <command> | ||
|
||
AVAILABLE COMMANDS: | ||
account Account API | ||
account User related data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's change the phrasing here too. |
||
apple-silicon Apple silicon API | ||
autocomplete Autocomplete related commands | ||
baremetal Elastic metal API | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ IAM API | |
- [Create an SSH key](#create-an-ssh-key) | ||
- [Delete an SSH key](#delete-an-ssh-key) | ||
- [Get an SSH key](#get-an-ssh-key) | ||
- [Initialize SSH key](#initialize-ssh-key) | ||
- [List SSH keys](#list-ssh-keys) | ||
- [Update an SSH key](#update-an-ssh-key) | ||
- [Users management commands](#users-management-commands) | ||
|
@@ -736,6 +737,18 @@ scw iam ssh-key get <ssh-key-id ...> [arg=value ...] | |
|
||
|
||
|
||
### Initialize SSH key | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change phrasing |
||
|
||
Initialize SSH key. | ||
|
||
**Usage:** | ||
|
||
``` | ||
scw iam ssh-key init | ||
``` | ||
|
||
|
||
|
||
### List SSH keys | ||
|
||
List SSH keys. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,5 @@ | ||
package account | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
) | ||
|
||
// Token represents a Token | ||
type Token struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is token maintained in this package? Should we use only the one in the IAM package? |
||
ID string `json:"id"` | ||
|
@@ -31,32 +23,3 @@ type LoginRequest struct { | |
Description string `json:"description,omitempty"` | ||
Expires bool `json:"expires"` | ||
} | ||
|
||
var ( | ||
accountURL = "https://api.scaleway.com/account/v1" | ||
) | ||
|
||
func GetAPIKey(ctx context.Context, secretKey string) (*Token, error) { | ||
resp, err := extractHTTPClient(ctx).Get(accountURL + "/tokens/" + secretKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
return nil, fmt.Errorf("could not get token") | ||
} | ||
|
||
token := &LoginResponse{} | ||
b, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = json.Unmarshal(b, token) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return token.Token, err | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,3 @@ var contextKey = contextKeyType{} | |
func InjectHTTPClient(ctx context.Context, httpClient *http.Client) context.Context { | ||
return context.WithValue(ctx, contextKey, httpClient) | ||
} | ||
|
||
func extractHTTPClient(ctx context.Context) *http.Client { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems weird that we have to delete this code. Why? Why does using IAM instead of accountv2 impact this function? |
||
httpClient, isHTTPClient := ctx.Value(contextKey).(*http.Client) | ||
if httpClient != nil && isHTTPClient { | ||
return httpClient | ||
} | ||
return http.DefaultClient | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ import ( | |
|
||
"github.com/scaleway/scaleway-cli/v2/internal/core" | ||
accountv2 "github.com/scaleway/scaleway-cli/v2/internal/namespaces/account/v2" | ||
account "github.com/scaleway/scaleway-cli/v2/internal/namespaces/account/v2alpha1" | ||
applesilicon "github.com/scaleway/scaleway-cli/v2/internal/namespaces/applesilicon/v1alpha1" | ||
autocompleteNamespace "github.com/scaleway/scaleway-cli/v2/internal/namespaces/autocomplete" | ||
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/baremetal/v1" | ||
|
@@ -54,7 +53,6 @@ func GetCommands(beta ...bool) *core.Commands { | |
marketplace.GetCommands(), | ||
initNamespace.GetCommands(), | ||
configNamespace.GetCommands(), | ||
account.GetCommands(), | ||
accountv2.GetCommands(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should have one account. Rename it to simply account or avoid renaming entirely if possible. |
||
autocompleteNamespace.GetCommands(), | ||
object.GetCommands(), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to chance the phrasing here.