Skip to content

Commit

Permalink
fix: import paths to avoid cycle (#2861)
Browse files Browse the repository at this point in the history
Signed-off-by: Philip Laine <philip.laine@gmail.com>
  • Loading branch information
phillebaba committed Aug 8, 2024
1 parent 9f442ce commit 7e766fd
Show file tree
Hide file tree
Showing 28 changed files with 331 additions and 384 deletions.
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module github.com/zarf-dev/zarf

go 1.22.4

replace github.com/zarf-dev/zarf/src/api => ./src/api

// TODO (@AABRO): Pending merge into github.com/gojsonschema/gojsonschema (https://github.com/gojsonschema/gojsonschema/pull/5)
replace github.com/xeipuuv/gojsonschema => github.com/defenseunicorns/gojsonschema v0.0.0-20231116163348-e00f069122d6

Expand Down Expand Up @@ -51,7 +49,6 @@ require (
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
github.com/xeipuuv/gojsonschema v1.2.0
github.com/zarf-dev/zarf/src/api v0.0.0-00010101000000-000000000000
golang.org/x/crypto v0.25.0
golang.org/x/sync v0.7.0
golang.org/x/term v0.22.0
Expand Down
28 changes: 0 additions & 28 deletions src/api/go.mod

This file was deleted.

37 changes: 0 additions & 37 deletions src/api/go.sum

This file was deleted.

15 changes: 10 additions & 5 deletions src/api/v1alpha1/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ package v1alpha1
import (
"github.com/invopop/jsonschema"
"github.com/zarf-dev/zarf/src/api/v1alpha1/extensions"
"github.com/zarf-dev/zarf/src/pkg/utils/exec"
"github.com/zarf-dev/zarf/src/pkg/variables"
)

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

// ZarfComponentAction represents a single action to run during a zarf package operation.
Expand All @@ -246,11 +244,11 @@ type ZarfComponentAction struct {
// The command to run. Must specify either cmd or wait for the action to do anything.
Cmd string `json:"cmd,omitempty"`
// (cmd only) Indicates a preference for a shell for the provided cmd to be executed in on supported operating systems.
Shell *exec.Shell `json:"shell,omitempty"`
Shell *Shell `json:"shell,omitempty"`
// [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.
DeprecatedSetVariable string `json:"setVariable,omitempty" jsonschema:"pattern=^[A-Z0-9_]+$"`
// (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.
SetVariables []variables.Variable `json:"setVariables,omitempty"`
SetVariables []Variable `json:"setVariables,omitempty"`
// Description of the action to be displayed during package execution instead of the command.
Description string `json:"description,omitempty"`
// 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.
Expand Down Expand Up @@ -331,3 +329,10 @@ func (ZarfComponentImport) JSONSchemaExtend(schema *jsonschema.Schema) {
path.Not = notSchema
url.Not = notSchema
}

// Shell represents the desired shell to use for a given command
type Shell struct {
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"`
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"`
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"`
}
82 changes: 77 additions & 5 deletions src/api/v1alpha1/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,24 @@
package v1alpha1

import (
"github.com/zarf-dev/zarf/src/pkg/variables"
"fmt"
"regexp"
)

// VariableType represents a type of a Zarf package variable
type VariableType string

const (
// RawVariableType is the default type for a Zarf package variable
RawVariableType VariableType = "raw"
// FileVariableType is a type for a Zarf package variable that loads its contents from a file
FileVariableType VariableType = "file"
)

var (
// IsUppercaseNumberUnderscore is a regex for uppercase, numbers and underscores.
// https://regex101.com/r/tfsEuZ/1
IsUppercaseNumberUnderscore = regexp.MustCompile(`^[A-Z0-9_]+$`).MatchString
)

// ZarfPackageKind is an enum of the different kinds of Zarf packages.
Expand All @@ -16,13 +33,14 @@ const (
ZarfInitConfig ZarfPackageKind = "ZarfInitConfig"
// ZarfPackageConfig is the default kind of Zarf package, primarily used during `zarf package`.
ZarfPackageConfig ZarfPackageKind = "ZarfPackageConfig"
ApiVersion string = "zarf.dev/v1alpha1"
// APIVersion the api version of this package.
APIVersion string = "zarf.dev/v1alpha1"
)

// ZarfPackage the top-level structure of a Zarf config file.
type ZarfPackage struct {
// The API version of the Zarf package.
ApiVersion string `json:"apiVersion,omitempty," jsonschema:"enum=zarf.dev/v1alpha1"`
APIVersion string `json:"apiVersion,omitempty," jsonschema:"enum=zarf.dev/v1alpha1"`
// The kind of Zarf package.
Kind ZarfPackageKind `json:"kind" jsonschema:"enum=ZarfInitConfig,enum=ZarfPackageConfig,default=ZarfPackageConfig"`
// Package metadata.
Expand All @@ -32,9 +50,9 @@ type ZarfPackage struct {
// List of components to deploy in this package.
Components []ZarfComponent `json:"components" jsonschema:"minItems=1"`
// Constant template values applied on deploy for K8s resources.
Constants []variables.Constant `json:"constants,omitempty"`
Constants []Constant `json:"constants,omitempty"`
// Variable template values applied on deploy for K8s resources.
Variables []variables.InteractiveVariable `json:"variables,omitempty"`
Variables []InteractiveVariable `json:"variables,omitempty"`
}

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

// Variable represents a variable that has a value set programmatically
type Variable struct {
// The name to be used for the variable
Name string `json:"name" jsonschema:"pattern=^[A-Z0-9_]+$"`
// Whether to mark this variable as sensitive to not print it in the log
Sensitive bool `json:"sensitive,omitempty"`
// Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_VAR_.
AutoIndent bool `json:"autoIndent,omitempty"`
// An optional regex pattern that a variable value must match before a package deployment can continue.
Pattern string `json:"pattern,omitempty"`
// 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)
Type VariableType `json:"type,omitempty" jsonschema:"enum=raw,enum=file"`
}

// InteractiveVariable is a variable that can be used to prompt a user for more information
type InteractiveVariable struct {
Variable `json:",inline"`
// A description of the variable to be used when prompting the user a value
Description string `json:"description,omitempty"`
// The default value to use for the variable
Default string `json:"default,omitempty"`
// Whether to prompt the user for input for this variable
Prompt bool `json:"prompt,omitempty"`
}

// Constant are constants that can be used to dynamically template K8s resources or run in actions.
type Constant struct {
// The name to be used for the constant
Name string `json:"name" jsonschema:"pattern=^[A-Z0-9_]+$"`
// The value to set for the constant during deploy
Value string `json:"value"`
// A description of the constant to explain its purpose on package create or deploy confirmation prompts
Description string `json:"description,omitempty"`
// Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_CONST_.
AutoIndent bool `json:"autoIndent,omitempty"`
// An optional regex pattern that a constant value must match before a package can be created.
Pattern string `json:"pattern,omitempty"`
}

// SetVariable tracks internal variables that have been set during this run of Zarf
type SetVariable struct {
Variable `json:",inline"`
// The value the variable is currently set with
Value string `json:"value"`
}

// Validate runs all validation checks on a package constant.
func (c Constant) Validate() error {
if !regexp.MustCompile(c.Pattern).MatchString(c.Value) {
return fmt.Errorf("provided value for constant %s does not match pattern %s", c.Name, c.Pattern)
}
return nil
}

// ZarfMetadata lists information about the current ZarfPackage.
type ZarfMetadata struct {
// Name to identify this Zarf package.
Expand Down
Loading

0 comments on commit 7e766fd

Please sign in to comment.