Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SMART
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UNI-KLU
SMART
Commits
ab8cb3d4
Commit
ab8cb3d4
authored
Sep 14, 2020
by
Manuel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added environment variable to set global resource directory for local mode
parent
3c9e0825
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
26 additions
and
34 deletions
+26
-34
.gitignore
.gitignore
+2
-0
env_info.py
src/modules/env_info.py
+9
-0
security_util.py
src/modules/security/security_util.py
+0
-1
token_manager.py
src/modules/security/token_manager.py
+4
-7
add_bityoga_schema.py
...hub/business-logic-microservice/app/add_bityoga_schema.py
+0
-1
main.py
...participation-hub/business-logic-microservice/app/main.py
+3
-10
add_users.py
src/rest-gateway/app/add_users.py
+3
-6
main.py
src/rest-gateway/app/main.py
+3
-8
token_service.py
src/rest-gateway/app/services/token_service.py
+2
-1
No files found.
.gitignore
View file @
ab8cb3d4
...
@@ -15,3 +15,5 @@ src/modules/certificate/articonf1-chain.crt
...
@@ -15,3 +15,5 @@ src/modules/certificate/articonf1-chain.crt
src/modules/security/regular_user_credentials.json
src/modules/security/regular_user_credentials.json
src/modules/security/default_users.json
src/modules/security/default_users.json
resources/
src/modules/env_info.py
View file @
ab8cb3d4
...
@@ -2,6 +2,15 @@
...
@@ -2,6 +2,15 @@
import
os
import
os
def
get_resources_path
():
if
is_running_locally
():
try
:
return
os
.
environ
[
'ARTICONF_RESOURCES_PATH'
]
except
:
return
'/srv/articonf'
else
:
return
'/srv/articonf'
def
is_running_locally
():
def
is_running_locally
():
'''Set env var ARTICONF_LOCAL=1 to run locally.'''
'''Set env var ARTICONF_LOCAL=1 to run locally.'''
server
=
True
server
=
True
...
...
src/modules/security/security_util.py
View file @
ab8cb3d4
...
@@ -33,7 +33,6 @@ class TokenStash:
...
@@ -33,7 +33,6 @@ class TokenStash:
return
None
return
None
def
decodeToken
(
token
:
str
,
roles
:
List
[
str
]
=
[])
->
Dict
:
def
decodeToken
(
token
:
str
,
roles
:
List
[
str
]
=
[])
->
Dict
:
'''
'''
verifies the passed token on the user-microservice and returns a dictionary with the
verifies the passed token on the user-microservice and returns a dictionary with the
...
...
src/modules/security/token_manager.py
View file @
ab8cb3d4
# global import, red is normal don't worry
# global import, red is normal don't worry
import
network_constants
import
network_constants
from
env_info
import
is_running_locally
from
env_info
import
is_running_locally
,
get_resources_path
import
os
import
os
import
json
import
json
...
@@ -22,15 +22,12 @@ class TokenManager:
...
@@ -22,15 +22,12 @@ class TokenManager:
def
getToken
(
self
)
->
str
:
def
getToken
(
self
)
->
str
:
if
self
.
_token
==
None
:
if
self
.
_token
==
None
:
if
is_running_locally
():
credentials_path
=
get_resources_path
()
credentials_path
=
'../../../modules/security/'
else
:
credentials_path
=
'/srv/articonf/'
print
(
"Looking for credentials at ... "
+
str
(
credentials_path
))
print
(
"Looking for credentials at ... "
+
str
(
credentials_path
))
with
open
(
f
'{credentials_path}
regular_user_credentials.json'
)
as
file
:
with
open
(
f
'{credentials_path}
/regular_user_credentials.json'
)
as
file_handler
:
credentials
=
json
.
loads
(
file
.
read
())
credentials
=
json
.
loads
(
file
_handler
.
read
())
url
=
f
'https://{network_constants.REST_GATEWAY_HOSTNAME}:{network_constants.REST_GATEWAY_REST_PORT}/api/tokens'
url
=
f
'https://{network_constants.REST_GATEWAY_HOSTNAME}:{network_constants.REST_GATEWAY_REST_PORT}/api/tokens'
...
...
src/participation-hub/business-logic-microservice/app/add_bityoga_schema.py
View file @
ab8cb3d4
...
@@ -117,7 +117,6 @@ def add_by_layers():
...
@@ -117,7 +117,6 @@ def add_by_layers():
else
:
else
:
print
(
f
"Response: {response.status_code}: {response.text}"
)
print
(
f
"Response: {response.status_code}: {response.text}"
)
def
add_by_schema
():
def
add_by_schema
():
'''
'''
take the columns and add the mappings at the server
take the columns and add the mappings at the server
...
...
src/participation-hub/business-logic-microservice/app/main.py
View file @
ab8cb3d4
...
@@ -8,11 +8,10 @@ modules_path = '../../../modules/'
...
@@ -8,11 +8,10 @@ modules_path = '../../../modules/'
if
os
.
path
.
exists
(
modules_path
):
if
os
.
path
.
exists
(
modules_path
):
sys
.
path
.
insert
(
1
,
modules_path
)
sys
.
path
.
insert
(
1
,
modules_path
)
# load swagger config
# load swagger config
import
connexion
import
connexion
from
security
import
swagger_util
from
security
import
swagger_util
from
env_info
import
is_running_locally
from
env_info
import
is_running_locally
,
get_resources_path
app
=
connexion
.
App
(
__name__
,
specification_dir
=
'configs/'
)
app
=
connexion
.
App
(
__name__
,
specification_dir
=
'configs/'
)
...
@@ -23,23 +22,17 @@ def api_root():
...
@@ -23,23 +22,17 @@ def api_root():
return
'Endpoint of business-logic-microservice!'
return
'Endpoint of business-logic-microservice!'
# SSL configuration
# SSL configuration
try
:
certificate_path
=
get_resources_path
()
certificate_path
=
os
.
environ
[
'ARTICONF_CERTIFICATE_PATH'
]
except
KeyError
:
certificate_path
=
'/srv/articonf/'
context
=
(
os
.
path
.
normpath
(
f
'{certificate_path}/articonf1.crt'
),
os
.
path
.
normpath
(
f
'{certificate_path}/articonf1.key'
))
# certificate and key files
context
=
(
os
.
path
.
normpath
(
f
'{certificate_path}/articonf1.crt'
),
os
.
path
.
normpath
(
f
'{certificate_path}/articonf1.key'
))
# certificate and key files
if
is_running_locally
():
if
is_running_locally
():
# Local Mode
print
(
"Running locally..."
)
print
(
"Running with local settings..."
)
app
.
add_api
(
swagger_util
.
get_bundled_specs
(
Path
(
"configs/swagger_local.yml"
)),
app
.
add_api
(
swagger_util
.
get_bundled_specs
(
Path
(
"configs/swagger_local.yml"
)),
resolver
=
connexion
.
RestyResolver
(
"cms_rest_api"
))
resolver
=
connexion
.
RestyResolver
(
"cms_rest_api"
))
context
=
'adhoc'
else
:
else
:
app
.
add_api
(
swagger_util
.
get_bundled_specs
(
Path
(
"configs/swagger.yml"
)),
app
.
add_api
(
swagger_util
.
get_bundled_specs
(
Path
(
"configs/swagger.yml"
)),
resolver
=
connexion
.
RestyResolver
(
"cms_rest_api"
))
resolver
=
connexion
.
RestyResolver
(
"cms_rest_api"
))
# start app
# start app
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
print
(
context
)
app
.
run
(
host
=
'0.0.0.0'
,
port
=
5000
,
debug
=
False
,
ssl_context
=
context
)
app
.
run
(
host
=
'0.0.0.0'
,
port
=
5000
,
debug
=
False
,
ssl_context
=
context
)
src/rest-gateway/app/add_users.py
View file @
ab8cb3d4
...
@@ -11,15 +11,12 @@ if os.path.exists(modules_path):
...
@@ -11,15 +11,12 @@ if os.path.exists(modules_path):
sys
.
path
.
insert
(
1
,
modules_path
)
sys
.
path
.
insert
(
1
,
modules_path
)
from
services.user_service
import
UserService
from
services.user_service
import
UserService
from
env_info
import
is_running_locally
from
env_info
import
is_running_locally
,
get_resources_path
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
if
is_running_locally
():
resources_path
=
get_resources_path
()
path
=
f
'{modules_path}/security/default_users.json'
else
:
path
=
'/srv/articonf/default_users.json'
with
open
(
path
,
"r"
)
as
file_handler
:
with
open
(
f
'{resources_path}/default_users.json'
,
"r"
)
as
file_handler
:
content
=
file_handler
.
read
()
content
=
file_handler
.
read
()
users
=
json
.
loads
(
content
)
users
=
json
.
loads
(
content
)
...
...
src/rest-gateway/app/main.py
View file @
ab8cb3d4
...
@@ -19,7 +19,7 @@ LOGGER = logging.getLogger(__name__)
...
@@ -19,7 +19,7 @@ LOGGER = logging.getLogger(__name__)
import
connexion
import
connexion
from
security
import
swagger_util
from
security
import
swagger_util
from
env_info
import
is_running_locally
from
env_info
import
is_running_locally
,
get_resources_path
app
=
connexion
.
App
(
__name__
,
specification_dir
=
'configs/'
)
app
=
connexion
.
App
(
__name__
,
specification_dir
=
'configs/'
)
...
@@ -28,18 +28,13 @@ def api_root():
...
@@ -28,18 +28,13 @@ def api_root():
return
'Endpoint of SMART RESTful API Gateway!'
return
'Endpoint of SMART RESTful API Gateway!'
# SSL configuration
# SSL configuration
try
:
certificate_path
=
get_resources_path
()
certificate_path
=
os
.
environ
[
'ARTICONF_CERTIFICATE_PATH'
]
except
KeyError
:
certificate_path
=
'/srv/articonf/'
context
=
(
os
.
path
.
normpath
(
f
'{certificate_path}/articonf1.crt'
),
os
.
path
.
normpath
(
f
'{certificate_path}/articonf1.key'
))
# certificate and key files
context
=
(
os
.
path
.
normpath
(
f
'{certificate_path}/articonf1.crt'
),
os
.
path
.
normpath
(
f
'{certificate_path}/articonf1.key'
))
# certificate and key files
if
is_running_locally
():
if
is_running_locally
():
# Local Mode
print
(
"Running locally..."
)
print
(
"Running with local settings..."
)
app
.
add_api
(
swagger_util
.
get_bundled_specs
(
Path
(
"configs/swagger_local.yml"
)),
app
.
add_api
(
swagger_util
.
get_bundled_specs
(
Path
(
"configs/swagger_local.yml"
)),
resolver
=
connexion
.
RestyResolver
(
"cms_rest_api"
))
resolver
=
connexion
.
RestyResolver
(
"cms_rest_api"
))
context
=
'adhoc'
else
:
else
:
app
.
add_api
(
swagger_util
.
get_bundled_specs
(
Path
(
"configs/swagger.yml"
)),
app
.
add_api
(
swagger_util
.
get_bundled_specs
(
Path
(
"configs/swagger.yml"
)),
resolver
=
connexion
.
RestyResolver
(
"cms_rest_api"
))
resolver
=
connexion
.
RestyResolver
(
"cms_rest_api"
))
...
...
src/rest-gateway/app/services/token_service.py
View file @
ab8cb3d4
# global imports (dont't worry, red is normal)
# global imports (dont't worry, red is normal)
from
db.entities.user
import
User
from
db.entities.user
import
User
from
services.user_service
import
UserService
from
services.user_service
import
UserService
from
env_info
import
get_resources_path
import
jwt
import
jwt
from
datetime
import
datetime
,
timedelta
from
datetime
import
datetime
,
timedelta
...
@@ -43,7 +44,7 @@ class TokenService:
...
@@ -43,7 +44,7 @@ class TokenService:
@
staticmethod
@
staticmethod
def
read_secret
()
->
str
:
def
read_secret
()
->
str
:
with
open
(
'/srv/articonf
/jwt_secret.txt'
,
'r'
)
as
file
:
with
open
(
f
'{get_resources_path()}
/jwt_secret.txt'
,
'r'
)
as
file
:
secret
=
file
.
read
()
.
replace
(
'
\n
'
,
''
)
secret
=
file
.
read
()
.
replace
(
'
\n
'
,
''
)
return
secret
return
secret
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment