Skip to content

Commit

Permalink
fix(front50-gcs): Fix ObjectType filenames for GCS Front50 persistent…
Browse files Browse the repository at this point in the history
… store (#1493) (#1494)

(cherry picked from commit 2f828b7)

Co-authored-by: Christos Arvanitis <christos.arvanitis@armory.io>
  • Loading branch information
mergify[bot] and christosarvanitis authored Aug 23, 2024
1 parent 27526ee commit 25bda17
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,41 @@
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(
Application.Permission.class,
"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<? extends Timestamped> clazz;
public final String group;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand 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<Array<Any>> {
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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 25bda17

Please sign in to comment.