Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions pkg/connectors/keycloak_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,16 @@ func (c *keycloakClient) ConnectAndGetToken() (string, error) {

body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err.Error())
return "", fmt.Errorf("failed to read Keycloak token response: %w", err)
}

var openIDResp map[string]interface{}
if err := json.Unmarshal(body, &openIDResp); err != nil {
panic(err)
return "", fmt.Errorf("failed to parse Keycloak token response: %w", err)
}

accessToken := openIDResp["access_token"].(string)
return accessToken, err
return accessToken, nil
}

func (c *keycloakClient) GetOIDCConfig() (*oauth2.Config, error) {
Expand All @@ -127,12 +127,12 @@ func (c *keycloakClient) GetOIDCConfig() (*oauth2.Config, error) {

body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err.Error())
return nil, fmt.Errorf("failed to read OIDC config response: %w", err)
}

var openIDResp map[string]interface{}
if err := json.Unmarshal(body, &openIDResp); err != nil {
panic(err)
return nil, fmt.Errorf("failed to parse OIDC config response: %w", err)
}

authURL := openIDResp["authorization_endpoint"].(string)
Expand Down Expand Up @@ -174,12 +174,12 @@ func (c *keycloakClient) ConnectAndGetTokenAndRefreshToken(username, password st

body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err.Error())
return "", "", fmt.Errorf("failed to read Keycloak token response: %w", err)
}

var openIDResp map[string]interface{}
if err := json.Unmarshal(body, &openIDResp); err != nil {
panic(err)
return "", "", fmt.Errorf("failed to parse Keycloak token response: %w", err)
}

authToken := openIDResp["access_token"].(string)
Expand Down
22 changes: 11 additions & 11 deletions pkg/connectors/microcks_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,12 @@ func (c *microcksClient) GetKeycloakURL() (string, error) {

body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err.Error())
return "", fmt.Errorf("failed to read Keycloak config response: %w", err)
}

var configResp map[string]interface{}
if err := json.Unmarshal(body, &configResp); err != nil {
panic(err)
return "", fmt.Errorf("failed to parse Keycloak config response: %w", err)
}

// Retrieve auth server url and realm name.
Expand Down Expand Up @@ -367,16 +367,16 @@ func (c *microcksClient) CreateTestResult(serviceID string, testEndpoint string,

body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err.Error())
return "", fmt.Errorf("failed to read create test result response: %w", err)
}

var createTestResp map[string]interface{}
if err := json.Unmarshal(body, &createTestResp); err != nil {
panic(err)
return "", fmt.Errorf("failed to parse create test result response: %w", err)
}

testID := createTestResp["id"].(string)
return testID, err
return testID, nil
}

func (c *microcksClient) GetTestResult(testResultID string) (*TestResultSummary, error) {
Expand Down Expand Up @@ -406,7 +406,7 @@ func (c *microcksClient) GetTestResult(testResultID string) (*TestResultSummary,

body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err.Error())
return nil, fmt.Errorf("failed to read test result response: %w", err)
}

result := TestResultSummary{}
Expand Down Expand Up @@ -434,7 +434,7 @@ func (c *microcksClient) UploadArtifact(specificationFilePath string, mainArtifa
}
_, err = io.Copy(part, file)
if err != nil {
panic(err.Error())
return "", fmt.Errorf("failed to copy file content into multipart body: %w", err)
}

// Add the mainArtifact flag to request.
Expand Down Expand Up @@ -470,15 +470,15 @@ func (c *microcksClient) UploadArtifact(specificationFilePath string, mainArtifa

respBody, err := io.ReadAll(resp.Body)
if err != nil {
panic(err.Error())
return "", fmt.Errorf("failed to read upload artifact response: %w", err)
}

// Raise exception if not created.
if resp.StatusCode != 201 {
return "", errs.New(string(respBody))
}

return string(respBody), err
return string(respBody), nil
}

func (c *microcksClient) DownloadArtifact(artifactURL string, mainArtifact bool, secret string) (string, error) {
Expand Down Expand Up @@ -524,15 +524,15 @@ func (c *microcksClient) DownloadArtifact(artifactURL string, mainArtifact bool,

respBody, err := io.ReadAll(resp.Body)
if err != nil {
panic(err.Error())
return "", fmt.Errorf("failed to read download artifact response: %w", err)
}

// Raise exception if not created.
if resp.StatusCode != 201 {
return "", errs.New(string(respBody))
}

return string(respBody), err
return string(respBody), nil
}

func ensureValidOperationsList(filteredOperations string) bool {
Expand Down