Esempio n. 1
0
    def setUp(self):
        dotenv_path = Path(os.getcwd()).joinpath('.env')
        if os.path.exists(dotenv_path):
            load_dotenv(dotenv_path)

        # create pm_orgNotifyMailDestinaltions
        pm_orgNotifyMailDestinations.create(
            trace_id, notify_mail_template['OrganizationID'],
            notify_mail_template['NotifyCode'],
            notify_mail_template['Destinations'])

        num = 0
        while num < 6:
            # Create organization task
            tmp_organization_task = copy.copy(organization_task_template)
            tmp_organization_task['TaskStatus'] = num
            if (num == 4):
                tmp_organization_task['TaskStatus'] = -1
            elif (num == 5):
                tmp_organization_task['TaskStatus'] = -1
                tmp_organization_task[
                    'RetryCount'] = tmp_organization_task['MaxRetry'] + 1

            pm_organizationTasks.create_organizationTask(
                trace_id, tmp_organization_task['TaskID'].format(str(num)),
                tmp_organization_task['Code'],
                tmp_organization_task['Target'].format(str(num)),
                tmp_organization_task['UserID'],
                tmp_organization_task['MailAddress'],
                tmp_organization_task['TaskStatus'],
                tmp_organization_task['RetryCount'],
                tmp_organization_task['MaxRetry'])
            num += 1
def delete_user(trace_id, organization_id, user_id, email):
    pm_logger = common_utils.begin_logger(trace_id, __name__,
                                          inspect.currentframe())
    # check the deletion condition
    if user_id == trace_id:
        try:
            count = pm_affiliation.query_users_check_authority_count(
                trace_id, user_id, organization_id, Authority.Owner)
        except PmError as e:
            return common_utils.error_exception(
                MsgConst.ERR_402, HTTPStatus.INTERNAL_SERVER_ERROR, e,
                pm_logger, True)
        if count == 0:
            return common_utils.error_common(MsgConst.ERR_REQUEST_203,
                                             HTTPStatus.PRECONDITION_FAILED,
                                             pm_logger)
    # get user to delete
    try:
        user = pm_affiliation.query(user_id, organization_id)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_402,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)
    if not user:
        return common_utils.error_common(MsgConst.ERR_301,
                                         HTTPStatus.NOT_FOUND, pm_logger)

    # delete user
    try:
        pm_affiliation.delete_affiliation(user_id, organization_id)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_DB_405,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)

    # set task informaiton request delete in Organization Tasks
    task_id = str(uuid.uuid4())
    target = CommonConst.TARGET_DELETE_ORG_USER.format(user_id,
                                                       organization_id)

    try:
        # create task informaiton request delete in Organization Tasks
        pm_organizationTasks.create_organizationTask(
            trace_id, task_id, CommonConst.TASK_TYPE_CODE_DELETE_ORG_USER,
            target, trace_id, email, Status.Waiting.value, 0, 3)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_DB_403,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)
    try:
        # Send message to organization topic task
        aws_common.sns_organization_topic(
            trace_id, task_id, CommonConst.TASK_TYPE_CODE_DELETE_ORG_USER)
    except PmError as e:
        common_utils.write_log_pm_error(e, pm_logger, exc_info=True)

    response = common_utils.get_response_by_response_body(
        HTTPStatus.NO_CONTENT, None)
    return common_utils.response(response, pm_logger)
Esempio n. 3
0
 def test_create_exception(self):
     with self.assertRaises(NoRetryException):
         # Duplicate Task ID
         tmp_organization_task = copy.copy(organization_task_template)
         pm_organizationTasks.create_organizationTask(
             trace_id, tmp_organization_task['TaskID'].format(str(1)),
             tmp_organization_task['Code'],
             tmp_organization_task['Target'],
             tmp_organization_task['UserID'],
             tmp_organization_task['MailAddress'],
             tmp_organization_task['TaskStatus'],
             tmp_organization_task['RetryCount'],
             tmp_organization_task['MaxRetry'])
