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

formatted all code with go fmt #248

Merged
merged 3 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 1 addition & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
.DS_Store

# Vagrant
.vagrant

# Editor directories and files
**/.DS_Store
.idea
.vscode
*.suo
Expand All @@ -12,13 +8,9 @@
*.sln
*.sw?
*.dir-locals.el

# old, ad-hoc ignores
artifacts
local-artifacts
airgap-scp.sh

# generated
dist/
tmp/
bin/
Expand Down
12 changes: 6 additions & 6 deletions cmd/hauler/cli/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ package cli

import (
"fmt"
"os"
"github.com/spf13/cobra"
"os"
)

func addCompletion(parent *cobra.Command) {
cmd := &cobra.Command{
Use: "completion",
Short: "Generates completion scripts for various shells",
Use: "completion",
Short: "Generates completion scripts for various shells",
Long: `The completion sub-command generates completion scripts for various shells.`,
}

cmd.AddCommand(
addCompletionZsh(),
addCompletionBash(),
addCompletionFish(),
addCompletionPowershell(),
)

parent.AddCommand(cmd)
}

Expand Down Expand Up @@ -120,4 +120,4 @@ func addCompletionPowershell() *cobra.Command {
},
}
return cmd
}
}
22 changes: 11 additions & 11 deletions cmd/hauler/cli/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ package cli

import (
"context"
"strings"
"os"
"io"
"fmt"
"github.com/spf13/cobra"
"io"
"os"
"strings"

"oras.land/oras-go/pkg/content"

"github.com/rancherfederal/hauler/pkg/cosign"
)

type Opts struct {
Username string
Password string
Username string
Password string
PasswordStdin bool
}

Expand All @@ -35,7 +35,7 @@ func addLogin(parent *cobra.Command) {
Example: `
# Log in to reg.example.com
hauler login reg.example.com -u bob -p haulin`,
Args: cobra.ExactArgs(1),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, arg []string) error {
ctx := cmd.Context()

Expand All @@ -47,7 +47,7 @@ hauler login reg.example.com -u bob -p haulin`,
o.Password = strings.TrimSuffix(string(contents), "\n")
o.Password = strings.TrimSuffix(o.Password, "\r")
}

if o.Username == "" && o.Password == "" {
return fmt.Errorf("username and password required")
}
Expand All @@ -62,14 +62,14 @@ hauler login reg.example.com -u bob -p haulin`,

func login(ctx context.Context, o *Opts, registry string) error {
ropts := content.RegistryOptions{
Username: o.Username,
Password: o.Password,
Username: o.Username,
Password: o.Password,
}

err := cosign.RegistryLogin(ctx, nil, registry, ropts)
if err != nil {
return err
}

return nil
}
}
36 changes: 18 additions & 18 deletions cmd/hauler/cli/store.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cli

import (
"fmt"
"github.com/spf13/cobra"
"helm.sh/helm/v3/pkg/action"
"fmt"

"github.com/rancherfederal/hauler/cmd/hauler/cli/store"
)
Expand Down Expand Up @@ -125,11 +125,11 @@ func addStoreServe() *cobra.Command {

// RegistryCmd serves the embedded registry
func addStoreServeRegistry() *cobra.Command {
o := &store.ServeRegistryOpts{RootOpts: rootStoreOpts}
o := &store.ServeRegistryOpts{RootOpts: rootStoreOpts}
cmd := &cobra.Command{
Use: "registry",
Short: "Serve the embedded registry",
RunE: func(cmd *cobra.Command, args []string) error {
Use: "registry",
Short: "Serve the embedded registry",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()

s, err := o.Store(ctx)
Expand All @@ -138,21 +138,21 @@ func addStoreServeRegistry() *cobra.Command {
}

return store.ServeRegistryCmd(ctx, o, s)
},
}
},
}

o.AddFlags(cmd)
o.AddFlags(cmd)

return cmd
return cmd
}

// FileServerCmd serves the file server
func addStoreServeFiles() *cobra.Command {
o := &store.ServeFilesOpts{RootOpts: rootStoreOpts}
o := &store.ServeFilesOpts{RootOpts: rootStoreOpts}
cmd := &cobra.Command{
Use: "fileserver",
Short: "Serve the file server",
RunE: func(cmd *cobra.Command, args []string) error {
Use: "fileserver",
Short: "Serve the file server",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()

s, err := o.Store(ctx)
Expand All @@ -161,12 +161,12 @@ func addStoreServeFiles() *cobra.Command {
}

return store.ServeFilesCmd(ctx, o, s)
},
}
},
}

o.AddFlags(cmd)
o.AddFlags(cmd)

return cmd
return cmd
}

