Skip to content

Commit 7e766fd

Browse files
authored
fix: import paths to avoid cycle (#2861)
Signed-off-by: Philip Laine <[email protected]>
1 parent 9f442ce commit 7e766fd

28 files changed

+331
-384
lines changed

go.mod

-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ module github.com/zarf-dev/zarf
22

33
go 1.22.4
44

5-
replace github.com/zarf-dev/zarf/src/api => ./src/api
6-
75
// TODO (@AABRO): Pending merge into github.com/gojsonschema/gojsonschema (https://github.com/gojsonschema/gojsonschema/pull/5)
86
replace github.com/xeipuuv/gojsonschema => github.com/defenseunicorns/gojsonschema v0.0.0-20231116163348-e00f069122d6
97

@@ -51,7 +49,6 @@ require (
5149
github.com/spf13/viper v1.19.0
5250
github.com/stretchr/testify v1.9.0
5351
github.com/xeipuuv/gojsonschema v1.2.0
54-
github.com/zarf-dev/zarf/src/api v0.0.0-00010101000000-000000000000
5552
golang.org/x/crypto v0.25.0
5653
golang.org/x/sync v0.7.0
5754
golang.org/x/term v0.22.0

src/api/go.mod

-28
This file was deleted.

src/api/go.sum

-37
This file was deleted.

src/api/v1alpha1/component.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ package v1alpha1
77
import (
88
"github.com/invopop/jsonschema"
99
"github.com/zarf-dev/zarf/src/api/v1alpha1/extensions"
10-
"github.com/zarf-dev/zarf/src/pkg/utils/exec"
11-
"github.com/zarf-dev/zarf/src/pkg/variables"
1210
)
1311

1412
// ZarfComponent is the primary functional grouping of assets to deploy by Zarf.
@@ -228,7 +226,7 @@ type ZarfComponentActionDefaults struct {
228226
// Additional environment variables for commands.
229227
Env []string `json:"env,omitempty"`
230228
// (cmd only) Indicates a preference for a shell for the provided cmd to be executed in on supported operating systems.
231-
Shell exec.Shell `json:"shell,omitempty"`
229+
Shell Shell `json:"shell,omitempty"`
232230
}
233231

234232
// ZarfComponentAction represents a single action to run during a zarf package operation.
@@ -246,11 +244,11 @@ type ZarfComponentAction struct {
246244
// The command to run. Must specify either cmd or wait for the action to do anything.
247245
Cmd string `json:"cmd,omitempty"`
248246
// (cmd only) Indicates a preference for a shell for the provided cmd to be executed in on supported operating systems.
249-
Shell *exec.Shell `json:"shell,omitempty"`
247+
Shell *Shell `json:"shell,omitempty"`
250248
// [Deprecated] (replaced by setVariables) (onDeploy/cmd only) The name of a variable to update with the output of the command. This variable will be available to all remaining actions and components in the package. This will be removed in Zarf v1.0.0.
251249
DeprecatedSetVariable string `json:"setVariable,omitempty" jsonschema:"pattern=^[A-Z0-9_]+$"`
252250
// (onDeploy/cmd only) An array of variables to update with the output of the command. These variables will be available to all remaining actions and components in the package.
253-
SetVariables []variables.Variable `json:"setVariables,omitempty"`
251+
SetVariables []Variable `json:"setVariables,omitempty"`
254252
// Description of the action to be displayed during package execution instead of the command.
255253
Description string `json:"description,omitempty"`
256254
// Wait for a condition to be met before continuing. Must specify either cmd or wait for the action. See the 'zarf tools wait-for' command for more info.
@@ -331,3 +329,10 @@ func (ZarfComponentImport) JSONSchemaExtend(schema *jsonschema.Schema) {
331329
path.Not = notSchema
332330
url.Not = notSchema
333331
}
332+
333+
// Shell represents the desired shell to use for a given command
334+
type Shell struct {
335+
Windows string `json:"windows,omitempty" jsonschema:"description=(default 'powershell') Indicates a preference for the shell to use on Windows systems (note that choosing 'cmd' will turn off migrations like touch -> New-Item),example=powershell,example=cmd,example=pwsh,example=sh,example=bash,example=gsh"`
336+
Linux string `json:"linux,omitempty" jsonschema:"description=(default 'sh') Indicates a preference for the shell to use on Linux systems,example=sh,example=bash,example=fish,example=zsh,example=pwsh"`
337+
Darwin string `json:"darwin,omitempty" jsonschema:"description=(default 'sh') Indicates a preference for the shell to use on macOS systems,example=sh,example=bash,example=fish,example=zsh,example=pwsh"`
338+
}

src/api/v1alpha1/package.go

+77-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,24 @@
55
package v1alpha1
66

77
import (
8-
"github.com/zarf-dev/zarf/src/pkg/variables"
8+
"fmt"
9+
"regexp"
10+
)
11+
12+
// VariableType represents a type of a Zarf package variable
13+
type VariableType string
14+
15+
const (
16+
// RawVariableType is the default type for a Zarf package variable
17+
RawVariableType VariableType = "raw"
18+
// FileVariableType is a type for a Zarf package variable that loads its contents from a file
19+
FileVariableType VariableType = "file"
20+
)
21+
22+
var (
23+
// IsUppercaseNumberUnderscore is a regex for uppercase, numbers and underscores.
24+
// https://regex101.com/r/tfsEuZ/1
25+
IsUppercaseNumberUnderscore = regexp.MustCompile(`^[A-Z0-9_]+$`).MatchString
926
)
1027

1128
// ZarfPackageKind is an enum of the different kinds of Zarf packages.
@@ -16,13 +33,14 @@ const (
1633
ZarfInitConfig ZarfPackageKind = "ZarfInitConfig"
1734
// ZarfPackageConfig is the default kind of Zarf package, primarily used during `zarf package`.
1835
ZarfPackageConfig ZarfPackageKind = "ZarfPackageConfig"
19-
ApiVersion string = "zarf.dev/v1alpha1"
36+
// APIVersion the api version of this package.
37+
APIVersion string = "zarf.dev/v1alpha1"
2038
)
2139

2240
// ZarfPackage the top-level structure of a Zarf config file.
2341
type ZarfPackage struct {
2442
// The API version of the Zarf package.
25-
ApiVersion string `json:"apiVersion,omitempty," jsonschema:"enum=zarf.dev/v1alpha1"`
43+
APIVersion string `json:"apiVersion,omitempty," jsonschema:"enum=zarf.dev/v1alpha1"`
2644
// The kind of Zarf package.
2745
Kind ZarfPackageKind `json:"kind" jsonschema:"enum=ZarfInitConfig,enum=ZarfPackageConfig,default=ZarfPackageConfig"`
2846
// Package metadata.
@@ -32,9 +50,9 @@ type ZarfPackage struct {
3250
// List of components to deploy in this package.
3351
Components []ZarfComponent `json:"components" jsonschema:"minItems=1"`
3452
// Constant template values applied on deploy for K8s resources.
35-
Constants []variables.Constant `json:"constants,omitempty"`
53+
Constants []Constant `json:"constants,omitempty"`
3654
// Variable template values applied on deploy for K8s resources.
37-
Variables []variables.InteractiveVariable `json:"variables,omitempty"`
55+
Variables []InteractiveVariable `json:"variables,omitempty"`
3856
}
3957

4058
// IsInitConfig returns whether a Zarf package is an init config.
@@ -62,6 +80,60 @@ func (pkg ZarfPackage) IsSBOMAble() bool {
6280
return false
6381
}
6482

83+
// Variable represents a variable that has a value set programmatically
84+
type Variable struct {
85+
// The name to be used for the variable
86+
Name string `json:"name" jsonschema:"pattern=^[A-Z0-9_]+$"`
87+
// Whether to mark this variable as sensitive to not print it in the log
88+
Sensitive bool `json:"sensitive,omitempty"`
89+
// Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_VAR_.
90+
AutoIndent bool `json:"autoIndent,omitempty"`
91+
// An optional regex pattern that a variable value must match before a package deployment can continue.
92+
Pattern string `json:"pattern,omitempty"`
93+
// Changes the handling of a variable to load contents differently (i.e. from a file rather than as a raw variable - templated files should be kept below 1 MiB)
94+
Type VariableType `json:"type,omitempty" jsonschema:"enum=raw,enum=file"`
95+
}
96+
97+
// InteractiveVariable is a variable that can be used to prompt a user for more information
98+
type InteractiveVariable struct {
99+
Variable `json:",inline"`
100+
// A description of the variable to be used when prompting the user a value
101+
Description string `json:"description,omitempty"`
102+
// The default value to use for the variable
103+
Default string `json:"default,omitempty"`
104+
// Whether to prompt the user for input for this variable
105+
Prompt bool `json:"prompt,omitempty"`
106+
}
107+
108+
// Constant are constants that can be used to dynamically template K8s resources or run in actions.
109+
type Constant struct {
110+
// The name to be used for the constant
111+
Name string `json:"name" jsonschema:"pattern=^[A-Z0-9_]+$"`
112+
// The value to set for the constant during deploy
113+
Value string `json:"value"`
114+
// A description of the constant to explain its purpose on package create or deploy confirmation prompts
115+
Description string `json:"description,omitempty"`
116+
// Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_CONST_.
117+
AutoIndent bool `json:"autoIndent,omitempty"`
118+
// An optional regex pattern that a constant value must match before a package can be created.
119+
Pattern string `json:"pattern,omitempty"`
120+
}
121+
122+
// SetVariable tracks internal variables that have been set during this run of Zarf
123+
type SetVariable struct {
124+
Variable `json:",inline"`
125+
// The value the variable is currently set with
126+
Value string `json:"value"`
127+
}
128+
129+
// Validate runs all validation checks on a package constant.
130+
func (c Constant) Validate() error {
131+
if !regexp.MustCompile(c.Pattern).MatchString(c.Value) {
132+
return fmt.Errorf("provided value for constant %s does not match pattern %s", c.Name, c.Pattern)
133+
}
134+
return nil
135+
}
136+
65137
// ZarfMetadata lists information about the current ZarfPackage.
66138
type ZarfMetadata struct {
67139
// Name to identify this Zarf package.

0 commit comments

Comments
 (0)