-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
111 changed files
with
13,222 additions
and
87 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -79,6 +79,9 @@ Contents: | |
- [(( contains(list, "foobar") ))](#-containslist-foobar-) | ||
- [(( index(list, "foobar") ))](#-indexlist-foobar-) | ||
- [(( lastindex(list, "foobar") ))](#-lastindexlist-foobar-) | ||
- [(( basename(path) ))](#-basenamepath-) | ||
- [(( dirname(path) ))](#-dirnamepath-) | ||
- [(( parseurl("http://github.com") ))](#-parseurlhttpgithubcom-) | ||
- [(( sort(list) ))](#-sortlist-) | ||
- [(( replace(string, "foo", "bar") ))](#-replacestring-foo-bar-) | ||
- [(( substr(string, 1, 3) ))](#-substrstring-1-3-) | ||
|
@@ -303,6 +306,13 @@ value of a map or an entry in a list. The expression might span multiple | |
lines. In any case the yaml string value *must not* end with a newline | ||
(for example using `|-`) | ||
|
||
If a parenthesized value should not be interpreted as an *dynaml* expression and | ||
kept as it is in the output, it can be escaped by an exclamation mark directly | ||
after the openeing brackets. | ||
|
||
For example, `((! .field ))` maps to the string value `(( .field ))` and | ||
`((!! .field ))` maps to the string value `((! .field ))`. | ||
|
||
The following is a complete list of dynaml expressions: | ||
|
||
|
||
|
@@ -703,11 +713,6 @@ If the corresponding value is not defined, it will return nil. This then has the | |
same semantics as reference expressions; a nil merge is an unresolved template. | ||
See [`||`](#-a--b-). | ||
|
||
**Note**: Instead of using a `<<:` insert field to place merge expressions it is | ||
possible now to use `<<<:`, also, which allows to use regular yaml parsers for | ||
spiff-like yaml documents. `<<:` is kept for backward compatibility. | ||
|
||
|
||
### `<<: (( merge ))` | ||
|
||
Merging of maps or lists with the content of the same element found in some stub. | ||
|
@@ -720,8 +725,18 @@ require content in at least one stub (as always for the merge operator). Now thi | |
is evaluated correctly, but this would break existing manifest template sets, which use the | ||
first variant, but mean the second. Therfore this case is explicitly handled to describe an | ||
optional merge. If really a required merge is meant an additional explicit qualifier has to | ||
|
||
**Note**: Instead of using a `<<:` insert field to place merge expressions it is | ||
possible now to use `<<<:`, also, which allows to use regular yaml parsers for | ||
spiff-like yaml documents. `<<:` is kept for backward compatibility. | ||
be used (`(( merge required ))`). | ||
|
||
If the merge key should not be interpreted as regular key instead of a merge | ||
directive, it can be escaped by an excalamtion mark (`!`). | ||
|
||
For example, a map key `<<<!` will result in a string key `<<<` and `<<<!!` | ||
will result in a string key `<<<!` | ||
|
||
#### Merging maps | ||
|
||
**values.yml** | ||
|
@@ -1465,6 +1480,75 @@ contains: (( contains("foobar", "bar") )) | |
|
||
yields `true`. | ||
|
||
### `(( basename(path) ))` | ||
|
||
The function `basename` returns the name of the last element of a path. | ||
The argument may either be a regular path name or a URL. | ||
|
||
e.g.: | ||
|
||
```yaml | ||
pathbase: (( basename("alice/bob") )) | ||
urlbase: (( basename("http://foobar/alice/bob?any=parameter") )) | ||
``` | ||
|
||
yields: | ||
|
||
```yaml | ||
pathbase: bob | ||
urlbase: bob | ||
``` | ||
|
||
### `(( dirname(path) ))` | ||
|
||
The function `dirname` returns the parent directory of a path. | ||
The argument may either be a regular path name or a URL. | ||
|
||
e.g.: | ||
|
||
```yaml | ||
pathbase: (( dirname("alice/bob") )) | ||
urlbase: (( dirname("http://foobar/alice/bob?any=parameter") )) | ||
``` | ||
|
||
yields: | ||
|
||
```yaml | ||
pathbase: alice | ||
urlbase: /alice | ||
``` | ||
|
||
### `(( parseurl("http://github.com") ))` | ||
|
||
This function parses a URL and yield a map with all elements of an URL. | ||
The fields `port`, `userinfo`and `password` are optional. | ||
|
||
e.g.: | ||
|
||
```yaml | ||
url: (( parseurl("https://user:[email protected]:443/mandelsoft/spiff?branch=master&tag=v1#anchor") )) | ||
``` | ||
|
||
yields: | ||
|
||
```yaml | ||
url: | ||
scheme: https | ||
host: github.com | ||
port: 443 | ||
path: /mandelsoft/spiff | ||
fragment: anchor | ||
query: branch=master&tag=v1 | ||
values: | ||
branch: [ master ] | ||
tag: [ v1 ] | ||
userinfo: | ||
username: user | ||
password: pass | ||
``` | ||
|
||
|
||
|
||
### `(( index(list, "foobar") ))` | ||
|
||
Checks whether a list contains a dedicated value and returns the index of the first match. | ||
|
@@ -3133,8 +3217,12 @@ public: |+ | |
``` | ||
|
||
To generate an ssh public key an optional additional format argument can be set | ||
to `ssh`. The result will then be a regular publc key format usable for ssh. | ||
The default format is `pem` providinf the pem output format shown above. | ||
to `ssh`. The result will then be a regular public key format usable for ssh. | ||
The default format is `pem` providing the pem output format shown above. | ||
|
||
RSA keys are by default marshalled in PKCS#1 format(`RSA PUBLIC KEY`) in pem. | ||
If the the generic *PKIX* format (`PUBLIC KEY`) is required the format | ||
argument `pkix` must be given. | ||
|
||
Using the format `ssh` this function can also be used to convert a pem formatted | ||
public key into an ssh key, | ||
|
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,64 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"github.com/mandelsoft/spiff/debug" | ||
"github.com/mandelsoft/spiff/yaml" | ||
"github.com/spf13/cobra" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"path" | ||
) | ||
|
||
// runCmd represents the merge command | ||
var processCmd = &cobra.Command{ | ||
Use: "process", | ||
Aliases: []string{"r"}, | ||
Short: "Process a template with merged stubs on a document", | ||
Long: `Merge a bunch of template files into one manifest processing a document input, printing it out.`, | ||
Args: func(cmd *cobra.Command, args []string) error { | ||
if len(args) < 1 { | ||
return errors.New("requires at least two args (document and template)") | ||
} | ||
return nil | ||
}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
run(args[0], args[1], partial, asJSON, split, outputPath, selection, state, args[2:]) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(processCmd) | ||
|
||
processCmd.Flags().BoolVar(&asJSON, "json", false, "print output in json format") | ||
processCmd.Flags().BoolVar(&debug.DebugFlag, "debug", false, "Print state info") | ||
processCmd.Flags().BoolVar(&partial, "partial", false, "Allow partial evaluation only") | ||
processCmd.Flags().StringVar(&outputPath, "path", "", "output is taken from given path") | ||
processCmd.Flags().StringVar(&state, "state", "", "select state file to maintain") | ||
processCmd.Flags().StringArrayVar(&selection, "select", []string{}, "filter dedicated output fields") | ||
} | ||
|
||
func run(documentFilePath, templateFilePath string, partial bool, json, split bool, | ||
subpath string, selection []string, stateFilePath string, stubFilePaths []string) { | ||
var err error | ||
var stdin = false | ||
var documentFile []byte | ||
|
||
if documentFilePath == "-" { | ||
documentFile, err = ioutil.ReadAll(os.Stdin) | ||
stdin = true | ||
} else { | ||
documentFile, err = ReadFile(documentFilePath) | ||
} | ||
|
||
documentYAML, err := yaml.Parse(documentFilePath, documentFile) | ||
if err != nil { | ||
log.Fatalln(fmt.Sprintf("error parsing template [%s]:", path.Clean(documentFilePath)), err) | ||
} | ||
|
||
documentYAML = yaml.NewNode(map[string]yaml.Node{"document": documentYAML}, "<"+documentFilePath+">") | ||
stub := yaml.NewNode(map[string]yaml.Node{"document": yaml.NewNode("(( &temporary &inject (merge) ))", "<document>)")}, "<document>") | ||
merge(stdin, templateFilePath, partial, json, split, subpath, selection, stateFilePath, []yaml.Node{stub, documentYAML}, stubFilePaths) | ||
} |
Oops, something went wrong.