Esempio n. 4
0
def delete_project(trace_id, email, project_id, organization_id):
    # Get logging
    pm_logger = common_utils.begin_logger(trace_id, __name__,
                                          inspect.currentframe())
    try:
        project = pm_projects.get_projects_by_organization_id(
            trace_id, project_id, organization_id, convert_response=True)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_402,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)

    # 組織情報を取得します。
    if (not project):
        return common_utils.error_common(MsgConst.ERR_301,
                                         HTTPStatus.NOT_FOUND, pm_logger)

    # プロジェクト削除の条件を満たしているかチェックを行います。現時点ではチェックすべき項目はありません。
    # 現時点ではチェックすべき項目はありません。

    # Delete project
    try:
        pm_projects.delete_projects(trace_id, project_id)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_DB_405,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)

    # Create task
    task_id = str(uuid.uuid4())
    user_id = trace_id
    try:
        pm_organizationTasks.create_organizationTask(trace_id, task_id,
                                                     "DELETE_PRJ", project_id,
                                                     user_id, email,
                                                     Status.Waiting.value, 0,
                                                     3)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_DB_403,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)

    aws_common.sns_organization_topic(trace_id, task_id, "DELETE_PRJ")

    # data response
    response = common_utils.get_response_by_response_body(
        HTTPStatus.NO_CONTENT, None)
    return common_utils.response(response, pm_logger)
Esempio n. 5
0
 def test_create_success(self):
     tmp_organization_task = copy.copy(organization_task_template)
     tmp_organization_task['TaskID'] = task_id.format(str(3))
     pm_organizationTasks.create_organizationTask(
         trace_id, tmp_organization_task['TaskID'],
         tmp_organization_task['Code'],
         tmp_organization_task['Target'],
         tmp_organization_task['UserID'],
         tmp_organization_task['MailAddress'],
         tmp_organization_task['TaskStatus'],
         tmp_organization_task['RetryCount'],
         tmp_organization_task['MaxRetry'])
     insert_result = pm_organizationTasks.query_key(task_id.format(str(3)))
     self.organizationTask_result_check(
         actual_organization=insert_result,
         expected_organization=tmp_organization_task)
     pm_organizationTasks.delete(trace_id, task_id.format(str(3)))
Esempio n. 6
0
    def setUp(self):
        dotenv_path = Path(os.getcwd()).joinpath('.env')
        if os.path.exists(dotenv_path):
            load_dotenv(dotenv_path)

        num = 1
        while num < 3:
            # Create organization task
            tmp_organization_task = copy.copy(organization_task_template)
            pm_organizationTasks.create_organizationTask(
                trace_id, tmp_organization_task['TaskID'].format(str(num)),
                tmp_organization_task['Code'],
                tmp_organization_task['Target'],
                tmp_organization_task['UserID'],
                tmp_organization_task['MailAddress'],
                tmp_organization_task['TaskStatus'],
                tmp_organization_task['RetryCount'],
                tmp_organization_task['MaxRetry'])
            num += 1
Esempio n. 7
0
def delete_report(trace_id, email, report_id, organization_id, project_id):
    pm_logger = common_utils.begin_logger(trace_id, __name__,
                                          inspect.currentframe())
    try:
        # get report
        report_item = pm_reports.query_report_filter_organization_project(
            trace_id, report_id, project_id, organization_id)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_402,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)

    if (not report_item):
        return common_utils.error_common(MsgConst.ERR_301,
                                         HTTPStatus.NOT_FOUND, pm_logger)

    try:
        # delete report
        pm_reports.delete_reports(trace_id, report_id)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_DB_405,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)

    task_id = common_utils.get_uuid4()
    try:
        # create task informaiton request delete in Organization Tasks
        pm_organizationTasks.create_organizationTask(trace_id, task_id,
                                                     task_code, report_id,
                                                     trace_id, email, 0, 0, 3)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_DB_403,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)

    # Send message to organization topic task
    aws_common.sns_organization_topic(trace_id, task_id, task_code)

    # response if delete success
    response = common_utils.get_response_by_response_body(
        HTTPStatus.NO_CONTENT, None)
    return common_utils.response(response, pm_logger)
