Skip to content

Commit dc6582c

Browse files
authored
Merge pull request #3112 from jeff1evesque/bug-3100
#3100: Ensure flask logs errors to designated file
2 parents 1e4c827 + 4ec306b commit dc6582c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1601
-823
lines changed

README.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ The following lines, indicate the application is accessible via `localhost:8080`
6868
```bash
6969
...
7070
## Create a forwarded port mapping which allows access to a specific port
71-
# within the machine from a port on the host machine. In the example below,
72-
# accessing "localhost:8080" will access port 80 on the guest machine.
73-
config.vm.network "forwarded_port", guest: 5000, host: 8080
71+
## within the machine from a port on the host machine. In the example below,
72+
## accessing "localhost:8080" will access port 80 on the guest machine.
73+
main.vm.network 'forwarded_port', guest: 5000, host: 8080
74+
main.vm.network 'forwarded_port', guest: 6000, host: 9090
7475
...
7576
```
7677

@@ -85,8 +86,8 @@ Both the web-interface, and the programmatic-api, have corresponding
8586

8687
### Web Interface
8788

88-
The [web-interface](https://github.com/jeff1evesque/machine-learning/blob/master/interface/templates/index.html)
89-
, or GUI implementation, allow users to implement the following sessions:
89+
The [web-interface](https://github.com/jeff1evesque/machine-learning/blob/master/interface/templates/index.html),
90+
or GUI implementation, allow users to implement the following sessions:
9091

9192
- `data_new`: store the provided dataset(s), within the implemented sql
9293
database.
@@ -139,13 +140,21 @@ A post request, can be implemented in python, as follows:
139140
```python
140141
import requests
141142

142-
endpoint_url = 'https://localhost:8080/load-data'
143-
headers = {'Content-Type': 'application/json'}
143+
endpoint = 'https://localhost:9090/load-data'
144+
headers = {
145+
'Authorization': 'Bearer ' + token,
146+
'Content-Type': 'application/json'
147+
}
144148

145-
requests.post(endpoint_url, headers=headers, data=json_string_here)
149+
requests.post(endpoint, headers=headers, data=json_string_here)
146150
```
147151

148-
**Note:** the above `post` request, can be implemented in a different language,
149-
respectively.
152+
**Note:** more information, regarding how to obtain a valid `token`, can be further
153+
reviewed, in the `/login` [documentation](https://github.com/jeff1evesque/machine-learning/tree/master/doc/programmatic_interface/authentication/login.rst).
150154

151155
**Note:** various `data` [attributes](https://github.com/jeff1evesque/machine-learning/blob/master/doc/programmatic_interface/data_attributes.rst) can be nested in above `POST` request.
156+
157+
It is important to remember that the [`Vagrantfile`](https://github.com/jeff1evesque/machine-learning/blob/98c7f57986cbe56ca14f8ee47859b50a08c2ef9b/Vagrantfile#L54-L55),
158+
as denoted by the above snippet, has defined two port forwards. Specifically, on
159+
the host, `8080` is reserved for the web-interface, while `9090`, is reserved for
160+
the programmatic rest-api.

Vagrantfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Vagrant.configure(2) do |config|
5252
## within the machine from a port on the host machine. In the example below,
5353
## accessing "localhost:8080" will access port 80 on the guest machine.
5454
main.vm.network 'forwarded_port', guest: 5000, host: 8080
55+
main.vm.network 'forwarded_port', guest: 6000, host: 9090
5556

5657
## Run r10k
5758
main.r10k.puppet_dir = "puppet/environment/#{puppet_environment}"

app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
'--cov', '.',
2323
'test/live_server'
2424
])
25-
elif sys.argv[1] == 'run':
25+
elif sys.argv[1] == 'run-api':
2626
args = {
2727
'prefix': 'test/hiera',
28-
'settings': ''
28+
'instance': 'programmatic'
2929
}
3030
app = create_app(args)
3131
app.run(host='0.0.0.0')

brain/database/account.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,7 @@ def get_uid(self, username):
152152
# return result
153153
if response_error:
154154
return {'error': response_error, 'result': None}
155+
elif not response['result']:
156+
return {'error': 'no uid', 'result': None}
155157
else:
156158
return {'error': None, 'result': response['result'][0][0]}

brain/load_data.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from brain.session.model_generate import ModelGenerate
1515
from brain.session.model_predict import ModelPredict
1616
from brain.database.session import Session
17-
from brain.database.account import Account
1817

1918

2019
class Load_Data(object):
@@ -31,7 +30,7 @@ class Load_Data(object):
3130
3231
'''
3332

34-
def __init__(self, data, username=None):
33+
def __init__(self, data, uid=None):
3534
'''
3635
3736
This constructor is responsible for defining class variables.
@@ -47,17 +46,13 @@ def __init__(self, data, username=None):
4746
]
4847
self.list_error = []
4948

50-
# flask session user
51-
if 'uid' in session and session['uid']:
52-
self.uid = session['uid']
49+
# programmatic api: flask jwt-token user
50+
if uid:
51+
self.uid = uid
5352

54-
# flask jwt-token user
55-
elif username:
56-
uid = Account().get_uid(username)
57-
if uid['result']:
58-
self.uid = uid['result']
59-
else:
60-
self.uid = current_app.config.get('USER_ID')
53+
# web interface: flask session user
54+
elif (not uid and 'uid' in session and session['uid']):
55+
self.uid = session['uid']
6156

6257
# unauthenticated user
6358
else:
@@ -89,7 +84,6 @@ def load_data_new(self):
8984
}
9085

9186
else:
92-
print session.get_errors()
9387
response = {
9488
'status': 1,
9589
'msg': 'Dataset(s) not uploaded into database',

doc/programmatic_interface/authentication/login.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ a valid token, to the ``/load-data`` endpoint:
3232
3333
# login and get flask-jwt token
3434
login = client.post(
35-
'/login',
35+
'https://localhost:9090/login',
3636
headers={'Content-Type': 'application/json'},
3737
data=payload
3838
)
3939
token = login.json['access_token']
4040
4141
# provide flask-jwt token
42-
login = client.post(
43-
'/load-data',
42+
res = client.post(
43+
'https://localhost:9090/load-data',
4444
headers={
4545
'Authorization': 'Bearer ' + token,
4646
'Content-Type': 'application/json'

doc/programmatic_interface/data/data_append.rst

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,13 @@ the ``data`` attribute, in a given ``POST`` request:
2323
2424
import requests
2525
26-
endpoint_url = 'https://localhost:8080/load-data'
27-
headers = {'Content-Type': 'application/json'}
28-
29-
requests.post(endpoint_url, headers=headers, data=json_string_here)
30-
31-
To submit a ``/load-data`` request, as a valid authenticated user, a valid token
32-
must be suppied to the ``headers``:
33-
34-
.. code:: python
35-
36-
import requests
37-
38-
endpoint_url = 'https://localhost:8080/load-data'
39-
headers={
26+
endpoint = 'https://localhost:9090/load-data'
27+
headers = {
4028
'Authorization': 'Bearer ' + token,
4129
'Content-Type': 'application/json'
42-
},
30+
}
4331
44-
requests.post(endpoint_url, headers=headers, data=json_string_here)
32+
requests.post(endpoint, headers=headers, data=json_string_here)
4533
4634
**Note:** more information, regarding how to obtain a valid ``token``, can be further
4735
reviewed, in the ``/login`` `documentation <https://github.com/jeff1evesque/machine-learning/tree/master/doc/programmatic_interface/authentication/login.rst>`_.

doc/programmatic_interface/data/data_new.rst

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,13 @@ the ``data`` attribute, in a given ``POST`` request:
2323
2424
import requests
2525
26-
endpoint_url = 'https://localhost:8080/load-data'
27-
headers = {'Content-Type': 'application/json'}
28-
29-
requests.post(endpoint_url, headers=headers, data=json_string_here)
30-
31-
To submit a ``/load-data`` request, as a valid authenticated user, a valid token
32-
must be suppied to the ``headers``:
33-
34-
.. code:: python
35-
36-
import requests
37-
38-
endpoint_url = 'https://localhost:8080/load-data'
39-
headers={
26+
endpoint = 'https://localhost:9090/load-data'
27+
headers = {
4028
'Authorization': 'Bearer ' + token,
4129
'Content-Type': 'application/json'
42-
},
30+
}
4331
44-
requests.post(endpoint_url, headers=headers, data=json_string_here)
32+
requests.post(endpoint, headers=headers, data=json_string_here)
4533
4634
**Note:** more information, regarding how to obtain a valid ``token``, can be further
4735
reviewed, in the ``/login`` `documentation <https://github.com/jeff1evesque/machine-learning/tree/master/doc/programmatic_interface/authentication/login.rst>`_.

doc/programmatic_interface/model/model_generate.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ the ``data`` attribute, in a given ``POST`` request:
1717
1818
import requests
1919
20-
endpoint_url = 'https://localhost:8080/load-data'
21-
headers = {'Content-Type': 'application/json'}
20+
endpoint = 'https://localhost:9090/load-data'
21+
headers = {
22+
'Authorization': 'Bearer ' + token,
23+
'Content-Type': 'application/json'
24+
}
2225
23-
requests.post(endpoint_url, headers=headers, data=json_string_here)
26+
requests.post(endpoint, headers=headers, data=json_string_here)
27+
28+
**Note:** more information, regarding how to obtain a valid ``token``, can be further
29+
reviewed, in the ``/login`` `documentation <https://github.com/jeff1evesque/machine-learning/tree/master/doc/programmatic_interface/authentication/login.rst>`_.
2430

2531
The following properties define the above ``data`` attribute:
2632

doc/programmatic_interface/predict/model_predict.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ the ``data`` attribute, in a given ``POST`` request:
1717
1818
import requests
1919
20-
endpoint_url = 'https://localhost:8080/load-data'
21-
headers = {'Content-Type': 'application/json'}
20+
endpoint = 'https://localhost:9090/load-data'
21+
headers = {
22+
'Authorization': 'Bearer ' + token,
23+
'Content-Type': 'application/json'
24+
}
2225
23-
requests.post(endpoint_url, headers=headers, data=json_string_here)
26+
requests.post(endpoint, headers=headers, data=json_string_here)
27+
28+
**Note:** more information, regarding how to obtain a valid ``token``, can be further
29+
reviewed, in the ``/login`` `documentation <https://github.com/jeff1evesque/machine-learning/tree/master/doc/programmatic_interface/authentication/login.rst>`_.
2430

2531
The following properties define the above ``data`` attribute:
2632

0 commit comments

Comments
 (0)