fix(outputs.opensearch): Migrate to new secrets API (#14021)
This commit is contained in:
parent
4e35ac8dc3
commit
3ffa5f615a
|
|
@ -31,19 +31,18 @@ import (
|
||||||
var sampleConfig string
|
var sampleConfig string
|
||||||
|
|
||||||
type Opensearch struct {
|
type Opensearch struct {
|
||||||
Username config.Secret `toml:"username"`
|
Username config.Secret `toml:"username"`
|
||||||
Password config.Secret `toml:"password"`
|
Password config.Secret `toml:"password"`
|
||||||
AuthBearerToken config.Secret `toml:"auth_bearer_token"`
|
AuthBearerToken config.Secret `toml:"auth_bearer_token"`
|
||||||
EnableGzip bool `toml:"enable_gzip"`
|
EnableGzip bool `toml:"enable_gzip"`
|
||||||
EnableSniffer bool `toml:"enable_sniffer"`
|
EnableSniffer bool `toml:"enable_sniffer"`
|
||||||
FloatHandling string `toml:"float_handling"`
|
FloatHandling string `toml:"float_handling"`
|
||||||
FloatReplacement float64 `toml:"float_replacement_value"`
|
FloatReplacement float64 `toml:"float_replacement_value"`
|
||||||
ForceDocumentID bool `toml:"force_document_id"`
|
ForceDocumentID bool `toml:"force_document_id"`
|
||||||
IndexName string `toml:"index_name"`
|
IndexName string `toml:"index_name"`
|
||||||
TemplateName string `toml:"template_name"`
|
TemplateName string `toml:"template_name"`
|
||||||
ManageTemplate bool `toml:"manage_template"`
|
ManageTemplate bool `toml:"manage_template"`
|
||||||
OverwriteTemplate bool `toml:"overwrite_template"`
|
OverwriteTemplate bool `toml:"overwrite_template"`
|
||||||
pipelineName string
|
|
||||||
DefaultPipeline string `toml:"default_pipeline"`
|
DefaultPipeline string `toml:"default_pipeline"`
|
||||||
UsePipeline string `toml:"use_pipeline"`
|
UsePipeline string `toml:"use_pipeline"`
|
||||||
Timeout config.Duration `toml:"timeout"`
|
Timeout config.Duration `toml:"timeout"`
|
||||||
|
|
@ -51,12 +50,14 @@ type Opensearch struct {
|
||||||
HealthCheckTimeout config.Duration `toml:"health_check_timeout"`
|
HealthCheckTimeout config.Duration `toml:"health_check_timeout"`
|
||||||
URLs []string `toml:"urls"`
|
URLs []string `toml:"urls"`
|
||||||
Log telegraf.Logger `toml:"-"`
|
Log telegraf.Logger `toml:"-"`
|
||||||
indexTmpl *template.Template
|
|
||||||
pipelineTmpl *template.Template
|
pipelineName string
|
||||||
onSucc func(context.Context, opensearchutil.BulkIndexerItem, opensearchutil.BulkIndexerResponseItem)
|
indexTmpl *template.Template
|
||||||
onFail func(context.Context, opensearchutil.BulkIndexerItem, opensearchutil.BulkIndexerResponseItem, error)
|
pipelineTmpl *template.Template
|
||||||
configOptions httpconfig.HTTPClientConfig
|
onSucc func(context.Context, opensearchutil.BulkIndexerItem, opensearchutil.BulkIndexerResponseItem)
|
||||||
osClient *opensearch.Client
|
onFail func(context.Context, opensearchutil.BulkIndexerItem, opensearchutil.BulkIndexerResponseItem, error)
|
||||||
|
configOptions httpconfig.HTTPClientConfig
|
||||||
|
osClient *opensearch.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:embed template.json
|
//go:embed template.json
|
||||||
|
|
@ -149,18 +150,18 @@ func (o *Opensearch) newClient() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("getting username failed: %w", err)
|
return fmt.Errorf("getting username failed: %w", err)
|
||||||
}
|
}
|
||||||
defer config.ReleaseSecret(username)
|
defer username.Destroy()
|
||||||
|
|
||||||
password, err := o.Password.Get()
|
password, err := o.Password.Get()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("getting password failed: %w", err)
|
return fmt.Errorf("getting password failed: %w", err)
|
||||||
}
|
}
|
||||||
defer config.ReleaseSecret(password)
|
defer password.Destroy()
|
||||||
|
|
||||||
clientConfig := opensearch.Config{
|
clientConfig := opensearch.Config{
|
||||||
Addresses: o.URLs,
|
Addresses: o.URLs,
|
||||||
Username: string(username),
|
Username: username.String(),
|
||||||
Password: string(password),
|
Password: password.String(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if o.configOptions.InsecureSkipVerify {
|
if o.configOptions.InsecureSkipVerify {
|
||||||
|
|
@ -181,9 +182,8 @@ func (o *Opensearch) newClient() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("getting token failed: %w", err)
|
return fmt.Errorf("getting token failed: %w", err)
|
||||||
}
|
}
|
||||||
if string(token) != "" {
|
header.Add("Authorization", "Bearer "+token.String())
|
||||||
header.Add("Authorization", "Bearer "+string(token))
|
defer token.Destroy()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
clientConfig.Header = header
|
clientConfig.Header = header
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue