Skip to content

Commit

Permalink
Merge pull request #302 from cherwin/master
Browse files Browse the repository at this point in the history
Allow setting insecure repo globally
  • Loading branch information
xtremerui authored Sep 28, 2021
2 parents 53d4bf5 + 0f609ea commit 0955245
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion commands/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (c *Check) Execute() error {
}

func check(source resource.Source, from *resource.Version) (resource.CheckResponse, error) {
repo, err := name.NewRepository(source.Repository)
repo, err := source.NewRepository()
if err != nil {
return resource.CheckResponse{}, fmt.Errorf("resolve repository: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions commands/in.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (i *In) Execute() error {
}
}

repo, err := name.NewRepository(req.Source.Repository)
repo, err := req.Source.NewRepository()
if err != nil {
return fmt.Errorf("failed to resolve repository: %w", err)
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func (i *In) Execute() error {
func downloadWithRetry(tag name.Tag, source resource.Source, params resource.GetParams, version resource.Version, dest string, stderr io.Writer) error {
fmt.Fprintf(os.Stderr, "fetching %s@%s\n", color.GreenString(source.Repository), color.YellowString(version.Digest))

repo, err := name.NewRepository(source.Repository)
repo, err := source.NewRepository()
if err != nil {
return fmt.Errorf("resolve repository name: %w", err)
}
Expand Down
11 changes: 3 additions & 8 deletions commands/out.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (o *Out) Execute() error {

tagsToPush := []name.Tag{}

repo, err := name.NewRepository(req.Source.Repository)
repo, err := req.Source.NewRepository()
if err != nil {
return fmt.Errorf("could not resolve repository: %w", err)
}
Expand Down Expand Up @@ -195,12 +195,7 @@ func put(req resource.OutRequest, img v1.Image, tags []name.Tag) error {
identifiers = append(identifiers, tag.Identifier())
}

var repoOpts []name.Option
if req.Source.Insecure {
repoOpts = append(repoOpts, name.Insecure)
}

repo, err := name.NewRepository(req.Source.Repository, repoOpts...)
repo, err := req.Source.NewRepository()
if err != nil {
return fmt.Errorf("resolve repository name: %w", err)
}
Expand Down Expand Up @@ -265,7 +260,7 @@ func createAuth(req resource.OutRequest) *authn.Basic {
func aliasesToBump(req resource.OutRequest, repo name.Repository, ver *semver.Version) ([]name.Tag, error) {
variant := req.Source.Variant

repo, err := name.NewRepository(req.Source.Repository)
repo, err := req.Source.NewRepository()
if err != nil {
return nil, fmt.Errorf("resolve repository name: %w", err)
}
Expand Down
12 changes: 12 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,18 @@ func (source Source) AuthOptions(repo name.Repository, scopeActions []string) ([
return []remote.Option{remote.WithAuth(auth), remote.WithTransport(rt)}, nil
}

func (source Source) NewRepository() (name.Repository, error) {
return name.NewRepository(source.Repository, source.RepositoryOptions()...)
}

func (source Source) RepositoryOptions() []name.Option {
var opts []name.Option
if source.Insecure {
opts = append(opts, name.Insecure)
}
return opts
}

type ContentTrust struct {
Server string `json:"server"`
RepositoryKeyID string `json:"repository_key_id"`
Expand Down

0 comments on commit 0955245

Please sign in to comment.