-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvariable.go
More file actions
30 lines (26 loc) · 801 Bytes
/
variable.go
File metadata and controls
30 lines (26 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Contributor:
// - Aaron Meihm ameihm@mozilla.com
package scribe
import (
"regexp"
)
// Variable defines variables that can be included in the policy document.
// Variables are expanded in objects at runtime.
type Variable struct {
Key string `json:"key" yaml:"key"`
Value string `json:"value" yaml:"value"`
}
func variableExpansion(v []Variable, in string) string {
res := in
for _, x := range v {
s := "\\$\\{" + x.Key + "\\}"
re := regexp.MustCompile(s)
res = re.ReplaceAllLiteralString(res, x.Value)
}
debugPrint("variableExpansion(): %v -> %v\n", in, res)
return res
}