Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: unpinned resources (images/repos/files) warning on zarf prepare lint #2171

Merged
merged 224 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 215 commits
Commits
Show all changes
224 commits
Select commit Hold shift + click to select a range
9e83f8f
early WIP have an example of a yaml file being read and validated
AustinAbro321 Oct 16, 2023
1a77654
refactor
AustinAbro321 Oct 16, 2023
fb3a56e
WIP refactor
AustinAbro321 Oct 16, 2023
353ed3f
refactor validate schema to work with unmarshalled yaml
AustinAbro321 Oct 16, 2023
719bf9a
wip
AustinAbro321 Oct 16, 2023
ccf26ad
wip
AustinAbro321 Oct 17, 2023
610c088
WIP have test working with sucessful and unsuccsful example
AustinAbro321 Oct 19, 2023
db1c19a
adding bad zarf file for testing
AustinAbro321 Oct 19, 2023
faebd0a
WIP
AustinAbro321 Oct 19, 2023
8ea6213
merge
AustinAbro321 Oct 19, 2023
063c438
refactor schema unit tests
AustinAbro321 Oct 19, 2023
96efdb8
moving lint
AustinAbro321 Oct 19, 2023
6485174
WIP
AustinAbro321 Oct 19, 2023
93238ed
WIP e2e tests functional
AustinAbro321 Oct 19, 2023
ad05c6b
fix test lint
AustinAbro321 Oct 20, 2023
5b28577
lint tests working
AustinAbro321 Oct 20, 2023
bb8eaf6
adding tests, adding success mesage, taking away negative lookahead r…
AustinAbro321 Oct 24, 2023
e28be8e
add yamls for tests
AustinAbro321 Oct 24, 2023
aec9660
Merge branch 'main' into validate-schema-1667
AustinAbro321 Oct 24, 2023
e2a632d
yaml extension partially tested
AustinAbro321 Nov 1, 2023
09d1c07
moving lint back to prepare
AustinAbro321 Nov 1, 2023
9cc9d26
Merge branch 'main' into validate-schema-1667
AustinAbro321 Nov 1, 2023
61e8f60
WIP test working
AustinAbro321 Nov 6, 2023
35c8e09
lint feature is working
AustinAbro321 Nov 7, 2023
fa03f35
refactoring
AustinAbro321 Nov 7, 2023
a0c307d
adding comment to exported function
AustinAbro321 Nov 7, 2023
3376a3e
unexporting validate schema
AustinAbro321 Nov 7, 2023
73d4de8
moving lint to test 11
AustinAbro321 Nov 7, 2023
8d0a09f
Merge branch 'main' into validate-schema-1667
AustinAbro321 Nov 7, 2023
d6dc0b5
tests working
AustinAbro321 Nov 7, 2023
0d414ee
warning if someone has zarf_pkg_tmpl somewhere
AustinAbro321 Nov 7, 2023
14e9804
refactor
AustinAbro321 Nov 7, 2023
78b76f0
changing format of message
AustinAbro321 Nov 7, 2023
03ea445
fixing comment
AustinAbro321 Nov 7, 2023
ec1eb04
fix comment
AustinAbro321 Nov 7, 2023
f5f484f
comment
AustinAbro321 Nov 7, 2023
b82f857
refactor tests
AustinAbro321 Nov 7, 2023
347a8d1
refactor tests
AustinAbro321 Nov 8, 2023
fba2afe
refactor e2e, make docs and schema
AustinAbro321 Nov 8, 2023
84e82c3
refactor e2e
AustinAbro321 Nov 8, 2023
094a192
refactor to use sprintf
AustinAbro321 Nov 8, 2023
3b3aa75
exporting template var string
AustinAbro321 Nov 8, 2023
5a0028e
Merge branch 'main' into validate-schema-1667
bdw617 Nov 8, 2023
fa6ff16
moved lint into packager
AustinAbro321 Nov 8, 2023
317a809
Merge branch 'validate-schema-1667' of github.com:defenseunicorns/zar…
AustinAbro321 Nov 8, 2023
02a39b7
move 11 to 12
AustinAbro321 Nov 8, 2023
3bd8a7d
with files this time
AustinAbro321 Nov 8, 2023
5013c9f
changing to use more maintained json package
AustinAbro321 Nov 9, 2023
5b67dea
removing old jsonschema package
AustinAbro321 Nov 9, 2023
1e99845
changed language
AustinAbro321 Nov 9, 2023
94fad1c
make docs
AustinAbro321 Nov 9, 2023
b27054e
Merge branch 'main' into validate-schema-1667
AustinAbro321 Nov 9, 2023
4750a1a
refactor tests
AustinAbro321 Nov 9, 2023
167a78d
refactor func name
AustinAbro321 Nov 9, 2023
762c34e
refactor lint
AustinAbro321 Nov 9, 2023
eb2ae98
Merge branch 'main' into validate-schema-1667
AustinAbro321 Nov 13, 2023
d1aa79c
Merge branch 'main' into validate-schema-1667
Racer159 Nov 13, 2023
6d0e927
Merge branch 'validate-schema-1667' of github.com:defenseunicorns/zar…
AustinAbro321 Nov 13, 2023
c8a66e2
matching style guide better
AustinAbro321 Nov 14, 2023
f22c59a
Merge branch 'main' into validate-schema-1667
AustinAbro321 Nov 14, 2023
527c26b
removing local helm plugin so docs are correct
AustinAbro321 Nov 14, 2023
251b5e8
changing back to xeipuuv/gojsonschema
AustinAbro321 Nov 15, 2023
509e719
changing lint tests to be from yaml string rather than file
AustinAbro321 Nov 15, 2023
5a42ffa
adding validator, moving to defenseunicorns/jsonschema
AustinAbro321 Nov 16, 2023
48acf97
fix file path unit tests
AustinAbro321 Nov 16, 2023
7d695f9
moving some magic strings into types
AustinAbro321 Nov 16, 2023
1806957
fix comment
AustinAbro321 Nov 16, 2023
0db8eef
Merge branch 'main' into validate-schema-1667
AustinAbro321 Nov 16, 2023
269c118
refactoring
AustinAbro321 Nov 16, 2023
2e785cf
refactor validator
AustinAbro321 Nov 16, 2023
37f92d9
Merge branch 'main' into validate-schema-1667
Racer159 Nov 16, 2023
743ecd7
WIP introducing validator struct
AustinAbro321 Nov 17, 2023
d240e86
tests working with refactored validator, still more refactoring todo
AustinAbro321 Nov 17, 2023
a02647a
refactoring
AustinAbro321 Nov 17, 2023
a9eb84f
validator refactor
AustinAbro321 Nov 17, 2023
386e1ff
Merge branch 'validate-schema-1667' of github.com:defenseunicorns/zar…
AustinAbro321 Nov 17, 2023
50e85a0
refactoring validator
AustinAbro321 Nov 17, 2023
acbf48e
change commment
AustinAbro321 Nov 17, 2023
739aaa9
moving errors to type error
AustinAbro321 Nov 17, 2023
1dac9bc
Merge branch 'main' into validate-schema-1667
AustinAbro321 Nov 17, 2023
48eaf4b
renaming package to lint to make it easier to different object and pa…
AustinAbro321 Nov 17, 2023
6b9d3f9
moving get schema file inside of lint
AustinAbro321 Nov 17, 2023
bf58868
making warnings with numbers work with yq
AustinAbro321 Nov 17, 2023
bc4eb7b
changign validatezarfschema to return a pointer
AustinAbro321 Nov 27, 2023
ee5cce0
separating validator object into it's own file
AustinAbro321 Nov 27, 2023
bce2796
lint comment
AustinAbro321 Nov 27, 2023
0bd8d4a
implementing error in validate
AustinAbro321 Nov 27, 2023
4eb7fc1
updating zarf docs for lint
AustinAbro321 Nov 27, 2023
63bcb8c
refactoring message to use table function and printing a table for wa…
AustinAbro321 Nov 27, 2023
3106628
formmating lint table
AustinAbro321 Nov 28, 2023
7443793
exported function comment
AustinAbro321 Nov 28, 2023
515c2f2
Merge branch 'main' into validate-schema-1667
AustinAbro321 Nov 28, 2023
714ba99
exiting when there is a warning or error
AustinAbro321 Nov 28, 2023
a6c3ad7
Merge branch 'main' into validate-schema-1667
Racer159 Nov 29, 2023
5b549d2
Apply suggestions from code review
AustinAbro321 Nov 29, 2023
da445e5
fixing language to be lint
AustinAbro321 Nov 29, 2023
ca7cc1b
changing order of functions
AustinAbro321 Nov 29, 2023
3a95e03
refactor validate schema
AustinAbro321 Nov 29, 2023
37df5f7
making error strings yqable
AustinAbro321 Nov 29, 2023
47e724d
fix .(root) exit only on error now
AustinAbro321 Nov 29, 2023
8e4a723
Merge branch 'main' into validate-schema-1667
AustinAbro321 Nov 29, 2023
170938f
make docs and schema
AustinAbro321 Nov 29, 2023
140a5b8
refactor validator
AustinAbro321 Nov 29, 2023
b7a7b4c
make warning actually yq compatiable, refactor message
AustinAbro321 Nov 29, 2023
ec0a969
Merge branch 'main' into validate-schema-1667
AustinAbro321 Nov 29, 2023
e087e2d
checking for unpinned repos in lint
AustinAbro321 Nov 29, 2023
baaefff
merge
AustinAbro321 Nov 29, 2023
3a64288
unpinned images and repos
AustinAbro321 Nov 30, 2023
913a113
Merge branch 'main' into unpinned-warning-lint-2064
AustinAbro321 Nov 30, 2023
c197212
adding support for unpinned files
AustinAbro321 Nov 30, 2023
8da1d9a
update docs
AustinAbro321 Nov 30, 2023
fb20de6
update docs
AustinAbro321 Nov 30, 2023
dd2b03c
refactor isPinnedImage
AustinAbro321 Nov 30, 2023
596292a
refactor lint
AustinAbro321 Nov 30, 2023
4ec54a9
removed unnecessary comment
AustinAbro321 Nov 30, 2023
03054f2
spelling fix
AustinAbro321 Nov 30, 2023
05da414
doc changes
AustinAbro321 Nov 30, 2023
44fd930
Merge branch 'main' into unpinned-warning-lint-2064
Racer159 Nov 30, 2023
70b26ed
using transformer.parseimageref now
AustinAbro321 Nov 30, 2023
56f95ae
Update src/config/lang/english.go
AustinAbro321 Dec 4, 2023
2821adf
wip
AustinAbro321 Dec 4, 2023
5f74331
Merge branch 'unpinned-warning-lint-2064' of github.com:defenseunicor…
AustinAbro321 Dec 4, 2023
601bebf
refactor lint
AustinAbro321 Dec 4, 2023
62bf8a3
WIP, closer
AustinAbro321 Dec 5, 2023
def023d
things are working seemingly
AustinAbro321 Dec 5, 2023
e4ad437
deleting composer function
AustinAbro321 Dec 5, 2023
31a8ff2
fix color wrap
AustinAbro321 Dec 5, 2023
d6682ba
remove duplication
AustinAbro321 Dec 5, 2023
09d0132
make docs + refactor
AustinAbro321 Dec 5, 2023
f841f75
WIP, changing message output
AustinAbro321 Dec 5, 2023
f1fd856
refactor message
AustinAbro321 Dec 5, 2023
f03eb23
WIP
AustinAbro321 Dec 5, 2023
dc76d86
adding getters for node
AustinAbro321 Dec 6, 2023
603b8ca
added text for import path and changed messaging
AustinAbro321 Dec 6, 2023
e88bb30
fixed logic to allow for detection of zarf vars in component imports
AustinAbro321 Dec 6, 2023
774cad5
fix unit tests
AustinAbro321 Dec 6, 2023
14af47a
refactor tests
AustinAbro321 Dec 6, 2023
c0e96b8
refactor tests
AustinAbro321 Dec 6, 2023
f1fdee5
fix e2e tests
AustinAbro321 Dec 6, 2023
7b94f74
add test file
AustinAbro321 Dec 6, 2023
588d607
remove unnecessary comments
AustinAbro321 Dec 6, 2023
a993418
add color to yq path
AustinAbro321 Dec 6, 2023
a479e58
Merge branch 'main' into unpinned-warning-lint-2064
AustinAbro321 Dec 6, 2023
0a94706
fix merge and remove doublespaces
AustinAbro321 Dec 6, 2023
ba6e500
now getting the oci name and outtping it
AustinAbro321 Dec 6, 2023
5f370d9
fix lints
AustinAbro321 Dec 6, 2023
162f8fa
refactoring list and lint
AustinAbro321 Dec 7, 2023
bc27ab0
refactoring list and lint
AustinAbro321 Dec 7, 2023
4fc2782
changed wording, added file to lint all packages
AustinAbro321 Dec 7, 2023
e274742
Merge branch 'main' into unpinned-warning-lint-2064
AustinAbro321 Dec 7, 2023
c2e5657
removing comments
AustinAbro321 Dec 7, 2023
cb46953
change lint to not return an error on variable failure
AustinAbro321 Dec 7, 2023
b825184
refactor
AustinAbro321 Dec 7, 2023
a620c93
refactor tests
AustinAbro321 Dec 7, 2023
4cfaa3d
fix tests
AustinAbro321 Dec 7, 2023
cf9059b
mod tidy
AustinAbro321 Dec 7, 2023
8b1d34a
refactor tests
AustinAbro321 Dec 7, 2023
308f84d
lint
AustinAbro321 Dec 7, 2023
09de058
list returns nil on error + lint
AustinAbro321 Dec 7, 2023
74ac3db
moving lint all packages into hack + adding make command
AustinAbro321 Dec 7, 2023
82913ff
Update src/pkg/packager/variables.go
AustinAbro321 Dec 7, 2023
1a46639
remove unneeded code
AustinAbro321 Dec 7, 2023
6b810aa
Update src/pkg/packager/composer/list.go
AustinAbro321 Dec 7, 2023
3ac81c5
super ugly wip and testing things out
AustinAbro321 Dec 8, 2023
7f4c878
Merge branch 'unpinned-warning-lint-2064' of github.com:defenseunicor…
AustinAbro321 Dec 8, 2023
8a93bb3
WIP, things working somewhat
AustinAbro321 Dec 8, 2023
02b5eb8
separating tables mostly working
AustinAbro321 Dec 8, 2023
63ee08b
refactoring
AustinAbro321 Dec 8, 2023
a58eac8
have unset var message for all packages
AustinAbro321 Dec 8, 2023
eacd341
refactor to further use packagekey
AustinAbro321 Dec 8, 2023
1862ad5
additional paths on broken imports, refactors
AustinAbro321 Dec 11, 2023
9d750cb
lint, removing duplicate findings, and fixing package path
AustinAbro321 Dec 11, 2023
208ed8e
fix lint script
AustinAbro321 Dec 11, 2023
47c2a4b
Apply suggestions from code review
AustinAbro321 Dec 11, 2023
60bf504
suggestions
AustinAbro321 Dec 11, 2023
0b7fd71
refactor
AustinAbro321 Dec 11, 2023
4cc3bf2
refactor
AustinAbro321 Dec 11, 2023
516b1a4
no longer linting base and downstream components separtely
AustinAbro321 Dec 11, 2023
fea98bb
add tests for lint composable components
AustinAbro321 Dec 12, 2023
9a59551
add additional test
AustinAbro321 Dec 12, 2023
22a1b9c
adding test to files
AustinAbro321 Dec 12, 2023
08f2076
adding test to transform parse image
AustinAbro321 Dec 12, 2023
6d88659
fix weird helper code
AustinAbro321 Dec 12, 2023
49bcd5b
Keeping relative paths for lint
AustinAbro321 Dec 12, 2023
11d9d41
moving color wrap to message
AustinAbro321 Dec 12, 2023
8026621
moving random to helpers
AustinAbro321 Dec 12, 2023
5c96525
update e2e
AustinAbro321 Dec 12, 2023
8a17413
refactor tests
AustinAbro321 Dec 12, 2023
363ef42
changing lint all script to use one binary
AustinAbro321 Dec 12, 2023
396a69e
refactoring to use node and not use packagekey
AustinAbro321 Dec 12, 2023
10bdff2
removing new node
AustinAbro321 Dec 12, 2023
e6eefad
method renaem
AustinAbro321 Dec 12, 2023
ec9cb25
merge
AustinAbro321 Dec 12, 2023
7165595
make docs and schema
AustinAbro321 Dec 12, 2023
4f7fc77
Apply suggestions from code review
AustinAbro321 Dec 13, 2023
b1e8ebe
clean up
AustinAbro321 Dec 13, 2023
0884591
changing how errors are sent through in zarf state
AustinAbro321 Dec 13, 2023
4a10df8
added comment
AustinAbro321 Dec 13, 2023
ec64dbc
build correct package in make file
AustinAbro321 Dec 13, 2023
27d41d5
fixing windows tests
AustinAbro321 Dec 13, 2023
a35c83c
fixing windows tests
AustinAbro321 Dec 13, 2023
4291ecc
fixing windows tests
AustinAbro321 Dec 13, 2023
8d347f9
fixing windows tests
AustinAbro321 Dec 13, 2023
558980a
refactor and renames
AustinAbro321 Dec 13, 2023
fa99700
fix windows tests
AustinAbro321 Dec 13, 2023
7cf1bc7
Merge branch 'main' into unpinned-warning-lint-2064
AustinAbro321 Dec 14, 2023
078b9a8
merge main
AustinAbro321 Dec 15, 2023
b417449
make docs and schema
AustinAbro321 Dec 15, 2023
cd807d7
rename var, dry cmds
AustinAbro321 Dec 15, 2023
c796ffc
var rename
AustinAbro321 Dec 15, 2023
dafa68d
lint
AustinAbro321 Dec 15, 2023
4d77c22
changign lang var name, refactoring / separating out var names
AustinAbro321 Dec 15, 2023
12e31fa
renames
AustinAbro321 Dec 15, 2023
42aa2ce
Merge branch 'main' into unpinned-warning-lint-2064
Racer159 Dec 15, 2023
3364824
Merge branch 'main' into unpinned-warning-lint-2064
Racer159 Dec 16, 2023
1479cc8
moving cmds to dev over lint
AustinAbro321 Dec 18, 2023
deb0fa3
Update Makefile
AustinAbro321 Dec 18, 2023
9473c25
Update src/pkg/packager/composer/list.go
AustinAbro321 Dec 18, 2023
be35e72
refactor name
AustinAbro321 Dec 18, 2023
8702613
making remotes deterministic
AustinAbro321 Dec 18, 2023
4c08da8
Update hack/lint_all_zarf_packages.sh
AustinAbro321 Dec 18, 2023
b698421
Update hack/lint_all_zarf_packages.sh
AustinAbro321 Dec 18, 2023
44eebde
Merge branch 'unpinned-warning-lint-2064' of github.com:defenseunicor…
AustinAbro321 Dec 18, 2023
3a9f65d
defaulting to build in make file
AustinAbro321 Dec 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ KEY ?= ""

