How to use the ara.webapp.create_app 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 ansible-community / ara / tests / unit / test_cli.py View on Github external
def create_app(self):
        return w.create_app(self)
github ansible-community / ara / tests / unit / test_app.py View on Github external
def create_app(self):
        return w.create_app(self)
github dmsimard / ara-archive / ara / plugins / actions / ara_read.py View on Github external
def run(self, tmp=None, task_vars=None):
        if task_vars is None:
            task_vars = dict()

        if not HAS_ARA:
            result = {
                'failed': True,
                'msg': 'ARA is required to run this module.'
            }
            return result

        app = create_app()
        if not current_app:
            context = app.app_context()
            context.push()

        for arg in self._task.args:
            if arg not in self.VALID_ARGS:
                result = {
                    'failed': True,
                    'msg': '{0} is not a valid option.'.format(arg)
                }
                return result

        result = super(ActionModule, self).run(tmp, task_vars)

        playbook_id = self._task.args.get('playbook', None)
        key = self._task.args.get('key', None)
github ansible-community / ara / ara / wsgi_sqlite.py View on Github external
# The intent is that we are dealing with databases that already exist.
    # Therefore, we're not really interested in creating the database and
    # making sure that the SQL migrations are done. Toggle that off.
    # This needs to be a string, we're setting an environment variable
    os.environ['ARA_AUTOCREATE_DATABASE'] = 'false'

    msg = 'Request {request} mapped to {database} with root {root}'.format(
        request=request,
        database='sqlite:///{}'.format(database),
        root=match.group('path')
    )
    logger.debug(msg)

    from ara.webapp import create_app
    try:
        app = create_app()
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///{}'.format(database)
        app.config['APPLICATION_ROOT'] = environ['PATH_INFO']
        return app(environ, start_response)
    except Exception as e:
        # We're staying relatively vague on purpose to avoid disclosure
        logger.error('ARA bootstrap failure for %s: %s' % (database, str(e)))
        return bad_request(environ, start_response, 'ARA bootstrap failure.')
github ansible-community / ara / ara / plugins / actions / ara_read.py View on Github external
}
                return result

        result = super(ActionModule, self).run(tmp, task_vars)

        playbook_id = self._task.args.get('playbook', None)
        key = self._task.args.get('key', None)

        required = ['key']
        for parameter in required:
            if not self._task.args.get(parameter):
                result['failed'] = True
                result['msg'] = '{0} parameter is required'.format(parameter)
                return result

        app = create_app()
        if not current_app:
            context = app.app_context()
            context.push()

        if playbook_id is None:
            # Retrieve playbook_id from the cached context
            playbook_id = current_app._cache['playbook']

        try:
            data = self.get_key(playbook_id, key)
            if data:
                result['key'] = data.key
                result['value'] = data.value
                result['type'] = data.type
                result['playbook_id'] = data.playbook_id
            msg = 'Sucessfully read data for the key {0}'.format(data.key)
github dmsimard / ara-archive / ara / plugins / callbacks / log_ara.py View on Github external
from ansible.plugins.callback import CallbackBase
from ara import models
from ara.models import db
from ara.webapp import create_app
from datetime import datetime
from distutils.version import LooseVersion
from oslo_serialization import jsonutils

# To retrieve Ansible CLI options
try:
    from __main__ import cli
except ImportError:
    cli = None

LOG = logging.getLogger('ara.callback')
app = create_app()


class IncludeResult(object):
    """
    This is used by the v2_playbook_on_include callback to synthesize a task
    result for calling log_task.
    """
    def __init__(self, host, path):
        self._host = host
        self._result = {'included_file': path}


class CallbackModule(CallbackBase):
    """
    Saves data from an Ansible run into a database
    """
github ansible-community / ara / ara / manage.py View on Github external
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with ARA.  If not, see .


from flask_script import commands
from flask_script import Manager
from flask_script import prompt_bool
from flask_migrate import Migrate
from flask_migrate import MigrateCommand

from ara.webapp import create_app
from ara.models import db

app = create_app()
manager = Manager(app)
manager.add_command('db', MigrateCommand)
migrate = Migrate(app, db, directory=app.config['DB_MIGRATIONS'])

# Overwrite the default runserver command to be able to pass a custom host
# and port from the config as the defaults
manager.add_command(
    "runserver",
    commands.Server(host=app.config['ARA_HOST'],
                    port=app.config['ARA_PORT'],
                    processes=8,
                    threaded=False)
)


@manager.command