-
Notifications
You must be signed in to change notification settings - Fork 182
/
Copy pathtools.go
84 lines (73 loc) · 2.51 KB
/
tools.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package cmd
import (
"fmt"
"github.com/defenseunicorns/zarf/cli/config"
"github.com/defenseunicorns/zarf/cli/internal/git"
"github.com/defenseunicorns/zarf/cli/internal/log"
craneCmd "github.com/google/go-containerregistry/cmd/crane/cmd"
"github.com/google/go-containerregistry/pkg/crane"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/mholt/archiver/v3"
"github.com/spf13/cobra"
)
var toolsCmd = &cobra.Command{
Use: "tools",
Short: "Collection of additional tools to make airgap easier",
}
// destroyCmd represents the init command
var archiverCmd = &cobra.Command{
Use: "archiver",
Short: "Compress/Decompress tools",
}
var archiverCompressCmd = &cobra.Command{
Use: "compress SOURCES ARCHIVE",
Short: "Compress a collection of sources based off of the destination file extension",
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
sourceFiles, destinationArchive := args[:len(args)-1], args[len(args)-1]
err := archiver.Archive(sourceFiles, destinationArchive)
if err != nil {
log.Logger.Fatal(err)
}
},
}
var archiverDecompressCmd = &cobra.Command{
Use: "decompress ARCHIVE DESTINATION",
Short: "Decompress an archive to a specified location.",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
sourceArchive, destinationPath := args[0], args[1]
err := archiver.Unarchive(sourceArchive, destinationPath)
if err != nil {
log.Logger.Fatal(err)
}
},
}
var registryCmd = &cobra.Command{
Use: "registry",
Short: "Collection of registry commands provided by Crane",
}
var readCredsCmd = &cobra.Command{
Use: "get-admin-password",
Short: "Returns the Zarf admin password read from ~/.git-credentials",
Run: func(cmd *cobra.Command, args []string) {
authInfo := git.FindAuthForHost(config.ZarfLocalIP)
fmt.Println(authInfo.Auth.Password)
},
}
func init() {
rootCmd.AddCommand(toolsCmd)
toolsCmd.AddCommand(archiverCmd)
toolsCmd.AddCommand(readCredsCmd)
archiverCmd.AddCommand(archiverCompressCmd)
archiverCmd.AddCommand(archiverDecompressCmd)
toolsCmd.AddCommand(registryCmd)
cranePlatformOptions := []crane.Option{
crane.WithPlatform(&v1.Platform{OS: "linux", Architecture: "amd64"}),
}
registryCmd.AddCommand(craneCmd.NewCmdAuthLogin())
registryCmd.AddCommand(craneCmd.NewCmdPull(&cranePlatformOptions))
registryCmd.AddCommand(craneCmd.NewCmdPush(&cranePlatformOptions))
registryCmd.AddCommand(craneCmd.NewCmdCopy(&cranePlatformOptions))
registryCmd.AddCommand(craneCmd.NewCmdCatalog(&cranePlatformOptions))
}