Commit ab8cb3d4 authored by Manuel's avatar Manuel

added environment variable to set global resource directory for local mode

parent 3c9e0825
......@@ -15,3 +15,5 @@ src/modules/certificate/articonf1-chain.crt
src/modules/security/regular_user_credentials.json
src/modules/security/default_users.json
resources/
......@@ -2,6 +2,15 @@
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():
'''Set env var ARTICONF_LOCAL=1 to run locally.'''
server = True
......
......@@ -33,7 +33,6 @@ class TokenStash:
return None
def decodeToken(token: str, roles:List[str]=[]) -> Dict:
'''
verifies the passed token on the user-microservice and returns a dictionary with the
......
# global import, red is normal don't worry
import network_constants
from env_info import is_running_locally
from env_info import is_running_locally, get_resources_path
import os
import json
......@@ -22,15 +22,12 @@ class TokenManager:
def getToken(self) -> str:
if self._token == None:
if is_running_locally():
credentials_path = '../../../modules/security/'
else:
credentials_path = '/srv/articonf/'
credentials_path = get_resources_path()
print("Looking for credentials at ... "+str(credentials_path))
with open(f'{credentials_path}regular_user_credentials.json') as file:
credentials = json.loads(file.read())
with open(f'{credentials_path}/regular_user_credentials.json') as file_handler:
credentials = json.loads(file_handler.read())
url = f'https://{network_constants.REST_GATEWAY_HOSTNAME}:{network_constants.REST_GATEWAY_REST_PORT}/api/tokens'
......
......@@ -117,7 +117,6 @@ def add_by_layers():
else:
print(f"Response: {response.status_code}: {response.text}")
def add_by_schema():
'''
take the columns and add the mappings at the server
......
......@@ -8,11 +8,10 @@ modules_path = '../../../modules/'
if os.path.exists(modules_path):
sys.path.insert(1, modules_path)
# load swagger config
import connexion
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/')
......@@ -23,23 +22,17 @@ def api_root():
return 'Endpoint of business-logic-microservice!'
# SSL configuration
try:
certificate_path = os.environ['ARTICONF_CERTIFICATE_PATH']
except KeyError:
certificate_path = '/srv/articonf/'
certificate_path = get_resources_path()
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():
# Local Mode
print("Running with local settings...")
print("Running locally...")
app.add_api(swagger_util.get_bundled_specs(Path("configs/swagger_local.yml")),
resolver = connexion.RestyResolver("cms_rest_api"))
context = 'adhoc'
else:
app.add_api(swagger_util.get_bundled_specs(Path("configs/swagger.yml")),
resolver = connexion.RestyResolver("cms_rest_api"))
# start app
if __name__ == '__main__':
print(context)
app.run(host='0.0.0.0', port=5000, debug=False, ssl_context=context)
......@@ -11,15 +11,12 @@ if os.path.exists(modules_path):
sys.path.insert(1, modules_path)
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 is_running_locally():
path = f'{modules_path}/security/default_users.json'
else:
path = '/srv/articonf/default_users.json'
resources_path = get_resources_path()
with open(path, "r") as file_handler:
with open(f'{resources_path}/default_users.json', "r") as file_handler:
content = file_handler.read()
users = json.loads(content)
......
......@@ -19,7 +19,7 @@ LOGGER = logging.getLogger(__name__)
import connexion
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/')
......@@ -28,18 +28,13 @@ def api_root():
return 'Endpoint of SMART RESTful API Gateway!'
# SSL configuration
try:
certificate_path = os.environ['ARTICONF_CERTIFICATE_PATH']
except KeyError:
certificate_path = '/srv/articonf/'
certificate_path = get_resources_path()
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():
# Local Mode
print("Running with local settings...")
print("Running locally...")
app.add_api(swagger_util.get_bundled_specs(Path("configs/swagger_local.yml")),
resolver = connexion.RestyResolver("cms_rest_api"))
context = 'adhoc'
else:
app.add_api(swagger_util.get_bundled_specs(Path("configs/swagger.yml")),
resolver = connexion.RestyResolver("cms_rest_api"))
......
# global imports (dont't worry, red is normal)
from db.entities.user import User
from services.user_service import UserService
from env_info import get_resources_path
import jwt
from datetime import datetime, timedelta
......@@ -43,7 +44,7 @@ class TokenService:
@staticmethod
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', '')
return secret
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment