Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
result = m.TaskResult(task=task, status='ok', host=host, result=msg)
ctx = dict(
playbook=playbook,
play=play,
file=playbook_file,
task=task,
host=host,
result=result)
if gather_facts:
facts = m.HostFacts(host=host, values='{"fact": "value"}')
ctx['facts'] = facts
if ara_record:
data = m.Data(playbook=playbook, key='test key', value='test value')
ctx['data'] = data
for obj in ctx.values():
if hasattr(obj, 'start'):
obj.start()
db.session.add(obj)
db.session.commit()
if complete:
stats = m.Stats(playbook=playbook, host=host)
ctx['stats'] = stats
db.session.add(stats)
ctx['playbook'].complete = True
for obj in ctx.values():
def test_duplicate_data(self):
data = m.Data(
playbook=self.playbook,
key='test key',
value='another value'
)
m.db.session.add(data)
with self.assertRaises(Exception):
m.db.session.commit()
m.db.create_all()
self.playbook = m.Playbook(path='testing.yml')
self.play = m.Play(
name='test play',
playbook=self.playbook,
)
self.task = m.Task(
name='test task',
play=self.play,
playbook=self.playbook,
)
self.data = m.Data(
playbook=self.playbook,
key='test key',
value='test value'
)
self.host = m.Host(
name='localhost',
playbook=self.playbook,
)
self.host_facts = m.HostFacts(
host=self.host,
values=json.dumps('{"fact": "value"}')
)
self.task_result = m.TaskResult(
def test_data(self):
data = m.Data.query.get(self.data.id)
self.assertEqual(data.playbook_id, self.playbook.id)
self.assertEqual(data.key, 'test key')
self.assertEqual(data.value, 'test value')
def create_or_update_key(self, playbook_id, key, value, type):
try:
data = (models.Data.query
.filter_by(key=key)
.filter_by(playbook_id=playbook_id)
.one())
data.value = value
data.type = type
except models.NoResultFound:
data = models.Data(playbook_id=playbook_id,
key=key,
value=value,
type=type)
db.session.add(data)
db.session.commit()
return data
def take_action(self, args):
try:
if args.playbook:
data = (models.Data.query
.filter_by(playbook_id=args.playbook)
.filter((models.Data.id == args.key) |
(models.Data.key == args.key)).one())
else:
data = models.Data.query.filter_by(id=args.key).one()
except (models.NoResultFound, models.MultipleResultsFound):
raise RuntimeError('Key %s could not be found' % args.key)
return [[field.name for field in SHOW_FIELDS],
[field(data) for field in SHOW_FIELDS]]
hosts = models.Host.query
facts = models.HostFacts.query
playbooks = models.Playbook.query
records = models.Data.query
tasks = models.Task.query
results = models.TaskResult.query
if current_app.config['ARA_PLAYBOOK_OVERRIDE'] is not None:
override = current_app.config['ARA_PLAYBOOK_OVERRIDE']
files = files.filter(models.File.playbook_id.in_(override))
facts = (facts
.join(models.Host)
.filter(models.Host.playbook_id.in_(override)))
hosts = hosts.filter(models.Host.playbook_id.in_(override))
playbooks = playbooks.filter(models.Playbook.id.in_(override))
records = records.filter(models.Data.playbook_id.in_(override))
tasks = tasks.filter(models.Task.playbook_id.in_(override))
results = (results
.join(models.Task)
.filter(models.Task.playbook_id.in_(override)))
return render_template(
'about.html',
active='about',
files=fast_count(files),
hosts=fast_count(hosts),
facts=fast_count(facts),
playbooks=fast_count(playbooks),
records=fast_count(records),
tasks=fast_count(tasks),
results=fast_count(results)
)
def take_action(self, args):
try:
if args.playbook:
data = (models.Data.query
.filter_by(playbook_id=args.playbook)
.filter((models.Data.id == args.key) |
(models.Data.key == args.key)).one())
else:
data = models.Data.query.filter_by(id=args.key).one()
except (models.NoResultFound, models.MultipleResultsFound):
raise RuntimeError('Key %s could not be found' % args.key)
return [[field.name for field in SHOW_FIELDS],
[field(data) for field in SHOW_FIELDS]]
def ajax_records(playbook):
records = (models.Data.query
.filter(models.Data.playbook_id == playbook))
if not utils.fast_count(records):
abort(404)
jinja = current_app.jinja_env
record_key = jinja.get_template('ajax/record_key.html')
record_value = jinja.get_template('ajax/record_value.html')
results = dict()
results['data'] = list()
log.debug('Loading records')
for record in records:
key = record_key.render(record=record)
value = record_value.render(record=record)
results['data'].append([key, value])