Skip to content

Commit

Permalink
OPS-15506 Skip template symbols in order to perform CI in unauthorize…
Browse files Browse the repository at this point in the history
…d environments (#188)

* Skip some template symbols in order to perform CI into unauthorized environments

* Insert skip_symbols into class constructor

* Update efopen/ef_template_resolver.py

Co-authored-by: Dumitru Melenteanu <[email protected]>

* Add skip_symbols to ef-resolve-config

Co-authored-by: Dumitru Melenteanu <[email protected]>
  • Loading branch information
csalagean-ellation and momoneko authored Jul 23, 2020
1 parent 3be5f9c commit f0bc5f9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
8 changes: 6 additions & 2 deletions efopen/ef_cf.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def handle_args_and_set_context(args):
type=int, default=False)
parser.add_argument("--poll", help="Poll Cloudformation to check status of stack creation/updates",
action="store_true", default=False)
parser.add_argument("--skip_symbols", help="Skip resolving the provided symbols", nargs='+', default=[])
parsed_args = vars(parser.parse_args(args))
context = EFCFContext()
try:
Expand All @@ -136,16 +137,17 @@ def handle_args_and_set_context(args):
context.lint = parsed_args["lint"]
context.percent = parsed_args["percent"]
context.poll_status = parsed_args["poll"]
context.skip_symbols = parsed_args["skip_symbols"]
context.verbose = parsed_args["verbose"]
# Set up service registry and policy template path which depends on it
context.service_registry = EFServiceRegistry(parsed_args["sr"])
return context

def resolve_template(template, profile, env, region, service, verbose):
def resolve_template(template, profile, env, region, service, skip_symbols, verbose):
# resolve {{SYMBOLS}} in the passed template file
os.path.isfile(template) or fail("Not a file: {}".format(template))
resolver = EFTemplateResolver(profile=profile, target_other=True, env=env,
region=region, service=service, verbose=verbose)
region=region, service=service, skip_symbols=skip_symbols, verbose=verbose)
with open(template) as template_file:
resolver.load(template_file)
resolver.render()
Expand Down Expand Up @@ -287,6 +289,7 @@ def main():
env=context.env,
region=region,
service=service_name,
skip_symbols=context.skip_symbols,
verbose=context.verbose
)

Expand All @@ -310,6 +313,7 @@ def main():
env=context.env,
region=region,
service=service_name,
skip_symbols=context.skip_symbols,
verbose=context.verbose
)
try:
Expand Down
10 changes: 7 additions & 3 deletions efopen/ef_resolve_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@


class Context:
def __init__(self, profile, region, env, service, template_path, no_params, verbose, lint, silent):
def __init__(self, profile, region, env, service, template_path, no_params, verbose, lint, silent, skip_symbols):
self.profile = profile
self.region = region
self.env = env
Expand All @@ -54,6 +54,7 @@ def __init__(self, profile, region, env, service, template_path, no_params, verb
self.verbose = verbose
self.lint = lint
self.silent = silent
self.skip_symbols = skip_symbols

def __str__(self):
return("profile: {}\nregion: {}\nenv: {}\nservice: {}\ntemplate_path: {}\nparam_path: {}\nlint: {}".format(
Expand All @@ -74,6 +75,7 @@ def handle_args_and_set_context(args):
parser.add_argument("--verbose", help="Output extra info", action="store_true", default=False)
parser.add_argument("--lint", help="Test configs for valid JSON/YAML syntax", action="store_true", default=False)
parser.add_argument("--silent", help="Suppress output of rendered template", action="store_true", default=False)
parser.add_argument("--skip_symbols", help="Skip resolving the provided symbols", nargs='+', default=[])
parsed = vars(parser.parse_args(args))
path_to_template = abspath(parsed["path_to_template"])
service = path_to_template.split('/')[-3]
Expand All @@ -87,7 +89,8 @@ def handle_args_and_set_context(args):
parsed["no_params"],
parsed["verbose"],
parsed["lint"],
parsed["silent"]
parsed["silent"],
parsed["skip_symbols"]
)


Expand All @@ -102,7 +105,8 @@ def merge_files(context):
profile=context.profile,
region=context.region,
env=context.env,
service=context.service
service=context.service,
skip_symbols=context.skip_symbols
)

try:
Expand Down
8 changes: 7 additions & 1 deletion efopen/ef_template_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def __init__(self,
profile=None, region=None, # set both for user access mode
lambda_context=None, # set if target is 'self' and this is a lambda
target_other=False, env=None, service=None, # set env & service if target_other=True
skip_symbols={},
verbose=False
):
"""
Expand Down Expand Up @@ -202,6 +203,7 @@ def __init__(self,
# Sets of symbols found in the current template (only)
# read back with self.symbols() and self.unresolved_symbols()
self.symbols = set()
self.skip_symbols = skip_symbols
# capture verbosity pref from constructor
self.verbose = verbose

Expand Down Expand Up @@ -413,8 +415,12 @@ def render(self):
# resolve and replace symbols
for symbol in template_symbols:
resolved_symbol = None

# Don't resolve symbols that are provided as skippable
if symbol.split(',')[0] in self.skip_symbols:
resolved_symbol = "SKIPPED_SYMBOL"
# Lookups in AWS, only if we have an EFAwsResolver
if symbol[:4] == "aws:" and EFTemplateResolver.__AWSR:
elif symbol[:4] == "aws:" and EFTemplateResolver.__AWSR:
resolved_symbol = EFTemplateResolver.__AWSR.lookup(symbol[4:])
# Lookups in credentials
elif symbol[:12] == "credentials:":
Expand Down

0 comments on commit f0bc5f9

Please sign in to comment.