Skip to content

Commit

Permalink
skip cloud autodiscover if HostOverride is set (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
ffalor authored Aug 31, 2023
1 parent 739eaf9 commit f7de15b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions falcon/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ func NewClient(ac *ApiConfig) (*client.CrowdStrikeAPISpecification, error) {
return nil, errors.New("Invalid Context for falcon.ApiConfig.Context. Make that ApiConfig.Context is set.")
}

if ac.AccessToken == "" {
if err := ac.Cloud.Autodiscover(ac.Context, ac.ClientId, ac.ClientSecret); err != nil {
return nil, err
// If HostOverride is provided we do not need to discover the cloud
if ac.HostOverride == "" {
if ac.AccessToken == "" {
if err := ac.Cloud.Autodiscover(ac.Context, ac.ClientId, ac.ClientSecret); err != nil {
return nil, err
}
} else if ac.Cloud == CloudAutoDiscover {
// There is nothing in the access token (JWT) which identifies the cloud.
return nil, errors.New("Cannot autodiscover cloud when using an access token. Please specify the cloud explicitly.")
}
} else if ac.Cloud == CloudAutoDiscover {
// There is nothing in the access token (JWT) which identifies the cloud.
return nil, errors.New("Cannot autodiscover cloud when using an access token. Please specify the cloud explicitly.")
}

var authenticatedClient *http.Client
Expand Down
4 changes: 2 additions & 2 deletions falcon/api_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
// ApiConfig object is used to initialise and configure API Client. Together with NewClient function, ApiConfig provides preferred way to initiate API communication.
type ApiConfig struct {
// AccessToken is the access token used to access the CrowdStrike Falcon platform.
// If used either Cloud or HostOverride must be provided.
// *required* if ClientId and ClientSecret are empty.
AccessToken string
// Client ID used for authentication with CrowdStrike Falcon platform.
Expand All @@ -24,9 +25,8 @@ type ApiConfig struct {
// This Context object will be used only when authenticating with the OAuth interface.
Context context.Context
// Cloud allows us to select Falcon Cloud to connect.
// *required* if AccessToken is used.
Cloud CloudType
// HostOverride allows to override default host (default: api.crowdstrike.com)
// HostOverride allows to override host. Cloud will be ignored.
HostOverride string
// BasePathOverride allows to override default base path (default: /)
BasePathOverride string
Expand Down

0 comments on commit f7de15b

Please sign in to comment.