diff --git a/apiv2/client.go b/apiv2/client.go index 70ea533e..a3a239cc 100644 --- a/apiv2/client.go +++ b/apiv2/client.go @@ -114,7 +114,7 @@ func NewRESTClient(v2Client *v2client.Harbor, opts *config.Options, authInfo run // NewRESTClientForHost constructs a new REST client containing a swagger API client using the defined // host string and basePath, the additional Harbor v2 API suffix as well as basic auth info. -func NewRESTClientForHost(u, username, password string, opts *config.Options) (*RESTClient, error) { +func NewRESTClientForHost(u, username, password string, opts *config.Options, clientOpts runtimeclient.TLSClientOptions) (*RESTClient, error) { if !strings.HasSuffix(u, v2URLSuffix) { u += v2URLSuffix } @@ -124,7 +124,12 @@ func NewRESTClientForHost(u, username, password string, opts *config.Options) (* return nil, err } - v2SwaggerClient := v2client.New(runtimeclient.New(harborURL.Host, harborURL.Path, []string{harborURL.Scheme}), strfmt.Default) + client, err := runtimeclient.TLSClient(clientOpts) + if err != nil { + return nil, err + } + + v2SwaggerClient := v2client.New(runtimeclient.NewWithClient(harborURL.Host, harborURL.Path, []string{harborURL.Scheme}, client), strfmt.Default) authInfo := runtimeclient.BasicAuth(username, password) return NewRESTClient(v2SwaggerClient, opts, authInfo), nil diff --git a/apiv2/client_test.go b/apiv2/client_test.go index ece7c80e..dec02e14 100644 --- a/apiv2/client_test.go +++ b/apiv2/client_test.go @@ -28,7 +28,11 @@ func ExampleNewRESTClientForHost() { username := "user" password := "password" - harborClient, err := NewRESTClientForHost(apiURL, username, password, nil) + clientOpts := runtimeclient.TLSClientOptions{ + InsecureSkipVerify: true, + } + + harborClient, err := NewRESTClientForHost(apiURL, username, password, nil, clientOpts) if err != nil { panic(err) } @@ -55,7 +59,14 @@ func ExampleNewRESTClient() { panic(err) } - v2SwaggerClient := v2client.New(runtimeclient.New(harborURL.Host, harborURL.Path, []string{harborURL.Scheme}), strfmt.Default) + clientOpts := runtimeclient.TLSClientOptions{ + InsecureSkipVerify: true, + //refer to github.com/go-openapi/runtime/client/runtime_test.go + //Certificate: "", + //Key: "", + } + + v2SwaggerClient := v2client.New(runtimeclient.NewWithClient(harborURL.Host, harborURL.Path, []string{harborURL.Scheme}, clientOpts), strfmt.Default) authInfo := runtimeclient.BasicAuth(username, password) harborClient := NewRESTClient(v2SwaggerClient, nil, authInfo) @@ -82,7 +93,11 @@ func ExampleNewRESTClient_withOptions() { panic(err) } - v2SwaggerClient := v2client.New(runtimeclient.New(harborURL.Host, harborURL.Path, []string{harborURL.Scheme}), strfmt.Default) + clientOpts := runtimeclient.TLSClientOptions{ + InsecureSkipVerify: true, + } + + v2SwaggerClient := v2client.New(runtimeclient.NewWithClient(harborURL.Host, harborURL.Path, []string{harborURL.Scheme}, clientOpts), strfmt.Default) authInfo := runtimeclient.BasicAuth(username, password) options := &config.Options{