# Figure out which Zarf binary we should use based on the operating system we are on
ZARF_BIN := ./build/zarf
BUILD_CLI_FOR_SYSTEM := build-cli-linux-amd
ifeq ($(OS),Windows_NT)
ZARF_BIN := $(addsuffix .exe,$(ZARF_BIN))
BUILD_CLI_FOR_SYSTEM := build-cli-windows-amd
else
UNAME_S := $(shell uname -s)
UNAME_P := $(shell uname -p)
Expand All @@ -19,9 +21,11 @@ else
endif
ifeq ($(UNAME_P),i386)
ZARF_BIN := $(addsuffix -intel,$(ZARF_BIN))
BUILD_CLI_FOR_SYSTEM = build-cli-mac-intel
endif
ifeq ($(UNAME_P),arm)
ZARF_BIN := $(addsuffix -apple,$(ZARF_BIN))
BUILD_CLI_FOR_SYSTEM = build-cli-mac-apple
endif
endif
endif
Expand All @@ -48,8 +52,8 @@ BUILD_ARGS += -X k8s.io/component-base/version.buildDate=$(BUILD_DATE)
.PHONY: help
help: ## Display this help information
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| sort | awk 'BEGIN {FS = ":.*?## "}; \
{printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
| sort | awk 'BEGIN {FS = ":.*?## "}; \
{printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

