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
2 changes: 2 additions & 0 deletions base/utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type coreConfig struct {
EvaluatorUploadPrivateAddress string
EvaluatorRecalcPrivateAddress string
ContentSourcesAddress string
ContentSourcesUser string

// cloudwatch
CloudWatchAccessKeyID string
Expand Down Expand Up @@ -192,6 +193,7 @@ func initServicesFromEnv() {
CoreCfg.CandlepinKey = Getenv("CANDLEPIN_KEY", CoreCfg.CandlepinKey)
CoreCfg.CandlepinCA = Getenv("CANDLEPIN_CA", CoreCfg.CandlepinCA)
CoreCfg.ContentSourcesAddress = Getenv("CONTENT_SOURCES_ADDRESS", CoreCfg.ContentSourcesAddress)
CoreCfg.ContentSourcesUser = Getenv("CONTENT_SOURCES_USER", CoreCfg.ContentSourcesUser)
}

func initDBFromClowder() {
Expand Down
7 changes: 5 additions & 2 deletions base/utils/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ func EncodeXRHID(id identity.Identity) (string, error) {
return base64.StdEncoding.EncodeToString(js), nil
}

func XRHIDForOrg(orgID string) identity.XRHID {
func XRHIDForOrg(orgID string, username string) identity.XRHID {
return identity.XRHID{
Identity: identity.Identity{
Type: "User",
Type: "User",
User: &identity.User{
Username: username,
},
OrgID: orgID,
Internal: identity.Internal{
OrgID: orgID,
Expand Down
6 changes: 4 additions & 2 deletions base/utils/identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ func TestEncodeXRHID(t *testing.T) {
assert.Equal(t, testIdentityString, identityString)
}

func TestXRHIDForOrg(t *testing.T) {
func TestContentSourcesXRHIDForOrg(t *testing.T) {
const testUser = "test-user"
orgID := "1234"
xrhid := XRHIDForOrg(orgID)
xrhid := XRHIDForOrg(orgID, testUser)

assert.Equal(t, orgID, xrhid.Identity.OrgID)
assert.Equal(t, orgID, xrhid.Identity.Internal.OrgID)
assert.Equal(t, "User", xrhid.Identity.Type)
assert.Equal(t, testUser, xrhid.Identity.User.Username)
}
1 change: 1 addition & 0 deletions conf/common.env
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ ENABLE_PROFILER=true

CANDLEPIN_ADDRESS=http://platform:9001/candlepin
CONTENT_SOURCES_ADDRESS=http://platform:9001
CONTENT_SOURCES_USER=test-user
1 change: 1 addition & 0 deletions conf/local.env
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ DB_SSLROOTCERT=dev/database/secrets/pgca.crt
VMAAS_ADDRESS=http://localhost:9001
CANDLEPIN_ADDRESS=http://localhost:9001/candlepin
CONTENT_SOURCES_ADDRESS=http://localhost:9001
CONTENT_SOURCES_USER=test-user

KAFKA_ADDRESS=localhost:9092
KAFKA_GROUP=patchman
Expand Down
2 changes: 2 additions & 0 deletions deploy/clowdapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ objects:
- {name: ENABLE_PROFILER, value: '${ENABLE_PROFILER_LISTENER}'}
- {name: GOMEMLIMIT, value: '${GOMEMLIMIT_LISTENER}'}
- {name: POD_CONFIG, value: '${LISTENER_CONFIG}'}
- {name: CONTENT_SOURCES_USER, value: '${CONTENT_SOURCES_USER}'}

resources:
limits: {cpu: '${CPU_LIMIT_LISTENER}', memory: '${MEM_LIMIT_LISTENER}'}
Expand Down Expand Up @@ -790,6 +791,7 @@ parameters:
- {name: ENABLE_PROFILER_LISTENER, value: 'false'}
- {name: GOMEMLIMIT_LISTENER, value: '691MiB'} # set to 90% of the default memory limit (don't forget `B`)
- {name: LISTENER_CONFIG, value: ''}
- {name: CONTENT_SOURCES_USER, value: ''}

# Evaluator
- {name: GOGC, value: '100'}
Expand Down
8 changes: 6 additions & 2 deletions listener/template_advisories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ func setupContentSourcesClient(t *testing.T) {
originalAddress := utils.CoreCfg.ContentSourcesAddress
address := utils.Getenv("CONTENT_SOURCES_ADDRESS", "http://platform:9001")
utils.CoreCfg.ContentSourcesAddress = address
originalUser := utils.CoreCfg.ContentSourcesUser
user := utils.Getenv("CONTENT_SOURCES_USER", "test-user")
utils.CoreCfg.ContentSourcesUser = user
contentSourcesClient = content_sources.CreateContentSourcesClient()
contentSourcesBaseURL = address + "/api/content-sources/v1"
t.Cleanup(func() {
utils.CoreCfg.ContentSourcesAddress = originalAddress
contentSourcesClient = nil
contentSourcesBaseURL = ""
utils.CoreCfg.ContentSourcesUser = originalUser
})
}

Expand All @@ -31,7 +35,7 @@ func TestCallCSTemplateAdvisories(t *testing.T) {

templateUUID := "99900000-0000-0000-0000-000000000001"
orgID := "org_1"
ctx := identity.WithIdentity(context.Background(), utils.XRHIDForOrg(orgID))
ctx := identity.WithIdentity(context.Background(), utils.XRHIDForOrg(orgID, utils.CoreCfg.ContentSourcesUser))
result, err := callCSTemplateAdvisories(ctx, templateUUID)

assert.NoError(t, err)
Expand Down Expand Up @@ -127,7 +131,7 @@ func TestSyncTemplateAdvisories(t *testing.T) {
defer database.DeleteTemplateAdvisories(t, templateID, []int64{1, 2, 3})

// content sources mock returns RH-1 and RH-3 so we need to add RH-3, remove RH-2
ctx := identity.WithIdentity(context.Background(), utils.XRHIDForOrg(orgID))
ctx := identity.WithIdentity(context.Background(), utils.XRHIDForOrg(orgID, utils.CoreCfg.ContentSourcesUser))
err := syncTemplateAdvisories(ctx, accountID, templateID, templateUUID, orgID)
assert.Nil(t, err)

Expand Down
5 changes: 3 additions & 2 deletions listener/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ func TemplateUpdate(template mqueue.TemplateResponse, eventType string) error {
return errors.Wrap(err, "creating/updating template from message")
}

if contentSourcesBaseURL != "" && eventType == TemplateEventUpdate {
ctx := identity.WithIdentity(context.Background(), utils.XRHIDForOrg(template.OrgID))
if contentSourcesBaseURL != "" && utils.CoreCfg.ContentSourcesUser != "" && eventType == TemplateEventUpdate {
ctx := identity.WithIdentity(context.Background(),
utils.XRHIDForOrg(template.OrgID, utils.CoreCfg.ContentSourcesUser))
err = syncTemplateAdvisories(ctx, accountID, row.ID, template.UUID, template.OrgID)
if err != nil {
return errors.Wrap(err, "syncing template advisories")
Expand Down
Loading