def query_history_index(trace_id,
                        check_history_id,
                        filter_expression=None,
                        convert_response=None,
                        is_cw_logger=False):
    if (is_cw_logger):
        logger = common_utils.begin_cw_logger(trace_id, __name__,
                                              inspect.currentframe())
    else:
        logger = common_utils.begin_logger(trace_id, __name__,
                                           inspect.currentframe())
    key_conditions = {
        'CheckHistoryID': {
            'AttributeValueList': [check_history_id],
            'ComparisonOperator': 'EQ'
        }
    }
    result = DB_utils.query_index(trace_id,
                                  Tables.PM_CHECK_RESULTS,
                                  CHECK_HISTORY_INDEX,
                                  key_conditions,
                                  filter_expression,
                                  is_cw_logger=is_cw_logger)
    if result and convert_response:
        result = common_utils.convert_list_response(trace_id,
                                                    result,
                                                    RESPONSE_CHECK_RESULTS,
                                                    RESPONSE_REQUIRED,
                                                    is_cw_logger=is_cw_logger)
    return common_utils.response(result, logger)
def query_userid_key(trace_id,
                     user_id,
                     organization_id=None,
                     filter_expression=None,
                     convert_response=None,
                     is_cw_logger=False):
    if (is_cw_logger):
        logger = common_utils.begin_cw_logger(trace_id, __name__,
                                              inspect.currentframe())
    else:
        logger = common_utils.begin_logger(trace_id, __name__,
                                           inspect.currentframe())
    key_conditions = {
        'UserID': {
            'AttributeValueList': [user_id],
            'ComparisonOperator': 'EQ'
        }
    }
    if (organization_id):
        key_conditions['OrganizationID'] = {
            'AttributeValueList': [organization_id],
            'ComparisonOperator': 'EQ'
        }
    result = DB_utils.query(trace_id,
                            Tables.PM_AFFILIATION,
                            key_conditions,
                            filter_expression,
                            is_cw_logger=is_cw_logger)
    if result and convert_response:
        result = common_utils.convert_list_response(trace_id,
                                                    result,
                                                    RESPONSE_AFFILIATION,
                                                    is_cw_logger=is_cw_logger)
    return common_utils.response(result, logger)
def query_project_index(trace_id,
                        project_id,
                        user_id=None,
                        filter_expression=None,
                        convert_response=None):
    pm_logger = common_utils.begin_logger(trace_id, __name__,
                                          inspect.currentframe())
    key_conditions = {
        'ProjectID': {
            'AttributeValueList': [project_id],
            'ComparisonOperator': 'EQ'
        }
    }
    if common_utils.is_null(user_id) is False:
        key_conditions['UserID'] = {
            'AttributeValueList': [user_id],
            'ComparisonOperator': 'EQ'
        }

    result = DB_utils.query_index(trace_id, Tables.PM_SECURITY_CHECK_WEBHOOK,
                                  PROJECT_INDEX, key_conditions,
                                  filter_expression)
    if result and convert_response:
        result = common_utils.convert_list_response(
            trace_id, result, RESPONSE_SECURITY_CHECK_WEBHOOK)
    return common_utils.response(result, pm_logger)
def query_key(trace_id,
              organization_id,
              notify_code,
              convert_response=None,
              is_cw_logger=False):
    if (is_cw_logger):
        logger = common_utils.begin_cw_logger(trace_id, __name__,
                                              inspect.currentframe())
    else:
        logger = common_utils.begin_logger(trace_id, __name__,
                                           inspect.currentframe())
    key = {"OrganizationID": organization_id, "NotifyCode": notify_code}
    result = DB_utils.query_key(trace_id,
                                Tables.PM_ORG_NOTIFY_MAIL_DESTINATIONS,
                                key,
                                is_cw_logger=is_cw_logger)
    if result and convert_response:
        result = common_utils.convert_response(
            trace_id,
            result,
            RESPONSE_ORG_NOTIFY_MAIL_DESTINATIONS,
            is_cw_logger=is_cw_logger)
        result['destinations'] = common_utils.convert_list_response(
            trace_id,
            result['destinations'],
            RESPONSE_DESTINATIONS,
            is_cw_logger=is_cw_logger)
    return common_utils.response(result, logger)
