-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #358 from deNBI/dev
Dev
- Loading branch information
Showing
29 changed files
with
231 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.11.4 | ||
3.12.0 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
fastapi==0.101.0 | ||
fastapi==0.103.2 | ||
uvicorn==0.23.2 | ||
werkzeug==2.3.6 | ||
werkzeug==2.3.7 | ||
Jinja2==3.1.2 | ||
python-dotenv==1.0.0 | ||
gunicorn==20.1.0 | ||
pydantic-settings | ||
gunicorn==21.2.0 | ||
pydantic-settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import logging | ||
import os | ||
import shutil | ||
|
||
from app.main.service.openresty import reloadOpenresty | ||
from ..config import user_path | ||
|
||
logging.basicConfig() | ||
logger = logging.getLogger() | ||
logger.setLevel(logging.INFO) | ||
|
||
|
||
def get_users(backend_id): | ||
user_id_path = "{0}/{1}".format(user_path, backend_id) | ||
if not os.path.exists(user_id_path) and not os.access(user_id_path, os.R_OK): | ||
logger.error("Not able to access configured user id path. Backend id: {0}".format(backend_id)) | ||
return [] | ||
return os.listdir(user_id_path) | ||
|
||
|
||
def add_user(backend_id, user_id): | ||
user_id_path = "{0}/{1}".format(user_path, backend_id) | ||
user_file_name = "{0}".format(user_id) | ||
if not os.path.exists(user_id_path): | ||
try: | ||
os.mkdir(user_id_path) | ||
except OSError: | ||
logger.error("Not able to create backend directory with id {0} for user.".format(backend_id)) | ||
return 1 | ||
if not os.access(user_id_path, os.W_OK): | ||
logger.error("Not able to access configured user id path.") | ||
return 2 | ||
existing_users = os.listdir(user_id_path) | ||
for file in existing_users: | ||
if file == user_file_name: | ||
logger.info("User already added to backend.") | ||
return 3 | ||
with open(user_id_path + "/" + user_file_name, 'w') as userFile: | ||
userFile.write("") | ||
|
||
# attempt to reload openrest | ||
reloadOpenresty() | ||
return 0 | ||
|
||
|
||
def delete_user(backend_id, user_id): | ||
user_id_path = "{0}/{1}".format(user_path, backend_id) | ||
user_file_name = "{0}".format(user_id) | ||
user_file_path = "{0}/{1}".format(user_id_path, user_file_name) | ||
if not os.path.exists(user_id_path): | ||
logger.error("No user folder found for backend: {0}.".format(backend_id)) | ||
return 1 | ||
if not os.path.exists(user_file_path): | ||
logger.error("No user file {1} found for backend: {0}.".format(backend_id, user_file_name)) | ||
return 1 | ||
if not os.access(user_file_path, os.W_OK): | ||
logger.error("Not able to access configured user id path.") | ||
return 2 | ||
logger.info("Deleting user {0} from backend {1}.".format(user_file_name, backend_id)) | ||
try: | ||
existing_users = os.listdir(user_id_path) | ||
if len(existing_users) != 1: | ||
os.remove(user_file_path) | ||
else: | ||
delete_all(backend_id) | ||
reloadOpenresty() | ||
return 0 | ||
except OSError: | ||
logger.error("Not able to delete user {1} from backend {0}.".format(backend_id, user_file_name)) | ||
return 3 | ||
|
||
|
||
def delete_all(backend_id): | ||
user_id_path = "{0}/{1}".format(user_path, backend_id) | ||
if not os.path.exists(user_id_path): | ||
logger.info("No user folder found for backend: {0}.".format(backend_id)) | ||
return 1 | ||
try: | ||
shutil.rmtree(user_id_path, ignore_errors=True) | ||
return 0 | ||
except OSError: | ||
logger.error("Not able to delete users for backend {0}.".format(backend_id)) | ||
return 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from flask_restplus import Namespace, fields | ||
|
||
|
||
authorizations = { | ||
'apikey': { | ||
'type': 'apiKey', | ||
'in': 'header', | ||
'name': 'X-API-KEY' | ||
} | ||
} | ||
|
||
|
||
# General DTO for a backend json object | ||
class BackendDto: | ||
api = Namespace('backends', description="All backend related resources. Backends are generated nginx location snippets, generated from templates.", authorizations=authorizations) | ||
|
||
backend = api.model('Backend', { | ||
'id': fields.Integer(required=True, description="Unique ID of backend", example="78345"), | ||
'owner': fields.String(required=True, description="User who owns this backend."), | ||
'location_url': fields.String(required=True, description="Protected reverse-proxy path which leads to specific backend"), | ||
'template': fields.String(required=True, description="Used backend template", example="rstudio"), | ||
'template_version': fields.String(required=True, description="Template Version", example="v1") | ||
}) | ||
|
||
createBackend = api.model('CreateBackend', { | ||
'owner': fields.String(required=True, description="User who owns this backend.", example="21894723853fhdzug92"), | ||
'user_key_url': fields.String(required=True, description="User set location url prefix", example="myFavoriteRstudio"), | ||
'upstream_url': fields.String(required=True, description="Inject the full url (with protocol) for the real location of the backend service in the template.", example="http://localhost:7001/"), | ||
'template': fields.String(required=True, description="Used backend template", example="rstudio"), | ||
'template_version': fields.String(required=True, description="Template Version", example="v1") | ||
}) | ||
|
||
|
||
class UserDto: | ||
api = Namespace('users', description="All user related endpoints. Users are people allowed to access a backend.", authorizations=authorizations) | ||
|
||
createUser = api.model('createUser', { | ||
'owner': fields.String(required=True, description="User who owns this backend. "), | ||
'user': fields.String(required=True, description="User who will be added to this backend.") | ||
}) | ||
|
||
|
||
# General DTO for a template json object | ||
class TemplateDto: | ||
api = Namespace('templates', description="All template related endpoints. Templates are used to generate OpenResty location configurations.", authorizations=authorizations) | ||
|
||
template = api.model('Template', { | ||
'name': fields.String(required=True, description="Name of the template.", example="rstudio"), | ||
'version': fields.String(required=True, description="Version of this template.", example="v13") | ||
}) | ||
|
||
|
||
class UtilsDto: | ||
api = Namespace('utils', description="Misc endpoints.", authorizations=authorizations) | ||
|
||
version = api.model('Version', { | ||
'version': fields.String(required=True, description="Current running version of this service framework", example="v1.0.0") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import re | ||
|
||
ownerRegex = r'^[[email protected]]{30,}$' | ||
userKeyUrlRegex = r"^[a-zA-Z0-9]{3,25}$" | ||
|
||
upstreamURLRegex = r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+" | ||
|
||
|
||
|
||
def validatePostBackendContent(payload): | ||
#check owner | ||
owner = payload['owner'] | ||
if not re.fullmatch(ownerRegex, owner): | ||
return {"error" : "The owner name can only contain alphabetics, numerics and @ - with at least 30 chars."} | ||
|
||
user_key_url = payload['user_key_url'] | ||
if not re.fullmatch(userKeyUrlRegex, user_key_url): | ||
return {"error" : "The user key url prefix can only contain alphabetics and numerics with at least 3 and a maximum of 25 chars."} | ||
|
||
upstreamURL = payload['upstream_url'] | ||
if not re.fullmatch(upstreamURLRegex, upstreamURL): | ||
return {"error" : "This is not a valid upstream url. Example: http://129.70.168.5:3000"} | ||
|
||
return {"status" : "okay"} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.