@@ -2,15 +2,18 @@ package scw
22
33import (
44 "bytes"
5+ goerrors "errors"
56 "io/ioutil"
67 "os"
78 "path/filepath"
9+ "strings"
810 "text/template"
911
12+ "gopkg.in/yaml.v2"
13+
1014 "github.com/scaleway/scaleway-sdk-go/internal/auth"
1115 "github.com/scaleway/scaleway-sdk-go/internal/errors"
1216 "github.com/scaleway/scaleway-sdk-go/logger"
13- "gopkg.in/yaml.v2"
1417)
1518
1619const (
@@ -185,7 +188,24 @@ func MustLoadConfig() *Config {
185188
186189// LoadConfig read the config from the default path.
187190func LoadConfig () (* Config , error ) {
188- return LoadConfigFromPath (GetConfigPath ())
191+ configPath := GetConfigPath ()
192+ cfg , err := LoadConfigFromPath (configPath )
193+
194+ // Special case if using default config path
195+ // if config.yaml does not exist, we should try to read config.yml
196+ if os .Getenv (ScwConfigPathEnv ) == "" {
197+ var configNotFoundError * ConfigFileNotFoundError
198+ if err != nil && goerrors .As (err , & configNotFoundError ) && strings .HasSuffix (configPath , ".yaml" ) {
199+ configPath = strings .TrimSuffix (configPath , ".yaml" ) + ".yml"
200+ cfgYml , errYml := LoadConfigFromPath (configPath )
201+ // If .yml config is not found, return first error when reading .yaml
202+ if errYml == nil || (errYml != nil && ! goerrors .As (errYml , & configNotFoundError )) {
203+ return cfgYml , errYml
204+ }
205+ }
206+ }
207+
208+ return cfg , err
189209}
190210
191211// LoadConfigFromPath read the config from the given path.
0 commit comments