forked from akuity/kargo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial scaffolding for directive validation and git-based directives
Signed-off-by: Kent Rancourt <[email protected]>
- Loading branch information
Showing
17 changed files
with
1,010 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euxo pipefail | ||
|
||
out_file=internal/directives/zz_config_types.go | ||
generated_code_warning="// Code generated by quicktype. DO NOT EDIT.\n\n" | ||
|
||
rm -rf ${out_file} | ||
|
||
quicktype \ | ||
--src-lang schema --alphabetize-properties \ | ||
--lang go --just-types-and-package --package directives --omit-empty \ | ||
-o internal/directives/zz_config_types.go \ | ||
internal/directives/schemas/*.json | ||
|
||
printf "${generated_code_warning}$(cat ${out_file})" > ${out_file} | ||
|
||
# Pointers to bools and strings don't make a lot of sense in most cases. | ||
# | ||
# Note that -i works on Linux, but not on macOS. -i '' works on macOS, but not | ||
# on Linux. So we use -i.bak, which works on both. | ||
sed -i.bak 's/\*bool/bool/g' ${out_file} | ||
sed -i.bak 's/\*string/string/g' ${out_file} | ||
rm ${out_file}.bak | ||
|
||
gofmt -w ${out_file} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package directives | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/xeipuuv/gojsonschema" | ||
) | ||
|
||
func init() { | ||
// Register the git-clone directive with the builtins registry. | ||
builtins.RegisterDirective(newGitCloneDirective()) | ||
} | ||
|
||
// gitCloneDirective is a directive that clones one or more refs from a remote | ||
// Git repository to one or more working directories. | ||
type gitCloneDirective struct { | ||
schemaLoader gojsonschema.JSONLoader | ||
} | ||
|
||
// newGitCloneDirective creates a new git-clone directive. | ||
func newGitCloneDirective() Directive { | ||
return &gitCloneDirective{ | ||
schemaLoader: getConfigSchemaLoader("git-clone"), | ||
} | ||
} | ||
|
||
// Name implements the Directive interface. | ||
func (g *gitCloneDirective) Name() string { | ||
return "git-clone" | ||
} | ||
|
||
// Run implements the Directive interface. | ||
func (g *gitCloneDirective) Run( | ||
_ context.Context, | ||
stepCtx *StepContext, | ||
) (Result, error) { | ||
// Validate the configuration against the JSON Schema | ||
if err := validate( | ||
g.schemaLoader, | ||
gojsonschema.NewGoLoader(stepCtx.Config), | ||
"git-clone", | ||
); err != nil { | ||
return ResultFailure, err | ||
} | ||
if _, err := configToStruct[GitCloneConfig](stepCtx.Config); err != nil { | ||
return ResultFailure, | ||
fmt.Errorf("could not convert config into git-clone config: %w", err) | ||
} | ||
// TODO: Add implementation here | ||
return ResultSuccess, nil | ||
} |
Oops, something went wrong.