Compare commits
6 Commits
3e4843ff88
...
7923b6e7d7
Author | SHA1 | Date |
---|---|---|
oscar alvarez | 7923b6e7d7 | |
oscar alvarez | 6bc4181acb | |
oscar alvarez | 0531ccc38d | |
oscar alvarez | 6388beef72 | |
oscar alvarez | 702f18fc73 | |
oscar alvarez | bcb6879130 |
13
INSTALL.md
13
INSTALL.md
|
@ -1,10 +1,8 @@
|
|||
|
||||
# TRYTON INSTALL API
|
||||
|
||||
Esta guia describe los métodos para conectarse a la API de Tryton,
|
||||
creada por Presik SAS.
|
||||
|
||||
|
||||
## Dependences
|
||||
|
||||
Install next libraries:
|
||||
|
@ -30,19 +28,16 @@ Create a directory in home called ".flask"in Home, for add configuration files.
|
|||
|
||||
mkdir ~/.flask
|
||||
|
||||
|
||||
Add file dash.ini to .flask directory
|
||||
|
||||
cp {MYPATH}/predash/dash.ini ~/.flask/dash.ini
|
||||
|
||||
|
||||
Edit dash.ini and adjust for your company, database, etc.
|
||||
|
||||
Test gunicorn is installed starting app from terminal, inside predash_api
|
||||
directory, (inside virtualenv):
|
||||
|
||||
gunicorn --bind 0.0.0.0:5010 wsgi:app
|
||||
|
||||
gunicorn --bind 0.0.0.0:5010 wsgi:app --access-logfile '-'
|
||||
|
||||
Test gun_config.py file starting app:
|
||||
|
||||
|
@ -52,7 +47,6 @@ Create predash_api.service file for systemd:
|
|||
|
||||
sudo nano /etc/systemd/system/predash_api.service
|
||||
|
||||
|
||||
Add this text to the predash_api.service file, don't forget to change "User" and
|
||||
path to "WorkingDirectory" directory
|
||||
|
||||
|
@ -65,23 +59,20 @@ path to "WorkingDirectory" directory
|
|||
[Service]
|
||||
User=XXXXX
|
||||
WorkingDirectory=/home/psk/predash/predash-api
|
||||
ExecStart=/home/psk/.virtualenvs/tryton50/bin/gunicorn -c gun_config.py wsgi:app
|
||||
ExecStart=/home/psk/.virtualenvs/tryton50/bin/gunicorn -c gun_config.py wsgi:app --access-logfile '-'
|
||||
#ExecStop=
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
|
||||
Enable the service
|
||||
|
||||
sudo systemctl enable predash_api.service
|
||||
|
||||
|
||||
Start the service
|
||||
|
||||
sudo systemctl start predash_api.service
|
||||
|
||||
|
||||
Check status
|
||||
|
||||
sudo systemctl status predash_api.service
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import logging
|
||||
import os
|
||||
from decimal import Decimal
|
||||
import simplejson as json
|
||||
|
@ -25,6 +24,7 @@ config.read(config_file)
|
|||
trytond_config = get_config('trytond_config')
|
||||
host_ = config.get('General', 'host')
|
||||
API_KEY = config.get('Auth', 'api_key')
|
||||
API_KEY_VO = config.get('Auth', 'api_key_vo')
|
||||
|
||||
|
||||
# The actual decorator function
|
||||
|
@ -32,7 +32,10 @@ def require_appkey(view_function):
|
|||
@wraps(view_function)
|
||||
# the new, post-decoration function. Note *args and **kwargs here.
|
||||
def decorated_function(*args, **kwargs):
|
||||
if request.headers.get('Authorization') and request.headers.get('Authorization') == API_KEY:
|
||||
auth = request.headers.get('Authorization')
|
||||
print( 'esta llego mano ... ', auth)
|
||||
print( 'esta clave ... ', API_KEY, ' : ', API_KEY_VO)
|
||||
if auth and auth in [API_KEY, API_KEY_VO]:
|
||||
return view_function(*args, **kwargs)
|
||||
else:
|
||||
abort(401)
|
||||
|
@ -62,7 +65,7 @@ def create_app(dbname):
|
|||
tryton = Tryton(current_app)
|
||||
_pool = tryton.pool
|
||||
except:
|
||||
logging.warning('Error database disabled or unknown error: %s' % dbname)
|
||||
print('Error database disabled or unknown error: %s' % dbname)
|
||||
return None
|
||||
|
||||
@app.errorhandler(InvalidAPIUsage)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import logging
|
||||
import os
|
||||
from decimal import Decimal
|
||||
import simplejson as json
|
||||
|
@ -62,7 +61,7 @@ def create_app(dbname):
|
|||
tryton = Tryton(current_app)
|
||||
_pool = tryton.pool
|
||||
except:
|
||||
logging.warning('Error database disabled or unknown error: %s' % dbname)
|
||||
print('Error database disabled or unknown error: %s' % dbname)
|
||||
return None
|
||||
|
||||
@app.errorhandler(InvalidAPIUsage)
|
||||
|
|
|
@ -11,7 +11,7 @@ if os.path.exists(certificate_):
|
|||
else:
|
||||
print('Mode: Http')
|
||||
|
||||
bind = '0.0.0.0:5010'
|
||||
# bind = '0.0.0.0:5010'
|
||||
proc_name = 'api-escool'
|
||||
worker_connections = 1000
|
||||
workers = 2
|
||||
|
|
21
test_api.py
21
test_api.py
|
@ -2,10 +2,9 @@ import requests
|
|||
import simplejson as json
|
||||
|
||||
# The port is 5090 by default
|
||||
api_url = 'localhost:5010'
|
||||
database = 'DEMO'
|
||||
# api_url = '144.202.34.104:5010'
|
||||
# database = 'ESCOOLDEMO'
|
||||
api_url = 'cloud4.presik.com:5010'
|
||||
database = 'ESDEMO'
|
||||
API_KEY = 'dre67hidns5e862envr'
|
||||
|
||||
api = '/'.join(['http:/', api_url, database])
|
||||
|
||||
|
@ -21,6 +20,11 @@ def test_get_countries():
|
|||
return route, None
|
||||
|
||||
|
||||
def test_get_departments():
|
||||
route = api + '/departments'
|
||||
return route, None
|
||||
|
||||
|
||||
def test_search_party():
|
||||
body = {
|
||||
'id_number': '815439654'
|
||||
|
@ -390,13 +394,16 @@ def test_save_lab_order_remote():
|
|||
if __name__ == "__main__":
|
||||
# This method create a Sale Order (Este metodo crea una venta)
|
||||
|
||||
route, body = test_products_by_shop()
|
||||
route, body = test_get_countries()
|
||||
# route, body = test_products_by_shop()
|
||||
# route, body = test_save_lab_order_remote()
|
||||
if body:
|
||||
data = json.dumps(body)
|
||||
result = requests.post(route, data=data)
|
||||
result = requests.post(
|
||||
route, data=data, headers={'Authorization': API_KEY}
|
||||
)
|
||||
else:
|
||||
result = requests.get(route)
|
||||
result = requests.get(route, headers={'Authorization': API_KEY})
|
||||
|
||||
values = result.json()
|
||||
if isinstance(values, dict):
|
||||
|
|
Loading…
Reference in New Issue