Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1739)

Unified Diff: client/client.go

Issue 13360044: client/Client: Add API for non-validating SSL
Patch Set: Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « [revision details] ('k') | client/local_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/client.go
=== modified file 'client/client.go'
--- client/client.go 2013-09-04 10:33:07 +0000
+++ client/client.go 2013-09-04 10:35:49 +0000
@@ -51,9 +51,10 @@
// This client sends requests without authenticating.
type client struct {
- mu sync.Mutex
- logger *log.Logger
- baseURL string
+ mu sync.Mutex
+ logger *log.Logger
+ baseURL string
+ httpClient *goosehttp.Client
}
var _ Client = (*client)(nil)
@@ -84,39 +85,38 @@
var _ AuthenticatingClient = (*authenticatingClient)(nil)
func NewPublicClient(baseURL string, logger *log.Logger) Client {
- client := client{baseURL: baseURL, logger: logger}
+ client := client{baseURL: baseURL, logger: logger, httpClient: sharedHttpClient}
return &client
}
var defaultRequiredServiceTypes = []string{"compute", "object-store"}
-func NewClient(creds *identity.Credentials, auth_method identity.AuthMode, logger *log.Logger) AuthenticatingClient {
+func newClient(creds *identity.Credentials, auth_method identity.AuthMode, httpClient *goosehttp.Client, logger *log.Logger) AuthenticatingClient {
client_creds := *creds
client_creds.URL = client_creds.URL + apiTokens
client := authenticatingClient{
creds: &client_creds,
requiredServiceTypes: defaultRequiredServiceTypes,
- client: client{logger: logger},
+ client: client{logger: logger, httpClient: httpClient},
}
client.auth = &client
- switch auth_method {
- default:
- panic(fmt.Errorf("Invalid identity authorisation method: %d", auth_method))
- case identity.AuthLegacy:
- client.authMode = &identity.Legacy{}
- case identity.AuthUserPass:
- client.authMode = &identity.UserPass{}
- case identity.AuthKeyPair:
- client.authMode = &identity.KeyPair{}
- }
+ client.authMode = identity.NewAuthenticator(auth_method, httpClient)
return &client
}
+func NewClient(creds *identity.Credentials, auth_method identity.AuthMode, logger *log.Logger) AuthenticatingClient {
+ return newClient(creds, auth_method, sharedHttpClient, logger)
+}
+
+func NewNonValidatingClient(creds *identity.Credentials, auth_method identity.AuthMode, logger *log.Logger) AuthenticatingClient {
+ return newClient(creds, auth_method, goosehttp.NewNonSSLValidating(), logger)
+}
+
func (c *client) sendRequest(method, url, token string, requestData *goosehttp.RequestData) (err error) {
if requestData.ReqValue != nil || requestData.RespValue != nil {
- err = sharedHttpClient.JsonRequest(method, url, token, requestData, c.logger)
+ err = c.httpClient.JsonRequest(method, url, token, requestData, c.logger)
} else {
- err = sharedHttpClient.BinaryRequest(method, url, token, requestData, c.logger)
+ err = c.httpClient.BinaryRequest(method, url, token, requestData, c.logger)
}
return
}
« no previous file with comments | « [revision details] ('k') | client/local_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b