@@ -93,9 +93,9 @@ func errIsConfigFileNotFound(err error) bool {
93
93
// configErrorDetails generate a detailed error message for an invalid client option.
94
94
func configErrorDetails (configKey , varEnv string ) string {
95
95
// TODO: update the more info link
96
- return fmt .Sprintf (`%s can be initialised using the command "scw init".
96
+ return fmt .Sprintf (`%s can be initialized using the command "scw init".
97
97
98
- After initialisation , there are three ways to provide %s:
98
+ After initialization , there are three ways to provide %s:
99
99
- with the Scaleway config file, in the %s key: %s;
100
100
- with the %s environement variable;
101
101
@@ -110,10 +110,25 @@ More info: https://github.com/scaleway/scaleway-sdk-go/tree/master/scw#scaleway-
110
110
)
111
111
}
112
112
113
+ // noConfigErrorDetails prints a message prompting the user to run 'scw login' when both the access key
114
+ // and the secret key are missing.
115
+ func noConfigErrorDetails () string {
116
+ return `You can create a new API keypair using the command "scw login".`
117
+ }
118
+
113
119
// validateClient validate a client configuration and make sure all mandatory setting are present.
114
120
// This function is only call for commands that require a valid client.
115
121
func validateClient (client * scw.Client ) error {
116
- accessKey , _ := client .GetAccessKey ()
122
+ accessKey , accessKeyExists := client .GetAccessKey ()
123
+ secretKey , secretKeyExists := client .GetSecretKey ()
124
+
125
+ if ! accessKeyExists && ! secretKeyExists {
126
+ return & platform.ClientError {
127
+ Err : errors .New ("no credentials provided" ),
128
+ Details : noConfigErrorDetails (),
129
+ }
130
+ }
131
+
117
132
if accessKey == "" {
118
133
return & platform.ClientError {
119
134
Err : errors .New ("access key is required" ),
@@ -127,7 +142,6 @@ func validateClient(client *scw.Client) error {
127
142
}
128
143
}
129
144
130
- secretKey , _ := client .GetSecretKey ()
131
145
if secretKey == "" {
132
146
return & platform.ClientError {
133
147
Err : errors .New ("secret key is required" ),
0 commit comments