Skip to content

Commit b3df128

Browse files
authored
Merge branch 'main' into main
2 parents c4c4310 + 39d1148 commit b3df128

File tree

341 files changed

+2601
-2722
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

341 files changed

+2601
-2722
lines changed

cmd/crane/cmd/auth.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ $ curl -H "$(crane auth token -H ubuntu)" https://index.docker.io/v2/library/ubu
7373
return err
7474
}
7575

76-
auth, err := o.Keychain.Resolve(repo)
76+
auth, err := authn.Resolve(cmd.Context(), o.Keychain, repo)
7777
if err != nil {
7878
return err
7979
}
@@ -152,7 +152,7 @@ func NewCmdAuthGet(options []crane.Option, argv ...string) *cobra.Command {
152152
Short: "Implements a credential helper",
153153
Example: eg,
154154
Args: cobra.MaximumNArgs(1),
155-
RunE: func(_ *cobra.Command, args []string) error {
155+
RunE: func(cmd *cobra.Command, args []string) error {
156156
registryAddr := ""
157157
if len(args) == 1 {
158158
registryAddr = args[0]
@@ -168,7 +168,7 @@ func NewCmdAuthGet(options []crane.Option, argv ...string) *cobra.Command {
168168
if err != nil {
169169
return err
170170
}
171-
authorizer, err := crane.GetOptions(options...).Keychain.Resolve(reg)
171+
authorizer, err := authn.Resolve(cmd.Context(), crane.GetOptions(options...).Keychain, reg)
172172
if err != nil {
173173
return err
174174
}
@@ -182,7 +182,7 @@ func NewCmdAuthGet(options []crane.Option, argv ...string) *cobra.Command {
182182
os.Exit(1)
183183
}
184184

185-
auth, err := authorizer.Authorization()
185+
auth, err := authn.Authorization(cmd.Context(), authorizer)
186186
if err != nil {
187187
return err
188188
}

cmd/crane/cmd/mutate.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func NewCmdMutate(options *[]crane.Option) *cobra.Command {
4343
var workdir string
4444
var ports []string
4545
var ociEmptyBase bool
46+
var newPlatform string
4647

4748
mutateCmd := &cobra.Command{
4849
Use: "mutate",
@@ -151,8 +152,20 @@ func NewCmdMutate(options *[]crane.Option) *cobra.Command {
151152
cfg.Config.ExposedPorts = portMap
152153
}
153154

155+
// Set platform
156+
if len(newPlatform) > 0 {
157+
platform, err := parsePlatform(newPlatform)
158+
if err != nil {
159+
return err
160+
}
161+
cfg.OS = platform.OS
162+
cfg.Architecture = platform.Architecture
163+
cfg.Variant = platform.Variant
164+
cfg.OSVersion = platform.OSVersion
165+
}
166+
154167
// Mutate and write image.
155-
img, err = mutate.Config(img, cfg.Config)
168+
img, err = mutate.ConfigFile(img, cfg)
156169
if err != nil {
157170
return fmt.Errorf("mutating config: %w", err)
158171
}
@@ -205,8 +218,10 @@ func NewCmdMutate(options *[]crane.Option) *cobra.Command {
205218
mutateCmd.Flags().StringVarP(&workdir, "workdir", "w", "", "New working dir to set")
206219
mutateCmd.Flags().StringSliceVar(&ports, "exposed-ports", nil, "New ports to expose")
207220
mutateCmd.Flags().BoolVar(&ociEmptyBase, "oci-empty-base", false, "If true, scratch base image will have OCI media types instead of Docker")
208-
209-
return mutateCmd
221+
// Using "set-platform" to avoid clobbering "platform" persistent flag.
222+
mutateCmd.Flags().StringVar(&newPlatform, "set-platform", "", "New platform to set in the form os/arch[/variant][:osversion] (e.g. linux/amd64)")
223+
224+
return mutateCmd
210225
}
211226

212227
// validateKeyVals ensures no values are empty, returns error if they are

cmd/crane/doc/crane_mutate.md

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/krane/go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ require (
5656
github.com/spf13/cobra v1.7.0 // indirect
5757
github.com/spf13/pflag v1.0.5 // indirect
5858
github.com/vbatts/tar-split v0.11.3 // indirect
59-
golang.org/x/crypto v0.9.0 // indirect
60-
golang.org/x/net v0.10.0 // indirect
59+
golang.org/x/crypto v0.17.0 // indirect
60+
golang.org/x/net v0.17.0 // indirect
6161
golang.org/x/oauth2 v0.8.0 // indirect
6262
golang.org/x/sync v0.2.0 // indirect
63-
golang.org/x/sys v0.8.0 // indirect
63+
golang.org/x/sys v0.15.0 // indirect
6464
google.golang.org/appengine v1.6.7 // indirect
6565
google.golang.org/protobuf v1.30.0 // indirect
6666
gotest.tools/v3 v3.1.0 // indirect

cmd/krane/go.sum

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ require (
3737
github.com/spf13/pflag v1.0.5 // indirect
3838
github.com/vbatts/tar-split v0.11.3 // indirect
3939
golang.org/x/mod v0.10.0 // indirect
40-
golang.org/x/net v0.10.0 // indirect
41-
golang.org/x/sys v0.8.0 // indirect
40+
golang.org/x/net v0.17.0 // indirect
41+
golang.org/x/sys v0.15.0 // indirect
4242
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
4343
google.golang.org/appengine v1.6.7 // indirect
4444
google.golang.org/protobuf v1.30.0 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/authn/authn.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package authn
1616

1717
import (
18+
"context"
1819
"encoding/base64"
1920
"encoding/json"
2021
"fmt"
@@ -27,6 +28,22 @@ type Authenticator interface {
2728
Authorization() (*AuthConfig, error)
2829
}
2930

31+
// ContextAuthenticator is like Authenticator, but allows for context to be passed in.
32+
type ContextAuthenticator interface {
33+
// Authorization returns the value to use in an http transport's Authorization header.
34+
AuthorizationContext(context.Context) (*AuthConfig, error)
35+
}
36+
37+
// Authorization calls AuthorizationContext with ctx if the given [Authenticator] implements [ContextAuthenticator],
38+
// otherwise it calls Resolve with the given [Resource].
39+
func Authorization(ctx context.Context, authn Authenticator) (*AuthConfig, error) {
40+
if actx, ok := authn.(ContextAuthenticator); ok {
41+
return actx.AuthorizationContext(ctx)
42+
}
43+
44+
return authn.Authorization()
45+
}
46+
3047
// AuthConfig contains authorization information for connecting to a Registry
3148
// Inlined what we use from github.com/docker/cli/cli/config/types
3249
type AuthConfig struct {

pkg/authn/k8schain/go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ require (
7575
github.com/pkg/errors v0.9.1 // indirect
7676
github.com/sirupsen/logrus v1.9.1 // indirect
7777
github.com/vbatts/tar-split v0.11.3 // indirect
78-
golang.org/x/crypto v0.9.0 // indirect
79-
golang.org/x/net v0.10.0 // indirect
78+
golang.org/x/crypto v0.17.0 // indirect
79+
golang.org/x/net v0.17.0 // indirect
8080
golang.org/x/oauth2 v0.8.0 // indirect
8181
golang.org/x/sync v0.2.0 // indirect
82-
golang.org/x/sys v0.8.0 // indirect
83-
golang.org/x/term v0.8.0 // indirect
84-
golang.org/x/text v0.9.0 // indirect
82+
golang.org/x/sys v0.15.0 // indirect
83+
golang.org/x/term v0.15.0 // indirect
84+
golang.org/x/text v0.14.0 // indirect
8585
golang.org/x/time v0.3.0 // indirect
8686
google.golang.org/appengine v1.6.7 // indirect
8787
google.golang.org/protobuf v1.30.0 // indirect

pkg/authn/k8schain/go.sum

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)