diff --git a/adapter/api/proto/wso2/discovery/config/enforcer/client.proto b/adapter/api/proto/wso2/discovery/config/enforcer/client.proto index a7023f4cb..32d434fde 100644 --- a/adapter/api/proto/wso2/discovery/config/enforcer/client.proto +++ b/adapter/api/proto/wso2/discovery/config/enforcer/client.proto @@ -1,3 +1,19 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + syntax = "proto3"; package wso2.discovery.config.enforcer; diff --git a/common-controller/internal/operator/controllers/cp/applicationmapping_controller.go b/common-controller/internal/operator/controllers/cp/applicationmapping_controller.go index 9599f0b11..b4cda9e4f 100644 --- a/common-controller/internal/operator/controllers/cp/applicationmapping_controller.go +++ b/common-controller/internal/operator/controllers/cp/applicationmapping_controller.go @@ -121,7 +121,8 @@ func (r *ApplicationMappingReconciler) Reconcile(ctx context.Context, req ctrl.R applicationMapping, found := r.ods.GetApplicationMappingFromStore(applicationMappingKey) if found { loggers.LoggerAPKOperator.Debugf("Application mapping %s/%s found in operator data store. Deleting from operator data store and sending delete event to server", applicationMappingKey.Namespace, applicationMappingKey.Name) - utils.SendDeleteApplicationMappingEvent(applicationMappingKey.Name, applicationMapping) + resolvedApplicationMapping := server.GetApplicationMappingFromStore(applicationMappingKey.Name) + utils.SendDeleteApplicationMappingEvent(applicationMappingKey.Name, applicationMapping, resolvedApplicationMapping.OrganizationID) r.ods.DeleteApplicationMappingFromStore(applicationMappingKey) server.DeleteApplicationMapping(applicationMappingKey.Name) } else { diff --git a/common-controller/internal/server/event_server.go b/common-controller/internal/server/event_server.go index de6773957..bb0f10c13 100644 --- a/common-controller/internal/server/event_server.go +++ b/common-controller/internal/server/event_server.go @@ -2,7 +2,7 @@ package server import ( "github.com/wso2/apk/common-controller/internal/loggers" - utils "github.com/wso2/apk/common-controller/internal/utils" + "github.com/wso2/apk/common-controller/internal/utils" apkmgt "github.com/wso2/apk/common-go-libs/pkg/discovery/api/wso2/discovery/service/apkmgt" "google.golang.org/grpc/metadata" ) diff --git a/common-controller/internal/server/server.go b/common-controller/internal/server/server.go index 659e2ec6c..953560ee2 100644 --- a/common-controller/internal/server/server.go +++ b/common-controller/internal/server/server.go @@ -94,3 +94,8 @@ func DeleteSubscription(subscriptionUUID string) { func DeleteApplicationMapping(applicationMappingUUID string) { delete(applicationMappingMap, applicationMappingUUID) } + +// GetApplicationMappingFromStore returns an application mapping from the application mapping list +func GetApplicationMappingFromStore(applicationMappingUUID string) ApplicationMapping { + return applicationMappingMap[applicationMappingUUID] +} diff --git a/common-controller/internal/utils/event_utils.go b/common-controller/internal/utils/event_utils.go index d4c916224..f6a157311 100644 --- a/common-controller/internal/utils/event_utils.go +++ b/common-controller/internal/utils/event_utils.go @@ -108,7 +108,7 @@ func SendDeleteSubscriptionEvent(subscriptionUUID string, subscriptionSpec cpv1a Type: constants.SubscriptionDeleted, TimeStamp: milliseconds, Subscription: &subscription.Subscription{ - Uuid: uuid.New().String(), + Uuid: subscriptionUUID, SubStatus: subscriptionSpec.SubscriptionStatus, Organization: subscriptionSpec.Organization, SubscribedApi: &subscription.SubscribedAPI{ @@ -139,7 +139,7 @@ func SendCreateApplicationMappingEvent(applicationMapping cpv1alpha2.Application } // SendDeleteApplicationMappingEvent sends an application mapping deletion event to the enforcer -func SendDeleteApplicationMappingEvent(applicationMappingUUID string, applicationMappingSpec cpv1alpha2.ApplicationMappingSpec) { +func SendDeleteApplicationMappingEvent(applicationMappingUUID string, applicationMappingSpec cpv1alpha2.ApplicationMappingSpec, organization string) { currentTime := time.Now() milliseconds := currentTime.UnixNano() / int64(time.Millisecond) event := subscription.Event{ @@ -150,6 +150,7 @@ func SendDeleteApplicationMappingEvent(applicationMappingUUID string, applicatio Uuid: applicationMappingUUID, ApplicationRef: applicationMappingSpec.ApplicationRef, SubscriptionRef: applicationMappingSpec.SubscriptionRef, + Organization: organization, }, } sendEvent(&event)