|
1 | 1 | package packager
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "context" |
4 | 5 | "crypto/sha256"
|
5 | 6 | "encoding/hex"
|
6 | 7 | "fmt"
|
@@ -79,10 +80,10 @@ func confirmAction(configPath, userMessage string, sbomViewFiles []string) bool
|
79 | 80 | if err != nil {
|
80 | 81 | message.Fatal(err, "Unable to open the package config file")
|
81 | 82 | }
|
82 |
| - |
| 83 | + |
83 | 84 | // Convert []byte to string and print to screen
|
84 | 85 | text := string(content)
|
85 |
| - |
| 86 | + |
86 | 87 | pterm.Println()
|
87 | 88 | utils.ColorPrintYAML(text)
|
88 | 89 |
|
@@ -118,6 +119,11 @@ func HandleIfURL(packagePath string, shasum string, insecureDeploy bool) (string
|
118 | 119 | return packagePath, func() {}
|
119 | 120 | }
|
120 | 121 |
|
| 122 | + // Handle case where deploying remote package validated via sget |
| 123 | + if strings.HasPrefix(packagePath, "sget://") { |
| 124 | + return handleSgetPackage(packagePath) |
| 125 | + } |
| 126 | + |
121 | 127 | if !insecureDeploy && shasum == "" {
|
122 | 128 | message.Fatal(nil, "When deploying a remote package you must provide either a `--shasum` or the `--insecure` flag. Neither were provided.")
|
123 | 129 | }
|
@@ -163,6 +169,36 @@ func HandleIfURL(packagePath string, shasum string, insecureDeploy bool) (string
|
163 | 169 | return localPackagePath, tempPath.clean
|
164 | 170 | }
|
165 | 171 |
|
| 172 | +func handleSgetPackage(sgetPackagePath string) (string, func()) { |
| 173 | + // Write the package to a local file in a temp path |
| 174 | + tempPath := createPaths() |
| 175 | + |
| 176 | + // Create the local file for the package |
| 177 | + localPackagePath := filepath.Join(tempPath.base, "remote.tar.zst") |
| 178 | + destinationFile, err := os.Create(localPackagePath) |
| 179 | + if err != nil { |
| 180 | + message.Fatal(err, "Unable to create the destination file") |
| 181 | + } |
| 182 | + defer destinationFile.Close() |
| 183 | + |
| 184 | + // If this is a DefenseUnicorns package, use an internal sget public key |
| 185 | + if strings.HasPrefix(sgetPackagePath, "sget://defenseunicorns") { |
| 186 | + os.Setenv("DU_SGET_KEY", config.SGetPublicKey) |
| 187 | + config.DeployOptions.SGetKeyPath = "env://DU_SGET_KEY" |
| 188 | + } |
| 189 | + |
| 190 | + // Remove the 'sget://' header for the actual sget call |
| 191 | + sgetPackagePath = strings.TrimPrefix(sgetPackagePath, "sget://") |
| 192 | + |
| 193 | + // Sget the package |
| 194 | + err = utils.Sget(sgetPackagePath, config.DeployOptions.SGetKeyPath, destinationFile, context.TODO()) |
| 195 | + if err != nil { |
| 196 | + message.Fatal(err, "Unable to get the remote package via sget") |
| 197 | + } |
| 198 | + |
| 199 | + return localPackagePath, tempPath.clean |
| 200 | +} |
| 201 | + |
166 | 202 | func isValidFileExtension(filename string) bool {
|
167 | 203 | for _, extension := range config.GetValidPackageExtensions() {
|
168 | 204 | if strings.HasSuffix(filename, extension) {
|
|
0 commit comments