-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add new cli param * Docu * Implement env-concept * Fix tests * Simplify code * Add test * Use newDiagErr() * Log used env * Test multiple labels Co-authored-by: Marcel Ludwig <marcel.ludwig@avenga.com>
- Loading branch information
Alex Schneider
and
Marcel Ludwig
authored
Jun 22, 2022
1 parent
0682420
commit 02b7652
Showing
15 changed files
with
201 additions
and
25 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,57 @@ | ||
package configload | ||
|
||
import ( | ||
"github.com/hashicorp/hcl/v2/hclsyntax" | ||
) | ||
|
||
func preprocessEnvironmentBlocks(bodies []*hclsyntax.Body, env string) error { | ||
for _, body := range bodies { | ||
if err := preprocessBody(body, env); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func preprocessBody(parent *hclsyntax.Body, env string) error { | ||
var blocks []*hclsyntax.Block | ||
|
||
for _, block := range parent.Blocks { | ||
if block.Type != environment { | ||
blocks = append(blocks, block) | ||
|
||
continue | ||
} | ||
|
||
if len(block.Labels) == 0 { | ||
defRange := block.DefRange() | ||
|
||
return newDiagErr(&defRange, "Missing label(s) for 'environment' block") | ||
} | ||
|
||
for _, label := range block.Labels { | ||
if err := validLabel(label, getRange(block.Body)); err != nil { | ||
return err | ||
} | ||
|
||
if label == env { | ||
blocks = append(blocks, block.Body.Blocks...) | ||
|
||
for name, attr := range block.Body.Attributes { | ||
parent.Attributes[name] = attr | ||
} | ||
} | ||
} | ||
} | ||
|
||
for _, block := range blocks { | ||
if err := preprocessBody(block.Body, env); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
parent.Blocks = blocks | ||
|
||
return nil | ||
} |
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
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
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
Oops, something went wrong.