-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
185 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,57 @@ | ||
package kafka | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/Shopify/sarama" | ||
|
||
"github.com/confluentinc/cli/shared" | ||
) | ||
|
||
func NewSaramaKafka(kafka shared.KafkaCluster) (sarama.Client, error) { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
return sarama.NewClient(strings.Split(kafka.Bootstrap, ","), saramaConf(kafka)) | ||
} | ||
|
||
func NewSaramaAdmin(kafka shared.KafkaCluster) (sarama.ClusterAdmin, error) { | ||
return sarama.NewClusterAdmin(strings.Split(kafka.Bootstrap, ","), saramaConf(kafka)) | ||
} | ||
|
||
func NewSaramaKafkaForConfig(config *shared.Config) (sarama.Client, error) { | ||
cluster, err := kafkaCluster(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return NewSaramaKafka(cluster) | ||
} | ||
|
||
func NewSaramaAdminForConfig(config *shared.Config) (sarama.ClusterAdmin, error) { | ||
cluster, err := kafkaCluster(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return NewSaramaAdmin(cluster) | ||
} | ||
|
||
func kafkaCluster(config *shared.Config) (shared.KafkaCluster, error) { | ||
cfg, err := config.Context() | ||
if err != nil { | ||
return shared.KafkaCluster{}, err | ||
} | ||
cluster, found := config.Platforms[cfg.Platform].KafkaClusters[cfg.Kafka] | ||
if !found { | ||
e := fmt.Errorf("No auth found for Kafka %s. Please run `confluent kafka cluster auth` first.\n", cfg.Kafka) | ||
return shared.KafkaCluster{}, shared.ErrNotAuthenticated(e) | ||
} | ||
return cluster, nil | ||
} | ||
|
||
func saramaConf(kafka shared.KafkaCluster) *sarama.Config { | ||
saramaConf := sarama.NewConfig() | ||
saramaConf.Version = sarama.V1_1_0_0 | ||
saramaConf.Net.TLS.Enable = true | ||
saramaConf.Net.SASL.Enable = true | ||
saramaConf.Net.SASL.User = kafka.APIKey | ||
saramaConf.Net.SASL.Password = kafka.APISecret | ||
return saramaConf | ||
} |
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
Create a nested pkg for sarama if you want get rid of the Sarama prefix on all these apis