Skip to content

Commit 2715059

Browse files
nslaughterjmsnll
authored andcommitted
[receiver/sshcheck] Change keyfile -> key_file in e.g. config and docs (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.
1 parent e812c3b commit 2715059

File tree

5 files changed

+71
-8
lines changed

5 files changed

+71
-8
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: 'bug_fix'
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: sshcheckreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Use key_file instead of keyfile for the key in config. Aligns project practice, code, and docs.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [27035]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

receiver/sshcheckreceiver/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ If `ignore_host_key` is not set then host key validation requires the agent eith
2424
The following settings are required:
2525
- `endpoint`
2626
- `username`
27-
- `password` or `keyfile`
27+
- `password` or `key_file`
2828

29-
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.
29+
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.
3030

3131
The following settings are optional:
3232

receiver/sshcheckreceiver/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var (
2020
errMissingEndpoint = errors.New(`"endpoint" not specified in config`)
2121
errInvalidEndpoint = errors.New(`"endpoint" is invalid`)
2222
errMissingUsername = errors.New(`"username" not specified in config`)
23-
errMissingPasswordAndKeyFile = errors.New(`either "password" or "keyfile" is required`)
23+
errMissingPasswordAndKeyFile = errors.New(`either "password" or "key_file" is required`)
2424

2525
errConfigNotSSHCheck = errors.New("config was not a SSH check receiver config")
2626
errWindowsUnsupported = errors.New(metadata.Type + " is unsupported on Windows.")

receiver/sshcheckreceiver/config_test.go

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
package sshcheckreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sshcheckreceiver"
55

66
import (
7+
"path/filepath"
78
"testing"
9+
"time"
810

911
"github.com/stretchr/testify/require"
1012
"go.opentelemetry.io/collector/component/componenttest"
13+
"go.opentelemetry.io/collector/confmap/confmaptest"
1114
"go.opentelemetry.io/collector/receiver/scraperhelper"
1215
"go.uber.org/multierr"
1316

@@ -32,7 +35,7 @@ func TestValidate(t *testing.T) {
3235
expectedErr error
3336
}{
3437
{
35-
desc: "missing password and keyfile",
38+
desc: "missing password and key_file",
3639
cfg: &Config{
3740
SSHClientSettings: configssh.SSHClientSettings{
3841
Username: "otelu",
@@ -82,7 +85,7 @@ func TestValidate(t *testing.T) {
8285
expectedErr: error(nil),
8386
},
8487
{
85-
desc: "no error with keyfile",
88+
desc: "no error with key_file",
8689
cfg: &Config{
8790
SSHClientSettings: configssh.SSHClientSettings{
8891
Endpoint: "localhost:2222",
@@ -105,3 +108,36 @@ func TestValidate(t *testing.T) {
105108
})
106109
}
107110
}
111+
112+
func TestLoadConfig(t *testing.T) {
113+
// load test config
114+
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
115+
require.NoError(t, err)
116+
rcvrs, err := cm.Sub("receivers")
117+
require.NoError(t, err)
118+
sshconf, err := rcvrs.Sub("sshcheck")
119+
require.NoError(t, err)
120+
// unmarshal to receiver config
121+
actualConfig, ok := NewFactory().CreateDefaultConfig().(*Config)
122+
require.True(t, ok)
123+
require.NoError(t, sshconf.Unmarshal(actualConfig))
124+
125+
// set expected config
126+
expectedConfig, ok := NewFactory().CreateDefaultConfig().(*Config)
127+
require.True(t, ok)
128+
129+
expectedConfig.ScraperControllerSettings = scraperhelper.ScraperControllerSettings{
130+
InitialDelay: time.Second,
131+
CollectionInterval: 10 * time.Second,
132+
}
133+
expectedConfig.SSHClientSettings = configssh.SSHClientSettings{
134+
Endpoint: "notdefault:1313",
135+
Username: "notdefault_username",
136+
Password: "notdefault_password",
137+
KeyFile: "notdefault/path/keyfile",
138+
KnownHosts: "path/to/collector_known_hosts",
139+
IgnoreHostKey: false,
140+
Timeout: 10 * time.Second,
141+
}
142+
require.Equal(t, expectedConfig, actualConfig)
143+
}

receiver/sshcheckreceiver/testdata/config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
receivers:
22
sshcheck:
33
endpoint: notdefault:1313
4-
username: notdefault_password
4+
username: notdefault_username
55
password: notdefault_password
6-
keyfile: notdefault/path/keyfile
7-
collection_interval: 13m
6+
key_file: notdefault/path/keyfile
7+
collection_interval: 10s
88
known_hosts: path/to/collector_known_hosts
99
ignore_host_key: false
1010

0 commit comments

Comments
 (0)