Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:#149 x509 certificate is valid #153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions apiv2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down
21 changes: 18 additions & 3 deletions apiv2/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
Expand All @@ -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{
Expand Down