Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat-273: TLS Flags #303

Merged
merged 9 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ airgap-scp.sh
dist/
tmp/
bin/
/store/
/registry/
store/
registry/
fileserver/
cmd/hauler/binaries
25 changes: 13 additions & 12 deletions cmd/hauler/cli/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
"helm.sh/helm/v3/pkg/action"

"github.com/rancherfederal/hauler/cmd/hauler/cli/store"
"github.com/rancherfederal/hauler/internal/flags"
)

var rootStoreOpts = &store.RootOpts{}
var rootStoreOpts = &flags.RootOpts{}

func addStore(parent *cobra.Command) {
cmd := &cobra.Command{
Expand Down Expand Up @@ -39,7 +40,7 @@ func addStore(parent *cobra.Command) {
}

func addStoreExtract() *cobra.Command {
o := &store.ExtractOpts{RootOpts: rootStoreOpts}
o := &flags.ExtractOpts{RootOpts: rootStoreOpts}

cmd := &cobra.Command{
Use: "extract",
Expand All @@ -63,7 +64,7 @@ func addStoreExtract() *cobra.Command {
}

func addStoreSync() *cobra.Command {
o := &store.SyncOpts{RootOpts: rootStoreOpts}
o := &flags.SyncOpts{RootOpts: rootStoreOpts}

cmd := &cobra.Command{
Use: "sync",
Expand All @@ -85,7 +86,7 @@ func addStoreSync() *cobra.Command {
}

func addStoreLoad() *cobra.Command {
o := &store.LoadOpts{RootOpts: rootStoreOpts}
o := &flags.LoadOpts{RootOpts: rootStoreOpts}

cmd := &cobra.Command{
Use: "load",
Expand Down Expand Up @@ -126,7 +127,7 @@ func addStoreServe() *cobra.Command {

// RegistryCmd serves the embedded registry
func addStoreServeRegistry() *cobra.Command {
o := &store.ServeRegistryOpts{RootOpts: rootStoreOpts}
o := &flags.ServeRegistryOpts{RootOpts: rootStoreOpts}
cmd := &cobra.Command{
Use: "registry",
Short: "Serve the embedded registry",
Expand All @@ -149,7 +150,7 @@ func addStoreServeRegistry() *cobra.Command {

// FileServerCmd serves the file server
func addStoreServeFiles() *cobra.Command {
o := &store.ServeFilesOpts{RootOpts: rootStoreOpts}
o := &flags.ServeFilesOpts{RootOpts: rootStoreOpts}
cmd := &cobra.Command{
Use: "fileserver",
Short: "Serve the file server",
Expand All @@ -171,7 +172,7 @@ func addStoreServeFiles() *cobra.Command {
}

func addStoreSave() *cobra.Command {
o := &store.SaveOpts{RootOpts: rootStoreOpts}
o := &flags.SaveOpts{RootOpts: rootStoreOpts}

cmd := &cobra.Command{
Use: "save",
Expand All @@ -195,7 +196,7 @@ func addStoreSave() *cobra.Command {
}

func addStoreInfo() *cobra.Command {
o := &store.InfoOpts{RootOpts: rootStoreOpts}
o := &flags.InfoOpts{RootOpts: rootStoreOpts}

var allowedValues = []string{"image", "chart", "file", "sigs", "atts", "sbom", "all"}

Expand Down Expand Up @@ -226,7 +227,7 @@ func addStoreInfo() *cobra.Command {
}

func addStoreCopy() *cobra.Command {
o := &store.CopyOpts{RootOpts: rootStoreOpts}
o := &flags.CopyOpts{RootOpts: rootStoreOpts}

cmd := &cobra.Command{
Use: "copy",
Expand Down Expand Up @@ -267,7 +268,7 @@ func addStoreAdd() *cobra.Command {
}

func addStoreAddFile() *cobra.Command {
o := &store.AddFileOpts{RootOpts: rootStoreOpts}
o := &flags.AddFileOpts{RootOpts: rootStoreOpts}

cmd := &cobra.Command{
Use: "file",
Expand All @@ -290,7 +291,7 @@ func addStoreAddFile() *cobra.Command {
}

func addStoreAddImage() *cobra.Command {
o := &store.AddImageOpts{RootOpts: rootStoreOpts}
o := &flags.AddImageOpts{RootOpts: rootStoreOpts}

cmd := &cobra.Command{
Use: "image",
Expand All @@ -313,7 +314,7 @@ func addStoreAddImage() *cobra.Command {
}

func addStoreAddChart() *cobra.Command {
o := &store.AddChartOpts{
o := &flags.AddChartOpts{
RootOpts: rootStoreOpts,
ChartOpts: &action.ChartPathOptions{},
}
Expand Down
51 changes: 4 additions & 47 deletions cmd/hauler/cli/store/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (

"github.com/google/go-containerregistry/pkg/name"
"github.com/rancherfederal/hauler/pkg/artifacts/file/getter"
"github.com/spf13/cobra"
"helm.sh/helm/v3/pkg/action"

"github.com/rancherfederal/hauler/internal/flags"
"github.com/rancherfederal/hauler/pkg/apis/hauler.cattle.io/v1alpha1"
"github.com/rancherfederal/hauler/pkg/artifacts/file"
"github.com/rancherfederal/hauler/pkg/content/chart"
Expand All @@ -17,17 +17,7 @@ import (
"github.com/rancherfederal/hauler/pkg/store"
)

type AddFileOpts struct {
*RootOpts
Name string
}

func (o *AddFileOpts) AddFlags(cmd *cobra.Command) {
f := cmd.Flags()
f.StringVarP(&o.Name, "name", "n", "", "(Optional) Name to assign to file in store")
}

func AddFileCmd(ctx context.Context, o *AddFileOpts, s *store.Layout, reference string) error {
func AddFileCmd(ctx context.Context, o *flags.AddFileOpts, s *store.Layout, reference string) error {
cfg := v1alpha1.File{
Path: reference,
}
Expand Down Expand Up @@ -61,20 +51,7 @@ func storeFile(ctx context.Context, s *store.Layout, fi v1alpha1.File) error {
return nil
}

type AddImageOpts struct {
*RootOpts
Name string
Key string
Platform string
}

func (o *AddImageOpts) AddFlags(cmd *cobra.Command) {
f := cmd.Flags()
f.StringVarP(&o.Key, "key", "k", "", "(Optional) Path to the key for digital signature verification")
f.StringVarP(&o.Platform, "platform", "p", "", "(Optional) Specific platform to save. i.e. linux/amd64. Defaults to all if flag is omitted.")
}

func AddImageCmd(ctx context.Context, o *AddImageOpts, s *store.Layout, reference string) error {
func AddImageCmd(ctx context.Context, o *flags.AddImageOpts, s *store.Layout, reference string) error {
l := log.FromContext(ctx)
cfg := v1alpha1.Image{
Name: reference,
Expand Down Expand Up @@ -111,27 +88,7 @@ func storeImage(ctx context.Context, s *store.Layout, i v1alpha1.Image, platform
return nil
}

type AddChartOpts struct {
*RootOpts

ChartOpts *action.ChartPathOptions
}

func (o *AddChartOpts) AddFlags(cmd *cobra.Command) {
f := cmd.Flags()

f.StringVar(&o.ChartOpts.RepoURL, "repo", "", "chart repository url where to locate the requested chart")
f.StringVar(&o.ChartOpts.Version, "version", "", "specify a version constraint for the chart version to use. This constraint can be a specific tag (e.g. 1.1.1) or it may reference a valid range (e.g. ^2.0.0). If this is not specified, the latest version is used")
f.BoolVar(&o.ChartOpts.Verify, "verify", false, "verify the package before using it")
f.StringVar(&o.ChartOpts.Username, "username", "", "chart repository username where to locate the requested chart")
f.StringVar(&o.ChartOpts.Password, "password", "", "chart repository password where to locate the requested chart")
f.StringVar(&o.ChartOpts.CertFile, "cert-file", "", "identify HTTPS client using this SSL certificate file")
f.StringVar(&o.ChartOpts.KeyFile, "key-file", "", "identify HTTPS client using this SSL key file")
f.BoolVar(&o.ChartOpts.InsecureSkipTLSverify, "insecure-skip-tls-verify", false, "skip tls certificate checks for the chart download")
f.StringVar(&o.ChartOpts.CaFile, "ca-file", "", "verify certificates of HTTPS-enabled servers using this CA bundle")
}

func AddChartCmd(ctx context.Context, o *AddChartOpts, s *store.Layout, chartName string) error {
func AddChartCmd(ctx context.Context, o *flags.AddChartOpts, s *store.Layout, chartName string) error {
// TODO: Reduce duplicates between api chart and upstream helm opts
cfg := v1alpha1.Chart{
Name: chartName,
Expand Down
22 changes: 2 additions & 20 deletions cmd/hauler/cli/store/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,15 @@ import (
"fmt"
"strings"

"github.com/spf13/cobra"
"oras.land/oras-go/pkg/content"

"github.com/rancherfederal/hauler/internal/flags"
"github.com/rancherfederal/hauler/pkg/cosign"
"github.com/rancherfederal/hauler/pkg/log"
"github.com/rancherfederal/hauler/pkg/store"
)

type CopyOpts struct {
*RootOpts

Username string
Password string
Insecure bool
PlainHTTP bool
}

func (o *CopyOpts) AddFlags(cmd *cobra.Command) {
f := cmd.Flags()

f.StringVarP(&o.Username, "username", "u", "", "Username when copying to an authenticated remote registry")
f.StringVarP(&o.Password, "password", "p", "", "Password when copying to an authenticated remote registry")
f.BoolVar(&o.Insecure, "insecure", false, "Toggle allowing insecure connections when copying to a remote registry")
f.BoolVar(&o.PlainHTTP, "plain-http", false, "Toggle allowing plain http connections when copying to a remote registry")
}

func CopyCmd(ctx context.Context, o *CopyOpts, s *store.Layout, targetRef string) error {
func CopyCmd(ctx context.Context, o *flags.CopyOpts, s *store.Layout, targetRef string) error {
l := log.FromContext(ctx)

components := strings.SplitN(targetRef, "://", 2)
Expand Down
15 changes: 2 additions & 13 deletions cmd/hauler/cli/store/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,15 @@ import (
"strings"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/spf13/cobra"

"github.com/rancherfederal/hauler/internal/flags"
"github.com/rancherfederal/hauler/internal/mapper"
"github.com/rancherfederal/hauler/pkg/log"
"github.com/rancherfederal/hauler/pkg/reference"
"github.com/rancherfederal/hauler/pkg/store"
)

type ExtractOpts struct {
*RootOpts
DestinationDir string
}

func (o *ExtractOpts) AddArgs(cmd *cobra.Command) {
f := cmd.Flags()

f.StringVarP(&o.DestinationDir, "output", "o", "", "Directory to save contents to (defaults to current directory)")
}

func ExtractCmd(ctx context.Context, o *ExtractOpts, s *store.Layout, ref string) error {
func ExtractCmd(ctx context.Context, o *flags.ExtractOpts, s *store.Layout, ref string) error {
l := log.FromContext(ctx)

r, err := reference.Parse(ref)
Expand Down
25 changes: 3 additions & 22 deletions cmd/hauler/cli/store/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,14 @@ import (

"github.com/olekukonko/tablewriter"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/spf13/cobra"

"github.com/rancherfederal/hauler/internal/flags"
"github.com/rancherfederal/hauler/pkg/consts"
"github.com/rancherfederal/hauler/pkg/reference"
"github.com/rancherfederal/hauler/pkg/store"
)

type InfoOpts struct {
*RootOpts

OutputFormat string
TypeFilter string
SizeUnit string
ListRepos bool
}

func (o *InfoOpts) AddFlags(cmd *cobra.Command) {
f := cmd.Flags()

f.StringVarP(&o.OutputFormat, "output", "o", "table", "Output format (table, json)")
f.StringVarP(&o.TypeFilter, "type", "t", "all", "Filter on type (image, chart, file, sigs, atts, sbom)")
f.BoolVar(&o.ListRepos, "list-repos", false, "List all repository names")

// TODO: Regex/globbing
}

func InfoCmd(ctx context.Context, o *InfoOpts, s *store.Layout) error {
func InfoCmd(ctx context.Context, o *flags.InfoOpts, s *store.Layout) error {
var items []item
if err := s.Walk(func(ref string, desc ocispec.Descriptor) error {
if _, ok := desc.Annotations[ocispec.AnnotationRefName]; !ok {
Expand Down Expand Up @@ -229,7 +210,7 @@ func (a byReferenceAndArch) Less(i, j int) bool {
return a[i].Reference < a[j].Reference
}

func newItem(s *store.Layout, desc ocispec.Descriptor, m ocispec.Manifest, plat string, o *InfoOpts) item {
func newItem(s *store.Layout, desc ocispec.Descriptor, m ocispec.Manifest, plat string, o *flags.InfoOpts) item {
var size int64 = 0
for _, l := range m.Layers {
size += l.Size
Expand Down
19 changes: 2 additions & 17 deletions cmd/hauler/cli/store/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,16 @@ import (
"os"

"github.com/mholt/archiver/v3"
"github.com/spf13/cobra"

"github.com/rancherfederal/hauler/internal/flags"
"github.com/rancherfederal/hauler/pkg/content"
"github.com/rancherfederal/hauler/pkg/log"
"github.com/rancherfederal/hauler/pkg/store"
)

type LoadOpts struct {
*RootOpts
TempOverride string
}

func (o *LoadOpts) AddFlags(cmd *cobra.Command) {
f := cmd.Flags()

// On Unix systems, the default is $TMPDIR if non-empty, else /tmp.
// On Windows, the default is GetTempPath, returning the first non-empty
// value from %TMP%, %TEMP%, %USERPROFILE%, or the Windows directory.
// On Plan 9, the default is /tmp.
f.StringVarP(&o.TempOverride, "tempdir", "t", "", "overrides the default directory for temporary files, as returned by your OS.")
}

// LoadCmd
// TODO: Just use mholt/archiver for now, even though we don't need most of it
func LoadCmd(ctx context.Context, o *LoadOpts, archiveRefs ...string) error {
func LoadCmd(ctx context.Context, o *flags.LoadOpts, archiveRefs ...string) error {
l := log.FromContext(ctx)

for _, archiveRef := range archiveRefs {
Expand Down
15 changes: 2 additions & 13 deletions cmd/hauler/cli/store/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,14 @@ import (
"path/filepath"

"github.com/mholt/archiver/v3"
"github.com/spf13/cobra"

"github.com/rancherfederal/hauler/internal/flags"
"github.com/rancherfederal/hauler/pkg/log"
)

type SaveOpts struct {
*RootOpts
FileName string
}

func (o *SaveOpts) AddArgs(cmd *cobra.Command) {
f := cmd.Flags()

f.StringVarP(&o.FileName, "filename", "f", "haul.tar.zst", "Name of archive")
}

// SaveCmd
// TODO: Just use mholt/archiver for now, even though we don't need most of it
func SaveCmd(ctx context.Context, o *SaveOpts, outputFile string) error {
func SaveCmd(ctx context.Context, o *flags.SaveOpts, outputFile string) error {
l := log.FromContext(ctx)

// TODO: Support more formats?
Expand Down
Loading