Skip to content

Commit

Permalink
fix subs validation issue
Browse files Browse the repository at this point in the history
  • Loading branch information
tharindu1st committed Feb 14, 2024
1 parent 21dba6c commit 491ffee
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
16 changes: 16 additions & 0 deletions adapter/api/proto/wso2/discovery/config/enforcer/client.proto
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion common-controller/internal/server/event_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
5 changes: 5 additions & 0 deletions common-controller/internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
5 changes: 3 additions & 2 deletions common-controller/internal/utils/event_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand All @@ -150,6 +150,7 @@ func SendDeleteApplicationMappingEvent(applicationMappingUUID string, applicatio
Uuid: applicationMappingUUID,
ApplicationRef: applicationMappingSpec.ApplicationRef,
SubscriptionRef: applicationMappingSpec.SubscriptionRef,
Organization: organization,
},
}
sendEvent(&event)
Expand Down

0 comments on commit 491ffee

Please sign in to comment.