Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ export interface ApiTemplateRequest {
* @memberof ApiTemplateRequest
*/
description?: string;
/**
* Extended release type (eus, e4s)
* @type {string}
* @memberof ApiTemplateRequest
*/
extendedRelease?: string;
/**
* Extended release version (9.4, 9.6, etc.)
* @type {string}
* @memberof ApiTemplateRequest
*/
extendedReleaseVersion?: string;
/**
* Name of the template
* @type {string}
Expand Down Expand Up @@ -87,6 +99,8 @@ export function ApiTemplateRequestFromJSONTyped(json: any, ignoreDiscriminator:
'arch': json['arch'],
'date': json['date'] == null ? undefined : json['date'],
'description': json['description'] == null ? undefined : json['description'],
'extendedRelease': json['extended_release'] == null ? undefined : json['extended_release'],
'extendedReleaseVersion': json['extended_release_version'] == null ? undefined : json['extended_release_version'],
'name': json['name'],
'repositoryUuids': json['repository_uuids'],
'useLatest': json['use_latest'] == null ? undefined : json['use_latest'],
Expand All @@ -108,6 +122,8 @@ export function ApiTemplateRequestToJSONTyped(value?: ApiTemplateRequest | null,
'arch': value['arch'],
'date': value['date'],
'description': value['description'],
'extended_release': value['extendedRelease'],
'extended_release_version': value['extendedReleaseVersion'],
'name': value['name'],
'repository_uuids': value['repositoryUuids'],
'use_latest': value['useLatest'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ export interface ApiTemplateResponse {
* @memberof ApiTemplateResponse
*/
description?: string;
/**
* Extended release type (eus, e4s)
* @type {string}
* @memberof ApiTemplateResponse
*/
extendedRelease?: string;
/**
* Extended release version (9.4, 9.6, etc.)
* @type {string}
* @memberof ApiTemplateResponse
*/
extendedReleaseVersion?: string;
/**
* Error of last update_latest_snapshot task that updated the template
* @type {string}
Expand Down Expand Up @@ -178,6 +190,8 @@ export function ApiTemplateResponseFromJSONTyped(json: any, ignoreDiscriminator:
'createdBy': json['created_by'] == null ? undefined : json['created_by'],
'date': json['date'] == null ? undefined : json['date'],
'description': json['description'] == null ? undefined : json['description'],
'extendedRelease': json['extended_release'] == null ? undefined : json['extended_release'],
'extendedReleaseVersion': json['extended_release_version'] == null ? undefined : json['extended_release_version'],
'lastUpdateSnapshotError': json['last_update_snapshot_error'] == null ? undefined : json['last_update_snapshot_error'],
'lastUpdateTask': json['last_update_task'] == null ? undefined : ApiTaskInfoResponseFromJSON(json['last_update_task']),
'lastUpdateTaskUuid': json['last_update_task_uuid'] == null ? undefined : json['last_update_task_uuid'],
Expand Down Expand Up @@ -212,6 +226,8 @@ export function ApiTemplateResponseToJSONTyped(value?: Omit<ApiTemplateResponse,
'created_by': value['createdBy'],
'date': value['date'],
'description': value['description'],
'extended_release': value['extendedRelease'],
'extended_release_version': value['extendedReleaseVersion'],
'last_update_snapshot_error': value['lastUpdateSnapshotError'],
'last_update_task': ApiTaskInfoResponseToJSON(value['lastUpdateTask']),
'last_update_task_uuid': value['lastUpdateTaskUuid'],
Expand Down
16 changes: 16 additions & 0 deletions api/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5355,6 +5355,14 @@ const docTemplate = `{
"description": "Description of the template",
"type": "string"
},
"extended_release": {
"description": "Extended release type (eus, e4s)",
"type": "string"
},
"extended_release_version": {
"description": "Extended release version (9.4, 9.6, etc.)",
"type": "string"
},
"name": {
"description": "Name of the template",
"type": "string"
Expand Down Expand Up @@ -5399,6 +5407,14 @@ const docTemplate = `{
"description": "Description of the template",
"type": "string"
},
"extended_release": {
"description": "Extended release type (eus, e4s)",
"type": "string"
},
"extended_release_version": {
"description": "Extended release version (9.4, 9.6, etc.)",
"type": "string"
},
"last_update_snapshot_error": {
"description": "Error of last update_latest_snapshot task that updated the template",
"type": "string"
Expand Down
16 changes: 16 additions & 0 deletions api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,14 @@
"description": "Description of the template",
"type": "string"
},
"extended_release": {
"description": "Extended release type (eus, e4s)",
"type": "string"
},
"extended_release_version": {
"description": "Extended release version (9.4, 9.6, etc.)",
"type": "string"
},
"name": {
"description": "Name of the template",
"type": "string"
Expand Down Expand Up @@ -1787,6 +1795,14 @@
"description": "Description of the template",
"type": "string"
},
"extended_release": {
"description": "Extended release type (eus, e4s)",
"type": "string"
},
"extended_release_version": {
"description": "Extended release version (9.4, 9.6, etc.)",
"type": "string"
},
"last_update_snapshot_error": {
"description": "Error of last update_latest_snapshot task that updated the template",
"type": "string"
Expand Down
2 changes: 1 addition & 1 deletion db/migrations.latest
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20260116141110
20260123120000
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
BEGIN;

ALTER TABLE templates
DROP COLUMN IF EXISTS extended_release,
DROP COLUMN IF EXISTS extended_release_version;

COMMIT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
BEGIN;

ALTER TABLE templates
ADD COLUMN IF NOT EXISTS extended_release VARCHAR(10) DEFAULT NULL,
ADD COLUMN IF NOT EXISTS extended_release_version VARCHAR(10) DEFAULT NULL;

COMMIT;
40 changes: 23 additions & 17 deletions pkg/api/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ import (
)

type TemplateRequest struct {
UUID *string `json:"uuid" readonly:"true" swaggerignore:"true"`
Name *string `json:"name" validate:"required"` // Name of the template
Description *string `json:"description"` // Description of the template
RepositoryUUIDS []string `json:"repository_uuids" validate:"required"` // Repositories to add to the template
Arch *string `json:"arch" validate:"required"` // Architecture of the template
Version *string `json:"version" validate:"required"` // Version of the template
Date *EmptiableDate `json:"date"` // Latest date to include snapshots for
OrgID *string `json:"org_id" readonly:"true" swaggerignore:"true"` // Organization ID of the owner
User *string `json:"created_by" readonly:"true" swaggerignore:"true"` // User creating the template
UseLatest *bool `json:"use_latest"` // Use latest snapshot for all repositories in the template
UUID *string `json:"uuid" readonly:"true" swaggerignore:"true"`
Name *string `json:"name" validate:"required"` // Name of the template
Description *string `json:"description"` // Description of the template
RepositoryUUIDS []string `json:"repository_uuids" validate:"required"` // Repositories to add to the template
Arch *string `json:"arch" validate:"required"` // Architecture of the template
Version *string `json:"version" validate:"required"` // Version of the template
ExtendedRelease *string `json:"extended_release"` // Extended release type (eus, e4s)
ExtendedReleaseVersion *string `json:"extended_release_version"` // Extended release version (9.4, 9.6, etc.)
Date *EmptiableDate `json:"date"` // Latest date to include snapshots for
OrgID *string `json:"org_id" readonly:"true" swaggerignore:"true"` // Organization ID of the owner
User *string `json:"created_by" readonly:"true" swaggerignore:"true"` // User creating the template
UseLatest *bool `json:"use_latest"` // Use latest snapshot for all repositories in the template
}

type TemplateResponse struct {
Expand All @@ -28,6 +30,8 @@ type TemplateResponse struct {
Description string `json:"description"` // Description of the template
Arch string `json:"arch"` // Architecture of the template
Version string `json:"version"` // Version of the template
ExtendedRelease string `json:"extended_release,omitempty"` // Extended release type (eus, e4s)
ExtendedReleaseVersion string `json:"extended_release_version,omitempty"` // Extended release version (9.4, 9.6, etc.)
Date time.Time `json:"date"` // Latest date to include snapshots for
RepositoryUUIDS []string `json:"repository_uuids"` // Repositories added to the template
Snapshots []SnapshotResponse `json:"snapshots,omitempty" readonly:"true"` // The list of snapshots in use by the template
Expand Down Expand Up @@ -69,13 +73,15 @@ func (r *TemplateCollectionResponse) SetMetadata(meta ResponseMetadata, links Li
}

type TemplateFilterData struct {
Name string `json:"name"` // Filter templates by name using an exact match.
Arch string `json:"arch"` // Filter templates by arch using an exact match.
Version string `json:"version"` // Filter templates by version using an exact match.
Search string `json:"search"` // Search string based query to optionally filter on
RepositoryUUIDs []string `json:"repository_uuids"` // List templates that contain one or more of these Repositories
SnapshotUUIDs []string `json:"snapshot_uuids"` // List templates that contain one or more of these Snapshots
UseLatest bool `json:"use_latest"` // List templates that have use_latest set to true
Name string `json:"name"` // Filter templates by name using an exact match.
Arch string `json:"arch"` // Filter templates by arch using an exact match.
Version string `json:"version"` // Filter templates by version using an exact match.
ExtendedRelease string `json:"extended_release"` // Filter templates by extended release type using an exact match.
ExtendedReleaseVersion string `json:"extended_release_version"` // Filter templates by extended release version using an exact match.
Search string `json:"search"` // Search string based query to optionally filter on
RepositoryUUIDs []string `json:"repository_uuids"` // List templates that contain one or more of these Repositories
SnapshotUUIDs []string `json:"snapshot_uuids"` // List templates that contain one or more of these Snapshots
UseLatest bool `json:"use_latest"` // List templates that have use_latest set to true
}

// Provides defaults if not provided during PUT request
Expand Down
14 changes: 14 additions & 0 deletions pkg/dao/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,12 @@ func (t templateDaoImpl) filteredDbForList(orgID string, filteredDB *gorm.DB, fi
if filterData.Version != "" {
filteredDB = filteredDB.Where("version = ?", filterData.Version)
}
if filterData.ExtendedRelease != "" {
filteredDB = filteredDB.Where("extended_release = ?", filterData.ExtendedRelease)
}
if filterData.ExtendedReleaseVersion != "" {
filteredDB = filteredDB.Where("extended_release_version = ?", filterData.ExtendedReleaseVersion)
}
if filterData.Search != "" {
containsSearch := "%" + filterData.Search + "%"
filteredDB = filteredDB.
Expand Down Expand Up @@ -761,6 +767,12 @@ func templatesCreateApiToModel(api api.TemplateRequest, model *models.Template)
if api.UseLatest != nil {
model.UseLatest = *api.UseLatest
}
if api.ExtendedRelease != nil {
model.ExtendedRelease = *api.ExtendedRelease
}
if api.ExtendedReleaseVersion != nil {
model.ExtendedReleaseVersion = *api.ExtendedReleaseVersion
}
}

func templatesUpdateApiToModel(api api.TemplateUpdateRequest, model *models.Template) {
Expand Down Expand Up @@ -793,6 +805,8 @@ func templatesModelToApi(model models.Template, apiTemplate *api.TemplateRespons
apiTemplate.Description = model.Description
apiTemplate.Version = model.Version
apiTemplate.Arch = model.Arch
apiTemplate.ExtendedRelease = model.ExtendedRelease
apiTemplate.ExtendedReleaseVersion = model.ExtendedReleaseVersion
apiTemplate.Date = model.Date.UTC()
apiTemplate.CreatedBy = model.CreatedBy
apiTemplate.LastUpdatedBy = model.LastUpdatedBy
Expand Down
12 changes: 8 additions & 4 deletions pkg/handler/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,12 @@ func (th *TemplateHandler) update(c echo.Context, fillDefaults bool) error {

func ParseTemplateFilters(c echo.Context) api.TemplateFilterData {
filterData := api.TemplateFilterData{
Name: "",
Version: "",
Arch: "",
Search: "",
Name: "",
Version: "",
Arch: "",
Search: "",
ExtendedRelease: "",
ExtendedReleaseVersion: "",
}
repositoryUUIDs := ""
snapshotUUIDs := ""
Expand All @@ -239,6 +241,8 @@ func ParseTemplateFilters(c echo.Context) api.TemplateFilterData {
String("repository_uuids", &repositoryUUIDs).
String("snapshot_uuids", &snapshotUUIDs).
Bool("use_latest", &filterData.UseLatest).
String("extended_release", &filterData.ExtendedRelease).
String("extended_release_version", &filterData.ExtendedReleaseVersion).
BindError()

if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/models/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type Template struct {
Date time.Time `gorm:"default:null"`
Version string `gorm:"default:null"`
Arch string `gorm:"default:null"`
ExtendedRelease string `json:"extended_release" gorm:"default:null"`
ExtendedReleaseVersion string `json:"extended_release_version" gorm:"default:null"`
DeletedAt gorm.DeletedAt `json:"deleted_at"`
CreatedBy string
LastUpdatedBy string
Expand Down
18 changes: 17 additions & 1 deletion pkg/tasks/update_template_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"net/url"
"regexp"
"slices"
"strings"
"time"
Expand Down Expand Up @@ -526,7 +527,11 @@ func (t *UpdateTemplateContent) getContentList() ([]caliri.ContentDTO, []string,
func (t *UpdateTemplateContent) getRedHatContentIDs(rhRepos []api.RepositoryResponse) ([]string, error) {
labels := []string{}
for _, rhRepo := range rhRepos {
labels = append(labels, rhRepo.Label)
label := rhRepo.Label
if rhRepo.ExtendedRelease != "" {
label = normalizeExtendedReleaseLabel(rhRepo.Label)
}
labels = append(labels, label)
}
contents, err := t.cpClient.FetchContentsByLabel(t.ctx, t.orgId, labels)
if err != nil {
Expand Down Expand Up @@ -590,3 +595,14 @@ func difference(a, b []string) []string {
}
return diff
}

// normalizeExtendedReleaseLabel normalizes extended release repository labels
// For e4s and eus repositories, the label should use the major version only
// For example: "rhel-8.6-for-x86_64-appstream-e4s-rpms" becomes "rhel-8-for-x86_64-appstream-e4s-rpms"
func normalizeExtendedReleaseLabel(label string) string {
extendedReleasePattern := regexp.MustCompile(`^(rhel-\d+)\.\d+(-for-.+-(e4s|eus)-rpms)$`)
if extendedReleasePattern.MatchString(label) {
return extendedReleasePattern.ReplaceAllString(label, `${1}${2}`)
}
return label
}
41 changes: 41 additions & 0 deletions pkg/tasks/update_template_content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,44 @@ func (s *UpdateTemplateContentSuite) TestGetDistributionPath() {
assert.Equal(s.T(), expectedCustomPath, distPath)
assert.Equal(s.T(), expectedName, distName)
}

func (s *UpdateTemplateContentSuite) TestNormalizeExtendedReleaseLabel() {
testCases := []struct {
name string
input string
expected string
}{
{
name: "e4s label with minor version",
input: "rhel-8.6-for-x86_64-appstream-e4s-rpms",
expected: "rhel-8-for-x86_64-appstream-e4s-rpms",
},
{
name: "eus label with minor version",
input: "rhel-9.4-for-x86_64-appstream-eus-rpms",
expected: "rhel-9-for-x86_64-appstream-eus-rpms",
},
{
name: "regular rhel label without extended release",
input: "rhel-8-for-x86_64-appstream-rpms",
expected: "rhel-8-for-x86_64-appstream-rpms",
},
{
name: "already normalized e4s label",
input: "rhel-9-for-x86_64-appstream-e4s-rpms",
expected: "rhel-9-for-x86_64-appstream-e4s-rpms",
},
{
name: "custom repository label",
input: "custom-repo-label",
expected: "custom-repo-label",
},
}

for _, tc := range testCases {
s.T().Run(tc.name, func(t *testing.T) {
result := normalizeExtendedReleaseLabel(tc.input)
assert.Equal(t, tc.expected, result)
})
}
}