Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
Signed-off-by: Billy Zha <[email protected]>
  • Loading branch information
qweeah committed Sep 11, 2023
1 parent e64b34e commit 73667a2
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
10 changes: 5 additions & 5 deletions cmd/oras/internal/option/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (

// Remote options struct.
type Remote struct {
DistributionSpec
CACertFilePath string
Insecure bool
Configs []string
Expand All @@ -51,11 +52,10 @@ type Remote struct {

resolveFlag []string
applyDistributionSpec bool
DistributionSpec
headerFlags []string
headers http.Header
warned map[string]*sync.Map
plainHTTP func() (plainHTTP bool, enforced bool)
headerFlags []string
headers http.Header
warned map[string]*sync.Map
plainHTTP func() (plainHTTP bool, enforced bool)
}

// EnableDistributionSpecFlag set distribution specification flag as applicable.
Expand Down
2 changes: 1 addition & 1 deletion cmd/oras/root/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func runAttach(ctx context.Context, opts attachOptions) error {
}
// add both pull and push scope hints for dst repository
// to save potential push-scope token requests during copy
ctx = registryutil.WithScopeHint(dst, ctx, auth.ActionPull, auth.ActionPush)
ctx = registryutil.WithScopeHint(ctx, dst, auth.ActionPull, auth.ActionPush)
subject, err := dst.Resolve(ctx, opts.Reference)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/oras/root/blob/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func deleteBlob(ctx context.Context, opts deleteBlobOptions) (err error) {
}

// add both pull and delete scope hints for dst repository to save potential delete-scope token requests during deleting
ctx = registryutil.WithScopeHint(repo, ctx, auth.ActionPull, auth.ActionDelete)
ctx = registryutil.WithScopeHint(ctx, repo, auth.ActionPull, auth.ActionDelete)
blobs := repo.Blobs()
desc, err := blobs.Resolve(ctx, opts.targetRef)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/oras/root/manifest/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ func deleteManifest(ctx context.Context, opts deleteOptions) error {
return oerrors.NewErrInvalidReference(repo.Reference)
}

// add both pull, push and delete scope hints for dst repository to save potential delete-scope token requests during deleting
hints := []string{auth.ActionPull, auth.ActionPush, auth.ActionDelete}
// add both pull and delete scope hints for dst repository to save potential delete-scope token requests during deleting
hints := []string{auth.ActionPull, auth.ActionDelete}
if opts.ReferrersAPI == nil || !*opts.ReferrersAPI {
// possiblely need pushing to add a new referrers index
hints = append(hints, auth.ActionPush)
}
ctx = registryutil.WithScopeHint(repo, ctx, hints...)
ctx = registryutil.WithScopeHint(ctx, repo, hints...)
manifests := repo.Manifests()
desc, err := manifests.Resolve(ctx, opts.targetRef)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/oras/root/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func runPush(ctx context.Context, opts pushOptions) error {
copy := func(root ocispec.Descriptor) error {
// add both pull and push scope hints for dst repository
// to save potential push-scope token requests during copy
ctx = registryutil.WithScopeHint(dst, ctx, auth.ActionPull, auth.ActionPush)
ctx = registryutil.WithScopeHint(ctx, dst, auth.ActionPull, auth.ActionPush)

if tag := opts.Reference; tag == "" {
err = oras.CopyGraph(ctx, union, dst, root, copyOptions.CopyGraphOptions)
Expand Down
5 changes: 2 additions & 3 deletions internal/registryutil/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ import (
)

// WithScopeHint adds a hinted scope to the context.
func WithScopeHint(target oras.Target, ctx context.Context, actions ...string) context.Context {
func WithScopeHint(ctx context.Context, target oras.Target, actions ...string) context.Context {
if repo, ok := target.(*remote.Repository); ok {
scope := auth.ScopeRepository(repo.Reference.Repository, actions...)
return auth.AppendScopes(ctx, scope)
} else {
return ctx
}
return ctx
}

0 comments on commit 73667a2

Please sign in to comment.