feat: add username and password login (#418)

* feat: add username and password login

* fix: make sure cookie is not empty

* chore: go mod tidy

* fix: prevent local config from influencing tests

* fix: small cleanup on error handling

* fix: remove unnecessary trim
This commit is contained in:
Jeffrey Smith II
2022-07-28 10:53:19 -04:00
committed by GitHub
parent 182303e31d
commit f34e6a888f
11 changed files with 313 additions and 4 deletions

View File

@ -11,6 +11,7 @@ type ConfigParams struct {
Host *url.URL
UserAgent string
Token *string
Cookie *string
TraceId *string
AllowInsecureTLS bool
Debug bool
@ -26,8 +27,10 @@ func NewAPIConfig(params ConfigParams) *Configuration {
apiConfig.Scheme = params.Host.Scheme
apiConfig.UserAgent = params.UserAgent
apiConfig.HTTPClient = &http.Client{Transport: clientTransport}
if params.Token != nil {
if params.Token != nil && *params.Token != "" {
apiConfig.DefaultHeader["Authorization"] = fmt.Sprintf("Token %s", *params.Token)
} else if params.Cookie != nil && *params.Cookie != "" {
apiConfig.DefaultHeader["Cookie"] = fmt.Sprintf("influxdb-oss-session=%s", *params.Cookie)
}
if params.TraceId != nil {
// NOTE: This is circumventing our codegen. If the header we use for tracing ever changes,