From e57fd23b51ffd3558bc06faf78338bb9f3529f70 Mon Sep 17 00:00:00 2001 From: roleyfoley Date: Thu, 4 Feb 2021 05:06:53 +0000 Subject: [PATCH] feat: create prefix for move based on contexpath --- .../s3_inventory_copy_batch/extension.ftl | 38 +++++++++---- .../modules/s3_inventory_copy/module.ftl | 54 +++++++++++++------ 2 files changed, 65 insertions(+), 27 deletions(-) diff --git a/hamlet/s3support/extensions/s3_inventory_copy_batch/extension.ftl b/hamlet/s3support/extensions/s3_inventory_copy_batch/extension.ftl index 93f0ac5..6157d17 100644 --- a/hamlet/s3support/extensions/s3_inventory_copy_batch/extension.ftl +++ b/hamlet/s3support/extensions/s3_inventory_copy_batch/extension.ftl @@ -16,19 +16,35 @@ [#macro shared_extension_s3_inventory_copy_batch_deployment_setup occurrence ] + [#local s3PathConfig = ((_context.DefaultEnvironment["S3_PATH"])!"")?eval] + + [#local s3DestinationPrefix = ""] + [#if s3PathConfig.Prefix.Enabled ] + [#local s3DestinationPrefix = getContextPath(occurrence, s3PathConfig.Prefix.Path) ] + [#if s3PathConfig.Prefix.Path.Style == "path" ] + [#local s3DestinationPrefix = s3DestinationPrefix?ensure_ends_with("/") ] + [/#if] + [/#if] + + [#local s3DestinationSuffix = ""] + [#if s3PathConfig.Suffix.Enabled ] + [#local s3DestinationSuffix = getContextPath(occurrence, s3PathConfig.Suffix.Path) ] + [#if s3PathConfig.Suffix.Path.Style == "path" ] + [#local s3DestinationSuffix = s3DestinationSuffix?ensure_ends_with("/") ] + [/#if] + [/#if] + + [@Settings [ "DESTINATION_BUCKET_NAME" - ] + - valueIfContent( - [ "S3_DESTINATION_PREFIX" ], - (_context.DefaultEnvironment["S3_DESTINATION_PREFIX"])!"", - [] - ) + - valueIfContent( - [ "S3_DESTINATION_SUFFIX" ], - (_context.DefaultEnvironment["S3_DESTINATION_SUFFIX"])!"", - [] - ) + ] + /] + + [@Settings + { + "S3_DESTINATION_PREFIX" : s3DestinationPrefix, + "S3_DESTINATION_SUFFIX" : s3DestinationSuffix + } /] [/#macro] diff --git a/hamlet/s3support/modules/s3_inventory_copy/module.ftl b/hamlet/s3support/modules/s3_inventory_copy/module.ftl index 4055ad6..3506362 100644 --- a/hamlet/s3support/modules/s3_inventory_copy/module.ftl +++ b/hamlet/s3support/modules/s3_inventory_copy/module.ftl @@ -8,37 +8,55 @@ { "Names" : "id", "Description" : "A unique id for this instance of the api", - "Type" : STRING_TYPE, + "Types" : STRING_TYPE, "Mandatory" : true }, { "Names" : "tier", "Description" : "The tier the components will belong to", - "Type" : STRING_TYPE, + "Types" : STRING_TYPE, "Mandatory" : true }, { "Names" : "instance", "Description" : "The instance id of the components", - "Type" : STRING_TYPE, + "Types" : STRING_TYPE, "Default" : "default" }, { "Names" : "s3KeyPrefix", - "Description" : "A prefix to append to all keys in the report when copying", - "Type" : STRING_TYPE, - "Default" : "" + "Description" : "Creates a key prefix based on the deployment context", + "Children" : [ + { + "Names" : "Enabled", + "Types" : BOOLEAN_TYPE, + "Default" : true + }, + { + "Names" : "Path", + "AttributeSet" : CONTEXTPATH_ATTRIBUTESET_TYPE + } + ] }, { "Names" : "s3KeySuffix", - "Description" : "A suffix to append to all keys in the report when copying", - "Type" : STRING_TYPE, - "Default" : "" + "Description" : "Creates a key suffix based on the deployment context", + "Children" : [ + { + "Names" : "Enabled", + "Types" : BOOLEAN_TYPE, + "Default" : false + } + { + "Names" : "Path", + "AttributeSet" : CONTEXTPATH_ATTRIBUTESET_TYPE + } + ] }, { "Names" : "s3InventoryPrefix", "Description" : "The prefix to use for inventory generation on the source bucket", - "Type" : STRING_TYPE, + "Types" : STRING_TYPE, "Default" : "s3_inventory_copy/" }, { @@ -54,25 +72,25 @@ { "Names" : "s3InventoryProfileSuffix", "Description" : "The suffix ( added to the id ) for the deployment profile which configures the userpool client", - "Type" : STRING_TYPE, + "Types" : STRING_TYPE, "Default" : "_s3inventorycopy" }, { "Names" : "lambdaImageUrl", "Description" : "The url to the lambda zip image", - "Type" : STRING_TYPE, + "Types" : STRING_TYPE, "Default" : "https://github.com/hamlet-io/lambda-s3-support/releases/download/v0.0.9/s3-inventory-copy.zip" }, { "Names" : "lambdaImageHash", "Description" : "The sha1 hash of the lambda zip image", - "Type" : STRING_TYPE, + "Types" : STRING_TYPE, "Default" : "eec63deecde1ddc737d8e951eef8fe9b410a9ad4" }, { "Names" : "batchPriorty", "Description" : "The priority of the s3 batch call - Highest wins", - "Type" : NUMBER_TYPE, + "Types" : NUMBER_TYPE, "Default" : 100 } ] @@ -126,8 +144,12 @@ "Scope" : "Products", "Namespace" : s3BatchSettingsNamespace, "Settings" : { - "S3_DESTINATION_PREFIX" : s3KeyPrefix, - "S3_DESTINATION_SUFFIX" : s3KeySuffix + "s3_path": { + "Value": { + "Prefix" : s3KeyPrefix, + "Suffix" : s3KeySuffix + } + } } } ]