Example #5
0
def query_user_index(user_id, filter_expression=None, convert_response=None):
    pm_logger = common_utils.begin_logger(user_id, __name__,
                                          inspect.currentframe())
    key_conditions = {
        'UserID': {
            'AttributeValueList': [user_id],
            'ComparisonOperator': 'EQ'
        }
    }
    result = DB_utils.query_index(user_id, Tables.PM_EMAIL_CHANGE_APPLY,
                                  USER_INDEX, key_conditions,
                                  filter_expression)
    if convert_response:
        result = common_utils.convert_list_response(
            user_id, result, RESPONSE_EMAIL_CHANGE_APPLY)
    return common_utils.response(result, pm_logger)
Example #6
0
def get_projects(trace_id, project_id, filter_expression=None,
                 convert_response=None):
    pm_logger = common_utils.begin_logger(trace_id, __name__,
                                          inspect.currentframe())
    key_conditions = {
        'ProjectID': {
            'AttributeValueList': [project_id],
            'ComparisonOperator': 'EQ'
        }
    }
    result = DB_utils.query(trace_id, Tables.PM_PROJECTS,
                            key_conditions, filter_expression)

    if convert_response:
        result = common_utils.convert_list_response(
            trace_id, result, RESPONSE_PROJECTS)
    return common_utils.response(result, pm_logger)
Example #7
0
def query_organization_index(trace_id, organization_id,
                             filter_expression=None, convert_response=None):
    pm_logger = common_utils.begin_logger(trace_id, __name__,
                                          inspect.currentframe())
    key_conditions = {
        'OrganizationID': {
            'AttributeValueList': [organization_id],
            'ComparisonOperator': 'EQ'
        }
    }
    result = DB_utils.query_index(trace_id, Tables.PM_PROJECTS,
                                  ORGANIZATION_INDEX, key_conditions,
                                  filter_expression)

    if convert_response:
        result = common_utils.convert_list_response(
            trace_id, result, RESPONSE_PROJECTS)
    return common_utils.response(result, pm_logger)
def query_check_item_refine_code(trace_id,
                                 check_item_refine_code,
                                 filter_expression=None,
                                 convert_response=None):
    pm_logger = common_utils.begin_logger(trace_id, __name__,
                                          inspect.currentframe())
    key_conditions = {
        'CheckItemRefineCode': {
            'AttributeValueList': [check_item_refine_code],
            'ComparisonOperator': 'EQ'
        }
    }
    result = DB_utils.query_index(trace_id, Tables.PM_EXCLUSION_RESOURCES,
                                  CHECK_ITEM_REFINE_INDEX, key_conditions,
                                  filter_expression)
    if result and convert_response:
        result = common_utils.convert_list_response(
            trace_id, result, RESPONSE_EXCLUSION_RESOURCES)
    return common_utils.response(result, pm_logger)
def query_project_index_by_organization_id(trace_id,
                                           organization_id,
                                           project_id,
                                           convert_response=None):
    pm_logger = common_utils.begin_logger(trace_id, __name__,
                                          inspect.currentframe())
    key_conditions = {
        'ProjectID': {
            'AttributeValueList': [project_id],
            'ComparisonOperator': 'EQ'
        }
    }
    filter = Attr('OrganizationID').eq(organization_id)
    result = DB_utils.query_index(trace_id, Tables.PM_CHECK_HISTORY,
                                  PROJECT_INDEX, key_conditions, filter, False)
    if convert_response:
        result = common_utils.convert_list_response(trace_id, result,
                                                    RESPONSE_HISTORY)
    return common_utils.response(result, pm_logger)
