This commit is contained in:
Andrew Nester 2024-08-29 17:09:46 +02:00
parent 87b1c7a402
commit 9675aa7294
No known key found for this signature in database
GPG Key ID: 12BC628A44B7DA57
3 changed files with 10 additions and 6 deletions

View File

@ -22,8 +22,8 @@ func (m *prependWorkspacePrefix) Name() string {
}
var skipPrefixes = []string{
"/Workspace",
"/Volumes",
"/Workspace/",
"/Volumes/",
}
func (m *prependWorkspacePrefix) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {

View File

@ -23,24 +23,26 @@ func (m *noWorkspacePrefixUsed) Name() string {
func (m *noWorkspacePrefixUsed) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
diags := diag.Diagnostics{}
prefixes := []string{
paths := []string{
"/Workspace/${workspace.root_path}",
"/Workspace/${workspace.file_path}",
"/Workspace/${workspace.artifact_path}",
"/Workspace/${workspace.state_path}",
}
// Walk through the bundle configuration, check all the string leaves and
// see if any of the prefixes are used in the remote path.
_, err := dyn.Walk(b.Config.Value(), func(p dyn.Path, v dyn.Value) (dyn.Value, error) {
vv, ok := v.AsString()
if !ok {
return v, nil
}
for _, prefix := range prefixes {
if strings.HasPrefix(vv, prefix) {
for _, path := range paths {
if strings.Contains(vv, path) {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: fmt.Sprintf("%s used in the remote path %s. Please change to use %s instead", prefix, vv, strings.ReplaceAll(vv, "/Workspace/", "")),
Summary: fmt.Sprintf("%s used in the remote path %s. Please change to use %s instead", path, vv, strings.ReplaceAll(vv, "/Workspace/", "")),
Locations: v.Locations(),
Paths: []dyn.Path{p},
})

View File

@ -45,6 +45,8 @@ func Initialize() bundle.Mutator {
mutator.DefineDefaultWorkspacePaths(),
mutator.PrependWorkspacePrefix(),
// This mutator needs to be run before variable interpolation because it
// searches for strings with variable references in them.
validate.NoWorkspacePrefixUsed(),
mutator.SetVariables(),