feat(inputs.example): Add secret-store sample code (#12550)
This commit is contained in:
parent
177ce5eea3
commit
0ade9e1a88
|
|
@ -29,6 +29,10 @@ type Example struct {
|
||||||
// Example of passing a duration option allowing the format of e.g. "100ms", "5m" or "1h"
|
// Example of passing a duration option allowing the format of e.g. "100ms", "5m" or "1h"
|
||||||
Timeout config.Duration `toml:"timeout"`
|
Timeout config.Duration `toml:"timeout"`
|
||||||
|
|
||||||
|
// Example of passing a password/token/username or other sensitive data with the secret-store
|
||||||
|
UserName config.Secret `toml:"username"`
|
||||||
|
Password config.Secret `toml:"password"`
|
||||||
|
|
||||||
// Telegraf logging facility
|
// Telegraf logging facility
|
||||||
// The exact name is important to allow automatic initialization by telegraf.
|
// The exact name is important to allow automatic initialization by telegraf.
|
||||||
Log telegraf.Logger `toml:"-"`
|
Log telegraf.Logger `toml:"-"`
|
||||||
|
|
@ -56,6 +60,19 @@ func (m *Example) Init() error {
|
||||||
m.NumberFields = 2
|
m.NumberFields = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check using the secret-store
|
||||||
|
if m.UserName.Empty() {
|
||||||
|
// For example, use a default value
|
||||||
|
m.Log.Debug("using default username")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve credentials using the secret-store
|
||||||
|
password, err := m.Password.Get()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("getting password failed: %w", err)
|
||||||
|
}
|
||||||
|
defer config.ReleaseSecret(password)
|
||||||
|
|
||||||
// Initialze your internal states
|
// Initialze your internal states
|
||||||
m.count = 1
|
m.count = 1
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue