Skip to content

Commit 0f738b7

Browse files
committed
Adding support for api_key for Kibana
1 parent 1724ff5 commit 0f738b7

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ Optional:
125125

126126
Optional:
127127

128+
- `api_key` (String, Sensitive) API Key to use for authentication to Kibana
128129
- `endpoints` (List of String, Sensitive) A list of endpoints where the terraform provider will point to, this must include the http(s) schema and port number.
129130
- `insecure` (Boolean) Disable TLS certificate validation
130131
- `password` (String, Sensitive) Password to use for API authentication to Kibana.

generated/alerting/client.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/clients/api_client.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,16 @@ func (a *ApiClient) GetFleetClient() (*fleet.Client, error) {
247247
}
248248

249249
func (a *ApiClient) SetAlertingAuthContext(ctx context.Context) context.Context {
250-
return context.WithValue(ctx, alerting.ContextBasicAuth, alerting.BasicAuth{
251-
UserName: a.kibanaConfig.Username,
252-
Password: a.kibanaConfig.Password,
253-
})
250+
if a.kibanaConfig.ApiKey != "" {
251+
return context.WithValue(ctx, alerting.ContextAPIKeys, alerting.APIKey{
252+
Key: a.kibanaConfig.ApiKey,
253+
})
254+
} else {
255+
return context.WithValue(ctx, alerting.ContextBasicAuth, alerting.BasicAuth{
256+
UserName: a.kibanaConfig.Username,
257+
Password: a.kibanaConfig.Password,
258+
})
259+
}
254260
}
255261

256262
func (a *ApiClient) ID(ctx context.Context, resourceId string) (*CompositeId, diag.Diagnostics) {
@@ -508,6 +514,9 @@ func buildKibanaConfig(d *schema.ResourceData, baseConfig BaseConfig) (kibana.Co
508514
if password := os.Getenv("KIBANA_PASSWORD"); password != "" {
509515
config.Password = strings.TrimSpace(password)
510516
}
517+
if api_key := os.Getenv("KIBANA_API_KEY"); api_key != "" {
518+
config.ApiKey = strings.TrimSpace(api_key)
519+
}
511520
if endpoint := os.Getenv("KIBANA_ENDPOINT"); endpoint != "" {
512521
config.Address = endpoint
513522
}
@@ -524,6 +533,10 @@ func buildKibanaConfig(d *schema.ResourceData, baseConfig BaseConfig) (kibana.Co
524533
config.Password = password.(string)
525534
}
526535

536+
if api_key, ok := kibConfig["api_key"]; ok && api_key != "" {
537+
config.ApiKey = api_key.(string)
538+
}
539+
527540
if endpoints, ok := kibConfig["endpoints"]; ok && len(endpoints.([]interface{})) > 0 {
528541
// We're curently limited by the API to a single endpoint
529542
if endpoint := endpoints.([]interface{})[0]; endpoint != nil {

0 commit comments

Comments
 (0)