11-19-2021, 05:53 AM
(This post was last modified: 11-19-2021, 05:56 AM by LazyLeopard.)
(11-18-2021, 04:58 PM)LazyLeopard Wrote:(11-18-2021, 10:10 AM)listy Wrote: 1. Where are you running this code? From the script editor as admin ?I am running this code from a python repl from my host against the docker 4.8.0 image.
2. Print current login and ticket using api to make sure
I login using the get_ticket + set_ticket sequence.
For your convenience:
test_tactic.py
Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import tactic_client_lib as tcl
stub = tcl.TacticServerStub.get(setup=False)
stub.set_server('localhost')
ticket = stub.get_ticket('tactic', 'tactic123')
stub.set_ticket(ticket)
print('\nAcquired tactic ticket', ticket)
project_codes = stub.eval("@GET(sthpw/project.code)")
print('Project codes:', project_codes)
print('\nAccess status for tactic:')
print('===========================')
for pc in project_codes:
access = stub.check_access('project', {'code': pc}, 'allow')
print('project {pc} is {noaccess}accessible'.format(
pc=pc, noaccess='' if access else 'NOT '))
ticket = stub.query(
'sthpw/ticket', filters=[('login', 'admin')], order_bys=['timestamp desc'],
single=True)
print('\nAcquired ticket {ticket} for {login}!'.format(**ticket))
stub.set_ticket(ticket['ticket'])
print('\nAccess status for {login}:'.format(**ticket))
print('===========================')
for pc in project_codes:
access = stub.check_access('project', {'code': pc}, 'allow')
print('project {pc} is {noaccess}accessible'.format(
pc=pc, noaccess='' if access else 'not '))
Windows CMD
Code:
(venv) D:\talha.ahmed\Workspace>python test_tactic.py
Acquired tactic ticket cbb9ad3e6aeca620192
Project codes: ['admin', 'episodic', 'important_project', 'new_project', 'sthpw']
Access status for tactic:
===========================
project admin is NOT accessible
project episodic is NOT accessible
project important_project is NOT accessible
project new_project is NOT accessible
project sthpw is NOT accessible
Acquired ticket 5cdf6ef2992669e88b2 for admin!
Access status for admin:
===========================
project admin is accessible
project episodic is accessible
project important_project is accessible
project new_project is accessible
project sthpw is accessible