func addStoreSave() *cobra.Command {
Expand Down Expand Up @@ -210,7 +210,7 @@ func addStoreInfo() *cobra.Command {
if err != nil {
return err
}

for _, allowed := range allowedValues {
if o.TypeFilter == allowed {
return store.InfoCmd(ctx, o, s)
Expand Down
4 changes: 2 additions & 2 deletions cmd/hauler/cli/store/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func storeImage(ctx context.Context, s *store.Layout, i v1alpha1.Image, platform
if err != nil {
return err
}

err = cosign.SaveImage(ctx, s, r.Name(), platform)
if err != nil {
return err
Expand Down Expand Up @@ -147,7 +147,7 @@ func AddChartCmd(ctx context.Context, o *AddChartOpts, s *store.Layout, chartNam
func storeChart(ctx context.Context, s *store.Layout, cfg v1alpha1.Chart, opts *action.ChartPathOptions) error {
l := log.FromContext(ctx)
l.Infof("adding 'chart' [%s] to the store", cfg.Name)

// TODO: This shouldn't be necessary
opts.RepoURL = cfg.RepoURL
opts.Version = cfg.Version
Expand Down
2 changes: 1 addition & 1 deletion cmd/hauler/cli/store/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func CopyCmd(ctx context.Context, o *CopyOpts, s *store.Layout, targetRef string
Insecure: o.Insecure,
PlainHTTP: o.PlainHTTP,
}

if ropts.Username != "" {
err := cosign.RegistryLogin(ctx, s, components[1], ropts)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/hauler/cli/store/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package store

import (
"context"
"strings"
"encoding/json"
"fmt"
"strings"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -37,7 +37,7 @@ func ExtractCmd(ctx context.Context, o *ExtractOpts, s *store.Layout, ref string

found := false
if err := s.Walk(func(reference string, desc ocispec.Descriptor) error {

if !strings.Contains(reference, r.Name()) {
return nil
}
Expand Down
36 changes: 18 additions & 18 deletions cmd/hauler/cli/store/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func InfoCmd(ctx context.Context, o *InfoOpts, s *store.Layout) error {
}
defer rc.Close()

// handle multi-arch images
// handle multi-arch images
if desc.MediaType == consts.OCIImageIndexSchema || desc.MediaType == consts.DockerManifestListSchema2 {
var idx ocispec.Index
if err := json.NewDecoder(rc).Decode(&idx); err != nil {
Expand All @@ -72,13 +72,13 @@ func InfoCmd(ctx context.Context, o *InfoOpts, s *store.Layout) error {
items = append(items, i)
}
}
// handle "non" multi-arch images
// handle "non" multi-arch images
} else if desc.MediaType == consts.DockerManifestSchema2 || desc.MediaType == consts.OCIManifestSchema1 {
var m ocispec.Manifest
if err := json.NewDecoder(rc).Decode(&m); err != nil {
return err
}

rc, err := s.FetchManifest(ctx, m)
if err != nil {
return err
Expand All @@ -90,7 +90,7 @@ func InfoCmd(ctx context.Context, o *InfoOpts, s *store.Layout) error {
if err := json.NewDecoder(rc).Decode(&internalManifest); err != nil {
return err
}

if internalManifest.Architecture != "" {
i := newItem(s, desc, m, fmt.Sprintf("%s/%s", internalManifest.OS, internalManifest.Architecture), o)
var emptyItem item
Expand All @@ -104,8 +104,8 @@ func InfoCmd(ctx context.Context, o *InfoOpts, s *store.Layout) error {
items = append(items, i)
}
}
// handle the rest
} else {
// handle the rest
} else {
var m ocispec.Manifest
if err := json.NewDecoder(rc).Decode(&m); err != nil {
return err
Expand Down Expand Up @@ -144,7 +144,7 @@ func buildTable(items ...item) {
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
table.SetRowLine(false)
table.SetAutoMergeCellsByColumnIndex([]int{0})

totalSize := int64(0)
for _, i := range items {
if i.Type != "" {
Expand Down Expand Up @@ -173,11 +173,11 @@ func buildJson(item ...item) string {
}

type item struct {
Reference string
Type string
Platform string
Layers int
Size int64
Reference string
Type string
Platform string
Layers int
Size int64
}

type byReferenceAndArch []item
Expand Down Expand Up @@ -227,7 +227,7 @@ func newItem(s *store.Layout, desc ocispec.Descriptor, m ocispec.Manifest, plat
case "dev.cosignproject.cosign/sboms":
ctype = "sbom"
}

ref, err := reference.Parse(desc.Annotations[ocispec.AnnotationRefName])
if err != nil {
return item{}
Expand All @@ -238,11 +238,11 @@ func newItem(s *store.Layout, desc ocispec.Descriptor, m ocispec.Manifest, plat
}

return item{
Reference: ref.Name(),
Type: ctype,
Platform: plat,
Layers: len(m.Layers),
Size: size,
Reference: ref.Name(),
Type: ctype,
Platform: plat,
Layers: len(m.Layers),
Size: size,
}
}

Expand Down
Loading