Skip to content

Commit

Permalink
Allow use of insecure plain HTTP registries
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanilves committed Sep 25, 2017
1 parent 1c476c6 commit 8cc427e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
5 changes: 4 additions & 1 deletion auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (
"github.com/ivanilves/lstags/auth/bearer"
)

// WebSchema defines how do we connect to remote web servers
var WebSchema = "https://"

// TokenResponse is an abstraction for aggregated token-related information we get from authentication services
type TokenResponse interface {
Method() string
Expand Down Expand Up @@ -63,7 +66,7 @@ func validateParams(method string, params map[string]string) (map[string]string,
// * detects authentication type (e.g. Bearer or Basic)
// * delegates actual authentication to type-specific implementation
func NewToken(registry, repository, username, password string) (TokenResponse, error) {
url := "https://" + registry + "/v2"
url := WebSchema + registry + "/v2"

resp, err := http.Get(url)
if err != nil {
Expand Down
22 changes: 14 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ import (
)

type options struct {
DefaultRegistry string `short:"r" long:"default-registry" default:"registry.hub.docker.com" description:"Docker registry to use by default" env:"DEFAULT_REGISTRY"`
Username string `short:"u" long:"username" default:"" description:"Docker registry username" env:"USERNAME"`
Password string `short:"p" long:"password" default:"" description:"Docker registry password" env:"PASSWORD"`
DockerJSON string `shord:"j" long:"docker-json" default:"~/.docker/config.json" env:"DOCKER_JSON"`
Concurrency int `short:"c" long:"concurrency" default:"32" description:"Concurrent request limit while querying registry" env:"CONCURRENCY"`
TraceRequests bool `short:"T" long:"trace-requests" description:"Trace registry HTTP requests" env:"TRACE_REQUESTS"`
Version bool `short:"V" long:"version" description:"Show version and exit"`
Positional struct {
DefaultRegistry string `short:"r" long:"default-registry" default:"registry.hub.docker.com" description:"Docker registry to use by default" env:"DEFAULT_REGISTRY"`
Username string `short:"u" long:"username" default:"" description:"Docker registry username" env:"USERNAME"`
Password string `short:"p" long:"password" default:"" description:"Docker registry password" env:"PASSWORD"`
DockerJSON string `shord:"j" long:"docker-json" default:"~/.docker/config.json" env:"DOCKER_JSON"`
Concurrency int `short:"c" long:"concurrency" default:"32" description:"Concurrent request limit while querying registry" env:"CONCURRENCY"`
InsecureRegistry bool `short:"i" long:"insecure-registry" description:"Use insecure plain-HTTP registriy" env:"INSECURE_REGISTRY"`
TraceRequests bool `short:"T" long:"trace-requests" description:"Trace registry HTTP requests" env:"TRACE_REQUESTS"`
Version bool `short:"V" long:"version" description:"Show version and exit"`
Positional struct {
Repository string `positional-arg-name:"REPOSITORY" description:"Docker repository to list tags from"`
} `positional-args:"yes"`
}
Expand Down Expand Up @@ -137,6 +138,11 @@ func main() {
suicide(errors.New("You should provide a repository name, e.g. 'nginx' or 'mesosphere/chronos'"))
}

if o.InsecureRegistry {
auth.WebSchema = "http://"
registry.WebSchema = "http://"
}

registry.TraceRequests = o.TraceRequests

repository, filter, err := trimFilter(o.Positional.Repository)
Expand Down
7 changes: 5 additions & 2 deletions tag/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import (
"github.com/ivanilves/lstags/tag"
)

// WebSchema defines how do we connect to remote web servers
var WebSchema = "https://"

// TraceRequests defines if we should print out HTTP request URLs and response headers/bodies
var TraceRequests = false

Expand Down Expand Up @@ -101,7 +104,7 @@ func parseTagNamesJSON(data io.ReadCloser) ([]string, error) {
}

func fetchTagNames(registry, repo, authorization string) ([]string, error) {
url := "https://" + registry + "/v2/" + repo + "/tags/list"
url := WebSchema + registry + "/v2/" + repo + "/tags/list"

resp, err := httpRequest(url, authorization, "v2")
if err != nil {
Expand Down Expand Up @@ -173,7 +176,7 @@ func fetchDigest(url, authorization string) (string, error) {
}

func fetchDetails(registry, repo, tagName, authorization string) (string, int64, error) {
url := "https://" + registry + "/v2/" + repo + "/manifests/" + tagName
url := WebSchema + registry + "/v2/" + repo + "/manifests/" + tagName

dc := make(chan string, 0)
cc := make(chan int64, 0)
Expand Down

0 comments on commit 8cc427e

Please sign in to comment.