Skip to content

Commit 8ea7b71

Browse files
rkpattnaik780wtrocki
authored andcommitted
refactor(service-registry): get current instance from context file (#1484)
1 parent 76a0350 commit 8ea7b71

File tree

20 files changed

+552
-350
lines changed

20 files changed

+552
-350
lines changed

.rhoas/context.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

pkg/cmd/registry/artifact/crud/create/create.go

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import (
88
"github.com/redhat-developer/app-services-cli/pkg/cmd/registry/registrycmdutil"
99

1010
"github.com/redhat-developer/app-services-cli/pkg/core/cmdutil/flagutil"
11-
"github.com/redhat-developer/app-services-cli/pkg/core/config"
1211
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/color"
1312
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/dump"
1413
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/iostreams"
1514
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
1615
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
16+
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
1717
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
1818
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
19+
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
1920
"github.com/redhat-developer/app-services-cli/pkg/shared/serviceregistryutil"
2021
registryinstanceclient "github.com/redhat-developer/app-services-sdk-go/registryinstance/apiv1internal/client"
2122

@@ -36,22 +37,22 @@ type options struct {
3637
registryID string
3738
outputFormat string
3839

39-
IO *iostreams.IOStreams
40-
Config config.IConfig
41-
Connection factory.ConnectionFunc
42-
Logger logging.Logger
43-
localizer localize.Localizer
44-
Context context.Context
40+
IO *iostreams.IOStreams
41+
Connection factory.ConnectionFunc
42+
Logger logging.Logger
43+
localizer localize.Localizer
44+
Context context.Context
45+
ServiceContext servicecontext.IContext
4546
}
4647

4748
func NewCreateCommand(f *factory.Factory) *cobra.Command {
4849
opts := &options{
49-
IO: f.IOStreams,
50-
Config: f.Config,
51-
Connection: f.Connection,
52-
Logger: f.Logger,
53-
localizer: f.Localizer,
54-
Context: f.Context,
50+
IO: f.IOStreams,
51+
Connection: f.Connection,
52+
Logger: f.Logger,
53+
localizer: f.Localizer,
54+
Context: f.Context,
55+
ServiceContext: f.ServiceContext,
5556
}
5657

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

83-
cfg, err := opts.Config.Load()
84+
svcContext, err := opts.ServiceContext.Load()
8485
if err != nil {
8586
return err
8687
}
8788

88-
instanceID, ok := cfg.GetServiceRegistryIdOk()
89-
if !ok {
90-
return opts.localizer.MustLocalizeError("artifact.cmd.common.error.noServiceRegistrySelected")
89+
profileHandler := &profileutil.ContextHandler{
90+
Context: svcContext,
91+
Localizer: opts.localizer,
9192
}
9293

93-
opts.registryID = instanceID
94+
conn, err := opts.Connection(connection.DefaultConfigRequireMasAuth)
95+
if err != nil {
96+
return err
97+
}
98+
99+
registryInstance, err := profileHandler.GetCurrentRegistryInstance(conn.API().ServiceRegistryMgmt())
100+
if err != nil {
101+
return err
102+
}
103+
104+
opts.registryID = registryInstance.GetId()
94105
return runCreate(opts)
95106
},
96107
}

pkg/cmd/registry/artifact/crud/delete/delete.go

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import (
77
"github.com/AlecAivazis/survey/v2"
88
"github.com/redhat-developer/app-services-cli/pkg/cmd/registry/registrycmdutil"
99
"github.com/redhat-developer/app-services-cli/pkg/core/cmdutil/flagutil"
10-
"github.com/redhat-developer/app-services-cli/pkg/core/config"
1110
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/iostreams"
1211
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
1312
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
13+
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
1414
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
1515
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
16+
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
1617
"github.com/spf13/cobra"
1718
)
1819

@@ -23,22 +24,22 @@ type options struct {
2324
registryID string
2425
force bool
2526

26-
IO *iostreams.IOStreams
27-
Config config.IConfig
28-
Connection factory.ConnectionFunc
29-
Logger logging.Logger
30-
localizer localize.Localizer
31-
Context context.Context
27+
IO *iostreams.IOStreams
28+
Connection factory.ConnectionFunc
29+
Logger logging.Logger
30+
localizer localize.Localizer
31+
Context context.Context
32+
ServiceContext servicecontext.IContext
3233
}
3334

3435
func NewDeleteCommand(f *factory.Factory) *cobra.Command {
3536
opts := &options{
36-
Config: f.Config,
37-
Connection: f.Connection,
38-
Logger: f.Logger,
39-
IO: f.IOStreams,
40-
localizer: f.Localizer,
41-
Context: f.Context,
37+
Connection: f.Connection,
38+
Logger: f.Logger,
39+
IO: f.IOStreams,
40+
localizer: f.Localizer,
41+
Context: f.Context,
42+
ServiceContext: f.ServiceContext,
4243
}
4344

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

59-
cfg, err := opts.Config.Load()
60+
svcContext, err := opts.ServiceContext.Load()
6061
if err != nil {
6162
return err
6263
}
6364

64-
instanceID, ok := cfg.GetServiceRegistryIdOk()
65-
if !ok {
66-
return opts.localizer.MustLocalizeError("artifact.cmd.common.error.noServiceRegistrySelected")
65+
profileHandler := &profileutil.ContextHandler{
66+
Context: svcContext,
67+
Localizer: opts.localizer,
6768
}
6869

69-
opts.registryID = instanceID
70+
conn, err := opts.Connection(connection.DefaultConfigRequireMasAuth)
71+
if err != nil {
72+
return err
73+
}
74+
75+
registryInstance, err := profileHandler.GetCurrentRegistryInstance(conn.API().ServiceRegistryMgmt())
76+
if err != nil {
77+
return err
78+
}
79+
80+
opts.registryID = registryInstance.GetId()
7081
return runDelete(opts)
7182
},
7283
}

pkg/cmd/registry/artifact/crud/get/get.go

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import (
88

99
"github.com/redhat-developer/app-services-cli/pkg/cmd/registry/registrycmdutil"
1010
"github.com/redhat-developer/app-services-cli/pkg/core/cmdutil/flagutil"
11-
"github.com/redhat-developer/app-services-cli/pkg/core/config"
1211
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/icon"
1312
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/iostreams"
1413
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
1514
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
15+
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
1616
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
1717
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
18+
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
1819

1920
"github.com/spf13/cobra"
2021
)
@@ -27,22 +28,22 @@ type options struct {
2728
registryID string
2829
version string
2930

30-
IO *iostreams.IOStreams
31-
Config config.IConfig
32-
Logger logging.Logger
33-
Connection factory.ConnectionFunc
34-
localizer localize.Localizer
35-
Context context.Context
31+
IO *iostreams.IOStreams
32+
Logger logging.Logger
33+
Connection factory.ConnectionFunc
34+
localizer localize.Localizer
35+
Context context.Context
36+
ServiceContext servicecontext.IContext
3637
}
3738

3839
func NewGetCommand(f *factory.Factory) *cobra.Command {
3940
opts := &options{
40-
Config: f.Config,
41-
Connection: f.Connection,
42-
IO: f.IOStreams,
43-
localizer: f.Localizer,
44-
Logger: f.Logger,
45-
Context: f.Context,
41+
Connection: f.Connection,
42+
IO: f.IOStreams,
43+
localizer: f.Localizer,
44+
Logger: f.Logger,
45+
Context: f.Context,
46+
ServiceContext: f.ServiceContext,
4647
}
4748

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

63-
cfg, err := opts.Config.Load()
64+
svcContext, err := opts.ServiceContext.Load()
6465
if err != nil {
6566
return err
6667
}
6768

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

73-
opts.registryID = instanceID
74+
conn, err := opts.Connection(connection.DefaultConfigRequireMasAuth)
75+
if err != nil {
76+
return err
77+
}
78+
79+
registryInstance, err := profileHandler.GetCurrentRegistryInstance(conn.API().ServiceRegistryMgmt())
80+
if err != nil {
81+
return err
82+
}
83+
84+
opts.registryID = registryInstance.GetId()
7485
return runGet(opts)
7586
},
7687
}

pkg/cmd/registry/artifact/crud/list/list.go

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ import (
66
"github.com/redhat-developer/app-services-cli/pkg/cmd/registry/registrycmdutil"
77

88
"github.com/redhat-developer/app-services-cli/pkg/core/cmdutil/flagutil"
9-
"github.com/redhat-developer/app-services-cli/pkg/core/config"
109
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/dump"
1110
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/iostreams"
1211
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
1312
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
13+
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
1414
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
1515
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
16+
"github.com/redhat-developer/app-services-cli/pkg/shared/profileutil"
1617
registryinstanceclient "github.com/redhat-developer/app-services-sdk-go/registryinstance/apiv1internal/client"
1718

1819
"github.com/spf13/cobra"
@@ -47,23 +48,23 @@ type options struct {
4748
page int32
4849
limit int32
4950

50-
IO *iostreams.IOStreams
51-
Config config.IConfig
52-
Connection factory.ConnectionFunc
53-
Logger logging.Logger
54-
localizer localize.Localizer
55-
Context context.Context
51+
IO *iostreams.IOStreams
52+
Connection factory.ConnectionFunc
53+
Logger logging.Logger
54+
localizer localize.Localizer
55+
Context context.Context
56+
ServiceContext servicecontext.IContext
5657
}
5758

5859
// NewListCommand creates a new command for listing registry artifacts.
5960
func NewListCommand(f *factory.Factory) *cobra.Command {
6061
opts := &options{
61-
Config: f.Config,
62-
Connection: f.Connection,
63-
Logger: f.Logger,
64-
IO: f.IOStreams,
65-
localizer: f.Localizer,
66-
Context: f.Context,
62+
Connection: f.Connection,
63+
Logger: f.Logger,
64+
IO: f.IOStreams,
65+
localizer: f.Localizer,
66+
Context: f.Context,
67+
ServiceContext: f.ServiceContext,
6768
}
6869

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

88-
cfg, err := opts.Config.Load()
89+
svcContext, err := opts.ServiceContext.Load()
8990
if err != nil {
9091
return err
9192
}
9293

93-
instanceID, ok := cfg.GetServiceRegistryIdOk()
94-
if !ok {
95-
return opts.localizer.MustLocalizeError("artifact.cmd.common.error.noServiceRegistrySelected")
94+
profileHandler := &profileutil.ContextHandler{
95+
Context: svcContext,
96+
Localizer: opts.localizer,
9697
}
9798

98-
opts.registryID = instanceID
99+
conn, err := opts.Connection(connection.DefaultConfigRequireMasAuth)
100+
if err != nil {
101+
return err
102+
}
103+
104+
registryInstance, err := profileHandler.GetCurrentRegistryInstance(conn.API().ServiceRegistryMgmt())
105+
if err != nil {
106+
return err
107+
}
108+
109+
opts.registryID = registryInstance.GetId()
99110

100111
return runList(opts)
101112
},

0 commit comments

Comments
 (0)