From 25bda17aa84235c0b02bf5e97d7fac11a1439ac2 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 23 Aug 2024 16:11:18 +0000 Subject: [PATCH] fix(front50-gcs): Fix ObjectType filenames for GCS Front50 persistent store (#1493) (#1494) (cherry picked from commit 2f828b74065412ba5423f4ef4b00735158bda0f5) Co-authored-by: Christos Arvanitis --- .../spinnaker/front50/model/ObjectType.java | 37 ++++++++++----- .../front50/model/TestGcsStorageService.kt | 47 ++++++++++++++++--- 2 files changed, 66 insertions(+), 18 deletions(-) diff --git a/front50-core/src/main/java/com/netflix/spinnaker/front50/model/ObjectType.java b/front50-core/src/main/java/com/netflix/spinnaker/front50/model/ObjectType.java index 0d9aed2b8..a50c44ebc 100644 --- a/front50-core/src/main/java/com/netflix/spinnaker/front50/model/ObjectType.java +++ b/front50-core/src/main/java/com/netflix/spinnaker/front50/model/ObjectType.java @@ -30,13 +30,25 @@ import com.netflix.spinnaker.front50.model.tag.EntityTags; public enum ObjectType { - PROJECT(Project.class, "projects", "project-metadata.json"), - PIPELINE(Pipeline.class, "pipelines", "pipeline-metadata.json"), - STRATEGY(Pipeline.class, "pipeline-strategies", "pipeline-strategy-metadata.json"), + PROJECT(Project.class, "projects", "project-metadata.json", "specification.json"), + PIPELINE(Pipeline.class, "pipelines", "pipeline-metadata.json", "specification.json"), + STRATEGY( + Pipeline.class, + "pipeline-strategies", + "pipeline-strategy-metadata.json", + "specification.json"), PIPELINE_TEMPLATE( - PipelineTemplate.class, "pipeline-templates", "pipeline-template-metadata.json"), - NOTIFICATION(Notification.class, "notifications", "notification-metadata.json"), - SERVICE_ACCOUNT(ServiceAccount.class, "serviceAccounts", "serviceAccount-metadata.json"), + PipelineTemplate.class, + "pipeline-templates", + "pipeline-template-metadata.json", + "specification.json"), + NOTIFICATION( + Notification.class, "notifications", "notification-metadata.json", "specification.json"), + SERVICE_ACCOUNT( + ServiceAccount.class, + "serviceAccounts", + "serviceAccount-metadata.json", + "specification.json"), APPLICATION(Application.class, "applications", "application-metadata.json", "specification.json"), APPLICATION_PERMISSION( @@ -44,12 +56,15 @@ public enum ObjectType { "applications", "application-permission.json", "permission.json"), - SNAPSHOT(Snapshot.class, "snapshots", "snapshot.json"), - ENTITY_TAGS(EntityTags.class, "tags", "entity-tags-metadata.json"), - DELIVERY(Delivery.class, "delivery", "delivery-metadata.json"), - PLUGIN_INFO(PluginInfo.class, "pluginInfo", "plugin-info-metadata.json"), + SNAPSHOT(Snapshot.class, "snapshots", "snapshot.json", "specification.json"), + ENTITY_TAGS(EntityTags.class, "tags", "entity-tags-metadata.json", "specification.json"), + DELIVERY(Delivery.class, "delivery", "delivery-metadata.json", "specification.json"), + PLUGIN_INFO(PluginInfo.class, "pluginInfo", "plugin-info-metadata.json", "specification.json"), PLUGIN_VERSIONS( - ServerGroupPluginVersions.class, "pluginVersions", "plugin-versions-metadata.json"); + ServerGroupPluginVersions.class, + "pluginVersions", + "plugin-versions-metadata.json", + "specification.json"); public final Class clazz; public final String group; diff --git a/front50-gcs/src/test/kotlin/com/netflix/spinnaker/front50/model/TestGcsStorageService.kt b/front50-gcs/src/test/kotlin/com/netflix/spinnaker/front50/model/TestGcsStorageService.kt index dba4aba30..d47dcf706 100644 --- a/front50-gcs/src/test/kotlin/com/netflix/spinnaker/front50/model/TestGcsStorageService.kt +++ b/front50-gcs/src/test/kotlin/com/netflix/spinnaker/front50/model/TestGcsStorageService.kt @@ -50,6 +50,8 @@ import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestInfo import org.junit.jupiter.api.Timeout +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.MethodSource import strikt.api.expectCatching import strikt.api.expectThat import strikt.assertions.all @@ -72,7 +74,26 @@ class GcsStorageServiceTest { private const val BUCKET_NAME = "myBucket" private const val BUCKET_LOCATION = "bucketLocation" private const val BASE_PATH = "my/base/path" - private val DATA_FILENAME = ObjectType.APPLICATION.getDefaultMetadataFilename(true); + private val DATA_FILENAME = "specification.json"; + private val PERMISSION_DATA_FILENAME = "permission.json"; + + @JvmStatic + fun objectTypes() : List> { + return listOf( + arrayOf(ObjectType.PROJECT.group, ObjectType.PROJECT, """{"name": "APP NAME","email": "sample@example.com"}"""), + arrayOf(ObjectType.PIPELINE.group,ObjectType.PIPELINE, """{"name": "APP NAME","email": "sample@example.com"}"""), + arrayOf(ObjectType.STRATEGY.group,ObjectType.STRATEGY, """{"name": "APP NAME","email": "sample@example.com"}"""), + arrayOf(ObjectType.PIPELINE_TEMPLATE.group,ObjectType.PIPELINE_TEMPLATE, """{"name": "APP NAME","email": "sample@example.com"}"""), + arrayOf(ObjectType.NOTIFICATION.group,ObjectType.NOTIFICATION, """{"name": "APP NAME","email": "sample@example.com"}"""), + arrayOf(ObjectType.SERVICE_ACCOUNT.group,ObjectType.SERVICE_ACCOUNT, """{"name": "ServiceAccount","memberOf": ["myApp-prod","myApp-qa"]}"""), + arrayOf(ObjectType.APPLICATION.group,ObjectType.APPLICATION, """{"name": "APP NAME","email": "sample@example.com"}"""), + arrayOf(ObjectType.SNAPSHOT.group,ObjectType.SNAPSHOT, """{"application": "APP NAME","account": "someAccount"}"""), + arrayOf(ObjectType.ENTITY_TAGS.group,ObjectType.ENTITY_TAGS, """{"idPattern": "entityType__entityId__account__region"}"""), + arrayOf(ObjectType.DELIVERY.group,ObjectType.DELIVERY, """{"application": "APP NAME"}"""), + arrayOf(ObjectType.PLUGIN_INFO.group,ObjectType.PLUGIN_INFO, """{"description": "APP NAME","provider": "github"}"""), + arrayOf(ObjectType.PLUGIN_VERSIONS.group,ObjectType.PLUGIN_VERSIONS, """{"serverGroupName": "myapp","location": "us-west-2"}""") + ) + } } private lateinit var gcs: Storage @@ -159,23 +180,35 @@ class GcsStorageServiceTest { } @Test - fun `loadObject fetches previously stored data`() { + fun `loadObject fetches previously stored data - ApplicationPermissions`() { - val path = "$BASE_PATH/${ObjectType.APPLICATION.group}/plumpstuff/$DATA_FILENAME" + val path = "$BASE_PATH/${ObjectType.APPLICATION_PERMISSION.group}/plumpstuff/$PERMISSION_DATA_FILENAME" writeFile( path, """ { "name": "APP NAME", - "email": "sample@example.com" + "permissions": {} } """ ) - val application: Application = storageService.loadObject(ObjectType.APPLICATION, "plumpstuff") + val applicationPermission: Application.Permission = storageService.loadObject(ObjectType.APPLICATION_PERMISSION, "plumpstuff") + + expectThat(applicationPermission.name).isEqualTo("APP NAME") + } - expectThat(application.name).isEqualTo("APP NAME") - expectThat(application.email).isEqualTo("sample@example.com") + @ParameterizedTest(name = "loadObject fetches previously stored data of {0}") + @MethodSource("objectTypes") + fun `loadObject fetches previously stored data - All Types`(group: String, objectType: ObjectType, content: String) { + val path = "$BASE_PATH/${objectType.group}/plumpstuff/$DATA_FILENAME" + writeFile( + path, + content + ) + expectCatching { + val type: Any = storageService.loadObject(objectType, "plumpstuff") + }.isSuccess() } @Test