Skip to content

Commit

Permalink
Merge pull request #48 from mittwald/feature/rest_client_swagger
Browse files Browse the repository at this point in the history
introduce NewRESTClientWithSwaggerClient
  • Loading branch information
elenz97 authored Jul 14, 2020
2 parents da0d89a + 89774aa commit de45716
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package goharborclient
import (
"context"

runtimeclient "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"

"github.com/go-openapi/runtime"
"github.com/mittwald/goharbor-client/internal/api/v1_10_0/client"

Expand Down Expand Up @@ -35,14 +38,22 @@ type RESTClient struct {

// NewRESTClient constructs a new REST client containing each sub client.
func NewRESTClient(cl *client.Harbor, authInfo runtime.ClientAuthInfoWriter) *RESTClient {
c := &RESTClient{
return &RESTClient{
user: user.NewClient(cl, authInfo),
project: project.NewClient(cl, authInfo),
registry: registry.NewClient(cl, authInfo),
replication: replication.NewClient(cl, authInfo),
system: system.NewClient(cl, authInfo),
}
return c
}

// NewRESTClientForHost constructs a new REST client containing a swagger
// API client using the defined host string + basePath as well as basic auth info.
func NewRESTClientForHost(host, basePath, username, password string) *RESTClient {
swaggerClient := client.New(runtimeclient.New(host, basePath, []string{"http"}), strfmt.Default)
authInfo := runtimeclient.BasicAuth(username, password)

return NewRESTClient(swaggerClient, authInfo)
}

// User Client
Expand Down

0 comments on commit de45716

Please sign in to comment.