Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyouwen committed Feb 27, 2024
1 parent eb9d731 commit b14cd7d
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ type HTTPClient struct {
func NewClient(host string, client HTTP, authHandler func() string, keyFolder, version string) APIClient {
return &HTTPClient{
KeyFolder: keyFolder,
UncachedClient: NewUncachedClient(host, client, authHandler, version)
UncachedClient: NewUncachedClient(host, client, authHandler, version),
}
}

Expand Down Expand Up @@ -306,7 +306,7 @@ func (c *HTTPClient) GetACL(keyID string) (*ACL, error) {

// PutAccess will add an ACL rule to a specific key.
func (c *HTTPClient) PutAccess(keyID string, a ...Access) error {
return c.UncachedClient.PutAccess(keyID, a)
return c.UncachedClient.PutAccess(keyID, a...)
}

// AddVersion adds a key version to a specific key.
Expand All @@ -320,7 +320,10 @@ func (c *HTTPClient) UpdateVersion(keyID, versionID string, status VersionStatus
}

func (c *HTTPClient) getClient() (HTTP, error) {
return c.UncachedClient.getClient()
if c.UncachedClient.Client == nil {
c.UncachedClient.Client = &http.Client{}
}
return c.UncachedClient.Client, nil
}

func (c *HTTPClient) getHTTPData(method string, path string, body url.Values, data interface{}) error {
Expand All @@ -341,8 +344,8 @@ type UncachedHTTPClient struct {
}

// NewClient creates a new uncached client to connect to talk to Knox.
func NewUncachedClient(host string, client HTTP, authHandler func() string, version string) APIClient {
return &UncachedHTTPClient{
func NewUncachedClient(host string, client HTTP, authHandler func() string, version string) UncachedHTTPClient {
return UncachedHTTPClient{
Host: host,
Client: client,
AuthHandler: authHandler,
Expand Down Expand Up @@ -541,12 +544,14 @@ func getHTTPResp(cli HTTP, r *http.Request, resp *Response) error {
// MockClient builds a client that ignores certs and talks to the given host.
func MockClient(host, keyFolder string) *HTTPClient {
return &HTTPClient{
Host: host,
AuthHandler: func() string {
return "TESTAUTH"
},
KeyFolder: keyFolder,
Client: &http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}},
Version: "mock",
UncachedClient: UncachedHTTPClient{
Host: host,
AuthHandler: func() string {
return "TESTAUTH"
},
Client: &http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}},
Version: "mock",
},
}
}

0 comments on commit b14cd7d

Please sign in to comment.