Пример #1
0
 def fetch_accounts_for_target(self):
     if self.path == 'approval':
         return self._target_is_approval()
     if isinstance(self.path, dict):
         return self._target_is_tags()
     if str(self.path).startswith('ou-'):
         return self._target_is_ou_id()
     if AWS_ACCOUNT_ID_REGEX.match(str(self.path)):
         return self._target_is_account_id()
     if str(self.path).isnumeric():
         LOGGER.warning(
             "The specified path is numeric, but is not 12 chars long. "
             "This typically happens when you specify the account id as a "
             "number, while the account id starts with a zero. If this is "
             "the case, please wrap the account id in quotes to make it a "
             "string. The current path is interpreted as '%s'. "
             "It could be interpreted as an octal number due to the zero, "
             "so it might not match the account id as specified in the "
             "deployment map. Interpreted as an octal it would be '%s'. "
             "This error is thrown to be on the safe side such that it "
             "is not targeting the wrong account by accident.",
             str(self.path),
             # Optimistically convert the path from 10-base to octal 8-base
             # Then remove the use of the 'o' char, as it will output
             # in the correct way, starting with: 0o.
             str(oct(int(self.path))).replace('o', ''),
         )
     if str(self.path).startswith('/'):
         return self._target_is_ou_path()
     if self.path is None:
         # No path/target has been passed, path will default to /deployment
         return self._target_is_null_path()
     raise InvalidDeploymentMapError(
         "Unknown definition for target: {0}".format(self.path))
Пример #2
0
 def _validate_deployment_map(self):
     """
     Validates the deployment map contains valid configuration
     """
     try:
         for pipeline in self.map_contents["pipelines"]:
             for target in pipeline.get("targets", []):
                 if isinstance(target, dict):
                     # Prescriptive information on the error should be raised
                     assert target["regions"] and target["path"]
     except KeyError:
         raise InvalidDeploymentMapError(
             "Deployment Map target or regions specification is invalid")
 def _get_all(self):
     self.map_contents = {}
     self.map_contents['pipelines'] = []
     if os.path.isdir(self.map_dir_path):
         for file in os.listdir(self.map_dir_path):
             if file.endswith(
                     ".yml") and file != 'example-deployment_map.yml':
                 self.determine_extend_map(
                     self._read('{0}/{1}'.format(self.map_dir_path, file)))
     self.determine_extend_map(self._read(
     )  # Calling with default no args to get deployment_map.yml in root if it exists
                               )
     if not self.map_contents['pipelines']:
         raise InvalidDeploymentMapError("No Deployment Map files found..")
Пример #4
0
    def fetch_accounts_for_target(self):
        if self.path == 'approval':
            return self._target_is_approval()

        if (str(self.path)).startswith('ou-'):
            return self._target_is_ou_id()

        if (str(self.path).isnumeric() and len(str(self.path)) == 12):
            return self._target_is_account_id()

        if (str(self.path)).startswith('/'):
            return self._target_is_ou_path()

        raise InvalidDeploymentMapError("Unknown defintion for target: {0}".format(self.path))
 def fetch_accounts_for_target(self):
     if self.path == 'approval':
         return self._target_is_approval()
     if (str(self.path)).startswith('ou-'):
         return self._target_is_ou_id()
     if (str(self.path).isnumeric() and len(str(self.path)) == 12):
         return self._target_is_account_id()
     if (str(self.path)).startswith('/'):
         return self._target_is_ou_path()
     if self.path is None:
         return self._target_is_null_path(
         )  # No path/target has been passed, path will default to /deployment
     raise InvalidDeploymentMapError(
         "Unknown defintion for target: {0}".format(self.path))
Пример #6
0
 def _get_all(self):
     self.map_contents = {}
     self.map_contents['pipelines'] = []
     if os.path.isdir(self.map_dir_path):
         self._process_dir(self.map_dir_path)
     self.determine_extend_map(self._read(
     )  # Calling with default no args to get deployment_map.yml in root if it exists
                               )
     if not self.map_contents['pipelines']:
         LOGGER.error(
             "No Deployment Map files found, create a deployment_map.yml file in the root of the repository to create pipelines. "
             "You can create additional deployment maps if required in a folder named deployment_maps with any name (ending in .yml)"
         )
         raise InvalidDeploymentMapError(
             "No Deployment Map files found..") from None
 def _validate(self):
     """
     Validates the deployment map contains valid configuration
     """
     try:
         for pipeline in self.map_contents["pipelines"]:
             for target in pipeline.get("targets", []):
                 if isinstance(target, dict):
                     # Prescriptive information on the error should be raised
                     assert target["path"]
     except KeyError:
         raise InvalidDeploymentMapError(
             "Deployment Map target or regions specification is invalid")
     except TypeError:
         LOGGER.error(
             "No Deployment Map files found, create a deployment_map.yml file in the root of the repository to create pipelines. "
             "You can create additional deployment maps if required in a folder named deployment_maps with any name (ending in .yml)"
         )
         raise Exception from None