Skip to content

Commit

Permalink
Allow explicit configuration with api token
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmalkmus committed Mar 8, 2022
1 parent e77ec89 commit efc8339
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions axiom/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,15 @@ func (c *Client) populateClientFromEnvironment() (err error) {
}

// When the organization ID is not set, use `AXIOM_ORG_ID`. In case the url
// is the Axiom Cloud url and the access token is not a personal token, the
// is the Axiom Cloud url and the access token is a personal token, the
// organization ID is explicitly required and an error is returned, if it is
// not set.
cloudURLSetByOption := c.baseURL != nil && c.baseURL.String() == CloudURL
cloudURLSetByEnvironment := deploymentURL == CloudURL
cloudURLSet := cloudURLSetByOption || cloudURLSetByEnvironment
isAPIToken := IsAPIToken(c.accessToken) || IsAPIToken(accessToken)
isPersonalToken := IsPersonalToken(c.accessToken) || IsPersonalToken(accessToken)
if c.orgID == "" {
if c.orgID == "" && !isAPIToken {
if (orgID == "" && cloudURLSet && isPersonalToken) || (c.noEnv && cloudURLSet) {
return ErrMissingOrganizationID
}
Expand Down
8 changes: 8 additions & 0 deletions axiom/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ func TestNewClient(t *testing.T) {
},
err: ErrMissingAccessToken,
},
{
name: "no environment noEnv, cloudUrl and accessToken option with API token",
options: []Option{
SetNoEnv(),
SetURL(CloudURL),
SetAccessToken(apiToken),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit efc8339

Please sign in to comment.