Skip to content

Commit 216046a

Browse files
authored
[configauth] Add omitempty tags to fields (#12481)
<!-- Issue number if applicable --> #### Link to tracking issue Works toward #12191
1 parent e6b1e92 commit 216046a

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

.chloggen/configauth-omitempty.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: configauth
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add the `omitempty` mapstructure tag to struct fields
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [12191]
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: This results in unset fields not being rendered when marshaling.
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: [api]

config/configauth/configauth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var (
2424
// Authentication defines the auth settings for the receiver.
2525
type Authentication struct {
2626
// AuthenticatorID specifies the name of the extension to use in order to authenticate the incoming data point.
27-
AuthenticatorID component.ID `mapstructure:"authenticator"`
27+
AuthenticatorID component.ID `mapstructure:"authenticator,omitempty"`
2828
}
2929

3030
// GetServerAuthenticator attempts to select the appropriate extensionauth.Server from the list of extensions,

internal/e2e/configauth_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package e2e
5+
6+
import (
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
11+
12+
"go.opentelemetry.io/collector/config/configauth"
13+
"go.opentelemetry.io/collector/confmap"
14+
)
15+
16+
func TestConfmapMarshalConfigAuth(t *testing.T) {
17+
conf := confmap.New()
18+
require.NoError(t, conf.Marshal(configauth.Authentication{}))
19+
assert.Equal(t, map[string]any{}, conf.ToStringMap())
20+
}

internal/e2e/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
go.opentelemetry.io/collector/component v0.120.0
99
go.opentelemetry.io/collector/component/componentstatus v0.120.0
1010
go.opentelemetry.io/collector/component/componenttest v0.120.0
11+
go.opentelemetry.io/collector/config/configauth v0.120.0
1112
go.opentelemetry.io/collector/config/configgrpc v0.120.0
1213
go.opentelemetry.io/collector/config/confighttp v0.120.0
1314
go.opentelemetry.io/collector/config/confignet v1.26.0
@@ -80,7 +81,6 @@ require (
8081
github.com/yusufpapurcu/wmi v1.2.4 // indirect
8182
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
8283
go.opentelemetry.io/collector/client v1.26.0 // indirect
83-
go.opentelemetry.io/collector/config/configauth v0.120.0 // indirect
8484
go.opentelemetry.io/collector/config/configcompression v1.26.0 // indirect
8585
go.opentelemetry.io/collector/connector/xconnector v0.120.0 // indirect
8686
go.opentelemetry.io/collector/consumer/consumererror v0.120.0 // indirect

0 commit comments

Comments
 (0)