-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[exporter/cassandra] Added authorization by username and password (#2…
…7841) Added authorization by username and password for the Casandra exporter Fixes #27827 --------- Co-authored-by: Curtis Robert <92119472+crobert-1@users.noreply.github.com>
- Loading branch information
Showing
8 changed files
with
142 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: cassandraexporter | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: added authorization by username and password | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [27827] | ||
|
||
# (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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cassandraexporter | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/gocql/gocql" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNewCluster(t *testing.T) { | ||
testCases := map[string]struct { | ||
cfg *Config | ||
expectedAuthenticator gocql.Authenticator | ||
expectedErr error | ||
}{ | ||
"empty_auth": { | ||
cfg: withDefaultConfig(), | ||
expectedAuthenticator: nil, | ||
}, | ||
"empty_username": { | ||
cfg: withDefaultConfig(func(config *Config) { | ||
config.Auth.Password = "pass" | ||
}), | ||
expectedAuthenticator: nil, | ||
expectedErr: errors.New("empty auth.username"), | ||
}, | ||
"empty_password": { | ||
cfg: withDefaultConfig(func(config *Config) { | ||
config.Auth.UserName = "user" | ||
}), | ||
expectedAuthenticator: nil, | ||
expectedErr: errors.New("empty auth.password"), | ||
}, | ||
"success_auth": { | ||
cfg: withDefaultConfig(func(config *Config) { | ||
config.Auth.UserName = "user" | ||
config.Auth.Password = "pass" | ||
}), | ||
expectedAuthenticator: gocql.PasswordAuthenticator{ | ||
Username: "user", | ||
Password: "pass", | ||
}, | ||
}, | ||
} | ||
for name, test := range testCases { | ||
t.Run(name, func(t *testing.T) { | ||
c, err := newCluster(test.cfg) | ||
if err == nil { | ||
require.Equal(t, test.expectedAuthenticator, c.Authenticator) | ||
} | ||
require.Equal(t, test.expectedErr, err) | ||
}) | ||
} | ||
} | ||
|
||
func withDefaultConfig(fns ...func(*Config)) *Config { | ||
cfg := createDefaultConfig().(*Config) | ||
for _, fn := range fns { | ||
fn(cfg) | ||
} | ||
return cfg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.