This commit is contained in:
Wenkai Yin 2016-06-29 18:52:24 +08:00
parent 5f75156e1d
commit 92193f3456
4 changed files with 15 additions and 39 deletions

View File

@ -19,6 +19,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"os"
"strconv"
"github.com/astaxie/beego/validation"
@ -136,3 +137,14 @@ func (b *BaseAPI) GetIDFromURL() int64 {
return id
}
func getIsInsecure() bool {
insecure := false
verifyRemoteCert := os.Getenv("VERIFY_REMOTE_CERT")
if verifyRemoteCert == "off" {
insecure = true
}
return insecure
}

View File

@ -1,36 +0,0 @@
/*
Copyright (c) 2016 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package api
import (
"os"
)
var (
// Insecure represents whether verify cert if connecting to a https server.
Insecure bool
)
func init() {
verifyRemoteCert := os.Getenv("VERIFY_REMOTE_CERT")
if len(verifyRemoteCert) == 0 {
verifyRemoteCert = "on"
}
if verifyRemoteCert == "off" {
Insecure = false
}
}

View File

@ -258,7 +258,7 @@ func (ra *RepositoryAPI) initRepositoryClient(repoName string) (r *registry.Repo
username, password, ok := ra.Ctx.Request.BasicAuth()
if ok {
return newRepositoryClient(endpoint, Insecure, username, password,
return newRepositoryClient(endpoint, getIsInsecure(), username, password,
repoName, "repository", repoName, "pull", "push", "*")
}
@ -267,7 +267,7 @@ func (ra *RepositoryAPI) initRepositoryClient(repoName string) (r *registry.Repo
return nil, err
}
return cache.NewRepositoryClient(endpoint, Insecure, username, repoName,
return cache.NewRepositoryClient(endpoint, getIsInsecure(), username, repoName,
"repository", repoName, "pull", "push", "*")
}

View File

@ -92,7 +92,7 @@ func (t *TargetAPI) Ping() {
password = t.GetString("password")
}
registry, err := newRegistryClient(endpoint, Insecure, username, password,
registry, err := newRegistryClient(endpoint, getIsInsecure(), username, password,
"", "", "")
if err != nil {
// timeout, dns resolve error, connection refused, etc.