diff --git a/ovh/configuration.go b/ovh/configuration.go index 6102f06..f04b877 100644 --- a/ovh/configuration.go +++ b/ovh/configuration.go @@ -64,7 +64,7 @@ func expandConfigPaths() []interface{} { } // loadINI builds a ini.File from the configuration paths provided in configPaths. -// It's a helper for loadConfig. +// It's a helper for LoadConfig. func loadINI() (*ini.File, error) { paths := expandConfigPaths() if len(paths) == 0 { @@ -74,21 +74,21 @@ func loadINI() (*ini.File, error) { return ini.LooseLoad(paths[0], paths[1:]...) } -// loadConfig loads client configuration from params, environments or configuration +// LoadConfig loads client configuration from params, environments or configuration // files (by order of decreasing precedence). // -// loadConfig will check OVH_CONSUMER_KEY, OVH_APPLICATION_KEY, OVH_APPLICATION_SECRET +// LoadConfig will check OVH_CONSUMER_KEY, OVH_APPLICATION_KEY, OVH_APPLICATION_SECRET // and OVH_ENDPOINT environment variables. If any is present, it will take precedence // over any configuration from file. // // Configuration files are ini files. They share the same format as python-ovh, // node-ovh, php-ovh and all other wrappers. If any wrapper is configured, all -// can re-use the same configuration. loadConfig will check for configuration in: +// can re-use the same configuration. LoadConfig will check for configuration in: // // - ./ovh.conf // - $HOME/.ovh.conf // - /etc/ovh.conf -func (c *Client) loadConfig(endpointName string) error { +func (c *Client) LoadConfig(endpointName string) error { if strings.HasSuffix(endpointName, "/") { return fmt.Errorf("endpoint name cannot have a tailing slash") } diff --git a/ovh/configuration_test.go b/ovh/configuration_test.go index 5f3140b..ecf6ffe 100644 --- a/ovh/configuration_test.go +++ b/ovh/configuration_test.go @@ -29,7 +29,7 @@ func setConfigPaths(t testing.TB, paths ...string) { func TestConfigForbidsTrailingSlash(t *testing.T) { client := Client{} - err := client.loadConfig("https://example.org/") + err := client.LoadConfig("https://example.org/") td.Require(t).String(err, "endpoint name cannot have a tailing slash") } @@ -37,7 +37,7 @@ func TestConfigFromFiles(t *testing.T) { setConfigPaths(t, systemConf, userPartialConf, localPartialConf) client := Client{} - err := client.loadConfig("ovh-eu") + err := client.LoadConfig("ovh-eu") td.Require(t).CmpNoError(err) td.Cmp(t, client, td.Struct(Client{ AppKey: "system", @@ -50,7 +50,7 @@ func TestConfigFromOnlyOneFile(t *testing.T) { setConfigPaths(t, userConf) client := Client{} - err := client.loadConfig("ovh-eu") + err := client.LoadConfig("ovh-eu") td.Require(t).CmpNoError(err) td.Cmp(t, client, td.Struct(Client{ AppKey: "user", @@ -63,7 +63,7 @@ func TestConfigFromNonExistingFile(t *testing.T) { setConfigPaths(t, doesNotExistConf) client := Client{} - err := client.loadConfig("ovh-eu") + err := client.LoadConfig("ovh-eu") td.CmpString(t, err, `missing authentication information, you need to provide one of the following: application_key/application_secret, client_id/client_secret, or access_token`) } @@ -71,7 +71,7 @@ func TestConfigFromInvalidINIFile(t *testing.T) { setConfigPaths(t, invalidINIConf) client := Client{} - err := client.loadConfig("ovh-eu") + err := client.LoadConfig("ovh-eu") td.CmpString(t, err, "cannot load configuration: unclosed section: [ovh\n") } @@ -79,7 +79,7 @@ func TestConfigFromInvalidFile(t *testing.T) { setConfigPaths(t, errorConf) client := Client{} - err := client.loadConfig("ovh-eu") + err := client.LoadConfig("ovh-eu") td.CmpString(t, err, "cannot load configuration: BOM: read testdata: is a directory") } @@ -92,7 +92,7 @@ func TestConfigFromEnv(t *testing.T) { t.Setenv("OVH_CONSUMER_KEY", "env") client := Client{} - err := client.loadConfig("") + err := client.LoadConfig("") td.Require(t).CmpNoError(err) td.Cmp(t, client, td.Struct(Client{ AppKey: "env", @@ -106,7 +106,7 @@ func TestConfigFromArgs(t *testing.T) { setConfigPaths(t, userConf) client := Client{AppKey: "param", AppSecret: "param", ConsumerKey: "param"} - err := client.loadConfig("ovh-eu") + err := client.LoadConfig("ovh-eu") td.Require(t).CmpNoError(err) td.Cmp(t, client, td.Struct(Client{ AppKey: "param", @@ -123,7 +123,7 @@ func TestEndpoint(t *testing.T) { // Test: by name client := Client{} - err := client.loadConfig("ovh-eu") + err := client.LoadConfig("ovh-eu") require.CmpNoError(err) assert.Cmp(client, td.Struct(Client{ AppKey: "ovh", @@ -131,7 +131,7 @@ func TestEndpoint(t *testing.T) { // Test: by URL client = Client{} - err = client.loadConfig("https://api.example.com:4242") + err = client.LoadConfig("https://api.example.com:4242") require.CmpNoError(err) assert.Cmp(client, td.Struct(Client{ AppKey: "example.com", @@ -142,16 +142,16 @@ func TestMissingParam(t *testing.T) { client := Client{AppKey: "param", AppSecret: "param", ConsumerKey: "param"} client.endpoint = "" - err := client.loadConfig("") + err := client.LoadConfig("") td.CmpString(t, err, `unknown endpoint '', consider checking 'Endpoints' list or using an URL`) client.AppKey = "" - err = client.loadConfig("ovh-eu") + err = client.LoadConfig("ovh-eu") td.CmpString(t, err, `invalid authentication config, both application_key and application_secret must be given`) client.AppKey = "param" client.AppSecret = "" - err = client.loadConfig("ovh-eu") + err = client.LoadConfig("ovh-eu") td.CmpString(t, err, `invalid authentication config, both application_key and application_secret must be given`) } @@ -172,7 +172,7 @@ func TestConfigOAuth2(t *testing.T) { setConfigPaths(t, userOAuth2Conf) client := Client{} - err := client.loadConfig("ovh-eu") + err := client.LoadConfig("ovh-eu") td.Require(t).CmpNoError(err) td.Cmp(t, client, td.Struct(Client{ ClientID: "foo", @@ -184,7 +184,7 @@ func TestConfigInvalidBoth(t *testing.T) { setConfigPaths(t, userBothConf) client := Client{} - err := client.loadConfig("ovh-eu") + err := client.LoadConfig("ovh-eu") td.CmpString(t, err, "can't use multiple authentication methods: application_key/application_secret, client_id/client_secret") } @@ -192,7 +192,7 @@ func TestConfigOAuth2Invalid(t *testing.T) { setConfigPaths(t, userOAuth2InvalidConf) client := Client{} - err := client.loadConfig("ovh-eu") + err := client.LoadConfig("ovh-eu") td.CmpString(t, err, "invalid oauth2 config, both client_id and client_secret must be given") } @@ -200,6 +200,6 @@ func TestConfigOAuth2Incompatible(t *testing.T) { setConfigPaths(t, userOAuth2IncompatibleConfig) client := Client{} - err := client.loadConfig("kimsufi-eu") + err := client.LoadConfig("kimsufi-eu") td.CmpString(t, err, `oauth2 authentication is not compatible with endpoint "https://eu.api.kimsufi.com/1.0"`) } diff --git a/ovh/ovh.go b/ovh/ovh.go index a536340..189f527 100644 --- a/ovh/ovh.go +++ b/ovh/ovh.go @@ -110,7 +110,7 @@ func NewClient(endpoint, appKey, appSecret, consumerKey string) (*Client, error) } // Get and check the configuration - if err := client.loadConfig(endpoint); err != nil { + if err := client.LoadConfig(endpoint); err != nil { return nil, err } return &client, nil @@ -138,7 +138,7 @@ func NewOAuth2Client(endpoint, clientID, clientSecret string) (*Client, error) { } // Get and check the configuration - if err := client.loadConfig(endpoint); err != nil { + if err := client.LoadConfig(endpoint); err != nil { return nil, err } return &client, nil @@ -152,7 +152,7 @@ func NewAccessTokenClient(endpoint, accessToken string) (*Client, error) { } // Get and check the configuration - if err := client.loadConfig(endpoint); err != nil { + if err := client.LoadConfig(endpoint); err != nil { return nil, err } return &client, nil