clean: ## Clean the build directory
rm -rf build
Expand Down Expand Up @@ -85,10 +89,16 @@ build-cli-linux: build-cli-linux-amd build-cli-linux-arm ## Build the Zarf CLI f

build-cli: build-cli-linux-amd build-cli-linux-arm build-cli-mac-intel build-cli-mac-apple build-cli-windows-amd build-cli-windows-arm ## Build the CLI

build-cli-for-system:
$(MAKE) $(BUILD_CLI_FOR_SYSTEM)
AustinAbro321 marked this conversation as resolved.
Show resolved Hide resolved

docs-and-schema: ## Generate the Zarf Documentation and Schema
hack/gen-cli-docs.sh
ZARF_CONFIG=hack/empty-config.toml hack/create-zarf-schema.sh

lint-packages-and-examples: build-cli-for-system ## Recurisvely lint all zarf.yaml files in the repo except for those dedicated to tests
lucasrod16 marked this conversation as resolved.
Show resolved Hide resolved
AustinAbro321 marked this conversation as resolved.
Show resolved Hide resolved
hack/lint_all_zarf_packages.sh $(ZARF_BIN)

# INTERNAL: a shim used to build the agent image only if needed on Windows using the `test` command
init-package-local-agent:
@test "$(AGENT_IMAGE_TAG)" != "local" || $(MAKE) build-local-agent-image
Expand Down
2 changes: 1 addition & 1 deletion docs/2-the-zarf-cli/100-cli-commands/zarf_dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Commands useful for developing packages
* [zarf dev deploy](zarf_dev_deploy.md) - [beta] Creates and deploys a Zarf package from a given directory
* [zarf dev find-images](zarf_dev_find-images.md) - Evaluates components in a Zarf file to identify images specified in their helm charts and manifests
* [zarf dev generate-config](zarf_dev_generate-config.md) - Generates a config file for Zarf
* [zarf dev lint](zarf_dev_lint.md) - Verifies the package schema
* [zarf dev lint](zarf_dev_lint.md) - Lints the given package for valid schema and recommended practices
* [zarf dev patch-git](zarf_dev_patch-git.md) - Converts all .git URLs to the specified Zarf HOST and with the Zarf URL pattern in a given FILE. NOTE:
This should only be used for manifests that are not mutated by the Zarf Agent Mutating Webhook.
* [zarf dev sha256sum](zarf_dev_sha256sum.md) - Generates a SHA256SUM for the given file
8 changes: 5 additions & 3 deletions docs/2-the-zarf-cli/100-cli-commands/zarf_dev_lint.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# zarf dev lint
<!-- Auto-generated by hack/gen-cli-docs.sh -->

