コード例 #1
0
    def mutate(self, info, **parameters):
        success = False
        files_data = parameters['files_data']
        uploaded_file = info.context.FILES['1']
        project_name = parameters['project_name']
        user_email = util.get_jwt_content(info.context)['user_email']
        add_file = resources.create_file(files_data,
                                         uploaded_file,
                                         project_name,
                                         user_email)
        if add_file:
            resources.send_mail(project_name,
                                user_email,
                                files_data,
                                'added',
                                'file')

            success = True
        else:
            rollbar.report_message('Error: \
An error occurred uploading file', 'error', info.context)
        if success:
            util.invalidate_cache(project_name)
            util.cloudwatch_log(info.context, 'Security: Added evidence files to \
                {project} project succesfully'.format(project=project_name))
        else:
            util.cloudwatch_log(info.context, 'Security: Attempted to add evidence files \
                from {project} project'.format(project=project_name))
        ret = AddFiles(success=success, resources=Resource(project_name))
        return ret
コード例 #2
0
    def mutate(self,
               info, resource_data: Dict[str, Any], project_name: str, res_type: str) -> object:
        success = False
        user_email = util.get_jwt_content(info.context)['user_email']
        add_res = resources.create_resource(resource_data, project_name, res_type, user_email)
        if add_res:
            resources.send_mail(project_name,
                                user_email,
                                resource_data,
                                'added',
                                res_type)
            success = True
        else:
            rollbar.report_message('Error: \
An error occurred adding resource', 'error', info.context)
        if success:
            util.invalidate_cache(project_name)
            util.cloudwatch_log(info.context, 'Security: Added resources to \
                {project} project succesfully'.format(project=project_name))
        else:
            util.cloudwatch_log(info.context, 'Security: Attempted to add resources \
                from {project} project'.format(project=project_name))
        ret = AddResources(success=success,
                           resources=Resource(project_name))
        return ret
コード例 #3
0
    def mutate(_, info, project_name: str, repo: Dict[str, str],
               state: str) -> object:
        user_email = util.get_jwt_content(info.context)['user_email']
        success = resources.update_resource(
            repo, project_name, 'repository', user_email)

        if success:
            util.invalidate_cache(project_name)
            util.cloudwatch_log(
                info.context,
                f'Security: Updated repository state in {project_name} '
                'project succesfully')

            action = 'activated' if state == 'ACTIVE' else 'deactivated'
            resources.send_mail(
                project_name, user_email, [repo], action, 'repository')
        else:
            rollbar.report_message(
                'An error occurred updating repository state',
                level='error',
                payload_data=locals())
            util.cloudwatch_log(
                info.context,
                'Security: Attempted to update repository state in '
                f'{project_name} project')

        return UpdateRepository(success=success)
コード例 #4
0
    def mutate(self,
               info, resource_data: Dict[str, Any], project_name: str, res_type: str) -> object:
        success = False
        user_email = util.get_jwt_content(info.context)['user_email']
        update_res = resources.update_resource(resource_data, project_name, res_type, user_email)
        if update_res:
            resources.send_mail(project_name,
                                user_email,
                                [resource_data],
                                'activated'
                                if resource_data.get('state') == 'INACTIVE'
                                else 'deactivated',
                                res_type)
            success = True
        else:
            rollbar.report_message('Error: \
An error occurred updating resource', 'error', info.context)
        if success:
            util.invalidate_cache(project_name)
            util.cloudwatch_log(info.context, 'Security: Updated resources from \
                {project} project succesfully'.format(project=project_name))
        else:
            util.cloudwatch_log(info.context, 'Security: Attempted to update resources \
                from {project} project'.format(project=project_name))
        ret = UpdateResources(success=success,
                              resources=Resource(project_name))
        return ret
コード例 #5
0
    def mutate(_, info, envs: _List[Dict[str, str]],
               project_name: str) -> object:
        user_email = util.get_jwt_content(info.context)['user_email']
        success = resources.create_resource(
            envs, project_name, 'environment', user_email)

        if success:
            util.invalidate_cache(project_name)
            util.cloudwatch_log(
                info.context,
                f'Security: Added envs to {project_name} project succesfully')
            resources.send_mail(
                project_name, user_email, envs, 'added', 'environment')
        else:
            rollbar.report_message(
                'An error occurred adding environments',
                level='error',
                payload_data=locals())
            util.cloudwatch_log(
                info.context,
                f'Security: Attempted to add envs to {project_name} project')

        return AddRepositories(success=success)
コード例 #6
0
    def mutate(self, info, files_data: Dict[str, Any], project_name: str) -> object:
        success = False
        file_name = files_data.get('fileName')
        user_email = util.get_jwt_content(info.context)['user_email']
        remove_file = resources.remove_file(file_name, project_name)
        if remove_file:
            resources.send_mail(project_name,
                                user_email,
                                [files_data],
                                'removed',
                                'file')
            success = True
        else:
            rollbar.report_message('Error: \
An error occurred removing file', 'error', info.context)
        if success:
            util.invalidate_cache(project_name)
            util.cloudwatch_log(info.context, 'Security: Removed Files from \
                {project} project succesfully'.format(project=project_name))
        else:
            util.cloudwatch_log(info.context, 'Security: Attempted to remove files \
                from {project} project'.format(project=project_name))
        ret = RemoveFiles(success=success, resources=Resource(project_name))
        return ret
コード例 #7
0
def resolve_add_repositories(
    _, info, repos: _List[Dict[str, str]], project_name: str
) -> object:
    """Resolve add_repositories mutation."""
    user_email = util.get_jwt_content(info.context)['user_email']
    success = resources.create_resource(
        repos, project_name, 'repository', user_email)

    if success:
        util.invalidate_cache(project_name)
        util.cloudwatch_log(
            info.context,
            f'Security: Added repos to {project_name} project succesfully')
        resources.send_mail(
            project_name, user_email, repos, 'added', 'repository')
    else:
        rollbar.report_message(
            'An error occurred adding repositories',
            level='error',
            payload_data=locals())
        util.cloudwatch_log(
            info.context,
            f'Security: Attempted to add repos to {project_name} project')
    return dict(success=success)