コード例 #1
0
def delete_awscoop(trace_id, coop_id, organization_id, project_id):
    pm_logger = common_utils.begin_logger(trace_id, __name__,
                                          inspect.currentframe())
    try:
        awscoops = pm_awsAccountCoops.get_awscoops_update(
            trace_id, coop_id, project_id, organization_id)
    except PmError as err:
        return common_utils.error_exception(MsgConst.ERR_402,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            err, pm_logger, True)

    if awscoops is None:
        return common_utils.error_common(MsgConst.ERR_301,
                                         HTTPStatus.NOT_FOUND, pm_logger)

    try:
        pm_awsAccountCoops.delete_awscoops(trace_id, coop_id)
    except PmError as err:
        return common_utils.error_exception(MsgConst.ERR_DB_405,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            err, pm_logger, True)

    # response if delete success
    response = common_utils.get_response_by_response_body(
        HTTPStatus.NO_CONTENT, None)
    return common_utils.response(response, pm_logger)
コード例 #2
0
 def tearDown(self):
     num = 1
     while num < 7:
         pm_organizationTasks.delete(trace_id, task_id.format(str(num)))
         pm_reports.delete_reports(trace_id, report_id.format(str(num)))
         num += 1
     pm_organizationTasks.delete(trace_id, task_id.format(str(7)))
     pm_organizationTasks.delete(trace_id, task_id.format(str(8)))
     pm_awsAccountCoops.delete_awscoops(trace_id, coop_id.format(str(1)))
     pm_projects.delete_projects(trace_id, project_id)
     pm_projects.delete_projects(trace_id, project_id_error.format(str(1)))
     pm_organizations.delete_organization(trace_id, organization_id)
     pm_organizations.delete_organization(
         trace_id, organization_id_error.format(str(1)))
コード例 #3
0
    def test_update_awscoops_success_members_disable(self):
        test_user_id = user_id.format(str(3))

        # handler
        path_parameters = {
            "organization_id": organization_id,
            "project_id": project_id,
            "coop_id": coop_id.format(str(1))
        }
        tmp_awscoops_body = copy.copy(awscoops_body)
        tmp_awscoops_body['awsAccount'] = 'ERROR'
        event_mock = event_create.get_event_object(
            path_parameters=path_parameters,
            trace_id=test_user_id,
            body=json.dumps(tmp_awscoops_body))
        response = awscoops.update_awscoop_handler(event_mock, {})

        # Get data response
        status_code = response['statusCode']
        response_body = json.loads(response['body'])
        id = response_body["id"]
        awsAccount = response_body['awsAccount']
        roleName = response_body['roleName']
        externalId = response_body['externalId']
        projectId = response_body['projectId']
        organizationId = response_body['organizationId']
        description = response_body['description']
        createdAt = response_body['createdAt']
        updatedAt = response_body['updatedAt']
        members = response_body['members']

        # Get data in database
        awscoops_database = pm_awsAccountCoops.query_awscoop_coop_key(
            trace_id, id, convert_response=True)

        # Check data
        self.assertEqual(id, awscoops_database['id'])
        self.assertEqual(awsAccount, awscoops_database['awsAccount'])
        self.assertEqual(roleName, awscoops_database['roleName'])
        self.assertEqual(externalId, awscoops_database['externalId'])
        self.assertEqual(projectId, awscoops_database['projectId'])
        self.assertEqual(organizationId, awscoops_database['organizationId'])
        self.assertEqual(description, awscoops_database['description'])
        self.assertEqual(createdAt, awscoops_database['createdAt'])
        self.assertEqual(updatedAt, awscoops_database['updatedAt'])
        self.assertEqual(members, awscoops_database['members'])
        self.assertEqual(members, 0)
        self.assertEqual(status_code, HTTPStatus.OK.value)
        pm_awsAccountCoops.delete_awscoops(trace_id, id)
コード例 #4
0
 def tearDown(self):
     num = 1
     while num < 4:
         pm_affiliation.delete_affiliation(user_id.format(str(num)),
                                           organization_id)
         num += 1
     pm_projects.delete_projects(trace_id, project_id)
     pm_organizations.delete_organization(trace_id, organization_id)
     pm_awsAccountCoops.delete_awscoops(trace_id,
                                        awscoops_template["CoopID"])
     pm_awsAccountCoops.delete_awscoops(trace_id, coop_id.format(str(999)))
     pm_awsAccountCoops.delete_awscoops(trace_id, coop_id_members_enable)
コード例 #5
0
def delete_project(task_id, project_id):
    pm_logger = common_utils.begin_logger(task_id, __name__,
                                          inspect.currentframe())
    # get list awscoops with key project_id
    try:
        list_awscoops = pm_awsAccountCoops.query_awscoop_project_index(
            task_id, project_id)
    except PmError as e:
        pm_logger.error("AWSアカウント連携情報取得に失敗しました。: ProjectID=%s", project_id)
        pm_logger.error(e)
        return False

    for awscoop_item in list_awscoops:
        coop_id = awscoop_item["CoopID"]
        try:
            pm_awsAccountCoops.delete_awscoops(task_id, coop_id)
        except PmError as e:
            pm_logger.error("AWSアカウント連携情報削除に失敗しました。: CoopID=%s", coop_id)
            pm_logger.error(e)
            return False

    # get list security check webhook with key project_id
    try:
        list_security_check_webhooks = pm_securityCheckWebhook.query_project_index(
            task_id, project_id)
    except PmError as e:
        pm_logger.error("チェック実行Webhook情報の取得に失敗しました。: ProjectID=%s", project_id)
        pm_logger.error(e)
        return False

    for security_check_webhook in list_security_check_webhooks:
        security_check_webhook_id = security_check_webhook[
            "SecurityCheckWebhookID"]

        # get list security check webhook call history with key security_check_webhook_id
        security_check_webhook_call_historys = pm_securityCheckWebhookCallHistory.query(
            task_id, security_check_webhook_id)

        # delete record pm_securityCheckWebhookCallHistory with security_check_webhook_id, create_at
        for security_check_webhook_call_history in security_check_webhook_call_historys:
            create_at = security_check_webhook_call_history["CreatedAt"]
            try:
                pm_securityCheckWebhookCallHistory.delete(
                    task_id, security_check_webhook_id, create_at)
            except PmError as e:
                pm_logger.error("チェック実行Webhook実行履歴情報削除に失敗しました。: WebhookID=%s",
                                security_check_webhook_id)
                pm_logger.error(e)
                return False

        # delete record pm_securityCheckWebhook with security_check_webhook_id
        try:
            pm_securityCheckWebhook.delete(task_id, security_check_webhook_id)
        except PmError as e:
            pm_logger.error("チェック実行Webhook情報削除に失敗しました。: WebhookID=%s",
                            security_check_webhook_id)
            pm_logger.error(e)
            return False

    # get list reports with key project_id
    try:
        list_reports = pm_reports.query_list_reports_project_index(
            task_id, project_id)
    except PmError as e:
        pm_logger.error("レポート情報取得に失敗しました。: ProjectID=%s", project_id)
        pm_logger.error(e)
        return False

    for report_item in list_reports:
        report_id = report_item["ReportID"]
        try:
            pm_reports.delete_reports(task_id, report_id)
        except PmError as e:
            pm_logger.error("レポート情報削除に失敗しました。: ProjectID=%s", project_id)
            pm_logger.error(e)
            return False
        status_delete_report = reportsBatch_logic.delete_report(
            task_id, report_id)
        if status_delete_report is False:
            return False

    return True