From e374cd6445cb074d1c37aa40dc558373b91fc0dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20V=C3=ADtov=C3=A1?= Date: Mon, 18 Nov 2024 16:16:13 +0200 Subject: [PATCH] internal/v1: export snapshot date --- internal/common/testdata/exported_blueprint.json | 1 + internal/v1/api.go | 4 ++++ internal/v1/api.yaml | 5 +++++ internal/v1/handler_blueprints.go | 4 ++++ internal/v1/handler_blueprints_test.go | 4 ++++ 5 files changed, 18 insertions(+) diff --git a/internal/common/testdata/exported_blueprint.json b/internal/common/testdata/exported_blueprint.json index 389285f54..9b16c6204 100644 --- a/internal/common/testdata/exported_blueprint.json +++ b/internal/common/testdata/exported_blueprint.json @@ -6,6 +6,7 @@ "url": "http://snappy-url/snappy/baseos" } ], + "snapshot_date": "2012-12-20", "customizations": { "custom_repositories": [ { diff --git a/internal/v1/api.go b/internal/v1/api.go index bf8fa4af8..45a0ffa70 100644 --- a/internal/v1/api.go +++ b/internal/v1/api.go @@ -242,6 +242,10 @@ type BlueprintExportResponse struct { Distribution Distributions `json:"distribution"` Metadata BlueprintMetadata `json:"metadata"` Name string `json:"name"` + + // SnapshotDate Importing the snapshot date will not yet be supported. It is exported for informative reasons. + // The format is YYYY-MM-DD. + SnapshotDate *string `json:"snapshot_date,omitempty"` } // BlueprintItem defines model for BlueprintItem. diff --git a/internal/v1/api.yaml b/internal/v1/api.yaml index b254b5fd6..5cac36511 100644 --- a/internal/v1/api.yaml +++ b/internal/v1/api.yaml @@ -1077,6 +1077,11 @@ components: description: | List of custom repositories including all the repository details needed in order to recreate the repositories. + snapshot_date: + type: string + description: | + Importing the snapshot date will not yet be supported. It is exported for informative reasons. + The format is YYYY-MM-DD. BlueprintMetadata: required: - parent_id diff --git a/internal/v1/handler_blueprints.go b/internal/v1/handler_blueprints.go index 381fbd1d2..b4832993f 100644 --- a/internal/v1/handler_blueprints.go +++ b/internal/v1/handler_blueprints.go @@ -316,6 +316,10 @@ func (h *Handlers) ExportBlueprint(ctx echo.Context, id openapi_types.UUID) erro }, } + if len(blueprint.ImageRequests) != 0 { + blueprintExportResponse.SnapshotDate = blueprint.ImageRequests[0].SnapshotDate + } + repoUUIDs := []string{} if blueprint.Customizations.CustomRepositories != nil { for _, repo := range *blueprint.Customizations.CustomRepositories { diff --git a/internal/v1/handler_blueprints_test.go b/internal/v1/handler_blueprints_test.go index deb46480f..ebb165c31 100644 --- a/internal/v1/handler_blueprints_test.go +++ b/internal/v1/handler_blueprints_test.go @@ -31,6 +31,7 @@ type BlueprintExportResponseUnmarshal struct { Distribution Distributions `json:"distribution"` Metadata BlueprintMetadata `json:"metadata"` Name string `json:"name"` + SnapshotDate *string `json:"snapshot_date,omitempty"` } func makeTestServer(t *testing.T, apiSrv *string, csSrv *string) (dbase db.DB, srvURL string, shutdown func()) { @@ -1011,6 +1012,7 @@ func TestHandlers_ExportBlueprint(t *testing.T) { Type: UploadTypesAws, Options: uploadOptions, }, + SnapshotDate: common.ToPtr("2012-12-20"), }, { Architecture: ImageRequestArchitectureAarch64, @@ -1019,6 +1021,7 @@ func TestHandlers_ExportBlueprint(t *testing.T) { Type: UploadTypesAws, Options: uploadOptions, }, + SnapshotDate: common.ToPtr("2012-12-21"), }, }, } @@ -1056,6 +1059,7 @@ func TestHandlers_ExportBlueprint(t *testing.T) { require.Equal(t, "payload", *result.ContentSources[0].Name) require.Equal(t, "http://snappy-url/snappy/baseos", *result.ContentSources[0].Url) require.Equal(t, "some-gpg-key", *result.ContentSources[0].GpgKey) + require.Equal(t, "2012-12-20", *result.SnapshotDate) require.Len(t, result.ContentSources, 1) // Check that the password returned is redacted for _, u := range *result.Customizations.Users {