Skip to content

Commit

Permalink
Resolves #177 - Improves UX when no env vars set (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-r-west authored Jul 25, 2022
1 parent f0c5b28 commit b31c63c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion external/authentication/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func auth() (string, error) {
} else {
// Autologin using env vars
if config.Envs.EPCC_CLIENT_ID == "" {
log.Debug("No client secret found, no authentication will be used")
log.Info("No client id set in profile or env var, no authentication will be used for API request. To get started, set the EPCC_CLIENT_ID and (optionally) EPCC_CLIENT_SECRET environment variables")
return "", nil
}

Expand Down
9 changes: 9 additions & 0 deletions external/httpclient/httpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ var Limit *rate.Limiter = nil

var statsLock = &sync.Mutex{}

const defaultUrl = "https://api.moltin.com"

var stats = struct {
totalRateLimitedTimeInMs int64
totalRequests uint64
Expand Down Expand Up @@ -88,6 +90,13 @@ func doRequestInternal(ctx context.Context, method string, contentType string, p
return nil, err
}

if reqURL.Host == "" {
log.Infof("No API endpoint set in profile or environment variables, defaulting to \"%s\". To change this set the EPCC_API_BASE_URL environment variable.", defaultUrl)
reqURL, err = url.Parse(defaultUrl)
if err != nil {
log.Fatalf("Error when parsing default host, this is a bug, %s", defaultUrl)
}
}
reqURL.Path = path
reqURL.RawQuery = query

Expand Down

0 comments on commit b31c63c

Please sign in to comment.