Skip to content

Commit

Permalink
Merge pull request #14 from bundyfx/v0.2.3
Browse files Browse the repository at this point in the history
v0.2.3
  • Loading branch information
bundyfx authored Mar 14, 2019
2 parents 154c184 + 2073582 commit d90078b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
9 changes: 7 additions & 2 deletions src/bootstrap_repository/adf-build/shared/python/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,21 @@ class ParameterNotFoundError(Exception):
"""
pass


class InvalidConfigException(Exception):
"""
Used for invalid configuration(s) within
adfconfig.yml and deployment_map.yml
"""


class GenericAccountConfigureError(Exception):
"""
Generic Account cannot be setup since no base stack is present
"""
pass

class RootOUIDError(Exception):
"""
Raised when an account is moved to the root of the organization
and a describe call is attempted again the root of the org.
"""
pass
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"""

from botocore.config import Config
from botocore.exceptions import ClientError
from errors import RootOUIDError
from logger import configure_logger
from paginator import paginator

Expand Down Expand Up @@ -54,8 +56,8 @@ def describe_ou_name(self, ou_id):
OrganizationalUnitId=ou_id
)
return response['OrganizationalUnit']['Name']
except KeyError:
return "ROOT"
except ClientError:
raise RootOUIDError("OU is the Root of the Organization")

@staticmethod
def determine_ou_path(ou_path, ou_child_name):
Expand Down
17 changes: 11 additions & 6 deletions src/initial/lambda_codebase/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import ast
import os
from errors import ParameterNotFoundError
from errors import ParameterNotFoundError, RootOUIDError

DEPLOYMENT_ACCOUNT_OU_NAME = 'deployment'
DEPLOYMENT_ACCOUNT_S3_BUCKET = os.environ.get("DEPLOYMENT_ACCOUNT_BUCKET")
Expand All @@ -31,6 +31,7 @@ def __init__(self, event, parameter_store, organizations, account_id):
self.protected_ou_list = self.config.get('protected', [])
self.is_deployment_account = 0
self.deployment_account_id = None
self.destination_ou_name = None
self.main_notification_endpoint = self.config.get(
'main-notification-endpoint').pop().get('target')
self.notification_type = 'lambda' if '@' not in self.main_notification_endpoint else 'email'
Expand All @@ -49,7 +50,7 @@ def __init__(self, event, parameter_store, organizations, account_id):
'deployment_account_region')
self.cross_account_access_role = parameter_store.fetch_parameter(
'cross_account_access_role')
self.destination_ou_name = None
self.set_destination_ou_name()


def _determine_if_deployment_account(self):
Expand All @@ -71,10 +72,14 @@ def set_destination_ou_name(self):
That the account was moved into, afterwards determines if that name
was 'deployment'.
"""
self.destination_ou_name = self.organizations.describe_ou_name(
self.destination_ou_id
)
self._determine_if_deployment_account()
try:
self.destination_ou_name = self.organizations.describe_ou_name(
self.destination_ou_id
)
except RootOUIDError:
self.destination_ou_name = "ROOT"
finally:
self._determine_if_deployment_account()

def create_deployment_account_parameters(self):
"""
Expand Down
7 changes: 1 addition & 6 deletions src/initial/lambda_codebase/tests/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_event_moved_to_protected(cls):


def test_event_destination_ou_name(cls):
assert cls.destination_ou_name is None
assert cls.destination_ou_name is 'some_ou_name'


def test_event_protected_ou_list(cls):
Expand All @@ -60,11 +60,6 @@ def test_determine_if_deployment_account(cls):
assert cls.is_deployment_account is 0


def test_set_destination_ou_name(cls):
cls.set_destination_ou_name()
assert cls.destination_ou_name == 'some_ou_name'


def test_create_deployment_account_parameters(cls):
assertion = cls.create_deployment_account_parameters()
assert assertion.get('master_account_id') == '12345678910'
Expand Down

0 comments on commit d90078b

Please sign in to comment.