def query_awscoop(trace_id,
                  coop_id,
                  filter_expression=None,
                  convert_response=None):
    pm_logger = common_utils.begin_logger(trace_id, __name__,
                                          inspect.currentframe())
    key_conditions = {
        'CoopID': {
            'AttributeValueList': [coop_id],
            'ComparisonOperator': 'EQ'
        }
    }
    result = DB_utils.query(trace_id, Tables.PM_AWSACCOUNTCOOPS,
                            key_conditions, filter_expression)

    if convert_response:
        result = common_utils.convert_list_response(trace_id, result,
                                                    RESPONSE_AWSCOOPS,
                                                    RESPONSE_REQUIRED)
    return common_utils.response(result, pm_logger)
def query_webhook_index(trace_id,
                        webhook_path,
                        filter_expression=None,
                        convert_response=None):
    pm_logger = common_utils.begin_logger(trace_id, __name__,
                                          inspect.currentframe())
    key_conditions = {
        'WebhookPath': {
            'AttributeValueList': [webhook_path],
            'ComparisonOperator': 'EQ'
        }
    }

    result = DB_utils.query_index(trace_id, Tables.PM_SECURITY_CHECK_WEBHOOK,
                                  WEBHOOK_PATH_INDEX, key_conditions,
                                  filter_expression)
    if result and convert_response:
        result = common_utils.convert_list_response(
            trace_id, result, RESPONSE_SECURITY_CHECK_WEBHOOK)

    return common_utils.response(result, pm_logger)
Example #12
0
def query(user_id,
          organization_id,
          filter_expression=None,
          convert_response=None):
    pm_logger = common_utils.begin_logger(user_id, __name__,
                                          inspect.currentframe())
    key_conditions = {
        'UserID': {
            'AttributeValueList': [user_id],
            'ComparisonOperator': 'EQ'
        },
        'OrganizationID': {
            'AttributeValueList': [organization_id],
            'ComparisonOperator': 'EQ'
        }
    }
    result = DB_utils.query(user_id, Tables.PM_AFFILIATION, key_conditions,
                            filter_expression)
    if result and convert_response:
        result = common_utils.convert_list_response(user_id, result,
                                                    RESPONSE_AFFILIATION)
    return common_utils.response(result, pm_logger)
Example #13
0
def query_list_reports_project_index(trace_id,
                                     project_id,
                                     filter_expression=None,
                                     convert_response=None,
                                     scan_index_forward=True):
    pm_logger = common_utils.begin_logger(trace_id, __name__,
                                          inspect.currentframe())
    key_conditions = {
        'ProjectID': {
            'AttributeValueList': [project_id],
            'ComparisonOperator': 'EQ'
        }
    }
    result = DB_utils.query_index(trace_id, Tables.PM_REPORTS, PROJECT_INDEX,
                                  key_conditions, filter_expression,
                                  scan_index_forward)

    if convert_response:
        result = common_utils.convert_list_response(trace_id, result,
                                                    RESPONSE_REPORT)

    return common_utils.response(result, pm_logger)
def query_awscoop_project_index(trace_id,
                                project_id,
                                filter_expression=None,
                                convert_response=None,
                                aws_account=None,
                                is_cw_logger=False):
    if (is_cw_logger):
        logger = common_utils.begin_cw_logger(trace_id, __name__,
                                              inspect.currentframe())
    else:
        logger = common_utils.begin_logger(trace_id, __name__,
                                           inspect.currentframe())
    key_conditions = {
        'ProjectID': {
            'AttributeValueList': [project_id],
            'ComparisonOperator': 'EQ'
        }
    }
    if aws_account is not None:
        key_conditions['AWSAccount'] = {
            'AttributeValueList': [aws_account],
            'ComparisonOperator': 'EQ'
        }
    result = DB_utils.query_index(trace_id,
                                  Tables.PM_AWSACCOUNTCOOPS,
                                  PROJECT_INDEX,
                                  key_conditions,
                                  filter_expression,
                                  is_cw_logger=is_cw_logger)

    if convert_response:
        result = common_utils.convert_list_response(trace_id,
                                                    result,
                                                    RESPONSE_AWSCOOPS,
                                                    RESPONSE_REQUIRED,
                                                    is_cw_logger=is_cw_logger)
    return common_utils.response(result, logger)