Пример #1
0
    def add(self, db_session, arn_list_from_user, access_level):
        """
        This just adds the ARN, Service, and Access Level. ARN Format and Actions are not filled out.
        Example data can be found in the class ArnActionGroupTestCase in the testing folder.

        :param db_session: SQLAlchemy database session
        :param arn_list_from_user: Just a list of resource ARNs.
        :param access_level: "Read", "List", "Tagging", "Write", or "Permissions management"
        """
        for arn_from_user in arn_list_from_user:
            service = get_service_from_arn(arn_from_user)
            for row in db_session.query(ActionTable).filter(
                    ActionTable.service.like(service)):
                if does_arn_match(arn_from_user, row.resource_arn_format):
                    if row.access_level == access_level:
                        # If it's not a key in the dictionary, add it as a key
                        # and then add the item in the list
                        raw_arn_format = row.resource_arn_format
                        temp_arn_dict = {
                            'arn': arn_from_user,
                            'service': service,
                            'access_level': access_level,
                            'arn_format': raw_arn_format,
                            'actions': []
                        }

                        # If there is already an entry, skip it to avoid duplicates
                        # Otherwise, add it
                        if temp_arn_dict in self.arns:
                            continue
                        self.arns.append(copy.deepcopy(temp_arn_dict))
Пример #2
0
def build_arn_table(db_session, service):
    directory = os.path.abspath(os.path.dirname(__file__)) + '/data/docs/'
    html_list = get_html(directory, service)
    for df_list in html_list:
        for df in df_list:
            table = json.loads(df.to_json(orient='split'))
            table_data = df
            if 'Resource Types' in table_data and 'ARN' in table_data:
                temp = table['data'][1::]
                for i in range(len(table['data'])):
                    if get_resource_path_from_arn(table['data'][i][1]):
                        resource_path = get_resource_path_from_arn(
                            table['data'][i][1])
                    else:
                        resource_path = ''
                    db_session.add(ArnTable(
                        resource_type_name=table['data'][i][0],
                        raw_arn=str(table['data'][i][1]).replace(
                            "${Partition}", "aws"),
                        # raw_arn=get_string_arn(table['data'][i][1]),
                        arn='arn',
                        partition='aws',
                        service=get_service_from_arn(table['data'][i][1]),
                        region=get_region_from_arn(table['data'][i][1]),
                        account=get_account_from_arn(table['data'][i][1]),
                        resource=get_resource_from_arn(table['data'][i][1]),
                        resource_path=resource_path
                        # resource_path=get_resource_path_from_arn(table['data'][i][1])
                    ))
                    db_session.commit()
Пример #3
0
def build_arn_table(db_session, service):
    """
    Builds the ARN Table - the table of resource types - in the SQLite database.
    :param db_session: SQLAlchemy database session.
    :param service: The AWS service prefix
    """
    directory = os.path.abspath(os.path.dirname(__file__)) + '/data/docs/'
    html_list = get_html(directory, service)
    for df_list in html_list:
        for df in df_list:  # pylint: disable=invalid-name
            table = json.loads(df.to_json(orient='split'))
            table_data = df
            if 'Resource Types' in table_data and 'ARN' in table_data:
                for i in range(len(table['data'])):
                    # Handle resource ARN path
                    if get_resource_path_from_arn(table['data'][i][1]):
                        resource_path = get_resource_path_from_arn(
                            table['data'][i][1])
                    else:
                        resource_path = ''
                    # Handle condition keys
                    if table['data'][i][2] is None:
                        condition_keys = None
                    # If there are multiple condition keys, make them comma separated
                    # Otherwise, if we ingest them as-is, it will show up as
                    # two spaces
                    elif '  ' in table['data'][i][2]:
                        condition_keys = get_comma_separated_condition_keys(
                            table['data'][i][2])
                    else:
                        condition_keys = table['data'][i][2]
                    db_session.add(
                        ArnTable(
                            resource_type_name=table['data'][i][0],
                            raw_arn=str(table['data'][i][1]).replace(
                                "${Partition}", "aws"),
                            # raw_arn=get_string_arn(table['data'][i][1]),
                            arn='arn',
                            partition='aws',
                            service=get_service_from_arn(table['data'][i][1]),
                            region=get_region_from_arn(table['data'][i][1]),
                            account=get_account_from_arn(table['data'][i][1]),
                            resource=get_resource_from_arn(
                                table['data'][i][1]),
                            resource_path=resource_path,
                            condition_keys=condition_keys
                            # resource_path=get_resource_path_from_arn(table['data'][i][1])
                        ))
                    db_session.commit()