@@ -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,24 @@ More info: https://github.com/scaleway/scaleway-sdk-go/tree/master/scw#scaleway-
110
110
)
111
111
}
112
112
113
+ // noConfigErrorDetails prints a message for when both the access key and the secret key are missing.
114
+ func noConfigErrorDetails () string {
115
+ return `You can create a new API keypair using the command "scw login".`
116
+ }
117
+
113
118
// validateClient validate a client configuration and make sure all mandatory setting are present.
114
119
// This function is only call for commands that require a valid client.
115
120
func validateClient (client * scw.Client ) error {
116
- accessKey , _ := client .GetAccessKey ()
121
+ accessKey , accessKeyExists := client .GetAccessKey ()
122
+ secretKey , secretKeyExists := client .GetSecretKey ()
123
+
124
+ if ! accessKeyExists && ! secretKeyExists {
125
+ return & platform.ClientError {
126
+ Err : errors .New ("no credentials provided" ),
127
+ Details : noConfigErrorDetails (),
128
+ }
129
+ }
130
+
117
131
if accessKey == "" {
118
132
return & platform.ClientError {
119
133
Err : errors .New ("access key is required" ),
@@ -127,7 +141,6 @@ func validateClient(client *scw.Client) error {
127
141
}
128
142
}
129
143
130
- secretKey , _ := client .GetSecretKey ()
131
144
if secretKey == "" {
132
145
return & platform.ClientError {
133
146
Err : errors .New ("secret key is required" ),
0 commit comments