Merge remote-tracking branch 'upstream/new-ui-with-sync-image' into author

This commit is contained in:
wemeya 2016-06-24 16:51:27 +08:00
commit 19454bca74
5 changed files with 54 additions and 58 deletions

View File

@ -62,8 +62,8 @@ func NewDeleter(repository string, tags []string, dstURL, dstUsr, dstPwd string,
dstClient: dstClient, dstClient: dstClient,
logger: logger, logger: logger,
} }
deleter.logger.Infof("initialization completed: repository: %s, tags: %v, destination URL: %s, destination user: %s", deleter.logger.Infof("initialization completed: repository: %s, tags: %v, destination URL: %s, insecure: %v, destination user: %s",
deleter.repository, deleter.tags, deleter.dstURL, deleter.dstUsr) deleter.repository, deleter.tags, deleter.dstURL, deleter.insecure, deleter.dstUsr)
return deleter, nil return deleter, nil
} }

View File

@ -80,8 +80,8 @@ type BaseHandler struct {
func InitBaseHandler(repository, srcURL, srcSecret, func InitBaseHandler(repository, srcURL, srcSecret,
dstURL, dstUsr, dstPwd string, insecure bool, tags []string, logger *log.Logger) (*BaseHandler, error) { dstURL, dstUsr, dstPwd string, insecure bool, tags []string, logger *log.Logger) (*BaseHandler, error) {
logger.Infof("initializing: repository: %s, tags: %v, source URL: %s, destination URL: %s, destination user: %s", logger.Infof("initializing: repository: %s, tags: %v, source URL: %s, destination URL: %s, insecure: %v, destination user: %s",
repository, tags, srcURL, dstURL, dstUsr) repository, tags, srcURL, dstURL, insecure, dstUsr)
base := &BaseHandler{ base := &BaseHandler{
repository: repository, repository: repository,
@ -90,6 +90,7 @@ func InitBaseHandler(repository, srcURL, srcSecret,
dstURL: dstURL, dstURL: dstURL,
dstUsr: dstUsr, dstUsr: dstUsr,
dstPwd: dstPwd, dstPwd: dstPwd,
insecure: insecure,
blobsExistence: make(map[string]bool, 10), blobsExistence: make(map[string]bool, 10),
logger: logger, logger: logger,
} }
@ -102,6 +103,7 @@ func InitBaseHandler(repository, srcURL, srcSecret,
srcClient, err := newRepositoryClient(base.srcURL, base.insecure, srcCred, srcClient, err := newRepositoryClient(base.srcURL, base.insecure, srcCred,
base.repository, "repository", base.repository, "pull", "push", "*") base.repository, "repository", base.repository, "pull", "push", "*")
if err != nil { if err != nil {
base.logger.Errorf("an error occurred while creating source repository client: %v", err)
return nil, err return nil, err
} }
base.srcClient = srcClient base.srcClient = srcClient
@ -110,6 +112,7 @@ func InitBaseHandler(repository, srcURL, srcSecret,
dstClient, err := newRepositoryClient(base.dstURL, base.insecure, dstCred, dstClient, err := newRepositoryClient(base.dstURL, base.insecure, dstCred,
base.repository, "repository", base.repository, "pull", "push", "*") base.repository, "repository", base.repository, "pull", "push", "*")
if err != nil { if err != nil {
base.logger.Errorf("an error occurred while creating destination repository client: %v", err)
return nil, err return nil, err
} }
base.dstClient = dstClient base.dstClient = dstClient
@ -117,13 +120,14 @@ func InitBaseHandler(repository, srcURL, srcSecret,
if len(base.tags) == 0 { if len(base.tags) == 0 {
tags, err := base.srcClient.ListTag() tags, err := base.srcClient.ListTag()
if err != nil { if err != nil {
base.logger.Errorf("an error occurred while listing tags for source repository: %v", err)
return nil, err return nil, err
} }
base.tags = tags base.tags = tags
} }
base.logger.Infof("initialization completed: project: %s, repository: %s, tags: %v, source URL: %s, destination URL: %s, destination user: %s", base.logger.Infof("initialization completed: project: %s, repository: %s, tags: %v, source URL: %s, destination URL: %s, insecure: %v, destination user: %s",
base.project, base.repository, base.tags, base.srcURL, base.dstURL, base.dstUsr) base.project, base.repository, base.tags, base.srcURL, base.dstURL, base.insecure, base.dstUsr)
return base, nil return base, nil
} }

View File

@ -59,19 +59,13 @@
<div class="form-group col-md-12 form-group-custom"> <div class="form-group col-md-12 form-group-custom">
<label for="username" class="col-md-3 control-label">// 'username' | tr //:</label> <label for="username" class="col-md-3 control-label">// 'username' | tr //:</label>
<div class="col-md-9"> <div class="col-md-9">
<input type="text" class="form-control" id="username" ng-model="replication.destination.username" name="uUsername" ng-value="vm.username" required ng-disabled="!vm.targetEditable"> <input type="text" class="form-control" id="username" ng-model="replication.destination.username" name="uUsername" ng-value="vm.username" ng-disabled="!vm.targetEditable">
<div ng-messages="form.$submitted && form.uUsername.$error">
<span ng-message="required">// 'username_is_required' | tr //</span>
</div>
</div> </div>
</div> </div>
<div class="form-group col-md-12 form-group-custom"> <div class="form-group col-md-12 form-group-custom">
<label for="password" class="col-md-3 control-label">// 'password' | tr //:</label> <label for="password" class="col-md-3 control-label">// 'password' | tr //:</label>
<div class="col-md-9"> <div class="col-md-9">
<input type="password" class="form-control" id="password" ng-model="replication.destination.password" name="uPassword" ng-value="vm.password" required ng-disabled="!vm.targetEditable"> <input type="password" class="form-control" id="password" ng-model="replication.destination.password" name="uPassword" ng-value="vm.password" ng-disabled="!vm.targetEditable">
<div ng-messages="form.$submitted && form.uPassword.$error">
<span ng-message="required">// 'password_is_required' | tr //</span>
</div>
</div> </div>
</div> </div>
<div class="form-group col-md-12 form-group-custom"> <div class="form-group col-md-12 form-group-custom">

View File

@ -29,19 +29,13 @@
<div class="form-group col-md-12 form-group-custom"> <div class="form-group col-md-12 form-group-custom">
<label for="username" class="col-md-3 control-label">// 'username' | tr //:</label> <label for="username" class="col-md-3 control-label">// 'username' | tr //:</label>
<div class="col-md-9"> <div class="col-md-9">
<input type="text" class="form-control" id="username" ng-model="destination.username" name="uUsername" required ng-disabled="!vm.editable"> <input type="text" class="form-control" id="username" ng-model="destination.username" name="uUsername" ng-disabled="!vm.editable">
<div ng-messages="form.$submitted && form.uUsername.$error">
<span ng-message="required">// 'username_is_required' | tr //</span>
</div>
</div> </div>
</div> </div>
<div class="form-group col-md-12 form-group-custom"> <div class="form-group col-md-12 form-group-custom">
<label for="password" class="col-md-3 control-label">// 'password' | tr //:</label> <label for="password" class="col-md-3 control-label">// 'password' | tr //:</label>
<div class="col-md-9"> <div class="col-md-9">
<input type="password" class="form-control" id="password" ng-model="destination.password" name="uPassword" required ng-disabled="!vm.editable"> <input type="password" class="form-control" id="password" ng-model="destination.password" name="uPassword" ng-disabled="!vm.editable">
<div ng-messages="form.$submitted && form.uPassword.$error">
<span ng-message="required">// 'password_is_required' | tr //</span>
</div>
</div> </div>
</div> </div>
<div class="form-group col-md-12 form-group-custom"> <div class="form-group col-md-12 form-group-custom">

View File

@ -3,9 +3,7 @@
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -18,10 +16,10 @@ package registry
import ( import (
"crypto/tls" "crypto/tls"
"encoding/json" "encoding/json"
"fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"strings"
registry_error "github.com/vmware/harbor/utils/registry/error" registry_error "github.com/vmware/harbor/utils/registry/error"
"github.com/vmware/harbor/utils/registry/utils" "github.com/vmware/harbor/utils/registry/utils"
@ -74,19 +72,22 @@ func NewRegistryWithModifiers(endpoint string, insecure bool, modifiers ...Modif
// Catalog ... // Catalog ...
func (r *Registry) Catalog() ([]string, error) { func (r *Registry) Catalog() ([]string, error) {
repos := []string{} repos := []string{}
suffix := "/v2/_catalog?n=1000"
var url string
req, err := http.NewRequest("GET", buildCatalogURL(r.Endpoint.String()), nil) for len(suffix) > 0 {
url = r.Endpoint.String() + suffix
req, err := http.NewRequest("GET", url, nil)
if err != nil { if err != nil {
return repos, err return repos, err
} }
resp, err := r.client.Do(req) resp, err := r.client.Do(req)
if err != nil { if err != nil {
return repos, parseError(err) return nil, parseError(err)
} }
defer resp.Body.Close() defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body) b, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
return repos, err return repos, err
@ -101,16 +102,23 @@ func (r *Registry) Catalog() ([]string, error) {
return repos, err return repos, err
} }
repos = catalogResp.Repositories repos = append(repos, catalogResp.Repositories...)
//Link: </v2/_catalog?last=library%2Fhello-world-25&n=100>; rel="next"
return repos, nil link := resp.Header.Get("Link")
if strings.HasSuffix(link, `rel="next"`) && strings.Index(link, "<") >= 0 && strings.Index(link, ">") >= 0 {
suffix = link[strings.Index(link, "<")+1 : strings.Index(link, ">")]
} else {
suffix = ""
} }
} else {
return repos, &registry_error.Error{ return repos, &registry_error.Error{
StatusCode: resp.StatusCode, StatusCode: resp.StatusCode,
Detail: string(b), Detail: string(b),
} }
} }
}
return repos, nil
}
// Ping ... // Ping ...
func (r *Registry) Ping() error { func (r *Registry) Ping() error {
@ -140,7 +148,3 @@ func (r *Registry) Ping() error {
Detail: string(b), Detail: string(b),
} }
} }
func buildCatalogURL(endpoint string) string {
return fmt.Sprintf("%s/v2/_catalog", endpoint)
}