Skip to content

Commit e624066

Browse files
committed
Adds microcksURL, keycloakClientId and keycloakClientSecret as global flags to perform operations like import, test without doing login
Signed-off-by: Harsh4902 <[email protected]>
1 parent 2ef1046 commit e624066

File tree

2 files changed

+60
-12
lines changed

2 files changed

+60
-12
lines changed

cmd/importURL.go

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
>>>>>>> 13f5d52 (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+
>>>>>>> 13f5d52 (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

cmd/test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ func NewTestCommand(globalClientOpts *connectors.ClientOptions) *cobra.Command {
9797
}
9898

9999
<<<<<<< HEAD
100+
<<<<<<< HEAD
101+
=======
102+
>>>>>>> 13f5d52 (Adds microcksURL, keycloakClientId and keycloakClientSecret as global flags to perform operations like import, test without doing login)
100103
var mc connectors.MicrocksClient
101104
var serverAddr string
102105

@@ -154,6 +157,7 @@ func NewTestCommand(globalClientOpts *connectors.ClientOptions) *cobra.Command {
154157
errors.CheckError(err)
155158

156159
serverAddr = ctx.Server.Server
160+
<<<<<<< HEAD
157161
}
158162

159163
=======
@@ -184,6 +188,10 @@ func NewTestCommand(globalClientOpts *connectors.ClientOptions) *cobra.Command {
184188
serverAddr := ctx.Server.Server
185189

186190
>>>>>>> df054bc (feat: #160 Adds support of ClienOpts in all remaining commads)
191+
=======
192+
}
193+
194+
>>>>>>> 13f5d52 (Adds microcksURL, keycloakClientId and keycloakClientSecret as global flags to perform operations like import, test without doing login)
187195
var testResultID string
188196
testResultID, err := mc.CreateTestResult(serviceRef, testEndpoint, runnerType, secretName, waitForMilliseconds, filteredOperations, operationsHeaders, oAuth2Context)
189197
if err != nil {

0 commit comments

Comments
 (0)