Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
mwangggg committed Feb 29, 2024
1 parent e9ef8f5 commit a4df4b9
Show file tree
Hide file tree
Showing 5 changed files with 569 additions and 428 deletions.
42 changes: 42 additions & 0 deletions internal/test/scorecard/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ package scorecard

import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"net/http"

Expand Down Expand Up @@ -178,3 +180,43 @@ func ReadJSON(resp *http.Response, result interface{}) error {
}
return nil
}

func ReadString(resp *http.Response) (string, error) {
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
return string(body), nil
}

func ReadError(resp *http.Response) string {
body, _ := ReadString(resp)
return body
}

func NewHttpClient() *http.Client {
client := &http.Client{
Timeout: testTimeout,
}

transport := http.DefaultTransport.(*http.Transport).Clone()
// Ignore verifying certs
transport.TLSClientConfig.InsecureSkipVerify = true

client.Transport = transport
return client
}

func NewHttpRequest(ctx context.Context, method string, url string, body io.Reader) (*http.Request, error) {
req, err := http.NewRequestWithContext(ctx, method, url, body)
if err != nil {
return nil, err
}
// Authentication is only enabled on OCP. Ignored on k8s.
config, err := rest.InClusterConfig()
if err != nil {
return nil, fmt.Errorf("failed to get in-cluster configurations: %s", err.Error())
}
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", base64.StdEncoding.EncodeToString([]byte(config.BearerToken))))
return req, nil
}
Loading

0 comments on commit a4df4b9

Please sign in to comment.