Skip to content

Commit e45517d

Browse files
authored
Fixes 4943: support upload repos in templates (#872)
1 parent 398a3d2 commit e45517d

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

pkg/tasks/candlepin_helpers.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,19 @@ func GenContentDto(repo api.RepositoryResponse) caliri.ContentDTO {
2323
if repo.OrgID != config.RedHatOrg && repo.GpgKey != "" {
2424
gpgKeyUrl = models.CandlepinContentGpgKeyUrl(repo.OrgID, repo.UUID)
2525
}
26+
url := repo.URL
27+
if repo.Origin == config.OriginUpload {
28+
url = repo.LatestSnapshotURL
29+
}
30+
2631
return caliri.ContentDTO{
2732
Id: &id,
2833
Type: &repoType,
2934
Label: &repoLabel,
3035
Name: &repoName,
3136
Vendor: &repoVendor,
3237
GpgUrl: gpgKeyUrl,
33-
ContentUrl: &repo.URL, // Set to upstream URL, but it is not used. Will use content overrides instead.
38+
ContentUrl: &url, // Set to upstream URL, but it is not used. Will use content overrides instead.
3439
}
3540
}
3641

pkg/tasks/candlepin_helpers_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,26 @@ func (s *CandlepinHelpersTest) TestGenContentDto() {
4343
assert.True(s.T(), strings.HasSuffix(*dto.GpgUrl, "/api/content-sources/v1.0/repository_gpg_key/abce"))
4444
}
4545

46+
func (s *CandlepinHelpersTest) TestGenContentDtoUpload() {
47+
repo := api.RepositoryResponse{
48+
UUID: "abce",
49+
Name: "MyTestRepo",
50+
Label: "my_test_repo",
51+
URL: "",
52+
Origin: config.OriginUpload,
53+
AccountID: "1234",
54+
OrgID: "1234",
55+
GpgKey: "",
56+
LatestSnapshotURL: "http://example.com/snapshot",
57+
}
58+
59+
dto := GenContentDto(repo)
60+
assert.Equal(s.T(), repo.Name, *dto.Name)
61+
assert.Equal(s.T(), repo.Label, *dto.Label)
62+
assert.Equal(s.T(), "", *dto.GpgUrl)
63+
assert.Equal(s.T(), *dto.ContentUrl, repo.LatestSnapshotURL)
64+
}
65+
4666
func (s *CandlepinHelpersTest) TestUnneededOverrides() {
4767
existing := []caliri.ContentOverrideDTO{{
4868
Name: utils.Ptr("foo"),

pkg/tasks/update_template_content.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ func (t *UpdateTemplateContent) demoteContent(repoConfigUUIDs []string) error {
487487
// Returns list of custom content to be created, a list of custom content IDs, a list of red hat content IDs, and an error.
488488
func (t *UpdateTemplateContent) getContentList() ([]caliri.ContentDTO, []string, []string, error) {
489489
uuids := strings.Join(t.payload.RepoConfigUUIDs, ",")
490-
repoConfigs, _, err := t.daoReg.RepositoryConfig.List(t.ctx, t.orgId, api.PaginationData{Limit: -1}, api.FilterData{UUID: uuids, Origin: config.OriginExternal})
490+
repoConfigs, _, err := t.daoReg.RepositoryConfig.List(t.ctx, t.orgId, api.PaginationData{Limit: -1}, api.FilterData{UUID: uuids, Origin: strings.Join([]string{config.OriginExternal, config.OriginUpload}, ",")})
491491
if err != nil {
492492
return nil, nil, nil, err
493493
}

0 commit comments

Comments
 (0)