Skip to content

Commit

Permalink
[receiver/mongodbatlas] Change the types of Config.PrivateKey and `…
Browse files Browse the repository at this point in the history
…Config.Alerts.Secret` to be `configopaque.String` (#23865)

**Description:**
Split out from: #17353

**Link to tracking Issue:**
#17273
  • Loading branch information
mackjmr committed Jun 30, 2023
1 parent 35a2adb commit 5a2214b
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 9 deletions.
20 changes: 20 additions & 0 deletions .chloggen/mongodbatlas-use-configopaque.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use this changelog template to create an entry for release notes.
# If your change doesn't affect end users, such as a test fix or a tooling change,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

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

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Change the types of `Config.PrivateKey` and `Config.Alerts.Secret` to be `configopaque.String`

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

# (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:
2 changes: 1 addition & 1 deletion receiver/mongodbatlasreceiver/access_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type accessLogsReceiver struct {
func newAccessLogsReceiver(settings rcvr.CreateSettings, cfg *Config, consumer consumer.Logs) *accessLogsReceiver {
r := &accessLogsReceiver{
cancel: func() {},
client: internal.NewMongoDBAtlasClient(cfg.PublicKey, cfg.PrivateKey, cfg.RetrySettings, settings.Logger),
client: internal.NewMongoDBAtlasClient(cfg.PublicKey, string(cfg.PrivateKey), cfg.RetrySettings, settings.Logger),
cfg: cfg,
logger: settings.Logger,
consumer: consumer,
Expand Down
4 changes: 2 additions & 2 deletions receiver/mongodbatlasreceiver/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ func newAlertsReceiver(params rcvr.CreateSettings, baseConfig *Config, consumer

recv := &alertsReceiver{
addr: cfg.Endpoint,
secret: cfg.Secret,
secret: string(cfg.Secret),
tlsSettings: cfg.TLS,
consumer: consumer,
mode: cfg.Mode,
projects: cfg.Projects,
retrySettings: baseConfig.RetrySettings,
publicKey: baseConfig.PublicKey,
privateKey: baseConfig.PrivateKey,
privateKey: string(baseConfig.PrivateKey),
wg: &sync.WaitGroup{},
pollInterval: baseConfig.Alerts.PollInterval,
maxPages: baseConfig.Alerts.MaxPages,
Expand Down
5 changes: 3 additions & 2 deletions receiver/mongodbatlasreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/receiver/scraperhelper"
Expand All @@ -24,7 +25,7 @@ var _ component.Config = (*Config)(nil)
type Config struct {
scraperhelper.ScraperControllerSettings `mapstructure:",squash"`
PublicKey string `mapstructure:"public_key"`
PrivateKey string `mapstructure:"private_key"`
PrivateKey configopaque.String `mapstructure:"private_key"`
Granularity string `mapstructure:"granularity"`
MetricsBuilderConfig metadata.MetricsBuilderConfig `mapstructure:",squash"`
Alerts AlertConfig `mapstructure:"alerts"`
Expand All @@ -37,7 +38,7 @@ type Config struct {
type AlertConfig struct {
Enabled bool `mapstructure:"enabled"`
Endpoint string `mapstructure:"endpoint"`
Secret string `mapstructure:"secret"`
Secret configopaque.String `mapstructure:"secret"`
TLS *configtls.TLSServerSetting `mapstructure:"tls"`
Mode string `mapstructure:"mode"`

Expand Down
2 changes: 1 addition & 1 deletion receiver/mongodbatlasreceiver/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type eventRecord struct {

func newEventsReceiver(settings rcvr.CreateSettings, c *Config, consumer consumer.Logs) *eventsReceiver {
r := &eventsReceiver{
client: internal.NewMongoDBAtlasClient(c.PublicKey, c.PrivateKey, c.RetrySettings, settings.Logger),
client: internal.NewMongoDBAtlasClient(c.PublicKey, string(c.PrivateKey), c.RetrySettings, settings.Logger),
cfg: c,
logger: settings.Logger,
consumer: consumer,
Expand Down
2 changes: 1 addition & 1 deletion receiver/mongodbatlasreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/stretchr/testify v1.8.4
go.mongodb.org/atlas v0.29.0
go.opentelemetry.io/collector/component v0.80.1-0.20230629144634-c3f70bd1f8ea
go.opentelemetry.io/collector/config/configopaque v0.80.1-0.20230629144634-c3f70bd1f8ea
go.opentelemetry.io/collector/config/configtls v0.80.1-0.20230629144634-c3f70bd1f8ea
go.opentelemetry.io/collector/confmap v0.80.1-0.20230629144634-c3f70bd1f8ea
go.opentelemetry.io/collector/consumer v0.80.1-0.20230629144634-c3f70bd1f8ea
Expand Down Expand Up @@ -46,7 +47,6 @@ require (
github.com/stretchr/objx v0.5.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/collector v0.80.1-0.20230629144634-c3f70bd1f8ea // indirect
go.opentelemetry.io/collector/config/configopaque v0.80.1-0.20230629144634-c3f70bd1f8ea // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.80.1-0.20230629144634-c3f70bd1f8ea // indirect
go.opentelemetry.io/collector/featuregate v1.0.0-rcv0013.0.20230629144634-c3f70bd1f8ea // indirect
go.opentelemetry.io/collector/processor v0.80.1-0.20230629144634-c3f70bd1f8ea // indirect
Expand Down
2 changes: 1 addition & 1 deletion receiver/mongodbatlasreceiver/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type ProjectContext struct {
const collectionInterval = time.Minute * 5

func newMongoDBAtlasLogsReceiver(settings rcvr.CreateSettings, cfg *Config, consumer consumer.Logs) *logsReceiver {
client := internal.NewMongoDBAtlasClient(cfg.PublicKey, cfg.PrivateKey, cfg.RetrySettings, settings.Logger)
client := internal.NewMongoDBAtlasClient(cfg.PublicKey, string(cfg.PrivateKey), cfg.RetrySettings, settings.Logger)

for _, p := range cfg.Logs.Projects {
p.populateIncludesAndExcludes()
Expand Down
2 changes: 1 addition & 1 deletion receiver/mongodbatlasreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type timeconstraints struct {
}

func newMongoDBAtlasReceiver(settings rcvr.CreateSettings, cfg *Config) *receiver {
client := internal.NewMongoDBAtlasClient(cfg.PublicKey, cfg.PrivateKey, cfg.RetrySettings, settings.Logger)
client := internal.NewMongoDBAtlasClient(cfg.PublicKey, string(cfg.PrivateKey), cfg.RetrySettings, settings.Logger)
return &receiver{
log: settings.Logger,
cfg: cfg,
Expand Down

0 comments on commit 5a2214b

Please sign in to comment.