Skip to content

Commit

Permalink
internal: Support both DateOnly and RFC3339 format for snapshot dates
Browse files Browse the repository at this point in the history
This adds back support for DateOnly format of snapshot dates.
  • Loading branch information
regexowl committed Jan 8, 2025
1 parent ed87818 commit 2e9692e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/v1/handler_compose_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,13 @@ func buildRepositories(arch *distribution.Architecture, imageType ImageTypes) []

func (h *Handlers) buildRepositorySnapshots(ctx echo.Context, repoURLs []string, repoIDs []string, external bool, snapshotDate string) ([]composer.Repository, []composer.CustomRepository, error) {
date, err := time.Parse(time.RFC3339, snapshotDate)

if err != nil {
date, err = time.Parse(time.DateOnly, snapshotDate)
}

if err != nil {
return nil, nil, echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Snapshot date %s is not in RFC3339 (yyyy-mm-ddThh:mm:ssZ) format", snapshotDate))
return nil, nil, echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Snapshot date %s is not in DateOnly (yyyy-mm-dd) or RFC3339 (yyyy-mm-ddThh:mm:ssZ) format", snapshotDate))
}

repoMap, err := h.server.csClient.GetRepositories(ctx.Request().Context(), repoURLs, repoIDs, external)
Expand Down
49 changes: 49 additions & 0 deletions internal/v1/handler_post_compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,55 @@ func TestComposeWithSnapshots(t *testing.T) {
},
},
},
// basic with old snapshotting date format
{
imageBuilderRequest: v1.ComposeRequest{
Distribution: "rhel-95",
ImageRequests: []v1.ImageRequest{
{
Architecture: "x86_64",
ImageType: v1.ImageTypesGuestImage,
SnapshotDate: common.ToPtr("1999-01-30"),
UploadRequest: v1.UploadRequest{
Type: v1.UploadTypesAwsS3,
Options: uo,
},
},
},
},
composerRequest: composer.ComposeRequest{
Distribution: "rhel-9.5",
ImageRequest: &composer.ImageRequest{
Architecture: "x86_64",
ImageType: composer.ImageTypesGuestImage,
Repositories: []composer.Repository{
{
Baseurl: common.ToPtr("https://content-sources.org/snappy/baseos"),
Rhsm: common.ToPtr(false),
Gpgkey: common.ToPtr(mocks.RhelGPG),
CheckGpg: common.ToPtr(true),
IgnoreSsl: nil,
Metalink: nil,
Mirrorlist: nil,
PackageSets: nil,
},
{
Baseurl: common.ToPtr("https://content-sources.org/snappy/appstream"),
Rhsm: common.ToPtr(false),
Gpgkey: common.ToPtr(mocks.RhelGPG),
CheckGpg: common.ToPtr(true),
IgnoreSsl: nil,
Metalink: nil,
Mirrorlist: nil,
PackageSets: nil,
},
},
UploadOptions: makeUploadOptions(t, composer.AWSS3UploadOptions{
Region: "",
}),
},
},
},
// 1 payload 2 custom repositories
{
imageBuilderRequest: v1.ComposeRequest{
Expand Down

0 comments on commit 2e9692e

Please sign in to comment.