diff --git a/inventory-app/const.py b/inventory-app/const.py index 3fe5195..664007c 100644 --- a/inventory-app/const.py +++ b/inventory-app/const.py @@ -13,7 +13,8 @@ def file_exists(path): ENVIRONMENT_TYPE = getenv_in("ENVIRONMENT_TYPE", "DEV", "PROD") SECRET_KEY = os.environ["SECRET_KEY"] -AWS_ENDPOINT_URL = os.environ["AWS_ENDPOINT_URL"] +AWS_S3_ENDPOINT_URL = os.environ["AWS_S3_ENDPOINT_URL"] +BUCKET_NAME = os.environ["BUCKET_NAME"] INVENTORY_ASSETS_BASE_URL = os.environ["INVENTORY_ASSETS_BASE_URL"] MONGO_URI = os.environ["MONGO_URI"] MEMBERS_HOST = os.environ["MEMBERS_HOST"] diff --git a/inventory-app/inventory.py b/inventory-app/inventory.py index 6233058..85a26bf 100644 --- a/inventory-app/inventory.py +++ b/inventory-app/inventory.py @@ -25,8 +25,15 @@ def view_inventory_view(item_id): if not item["inventory"].get("public"): return do_login() template = "inventory_view_public.html" - base_url = const.INVENTORY_ASSETS_BASE_URL - photo_url = "%s/kspace-inventory/%s" % (base_url, item_id) + bucket=get_bucket() + photo_url = bucket.generate_presigned_url( + ClientMethod='get_object', + Params={ + 'Bucket': const.BUCKET_NAME, + 'Key': item_id + }, + ExpiresIn=3600 + ) return render_template(template , **locals()) def fetch_members_select(): @@ -213,7 +220,7 @@ def is_image_ext(filename): def get_bucket(): return boto3.client('s3', - endpoint_url=const.AWS_ENDPOINT_URL, + endpoint_url=const.AWS_S3_ENDPOINT_URL, config=boto3.session.Config(signature_version='s3v4'), region_name='us-east-1') @@ -238,7 +245,7 @@ def upload_photo(item_id): return "Image must have smallest dimension of at least 576px", 400 bucket = get_bucket() file.seek(0) - bucket.upload_fileobj(file, 'kspace-inventory', item_id) + bucket.upload_fileobj(file, const.BUCKET_NAME, item_id) db.inventory.update_one({ "_id": ObjectId(item_id) }, {"$set": {"has_photo": True}}) delete_thumbs(item)