Skip to content

Commit 48ead1b

Browse files
loresusopoiana
authored andcommitted
update: add options for oauth and plain http for pusher and puller
Signed-off-by: Lorenzo Susini <[email protected]>
1 parent c94ca13 commit 48ead1b

File tree

5 files changed

+38
-3
lines changed

5 files changed

+38
-3
lines changed

internal/registry/pull/pull.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Example - Pull artifact "myrulesfile" of type "rulesfile":
4343
type pullOptions struct {
4444
*options.CommonOptions
4545
*options.ArtifactOptions
46+
*options.RegistryOptions
4647
destDir string
4748
}
4849

@@ -55,6 +56,7 @@ func NewPullCmd(ctx context.Context, opt *options.CommonOptions) *cobra.Command
5556
o := pullOptions{
5657
CommonOptions: opt,
5758
ArtifactOptions: &options.ArtifactOptions{},
59+
RegistryOptions: &options.RegistryOptions{},
5860
}
5961

6062
cmd := &cobra.Command{
@@ -71,6 +73,7 @@ func NewPullCmd(ctx context.Context, opt *options.CommonOptions) *cobra.Command
7173
},
7274
}
7375
o.CommonOptions.AddFlags(cmd.Flags())
76+
o.RegistryOptions.AddFlags(cmd)
7477
o.Printer.CheckErr(o.ArtifactOptions.AddFlags(cmd))
7578
cmd.Flags().StringVarP(&o.destDir, "dest-dir", "o", "", "destination dir where to save the artifacts(default: current directory)")
7679
return cmd
@@ -86,7 +89,7 @@ func (o *pullOptions) RunPull(ctx context.Context, args []string) error {
8689
return err
8790
}
8891

89-
puller, err := utils.PullerForRegistry(ctx, registry, true, true, o.Printer)
92+
puller, err := utils.PullerForRegistry(ctx, registry, o.PlainHTTP, o.Oauth, o.Printer)
9093
if err != nil {
9194
return fmt.Errorf("an error occurred while creating the puller for registry %s: %w", registry, err)
9295
}

internal/registry/push/push.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Example - Push artifact "myrulesfile.tar.gz" of type "rulesfile" with multiple d
5757
type pushOptions struct {
5858
*options.CommonOptions
5959
*options.ArtifactOptions
60+
*options.RegistryOptions
6061
}
6162

6263
func (o pushOptions) validate() error {
@@ -68,6 +69,7 @@ func NewPushCmd(ctx context.Context, opt *options.CommonOptions) *cobra.Command
6869
o := pushOptions{
6970
CommonOptions: opt,
7071
ArtifactOptions: &options.ArtifactOptions{},
72+
RegistryOptions: &options.RegistryOptions{},
7173
}
7274

7375
cmd := &cobra.Command{
@@ -85,6 +87,7 @@ func NewPushCmd(ctx context.Context, opt *options.CommonOptions) *cobra.Command
8587
},
8688
}
8789
o.CommonOptions.AddFlags(cmd.Flags())
90+
o.RegistryOptions.AddFlags(cmd)
8891
o.Printer.CheckErr(o.ArtifactOptions.AddFlags(cmd))
8992

9093
return cmd
@@ -101,7 +104,7 @@ func (o *pushOptions) RunPush(ctx context.Context, args []string) error {
101104
return err
102105
}
103106

104-
pusher, err := utils.PusherForRegistry(ctx, true, true, registry, o.Printer)
107+
pusher, err := utils.PusherForRegistry(ctx, o.PlainHTTP, o.Oauth, registry, o.Printer)
105108
if err != nil {
106109
return fmt.Errorf("an error occurred while creating the pusher for registry %s: %w", registry, err)
107110
}

internal/utils/registry.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func ClientForRegistry(ctx context.Context, registry string, oauth bool, printer
6969
if err != nil {
7070
return nil, fmt.Errorf("unable to retrieve credentials for registry %s: %w", registry, err)
7171
}
72+
}
7273

7374
if err := CheckRegistryConnection(ctx, &cred, registry, printer); err != nil {
7475
printer.Verbosef("%s", err.Error())

pkg/oci/puller/puller.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
v1 "github.com/opencontainers/image-spec/specs-go/v1"
2424
"oras.land/oras-go/v2"
2525
"oras.land/oras-go/v2/content/file"
26-
"oras.land/oras-go/v2/registry/remote"
2726

2827
"github.com/falcosecurity/falcoctl/pkg/oci"
2928
"github.com/falcosecurity/falcoctl/pkg/oci/authn"

pkg/options/registry_options.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2022 The Falco Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package options
16+
17+
import "github.com/spf13/cobra"
18+
19+
// RegistryOptions defines options that are common while interacting with a remote registry.
20+
type RegistryOptions struct {
21+
Oauth bool
22+
PlainHTTP bool
23+
}
24+
25+
// AddFlags registers the registry flags.
26+
func (r *RegistryOptions) AddFlags(cmd *cobra.Command) {
27+
cmd.Flags().BoolVar(&r.Oauth, "oauth", false, "allows interacting with remote registry via OAuth authentication")
28+
cmd.Flags().BoolVar(&r.PlainHTTP, "plain-http", false, "allows interacting with remote registry via plain http requests")
29+
}

0 commit comments

Comments
 (0)