@@ -2,9 +2,11 @@ package update
2
2
3
3
import (
4
4
"encoding/json"
5
+
5
6
"github.com/redhat-developer/app-services-cli/pkg/core/cmdutil/flagutil"
6
7
"github.com/redhat-developer/app-services-cli/pkg/shared/connectorutil"
7
8
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil"
9
+ "github.com/redhat-developer/app-services-cli/pkg/shared/kafkautil"
8
10
"github.com/spf13/cobra"
9
11
10
12
"github.com/redhat-developer/app-services-cli/pkg/core/ioutil/dump"
@@ -20,6 +22,7 @@ type options struct {
20
22
namespaceID string
21
23
kafkaID string
22
24
name string
25
+ id string
23
26
24
27
outputFormat string
25
28
f * factory.Factory
@@ -43,13 +46,30 @@ func NewUpdateCommand(f *factory.Factory) *cobra.Command {
43
46
return flagutil .InvalidValueError ("output" , opts .outputFormat , validOutputFormats ... )
44
47
}
45
48
49
+ if opts .id != "" {
50
+ return runUpdate (opts )
51
+ }
52
+
53
+ conn , err := opts .f .Connection ()
54
+ if err != nil {
55
+ return err
56
+ }
57
+
58
+ connector , err := contextutil .GetCurrentConnectorInstance (& conn , opts .f )
59
+ if err != nil {
60
+ return err
61
+ }
62
+
63
+ opts .id = connector .GetId ()
64
+
46
65
return runUpdate (opts )
47
66
},
48
67
}
49
68
flags := flagutil .NewFlagSet (cmd , f .Localizer )
69
+ flags .StringVar (& opts .id , "id" , "" , f .Localizer .MustLocalize ("connector.flag.id.description" ))
50
70
flags .StringVar (& opts .name , "name" , "" , f .Localizer .MustLocalize ("connector.flag.name.description" ))
51
- flags .StringVar (& opts .namespaceID , "namespace-id" , "" , f .Localizer .MustLocalize ("connector.flag.kafkaID .description" ))
52
- flags .StringVar (& opts .kafkaID , "kafka-id" , "" , f .Localizer .MustLocalize ("connector.flag.namespaceID .description" ))
71
+ flags .StringVar (& opts .namespaceID , "namespace-id" , "" , f .Localizer .MustLocalize ("connector.flag.namespaceID .description" ))
72
+ flags .StringVar (& opts .kafkaID , "kafka-id" , "" , f .Localizer .MustLocalize ("connector.flag.kafkaID .description" ))
53
73
flags .AddOutput (& opts .outputFormat )
54
74
55
75
return cmd
@@ -63,13 +83,10 @@ func runUpdate(opts *options) error {
63
83
return err
64
84
}
65
85
66
- api := conn .API ()
67
-
68
- connector , err := contextutil .GetCurrentConnectorInstance (& conn , opts .f )
69
- if err != nil || connector == nil {
70
- if connector , err = connectorutil .InteractiveSelect (conn , opts .f ); err != nil {
71
- return err
72
- }
86
+ connectorsApi := conn .API ().ConnectorsMgmt ()
87
+ connector , err := connectorutil .GetConnectorByID (& connectorsApi , opts .id , opts .f )
88
+ if err != nil {
89
+ return err
73
90
}
74
91
75
92
connectorChanged := false
@@ -82,7 +99,12 @@ func runUpdate(opts *options) error {
82
99
connectorChanged = true
83
100
}
84
101
if opts .kafkaID != "" {
85
- connector .Kafka .SetId (opts .kafkaID )
102
+ kafkaInstance , _ , kafkaErr := kafkautil .GetKafkaByID (opts .f .Context , conn .API ().KafkaMgmt (), opts .kafkaID )
103
+ if kafkaErr != nil {
104
+ return kafkaErr
105
+ }
106
+ connector .Kafka .SetId (kafkaInstance .GetId ())
107
+ connector .Kafka .SetUrl (kafkaInstance .GetBootstrapServerHost ())
86
108
connectorChanged = true
87
109
}
88
110
@@ -105,7 +127,7 @@ func runUpdate(opts *options) error {
105
127
return err
106
128
}
107
129
108
- a := api .ConnectorsMgmt ().ConnectorsApi .PatchConnector (opts .f .Context , connector .GetId ())
130
+ a := conn . API () .ConnectorsMgmt ().ConnectorsApi .PatchConnector (opts .f .Context , connector .GetId ())
109
131
a = a .Body (patchData )
110
132
updated , httpRes , err := a .Execute ()
111
133
if httpRes != nil {
0 commit comments