From 0ade9e1a88e135eb12e3540b164e86c43d74ed7b Mon Sep 17 00:00:00 2001 From: Thomas Casteleyn Date: Thu, 2 Feb 2023 14:14:47 +0100 Subject: [PATCH] feat(inputs.example): Add secret-store sample code (#12550) --- plugins/inputs/example/example.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/plugins/inputs/example/example.go b/plugins/inputs/example/example.go index 59f49e56a..5adea27a0 100644 --- a/plugins/inputs/example/example.go +++ b/plugins/inputs/example/example.go @@ -29,6 +29,10 @@ type Example struct { // Example of passing a duration option allowing the format of e.g. "100ms", "5m" or "1h" 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 // The exact name is important to allow automatic initialization by telegraf. Log telegraf.Logger `toml:"-"` @@ -56,6 +60,19 @@ func (m *Example) Init() error { 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 m.count = 1