Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pkg/cmd/kafka/consumergroup/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ func runCmd(opts *Options) error {
ctx := context.Background()

_, httpRes, err := api.GroupsApi.GetConsumerGroupById(ctx, opts.id).Execute()
defer httpRes.Body.Close()
if httpRes != nil {
defer httpRes.Body.Close()
}

cgIDPair := localize.NewEntry("ID", opts.id)
kafkaNameTmplPair := localize.NewEntry("InstanceName", kafkaInstance.GetName())
Expand Down Expand Up @@ -122,14 +124,15 @@ func runCmd(opts *Options) error {
}

httpRes, err = api.GroupsApi.DeleteConsumerGroupById(ctx, opts.id).Execute()
if httpRes != nil {
defer httpRes.Body.Close()
}

if err != nil {
if httpRes == nil {
return err
}

defer httpRes.Body.Close()

operationTmplPair := localize.NewEntry("Operation", "delete")

switch httpRes.StatusCode {
Expand Down
5 changes: 4 additions & 1 deletion pkg/cmd/kafka/consumergroup/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ func runCmd(opts *Options) error {
ctx := context.Background()

consumerGroupData, httpRes, err := api.GroupsApi.GetConsumerGroupById(ctx, opts.id).Execute()
defer httpRes.Body.Close()
if httpRes != nil {
defer httpRes.Body.Close()
}

if err != nil {
if httpRes == nil {
return err
Expand Down
4 changes: 3 additions & 1 deletion pkg/cmd/kafka/consumergroup/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ func runList(opts *Options) (err error) {
req = req.Page(opts.page)

consumerGroupData, httpRes, err := req.Execute()
defer httpRes.Body.Close()
if httpRes != nil {
defer httpRes.Body.Close()
}
if err != nil {
if httpRes == nil {
return err
Expand Down
9 changes: 7 additions & 2 deletions pkg/cmd/kafka/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ func runCreate(opts *Options) error {
a = a.KafkaRequestPayload(*payload)
a = a.Async(true)
response, httpRes, err := a.Execute()
defer httpRes.Body.Close()
if httpRes != nil {
defer httpRes.Body.Close()
}

if httpRes.StatusCode == http.StatusBadRequest {
return errors.New(opts.localizer.MustLocalize("kafka.create.error.conflictError", localize.NewEntry("Name", payload.Name)))
Expand Down Expand Up @@ -295,7 +297,10 @@ func promptKafkaPayload(opts *Options) (payload *kafkamgmtclient.KafkaRequestPay

// fetch all cloud available providers
cloudProviderResponse, httpRes, err := api.Kafka().GetCloudProviders(context.Background()).Execute()
defer httpRes.Body.Close()
if httpRes != nil {
defer httpRes.Body.Close()
}

if err != nil {
return nil, err
}
Expand Down
12 changes: 10 additions & 2 deletions pkg/cmd/kafka/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"net/http"

flagutil "github.com/redhat-developer/app-services-cli/pkg/cmdutil/flags"
"github.com/redhat-developer/app-services-cli/pkg/connection"
Expand Down Expand Up @@ -103,14 +104,21 @@ func runDescribe(opts *Options) error {
api := conn.API()

var kafkaInstance *kafkamgmtclient.KafkaRequest
var httpRes *http.Response
ctx := context.Background()
if opts.name != "" {
kafkaInstance, _, err = kafka.GetKafkaByName(ctx, api.Kafka(), opts.name)
kafkaInstance, httpRes, err = kafka.GetKafkaByName(ctx, api.Kafka(), opts.name)
if httpRes != nil {
defer httpRes.Body.Close()
}
if err != nil {
return err
}
} else {
kafkaInstance, _, err = kafka.GetKafkaByID(ctx, api.Kafka(), opts.id)
kafkaInstance, httpRes, err = kafka.GetKafkaByID(ctx, api.Kafka(), opts.id)
if httpRes != nil {
defer httpRes.Body.Close()
}
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/cmd/kafka/topic/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ func runCmd(opts *Options) error {
createTopicReq = createTopicReq.NewTopicInput(topicInput)

response, httpRes, err := createTopicReq.Execute()
defer httpRes.Body.Close()
if httpRes != nil {
defer httpRes.Body.Close()
}

if err != nil {
if httpRes == nil {
Expand Down
8 changes: 6 additions & 2 deletions pkg/cmd/kafka/topic/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ func runCmd(opts *Options) error {

// perform delete topic API request
_, httpRes, err := api.TopicsApi.GetTopic(context.Background(), opts.topicName).Execute()
defer httpRes.Body.Close()
if httpRes != nil {
defer httpRes.Body.Close()
}

topicNameTmplPair := localize.NewEntry("TopicName", opts.topicName)
kafkaNameTmplPair := localize.NewEntry("InstanceName", kafkaInstance.GetName())
Expand Down Expand Up @@ -126,6 +128,9 @@ func runCmd(opts *Options) error {

// perform delete topic API request
httpRes, err = api.TopicsApi.DeleteTopic(context.Background(), opts.topicName).Execute()
if httpRes != nil {
defer httpRes.Body.Close()
}
if err != nil {
if httpRes == nil {
return err
Expand All @@ -147,7 +152,6 @@ func runCmd(opts *Options) error {
return err
}
}
defer httpRes.Body.Close()

opts.Logger.Info(opts.localizer.MustLocalize("kafka.topic.delete.log.info.topicDeleted", topicNameTmplPair, kafkaNameTmplPair))

Expand Down
4 changes: 3 additions & 1 deletion pkg/cmd/kafka/topic/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ func runCmd(opts *Options) error {

// fetch the topic
topicResponse, httpRes, err := api.TopicsApi.GetTopic(context.Background(), opts.name).Execute()
defer httpRes.Body.Close()
if httpRes != nil {
defer httpRes.Body.Close()
}

if err != nil {
if httpRes == nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/cmd/kafka/topic/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ func runCmd(opts *Options) error {
a = a.Page(opts.page)

topicData, httpRes, err := a.Execute()
if httpRes != nil {
defer httpRes.Body.Close()
}
if err != nil {
if httpRes == nil {
return err
Expand All @@ -158,8 +161,6 @@ func runCmd(opts *Options) error {
}
}

defer httpRes.Body.Close()

if topicData.GetTotal() == 0 && opts.output == "" {
opts.Logger.Info(opts.localizer.MustLocalize("kafka.topic.list.log.info.noTopics", localize.NewEntry("InstanceName", kafkaInstance.GetName())))

Expand Down
12 changes: 9 additions & 3 deletions pkg/cmd/kafka/topic/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ func runCmd(opts *Options) error {
var needsUpdate bool

topic, httpRes, err := api.TopicsApi.GetTopic(context.Background(), opts.name).Execute()
defer httpRes.Body.Close()
if httpRes != nil {
defer httpRes.Body.Close()
}

topicNameTmplPair := localize.NewEntry("TopicName", opts.name)
kafkaNameTmplPair := localize.NewEntry("InstanceName", kafkaInstance.GetName())
Expand Down Expand Up @@ -274,7 +276,9 @@ func runCmd(opts *Options) error {

// update the topic
response, httpRes, err := updateTopicReq.Execute()
defer httpRes.Body.Close()
if httpRes != nil {
defer httpRes.Body.Close()
}

// handle error
if err != nil {
Expand Down Expand Up @@ -326,7 +330,9 @@ func runInteractivePrompt(opts *Options) (err error) {

// check if topic exists
topic, httpRes, err := api.TopicsApi.GetTopic(context.Background(), opts.name).Execute()
defer httpRes.Body.Close()
if httpRes != nil {
defer httpRes.Body.Close()
}

topicNameTmplPair := localize.NewEntry("TopicName", opts.name)
kafkaNameTmplPair := localize.NewEntry("InstanceName", kafkaInstance.GetName())
Expand Down
8 changes: 6 additions & 2 deletions pkg/cmd/serviceaccount/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ func runDelete(opts *Options) (err error) {
}

_, httpRes, err := conn.API().ServiceAccount().GetServiceAccountById(context.Background(), opts.id).Execute()
defer httpRes.Body.Close()
if httpRes != nil {
defer httpRes.Body.Close()
}
if err != nil {
if httpRes == nil {
return err
Expand Down Expand Up @@ -115,7 +117,9 @@ func deleteServiceAccount(opts *Options) error {
}

_, httpRes, err := conn.API().ServiceAccount().DeleteServiceAccountById(context.Background(), opts.id).Execute()
defer httpRes.Body.Close()
if httpRes != nil {
defer httpRes.Body.Close()
}
if err != nil {
if httpRes == nil {
return err
Expand Down
4 changes: 3 additions & 1 deletion pkg/cmd/serviceaccount/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ func runDescribe(opts *Options) error {
api := conn.API()

res, httpRes, err := api.ServiceAccount().GetServiceAccountById(context.Background(), opts.id).Execute()
defer httpRes.Body.Close()
if httpRes != nil {
defer httpRes.Body.Close()
}
if err != nil {
if httpRes == nil {
return err
Expand Down
9 changes: 7 additions & 2 deletions pkg/cmd/serviceaccount/resetcredentials/reset_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ func runResetCredentials(opts *Options) (err error) {
api := conn.API()

serviceacct, httpRes, err := api.ServiceAccount().GetServiceAccountById(context.Background(), opts.id).Execute()
defer httpRes.Body.Close()
if httpRes != nil {
defer httpRes.Body.Close()
}

if err != nil {
return err
}
Expand Down Expand Up @@ -182,7 +185,9 @@ func resetCredentials(name string, opts *Options) (*kafkamgmtclient.ServiceAccou
opts.Logger.Debug(opts.localizer.MustLocalize("serviceAccount.resetCredentials.log.debug.resettingCredentials", localize.NewEntry("Name", name)))

serviceacct, httpRes, err := api.ServiceAccount().ResetServiceAccountCreds(context.Background(), opts.id).Execute()
defer httpRes.Body.Close()
if httpRes != nil {
defer httpRes.Body.Close()
}
if err != nil {
if httpRes == nil {
return nil, err
Expand Down
File renamed without changes.
17 changes: 5 additions & 12 deletions pkg/kafka/kafka_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,13 @@ func (v *Validator) ValidateNameIsAvailable(val interface{}) error {

api := conn.API()

_, httpRes, err := GetKafkaByName(context.Background(), api.Kafka(), name)
_, httpRes, _ := GetKafkaByName(context.Background(), api.Kafka(), name)

if httpRes != nil {
defer httpRes.Body.Close()
}
if err != nil {
return err
}

if httpRes != nil && httpRes.StatusCode == http.StatusOK {
return errors.New(v.Localizer.MustLocalize("kafka.create.error.conflictError", localize.NewEntry("Name", name)))
}

if httpRes != nil && httpRes.Body != nil {
httpRes.Body.Close()
if httpRes.StatusCode == http.StatusOK {
return errors.New(v.Localizer.MustLocalize("kafka.create.error.conflictError", localize.NewEntry("Name", name)))
}
}

return nil
Expand Down
13 changes: 7 additions & 6 deletions pkg/kafka/topic/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,13 @@ func (v *Validator) ValidateNameIsAvailable(val interface{}) error {
return err
}

_, httpRes, _ := api.TopicsApi.GetTopic(context.Background(), name).Execute()

if httpRes != nil && httpRes.StatusCode == http.StatusOK {
return errors.New(v.Localizer.MustLocalize("kafka.topic.create.error.conflictError", localize.NewEntry("TopicName", name), localize.NewEntry("InstanceName", kafkaInstance.GetName())))
_, httpRes, err := api.TopicsApi.GetTopic(context.Background(), name).Execute()
if httpRes != nil {
defer httpRes.Body.Close()
if httpRes.StatusCode == http.StatusOK {
return errors.New(v.Localizer.MustLocalize("kafka.topic.create.error.conflictError", localize.NewEntry("TopicName", name), localize.NewEntry("InstanceName", kafkaInstance.GetName())))
}
}
defer httpRes.Body.Close()

return nil
return err
}