Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add basic auth to default provider #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion provider/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions provider/defaultprovider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
14 changes: 13 additions & 1 deletion provider/defaultprovider/default_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@ 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
Expand Down Expand Up @@ -43,7 +51,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
Expand All @@ -64,6 +74,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)
Expand Down