-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for config_merger to filter root keys (#162)
- Loading branch information
Showing
14 changed files
with
228 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
env: default | ||
region: default | ||
cluster: default | ||
|
||
cluster_info: | ||
name: default # this will be overridden by the inner cluster.yaml file | ||
|
||
# Interpolation example | ||
description: "This is cluster: {{cluster}}. It is using {{cluster_info.node_type}} instance type." | ||
node_type: c3.2xlarge # default value, which can be overridden by each cluster | ||
cluster_metrics: | ||
- id: 1 | ||
metric: cpu | ||
value: 90 | ||
- id: 2 | ||
metric: memory | ||
value: 90 | ||
- id: 3 | ||
metric: disk | ||
value: 90 | ||
metrics: | ||
- cpu | ||
- memory | ||
- disk | ||
myList: | ||
- id1 | ||
- id4 | ||
# Fetching the secret value at runtime, from a secrets store (in this case AWS SSM). | ||
# passphrase: "{{ssm.path(/key/coming/from/aws/secrets/store/manager).aws_profile(myprofile)}}" | ||
|
||
# Fetching the value at runtime from S3 | ||
# my_secret: "{{s3.bucket(my-bucket).path(path/to/file.txt).base64encode(true).aws_profile(myprofile)}}" | ||
|
||
|
||
_filters: | ||
# Keep _filters key for all outputs. No selector matches all outputs by default. | ||
# - keys: | ||
# values: | ||
# - "_filters" | ||
|
||
- selector: | ||
cluster: "cluster.*" | ||
keys: | ||
values: | ||
- persisted_key | ||
# - persisted_key_referenced | ||
# - persisted_key_to_drop | ||
# - persisted_key_to_drop2 | ||
# - cluster_persisted_object | ||
# - cluster_persisted_list | ||
|
||
- selector: | ||
cluster: cluster1 | ||
keys: | ||
values: | ||
- testkey | ||
- home | ||
- cluster_persisted_key | ||
|
||
- selector: | ||
cluster: cluster2 | ||
keys: | ||
values: | ||
- metrics | ||
- myList | ||
regex: ".*persisted.*" |
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,6 @@ | ||
env: dev | ||
persisted_key: &persisted persisted key | ||
dropped_key: &dropped object will be filtered out | ||
persisted_key_referenced: *persisted | ||
persisted_key_to_drop: *dropped | ||
persisted_key_to_drop2: *dropped |
21 changes: 21 additions & 0 deletions
21
examples/filters/env=dev/region=us-east-1/cluster=cluster1/cluster.yaml
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,21 @@ | ||
cluster: cluster1 | ||
|
||
testkey: |- | ||
# Set to true to log user information returned from LDAP | ||
verbose_logging = true | ||
[[servers]] | ||
# Ldap server host | ||
host = "someaddress" | ||
# Default port is 389 or 636 if use_ssl = true | ||
port = 389 | ||
start_tls = true | ||
cluster_persisted_key: this object will be persisted | ||
cluster_filtered_key: this object will be filtered out | ||
cluster_persisted_list: "{{ myList }}" | ||
cluster_persisted_object: | ||
cluster_info: "{{ cluster_info }}" | ||
cluster_list: "{{ myList }}" |
23 changes: 23 additions & 0 deletions
23
examples/filters/env=dev/region=us-east-1/cluster=cluster2/cluster.yaml
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,23 @@ | ||
cluster: cluster2 | ||
cluster_metrics: | ||
- id: 1 | ||
metric: cpu | ||
value: 95 | ||
- id: 2 | ||
metric: memory | ||
value: 95 | ||
- id: 3 | ||
metric: disk | ||
remove: True | ||
- metric: exec | ||
value: 5 | ||
metrics: | ||
- cpu | ||
- exec | ||
myList: | ||
- id1 | ||
- id2 | ||
- id3 | ||
persisted_key: this object will be persisted | ||
dropped_key: this object will be dropped | ||
another_persisted_key: this object will also be persisted |
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 @@ | ||
region: us-east-1 |
2 changes: 2 additions & 0 deletions
2
examples/filters/env=dev/region=us-west-2/cluster=cluster1/cluster.yaml
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,2 @@ | ||
cluster: cluster1 | ||
home: "{{env(HOME)}}" |
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 @@ | ||
region: us-west-2 |
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 @@ | ||
env: prod |
3 changes: 3 additions & 0 deletions
3
examples/filters/env=prod/region=eu-west-2/cluster=ireland1/cluster.yaml
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,3 @@ | ||
cluster: ireland1 | ||
|
||
file: "{{cwd}}/test.txt" |
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 @@ | ||
region: eu-west-2 |
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,37 @@ | ||
import re | ||
|
||
|
||
class FilterRules(object): | ||
|
||
def __init__(self, rules, levels): | ||
self.rules = rules | ||
self.levels = levels | ||
|
||
def run(self, output): | ||
|
||
removable_keys = set(output.keys()) - set(self.levels) | ||
|
||
for filter in self.rules: | ||
selector = filter.get("selector", {}) | ||
if type(selector) != dict: | ||
raise Exception("Filter selector must be a dictionary") | ||
|
||
if not self.match(output, selector): | ||
continue | ||
|
||
keys = filter.get("keys") | ||
if "values" in keys: | ||
removable_keys = removable_keys - set(keys["values"]) | ||
if "regex" in keys: | ||
key_re = re.compile(keys["regex"]) | ||
removable_keys = {k for k in removable_keys if not key_re.match(k)} | ||
|
||
for key in removable_keys: | ||
del output[key] | ||
|
||
def match(self, output, selector): | ||
for key, pattern in selector.items(): | ||
value = "" if key not in output else output[key] | ||
if not re.match(pattern, value): | ||
return False | ||
return True |
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