This repository has been archived by the owner on Nov 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
/
rest_clients.go
86 lines (68 loc) · 2.68 KB
/
rest_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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
///////////////////////////////////////////////////////////////////////
// Copyright (c) 2017 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
///////////////////////////////////////////////////////////////////////
package cmd
import (
"crypto/tls"
"fmt"
"net/http"
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
"github.com/vmware/dispatch/pkg/client"
applicationclient "github.com/vmware/dispatch/pkg/application-manager/gen/client"
)
// NO TEST
func tlsClient() *http.Client {
return &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: dispatchConfig.Insecure,
},
},
}
}
func httpTransport(path string) *httptransport.Runtime {
host := fmt.Sprintf("%s:%d", dispatchConfig.Host, dispatchConfig.Port)
if dispatchConfig.Scheme == "http" {
return httptransport.NewWithClient(host, path, []string{"http"}, &http.Client{})
}
return httptransport.NewWithClient(host, path, []string{"https"}, tlsClient())
}
func getDispatchHost() string {
if dispatchConfig.Scheme == "" {
dispatchConfig.Scheme = "https"
}
// TODO(karols): this is a hack as it changes the global http.DefaultTransport.
// Instead, Client constructor should accept a flag (or custom transport)
if dispatchConfig.Insecure {
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{
InsecureSkipVerify: dispatchConfig.Insecure,
}
}
return fmt.Sprintf("%s://%s:%d", dispatchConfig.Scheme, dispatchConfig.Host, dispatchConfig.Port)
}
func functionManagerClient() client.FunctionsClient {
return client.NewFunctionsClient(getDispatchHost(), GetAuthInfoWriter(), getOrgFromConfig())
}
func imageManagerClient() client.ImagesClient {
return client.NewImagesClient(getDispatchHost(), GetAuthInfoWriter(), getOrgFromConfig())
}
func secretStoreClient() client.SecretsClient {
return client.NewSecretsClient(getDispatchHost(), GetAuthInfoWriter(), getOrgFromConfig())
}
func serviceManagerClient() client.ServicesClient {
return client.NewServicesClient(getDispatchHost(), GetAuthInfoWriter(), getOrgFromConfig())
}
func apiManagerClient() client.APIsClient {
return client.NewAPIsClient(getDispatchHost(), GetAuthInfoWriter(), getOrgFromConfig())
}
func applicationManagerClient() *applicationclient.ApplicationManager {
return applicationclient.New(httpTransport(applicationclient.DefaultBasePath), strfmt.Default)
}
func eventManagerClient() client.EventsClient {
return client.NewEventsClient(getDispatchHost(), GetAuthInfoWriter(), getOrgFromConfig())
}
func identityManagerClient() client.IdentityClient {
return client.NewIdentityClient(getDispatchHost(), GetAuthInfoWriter(), getOrgFromConfig())
}