Skip to content

Commit

Permalink
refactor(service-registry): get current instance from context file (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rkpattnaik780 authored and wtrocki committed Apr 11, 2022
1 parent 76a0350 commit 8ea7b71
Show file tree
Hide file tree
Showing 20 changed files with 552 additions and 350 deletions.
13 changes: 0 additions & 13 deletions .rhoas/context.json

This file was deleted.

47 changes: 29 additions & 18 deletions pkg/cmd/registry/artifact/crud/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import (
"github.com/redhat-developer/app-services-cli/pkg/cmd/registry/registrycmdutil"

"github.com/redhat-developer/app-services-cli/pkg/core/cmdutil/flagutil"
"github.com/redhat-developer/app-services-cli/pkg/core/config"
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/color"
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/dump"
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/iostreams"
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/serviceregistryutil"
registryinstanceclient "github.com/redhat-developer/app-services-sdk-go/registryinstance/apiv1internal/client"

Expand All @@ -36,22 +37,22 @@ type options struct {
registryID string
outputFormat string

IO *iostreams.IOStreams
Config config.IConfig
Connection factory.ConnectionFunc
Logger logging.Logger
localizer localize.Localizer
Context context.Context
IO *iostreams.IOStreams
Connection factory.ConnectionFunc
Logger logging.Logger
localizer localize.Localizer
Context context.Context
ServiceContext servicecontext.IContext
}

func NewCreateCommand(f *factory.Factory) *cobra.Command {
opts := &options{
IO: f.IOStreams,
Config: f.Config,
Connection: f.Connection,
Logger: f.Logger,
localizer: f.Localizer,
Context: f.Context,
IO: f.IOStreams,
Connection: f.Connection,
Logger: f.Logger,
localizer: f.Localizer,
Context: f.Context,
ServiceContext: f.ServiceContext,
}

cmd := &cobra.Command{
Expand Down Expand Up @@ -80,17 +81,27 @@ func NewCreateCommand(f *factory.Factory) *cobra.Command {
return runCreate(opts)
}

cfg, err := opts.Config.Load()
svcContext, err := opts.ServiceContext.Load()
if err != nil {
return err
}

instanceID, ok := cfg.GetServiceRegistryIdOk()
if !ok {
return opts.localizer.MustLocalizeError("artifact.cmd.common.error.noServiceRegistrySelected")
profileHandler := &profileutil.ContextHandler{
Context: svcContext,
Localizer: opts.localizer,
}

opts.registryID = instanceID
conn, err := opts.Connection(connection.DefaultConfigRequireMasAuth)
if err != nil {
return err
}

registryInstance, err := profileHandler.GetCurrentRegistryInstance(conn.API().ServiceRegistryMgmt())
if err != nil {
return err
}

opts.registryID = registryInstance.GetId()
return runCreate(opts)
},
}
Expand Down
47 changes: 29 additions & 18 deletions pkg/cmd/registry/artifact/crud/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
"github.com/AlecAivazis/survey/v2"
"github.com/redhat-developer/app-services-cli/pkg/cmd/registry/registrycmdutil"
"github.com/redhat-developer/app-services-cli/pkg/core/cmdutil/flagutil"
"github.com/redhat-developer/app-services-cli/pkg/core/config"
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/iostreams"
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
"github.com/spf13/cobra"
)

Expand All @@ -23,22 +24,22 @@ type options struct {
registryID string
force bool

IO *iostreams.IOStreams
Config config.IConfig
Connection factory.ConnectionFunc
Logger logging.Logger
localizer localize.Localizer
Context context.Context
IO *iostreams.IOStreams
Connection factory.ConnectionFunc
Logger logging.Logger
localizer localize.Localizer
Context context.Context
ServiceContext servicecontext.IContext
}

func NewDeleteCommand(f *factory.Factory) *cobra.Command {
opts := &options{
Config: f.Config,
Connection: f.Connection,
Logger: f.Logger,
IO: f.IOStreams,
localizer: f.Localizer,
Context: f.Context,
Connection: f.Connection,
Logger: f.Logger,
IO: f.IOStreams,
localizer: f.Localizer,
Context: f.Context,
ServiceContext: f.ServiceContext,
}

cmd := &cobra.Command{
Expand All @@ -56,17 +57,27 @@ func NewDeleteCommand(f *factory.Factory) *cobra.Command {
return runDelete(opts)
}

cfg, err := opts.Config.Load()
svcContext, err := opts.ServiceContext.Load()
if err != nil {
return err
}

instanceID, ok := cfg.GetServiceRegistryIdOk()
if !ok {
return opts.localizer.MustLocalizeError("artifact.cmd.common.error.noServiceRegistrySelected")
profileHandler := &profileutil.ContextHandler{
Context: svcContext,
Localizer: opts.localizer,
}

opts.registryID = instanceID
conn, err := opts.Connection(connection.DefaultConfigRequireMasAuth)
if err != nil {
return err
}

registryInstance, err := profileHandler.GetCurrentRegistryInstance(conn.API().ServiceRegistryMgmt())
if err != nil {
return err
}

opts.registryID = registryInstance.GetId()
return runDelete(opts)
},
}
Expand Down
47 changes: 29 additions & 18 deletions pkg/cmd/registry/artifact/crud/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import (

"github.com/redhat-developer/app-services-cli/pkg/cmd/registry/registrycmdutil"
"github.com/redhat-developer/app-services-cli/pkg/core/cmdutil/flagutil"
"github.com/redhat-developer/app-services-cli/pkg/core/config"
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/icon"
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/iostreams"
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"

"github.com/spf13/cobra"
)
Expand All @@ -27,22 +28,22 @@ type options struct {
registryID string
version string

IO *iostreams.IOStreams
Config config.IConfig
Logger logging.Logger
Connection factory.ConnectionFunc
localizer localize.Localizer
Context context.Context
IO *iostreams.IOStreams
Logger logging.Logger
Connection factory.ConnectionFunc
localizer localize.Localizer
Context context.Context
ServiceContext servicecontext.IContext
}

func NewGetCommand(f *factory.Factory) *cobra.Command {
opts := &options{
Config: f.Config,
Connection: f.Connection,
IO: f.IOStreams,
localizer: f.Localizer,
Logger: f.Logger,
Context: f.Context,
Connection: f.Connection,
IO: f.IOStreams,
localizer: f.Localizer,
Logger: f.Logger,
Context: f.Context,
ServiceContext: f.ServiceContext,
}

cmd := &cobra.Command{
Expand All @@ -60,17 +61,27 @@ func NewGetCommand(f *factory.Factory) *cobra.Command {
return runGet(opts)
}

cfg, err := opts.Config.Load()
svcContext, err := opts.ServiceContext.Load()
if err != nil {
return err
}

instanceID, ok := cfg.GetServiceRegistryIdOk()
if !ok {
return opts.localizer.MustLocalizeError("registry.no.service.selected.use.instance.id.flag")
profileHandler := &profileutil.ContextHandler{
Context: svcContext,
Localizer: opts.localizer,
}

opts.registryID = instanceID
conn, err := opts.Connection(connection.DefaultConfigRequireMasAuth)
if err != nil {
return err
}

registryInstance, err := profileHandler.GetCurrentRegistryInstance(conn.API().ServiceRegistryMgmt())
if err != nil {
return err
}

opts.registryID = registryInstance.GetId()
return runGet(opts)
},
}
Expand Down
47 changes: 29 additions & 18 deletions pkg/cmd/registry/artifact/crud/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (
"github.com/redhat-developer/app-services-cli/pkg/cmd/registry/registrycmdutil"

"github.com/redhat-developer/app-services-cli/pkg/core/cmdutil/flagutil"
"github.com/redhat-developer/app-services-cli/pkg/core/config"
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/dump"
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/iostreams"
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
registryinstanceclient "github.com/redhat-developer/app-services-sdk-go/registryinstance/apiv1internal/client"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -47,23 +48,23 @@ type options struct {
page int32
limit int32

IO *iostreams.IOStreams
Config config.IConfig
Connection factory.ConnectionFunc
Logger logging.Logger
localizer localize.Localizer
Context context.Context
IO *iostreams.IOStreams
Connection factory.ConnectionFunc
Logger logging.Logger
localizer localize.Localizer
Context context.Context
ServiceContext servicecontext.IContext
}

// NewListCommand creates a new command for listing registry artifacts.
func NewListCommand(f *factory.Factory) *cobra.Command {
opts := &options{
Config: f.Config,
Connection: f.Connection,
Logger: f.Logger,
IO: f.IOStreams,
localizer: f.Localizer,
Context: f.Context,
Connection: f.Connection,
Logger: f.Logger,
IO: f.IOStreams,
localizer: f.Localizer,
Context: f.Context,
ServiceContext: f.ServiceContext,
}

cmd := &cobra.Command{
Expand All @@ -85,17 +86,27 @@ func NewListCommand(f *factory.Factory) *cobra.Command {
return runList(opts)
}

cfg, err := opts.Config.Load()
svcContext, err := opts.ServiceContext.Load()
if err != nil {
return err
}

instanceID, ok := cfg.GetServiceRegistryIdOk()
if !ok {
return opts.localizer.MustLocalizeError("artifact.cmd.common.error.noServiceRegistrySelected")
profileHandler := &profileutil.ContextHandler{
Context: svcContext,
Localizer: opts.localizer,
}

opts.registryID = instanceID
conn, err := opts.Connection(connection.DefaultConfigRequireMasAuth)
if err != nil {
return err
}

registryInstance, err := profileHandler.GetCurrentRegistryInstance(conn.API().ServiceRegistryMgmt())
if err != nil {
return err
}

opts.registryID = registryInstance.GetId()

return runList(opts)
},
Expand Down
Loading

0 comments on commit 8ea7b71

Please sign in to comment.