Esempio n. 8
0
    def setUp(self):
        dotenv_path = Path(os.getcwd()).joinpath('.env')
        if os.path.exists(dotenv_path):
            load_dotenv(dotenv_path)

        num = 1
        while num < 7:
            # Create Report
            tmp_report = copy.copy(reports_template)
            pm_reports.create_report(
                trace_id, tmp_report['ReportID'].format(str(num)),
                tmp_report['ReportName'], tmp_report['GenerateUser'],
                tmp_report['AWSAccounts'], 4, tmp_report['ResourceInfoPath'],
                tmp_report['JsonOutputPath'], tmp_report['JsonOutputTime'],
                tmp_report['HTMLOutputStatus'], tmp_report['HTMLPath'],
                tmp_report['HTMLOutputTime'], 2, tmp_report['ExcelPath'],
                tmp_report['ExcelOutputTime'], tmp_report['SchemaVersion'],
                tmp_report['OrganizationID'], tmp_report['ProjectID'])

            # Create organization task
            tmp_organization_task = copy.copy(organization_task_template)
            tmp_organization_task['TaskStatus'] = num
            if (num == 3 and num == 6):
                tmp_organization_task['TaskStatus'] = 0
            elif (num == 4):
                tmp_organization_task['TaskStatus'] = -1
            elif (num == 5):
                tmp_organization_task['TaskStatus'] = -1
                tmp_organization_task['RetryCount'] = tmp_organization_task['MaxRetry'] + 1

            pm_organizationTasks.create_organizationTask(
                trace_id, tmp_organization_task['TaskID'].format(str(num)),
                tmp_organization_task['Code'],
                tmp_organization_task['Target'].format(str(num)),
                tmp_organization_task['UserID'],
                tmp_organization_task['MailAddress'],
                tmp_organization_task['TaskStatus'],
                tmp_organization_task['RetryCount'],
                tmp_organization_task['MaxRetry'])
            num += 1
Esempio n. 9
0
    def setUp(self):
        dotenv_path = Path(os.getcwd()).joinpath('.env')
        if os.path.exists(dotenv_path):
            load_dotenv(dotenv_path)

        # Create Organization
        pm_organizations.create_organization(
            trace_id, organization_template['OrganizationID'],
            organization_template['OrganizationName'],
            organization_template['Contract'],
            organization_template['ContractStatus'])

        # Create Projects
        pm_projects.create_projects(trace_id, projects_template['ProjectID'],
                                    projects_template['ProjectName'],
                                    projects_template['Description'],
                                    projects_template['OrganizationID'])

        # Create awscoop
        pm_awsAccountCoops.create_awscoops(
            trace_id, awscoops_template["CoopID"],
            awscoops_template["AWSAccountName"],
            awscoops_template["AWSAccount"], awscoops_template["RoleName"],
            awscoops_template["ExternalID"], awscoops_template["Description"],
            awscoops_template["Effective"],
            awscoops_template["OrganizationID"],
            awscoops_template["ProjectID"])

        num = 1
        while num < 7:
            # Create Report
            tmp_report = copy.copy(reports_template)
            pm_reports.create_report(
                trace_id, tmp_report['ReportID'].format(str(num)),
                tmp_report['ReportName'], tmp_report['GenerateUser'],
                tmp_report['AWSAccounts'], 4, tmp_report['ResourceInfoPath'],
                tmp_report['JsonOutputPath'], tmp_report['JsonOutputTime'],
                tmp_report['HTMLOutputStatus'], tmp_report['HTMLPath'],
                tmp_report['HTMLOutputTime'], 2, tmp_report['ExcelPath'],
                tmp_report['ExcelOutputTime'], tmp_report['SchemaVersion'],
                tmp_report['OrganizationID'], tmp_report['ProjectID'])

            # Create organization task
            tmp_organization_task = copy.copy(organization_task_template)
            tmp_organization_task['TaskStatus'] = num
            if (num == 3 and num == 6):
                tmp_organization_task['TaskStatus'] = 0
            elif (num == 4):
                tmp_organization_task['TaskStatus'] = -1
            elif (num == 5):
                tmp_organization_task['TaskStatus'] = -1
                tmp_organization_task[
                    'RetryCount'] = tmp_organization_task['MaxRetry'] + 1

            pm_organizationTasks.create_organizationTask(
                trace_id, tmp_organization_task['TaskID'].format(str(num)),
                tmp_organization_task['Code'],
                tmp_organization_task['Target'].format(str(num)),
                tmp_organization_task['UserID'],
                tmp_organization_task['MailAddress'],
                tmp_organization_task['TaskStatus'],
                tmp_organization_task['RetryCount'],
                tmp_organization_task['MaxRetry'])
            num += 1

        # create data error no project
        # Create Organization
        pm_organizations.create_organization(
            trace_id, organization_id_error.format(str(1)),
            organization_template['OrganizationName'],
            organization_template['Contract'],
            organization_template['ContractStatus'])
        # Create organization task
        tmp_organization_task = copy.copy(organization_task_template)
        pm_organizationTasks.create_organizationTask(
            trace_id, tmp_organization_task['TaskID'].format(str(7)),
            tmp_organization_task['Code'],
            project_id_error.format(str(1)),
            tmp_organization_task['UserID'],
            tmp_organization_task['MailAddress'],
            tmp_organization_task['TaskStatus'],
            tmp_organization_task['RetryCount'],
            tmp_organization_task['MaxRetry'])

        # create data error no awscoops and no reports
        # Create organization task
        tmp_organization_task = copy.copy(organization_task_template)
        pm_organizationTasks.create_organizationTask(
            trace_id, tmp_organization_task['TaskID'].format(str(8)),
            tmp_organization_task['Code'],
            project_id_error.format(str(1)),
            tmp_organization_task['UserID'],
            tmp_organization_task['MailAddress'],
            tmp_organization_task['TaskStatus'],
            tmp_organization_task['RetryCount'],
            tmp_organization_task['MaxRetry'])

        # Create Projects
        pm_projects.create_projects(trace_id, project_id_error.format(str(1)),
                                    projects_template['ProjectName'],
                                    projects_template['Description'],
                                    organization_id_error.format(str(1)))

        # create data error no reports
        # Create organization task
        tmp_organization_task = copy.copy(organization_task_template)
        pm_organizationTasks.create_organizationTask(
            trace_id, tmp_organization_task['TaskID'].format(str(9)),
            tmp_organization_task['Code'],
            project_id_error.format(str(1)),
            tmp_organization_task['UserID'],
            tmp_organization_task['MailAddress'],
            tmp_organization_task['TaskStatus'],
            tmp_organization_task['RetryCount'],
            tmp_organization_task['MaxRetry'])

        # Create awscoop
        pm_awsAccountCoops.create_awscoops(
            trace_id, coop_id.format(str(2)),
            awscoops_template["AWSAccount"],
            awscoops_template["AWSAccountName"],
            awscoops_template["RoleName"],
            awscoops_template["ExternalID"], awscoops_template["Description"],
            awscoops_template["Effective"],
            organization_id_error.format(str(1)),
            project_id_error.format(str(1)))
