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 all 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
45 changes: 23 additions & 22 deletions cmd/hauler/cli/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@ package cli
import (
"fmt"
"os"

"github.com/spf13/cobra"
)

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 All @@ -34,19 +35,19 @@ func addCompletionZsh() *cobra.Command {
Short: "Generates zsh completion scripts",
Long: `The completion sub-command generates completion scripts for zsh.`,
Example: `To load completion run

. <(hauler completion zsh)

To configure your zsh shell to load completions for each session add to your zshrc

# ~/.zshrc or ~/.profile
command -v hauler >/dev/null && . <(hauler completion zsh)

or write a cached file in one of the completion directories in your ${fpath}:

echo "${fpath// /\n}" | grep -i completion
hauler completion zsh > _hauler

mv _hauler ~/.oh-my-zsh/completions # oh-my-zsh
mv _hauler ~/.zprezto/modules/completion/external/src/ # zprezto`,
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -64,11 +65,11 @@ func addCompletionBash() *cobra.Command {
Short: "Generates bash completion scripts",
Long: `The completion sub-command generates completion scripts for bash.`,
Example: `To load completion run

. <(hauler completion bash)

To configure your bash shell to load completions for each session add to your bashrc

# ~/.bashrc or ~/.profile
command -v hauler >/dev/null && . <(hauler completion bash)`,
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -84,9 +85,9 @@ func addCompletionFish() *cobra.Command {
Short: "Generates fish completion scripts",
Long: `The completion sub-command generates completion scripts for fish.`,
Example: `To configure your fish shell to load completions for each session write this script to your completions dir:

hauler completion fish > ~/.config/fish/completions/hauler.fish

See http://fishshell.com/docs/current/index.html#completion-own for more details`,
Run: func(cmd *cobra.Command, args []string) {
cmd.GenFishCompletion(os.Stdout, true)
Expand All @@ -101,23 +102,23 @@ func addCompletionPowershell() *cobra.Command {
Short: "Generates powershell completion scripts",
Long: `The completion sub-command generates completion scripts for powershell.`,
Example: `To load completion run

. <(hauler completion powershell)

To configure your powershell shell to load completions for each session add to your powershell profile

Windows:

cd "$env:USERPROFILE\Documents\WindowsPowerShell\Modules"
hauler completion powershell >> hauler-completion.ps1

Linux:

cd "${XDG_CONFIG_HOME:-"$HOME/.config/"}/powershell/modules"
hauler completion powershell >> hauler-completions.ps1`,
Run: func(cmd *cobra.Command, args []string) {
cmd.GenPowerShellCompletion(os.Stdout)
},
}
return cmd
}
}
24 changes: 12 additions & 12 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"

"github.com/spf13/cobra"
"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
}
}
37 changes: 19 additions & 18 deletions cmd/hauler/cli/store.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
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 +126,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 +139,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 +162,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 +211,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
10 changes: 4 additions & 6 deletions cmd/hauler/cli/store/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ import (
"github.com/spf13/cobra"
"helm.sh/helm/v3/pkg/action"

"github.com/rancherfederal/hauler/pkg/artifacts/file"

"github.com/rancherfederal/hauler/pkg/store"

"github.com/rancherfederal/hauler/pkg/apis/hauler.cattle.io/v1alpha1"
"github.com/rancherfederal/hauler/pkg/artifacts/file"
"github.com/rancherfederal/hauler/pkg/content/chart"
"github.com/rancherfederal/hauler/pkg/cosign"
"github.com/rancherfederal/hauler/pkg/log"
"github.com/rancherfederal/hauler/pkg/reference"
"github.com/rancherfederal/hauler/pkg/store"
)

type AddFileOpts struct {
Expand Down Expand Up @@ -103,7 +101,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 +145,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
5 changes: 2 additions & 3 deletions cmd/hauler/cli/store/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import (
"oras.land/oras-go/pkg/content"

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

"github.com/rancherfederal/hauler/pkg/log"
"github.com/rancherfederal/hauler/pkg/store"
)

type CopyOpts struct {
Expand Down Expand Up @@ -55,7 +54,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
7 changes: 3 additions & 4 deletions cmd/hauler/cli/store/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ package store

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

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

"github.com/rancherfederal/hauler/pkg/store"

"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 {
Expand All @@ -37,7 +36,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
2 changes: 1 addition & 1 deletion cmd/hauler/cli/store/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"os"
"path/filepath"

"github.com/rancherfederal/hauler/pkg/store"
"github.com/spf13/cobra"

"github.com/rancherfederal/hauler/pkg/log"
"github.com/rancherfederal/hauler/pkg/store"
)

const (
Expand Down
Loading