diff --git a/README.md b/README.md index 9e332fa1..36936769 100644 --- a/README.md +++ b/README.md @@ -70,3 +70,7 @@ Keep your Lambda functions optimized for performance and cost. # Lambda and S3 Lamda limits returns to 6MB and uploads to around 256K. So large uploads are done with presigned POST to S3 and large downloads by putting the data into S3 and having it pulled with a presigned URL. + + +colima start +docker ps -a diff --git a/deploy/app/__init__.py b/deploy/app/__init__.py index e69de29b..20679c7b 100644 --- a/deploy/app/__init__.py +++ b/deploy/app/__init__.py @@ -0,0 +1,4 @@ +""" +stuff +""" +__version__='0.9.0' diff --git a/deploy/app/apikey.py b/deploy/app/apikey.py index 93b17c14..d4aab7a0 100644 --- a/deploy/app/apikey.py +++ b/deploy/app/apikey.py @@ -10,10 +10,14 @@ import functools import subprocess import json +from functools import lru_cache +import base64 +from os.path import join from flask import request from . import db +from .paths import ETC_DIR from .auth import get_dbreader,AuthError from .constants import C,__version__ @@ -115,10 +119,16 @@ def get_user_dict(): userdict = db.validate_api_key(api_key) if not userdict: - logging.info("api_key %s is invalid ipaddr=%s request.url=%s", api_key,request.remote_addr,request.url) + logging.info("api_key %s is invalid ipaddr=%s request.url=%s", + api_key,request.remote_addr,request.url) raise AuthError(f"api_key '{api_key}' is invalid") return userdict +@lru_cache(maxsize=1) +def favicon_base64(): + with open( join( ETC_DIR, C.FAVICON), 'rb') as f: + return base64.b64encode(f.read()).decode('utf-8') + def page_dict(title='', *, require_auth=False, lookup=True, logout=False,debug=False): """Returns a dictionary that can be used by post of the templates. :param: title - the title we should give the page @@ -169,6 +179,7 @@ def page_dict(title='', *, require_auth=False, lookup=True, logout=False,debug=F ret= fix_types({ C.API_BASE: api_base, C.STATIC_BASE: static_base, + 'favicon_base64':favicon_base64(), 'api_key': api_key, # the API key that is currently active 'user_id': user_id, # the user_id that is active 'user_name': user_name, # the user's name diff --git a/deploy/app/bottle_app.py b/deploy/app/bottle_app.py index a99eb0ce..a93aff95 100644 --- a/deploy/app/bottle_app.py +++ b/deploy/app/bottle_app.py @@ -43,7 +43,7 @@ def lambda_startup(): clogging.setup(level=os.environ.get('PLANTTRACER_LOG_LEVEL',logging.INFO)) fix_boto_log_level() - if C.PLANTTRACER_S3_BUCKET in os.environ: + if os.environ.get(C.PLANTTRACER_S3_BUCKET,None): db_object.S3_BUCKET = os.environ[C.PLANTTRACER_S3_BUCKET] else: config = auth.config() diff --git a/deploy/app/constants.py b/deploy/app/constants.py index 9d8a3985..3fa34310 100644 --- a/deploy/app/constants.py +++ b/deploy/app/constants.py @@ -23,6 +23,7 @@ class C: FFMPEG_PATH = 'FFMPEG_PATH' # Other + FAVICON = 'icon.png' API_BASE='API_BASE' STATIC_BASE='STATIC_BASE' TRACKING_COMPLETED='TRACKING COMPLETED' # keep case; it's used as a flag diff --git a/deploy/app/db_object.py b/deploy/app/db_object.py index 88205a17..45323c5f 100644 --- a/deploy/app/db_object.py +++ b/deploy/app/db_object.py @@ -95,6 +95,7 @@ def make_urn(*, object_name, scheme = None ): if scheme == C.SCHEME_S3 and S3_BUCKET is None: scheme = C.SCHEME_DB if scheme == C.SCHEME_S3: + assert len(S3_BUCKET)>0 netloc = S3_BUCKET elif scheme == C.SCHEME_DB: netloc = DB_TABLE diff --git a/deploy/app/paths.py b/deploy/app/paths.py index faa137dd..ad379188 100644 --- a/deploy/app/paths.py +++ b/deploy/app/paths.py @@ -39,7 +39,12 @@ def ffmpeg_path(): if C.FFMPEG_PATH in os.environ: - return os.environ[C.FFMPEG_PATH] + pth = os.environ[C.FFMPEG_PATH] + if os.path.exists(path): + return pth + pth = shutil.which('ffmpeg') + if pth: + return pth if os.path.exists(AWS_LAMBDA_LINUX_STATIC_FFMPEG): return AWS_LAMBDA_LINUX_STATIC_FFMPEG - return shutil.which('ffmpeg') + raise FileNotFoundError("ffmpeg") diff --git a/deploy/app/templates/base.html b/deploy/app/templates/base.html index fb0e1d2c..226ef5dd 100644 --- a/deploy/app/templates/base.html +++ b/deploy/app/templates/base.html @@ -1,12 +1,12 @@ - {% block title %} {{title}} {% endblock %} + + - - + {% block title %} {{title}} {% endblock %}