-
Notifications
You must be signed in to change notification settings - Fork 147
/
interactive.go
114 lines (93 loc) · 4.28 KB
/
interactive.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors
// Package packager contains functions for interacting with, managing and deploying Zarf packages.
package packager
import (
"fmt"
"os"
"path/filepath"
"github.com/AlecAivazis/survey/v2"
"github.com/defenseunicorns/pkg/helpers"
"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/pkg/layout"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/pkg/utils"
"github.com/pterm/pterm"
)
func (p *Packager) confirmAction(stage string) (confirm bool) {
pterm.Println()
message.HeaderInfof("📦 PACKAGE DEFINITION")
utils.ColorPrintYAML(p.cfg.Pkg, p.getPackageYAMLHints(stage), true)
// Print any potential breaking changes (if this is a Deploy confirm) between this CLI version and the deployed init package
if stage == config.ZarfDeployStage {
if p.cfg.Pkg.IsSBOMAble() {
// Print the location that the user can view the package SBOMs from
message.HorizontalRule()
message.Title("Software Bill of Materials", "an inventory of all software contained in this package")
if len(p.sbomViewFiles) > 0 {
cwd, _ := os.Getwd()
link := pterm.FgLightCyan.Sprint(pterm.Bold.Sprint(filepath.Join(cwd, layout.SBOMDir, filepath.Base(p.sbomViewFiles[0]))))
inspect := pterm.BgBlack.Sprint(pterm.FgWhite.Sprint(pterm.Bold.Sprintf("$ zarf package inspect %s", p.cfg.PkgOpts.PackageSource)))
artifactMsg := pterm.Bold.Sprintf("%d artifacts", len(p.sbomViewFiles)) + " to be reviewed. These are"
if len(p.sbomViewFiles) == 1 {
artifactMsg = pterm.Bold.Sprintf("%d artifact", len(p.sbomViewFiles)) + " to be reviewed. This is"
}
msg := fmt.Sprintf("This package has %s available in a temporary '%s' folder in this directory and will be removed upon deployment.\n", artifactMsg, pterm.Bold.Sprint("zarf-sbom"))
viewNow := fmt.Sprintf("\n- View SBOMs %s by navigating to the '%s' folder or copying this link into a browser:\n%s", pterm.Bold.Sprint("now"), pterm.Bold.Sprint("zarf-sbom"), link)
viewLater := fmt.Sprintf("\n- View SBOMs %s deployment with this command:\n%s", pterm.Bold.Sprint("after"), inspect)
message.Note(msg)
pterm.Println(viewNow)
pterm.Println(viewLater)
} else {
message.Warn("This package does NOT contain an SBOM. If you require an SBOM, please contact the creator of this package to request a version that includes an SBOM.")
}
}
}
if len(p.warnings) > 0 {
message.HorizontalRule()
message.Title("Package Warnings", "the following warnings were flagged while reading the package")
for _, warning := range p.warnings {
message.Warn(warning)
}
}
message.HorizontalRule()
// Display prompt if not auto-confirmed
if config.CommonOptions.Confirm {
pterm.Println()
message.Successf("%s Zarf package confirmed", stage)
return config.CommonOptions.Confirm
}
prompt := &survey.Confirm{
Message: stage + " this Zarf package?",
}
pterm.Println()
// Prompt the user for confirmation, on abort return false
if err := survey.AskOne(prompt, &confirm); err != nil || !confirm {
// User aborted or declined, cancel the action
return false
}
return true
}
func (p *Packager) getPackageYAMLHints(stage string) map[string]string {
hints := map[string]string{}
if stage == config.ZarfDeployStage {
for _, variable := range p.cfg.Pkg.Variables {
value, present := p.cfg.PkgOpts.SetVariables[variable.Name]
if !present {
value = fmt.Sprintf("'%s' (default)", helpers.Truncate(variable.Default, 20, false))
} else {
value = fmt.Sprintf("'%s'", helpers.Truncate(value, 20, false))
}
if variable.Sensitive {
value = "'**sanitized**'"
}
hints = utils.AddRootListHint(hints, "name", variable.Name, fmt.Sprintf("currently set to %s", value))
}
}
hints = utils.AddRootHint(hints, "metadata", "information about this package\n")
hints = utils.AddRootHint(hints, "build", "info about the machine, zarf version, and user that created this package\n")
hints = utils.AddRootHint(hints, "components", "components selected for this operation")
hints = utils.AddRootHint(hints, "constants", "static values set by the package author")
hints = utils.AddRootHint(hints, "variables", "deployment-specific values that are set on each package deployment")
return hints
}