How to use the ara.api.v1.utils function in ara

To help you get started, we’ve selected a few ara examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dmsimard / ara-archive / ara / api / v1 / records.py View on Github external
args = parser.parse_args()

        record = Record.query.get(args.id)
        if not record:
            abort(404, message="Record {} doesn't exist".format(args.id),
                  help=api_utils.help(parser.args, RECORD_FIELDS))

        keys = ['key', 'value', 'type']
        updates = 0
        for key in keys:
            if getattr(args, key) is not None:
                updates += 1
                setattr(record, key, getattr(args, key))
        if not updates:
            abort(400, message="No parameters to update provided",
                  help=api_utils.help(parser.args, RECORD_FIELDS))

        db.session.add(record)
        db.session.commit()

        return self.get(id=record.id)
github dmsimard / ara-archive / ara / api / v1 / tasks.py View on Github external
"""
        parser = self._get_parser()

        if id is not None:
            task = _find_tasks(id=id)
            if task is None:
                abort(404, message="Task {} doesn't exist".format(id),
                      help=api_utils.help(parser.args, TASK_FIELDS))

            return marshal(task, TASK_FIELDS)

        args = parser.parse_args()
        tasks = _find_tasks(**args)
        if not tasks:
            abort(404, message="No tasks found for this query",
                  help=api_utils.help(parser.args, TASK_FIELDS))

        return marshal(tasks, TASK_FIELDS)
github dmsimard / ara-archive / ara / api / v1 / playbooks.py View on Github external
def get(self, id=None):
        """
        Retrieves one or many playbooks based on the request and the query
        """
        parser = self._get_parser()

        if id is not None:
            playbook = _find_playbooks(id=id)
            if playbook is None:
                abort(404, message="Playbook {} doesn't exist".format(id),
                      help=api_utils.help(parser.args, PLAYBOOK_FIELDS))

            return marshal(playbook, PLAYBOOK_FIELDS)

        args = parser.parse_args()
        playbooks = _find_playbooks(**args)
        if not playbooks:
            abort(404, message='No playbooks found for this query',
                  help=api_utils.help(parser.args, PLAYBOOK_FIELDS))

        return marshal(playbooks, PLAYBOOK_FIELDS)
github dmsimard / ara-archive / ara / api / v1 / hosts.py View on Github external
'id', dest='id',
            type=int,
            location='values',
            required=False,
            help='Search with the id of the host'
        )
        parser.add_argument(
            'playbook_id', dest='playbook_id',
            type=int,
            location='values',
            required=False,
            help='Search hosts for a playbook id'
        )
        parser.add_argument(
            'name', dest='name',
            type=api_utils.encoded_input,
            location='values',
            required=False,
            help='Search with the name (full or part) of a host'
        )
        return parser
github dmsimard / ara-archive / ara / api / v1 / hosts.py View on Github external
def _post_parser():
        parser = reqparse.RequestParser()
        parser.add_argument(
            'playbook_id', dest='playbook_id',
            type=int,
            location='json',
            required=True,
            help='The playbook_id of the host'
        )
        parser.add_argument(
            'name', dest='name',
            type=api_utils.encoded_input,
            location='json',
            required=True,
            help='The name of the host'
        )
        parser.add_argument(
            'facts', dest='facts',
            type=dict,
            location='json',
            required=False,
            default={},
            help='The facts for the host'
        )
        parser.add_argument(
            'changed', dest='changed',
            type=int,
            location='json',
github dmsimard / ara-archive / ara / api / v1 / results.py View on Github external
parser = self._post_parser()
        args = parser.parse_args()

        # Validate and retrieve the task reference
        task = Task.query.get(args.task_id)
        if not task:
            abort(404,
                  message="Task {} doesn't exist".format(args.task_id),
                  help=api_utils.help(parser.args, RESULT_FIELDS))

        # Validate and retrieve the host reference
        host = Host.query.get(args.host_id)
        if not host:
            abort(404,
                  message="Host {} doesn't exist".format(args.host_id),
                  help=api_utils.help(parser.args, RESULT_FIELDS))

        result = Result(
            playbook=task.playbook,
            host=host,
            play=task.play,
            task=task,
            status=args.status,
            changed=args.changed,
            failed=args.failed,
            skipped=args.skipped,
            unreachable=args.unreachable,
            ignore_errors=args.ignore_errors,
            result=args.result,
            started=args.started,
            ended=args.ended
        )
github dmsimard / ara-archive / ara / api / v1 / files.py View on Github external
'playbook_id', dest='playbook_id',
            type=int,
            location='json',
            required=True,
            help='The playbook_id of the file'
        )
        parser.add_argument(
            'path', dest='path',
            type=str,
            location='json',
            required=True,
            help='The path of the file'
        )
        parser.add_argument(
            'content', dest='content',
            type=api_utils.encoded_input,
            location='json',
            required=True,
            help='The content of the file'
        )
        return parser
github dmsimard / ara-archive / ara / api / v1 / files.py View on Github external
"""
        parser = self._get_parser()

        if id is not None:
            file_ = _find_files(id=id)
            if file_ is None:
                abort(404, message="File {} doesn't exist".format(id),
                      help=api_utils.help(parser.args, FILE_FIELDS))

            return marshal(file_, FILE_FIELDS)

        args = parser.parse_args()
        files = _find_files(**args)
        if not files:
            abort(404, message='No files found for this query',
                  help=api_utils.help(parser.args, FILE_FIELDS))

        return marshal(files, FILE_FIELDS)
github dmsimard / ara-archive / ara / api / v1 / tasks.py View on Github external
'play_id', dest='play_id',
            type=int,
            location='values',
            required=False,
            help='Search tasks for a play id'
        )
        parser.add_argument(
            'file_id', dest='file_id',
            type=int,
            location='values',
            required=False,
            help='Search tasks for a file id'
        )
        parser.add_argument(
            'name', dest='name',
            type=api_utils.encoded_input,
            location='values',
            required=False,
            help='Search with the name (full or part) of a task'
        )
        parser.add_argument(
            'action', dest='action',
            type=str,
            location='values',
            required=False,
            help='Search with the action (full or part) of a task'
        )
        parser.add_argument(
            'lineno', dest='lineno',
            type=int,
            location='values',
            required=False,
github dmsimard / ara-archive / ara / api / v1 / plays.py View on Github external
def get(self, id=None):
        """
        Retrieves one or many plays based on the request and the query
        """
        parser = self._get_parser()

        if id is not None:
            play = _find_plays(id=id)
            if play is None:
                abort(404, message="Play {} doesn't exist".format(id),
                      help=api_utils.help(parser.args, PLAY_FIELDS))

            return marshal(play, PLAY_FIELDS)

        args = parser.parse_args()
        plays = _find_plays(**args)
        if not plays:
            abort(404, message="No plays found for this query",
                  help=api_utils.help(parser.args, PLAY_FIELDS))

        return marshal(plays, PLAY_FIELDS)