@@ -2,6 +2,7 @@ package apiv2
2
2
3
3
import (
4
4
"context"
5
+ "net/http"
5
6
"net/url"
6
7
"strings"
7
8
@@ -154,6 +155,24 @@ func NewRESTClientForHost(u, username, password string, opts *config.Options) (*
154
155
return NewRESTClient (v2SwaggerClient , opts , authInfo ), nil
155
156
}
156
157
158
+ // NewRESTClientForHostWithClient constructs a new REST client containing a swagger API client using the defined
159
+ // host string and basePath, the additional Harbor v2 API suffix as well as basic auth info while using provided http client.
160
+ func NewRESTClientForHostWithClient (u , username , password string , opts * config.Options , client * http.Client ) (* RESTClient , error ) {
161
+ if ! strings .HasSuffix (u , v2URLSuffix ) {
162
+ u += v2URLSuffix
163
+ }
164
+
165
+ harborURL , err := url .Parse (u )
166
+ if err != nil {
167
+ return nil , err
168
+ }
169
+
170
+ v2SwaggerClient := v2client .New (runtimeclient .NewWithClient (harborURL .Host , harborURL .Path , []string {harborURL .Scheme }, client ), strfmt .Default )
171
+ authInfo := runtimeclient .BasicAuth (username , password )
172
+
173
+ return NewRESTClient (v2SwaggerClient , opts , authInfo ), nil
174
+ }
175
+
157
176
// NewRESTClientWithAuthFunc constructs a new REST client containing a swagger API client using the defined
158
177
// host string and basePath, the additional Harbor v2 API suffix as well as a custom auth func, e.g. basic auth or token auth.
159
178
func NewRESTClientWithAuthFunc (u string , authFunc runtime.ClientAuthInfoWriterFunc , opts * config.Options ) (* RESTClient , error ) {
0 commit comments