Skip to content
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: 1 addition & 0 deletions cmd/baton-splunk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func getConnector(ctx context.Context, c *cfg.Splunk) (types.ConnectorServer, er
Unsafe: c.Unsafe,
Verbose: c.Verbose,
Cloud: c.Cloud,
BaseURL: c.BaseUrl,
},
c.Deployments,
)
Expand Down
1 change: 1 addition & 0 deletions pkg/config/conf.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ var (
"deployments",
field.WithDescription("Limit syncing to specific deployments by specifying cloud deployment names or IP addresses of on-premise deployments."),
)
BaseURL = field.StringField(
"base-url",
field.WithDescription("Override the Splunk API URL (for testing)"),
field.WithHidden(true),
field.WithExportTarget(field.ExportTargetCLIOnly),
)
)

//go:generate go run ./gen
Expand All @@ -52,4 +58,5 @@ var Config = field.NewConfiguration([]field.SchemaField{
Verbose,
Cloud,
Deployments,
BaseURL,
})
3 changes: 2 additions & 1 deletion pkg/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ type CLIConfig struct {
Unsafe bool
Verbose bool
Cloud bool
BaseURL string
}

// New returns the Splunk connector.
Expand Down Expand Up @@ -134,7 +135,7 @@ func New(ctx context.Context, auth string, config CLIConfig, deployments []strin
}

return &Splunk{
client: splunk.NewClient(httpClient, auth, config.Cloud),
client: splunk.NewClient(httpClient, auth, config.Cloud, config.BaseURL),
verbose: config.Verbose,
cloud: config.Cloud,
deployments: deployments,
Expand Down
10 changes: 7 additions & 3 deletions pkg/splunk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
Auth string
Cloud bool
Deployment string
BaseURL string
}

type PaginationData struct {
Expand All @@ -53,12 +54,13 @@
PaginationData `json:"paging"`
}

func NewClient(httpClient *http.Client, auth string, cloud bool) *Client {
func NewClient(httpClient *http.Client, auth string, cloud bool, baseURL string) *Client {
return &Client{
httpClient: httpClient,
Auth: auth,
Cloud: cloud,
Deployment: Localhost,
BaseURL: baseURL,
}
}

Expand All @@ -76,11 +78,13 @@

// GetUrl returns the full URL for the given endpoint based on platform.
func (c *Client) CreateUrl(endpoint string) string {
if c.BaseURL != "" {
return strings.TrimSuffix(c.BaseURL, "/") + endpoint
}
if c.Cloud {
return fmt.Sprintf(CloudBaseURL, c.Deployment) + endpoint
} else {
return fmt.Sprintf(BaseURL, c.Deployment) + endpoint
}
return fmt.Sprintf(BaseURL, c.Deployment) + endpoint
}

func (c *Client) IsCloudPlatform() bool {
Expand Down Expand Up @@ -389,7 +393,7 @@
req.Header.Set("content-type", "application/json")
req.Header.Set("Authorization", c.Auth)

rawResponse, err := c.httpClient.Do(req)

Check failure on line 396 in pkg/splunk/client.go

View workflow job for this annotation

GitHub Actions / verify / lint

G704: SSRF via taint analysis (gosec)
if err != nil {
return err
}
Expand Down
Loading