@@ -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,10 +110,25 @@ More info: https://github.com/scaleway/scaleway-sdk-go/tree/master/scw#scaleway-
110110 )
111111}
112112
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+
113119// validateClient validate a client configuration and make sure all mandatory setting are present.
114120// This function is only call for commands that require a valid client.
115121func 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+
117132 if accessKey == "" {
118133 return & platform.ClientError {
119134 Err : errors .New ("access key is required" ),
@@ -127,7 +142,6 @@ func validateClient(client *scw.Client) error {
127142 }
128143 }
129144
130- secretKey , _ := client .GetSecretKey ()
131145 if secretKey == "" {
132146 return & platform.ClientError {
133147 Err : errors .New ("secret key is required" ),
0 commit comments