Skip to content

Commit

Permalink
fix: allow HTTPS for localhost
Browse files Browse the repository at this point in the history
Signed-off-by: Billy Zha <[email protected]>
  • Loading branch information
qweeah committed Sep 7, 2023
1 parent ed1a9e6 commit 34fcb7e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions cmd/oras/internal/option/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import (
// Remote options struct.
type Remote struct {
CACertFilePath string
PlainHTTP bool
PlainHTTP *bool
Insecure bool
Configs []string
Username string
Expand Down Expand Up @@ -98,7 +98,7 @@ func (opts *Remote) ApplyFlagsWithPrefix(fs *pflag.FlagSet, prefix, description
fs.StringVarP(&opts.Username, flagPrefix+"username", shortUser, "", notePrefix+"registry username")
fs.StringVarP(&opts.Password, flagPrefix+"password", shortPassword, "", notePrefix+"registry password or identity token")
fs.BoolVarP(&opts.Insecure, flagPrefix+"insecure", "", false, "allow connections to "+notePrefix+"SSL registry without certs")
fs.BoolVarP(&opts.PlainHTTP, flagPrefix+"plain-http", "", false, "allow insecure connections to "+notePrefix+"registry without SSL check")
fs.BoolVarP(opts.PlainHTTP, flagPrefix+"plain-http", "", false, "allow insecure connections to "+notePrefix+"registry without SSL check")
fs.StringVarP(&opts.CACertFilePath, flagPrefix+"ca-file", "", "", "server certificate authority file for the remote "+notePrefix+"registry")
fs.StringArrayVarP(&opts.resolveFlag, flagPrefix+"resolve", "", nil, "customized DNS for "+notePrefix+"registry, formatted in `host:port:address[:address_port]`")
fs.StringArrayVarP(&opts.Configs, flagPrefix+"registry-config", "", nil, "`path` of the authentication file for "+notePrefix+"registry")
Expand Down Expand Up @@ -305,9 +305,12 @@ func (opts *Remote) NewRepository(reference string, common Common, logger logrus

// isPlainHttp returns the plain http flag for a given registry.
func (opts *Remote) isPlainHttp(registry string) bool {
if opts.PlainHTTP != nil {
return *opts.PlainHTTP
}
host, _, _ := net.SplitHostPort(registry)
if host == "localhost" || registry == "localhost" {
return true
}
return opts.PlainHTTP
return false
}

0 comments on commit 34fcb7e

Please sign in to comment.