def delete_organization(trace_id, email, organization_id):
    pm_logger = common_utils.begin_logger(trace_id, __name__,
                                          inspect.currentframe())
    try:
        organization_item = pm_organizations.get_organization(
            trace_id, organization_id)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_402,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)

    if (not organization_item):
        return common_utils.error_common(MsgConst.ERR_301,
                                         HTTPStatus.NOT_FOUND, pm_logger)

    try:
        # delete organization
        pm_organizations.delete_organization(trace_id, organization_id)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_DB_405,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)
    try:
        # get affiliations get by organization id
        affiliation_items = pm_affiliation.query_organization_index(
            trace_id, organization_id)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_402,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)

    for affiliation in affiliation_items:
        try:
            # delete affiliations get by organization id
            pm_affiliation.delete_affiliation(affiliation["UserID"],
                                              organization_id)
        except PmError as e:
            return common_utils.error_exception(
                MsgConst.ERR_DB_405, HTTPStatus.INTERNAL_SERVER_ERROR, e,
                pm_logger, True)

        # set task informaiton request delete in Organization Tasks
        task_id = common_utils.get_uuid4()
        target = CommonConst.TARGET_DELETE_ORG_USER.format(
            affiliation["UserID"], organization_id)

        try:
            # create task informaiton request delete in Organization Tasks
            pm_organizationTasks.create_organizationTask(
                trace_id, task_id, CommonConst.TASK_TYPE_CODE_DELETE_ORG_USER,
                target, trace_id, email, Status.Waiting.value, 0, 3)
        except PmError as e:
            return common_utils.error_exception(
                MsgConst.ERR_DB_403, HTTPStatus.INTERNAL_SERVER_ERROR, e,
                pm_logger, True)

        try:
            # Send message to organization topic task
            aws_common.sns_organization_topic(
                trace_id, task_id, CommonConst.TASK_TYPE_CODE_DELETE_ORG_USER)
        except PmError as e:
            common_utils.write_log_pm_error(e, pm_logger, exc_info=True)

    # set task informaiton request delete in Organization Tasks
    task_id = common_utils.get_uuid4()
    try:
        # create task informaiton request delete in Organization Tasks
        pm_organizationTasks.create_organizationTask(
            trace_id, task_id, CommonConst.TASK_TYPE_CODE_DELETE_ORG,
            organization_id, trace_id, email, 0, 0, 3)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_DB_403,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)

    # Send message to organization topic task
    aws_common.sns_organization_topic(trace_id, task_id,
                                      CommonConst.TASK_TYPE_CODE_DELETE_ORG,
                                      organization_id, trace_id)
    # response if delete success
    response = common_utils.get_response_by_response_body(
        HTTPStatus.NO_CONTENT, None)
    return common_utils.response(response, pm_logger)