Skip to content

Commit

Permalink
New infra compatibility updates (#246)
Browse files Browse the repository at this point in the history
* update sg lookup to include name tags

* remove gitleaks due to lack of license

* add ENV_NEW symbol

* add default for NEW_ENV_MAP in case it doesnt exist

* novalue subtitution
  • Loading branch information
dlutsch committed Sep 26, 2023
1 parent 1aa9ca4 commit b691563
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/gitleaks.yml

This file was deleted.

23 changes: 16 additions & 7 deletions efopen/ef_aws_resolver.py
Expand Up @@ -209,14 +209,23 @@ def ec2_security_group_security_group_id(self, lookup, default=None):
"""
try:
response = EFAwsResolver.__CLIENTS["ec2"].describe_security_groups(Filters=[{
'Name':'group-name', 'Values':[lookup]
'Name': 'group-name', 'Values': [lookup]
}])
except:
return default
if len(response["SecurityGroups"]) > 0:
return response["SecurityGroups"][0]["GroupId"]
else:
return default
if len(response["SecurityGroups"]) > 0:
return response["SecurityGroups"][0]["GroupId"]
except Exception as e:
print("Error occurred while searching by group name: {}".format(e))

try:
response = EFAwsResolver.__CLIENTS["ec2"].describe_security_groups(Filters=[{
'Name': 'tag:Name', 'Values': [lookup]
}])
if len(response["SecurityGroups"]) > 0:
return response["SecurityGroups"][0]["GroupId"]
except Exception as e:
print("Error occurred while searching by tag name: {}".format(e))

return default

def ec2_subnet_subnet_id(self, lookup, default=None):
"""
Expand Down
1 change: 1 addition & 0 deletions efopen/ef_config.py
Expand Up @@ -37,6 +37,7 @@ class EFConfig(object):
EF_REPO_BRANCH = _ef_site_config["EF_REPO_BRANCH"]
ENV_ACCOUNT_MAP = _ef_site_config["ENV_ACCOUNT_MAP"]
EPHEMERAL_ENVS = _ef_site_config["EPHEMERAL_ENVS"]
NEW_ENV_MAP = _ef_site_config.get("NEW_ENV_MAP", {})
S3_CONFIG_BUCKET = _ef_site_config["S3_CONFIG_BUCKET"]
S3_VERSION_BUCKET = _ef_site_config["S3_VERSION_BUCKET"]
SERVICE_GROUPS = set(_ef_site_config["SERVICE_GROUPS"])
Expand Down
9 changes: 9 additions & 0 deletions efopen/ef_template_resolver.py
Expand Up @@ -174,6 +174,7 @@ def __init__(self,
{{ENV}} - environment: mgmt, prod, staging, proto<N>, etc.
{{ENV_SHORT}} - env with <N> or account trimmed: mgmt, prod, staging, proto, etc.
{{ENV_FULL}} - env fully qualified: prod, staging, proto<N>, mgmt.<account_alias>, etc.
{{ENV_NEW}} - parallel new env name
{{FUNCTION_NAME}} - only for lambdas
{{INSTANCE_ID}} - only for ec2
{{REGION}} - the region currently being worked in
Expand All @@ -188,6 +189,7 @@ def __init__(self,
"ACCOUNT": None,
"ACCOUNT_ALIAS": None,
"ENV": None,
"ENV_NEW": None,
"ENV_SHORT": None,
"ENV_FULL": None,
"FUNCTION_NAME": None,
Expand Down Expand Up @@ -321,6 +323,11 @@ def __init__(self,
else:
self.resolved["ENV_FULL"] = self.resolved["ENV"]

if self.resolved["ENV_SHORT"] in EFConfig.NEW_ENV_MAP:
self.resolved["ENV_NEW"] = EFConfig.NEW_ENV_MAP[self.resolved["ENV_SHORT"]]
else:
self.resolved["ENV_NEW"] = self.resolved["ENV_SHORT"]

if self.verbose:
print(repr(self.resolved), file=sys.stderr)

Expand Down Expand Up @@ -454,6 +461,8 @@ def render(self):
if isinstance(resolved_symbol, list):
# Using old style of string formatting here due to str.format() interaction with curly braces
self.template = re.sub(r'{{\.?%s}}' % re.escape(symbol), "\n".join(resolved_symbol), self.template)
elif resolved_symbol.lower() == "novalue":
self.template = re.sub(r'"{{\.?%s}}"' % re.escape(symbol), '{ "Ref": "AWS::NoValue" }', self.template)
else:
self.template = re.sub(r'{{\.?%s}}' % re.escape(symbol), resolved_symbol, self.template)
go_again = True
Expand Down

0 comments on commit b691563

Please sign in to comment.