diff --git a/cmd/rhoas/main.go b/cmd/rhoas/main.go index d8b61fc69..9176415a1 100644 --- a/cmd/rhoas/main.go +++ b/cmd/rhoas/main.go @@ -1,7 +1,6 @@ package main import ( - "context" "fmt" "os" "strings" @@ -52,12 +51,12 @@ func main() { err = rootCmd.Execute() if err == nil { if debug.Enabled() { - build.CheckForUpdate(context.Background(), cmdFactory.Logger, localizer) + build.CheckForUpdate(cmdFactory.Context, cmdFactory.Logger, localizer) } return } cmdFactory.Logger.Error(rootError(err, localizer)) - build.CheckForUpdate(context.Background(), cmdFactory.Logger, localizer) + build.CheckForUpdate(cmdFactory.Context, cmdFactory.Logger, localizer) os.Exit(1) } diff --git a/pkg/ams/ams.go b/pkg/ams/ams.go index 24d9bc3f7..59cf3f850 100644 --- a/pkg/ams/ams.go +++ b/pkg/ams/ams.go @@ -9,9 +9,9 @@ import ( "github.com/redhat-developer/app-services-cli/pkg/connection" ) -func CheckTermsAccepted(conn connection.Connection) (accepted bool, redirectURI string, err error) { +func CheckTermsAccepted(ctx context.Context, conn connection.Connection) (accepted bool, redirectURI string, err error) { termsReview, _, err := conn.API().AccountMgmt(). - ApiAuthorizationsV1SelfTermsReviewPost(context.Background()). + ApiAuthorizationsV1SelfTermsReviewPost(ctx). SelfTermsReview(amsclient.SelfTermsReview{ EventCode: &build.TermsReviewEventCode, SiteCode: &build.TermsReviewSiteCode, diff --git a/pkg/cluster/kcManager.go b/pkg/cluster/kcManager.go index 3c89eafc3..71a38978f 100644 --- a/pkg/cluster/kcManager.go +++ b/pkg/cluster/kcManager.go @@ -84,10 +84,10 @@ func getKafkaConnectionsAPIURL(namespace string) string { return fmt.Sprintf("/apis/rhoas.redhat.com/v1alpha1/namespaces/%v/kafkaconnections", namespace) } -func watchForKafkaStatus(c *KubernetesCluster, crName string, namespace string) error { +func watchForKafkaStatus(ctx context.Context, c *KubernetesCluster, crName string, namespace string) error { c.logger.Info(c.localizer.MustLocalize("cluster.kubernetes.watchForKafkaStatus.log.info.wait")) - w, err := c.dynamicClient.Resource(AKCResource).Namespace(namespace).Watch(context.TODO(), metav1.ListOptions{ + w, err := c.dynamicClient.Resource(AKCResource).Namespace(namespace).Watch(ctx, metav1.ListOptions{ FieldSelector: fields.OneTermEqualSelector("metadata.name", crName).String(), }) if err != nil { diff --git a/pkg/cluster/kubernetes_cluster.go b/pkg/cluster/kubernetes_cluster.go index f42d5f97d..797204b0f 100644 --- a/pkg/cluster/kubernetes_cluster.go +++ b/pkg/cluster/kubernetes_cluster.go @@ -213,7 +213,7 @@ func (c *KubernetesCluster) createKafkaConnectionCustomResource(ctx context.Cont c.logger.Info(c.localizer.MustLocalize("cluster.kubernetes.createKafkaCR.log.info.customResourceCreated", localize.NewEntry("Name", crName))) - return watchForKafkaStatus(c, crName, namespace) + return watchForKafkaStatus(ctx, c, crName, namespace) } // IsRhoasOperatorAvailableOnCluster checks the cluster to see if a KafkaConnection CRD is installed @@ -222,7 +222,7 @@ func (c *KubernetesCluster) IsRhoasOperatorAvailableOnCluster(ctx context.Contex } func (c *KubernetesCluster) createTokenSecretIfNeeded(ctx context.Context, namespace string, opts *ConnectArguments) error { - _, err := c.clientset.CoreV1().Secrets(namespace).Get(context.TODO(), tokenSecretName, metav1.GetOptions{}) + _, err := c.clientset.CoreV1().Secrets(namespace).Get(ctx, tokenSecretName, metav1.GetOptions{}) if err == nil { c.logger.Info(c.localizer.MustLocalize("cluster.kubernetes.tokensecret.log.info.found"), tokenSecretName) return nil @@ -271,7 +271,7 @@ func (c *KubernetesCluster) createTokenSecretIfNeeded(ctx context.Context, names // createSecret creates a new secret to store the SASL/PLAIN credentials from the service account func (c *KubernetesCluster) createServiceAccountSecretIfNeeded(ctx context.Context, namespace string) error { - _, err := c.clientset.CoreV1().Secrets(namespace).Get(context.TODO(), serviceAccountSecretName, metav1.GetOptions{}) + _, err := c.clientset.CoreV1().Secrets(namespace).Get(ctx, serviceAccountSecretName, metav1.GetOptions{}) if err == nil { c.logger.Info(c.localizer.MustLocalize("cluster.kubernetes.serviceaccountsecret.log.info.exist")) return nil @@ -297,7 +297,7 @@ func (c *KubernetesCluster) createServiceAccountSecretIfNeeded(ctx context.Conte }, } - createdSecret, err := c.clientset.CoreV1().Secrets(namespace).Create(context.TODO(), secret, metav1.CreateOptions{}) + createdSecret, err := c.clientset.CoreV1().Secrets(namespace).Create(ctx, secret, metav1.CreateOptions{}) if err != nil { return fmt.Errorf("%v: %w", c.localizer.MustLocalize("cluster.kubernetes.serviceaccountsecret.error.createError"), err) } diff --git a/pkg/cluster/serviceBinding.go b/pkg/cluster/serviceBinding.go index 30774a819..5fdaa7903 100644 --- a/pkg/cluster/serviceBinding.go +++ b/pkg/cluster/serviceBinding.go @@ -46,7 +46,7 @@ type ServiceBindingOptions struct { BindAsFiles bool } -func ExecuteServiceBinding(logger logging.Logger, localizer localize.Localizer, options *ServiceBindingOptions) error { +func ExecuteServiceBinding(ctx context.Context, logger logging.Logger, localizer localize.Localizer, options *ServiceBindingOptions) error { clients, err := client(localizer) if err != nil { return err @@ -62,12 +62,12 @@ func ExecuteServiceBinding(logger logging.Logger, localizer localize.Localizer, // Get proper deployment if options.AppName == "" { - options.AppName, err = fetchAppNameFromCluster(clients, localizer, ns) + options.AppName, err = fetchAppNameFromCluster(ctx, clients, localizer, ns) if err != nil { return err } } else { - _, err = clients.dynamicClient.Resource(deploymentResource).Namespace(ns).Get(context.TODO(), options.AppName, metav1.GetOptions{}) + _, err = clients.dynamicClient.Resource(deploymentResource).Namespace(ns).Get(ctx, options.AppName, metav1.GetOptions{}) if err != nil { return err } @@ -92,13 +92,13 @@ func ExecuteServiceBinding(logger logging.Logger, localizer localize.Localizer, } // Check KafkaConnection - _, err = clients.dynamicClient.Resource(AKCResource).Namespace(ns).Get(context.TODO(), options.ServiceName, metav1.GetOptions{}) + _, err = clients.dynamicClient.Resource(AKCResource).Namespace(ns).Get(ctx, options.ServiceName, metav1.GetOptions{}) if err != nil { return errors.New(localizer.MustLocalize("cluster.serviceBinding.serviceMissing.message")) } // Execute binding - err = performBinding(options, ns, clients, logger, localizer) + err = performBinding(ctx, options, ns, clients, logger, localizer) if err != nil { return err } @@ -107,7 +107,7 @@ func ExecuteServiceBinding(logger logging.Logger, localizer localize.Localizer, return nil } -func performBinding(options *ServiceBindingOptions, ns string, clients *KubernetesClients, logger logging.Logger, localizer localize.Localizer) error { +func performBinding(ctx context.Context, options *ServiceBindingOptions, ns string, clients *KubernetesClients, logger logging.Logger, localizer localize.Localizer) error { serviceRef := v1alpha1.Service{ NamespacedRef: v1alpha1.NamespacedRef{ Ref: v1alpha1.Ref{ @@ -156,7 +156,7 @@ func performBinding(options *ServiceBindingOptions, ns string, clients *Kubernet // Check of operator is installed _, err := clients.dynamicClient.Resource(v1alpha1.GroupVersionResource).Namespace(ns). - List(context.TODO(), metav1.ListOptions{Limit: 1}) + List(ctx, metav1.ListOptions{Limit: 1}) if err != nil { if options.ForceUseOperator { return errors.New(localizer.MustLocalize("cluster.serviceBinding.operatorMissing") + err.Error()) @@ -165,10 +165,10 @@ func performBinding(options *ServiceBindingOptions, ns string, clients *Kubernet return useSDKForBinding(clients, sb) } - return useOperatorForBinding(logger, localizer, sb, clients, ns) + return useOperatorForBinding(ctx, logger, localizer, sb, clients, ns) } -func useOperatorForBinding(logger logging.Logger, localizer localize.Localizer, sb *v1alpha1.ServiceBinding, clients *KubernetesClients, ns string) error { +func useOperatorForBinding(ctx context.Context, logger logging.Logger, localizer localize.Localizer, sb *v1alpha1.ServiceBinding, clients *KubernetesClients, ns string) error { logger.Info(localizer.MustLocalize("cluster.serviceBinding.usingOperator")) sbData, err := runtime.DefaultUnstructuredConverter.ToUnstructured(sb) if err != nil { @@ -177,7 +177,7 @@ func useOperatorForBinding(logger logging.Logger, localizer localize.Localizer, unstructuredSB := unstructured.Unstructured{Object: sbData} _, err = clients.dynamicClient.Resource(v1alpha1.GroupVersionResource).Namespace(ns). - Create(context.TODO(), &unstructuredSB, metav1.CreateOptions{}) + Create(ctx, &unstructuredSB, metav1.CreateOptions{}) return err } @@ -199,8 +199,8 @@ func useSDKForBinding(clients *KubernetesClients, sb *v1alpha1.ServiceBinding) e return err } -func fetchAppNameFromCluster(clients *KubernetesClients, localizer localize.Localizer, ns string) (string, error) { - list, err := clients.dynamicClient.Resource(deploymentResource).Namespace(ns).List(context.TODO(), metav1.ListOptions{}) +func fetchAppNameFromCluster(ctx context.Context, clients *KubernetesClients, localizer localize.Localizer, ns string) (string, error) { + list, err := clients.dynamicClient.Resource(deploymentResource).Namespace(ns).List(ctx, metav1.ListOptions{}) if err != nil { return "", err } diff --git a/pkg/cmd/cluster/bind/bind.go b/pkg/cmd/cluster/bind/bind.go index e4cd80477..7d5bdbc46 100644 --- a/pkg/cmd/cluster/bind/bind.go +++ b/pkg/cmd/cluster/bind/bind.go @@ -21,6 +21,7 @@ type Options struct { Logger logging.Logger IO *iostreams.IOStreams localizer localize.Localizer + Context context.Context kubeconfigLocation string namespace string @@ -42,6 +43,7 @@ func NewBindCommand(f *factory.Factory) *cobra.Command { Logger: f.Logger, IO: f.IOStreams, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -85,7 +87,7 @@ func runBind(opts *Options) error { // In future config will include Id's of other services if cfg.Services.Kafka == nil || opts.ignoreContext { // nolint:govet - selectedKafka, err := kafka.InteractiveSelect(apiConnection, opts.Logger) + selectedKafka, err := kafka.InteractiveSelect(opts.Context, apiConnection, opts.Logger) if err != nil { return err } @@ -98,7 +100,7 @@ func runBind(opts *Options) error { } api := apiConnection.API() - kafkaInstance, _, err := api.Kafka().GetKafkaById(context.Background(), opts.selectedKafka).Execute() + kafkaInstance, _, err := api.Kafka().GetKafkaById(opts.Context, opts.selectedKafka).Execute() if err != nil { return err } @@ -107,7 +109,7 @@ func runBind(opts *Options) error { return errors.New(opts.localizer.MustLocalize("cluster.bind.error.emptyResponse")) } - err = cluster.ExecuteServiceBinding(opts.Logger, opts.localizer, &cluster.ServiceBindingOptions{ + err = cluster.ExecuteServiceBinding(opts.Context, opts.Logger, opts.localizer, &cluster.ServiceBindingOptions{ ServiceName: kafkaInstance.GetName(), Namespace: opts.namespace, AppName: opts.appName, diff --git a/pkg/cmd/cluster/connect/connect.go b/pkg/cmd/cluster/connect/connect.go index 6bf2646eb..52fe367ae 100644 --- a/pkg/cmd/cluster/connect/connect.go +++ b/pkg/cmd/cluster/connect/connect.go @@ -22,6 +22,7 @@ type Options struct { Logger logging.Logger IO *iostreams.IOStreams localizer localize.Localizer + Context context.Context kubeconfigLocation string namespace string @@ -39,6 +40,7 @@ func NewConnectCommand(f *factory.Factory) *cobra.Command { Logger: f.Logger, IO: f.IOStreams, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -83,7 +85,7 @@ func runConnect(opts *Options) error { // In future config will include Id's of other services if cfg.Services.Kafka == nil || opts.ignoreContext { // nolint - selectedKafka, err := kafka.InteractiveSelect(conn, opts.Logger) + selectedKafka, err := kafka.InteractiveSelect(opts.Context, conn, opts.Logger) if err != nil { return err } @@ -103,7 +105,7 @@ func runConnect(opts *Options) error { Namespace: opts.namespace, } - err = clusterConn.Connect(context.Background(), arguments) + err = clusterConn.Connect(opts.Context, arguments) if err != nil { return err } diff --git a/pkg/cmd/cluster/status/status.go b/pkg/cmd/cluster/status/status.go index fdd3d5a87..db84c5670 100644 --- a/pkg/cmd/cluster/status/status.go +++ b/pkg/cmd/cluster/status/status.go @@ -26,7 +26,7 @@ type Options struct { Logger logging.Logger IO *iostreams.IOStreams localizer localize.Localizer - + Context context.Context kubeconfig string } @@ -37,6 +37,7 @@ func NewStatusCommand(f *factory.Factory) *cobra.Command { Logger: f.Logger, IO: f.IOStreams, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -68,7 +69,7 @@ func runStatus(opts *Options) error { var operatorStatus string // Add versioning in future - isCRDInstalled, err := clusterConn.IsRhoasOperatorAvailableOnCluster(context.Background()) + isCRDInstalled, err := clusterConn.IsRhoasOperatorAvailableOnCluster(opts.Context) if isCRDInstalled && err != nil { opts.Logger.Debug(err) } diff --git a/pkg/cmd/factory/default.go b/pkg/cmd/factory/default.go index a896cc7d0..09d22b061 100644 --- a/pkg/cmd/factory/default.go +++ b/pkg/cmd/factory/default.go @@ -34,6 +34,8 @@ func New(localizer localize.Localizer) *Factory { logger, _ = loggerBuilder.Build() + ctx := context.Background() + connectionFunc := func(connectionCfg *connection.Config) (connection.Connection, error) { if conn != nil { return conn, nil @@ -99,7 +101,7 @@ func New(localizer localize.Localizer) *Factory { return nil, err } - err = conn.RefreshTokens(context.TODO()) + err = conn.RefreshTokens(ctx) if err != nil { return nil, err } @@ -113,5 +115,6 @@ func New(localizer localize.Localizer) *Factory { Connection: connectionFunc, Logger: logger, Localizer: localizer, + Context: ctx, } } diff --git a/pkg/cmd/factory/factory.go b/pkg/cmd/factory/factory.go index 15b07092f..aff0c11f3 100644 --- a/pkg/cmd/factory/factory.go +++ b/pkg/cmd/factory/factory.go @@ -1,6 +1,7 @@ package factory import ( + "context" "github.com/redhat-developer/app-services-cli/internal/config" "github.com/redhat-developer/app-services-cli/pkg/connection" "github.com/redhat-developer/app-services-cli/pkg/iostreams" @@ -21,6 +22,8 @@ type Factory struct { Logger logging.Logger // Localizer provides text to the commands Localizer localize.Localizer + // Context returns the default context for the application + Context context.Context } type ConnectionFunc func(cfg *connection.Config) (connection.Connection, error) diff --git a/pkg/cmd/kafka/consumergroup/delete/delete.go b/pkg/cmd/kafka/consumergroup/delete/delete.go index 40b5c7434..d72910a15 100644 --- a/pkg/cmd/kafka/consumergroup/delete/delete.go +++ b/pkg/cmd/kafka/consumergroup/delete/delete.go @@ -26,6 +26,7 @@ type Options struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context } // NewDeleteConsumerGroupCommand gets a new command for deleting a consumer group. @@ -36,6 +37,7 @@ func NewDeleteConsumerGroupCommand(f *factory.Factory) *cobra.Command { IO: f.IOStreams, Logger: f.Logger, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -88,9 +90,7 @@ func runCmd(opts *Options) error { return err } - ctx := context.Background() - - _, httpRes, err := api.GroupsApi.GetConsumerGroupById(ctx, opts.id).Execute() + _, httpRes, err := api.GroupsApi.GetConsumerGroupById(opts.Context, opts.id).Execute() if httpRes != nil { defer httpRes.Body.Close() } @@ -122,7 +122,7 @@ func runCmd(opts *Options) error { } } - httpRes, err = api.GroupsApi.DeleteConsumerGroupById(ctx, opts.id).Execute() + httpRes, err = api.GroupsApi.DeleteConsumerGroupById(opts.Context, opts.id).Execute() if httpRes != nil { defer httpRes.Body.Close() } diff --git a/pkg/cmd/kafka/consumergroup/describe/describe.go b/pkg/cmd/kafka/consumergroup/describe/describe.go index 97a957aa0..0d32a0d5c 100644 --- a/pkg/cmd/kafka/consumergroup/describe/describe.go +++ b/pkg/cmd/kafka/consumergroup/describe/describe.go @@ -35,6 +35,7 @@ type Options struct { Config config.IConfig Connection factory.ConnectionFunc localizer localize.Localizer + Context context.Context } type consumerRow struct { @@ -53,6 +54,7 @@ func NewDescribeConsumerGroupCommand(f *factory.Factory) *cobra.Command { Config: f.Config, IO: f.IOStreams, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ Use: "describe", @@ -111,9 +113,7 @@ func runCmd(opts *Options) error { return err } - ctx := context.Background() - - consumerGroupData, httpRes, err := api.GroupsApi.GetConsumerGroupById(ctx, opts.id).Execute() + consumerGroupData, httpRes, err := api.GroupsApi.GetConsumerGroupById(opts.Context, opts.id).Execute() if httpRes != nil { defer httpRes.Body.Close() } diff --git a/pkg/cmd/kafka/consumergroup/list/list.go b/pkg/cmd/kafka/consumergroup/list/list.go index 145490b44..a1878d0f0 100644 --- a/pkg/cmd/kafka/consumergroup/list/list.go +++ b/pkg/cmd/kafka/consumergroup/list/list.go @@ -31,6 +31,7 @@ type Options struct { Logger logging.Logger IO *iostreams.IOStreams localizer localize.Localizer + Context context.Context output string kafkaID string @@ -54,6 +55,7 @@ func NewListConsumerGroupCommand(f *factory.Factory) *cobra.Command { Logger: f.Logger, IO: f.IOStreams, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -112,14 +114,12 @@ func runList(opts *Options) (err error) { return err } - ctx := context.Background() - api, kafkaInstance, err := conn.API().KafkaAdmin(opts.kafkaID) if err != nil { return err } - req := api.GroupsApi.GetConsumerGroups(ctx) + req := api.GroupsApi.GetConsumerGroups(opts.Context) if opts.topic != "" { req = req.Topic(opts.topic) diff --git a/pkg/cmd/kafka/consumergroup/resetoffset/reset_offset.go b/pkg/cmd/kafka/consumergroup/resetoffset/reset_offset.go index 48d486d1d..e2b5423be 100644 --- a/pkg/cmd/kafka/consumergroup/resetoffset/reset_offset.go +++ b/pkg/cmd/kafka/consumergroup/resetoffset/reset_offset.go @@ -37,6 +37,7 @@ type Options struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context } type updatedConsumerRow struct { @@ -55,6 +56,7 @@ func NewResetOffsetConsumerGroupCommand(f *factory.Factory) *cobra.Command { IO: f.IOStreams, Logger: f.Logger, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -143,8 +145,6 @@ func runCmd(opts *Options) error { return err } - ctx := context.Background() - offsetResetParams := kafkainstanceclient.ConsumerGroupResetOffsetParameters{ Offset: opts.offset, } @@ -160,7 +160,7 @@ func runCmd(opts *Options) error { } if opts.id != "" { - _, httpRes, newErr := api.GroupsApi.GetConsumerGroupById(ctx, opts.id).Execute() + _, httpRes, newErr := api.GroupsApi.GetConsumerGroupById(opts.Context, opts.id).Execute() if httpRes != nil { defer httpRes.Body.Close() } @@ -179,7 +179,7 @@ func runCmd(opts *Options) error { } if opts.topic != "" { - _, httpRes, newErr := api.TopicsApi.GetTopic(context.Background(), opts.topic).Execute() + _, httpRes, newErr := api.TopicsApi.GetTopic(opts.Context, opts.topic).Execute() if httpRes != nil { defer httpRes.Body.Close() } @@ -209,7 +209,7 @@ func runCmd(opts *Options) error { offsetResetParams.Topics = &topicsToResetArr } - a := api.GroupsApi.ResetConsumerGroupOffset(ctx, opts.id).ConsumerGroupResetOffsetParameters(offsetResetParams) + a := api.GroupsApi.ResetConsumerGroupOffset(opts.Context, opts.id).ConsumerGroupResetOffsetParameters(offsetResetParams) if !opts.skipConfirm { diff --git a/pkg/cmd/kafka/create/create.go b/pkg/cmd/kafka/create/create.go index 835ae3189..7415dee50 100644 --- a/pkg/cmd/kafka/create/create.go +++ b/pkg/cmd/kafka/create/create.go @@ -55,6 +55,7 @@ type Options struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context } const ( @@ -72,6 +73,7 @@ func NewCreateCommand(f *factory.Factory) *cobra.Command { Connection: f.Connection, Logger: f.Logger, localizer: f.Localizer, + Context: f.Context, multiAZ: defaultMultiAZ, } @@ -141,7 +143,7 @@ func runCreate(opts *Options) error { // the user must have accepted the terms and conditions from the provider // before they can create a kafka instance - termsAccepted, termsURL, err := ams.CheckTermsAccepted(conn) + termsAccepted, termsURL, err := ams.CheckTermsAccepted(opts.Context, conn) if err != nil { return err } @@ -177,7 +179,7 @@ func runCreate(opts *Options) error { api := conn.API() - a := api.Kafka().CreateKafka(context.Background()) + a := api.Kafka().CreateKafka(opts.Context) a = a.KafkaRequestPayload(*payload) a = a.Async(true) response, httpRes, err := a.Execute() @@ -230,7 +232,7 @@ func runCreate(opts *Options) error { for svcstatus.IsCreating(response.GetStatus()) { time.Sleep(cmdutil.DefaultPollTime) - response, httpRes, err = api.Kafka().GetKafkaById(context.Background(), response.GetId()).Execute() + response, httpRes, err = api.Kafka().GetKafkaById(opts.Context, response.GetId()).Execute() if err != nil { return err } @@ -297,7 +299,7 @@ func promptKafkaPayload(opts *Options) (payload *kafkamgmtclient.KafkaRequestPay } // fetch all cloud available providers - cloudProviderResponse, httpRes, err := api.Kafka().GetCloudProviders(context.Background()).Execute() + cloudProviderResponse, httpRes, err := api.Kafka().GetCloudProviders(opts.Context).Execute() if httpRes != nil { defer httpRes.Body.Close() } @@ -323,7 +325,7 @@ func promptKafkaPayload(opts *Options) (payload *kafkamgmtclient.KafkaRequestPay selectedCloudProvider := kafkacmdutil.FindCloudProviderByName(cloudProviders, answers.CloudProvider) // nolint - cloudRegionResponse, _, err := api.Kafka().GetCloudProviderRegions(context.Background(), selectedCloudProvider.GetId()).Execute() + cloudRegionResponse, _, err := api.Kafka().GetCloudProviderRegions(opts.Context, selectedCloudProvider.GetId()).Execute() if err != nil { return nil, err } diff --git a/pkg/cmd/kafka/delete/delete.go b/pkg/cmd/kafka/delete/delete.go index bb2841162..4853ef964 100644 --- a/pkg/cmd/kafka/delete/delete.go +++ b/pkg/cmd/kafka/delete/delete.go @@ -32,6 +32,7 @@ type options struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context } // NewDeleteCommand command for deleting kafkas. @@ -42,6 +43,7 @@ func NewDeleteCommand(f *factory.Factory) *cobra.Command { Logger: f.Logger, IO: f.IOStreams, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -104,14 +106,13 @@ func runDelete(opts *options) error { api := conn.API() var response *kafkamgmtclient.KafkaRequest - ctx := context.Background() if opts.name != "" { - response, _, err = kafka.GetKafkaByName(ctx, api.Kafka(), opts.name) + response, _, err = kafka.GetKafkaByName(opts.Context, api.Kafka(), opts.name) if err != nil { return err } } else { - response, _, err = kafka.GetKafkaByID(ctx, api.Kafka(), opts.id) + response, _, err = kafka.GetKafkaByID(opts.Context, api.Kafka(), opts.id) if err != nil { return err } @@ -138,7 +139,7 @@ func runDelete(opts *options) error { // delete the Kafka opts.Logger.Debug(opts.localizer.MustLocalize("kafka.delete.log.debug.deletingKafka"), fmt.Sprintf("\"%s\"", kafkaName)) - a := api.Kafka().DeleteKafkaById(context.Background(), response.GetId()) + a := api.Kafka().DeleteKafkaById(opts.Context, response.GetId()) a = a.Async(true) _, _, err = a.Execute() diff --git a/pkg/cmd/kafka/describe/describe.go b/pkg/cmd/kafka/describe/describe.go index 27444e00c..ad0ac9dba 100644 --- a/pkg/cmd/kafka/describe/describe.go +++ b/pkg/cmd/kafka/describe/describe.go @@ -34,6 +34,7 @@ type Options struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context } // NewDescribeCommand describes a Kafka instance, either by passing an `--id flag` @@ -45,6 +46,7 @@ func NewDescribeCommand(f *factory.Factory) *cobra.Command { IO: f.IOStreams, Logger: f.Logger, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -105,9 +107,8 @@ func runDescribe(opts *Options) error { var kafkaInstance *kafkamgmtclient.KafkaRequest var httpRes *http.Response - ctx := context.Background() if opts.name != "" { - kafkaInstance, httpRes, err = kafka.GetKafkaByName(ctx, api.Kafka(), opts.name) + kafkaInstance, httpRes, err = kafka.GetKafkaByName(opts.Context, api.Kafka(), opts.name) if httpRes != nil { defer httpRes.Body.Close() } @@ -115,7 +116,7 @@ func runDescribe(opts *Options) error { return err } } else { - kafkaInstance, httpRes, err = kafka.GetKafkaByID(ctx, api.Kafka(), opts.id) + kafkaInstance, httpRes, err = kafka.GetKafkaByID(opts.Context, api.Kafka(), opts.id) if httpRes != nil { defer httpRes.Body.Close() } diff --git a/pkg/cmd/kafka/list/list.go b/pkg/cmd/kafka/list/list.go index 288bc3296..cc0282ed3 100644 --- a/pkg/cmd/kafka/list/list.go +++ b/pkg/cmd/kafka/list/list.go @@ -48,6 +48,7 @@ type options struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context } // NewListCommand creates a new command for listing kafkas. @@ -61,6 +62,7 @@ func NewListCommand(f *factory.Factory) *cobra.Command { Logger: f.Logger, IO: f.IOStreams, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -104,7 +106,7 @@ func runList(opts *options) error { api := conn.API() - a := api.Kafka().GetKafkas(context.Background()) + a := api.Kafka().GetKafkas(opts.Context) a = a.Page(strconv.Itoa(opts.page)) a = a.Size(strconv.Itoa(opts.limit)) diff --git a/pkg/cmd/kafka/topic/create/create.go b/pkg/cmd/kafka/topic/create/create.go index a73d18a18..150f241e3 100644 --- a/pkg/cmd/kafka/topic/create/create.go +++ b/pkg/cmd/kafka/topic/create/create.go @@ -50,6 +50,7 @@ type Options struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context } // NewCreateTopicCommand gets a new command for creating kafka topic. @@ -60,6 +61,7 @@ func NewCreateTopicCommand(f *factory.Factory) *cobra.Command { Logger: f.Logger, IO: f.IOStreams, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -154,13 +156,12 @@ func runCmd(opts *Options) error { return err } - ctx := context.Background() api, kafkaInstance, err := conn.API().KafkaAdmin(opts.kafkaID) if err != nil { return err } - createTopicReq := api.TopicsApi.CreateTopic(ctx) + createTopicReq := api.TopicsApi.CreateTopic(opts.Context) topicInput := kafkainstanceclient.NewTopicInput{ Name: opts.topicName, diff --git a/pkg/cmd/kafka/topic/delete/delete.go b/pkg/cmd/kafka/topic/delete/delete.go index 19961151b..47ec8ff7d 100644 --- a/pkg/cmd/kafka/topic/delete/delete.go +++ b/pkg/cmd/kafka/topic/delete/delete.go @@ -29,6 +29,7 @@ type Options struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context } // NewDeleteTopicCommand gets a new command for deleting a kafka topic. @@ -39,6 +40,7 @@ func NewDeleteTopicCommand(f *factory.Factory) *cobra.Command { Logger: f.Logger, IO: f.IOStreams, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -96,7 +98,7 @@ func runCmd(opts *Options) error { } // perform delete topic API request - _, httpRes, err := api.TopicsApi.GetTopic(context.Background(), opts.topicName).Execute() + _, httpRes, err := api.TopicsApi.GetTopic(opts.Context, opts.topicName).Execute() if httpRes != nil { defer httpRes.Body.Close() } @@ -127,7 +129,7 @@ func runCmd(opts *Options) error { } // perform delete topic API request - httpRes, err = api.TopicsApi.DeleteTopic(context.Background(), opts.topicName).Execute() + httpRes, err = api.TopicsApi.DeleteTopic(opts.Context, opts.topicName).Execute() if httpRes != nil { defer httpRes.Body.Close() } diff --git a/pkg/cmd/kafka/topic/describe/describe.go b/pkg/cmd/kafka/topic/describe/describe.go index d7e286102..d25e6f79c 100644 --- a/pkg/cmd/kafka/topic/describe/describe.go +++ b/pkg/cmd/kafka/topic/describe/describe.go @@ -35,6 +35,7 @@ type Options struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context } // NewDescribeTopicCommand gets a new command for describing a kafka topic. @@ -45,6 +46,7 @@ func NewDescribeTopicCommand(f *factory.Factory) *cobra.Command { Logger: f.Logger, IO: f.IOStreams, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -104,7 +106,7 @@ func runCmd(opts *Options) error { } // fetch the topic - topicResponse, httpRes, err := api.TopicsApi.GetTopic(context.Background(), opts.name).Execute() + topicResponse, httpRes, err := api.TopicsApi.GetTopic(opts.Context, opts.name).Execute() if httpRes != nil { defer httpRes.Body.Close() } diff --git a/pkg/cmd/kafka/topic/list/list.go b/pkg/cmd/kafka/topic/list/list.go index eca985847..5e31a004a 100644 --- a/pkg/cmd/kafka/topic/list/list.go +++ b/pkg/cmd/kafka/topic/list/list.go @@ -34,6 +34,7 @@ type Options struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context kafkaID string output string @@ -57,6 +58,7 @@ func NewListTopicCommand(f *factory.Factory) *cobra.Command { Logger: f.Logger, IO: f.IOStreams, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -125,7 +127,7 @@ func runCmd(opts *Options) error { return err } - a := api.TopicsApi.GetTopics(context.Background()) + a := api.TopicsApi.GetTopics(opts.Context) if opts.search != "" { opts.Logger.Debug(opts.localizer.MustLocalize("kafka.topic.list.log.debug.filteringTopicList", localize.NewEntry("Search", opts.search))) diff --git a/pkg/cmd/kafka/topic/update/update.go b/pkg/cmd/kafka/topic/update/update.go index 93b0d10f2..a341f76b7 100644 --- a/pkg/cmd/kafka/topic/update/update.go +++ b/pkg/cmd/kafka/topic/update/update.go @@ -51,6 +51,7 @@ type Options struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context } // NewUpdateTopicCommand gets a new command for updating a kafka topic. @@ -62,6 +63,7 @@ func NewUpdateTopicCommand(f *factory.Factory) *cobra.Command { Logger: f.Logger, IO: f.IOStreams, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -219,7 +221,7 @@ func runCmd(opts *Options) error { // track if any values have changed var needsUpdate bool - topic, httpRes, err := api.TopicsApi.GetTopic(context.Background(), opts.name).Execute() + topic, httpRes, err := api.TopicsApi.GetTopic(opts.Context, opts.name).Execute() if httpRes != nil { defer httpRes.Body.Close() } @@ -238,7 +240,7 @@ func runCmd(opts *Options) error { // map to store the config entries which will be updated configEntryMap := map[string]*string{} - updateTopicReq := api.TopicsApi.UpdateTopic(context.Background(), opts.name) + updateTopicReq := api.TopicsApi.UpdateTopic(opts.Context, opts.name) topicSettings := &kafkainstanceclient.UpdateTopicInput{} @@ -329,7 +331,7 @@ func runInteractivePrompt(opts *Options) (err error) { } // check if topic exists - topic, httpRes, err := api.TopicsApi.GetTopic(context.Background(), opts.name).Execute() + topic, httpRes, err := api.TopicsApi.GetTopic(opts.Context, opts.name).Execute() if httpRes != nil { defer httpRes.Body.Close() } diff --git a/pkg/cmd/kafka/update/update.go b/pkg/cmd/kafka/update/update.go index 1ca8a63f1..fd2460646 100644 --- a/pkg/cmd/kafka/update/update.go +++ b/pkg/cmd/kafka/update/update.go @@ -37,6 +37,7 @@ type Options struct { Connection factory.ConnectionFunc logger logging.Logger localizer localize.Localizer + Context context.Context } func NewUpdateCommand(f *factory.Factory) *cobra.Command { @@ -46,6 +47,7 @@ func NewUpdateCommand(f *factory.Factory) *cobra.Command { localizer: f.Localizer, logger: f.Logger, Connection: f.Connection, + Context: f.Context, } cmd := &cobra.Command{ @@ -119,14 +121,13 @@ func run(opts *Options) error { api := conn.API() var kafkaInstance *kafkamgmtclient.KafkaRequest - ctx := context.Background() if opts.name != "" { - kafkaInstance, _, err = kafka.GetKafkaByName(ctx, api.Kafka(), opts.name) + kafkaInstance, _, err = kafka.GetKafkaByName(opts.Context, api.Kafka(), opts.name) if err != nil { return err } } else { - kafkaInstance, _, err = kafka.GetKafkaByID(ctx, api.Kafka(), opts.id) + kafkaInstance, _, err = kafka.GetKafkaByID(opts.Context, api.Kafka(), opts.id) if err != nil { return err } @@ -166,7 +167,7 @@ func run(opts *Options) error { spinner.Start() response, httpRes, err := api.Kafka(). - UpdateKafkaById(context.Background(), kafkaInstance.GetId()). + UpdateKafkaById(opts.Context, kafkaInstance.GetId()). KafkaUpdateRequest(*updateObj). Execute() diff --git a/pkg/cmd/kafka/use/use.go b/pkg/cmd/kafka/use/use.go index 7d78fcd7e..1e289b0f0 100644 --- a/pkg/cmd/kafka/use/use.go +++ b/pkg/cmd/kafka/use/use.go @@ -31,6 +31,7 @@ type Options struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context } func NewUseCommand(f *factory.Factory) *cobra.Command { @@ -40,6 +41,7 @@ func NewUseCommand(f *factory.Factory) *cobra.Command { Logger: f.Logger, IO: f.IOStreams, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -100,14 +102,13 @@ func runUse(opts *Options) error { api := conn.API() var res *kafkamgmtclient.KafkaRequest - ctx := context.Background() if opts.name != "" { - res, _, err = kafka.GetKafkaByName(ctx, api.Kafka(), opts.name) + res, _, err = kafka.GetKafkaByName(opts.Context, api.Kafka(), opts.name) if err != nil { return err } } else { - res, _, err = kafka.GetKafkaByID(ctx, api.Kafka(), opts.id) + res, _, err = kafka.GetKafkaByID(opts.Context, api.Kafka(), opts.id) if err != nil { return err } @@ -138,7 +139,7 @@ func runInteractivePrompt(opts *Options) error { opts.Logger.Debug(opts.localizer.MustLocalize("common.log.debug.startingInteractivePrompt")) - selectedKafka, err := kafka.InteractiveSelect(conn, opts.Logger) + selectedKafka, err := kafka.InteractiveSelect(opts.Context, conn, opts.Logger) if err != nil { return err } diff --git a/pkg/cmd/login/login.go b/pkg/cmd/login/login.go index 7b6651192..e890548cd 100644 --- a/pkg/cmd/login/login.go +++ b/pkg/cmd/login/login.go @@ -66,6 +66,7 @@ type Options struct { Connection factory.ConnectionFunc IO *iostreams.IOStreams localizer localize.Localizer + Context context.Context url string authURL string @@ -85,6 +86,7 @@ func NewLoginCmd(f *factory.Factory) *cobra.Command { Logger: f.Logger, IO: f.IOStreams, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -139,7 +141,7 @@ func runLogin(opts *Options) (err error) { if opts.offlineToken == "" { tr := createTransport(opts.insecureSkipTLSVerify) - httpClient := oauth2.NewClient(context.Background(), nil) + httpClient := oauth2.NewClient(opts.Context, nil) httpClient.Transport = tr loginExec := &login.AuthorizationCodeGrant{ @@ -210,7 +212,7 @@ func runLogin(opts *Options) (err error) { // debug mode checks this for a version update also. // so we check if is enabled first so as not to print it twice if !debug.Enabled() { - build.CheckForUpdate(context.Background(), opts.Logger, opts.localizer) + build.CheckForUpdate(opts.Context, opts.Logger, opts.localizer) } return nil diff --git a/pkg/cmd/logout/logout.go b/pkg/cmd/logout/logout.go index 2689a6d43..9d304814d 100644 --- a/pkg/cmd/logout/logout.go +++ b/pkg/cmd/logout/logout.go @@ -21,6 +21,7 @@ type Options struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context } // NewLogoutCommand gets the command that's logs the current logged in user @@ -30,6 +31,7 @@ func NewLogoutCommand(f *factory.Factory) *cobra.Command { Connection: f.Connection, Logger: f.Logger, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -51,7 +53,7 @@ func runLogout(opts *Options) error { return err } - err = conn.Logout(context.TODO()) + err = conn.Logout(opts.Context) if err != nil { return fmt.Errorf("%v: %w", opts.localizer.MustLocalize("logout.error.unableToLogout"), err) diff --git a/pkg/cmd/registry/artifact/crud/create/create.go b/pkg/cmd/registry/artifact/crud/create/create.go index de50dd05c..8f70fff3b 100644 --- a/pkg/cmd/registry/artifact/crud/create/create.go +++ b/pkg/cmd/registry/artifact/crud/create/create.go @@ -44,6 +44,7 @@ type Options struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context } func NewCreateCommand(f *factory.Factory) *cobra.Command { @@ -53,6 +54,7 @@ func NewCreateCommand(f *factory.Factory) *cobra.Command { Connection: f.Connection, Logger: f.Logger, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -148,8 +150,7 @@ func runCreate(opts *Options) error { } } - ctx := context.Background() - request := dataAPI.ArtifactsApi.CreateArtifact(ctx, opts.group) + request := dataAPI.ArtifactsApi.CreateArtifact(opts.Context, opts.group) if opts.artifactType != "" { request = request.XRegistryArtifactType(registryinstanceclient.ArtifactType(opts.artifactType)) } diff --git a/pkg/cmd/registry/artifact/crud/delete/delete.go b/pkg/cmd/registry/artifact/crud/delete/delete.go index 6b89ef7a6..a39494988 100644 --- a/pkg/cmd/registry/artifact/crud/delete/delete.go +++ b/pkg/cmd/registry/artifact/crud/delete/delete.go @@ -34,6 +34,7 @@ type Options struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context } func NewDeleteCommand(f *factory.Factory) *cobra.Command { @@ -43,6 +44,7 @@ func NewDeleteCommand(f *factory.Factory) *cobra.Command { Logger: f.Logger, IO: f.IOStreams, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -99,21 +101,20 @@ func runDelete(opts *Options) error { opts.group = util.DefaultArtifactGroup } - ctx := context.Background() if opts.artifact == "" { opts.Logger.Info(opts.localizer.MustLocalize("artifact.common.message.deleteAllArtifactsInGroup")) err = confirmDelete(opts, opts.localizer.MustLocalize("artifact.common.message.deleteAllArtifactsFromGroup", localize.NewEntry("GroupName", opts.group))) if err != nil { return err } - request := dataAPI.ArtifactsApi.DeleteArtifactsInGroup(ctx, opts.group) + request := dataAPI.ArtifactsApi.DeleteArtifactsInGroup(opts.Context, opts.group) _, err = request.Execute() if err != nil { return registryinstanceerror.TransformError(err) } opts.Logger.Info(opts.localizer.MustLocalize("artifact.common.message.AllArtifactsInGroupDeleted", localize.NewEntry("GroupName", opts.group))) } else { - _, _, err := dataAPI.MetadataApi.GetArtifactMetaData(ctx, opts.group, opts.artifact).Execute() + _, _, err := dataAPI.MetadataApi.GetArtifactMetaData(opts.Context, opts.group, opts.artifact).Execute() if err != nil { return errors.New(opts.localizer.MustLocalize("artifact.common.error.artifact.notFound", localize.NewEntry("Name", opts.artifact))) } @@ -122,7 +123,7 @@ func runDelete(opts *Options) error { if err != nil { return err } - request := dataAPI.ArtifactsApi.DeleteArtifact(ctx, opts.group, opts.artifact) + request := dataAPI.ArtifactsApi.DeleteArtifact(opts.Context, opts.group, opts.artifact) _, err = request.Execute() if err != nil { diff --git a/pkg/cmd/registry/artifact/crud/get/get.go b/pkg/cmd/registry/artifact/crud/get/get.go index c3653857c..ea860a103 100644 --- a/pkg/cmd/registry/artifact/crud/get/get.go +++ b/pkg/cmd/registry/artifact/crud/get/get.go @@ -35,6 +35,7 @@ type Options struct { Logger logging.Logger Connection factory.ConnectionFunc localizer localize.Localizer + Context context.Context } func NewGetCommand(f *factory.Factory) *cobra.Command { @@ -44,6 +45,7 @@ func NewGetCommand(f *factory.Factory) *cobra.Command { IO: f.IOStreams, localizer: f.Localizer, Logger: f.Logger, + Context: f.Context, } cmd := &cobra.Command{ @@ -102,15 +104,14 @@ func runGet(opts *Options) error { opts.group = util.DefaultArtifactGroup } - ctx := context.Background() var dataFile *os.File if opts.version != "" { opts.Logger.Info(opts.localizer.MustLocalize("artifact.common.message.fetching.with.version", localize.NewEntry("Version", opts.version))) - request := dataAPI.VersionsApi.GetArtifactVersion(ctx, opts.group, opts.artifact, opts.version) + request := dataAPI.VersionsApi.GetArtifactVersion(opts.Context, opts.group, opts.artifact, opts.version) dataFile, _, err = request.Execute() } else { opts.Logger.Info(opts.localizer.MustLocalize("artifact.common.message.fetching.latest")) - request := dataAPI.ArtifactsApi.GetLatestArtifact(ctx, opts.group, opts.artifact) + request := dataAPI.ArtifactsApi.GetLatestArtifact(opts.Context, opts.group, opts.artifact) dataFile, _, err = request.Execute() } if err != nil { diff --git a/pkg/cmd/registry/artifact/crud/list/list.go b/pkg/cmd/registry/artifact/crud/list/list.go index 0d51877fb..ed4915464 100644 --- a/pkg/cmd/registry/artifact/crud/list/list.go +++ b/pkg/cmd/registry/artifact/crud/list/list.go @@ -55,6 +55,7 @@ type Options struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context } // NewListCommand creates a new command for listing registry artifacts. @@ -65,6 +66,7 @@ func NewListCommand(f *factory.Factory) *cobra.Command { Logger: f.Logger, IO: f.IOStreams, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -130,7 +132,7 @@ func runList(opts *Options) error { if err != nil { return err } - request := a.ArtifactsApi.ListArtifactsInGroup(context.Background(), opts.group) + request := a.ArtifactsApi.ListArtifactsInGroup(opts.Context, opts.group) request = request.Offset((opts.page - 1) * opts.limit) request = request.Limit(opts.limit) diff --git a/pkg/cmd/registry/artifact/crud/update/update.go b/pkg/cmd/registry/artifact/crud/update/update.go index 5e6c8d368..2f7a4dd0b 100644 --- a/pkg/cmd/registry/artifact/crud/update/update.go +++ b/pkg/cmd/registry/artifact/crud/update/update.go @@ -41,6 +41,7 @@ type Options struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context } // NewUpdateCommand creates a new command for updating binary content of registry artifacts. @@ -51,6 +52,7 @@ func NewUpdateCommand(f *factory.Factory) *cobra.Command { Connection: f.Connection, Logger: f.Logger, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -138,8 +140,7 @@ func runUpdate(opts *Options) error { } } - ctx := context.Background() - request := dataAPI.ArtifactsApi.UpdateArtifact(ctx, opts.group, opts.artifact) + request := dataAPI.ArtifactsApi.UpdateArtifact(opts.Context, opts.group, opts.artifact) if opts.version != "" { request = request.XRegistryVersion(opts.version) } diff --git a/pkg/cmd/registry/artifact/download/download.go b/pkg/cmd/registry/artifact/download/download.go index ab9d0eb44..ba6685344 100644 --- a/pkg/cmd/registry/artifact/download/download.go +++ b/pkg/cmd/registry/artifact/download/download.go @@ -39,6 +39,7 @@ type Options struct { Logger logging.Logger Connection factory.ConnectionFunc localizer localize.Localizer + Context context.Context } // NewDownloadCommand creates a new command for downloading binary content for registry artifacts. @@ -49,6 +50,7 @@ func NewDownloadCommand(f *factory.Factory) *cobra.Command { IO: f.IOStreams, localizer: f.Localizer, Logger: f.Logger, + Context: f.Context, } cmd := &cobra.Command{ @@ -107,17 +109,16 @@ func runGet(opts *Options) error { opts.Logger.Info(opts.localizer.MustLocalize("artifact.common.message.fetching.artifact")) - ctx := context.Background() var dataFile *os.File // nolint if opts.contentId != unusedFlagIdValue { - request := dataAPI.ArtifactsApi.GetContentById(ctx, opts.contentId) + request := dataAPI.ArtifactsApi.GetContentById(opts.Context, opts.contentId) dataFile, _, err = request.Execute() } else if opts.globalId != unusedFlagIdValue { - request := dataAPI.ArtifactsApi.GetContentByGlobalId(ctx, opts.globalId) + request := dataAPI.ArtifactsApi.GetContentByGlobalId(opts.Context, opts.globalId) dataFile, _, err = request.Execute() } else if opts.hash != "" { - request := dataAPI.ArtifactsApi.GetContentByHash(ctx, opts.hash) + request := dataAPI.ArtifactsApi.GetContentByHash(opts.Context, opts.hash) dataFile, _, err = request.Execute() } else { return errors.New(opts.localizer.MustLocalize("artifact.cmd.common.error.specify.contentId.globalId.hash")) diff --git a/pkg/cmd/registry/artifact/metadata/get.go b/pkg/cmd/registry/artifact/metadata/get.go index e3165cd02..475ac45b3 100644 --- a/pkg/cmd/registry/artifact/metadata/get.go +++ b/pkg/cmd/registry/artifact/metadata/get.go @@ -32,6 +32,7 @@ type GetOptions struct { Logger logging.Logger Connection factory.ConnectionFunc localizer localize.Localizer + Context context.Context } // NewGetMetadataCommand creates a new command for fetching metadata for registry artifacts. @@ -42,6 +43,7 @@ func NewGetMetadataCommand(f *factory.Factory) *cobra.Command { IO: f.IOStreams, localizer: f.Localizer, Logger: f.Logger, + Context: f.Context, } cmd := &cobra.Command{ @@ -101,8 +103,7 @@ func runGet(opts *GetOptions) error { opts.Logger.Info(opts.localizer.MustLocalize("artifact.common.message.artifact.metadata.fetching")) - ctx := context.Background() - request := dataAPI.MetadataApi.GetArtifactMetaData(ctx, opts.group, opts.artifact) + request := dataAPI.MetadataApi.GetArtifactMetaData(opts.Context, opts.group, opts.artifact) response, _, err := request.Execute() if err != nil { return registryinstanceerror.TransformError(err) diff --git a/pkg/cmd/registry/artifact/metadata/set.go b/pkg/cmd/registry/artifact/metadata/set.go index 2750cf826..605e9af09 100644 --- a/pkg/cmd/registry/artifact/metadata/set.go +++ b/pkg/cmd/registry/artifact/metadata/set.go @@ -36,6 +36,7 @@ type SetOptions struct { Logger logging.Logger Connection factory.ConnectionFunc localizer localize.Localizer + Context context.Context } // NewSetMetadataCommand creates a new command for updating metadata for registry artifacts. @@ -46,6 +47,7 @@ func NewSetMetadataCommand(f *factory.Factory) *cobra.Command { IO: f.IOStreams, localizer: f.Localizer, Logger: f.Logger, + Context: f.Context, } cmd := &cobra.Command{ @@ -112,8 +114,7 @@ func runSet(opts *SetOptions) error { opts.Logger.Info(opts.localizer.MustLocalize("artifact.common.message.artifact.metadata.fetching")) - ctx := context.Background() - request := dataAPI.MetadataApi.GetArtifactMetaData(ctx, opts.group, opts.artifact) + request := dataAPI.MetadataApi.GetArtifactMetaData(opts.Context, opts.group, opts.artifact) currentMetadata, _, err := request.Execute() if err != nil { return registryinstanceerror.TransformError(err) @@ -144,7 +145,7 @@ func runSet(opts *SetOptions) error { opts.Logger.Info(opts.localizer.MustLocalize("artifact.common.message.artifact.metadata.updating")) - editRequest := dataAPI.MetadataApi.UpdateArtifactMetaData(ctx, opts.group, opts.artifact) + editRequest := dataAPI.MetadataApi.UpdateArtifactMetaData(opts.Context, opts.group, opts.artifact) _, err = editRequest.EditableMetaData(*editableMedata).Execute() if err != nil { return registryinstanceerror.TransformError(err) diff --git a/pkg/cmd/registry/artifact/migrate/export.go b/pkg/cmd/registry/artifact/migrate/export.go index 708679f61..df4ca7f53 100644 --- a/pkg/cmd/registry/artifact/migrate/export.go +++ b/pkg/cmd/registry/artifact/migrate/export.go @@ -29,6 +29,7 @@ type ExportOptions struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context } func NewExportCommand(f *factory.Factory) *cobra.Command { @@ -38,6 +39,7 @@ func NewExportCommand(f *factory.Factory) *cobra.Command { Connection: f.Connection, Logger: f.Logger, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -87,8 +89,7 @@ func runExport(opts *ExportOptions) error { return err } - ctx := context.Background() - request := dataAPI.AdminApi.ExportData(ctx) + request := dataAPI.AdminApi.ExportData(opts.Context) file, _, err := request.Execute() if err != nil { return registryinstanceerror.TransformError(err) diff --git a/pkg/cmd/registry/artifact/migrate/import.go b/pkg/cmd/registry/artifact/migrate/import.go index c18997d16..6a744f283 100644 --- a/pkg/cmd/registry/artifact/migrate/import.go +++ b/pkg/cmd/registry/artifact/migrate/import.go @@ -28,6 +28,7 @@ type ImportOptions struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context } func NewImportCommand(f *factory.Factory) *cobra.Command { @@ -37,6 +38,7 @@ func NewImportCommand(f *factory.Factory) *cobra.Command { Connection: f.Connection, Logger: f.Logger, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -90,8 +92,7 @@ func runImport(opts *ImportOptions) error { return err } - ctx := context.Background() - request := dataAPI.AdminApi.ImportData(ctx) + request := dataAPI.AdminApi.ImportData(opts.Context) _, err = request.Body(specifiedFile).Execute() if err != nil { return registryinstanceerror.TransformError(err) diff --git a/pkg/cmd/registry/artifact/versions/versions.go b/pkg/cmd/registry/artifact/versions/versions.go index 04488cd98..965f61051 100644 --- a/pkg/cmd/registry/artifact/versions/versions.go +++ b/pkg/cmd/registry/artifact/versions/versions.go @@ -32,6 +32,7 @@ type Options struct { Logger logging.Logger Connection factory.ConnectionFunc localizer localize.Localizer + Context context.Context } func NewVersionsCommand(f *factory.Factory) *cobra.Command { @@ -41,6 +42,7 @@ func NewVersionsCommand(f *factory.Factory) *cobra.Command { IO: f.IOStreams, localizer: f.Localizer, Logger: f.Logger, + Context: f.Context, } cmd := &cobra.Command{ @@ -101,8 +103,7 @@ func runGet(opts *Options) error { opts.Logger.Info(opts.localizer.MustLocalize("artifact.common.message.artifact.versions.fetching")) - ctx := context.Background() - request := dataAPI.VersionsApi.ListArtifactVersions(ctx, opts.group, opts.artifact) + request := dataAPI.VersionsApi.ListArtifactVersions(opts.Context, opts.group, opts.artifact) response, _, err := request.Execute() if err != nil { return registryinstanceerror.TransformError(err) diff --git a/pkg/cmd/registry/create/create.go b/pkg/cmd/registry/create/create.go index 6acac4ebd..6f204cd50 100644 --- a/pkg/cmd/registry/create/create.go +++ b/pkg/cmd/registry/create/create.go @@ -41,6 +41,7 @@ type Options struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context } // NewCreateCommand creates a new command for creating registry. @@ -51,6 +52,7 @@ func NewCreateCommand(f *factory.Factory) *cobra.Command { Connection: f.Connection, Logger: f.Logger, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -117,7 +119,7 @@ func runCreate(opts *Options) error { // the user must have accepted the terms and conditions from the provider // before they can create a registry instance - termsAccepted, termsURL, err := ams.CheckTermsAccepted(conn) + termsAccepted, termsURL, err := ams.CheckTermsAccepted(opts.Context, conn) if err != nil { return err } @@ -130,7 +132,7 @@ func runCreate(opts *Options) error { response, _, err := conn.API(). ServiceRegistryMgmt(). - CreateRegistry(context.Background()). + CreateRegistry(opts.Context). RegistryCreate(*payload). Execute() if err != nil { diff --git a/pkg/cmd/registry/delete/delete.go b/pkg/cmd/registry/delete/delete.go index 0bfb65a8f..134a021f6 100644 --- a/pkg/cmd/registry/delete/delete.go +++ b/pkg/cmd/registry/delete/delete.go @@ -32,6 +32,7 @@ type options struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context } func NewDeleteCommand(f *factory.Factory) *cobra.Command { @@ -41,6 +42,7 @@ func NewDeleteCommand(f *factory.Factory) *cobra.Command { Logger: f.Logger, IO: f.IOStreams, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -99,14 +101,13 @@ func runDelete(opts *options) error { api := conn.API() var registry *srsmgmtv1client.Registry - ctx := context.Background() if opts.name != "" { - registry, _, err = serviceregistry.GetServiceRegistryByName(ctx, api.ServiceRegistryMgmt(), opts.name) + registry, _, err = serviceregistry.GetServiceRegistryByName(opts.Context, api.ServiceRegistryMgmt(), opts.name) if err != nil { return err } } else { - registry, _, err = serviceregistry.GetServiceRegistryByID(ctx, api.ServiceRegistryMgmt(), opts.id) + registry, _, err = serviceregistry.GetServiceRegistryByID(opts.Context, api.ServiceRegistryMgmt(), opts.id) if err != nil { return err } @@ -135,7 +136,7 @@ func runDelete(opts *options) error { opts.Logger.Debug("Deleting Service registry", fmt.Sprintf("\"%s\"", registryName)) - a := api.ServiceRegistryMgmt().DeleteRegistry(context.Background(), registry.GetId()) + a := api.ServiceRegistryMgmt().DeleteRegistry(opts.Context, registry.GetId()) _, err = a.Execute() if err != nil { diff --git a/pkg/cmd/registry/describe/describe.go b/pkg/cmd/registry/describe/describe.go index 49e1a8d35..c165e8f4e 100644 --- a/pkg/cmd/registry/describe/describe.go +++ b/pkg/cmd/registry/describe/describe.go @@ -28,6 +28,7 @@ type Options struct { Config config.IConfig Connection factory.ConnectionFunc localizer localize.Localizer + Context context.Context } // NewDescribeCommand describes a service instance, either by passing an `--id flag` @@ -38,6 +39,7 @@ func NewDescribeCommand(f *factory.Factory) *cobra.Command { Connection: f.Connection, IO: f.IOStreams, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -94,14 +96,13 @@ func runDescribe(opts *Options) error { api := conn.API() var registry *srsmgmtv1.Registry - ctx := context.Background() if opts.name != "" { - registry, _, err = serviceregistry.GetServiceRegistryByName(ctx, api.ServiceRegistryMgmt(), opts.name) + registry, _, err = serviceregistry.GetServiceRegistryByName(opts.Context, api.ServiceRegistryMgmt(), opts.name) if err != nil { return err } } else { - registry, _, err = serviceregistry.GetServiceRegistryByID(ctx, api.ServiceRegistryMgmt(), opts.id) + registry, _, err = serviceregistry.GetServiceRegistryByID(opts.Context, api.ServiceRegistryMgmt(), opts.id) if err != nil { return err } diff --git a/pkg/cmd/registry/list/list.go b/pkg/cmd/registry/list/list.go index 042f868cd..70a76b515 100644 --- a/pkg/cmd/registry/list/list.go +++ b/pkg/cmd/registry/list/list.go @@ -44,6 +44,7 @@ type options struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context } // NewListCommand creates a new command for listing service registries. @@ -54,6 +55,7 @@ func NewListCommand(f *factory.Factory) *cobra.Command { Logger: f.Logger, IO: f.IOStreams, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -88,7 +90,7 @@ func runList(opts *options) error { api := conn.API() - a := api.ServiceRegistryMgmt().GetRegistries(context.Background()) + a := api.ServiceRegistryMgmt().GetRegistries(opts.Context) a = a.Page(opts.page) a = a.Size(opts.limit) diff --git a/pkg/cmd/registry/use/use.go b/pkg/cmd/registry/use/use.go index 2c4988912..1f519f2a0 100644 --- a/pkg/cmd/registry/use/use.go +++ b/pkg/cmd/registry/use/use.go @@ -28,6 +28,7 @@ type Options struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context } func NewUseCommand(f *factory.Factory) *cobra.Command { @@ -37,6 +38,7 @@ func NewUseCommand(f *factory.Factory) *cobra.Command { Logger: f.Logger, IO: f.IOStreams, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -93,14 +95,13 @@ func runUse(opts *Options) error { api := conn.API() var registry *srsmgmtv1.Registry - ctx := context.Background() if opts.name != "" { - registry, _, err = serviceregistry.GetServiceRegistryByName(ctx, api.ServiceRegistryMgmt(), opts.name) + registry, _, err = serviceregistry.GetServiceRegistryByName(opts.Context, api.ServiceRegistryMgmt(), opts.name) if err != nil { return err } } else { - registry, _, err = serviceregistry.GetServiceRegistryByID(ctx, api.ServiceRegistryMgmt(), opts.id) + registry, _, err = serviceregistry.GetServiceRegistryByID(opts.Context, api.ServiceRegistryMgmt(), opts.id) if err != nil { return err } @@ -131,7 +132,7 @@ func runInteractivePrompt(opts *Options) error { opts.Logger.Debug(opts.localizer.MustLocalize("common.log.debug.startingInteractivePrompt")) - selectedRegistry, err := serviceregistry.InteractiveSelect(conn, opts.Logger) + selectedRegistry, err := serviceregistry.InteractiveSelect(opts.Context, conn, opts.Logger) if err != nil { return err } diff --git a/pkg/cmd/serviceaccount/create/create.go b/pkg/cmd/serviceaccount/create/create.go index 2ff5d96a0..2e858b5a9 100644 --- a/pkg/cmd/serviceaccount/create/create.go +++ b/pkg/cmd/serviceaccount/create/create.go @@ -31,6 +31,7 @@ type Options struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context fileFormat string overwrite bool @@ -49,6 +50,7 @@ func NewCreateCommand(f *factory.Factory) *cobra.Command { Connection: f.Connection, Logger: f.Logger, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -131,7 +133,7 @@ func runCreate(opts *Options) error { // create the service account serviceAccountPayload := &kafkamgmtclient.ServiceAccountRequest{Name: opts.name, Description: &opts.description} - a := conn.API().ServiceAccount().CreateServiceAccount(context.Background()) + a := conn.API().ServiceAccount().CreateServiceAccount(opts.Context) a = a.ServiceAccountRequest(*serviceAccountPayload) serviceacct, _, err := a.Execute() if err != nil { diff --git a/pkg/cmd/serviceaccount/delete/delete.go b/pkg/cmd/serviceaccount/delete/delete.go index ee3d6e827..df237e39c 100644 --- a/pkg/cmd/serviceaccount/delete/delete.go +++ b/pkg/cmd/serviceaccount/delete/delete.go @@ -24,6 +24,7 @@ type Options struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context id string force bool @@ -37,6 +38,7 @@ func NewDeleteCommand(f *factory.Factory) *cobra.Command { Logger: f.Logger, IO: f.IOStreams, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -77,7 +79,7 @@ func runDelete(opts *Options) (err error) { return err } - _, httpRes, err := conn.API().ServiceAccount().GetServiceAccountById(context.Background(), opts.id).Execute() + _, httpRes, err := conn.API().ServiceAccount().GetServiceAccountById(opts.Context, opts.id).Execute() if httpRes != nil { defer httpRes.Body.Close() } @@ -117,7 +119,7 @@ func deleteServiceAccount(opts *Options) error { return err } - _, httpRes, err := conn.API().ServiceAccount().DeleteServiceAccountById(context.Background(), opts.id).Execute() + _, httpRes, err := conn.API().ServiceAccount().DeleteServiceAccountById(opts.Context, opts.id).Execute() if httpRes != nil { defer httpRes.Body.Close() } diff --git a/pkg/cmd/serviceaccount/describe/describe.go b/pkg/cmd/serviceaccount/describe/describe.go index ba2322323..6b308663e 100644 --- a/pkg/cmd/serviceaccount/describe/describe.go +++ b/pkg/cmd/serviceaccount/describe/describe.go @@ -26,6 +26,7 @@ type Options struct { Config config.IConfig Connection factory.ConnectionFunc localizer localize.Localizer + Context context.Context } func NewDescribeCommand(f *factory.Factory) *cobra.Command { @@ -34,6 +35,7 @@ func NewDescribeCommand(f *factory.Factory) *cobra.Command { Connection: f.Connection, IO: f.IOStreams, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -70,7 +72,7 @@ func runDescribe(opts *Options) error { api := conn.API() - res, httpRes, err := api.ServiceAccount().GetServiceAccountById(context.Background(), opts.id).Execute() + res, httpRes, err := api.ServiceAccount().GetServiceAccountById(opts.Context, opts.id).Execute() if httpRes != nil { defer httpRes.Body.Close() } diff --git a/pkg/cmd/serviceaccount/list/list.go b/pkg/cmd/serviceaccount/list/list.go index 235515d3d..17a1ad845 100644 --- a/pkg/cmd/serviceaccount/list/list.go +++ b/pkg/cmd/serviceaccount/list/list.go @@ -25,6 +25,7 @@ type Options struct { Logger logging.Logger IO *iostreams.IOStreams localizer localize.Localizer + Context context.Context output string } @@ -47,6 +48,7 @@ func NewListCommand(f *factory.Factory) *cobra.Command { Logger: f.Logger, IO: f.IOStreams, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -77,7 +79,7 @@ func runList(opts *Options) (err error) { return err } - res, _, err := conn.API().ServiceAccount().GetServiceAccounts(context.Background()).Execute() + res, _, err := conn.API().ServiceAccount().GetServiceAccounts(opts.Context).Execute() if err != nil { return err } diff --git a/pkg/cmd/serviceaccount/resetcredentials/reset_credentials.go b/pkg/cmd/serviceaccount/resetcredentials/reset_credentials.go index 29dba8f74..cef0e2e9a 100644 --- a/pkg/cmd/serviceaccount/resetcredentials/reset_credentials.go +++ b/pkg/cmd/serviceaccount/resetcredentials/reset_credentials.go @@ -31,6 +31,7 @@ type Options struct { Connection factory.ConnectionFunc Logger logging.Logger localizer localize.Localizer + Context context.Context id string fileFormat string @@ -49,6 +50,7 @@ func NewResetCredentialsCommand(f *factory.Factory) *cobra.Command { Connection: f.Connection, Logger: f.Logger, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -107,7 +109,7 @@ func runResetCredentials(opts *Options) (err error) { api := conn.API() - serviceacct, httpRes, err := api.ServiceAccount().GetServiceAccountById(context.Background(), opts.id).Execute() + serviceacct, httpRes, err := api.ServiceAccount().GetServiceAccountById(opts.Context, opts.id).Execute() if httpRes != nil { defer httpRes.Body.Close() } @@ -184,7 +186,7 @@ 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() + serviceacct, httpRes, err := api.ServiceAccount().ResetServiceAccountCreds(opts.Context, opts.id).Execute() if httpRes != nil { defer httpRes.Body.Close() } diff --git a/pkg/cmd/status/status.go b/pkg/cmd/status/status.go index ad429d15c..e4f0e7b22 100644 --- a/pkg/cmd/status/status.go +++ b/pkg/cmd/status/status.go @@ -37,6 +37,7 @@ type Options struct { Logger logging.Logger Connection factory.ConnectionFunc localizer localize.Localizer + Context context.Context outputFormat string services []string @@ -55,6 +56,7 @@ func NewStatusCommand(f *factory.Factory) *cobra.Command { Logger: f.Logger, services: validServices, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -108,7 +110,7 @@ func runStatus(opts *Options) error { opts.Logger.Debug(opts.localizer.MustLocalize("status.log.debug.requestingStatusOfServices"), opts.services) } - status, ok, err := pkgStatus.Get(context.Background(), pkgOpts) + status, ok, err := pkgStatus.Get(opts.Context, pkgOpts) if err != nil { return err } diff --git a/pkg/cmd/version/version.go b/pkg/cmd/version/version.go index c6d949e58..ff0ef8b5c 100644 --- a/pkg/cmd/version/version.go +++ b/pkg/cmd/version/version.go @@ -17,6 +17,7 @@ type Options struct { IO *iostreams.IOStreams Logger logging.Logger localizer localize.Localizer + Context context.Context } func NewVersionCmd(f *factory.Factory) *cobra.Command { @@ -24,6 +25,7 @@ func NewVersionCmd(f *factory.Factory) *cobra.Command { IO: f.IOStreams, Logger: f.Logger, localizer: f.Localizer, + Context: f.Context, } cmd := &cobra.Command{ @@ -45,7 +47,7 @@ func runCmd(opts *Options) (err error) { // debug mode checks this for a version update also. // so we check if is enabled first so as not to print it twice if !debug.Enabled() { - build.CheckForUpdate(context.Background(), opts.Logger, opts.localizer) + build.CheckForUpdate(opts.Context, opts.Logger, opts.localizer) } return nil } diff --git a/pkg/cmdutil/cmdutil.go b/pkg/cmdutil/cmdutil.go index eb88c5b3a..bb10b4920 100644 --- a/pkg/cmdutil/cmdutil.go +++ b/pkg/cmdutil/cmdutil.go @@ -1,7 +1,6 @@ package cmdutil import ( - "context" "strconv" "github.com/redhat-developer/app-services-cli/pkg/cmd/factory" @@ -33,7 +32,7 @@ func FilterValidTopicNameArgs(f *factory.Factory, toComplete string) (validNames if err != nil { return validNames, directive } - req := api.TopicsApi.GetTopics(context.Background()) + req := api.TopicsApi.GetTopics(f.Context) if toComplete != "" { req = req.Filter(toComplete) } @@ -74,7 +73,7 @@ func FilterValidConsumerGroupIDs(f *factory.Factory, toComplete string) (validID if err != nil { return validIDs, directive } - req := api.GroupsApi.GetConsumerGroups(context.Background()) + req := api.GroupsApi.GetConsumerGroups(f.Context) if toComplete != "" { req = req.GroupIdFilter(toComplete) } diff --git a/pkg/kafka/cmdutil/util.go b/pkg/kafka/cmdutil/util.go index cc4f2262e..c2ab40a7e 100644 --- a/pkg/kafka/cmdutil/util.go +++ b/pkg/kafka/cmdutil/util.go @@ -1,8 +1,6 @@ package kafkacmdutil import ( - "context" - "github.com/redhat-developer/app-services-cli/pkg/cmd/factory" "github.com/redhat-developer/app-services-cli/pkg/connection" kafkamgmtclient "github.com/redhat-developer/app-services-sdk-go/kafkamgmt/apiv1/client" @@ -20,7 +18,7 @@ func RegisterNameFlagCompletionFunc(cmd *cobra.Command, f *factory.Factory) erro return validNames, directive } - req := conn.API().Kafka().GetKafkas(context.Background()) + req := conn.API().Kafka().GetKafkas(f.Context) if toComplete != "" { searchQ := "name like " + toComplete + "%" req = req.Search(searchQ) @@ -50,7 +48,7 @@ func GetCloudProviderCompletionValues(f *factory.Factory) (validProviders []stri return validProviders, directive } - cloudProviderResponse, _, err := conn.API().Kafka().GetCloudProviders(context.Background()).Execute() + cloudProviderResponse, _, err := conn.API().Kafka().GetCloudProviders(f.Context).Execute() if err != nil { return validProviders, directive } diff --git a/pkg/kafka/interactive.go b/pkg/kafka/interactive.go index e0aba1f63..a7d7ef105 100644 --- a/pkg/kafka/interactive.go +++ b/pkg/kafka/interactive.go @@ -14,10 +14,10 @@ const ( queryLimit = "1000" ) -func InteractiveSelect(connection connection.Connection, logger logging.Logger) (*kafkamgmtclient.KafkaRequest, error) { +func InteractiveSelect(ctx context.Context, connection connection.Connection, logger logging.Logger) (*kafkamgmtclient.KafkaRequest, error) { api := connection.API() - response, _, err := api.Kafka().GetKafkas(context.Background()).Size(queryLimit).Execute() + response, _, err := api.Kafka().GetKafkas(ctx).Size(queryLimit).Execute() if err != nil { return nil, fmt.Errorf("unable to list Kafka instances: %w", err) } diff --git a/pkg/serviceregistry/interactive.go b/pkg/serviceregistry/interactive.go index 752afa96c..047dccfaa 100644 --- a/pkg/serviceregistry/interactive.go +++ b/pkg/serviceregistry/interactive.go @@ -14,10 +14,10 @@ const ( queryLimit = 1000 ) -func InteractiveSelect(connection connection.Connection, logger logging.Logger) (*srsmgmtv1.Registry, error) { +func InteractiveSelect(ctx context.Context, connection connection.Connection, logger logging.Logger) (*srsmgmtv1.Registry, error) { api := connection.API() - response, _, err := api.ServiceRegistryMgmt().GetRegistries(context.Background()).Size(queryLimit).Execute() + response, _, err := api.ServiceRegistryMgmt().GetRegistries(ctx).Size(queryLimit).Execute() if err != nil { return nil, fmt.Errorf("unable to list Service Registry instances: %w", err) }