fix(outputs.opensearch): Migrate to new secrets API (#14021)

This commit is contained in:
Sven Rebhan 2023-09-29 15:56:58 +02:00 committed by GitHub
parent 4e35ac8dc3
commit 3ffa5f615a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 26 deletions

View File

@ -43,7 +43,6 @@ type Opensearch struct {
TemplateName string `toml:"template_name"`
ManageTemplate bool `toml:"manage_template"`
OverwriteTemplate bool `toml:"overwrite_template"`
pipelineName string
DefaultPipeline string `toml:"default_pipeline"`
UsePipeline string `toml:"use_pipeline"`
Timeout config.Duration `toml:"timeout"`
@ -51,6 +50,8 @@ type Opensearch struct {
HealthCheckTimeout config.Duration `toml:"health_check_timeout"`
URLs []string `toml:"urls"`
Log telegraf.Logger `toml:"-"`
pipelineName string
indexTmpl *template.Template
pipelineTmpl *template.Template
onSucc func(context.Context, opensearchutil.BulkIndexerItem, opensearchutil.BulkIndexerResponseItem)
@ -149,18 +150,18 @@ func (o *Opensearch) newClient() error {
if err != nil {
return fmt.Errorf("getting username failed: %w", err)
}
defer config.ReleaseSecret(username)
defer username.Destroy()
password, err := o.Password.Get()
if err != nil {
return fmt.Errorf("getting password failed: %w", err)
}
defer config.ReleaseSecret(password)
defer password.Destroy()
clientConfig := opensearch.Config{
Addresses: o.URLs,
Username: string(username),
Password: string(password),
Username: username.String(),
Password: password.String(),
}
if o.configOptions.InsecureSkipVerify {
@ -181,9 +182,8 @@ func (o *Opensearch) newClient() error {
if err != nil {
return fmt.Errorf("getting token failed: %w", err)
}
if string(token) != "" {
header.Add("Authorization", "Bearer "+string(token))
}
header.Add("Authorization", "Bearer "+token.String())
defer token.Destroy()
}
clientConfig.Header = header