From d4a8080bb55294ebfcdc1517da7ed1d63136f06b Mon Sep 17 00:00:00 2001 From: go-follow Date: Wed, 18 Oct 2023 19:52:00 +0700 Subject: [PATCH] [exporter/cassandra] close #27828 added authorization by username and password --- exporter/cassandraexporter/README.md | 4 ++++ exporter/cassandraexporter/config.go | 6 ++++++ exporter/cassandraexporter/exporter_logs.go | 6 ++++++ exporter/cassandraexporter/exporter_traces.go | 6 ++++++ 4 files changed, 22 insertions(+) diff --git a/exporter/cassandraexporter/README.md b/exporter/cassandraexporter/README.md index 1efd9cd72805..3daeef4f774f 100644 --- a/exporter/cassandraexporter/README.md +++ b/exporter/cassandraexporter/README.md @@ -24,6 +24,7 @@ The following settings can be optionally configured: - `replication` (default = class: SimpleStrategy, replication_factor: 1) The strategy of replication. https://cassandra.apache.org/doc/4.1/cassandra/architecture/dynamo.html#replication-strategy - `compression` (default = LZ4Compressor) https://cassandra.apache.org/doc/latest/cassandra/operating/compression.html +- `auth` (default = username: "", password: "") Authorization for the Cassandra. ## Example @@ -39,4 +40,7 @@ exporters: replication_factor: 1 compression: algorithm: "ZstdCompressor" + auth: + username: "your-username" + password: "your-password" ``` diff --git a/exporter/cassandraexporter/config.go b/exporter/cassandraexporter/config.go index b9b6bd769437..dbe0747fde5f 100644 --- a/exporter/cassandraexporter/config.go +++ b/exporter/cassandraexporter/config.go @@ -11,6 +11,7 @@ type Config struct { LogsTable string `mapstructure:"logs_table"` Replication Replication `mapstructure:"replication"` Compression Compression `mapstructure:"compression"` + Auth Auth `mapstructure:"auth"` } type Replication struct { @@ -21,3 +22,8 @@ type Replication struct { type Compression struct { Algorithm string `mapstructure:"algorithm"` } + +type Auth struct { + UserName string `mapstructure:"username"` + Password string `mapstructure:"password"` +} diff --git a/exporter/cassandraexporter/exporter_logs.go b/exporter/cassandraexporter/exporter_logs.go index 8b824829358a..4ad1cc2155af 100644 --- a/exporter/cassandraexporter/exporter_logs.go +++ b/exporter/cassandraexporter/exporter_logs.go @@ -25,6 +25,12 @@ type logsExporter struct { func newLogsExporter(logger *zap.Logger, cfg *Config) (*logsExporter, error) { cluster := gocql.NewCluster(cfg.DSN) + if cfg.Auth.UserName != "" && cfg.Auth.Password != "" { + cluster.Authenticator = gocql.PasswordAuthenticator{ + Username: cfg.Auth.UserName, + Password: cfg.Auth.Password, + } + } session, err := cluster.CreateSession() cluster.Keyspace = cfg.Keyspace cluster.Consistency = gocql.Quorum diff --git a/exporter/cassandraexporter/exporter_traces.go b/exporter/cassandraexporter/exporter_traces.go index f8f72e342d92..cb8d25aec7e5 100644 --- a/exporter/cassandraexporter/exporter_traces.go +++ b/exporter/cassandraexporter/exporter_traces.go @@ -24,6 +24,12 @@ type tracesExporter struct { func newTracesExporter(logger *zap.Logger, cfg *Config) (*tracesExporter, error) { cluster := gocql.NewCluster(cfg.DSN) + if cfg.Auth.UserName != "" && cfg.Auth.Password != "" { + cluster.Authenticator = gocql.PasswordAuthenticator{ + Username: cfg.Auth.UserName, + Password: cfg.Auth.Password, + } + } session, err := cluster.CreateSession() cluster.Keyspace = cfg.Keyspace cluster.Consistency = gocql.Quorum