@@ -45,6 +45,7 @@ func NewImportURLCommand(globalClientOpts *connectors.ClientOptions) *cobra.Comm
4545 config .CaCertPaths = globalClientOpts .CaCertPaths
4646 config .Verbose = globalClientOpts .Verbose
4747
48+ << << << < HEAD
4849<< << << < HEAD
4950 var mc connectors.MicrocksClient
5051
@@ -102,23 +103,62 @@ func NewImportURLCommand(globalClientOpts *connectors.ClientOptions) *cobra.Comm
102103 fmt .Println (err )
103104 return
104105 }
106+ == == == =
107+ var mc connectors.MicrocksClient
108+ >> >> >> > 13 f5d52 (Adds microcksURL , keycloakClientId and keycloakClientSecret as global flags to perform operations like import , test without doing login )
105109
106- if localConfig == nil {
107- fmt .Println ("Please login to perform opertion..." )
108- return
109- }
110+ if globalClientOpts .ServerAddr != "" && globalClientOpts .ClientId != "" && globalClientOpts .ClientSecret != "" {
111+ // create client with server address
112+ mc = connectors .NewMicrocksClient (globalClientOpts .ServerAddr )
110113
111- if globalClientOpts .Context == "" {
112- globalClientOpts .Context = localConfig .CurrentContext
113- }
114+ keycloakURL , err := mc .GetKeycloakURL ()
115+ if err != nil {
116+ fmt .Printf ("Got error when invoking Microcks client retrieving config: %s" , err )
117+ os .Exit (1 )
118+ }
114119
115- mc , err := connectors .NewClient (* globalClientOpts )
116- if err != nil {
117- fmt .Printf ("error %v" , err )
118- return
119- }
120+ var oauthToken string = "unauthentifed-token"
121+ if keycloakURL != "null" {
122+ // If Keycloak is enabled, retrieve an OAuth token using Keycloak Client.
123+ kc := connectors .NewKeycloakClient (keycloakURL , globalClientOpts .ClientId , globalClientOpts .ClientSecret )
120124
125+ << << << < HEAD
121126>> >> >> > df054bc (feat : #160 Adds support of ClienOpts in all remaining commads )
127+ == == == =
128+ oauthToken , err = kc .ConnectAndGetToken ()
129+ if err != nil {
130+ fmt .Printf ("Got error when invoking Keycloack client: %s" , err )
131+ os .Exit (1 )
132+ }
133+ //fmt.Printf("Retrieve OAuthToken: %s", oauthToken)
134+ }
135+
136+ //Set Auth token
137+ mc .SetOAuthToken (oauthToken )
138+ } else {
139+
140+ localConfig , err := config .ReadLocalConfig (globalClientOpts .ConfigPath )
141+ if err != nil {
142+ fmt .Println (err )
143+ return
144+ }
145+
146+ if localConfig == nil {
147+ fmt .Println ("Please login to perform opertion..." )
148+ return
149+ }
150+
151+ if globalClientOpts .Context == "" {
152+ globalClientOpts .Context = localConfig .CurrentContext
153+ }
154+
155+ mc , err = connectors .NewClient (* globalClientOpts )
156+ if err != nil {
157+ fmt .Printf ("error %v" , err )
158+ return
159+ }
160+ }
161+ >> >> >> > 13 f5d52 (Adds microcksURL , keycloakClientId and keycloakClientSecret as global flags to perform operations like import , test without doing login )
122162 sepSpecificationFiles := strings .Split (specificationFiles , "," )
123163 for _ , f := range sepSpecificationFiles {
124164 mainArtifact := true
0 commit comments