From 7883638899eaec876a4eed8418c817c1e7974695 Mon Sep 17 00:00:00 2001 From: Jerome Quere Date: Thu, 9 Jul 2020 15:23:13 +0200 Subject: [PATCH] feat(config): add support for default profile --- scw/config.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scw/config.go b/scw/config.go index 59cd95f71..3846a6b64 100644 --- a/scw/config.go +++ b/scw/config.go @@ -16,6 +16,9 @@ import ( const ( documentationLink = "https://github.com/scaleway/scaleway-sdk-go/blob/master/scw/README.md" defaultConfigPermission = 0600 + + // Reserved name for the default profile. + DefaultProfileName = "default" ) const configFileTemplate = `# Scaleway configuration file @@ -217,7 +220,11 @@ func LoadConfigFromPath(path string) (*Config, error) { // GetProfile returns the profile corresponding to the given profile name. func (c *Config) GetProfile(profileName string) (*Profile, error) { if profileName == "" { - return nil, errors.New("active profile cannot be empty") + return nil, errors.New("profileName cannot be empty") + } + + if profileName == DefaultProfileName { + return &c.Profile, nil } p, exist := c.Profiles[profileName]