@@ -93,9 +93,9 @@ func errIsConfigFileNotFound(err error) bool {
9393// configErrorDetails generate a detailed error message for an invalid client option.
9494func configErrorDetails (configKey , varEnv string ) string {
9595 // 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".
9797
98- After initialisation , there are three ways to provide %s:
98+ After initialization , there are three ways to provide %s:
9999- with the Scaleway config file, in the %s key: %s;
100100- with the %s environement variable;
101101
@@ -110,12 +110,23 @@ More info: https://github.com/scaleway/scaleway-sdk-go/tree/master/scw#scaleway-
110110 )
111111}
112112
113+ // noConfigErrorDetails prints a message for when both the access key and the secret key are missing.
114+ func noConfigErrorDetails () string {
115+ return `No credentials were provided.
116+
117+ You can create new credentials using the command "scw login".
118+
119+ Once created, you can check them here: https://console.scaleway.com/iam/api-keys`
120+ }
121+
113122// validateClient validate a client configuration and make sure all mandatory setting are present.
114123// This function is only call for commands that require a valid client.
115124func validateClient (client * scw.Client ) error {
116- accessKey , _ := client .GetAccessKey ()
125+ var configError * platform.ClientError
126+
127+ accessKey , accessKeyExists := client .GetAccessKey ()
117128 if accessKey == "" {
118- return & platform.ClientError {
129+ configError = & platform.ClientError {
119130 Err : errors .New ("access key is required" ),
120131 Details : configErrorDetails ("access_key" , "SCW_ACCESS_KEY" ),
121132 }
@@ -127,9 +138,9 @@ func validateClient(client *scw.Client) error {
127138 }
128139 }
129140
130- secretKey , _ := client .GetSecretKey ()
141+ secretKey , secretKeyExists := client .GetSecretKey ()
131142 if secretKey == "" {
132- return & platform.ClientError {
143+ configError = & platform.ClientError {
133144 Err : errors .New ("secret key is required" ),
134145 Details : configErrorDetails ("secret_key" , "SCW_SECRET_KEY" ),
135146 }
@@ -141,6 +152,16 @@ func validateClient(client *scw.Client) error {
141152 }
142153 }
143154
155+ switch {
156+ case ! accessKeyExists && ! secretKeyExists :
157+ return & platform.ClientError {
158+ Err : errors .New ("no credentials provided" ),
159+ Details : noConfigErrorDetails (),
160+ }
161+ case ! accessKeyExists || ! secretKeyExists :
162+ return configError
163+ }
164+
144165 defaultOrganizationID , _ := client .GetDefaultOrganizationID ()
145166 if defaultOrganizationID == "" {
146167 return & platform.ClientError {
0 commit comments