Verifies the package schema
Lints the given package for valid schema and recommended practices

## Synopsis

Verifies the package schema and warns the user if they have variables that won't be evaluated
Verifies the package schema, checks if any variables won't be evaluated, and checks for unpinned images/repos/files

```
zarf dev lint [ DIRECTORY ] [flags]
Expand All @@ -14,7 +14,9 @@ zarf dev lint [ DIRECTORY ] [flags]
## Options

```
-h, --help help for lint
-f, --flavor string The flavor of components to include in the resulting package (i.e. have a matching or empty "only.flavor" key)
-h, --help help for lint
--set stringToString Specify package variables to set on the command line (KEY=value) (default [])
```

## Options inherited from parent commands
Expand Down
17 changes: 17 additions & 0 deletions hack/lint_all_zarf_packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

ZARF_BIN=$1
LINT_SRC_TEST=$2
SCRIPT=$(realpath "$0")
SCRIPTPATH=$(dirname "$SCRIPT")
cd $SCRIPTPATH
AustinAbro321 marked this conversation as resolved.
Show resolved Hide resolved
cd ..
find "." -type f -name 'zarf.yaml' | while read -r yaml_file; do
dir=$(dirname "$yaml_file")
if [[ "$dir" == *src/test/* ]] && [ "$LINT_SRC_TEST" != true ]; then
continue
fi
echo "Running 'zarf prepare lint' in directory: $dir"
$ZARF_BIN prepare lint $dir
AustinAbro321 marked this conversation as resolved.
Show resolved Hide resolved
echo "---"
done
18 changes: 18 additions & 0 deletions src/cmd/common/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors

// Package common handles command configuration across all commands
package common

import (
"github.com/defenseunicorns/zarf/src/types"
)

// SetBaseDirectory sets base directory on package config when given in args
func SetBaseDirectory(args []string, pkgConfig *types.PackagerConfig) {
AustinAbro321 marked this conversation as resolved.
Show resolved Hide resolved
if len(args) > 0 {
pkgConfig.CreateOpts.BaseDir = args[0]
} else {
pkgConfig.CreateOpts.BaseDir = "."
}
}
44 changes: 12 additions & 32 deletions src/cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,9 @@ var devDeployCmd = &cobra.Command{
Use: "deploy",
Args: cobra.MaximumNArgs(1),
Short: lang.CmdDevDeployShort,
Long: lang.CmdDevDeployLong,
Long: lang.CmdDevDeployLong,
Run: func(cmd *cobra.Command, args []string) {
if len(args) > 0 {
pkgConfig.CreateOpts.BaseDir = args[0]
} else {
var err error
pkgConfig.CreateOpts.BaseDir, err = os.Getwd()
if err != nil {
message.Fatalf(err, lang.CmdPackageCreateErr, err.Error())
}
}
common.SetBaseDirectory(args, &pkgConfig)

v := common.GetViper()
pkgConfig.CreateOpts.SetVariables = helpers.TransformAndMergeMap(
Expand Down Expand Up @@ -194,15 +186,7 @@ var devFindImagesCmd = &cobra.Command{
Long: lang.CmdPrepareFindImagesLong,
Run: func(cmd *cobra.Command, args []string) {
// If a directory was provided, use that as the base directory
if len(args) > 0 {
pkgConfig.CreateOpts.BaseDir = args[0]
} else {
cwd, err := os.Getwd()
if err != nil {
message.Fatalf(err, lang.CmdPrepareFindImagesErr, err.Error())
}
pkgConfig.CreateOpts.BaseDir = cwd
}
common.SetBaseDirectory(args, &pkgConfig)

// Ensure uppercase keys from viper
v := common.GetViper()
Expand Down Expand Up @@ -245,20 +229,14 @@ var devLintCmd = &cobra.Command{
Use: "lint [ DIRECTORY ]",
Args: cobra.MaximumNArgs(1),
Aliases: []string{"l"},
Short: lang.CmdPrepareLintShort,
Long: lang.CmdPrepareLintLong,
Short: lang.CmdDevLintShort,
Long: lang.CmdDevLintLong,
Run: func(cmd *cobra.Command, args []string) {
baseDir := ""
if len(args) > 0 {
baseDir = args[0]
} else {
var err error
baseDir, err = os.Getwd()
if err != nil {
message.Fatalf(err, lang.CmdPrepareLintErr, err.Error())
}
}
validator, err := lint.ValidateZarfSchema(baseDir)
common.SetBaseDirectory(args, &pkgConfig)
v := common.GetViper()
pkgConfig.CreateOpts.SetVariables = helpers.TransformAndMergeMap(
v.GetStringMapString(common.VPkgCreateSet), pkgConfig.CreateOpts.SetVariables, strings.ToUpper)
validator, err := lint.Validate(pkgConfig.CreateOpts)
if err != nil {
message.Fatal(err, err.Error())
}
Expand Down Expand Up @@ -290,6 +268,8 @@ func init() {
// allow for the override of the default helm KubeVersion
devFindImagesCmd.Flags().StringVar(&pkgConfig.FindImagesOpts.KubeVersionOverride, "kube-version", "", lang.CmdPrepareFlagKubeVersion)

devLintCmd.Flags().StringToStringVar(&pkgConfig.CreateOpts.SetVariables, "set", v.GetStringMapString(common.VPkgCreateSet), lang.CmdPackageCreateFlagSet)
devLintCmd.Flags().StringVarP(&pkgConfig.CreateOpts.Flavor, "flavor", "f", v.GetString(common.VPkgCreateFlavor), lang.CmdPackageCreateFlagFlavor)
devTransformGitLinksCmd.Flags().StringVar(&pkgConfig.InitOpts.GitServer.PushUsername, "git-account", config.ZarfGitPushUser, lang.CmdPrepareFlagGitAccount)
}

Expand Down
13 changes: 1 addition & 12 deletions src/cmd/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package cmd

import (
"fmt"
"os"
"path/filepath"
"regexp"
"strings"
Expand Down Expand Up @@ -41,17 +40,7 @@ var packageCreateCmd = &cobra.Command{
Short: lang.CmdPackageCreateShort,
Long: lang.CmdPackageCreateLong,
Run: func(cmd *cobra.Command, args []string) {

// If a directory was provided, use that as the base directory
if len(args) > 0 {
pkgConfig.CreateOpts.BaseDir = args[0]
} else {
var err error
pkgConfig.CreateOpts.BaseDir, err = os.Getwd()
if err != nil {
message.Fatalf(err, lang.CmdPackageCreateErr, err.Error())
}
}
common.SetBaseDirectory(args, &pkgConfig)

var isCleanPathRegex = regexp.MustCompile(`^[a-zA-Z0-9\_\-\/\.\~\\:]+$`)
if !isCleanPathRegex.MatchString(config.CommonOptions.CachePath) {
Expand Down
6 changes: 4 additions & 2 deletions src/cmd/tools/zarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ var updateCredsCmd = &cobra.Command{
// If no distro the zarf secret did not load properly
message.Fatalf(nil, lang.ErrLoadState)
}

newState := c.MergeZarfState(oldState, updateCredsInitOpts, args)
var newState *types.ZarfState
if newState, err = c.MergeZarfState(oldState, updateCredsInitOpts, args); err != nil {
message.Fatal(err, lang.CmdToolsUpdateCredsUnableUpdateCreds)
}

message.PrintCredentialUpdates(oldState, newState, args)

Expand Down
43 changes: 25 additions & 18 deletions src/config/lang/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,26 @@ import "errors"
// Debug messages will not be a part of the language strings since they are not intended to be user facing
// Include sprintf formatting directives in the string if needed.
const (
ErrLoadState = "Failed to load the Zarf State from the cluster."
ErrSaveState = "Failed to save the Zarf State to the cluster."
ErrLoadPackageSecret = "Failed to load %s's secret from the cluster"
ErrNoClusterConnection = "Failed to connect to the cluster."
ErrTunnelFailed = "Failed to create a tunnel to the cluster."
ErrUnmarshal = "failed to unmarshal file: %w"
ErrWritingFile = "failed to write file %s: %s"
ErrDownloading = "failed to download %s: %s"
ErrCreatingDir = "failed to create directory %s: %s"
ErrRemoveFile = "failed to remove file %s: %s"
ErrUnarchive = "failed to unarchive %s: %s"
ErrConfirmCancel = "confirm selection canceled: %s"
ErrFileExtract = "failed to extract filename %s from archive %s: %s"
ErrFileNameExtract = "failed to extract filename from URL %s: %s"
ErrLoadState = "Failed to load the Zarf State from the cluster."
ErrSaveState = "Failed to save the Zarf State to the cluster."
ErrLoadPackageSecret = "Failed to load %s's secret from the cluster"
ErrNoClusterConnection = "Failed to connect to the cluster."
ErrTunnelFailed = "Failed to create a tunnel to the cluster."
ErrUnmarshal = "failed to unmarshal file: %w"
ErrWritingFile = "failed to write file %s: %s"
ErrDownloading = "failed to download %s: %s"
ErrCreatingDir = "failed to create directory %s: %s"
ErrRemoveFile = "failed to remove file %s: %s"
ErrUnarchive = "failed to unarchive %s: %s"
ErrConfirmCancel = "confirm selection canceled: %s"
ErrFileExtract = "failed to extract filename %s from archive %s: %s"
ErrFileNameExtract = "failed to extract filename from URL %s: %s"
ErrUnableToGenerateRandomSecret = "unable to generate a random secret"
)

// Lint messages
const (
UnsetVarLintWarning = "There are templates that are not set and won't be evaluated during lint"
)

// Zarf CLI commands.
Expand Down Expand Up @@ -365,9 +371,9 @@ $ zarf package publish ./path/to/dir oci://my-registry.com/my-namespace
CmdPrepareFlagGitAccount = "User or organization name for the git account that the repos are created under."
CmdPrepareFlagKubeVersion = "Override the default helm template KubeVersion when performing a package chart template"
AustinAbro321 marked this conversation as resolved.
Show resolved Hide resolved

CmdPrepareLintShort = "Verifies the package schema"
CmdPrepareLintLong = "Verifies the package schema and warns the user if they have variables that won't be evaluated"
CmdPrepareLintErr = "Unable to lint package: %s"
CmdDevLintShort = "Lints the given package for valid schema and recommended practices"
CmdDevLintLong = "Verifies the package schema, checks if any variables won't be evaluated, and checks for unpinned images/repos/files"
CmdDevLintErr = "Unable to lint package: %s"

// zarf tools
CmdToolsShort = "Collection of additional tools to make airgap easier"
Expand Down Expand Up @@ -563,6 +569,7 @@ $ zarf tools update-creds artifact --artifact-push-username={USERNAME} --artifac
CmdToolsUpdateCredsUnableUpdateRegistry = "Unable to update Zarf Registry values: %s"
CmdToolsUpdateCredsUnableUpdateGit = "Unable to update Zarf Git Server values: %s"
CmdToolsUpdateCredsUnableUpdateAgent = "Unable to update Zarf Agent TLS secrets: %s"
CmdToolsUpdateCredsUnableUpdateCreds = "Unable to update Zarf credentials"

// zarf version
CmdVersionShort = "Shows the version of the running Zarf binary"
Expand Down Expand Up @@ -604,7 +611,7 @@ const (

// src/internal/packager/validate.
const (
PkgValidateTemplateDeprecation = "Package template %q is using the deprecated syntax ###ZARF_PKG_VAR_%s###. This will be removed in Zarf v1.0.0. Please update to ###ZARF_PKG_TMPL_%s###."
PkgValidateTemplateDeprecation = "Package template %q is using the deprecated syntax ###ZARF_PKG_VAR_%s###. This will be removed in Zarf v1.0.0. Please update to ###ZARF_PKG_TMPL_%s###."
PkgValidateMustBeUppercase = "variable name %q must be all uppercase and contain no special characters except _"
PkgValidateErrAction = "invalid action: %w"
PkgValidateErrActionVariables = "component %q cannot contain setVariables outside of onDeploy in actions"
Expand Down
Loading
Loading