diff --git a/src/main/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogService.java b/src/main/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogService.java index 1bf4b3599c..370f9095e1 100644 --- a/src/main/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogService.java +++ b/src/main/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogService.java @@ -70,6 +70,10 @@ public class ServiceCatalogService implements PassedRoleLookup { this.clock = clock; } + private double nowEpochSeconds() { + return Instant.now(clock).toEpochMilli() / 1000.0; + } + public ObjectNode createPortfolio(JsonNode request, String region, String accountId) { requireText(request, "DisplayName"); requireText(request, "ProviderName"); @@ -77,7 +81,7 @@ public class ServiceCatalogService implements PassedRoleLookup { ObjectNode portfolio = copy(request); portfolio.put("Id", id); portfolio.put("ARN", AwsArnUtils.Arn.of("catalog", region, accountId, "portfolio/" + id).toString()); - portfolio.put("CreatedTime", Instant.now(clock).toEpochMilli() / 1000.0); + portfolio.put("CreatedTime", nowEpochSeconds()); portfolioStore.put(id, portfolio); return portfolio.deepCopy(); } @@ -110,7 +114,7 @@ public class ServiceCatalogService implements PassedRoleLookup { portfolio.put("DisplayName", CONTROL_TOWER_PORTFOLIO_NAME); portfolio.put("ProviderName", CONTROL_TOWER_PROVIDER_NAME); portfolio.put("Description", "AWS Control Tower Account Factory Portfolio"); - portfolio.put("CreatedTime", Instant.now(clock).toEpochMilli() / 1000.0); + portfolio.put("CreatedTime", nowEpochSeconds()); portfolioStore.put(CONTROL_TOWER_PORTFOLIO_ID, portfolio); } if (productStore.get(CONTROL_TOWER_PRODUCT_ID).isEmpty()) { @@ -121,7 +125,7 @@ public class ServiceCatalogService implements PassedRoleLookup { product.put("Name", CONTROL_TOWER_PRODUCT_NAME); product.put("Owner", CONTROL_TOWER_PROVIDER_NAME); product.put("Type", "CLOUD_FORMATION_TEMPLATE"); - product.put("CreatedTime", Instant.now(clock).toEpochMilli() / 1000.0); + product.put("CreatedTime", nowEpochSeconds()); product.putArray("ProvisioningArtifactIds").add(CONTROL_TOWER_ARTIFACT_ID); product.putArray("ProvisioningArtifactNames").add("AWS Control Tower Account Factory"); productStore.put(CONTROL_TOWER_PRODUCT_ID, product); @@ -162,7 +166,7 @@ public class ServiceCatalogService implements PassedRoleLookup { ObjectNode product = copy(request); product.put("Id", id); product.put("ARN", AwsArnUtils.Arn.of("catalog", region, accountId, "product/" + id).toString()); - product.put("CreatedTime", Instant.now(clock).toEpochMilli() / 1000.0); + product.put("CreatedTime", nowEpochSeconds()); ArrayNode artifactIds = product.putArray("ProvisioningArtifactIds"); ArrayNode artifactNames = product.putArray("ProvisioningArtifactNames"); JsonNode artifacts = request.path("ProvisioningArtifactParameters"); @@ -234,7 +238,7 @@ public class ServiceCatalogService implements PassedRoleLookup { provisioned.put("Status", "AVAILABLE"); provisioned.put("ProductId", productId); provisioned.put("ProvisioningArtifactId", artifactId); - provisioned.put("CreatedTime", Instant.now(clock).toEpochMilli() / 1000.0); + provisioned.put("CreatedTime", nowEpochSeconds()); provisionedProductStore.put(provisionedId, provisioned); return provisionedProductWithRecord(provisioned); } @@ -704,7 +708,7 @@ public class ServiceCatalogService implements PassedRoleLookup { ObjectNode product = source.deepCopy(); product.put("Id", newId); product.put("ARN", AwsArnUtils.Arn.of("catalog", region, accountId, "product/" + newId).toString()); - product.put("CreatedTime", Instant.now(clock).toEpochMilli() / 1000.0); + product.put("CreatedTime", nowEpochSeconds()); String targetName = text(request, "TargetProductName"); if (targetName != null && !targetName.isBlank()) { product.put("Name", targetName); @@ -958,7 +962,7 @@ public class ServiceCatalogService implements PassedRoleLookup { plan.put("ProvisionProductId", productId); plan.put("ProvisionedProductName", text(request, "ProvisionedProductName")); plan.put("ProvisioningArtifactId", artifactId); - plan.put("CreatedTime", Instant.now(clock).toEpochMilli() / 1000.0); + plan.put("CreatedTime", nowEpochSeconds()); associationStore.put(planId, plan); return plan.deepCopy(); } @@ -1152,7 +1156,7 @@ public class ServiceCatalogService implements PassedRoleLookup { ObjectNode record = objectMapper.createObjectNode(); record.put("RecordId", "rec-" + UUID.randomUUID().toString().replace("-", "").substring(0, 16)); record.put("Status", "SUCCEEDED"); - record.put("CreatedTime", Instant.now(clock).toEpochMilli() / 1000.0); + record.put("CreatedTime", nowEpochSeconds()); return record; } @@ -1165,7 +1169,7 @@ public class ServiceCatalogService implements PassedRoleLookup { String recordId = id("rec"); ObjectNode record = newProvisionedProductRecord(product, recordId, - "UPDATE_PROVISIONED_PRODUCT", Instant.now(clock).toEpochMilli() / 1000.0); + "UPDATE_PROVISIONED_PRODUCT", nowEpochSeconds()); record.put("ProvisionedProductType", text(product, "Type")); associationStore.put(recordId, record); @@ -1209,7 +1213,7 @@ public class ServiceCatalogService implements PassedRoleLookup { provisioned.put("PhysicalId", physicalId); provisioned.put("ProductId", productId); provisioned.put("ProvisioningArtifactId", provisioningArtifactId); - provisioned.put("CreatedTime", Instant.now(clock).toEpochMilli() / 1000.0); + provisioned.put("CreatedTime", nowEpochSeconds()); provisionedProductStore.put(provisionedId, provisioned); String recordId = id("rec"); @@ -1457,7 +1461,7 @@ public class ServiceCatalogService implements PassedRoleLookup { String recordId = id("rec"); ObjectNode record = newProvisionedProductRecord(product, recordId, - "UPDATE_PROVISIONED_PRODUCT", Instant.now(clock).toEpochMilli() / 1000.0); + "UPDATE_PROVISIONED_PRODUCT", nowEpochSeconds()); associationStore.put(recordId, record); ObjectNode result = product.deepCopy(); @@ -1480,7 +1484,7 @@ public class ServiceCatalogService implements PassedRoleLookup { String recordId = id("rec"); ObjectNode record = newProvisionedProductRecord(product, recordId, - "UPDATE_PROVISIONED_PRODUCT", Instant.now(clock).toEpochMilli() / 1000.0); + "UPDATE_PROVISIONED_PRODUCT", nowEpochSeconds()); associationStore.put(recordId, record); ObjectNode result = product.deepCopy(); @@ -1531,7 +1535,7 @@ public class ServiceCatalogService implements PassedRoleLookup { detail.put("Id", artifactId); detail.put("Name", name); detail.put("Type", type); - detail.put("CreatedTime", Instant.now(clock).toEpochMilli() / 1000.0); + detail.put("CreatedTime", nowEpochSeconds()); detail.put("Active", true); String description = text(parameters, "Description"); if (description != null && !description.isBlank()) { @@ -1572,7 +1576,7 @@ public class ServiceCatalogService implements PassedRoleLookup { } String id = text(product, "Id"); product.put("Status", "TERMINATED"); - product.put("UpdatedTime", Instant.now(clock).toEpochMilli() / 1000.0); + product.put("UpdatedTime", nowEpochSeconds()); provisionedProductStore.put(id, product); String recordId = id("rec");