-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
clients.go
41 lines (36 loc) · 1.03 KB
/
clients.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package http
import (
"context"
"crypto/tls"
"net/http"
"net/url"
cc "golang.org/x/oauth2/clientcredentials"
wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
)
func CreateClientWithCertificate(clientCert, clientKey []byte) (*http.Client, error) {
cert, err := tls.X509KeyPair(clientCert, clientKey)
if err != nil {
return nil, err
}
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{cert},
}
transport := &http.Transport{TLSClientConfig: tlsConfig}
client := &http.Client{Transport: transport}
return client, err
}
func CreateOauth2Client(clientID, clientSecret, tokenURL string, scopes []string, endpointParams []wfv1.OAuth2EndpointParam) *http.Client {
values := url.Values{}
for _, endpointParam := range endpointParams {
values.Add(endpointParam.Key, endpointParam.Value)
}
ctx := context.Background()
conf := cc.Config{
ClientID: clientID,
ClientSecret: clientSecret,
TokenURL: tokenURL,
EndpointParams: values,
Scopes: scopes,
}
return conf.Client(ctx)
}