Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
Use correct tenant for calling subscription API in System Field Disco…
Browse files Browse the repository at this point in the history
…very Engine flow (#3696)

* use right tenant for subscription

* bump values.yaml
  • Loading branch information
dragobt authored Mar 1, 2024
1 parent 692444c commit 1a4c377
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion chart/compass/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ global:
name: compass-pairing-adapter
director:
dir: dev/incubator/
version: "PR-3693"
version: "PR-3696"
name: compass-director
hydrator:
dir: dev/incubator/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ func (s *service) createApplicationFromTemplate(ctx context.Context, appTemplate
if !ok {
log.C(ctx).Infof("%s label for Application Template with ID %s is not a boolean", webhookprocessor.SystemFieldDiscoveryLabelKey, appTemplate.ID)
} else {
appCreateInputModel.Webhooks, systemFieldDiscoveryLabelIsTrue = s.systemFieldDiscoveryEngine.EnrichApplicationWebhookIfNeeded(ctx, appCreateInputModel, systemFieldDiscoveryValue, region, subscribedSubaccountID, appTemplate.Name, subscribedAppName)
appCreateInputModel.Webhooks, systemFieldDiscoveryLabelIsTrue = s.systemFieldDiscoveryEngine.EnrichApplicationWebhookIfNeeded(ctx, appCreateInputModel, systemFieldDiscoveryValue, region, consumerTenantID, appTemplate.Name, subscribedAppName)
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions components/director/internal/domain/subscription/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ func TestSubscribeTenantToApplication(t *testing.T) {
newWebhooks := modelAppCreateInputWithLabels.Webhooks
newWebhooks = append(newWebhooks, &model.WebhookInput{
Type: model.WebhookTypeSystemFieldDiscovery})
systemFieldDiscoveryEngine.On("EnrichApplicationWebhookIfNeeded", ctxWithTenantMatcher(subaccountTenantInternalID), modelAppCreateInputWithLabels, systemFieldDiscoveryLabelIsTrue, tenantRegionWithPrefix, subaccountTenantExtID, modelAppTemplate.Name, subscriptionAppName).Return(newWebhooks, true).Once()
systemFieldDiscoveryEngine.On("EnrichApplicationWebhookIfNeeded", ctxWithTenantMatcher(subaccountTenantInternalID), modelAppCreateInputWithLabels, systemFieldDiscoveryLabelIsTrue, tenantRegionWithPrefix, consumerTenantID, modelAppTemplate.Name, subscriptionAppName).Return(newWebhooks, true).Once()
systemFieldDiscoveryEngine.On("CreateLabelForApplicationWebhook", ctxWithTenantMatcher(subaccountTenantInternalID), appTmplID).Return(nil).Once()

return systemFieldDiscoveryEngine
Expand Down Expand Up @@ -1316,7 +1316,7 @@ func TestSubscribeTenantToApplication(t *testing.T) {
newWebhooks := modelAppCreateInputWithLabels.Webhooks
newWebhooks = append(newWebhooks, &model.WebhookInput{
Type: model.WebhookTypeSystemFieldDiscovery})
systemFieldDiscoveryEngine.On("EnrichApplicationWebhookIfNeeded", ctxWithTenantMatcher(subaccountTenantInternalID), modelAppCreateInputWithLabels, systemFieldDiscoveryLabelIsTrue, tenantRegionWithPrefix, subaccountTenantExtID, modelAppTemplate.Name, subscriptionAppName).Return(newWebhooks, true).Once()
systemFieldDiscoveryEngine.On("EnrichApplicationWebhookIfNeeded", ctxWithTenantMatcher(subaccountTenantInternalID), modelAppCreateInputWithLabels, systemFieldDiscoveryLabelIsTrue, tenantRegionWithPrefix, consumerTenantID, modelAppTemplate.Name, subscriptionAppName).Return(newWebhooks, true).Once()
systemFieldDiscoveryEngine.On("CreateLabelForApplicationWebhook", ctxWithTenantMatcher(subaccountTenantInternalID), appTmplID).Return(nil).Once()

return systemFieldDiscoveryEngine
Expand Down Expand Up @@ -1574,7 +1574,7 @@ func TestSubscribeTenantToApplication(t *testing.T) {
newWebhooks := modelAppCreateInputWithLabels.Webhooks
newWebhooks = append(newWebhooks, &model.WebhookInput{
Type: model.WebhookTypeSystemFieldDiscovery})
systemFieldDiscoveryEngine.On("EnrichApplicationWebhookIfNeeded", ctxWithTenantMatcher(subaccountTenantInternalID), modelAppCreateInputWithLabels, systemFieldDiscoveryLabelIsTrue, tenantRegionWithPrefix, subaccountTenantExtID, modelAppTemplate.Name, subscriptionAppName).Return(newWebhooks, true).Once()
systemFieldDiscoveryEngine.On("EnrichApplicationWebhookIfNeeded", ctxWithTenantMatcher(subaccountTenantInternalID), modelAppCreateInputWithLabels, systemFieldDiscoveryLabelIsTrue, tenantRegionWithPrefix, consumerTenantID, modelAppTemplate.Name, subscriptionAppName).Return(newWebhooks, true).Once()
systemFieldDiscoveryEngine.On("CreateLabelForApplicationWebhook", ctxWithTenantMatcher(subaccountTenantInternalID), appTmplID).Return(nil).Once()

return systemFieldDiscoveryEngine
Expand Down Expand Up @@ -1839,7 +1839,7 @@ func TestSubscribeTenantToApplication(t *testing.T) {
newWebhooks := modelAppCreateInputWithLabels.Webhooks
newWebhooks = append(newWebhooks, &model.WebhookInput{
Type: model.WebhookTypeSystemFieldDiscovery})
systemFieldDiscoveryEngine.On("EnrichApplicationWebhookIfNeeded", ctxWithTenantMatcher(subaccountTenantInternalID), modelAppCreateInputWithLabels, systemFieldDiscoveryLabelIsTrue, tenantRegionWithPrefix, subaccountTenantExtID, modelAppTemplate.Name, subscriptionAppName).Return(newWebhooks, true).Once()
systemFieldDiscoveryEngine.On("EnrichApplicationWebhookIfNeeded", ctxWithTenantMatcher(subaccountTenantInternalID), modelAppCreateInputWithLabels, systemFieldDiscoveryLabelIsTrue, tenantRegionWithPrefix, consumerTenantID, modelAppTemplate.Name, subscriptionAppName).Return(newWebhooks, true).Once()
systemFieldDiscoveryEngine.AssertNotCalled(t, "CreateLabelForApplicationWebhook")

return systemFieldDiscoveryEngine
Expand Down Expand Up @@ -1894,7 +1894,7 @@ func TestSubscribeTenantToApplication(t *testing.T) {
newWebhooks := modelAppCreateInputWithLabels.Webhooks
newWebhooks = append(newWebhooks, &model.WebhookInput{
Type: model.WebhookTypeSystemFieldDiscovery})
systemFieldDiscoveryEngine.On("EnrichApplicationWebhookIfNeeded", ctxWithTenantMatcher(subaccountTenantInternalID), modelAppCreateInputWithLabels, systemFieldDiscoveryLabelIsTrue, tenantRegionWithPrefix, subaccountTenantExtID, modelAppTemplate.Name, subscriptionAppName).Return(newWebhooks, true).Once()
systemFieldDiscoveryEngine.On("EnrichApplicationWebhookIfNeeded", ctxWithTenantMatcher(subaccountTenantInternalID), modelAppCreateInputWithLabels, systemFieldDiscoveryLabelIsTrue, tenantRegionWithPrefix, consumerTenantID, modelAppTemplate.Name, subscriptionAppName).Return(newWebhooks, true).Once()
systemFieldDiscoveryEngine.On("CreateLabelForApplicationWebhook", ctxWithTenantMatcher(subaccountTenantInternalID), appTmplID).Return(testError).Once()

return systemFieldDiscoveryEngine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ func NewSystemFieldDiscoveryEngine(cfg config.SystemFieldDiscoveryEngineConfig,
}

// EnrichApplicationWebhookIfNeeded enriches application webhook input with webhook of type 'SYSTEM_FIELD_DISCOVERY' if needed
func (s *systemFieldDiscoveryEngine) EnrichApplicationWebhookIfNeeded(ctx context.Context, appCreateInputModel model.ApplicationRegisterInput, systemFieldDiscovery bool, region, subaccountID, appTemplateName, appName string) ([]*model.WebhookInput, bool) {
func (s *systemFieldDiscoveryEngine) EnrichApplicationWebhookIfNeeded(ctx context.Context, appCreateInputModel model.ApplicationRegisterInput, systemFieldDiscovery bool, region, tenantID, appTemplateName, appName string) ([]*model.WebhookInput, bool) {
if _, regionExists := s.cfg.RegionToSaasRegConfig[region]; !regionExists {
log.C(ctx).Warnf("Region %q is not present into the saas reg configuration for application with name %q", region, appName)
return appCreateInputModel.Webhooks, false
}

if systemFieldDiscovery {
log.C(ctx).Infof("Application Template with name %q has label systemFieldDiscovery with value %t and region %q is present into the configuration. Enriching the application with name %q with webhook of type %q", appTemplateName, systemFieldDiscovery, region, appName, model.WebhookTypeSystemFieldDiscovery)
appCreateInputModel.Webhooks = s.enrichWithWebhook(appCreateInputModel.Webhooks, region, subaccountID)
appCreateInputModel.Webhooks = s.enrichWithWebhook(appCreateInputModel.Webhooks, region, tenantID)
log.C(ctx).Infof("Successfully enriched Application with name %q with webhook of type %q", appName, model.WebhookTypeSystemFieldDiscovery)
}

Expand Down Expand Up @@ -95,10 +95,10 @@ func (s *systemFieldDiscoveryEngine) CreateLabelForApplicationWebhook(ctx contex
return nil
}

func (s *systemFieldDiscoveryEngine) enrichWithWebhook(modelInputWebhooks []*model.WebhookInput, region, subaccountID string) []*model.WebhookInput {
func (s *systemFieldDiscoveryEngine) enrichWithWebhook(modelInputWebhooks []*model.WebhookInput, region, tenantID string) []*model.WebhookInput {
modelInputWebhooks = append(modelInputWebhooks, &model.WebhookInput{
Type: model.WebhookTypeSystemFieldDiscovery,
URL: str.Ptr(fmt.Sprintf("%s/saas-manager/v1/service/subscriptions?includeIndirectSubscriptions=true&tenantId=%s", s.cfg.RegionToSaasRegConfig[region].SaasRegistryURL, subaccountID)),
URL: str.Ptr(fmt.Sprintf("%s/saas-manager/v1/service/subscriptions?includeIndirectSubscriptions=true&tenantId=%s", s.cfg.RegionToSaasRegConfig[region].SaasRegistryURL, tenantID)),
Auth: &model.AuthInput{
Credential: &model.CredentialDataInput{
Oauth: &model.OAuthCredentialDataInput{
Expand Down

0 comments on commit 1a4c377

Please sign in to comment.