Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
codyaray committed Aug 3, 2018
1 parent 66a90a8 commit 01050ce
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gometalinter.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"command/.*/grpc.go:.* exported (method|type) .* should have comment or be unexported.*golint.*",
"command/.*/interface.go:.* exported (method|type) .* should have comment or be unexported.*golint.*",
"shared/errors.go:.* exported var Err.* should have comment or be unexported.*golint.*",
"shared/errors.go:.* exported type .*Error should have comment or be unexported.*golint.*",
"plugin/.*/main.go:.* exported (method|type) .* should have comment or be unexported.*golint.*",

".*Errors unhandled.*logger.Log.*gas.*",
Expand Down
4 changes: 2 additions & 2 deletions command/common/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func HandleError(err error) error {
switch err.(type) {
case editor.ErrEditing:
fmt.Println(err)
case shared.ErrNotAuthenticated:
case shared.NotAuthenticatedError:
fmt.Println(err)
case shared.ErrKafka:
case shared.KafkaError:
fmt.Println(err)
default:
return err
Expand Down
8 changes: 4 additions & 4 deletions command/kafka/command_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ func (c *clusterCommand) use(cmd *cobra.Command, args []string) error {
// Helper functions
//

func userHasKey(kafkaClusterId string) (bool, error) {
func userHasKey(kafkaClusterID string) (bool, error) {
reader := bufio.NewReader(os.Stdin)
fmt.Printf("Do you have an API key for %s? [N/y] ", kafkaClusterId)
fmt.Printf("Do you have an API key for %s? [N/y] ", kafkaClusterID)
response, err := reader.ReadString('\n')
if err != nil {
return false, err
Expand Down Expand Up @@ -212,11 +212,11 @@ func promptForKafkaCreds() (string, string, error) {
return strings.TrimSpace(key), strings.TrimSpace(secret), nil
}

func (c *clusterCommand) createKafkaCreds(kafkaClusterId string) (string, string, error) {
func (c *clusterCommand) createKafkaCreds(kafkaClusterID string) (string, string, error) {
client := chttp.NewClientWithJWT(context.Background(), c.config.AuthToken, c.config.AuthURL, c.config.Logger)
key, _, err := client.APIKey.Create(&orgv1.ApiKey{
UserId: c.config.Auth.User.Id,
ClusterId: kafkaClusterId,
ClusterId: kafkaClusterID,
})
if err != nil {
return "", "", shared.ConvertAPIError(err)
Expand Down
15 changes: 7 additions & 8 deletions command/kafka/command_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewTopicCommand(config *shared.Config, kafka Kafka) *cobra.Command {
return cmd.Command
}

func (c *topicCommand) init() error {
func (c *topicCommand) init() {
c.AddCommand(&cobra.Command{
Use: "list",
Short: "List Kafka topics.",
Expand Down Expand Up @@ -80,17 +80,16 @@ func (c *topicCommand) init() error {
RunE: c.consume,
Args: cobra.ExactArgs(1),
})
return nil
}

func (c *topicCommand) list(cmd *cobra.Command, args []string) error {
client, err := NewSaramaKafkaForConfig(c.config)
if err != nil {
return common.HandleError(shared.ErrKafka(err))
return common.HandleError(shared.KafkaError(err))
}
topics, err := client.Topics()
if err != nil {
return common.HandleError(shared.ErrKafka(err))
return common.HandleError(shared.KafkaError(err))
}
for _, topic := range topics {
fmt.Println(topic)
Expand All @@ -113,7 +112,7 @@ func (c *topicCommand) create(cmd *cobra.Command, args []string) error {
}
client, err := NewSaramaAdminForConfig(c.config)
if err != nil {
return common.HandleError(shared.ErrKafka(err))
return common.HandleError(shared.KafkaError(err))
}
entries := map[string]*string{}
for _, config := range configs {
Expand All @@ -126,7 +125,7 @@ func (c *topicCommand) create(cmd *cobra.Command, args []string) error {
ConfigEntries: entries,
}
err = client.CreateTopic(args[0], config, false)
return common.HandleError(shared.ErrKafka(err))
return common.HandleError(shared.KafkaError(err))
}

func (c *topicCommand) describe(cmd *cobra.Command, args []string) error {
Expand All @@ -140,10 +139,10 @@ func (c *topicCommand) update(cmd *cobra.Command, args []string) error {
func (c *topicCommand) delete(cmd *cobra.Command, args []string) error {
client, err := NewSaramaAdminForConfig(c.config)
if err != nil {
return common.HandleError(shared.ErrKafka(err))
return common.HandleError(shared.KafkaError(err))
}
err = client.DeleteTopic(args[0])
return common.HandleError(shared.ErrKafka(err))
return common.HandleError(shared.KafkaError(err))
}

func (c *topicCommand) produce(cmd *cobra.Command, args []string) error {
Expand Down
8 changes: 6 additions & 2 deletions command/kafka/sarama.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ import (
"github.com/confluentinc/cli/shared"
)

// NewSaramaKafka returns a sarama.Client configured for the KafkaCluster
func NewSaramaKafka(kafka shared.KafkaCluster) (sarama.Client, error) {
return sarama.NewClient(strings.Split(kafka.Bootstrap, ","), saramaConf(kafka))
}

// NewSaramaAdmin returns a sarama.ClusterAdmin configured for the KafkaCluster
func NewSaramaAdmin(kafka shared.KafkaCluster) (sarama.ClusterAdmin, error) {
return sarama.NewClusterAdmin(strings.Split(kafka.Bootstrap, ","), saramaConf(kafka))
}

// NewSaramaKafkaForConfig returns a sarama.Client configured for the CLI config
func NewSaramaKafkaForConfig(config *shared.Config) (sarama.Client, error) {
cluster, err := kafkaCluster(config)
if err != nil {
Expand All @@ -25,6 +28,7 @@ func NewSaramaKafkaForConfig(config *shared.Config) (sarama.Client, error) {
return NewSaramaKafka(cluster)
}

// NewSaramaAdminForConfig returns a sarama.ClusterAdmin configured for the CLI config
func NewSaramaAdminForConfig(config *shared.Config) (sarama.ClusterAdmin, error) {
cluster, err := kafkaCluster(config)
if err != nil {
Expand All @@ -40,8 +44,8 @@ func kafkaCluster(config *shared.Config) (shared.KafkaCluster, error) {
}
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)
e := fmt.Errorf("no auth found for Kafka %s, please run `confluent kafka cluster auth` first", cfg.Kafka)
return shared.KafkaCluster{}, shared.NotAuthenticatedError(e)
}
return cluster, nil
}
Expand Down
12 changes: 6 additions & 6 deletions http/api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ import (
"github.com/confluentinc/cli/log"
)

// ApiKeyService provides methods for managing API keys on Confluent Control Plane.
type ApiKeyService struct {
// APIKeyService provides methods for managing API keys on Confluent Control Plane.
type APIKeyService struct {
client *http.Client
sling *sling.Sling
logger *log.Logger
}

// NewAPIKeyService returns a new ApiKeyService.
func NewAPIKeyService(client *Client) *ApiKeyService {
return &ApiKeyService{
// NewAPIKeyService returns a new APIKeyService.
func NewAPIKeyService(client *Client) *APIKeyService {
return &APIKeyService{
client: client.httpClient,
logger: client.logger,
sling: client.sling,
}
}

// Create makes a new API Key
func (s *ApiKeyService) Create(key *orgv1.ApiKey) (*orgv1.ApiKey, *http.Response, error) {
func (s *APIKeyService) Create(key *orgv1.ApiKey) (*orgv1.ApiKey, *http.Response, error) {
request := &orgv1.CreateApiKeyRequest{ApiKey: key}
reply := new(orgv1.CreateApiKeyReply)
resp, err := s.sling.New().Post("/api/api_keys").BodyJSON(request).Receive(reply, reply)
Expand Down
2 changes: 1 addition & 1 deletion http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Client struct {
Kafka *KafkaService
Connect *ConnectService
User *UserService
APIKey *ApiKeyService
APIKey *APIKeyService
}

// NewClient creates a Confluent SDK client.
Expand Down
4 changes: 2 additions & 2 deletions shared/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
* - Commands call ConvertGRPCError() to transform these back into HTTP Error constants
*/

type ErrNotAuthenticated error
type ErrKafka error
type NotAuthenticatedError error
type KafkaError error

var (
ErrNotImplemented = fmt.Errorf("not implemented")
Expand Down

0 comments on commit 01050ce

Please sign in to comment.