From f98fb81d2fbc156e74ee0faa1ab8ba0ff4e86ba4 Mon Sep 17 00:00:00 2001 From: Owen Cliffe Date: Fri, 8 Jun 2018 14:59:07 +0100 Subject: [PATCH 1/2] add basic auth to default provider --- provider/config.go | 1 - provider/defaultprovider/README.md | 2 ++ provider/defaultprovider/default_provider.go | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/provider/config.go b/provider/config.go index 7ab7038..ced91fb 100644 --- a/provider/config.go +++ b/provider/config.go @@ -6,7 +6,6 @@ const ( //CfgFnAPIURL is a config key used as the default URL for resolving the API server - different providers may generate URLs in their own way CfgFnAPIURL = "api-url" CfgFnCallURL = "call-url" - CfgFnToken = "token" ) // ConfigSource abstracts loading configuration keys from an underlying configuration system such as Viper diff --git a/provider/defaultprovider/README.md b/provider/defaultprovider/README.md index e95fb6a..abc214b 100644 --- a/provider/defaultprovider/README.md +++ b/provider/defaultprovider/README.md @@ -9,3 +9,5 @@ Configuration: | `api-url` | https://my.functions.com/ | Yes | The API endpoint to contact for accessing the service API | | `call-url` | https://my.functions.com/ | No | The call endpoint base URL for calling functions- this defaults to `api-url` | | `token` | 0YHQtdC60YHRg9Cw0LvRjNC90YvQuSDQsdCw0L3QsNC9Cg== | No (Unless server requires authentication | The Bearer token to use for API auth | +| `user` | bob | No (Unless server requires authentication | User for basic auth this is only used if token is not set | +| `password` | letmein | No (Unless server requires authentication | Password for basic auth | diff --git a/provider/defaultprovider/default_provider.go b/provider/defaultprovider/default_provider.go index ec2655f..501db28 100644 --- a/provider/defaultprovider/default_provider.go +++ b/provider/defaultprovider/default_provider.go @@ -12,10 +12,19 @@ import ( "net/url" ) +const CfgFnToken = "token" +const CfgFnUser = "user" +const CfgFnPasswd = "password" + + // Provider is the default Auth provider type Provider struct { // Optional token to add as bearer token to auth calls Token string + // Optional basic auth user + User string + // Optional basic auth password + Password string // API url to use for FN API interactions FnApiUrl *url.URL // URL to use for FN call interactions @@ -43,7 +52,9 @@ func NewFromConfig(configSource provider.ConfigSource, _ provider.PassPhraseSour } } return &Provider{ - Token: configSource.GetString(provider.CfgFnToken), + Token: configSource.GetString(CfgFnToken), + User: configSource.GetString(CfgFnUser), + Password: configSource.GetString(CfgFnPasswd), FnApiUrl: apiUrl, CallUrl: callUrl, }, nil @@ -64,6 +75,8 @@ func (dp *Provider) APIClient() *client.Fn { transport := openapi.New(dp.FnApiUrl.Host, dp.FnApiUrl.Path, []string{dp.FnApiUrl.Scheme}) if dp.Token != "" { transport.DefaultAuthentication = openapi.BearerToken(dp.Token) + } else if dp.User != "" { + transport.DefaultAuthentication = openapi.BasicAuth(dp.User, dp.Password) } return client.New(transport, strfmt.Default) From 59cc2670bbbb50020cd74570cee49919fab9a039 Mon Sep 17 00:00:00 2001 From: Owen Cliffe Date: Fri, 8 Jun 2018 15:00:45 +0100 Subject: [PATCH 2/2] gofmt --- provider/defaultprovider/default_provider.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/provider/defaultprovider/default_provider.go b/provider/defaultprovider/default_provider.go index 501db28..9d6cd85 100644 --- a/provider/defaultprovider/default_provider.go +++ b/provider/defaultprovider/default_provider.go @@ -16,7 +16,6 @@ const CfgFnToken = "token" const CfgFnUser = "user" const CfgFnPasswd = "password" - // Provider is the default Auth provider type Provider struct { // Optional token to add as bearer token to auth calls @@ -53,8 +52,8 @@ func NewFromConfig(configSource provider.ConfigSource, _ provider.PassPhraseSour } return &Provider{ Token: configSource.GetString(CfgFnToken), - User: configSource.GetString(CfgFnUser), - Password: configSource.GetString(CfgFnPasswd), + User: configSource.GetString(CfgFnUser), + Password: configSource.GetString(CfgFnPasswd), FnApiUrl: apiUrl, CallUrl: callUrl, }, nil