-
Notifications
You must be signed in to change notification settings - Fork 85
/
int_system_client.go
39 lines (32 loc) · 1.06 KB
/
int_system_client.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
package clients
import (
"context"
"crypto/tls"
"fmt"
"net/http"
"time"
directorSchema "github.com/kyma-incubator/compass/components/director/pkg/graphql"
"golang.org/x/oauth2"
"golang.org/x/oauth2/clientcredentials"
)
func NewIntegrationSystemClient(ctx context.Context, intSystemCredentials *directorSchema.IntSysSystemAuth) (*http.Client, error) {
oauthCredentialData, ok := intSystemCredentials.Auth.Credential.(*directorSchema.OAuthCredentialData)
if !ok {
return nil, fmt.Errorf("while casting integration system credentials to OAuth credentials")
}
conf := &clientcredentials.Config{
ClientID: oauthCredentialData.ClientID,
ClientSecret: oauthCredentialData.ClientSecret,
TokenURL: oauthCredentialData.URL,
}
unsecuredHttpClient := http.DefaultClient
unsecuredHttpClient.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
}
ctx = context.WithValue(ctx, oauth2.HTTPClient, unsecuredHttpClient)
httpClient := conf.Client(ctx)
httpClient.Timeout = 20 * time.Second
return httpClient, nil
}