Skip to content

Commit

Permalink
[receiver/sshcheck] Change keyfile -> key_file in e.g. config and docs (
Browse files Browse the repository at this point in the history
open-telemetry#28834)

`keyfile` was the key used in config and documented in sshcheck, but
`key_file` is the preferred key for these purposes.

**Link to tracking Issue:** open-telemetry#27035 

**Testing:** Update tests to ensure this key is used in default.

**Documentation:** Updated documentation to reflect the change in key.
  • Loading branch information
nslaughter authored Nov 2, 2023
1 parent bfb780f commit b39f83d
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 8 deletions.
27 changes: 27 additions & 0 deletions .chloggen/sshcheckreceiver-fix-key_file-config-27035.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'bug_fix'

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: sshcheckreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Use key_file instead of keyfile for the key in config. Aligns project practice, code, and docs.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [27035]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
4 changes: 2 additions & 2 deletions receiver/sshcheckreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ If `ignore_host_key` is not set then host key validation requires the agent eith
The following settings are required:
- `endpoint`
- `username`
- `password` or `keyfile`
- `password` or `key_file`

Either `password` or `keyfile` must be set. But if both are set then password is treated as the `passphrase` and the key is assumed to be encrypted.
Either `password` or `key_file` must be set. But if both are set then password is treated as the `passphrase` and the key is assumed to be encrypted.

The following settings are optional:

Expand Down
2 changes: 1 addition & 1 deletion receiver/sshcheckreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
errMissingEndpoint = errors.New(`"endpoint" not specified in config`)
errInvalidEndpoint = errors.New(`"endpoint" is invalid`)
errMissingUsername = errors.New(`"username" not specified in config`)
errMissingPasswordAndKeyFile = errors.New(`either "password" or "keyfile" is required`)
errMissingPasswordAndKeyFile = errors.New(`either "password" or "key_file" is required`)

errConfigNotSSHCheck = errors.New("config was not a SSH check receiver config")
errWindowsUnsupported = errors.New(metadata.Type + " is unsupported on Windows.")
Expand Down
40 changes: 38 additions & 2 deletions receiver/sshcheckreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
package sshcheckreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sshcheckreceiver"

import (
"path/filepath"
"testing"
"time"

"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/confmap/confmaptest"
"go.opentelemetry.io/collector/receiver/scraperhelper"
"go.uber.org/multierr"

Expand All @@ -32,7 +35,7 @@ func TestValidate(t *testing.T) {
expectedErr error
}{
{
desc: "missing password and keyfile",
desc: "missing password and key_file",
cfg: &Config{
SSHClientSettings: configssh.SSHClientSettings{
Username: "otelu",
Expand Down Expand Up @@ -82,7 +85,7 @@ func TestValidate(t *testing.T) {
expectedErr: error(nil),
},
{
desc: "no error with keyfile",
desc: "no error with key_file",
cfg: &Config{
SSHClientSettings: configssh.SSHClientSettings{
Endpoint: "localhost:2222",
Expand All @@ -105,3 +108,36 @@ func TestValidate(t *testing.T) {
})
}
}

func TestLoadConfig(t *testing.T) {
// load test config
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
require.NoError(t, err)
rcvrs, err := cm.Sub("receivers")
require.NoError(t, err)
sshconf, err := rcvrs.Sub("sshcheck")
require.NoError(t, err)
// unmarshal to receiver config
actualConfig, ok := NewFactory().CreateDefaultConfig().(*Config)
require.True(t, ok)
require.NoError(t, sshconf.Unmarshal(actualConfig))

// set expected config
expectedConfig, ok := NewFactory().CreateDefaultConfig().(*Config)
require.True(t, ok)

expectedConfig.ScraperControllerSettings = scraperhelper.ScraperControllerSettings{
InitialDelay: time.Second,
CollectionInterval: 10 * time.Second,
}
expectedConfig.SSHClientSettings = configssh.SSHClientSettings{
Endpoint: "notdefault:1313",
Username: "notdefault_username",
Password: "notdefault_password",
KeyFile: "notdefault/path/keyfile",
KnownHosts: "path/to/collector_known_hosts",
IgnoreHostKey: false,
Timeout: 10 * time.Second,
}
require.Equal(t, expectedConfig, actualConfig)
}
6 changes: 3 additions & 3 deletions receiver/sshcheckreceiver/testdata/config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
receivers:
sshcheck:
endpoint: notdefault:1313
username: notdefault_password
username: notdefault_username
password: notdefault_password
keyfile: notdefault/path/keyfile
collection_interval: 13m
key_file: notdefault/path/keyfile
collection_interval: 10s
known_hosts: path/to/collector_known_hosts
ignore_host_key: false

Expand Down

0 comments on commit b39f83d

Please sign in to comment.