Skip to content

Commit

Permalink
Clean codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
ashera96 committed Nov 1, 2023
1 parent 269c3fb commit 1069553
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 884 deletions.
134 changes: 0 additions & 134 deletions adapter/internal/discovery/xds/marshaller.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,100 +279,6 @@ func MarshalKeyManager(keyManager *types.KeyManager) *keymgt.KeyManagerConfig {
return nil
}

// // MarshalMultipleApplications is used to update the applicationList during the startup where
// // multiple applications are pulled at once. And then it returns the ApplicationList.
// func MarshalMultipleApplications(appList *types.ApplicationList) *subscription.ApplicationList {
// resourceMap := make(map[string]*subscription.Application)
// for item := range appList.List {
// application := appList.List[item]
// applicationSub := marshalApplication(&application)
// resourceMap[application.UUID] = applicationSub
// }
// ApplicationMap = resourceMap
// return marshalApplicationMapToList(ApplicationMap)
// }

// // MarshalApplicationEventAndReturnList handles the Application Event corresponding to the event received
// // from message broker. And then it returns the ApplicationList.
// func MarshalApplicationEventAndReturnList(application *types.Application,
// eventType EventType) *subscription.ApplicationList {
// if eventType == DeleteEvent {
// delete(ApplicationMap, application.UUID)
// logger.LoggerXds.Infof("Application %s is deleted.", application.UUID)
// } else {
// applicationSub := marshalApplication(application)
// ApplicationMap[application.UUID] = applicationSub
// if eventType == CreateEvent {
// logger.LoggerXds.Infof("Application %s is added.", application.UUID)
// } else {
// logger.LoggerXds.Infof("Application %s is updated.", application.UUID)
// }
// }
// return marshalApplicationMapToList(ApplicationMap)
// }

// // MarshalMultipleApplicationKeyMappings is used to update the application key mappings during the startup where
// // multiple key mappings are pulled at once. And then it returns the ApplicationKeyMappingList.
// func MarshalMultipleApplicationKeyMappings(keymappingList *types.ApplicationKeyMappingList) *subscription.ApplicationKeyMappingList {
// resourceMap := make(map[string]*subscription.ApplicationKeyMapping)
// for item := range keymappingList.List {
// keyMapping := keymappingList.List[item]
// applicationKeyMappingReference := GetApplicationKeyMappingReference(&keyMapping)
// keyMappingSub := marshalKeyMapping(&keyMapping)
// resourceMap[applicationKeyMappingReference] = keyMappingSub
// }
// ApplicationKeyMappingMap = resourceMap
// return marshalKeyMappingMapToList(ApplicationKeyMappingMap)
// }

// // MarshalApplicationKeyMappingEventAndReturnList handles the Application Key Mapping Event corresponding to the event received
// // from message broker. And then it returns the ApplicationKeyMappingList.
// func MarshalApplicationKeyMappingEventAndReturnList(keyMapping *types.ApplicationKeyMapping,
// eventType EventType) *subscription.ApplicationKeyMappingList {
// applicationKeyMappingReference := GetApplicationKeyMappingReference(keyMapping)
// if eventType == DeleteEvent {
// delete(ApplicationKeyMappingMap, applicationKeyMappingReference)
// logger.LoggerXds.Infof("Application Key Mapping for the applicationKeyMappingReference %s is removed.",
// applicationKeyMappingReference)
// } else {
// keyMappingSub := marshalKeyMapping(keyMapping)
// ApplicationKeyMappingMap[applicationKeyMappingReference] = keyMappingSub
// logger.LoggerXds.Infof("Application Key Mapping for the applicationKeyMappingReference %s is added.",
// applicationKeyMappingReference)
// }
// return marshalKeyMappingMapToList(ApplicationKeyMappingMap)
// }

// // MarshalMultipleSubscriptions is used to update the subscriptions during the startup where
// // multiple subscriptions are pulled at once. And then it returns the SubscriptionList.
// func MarshalMultipleSubscriptions(subscriptionsList *types.SubscriptionList) *subscription.SubscriptionList {
// resourceMap := make(map[int32]*subscription.Subscription)
// for item := range subscriptionsList.List {
// sb := subscriptionsList.List[item]
// resourceMap[sb.SubscriptionID] = marshalSubscription(&sb)
// }
// SubscriptionMap = resourceMap
// return marshalSubscriptionMapToList(SubscriptionMap)
// }

// // MarshalSubscriptionEventAndReturnList handles the Subscription Event corresponding to the event received
// // from message broker. And then it returns the SubscriptionList.
// func MarshalSubscriptionEventAndReturnList(sub *types.Subscription, eventType EventType) *subscription.SubscriptionList {
// if eventType == DeleteEvent {
// delete(SubscriptionMap, sub.SubscriptionID)
// logger.LoggerXds.Infof("Subscription for %s:%s is deleted.", sub.APIUUID, sub.ApplicationUUID)
// } else {
// subscriptionSub := marshalSubscription(sub)
// SubscriptionMap[sub.SubscriptionID] = subscriptionSub
// if eventType == UpdateEvent {
// logger.LoggerXds.Infof("Subscription for %s:%s is updated.", sub.APIUUID, sub.ApplicationUUID)
// } else {
// logger.LoggerXds.Infof("Subscription for %s:%s is added.", x.APIUUID, sub.ApplicationUUID)
// }
// }
// return marshalSubscriptionMapToList(SubscriptionMap)
// }

// MarshalMultipleApplicationPolicies is used to update the applicationPolicies during the startup where
// multiple application policies are pulled at once. And then it returns the ApplicationPolicyList.
func MarshalMultipleApplicationPolicies(policies *types.ApplicationPolicyList) *subscription.ApplicationPolicyList {
Expand Down Expand Up @@ -499,40 +405,6 @@ func MarshalAPIForLifeCycleChangeEventAndReturnList(apiUUID, status, gatewayLabe
return marshalAPIListMapToList(APIListMap[gatewayLabel])
}

// func marshalSubscription(subscriptionInternal *types.Subscription) *subscription.Subscription {
// api := &subscription.API{
// Name: subscriptionInternal.Api.Name,
// Versions: subscriptionInternal.Api.Versions,
// }
// sub := &subscription.Subscription{
// Uuid: subscriptionInternal.SubscriptionUUID,
// SubStatus: subscriptionInternal.SubscriptionStatus,
// Organization: subscriptionInternal.Organization,
// }
// sub.Api = api
// return sub
// }

// func marshalApplication(appInternal *types.Application) *subscription.Application {
// app := &subscription.Application{
// Uuid: appInternal.UUID,
// Name: appInternal.Name,
// Owner: appInternal.Owner,
// Attributes: appInternal.Attributes,
// }
// return app
// }

// func marshalKeyMapping(keyMappingInternal *types.ApplicationKeyMapping) *subscription.ApplicationKeyMapping {
// return &subscription.ApplicationKeyMapping{
// ApplicationUUID: keyMappingInternal.ApplicationUUID,
// ApplicationIdentifier: keyMappingInternal.ApplicationIdentifier,
// KeyType: keyMappingInternal.KeyType,
// EnvID: keyMappingInternal.EnvId,
// Timestamp: keyMappingInternal.TimeStamp,
// }
// }

func marshalAPIMetadata(api *types.API) *subscription.APIs {
return &subscription.APIs{
ApiId: strconv.Itoa(api.APIID),
Expand Down Expand Up @@ -573,12 +445,6 @@ func marshalSubscriptionPolicy(policy *types.SubscriptionPolicy) *subscription.S
}
}

// // GetApplicationKeyMappingReference returns unique reference for each key Mapping event.
// // It is the combination of consumerKey
// func GetApplicationKeyMappingReference(keyMapping *types.ApplicationKeyMapping) string {
// return keyMapping.ApplicationIdentifier
// }

// CheckIfAPIMetadataIsAlreadyAvailable returns true only if the API Metadata for the given API UUID
// is already available
func CheckIfAPIMetadataIsAlreadyAvailable(apiUUID, label string) bool {
Expand Down
68 changes: 0 additions & 68 deletions adapter/internal/discovery/xds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,9 @@ type EnvoyGatewayConfig struct {
type EnforcerInternalAPI struct {
configs []types.Resource
keyManagers []types.Resource
// subscriptions []types.Resource
// applications []types.Resource
apiList []types.Resource
applicationPolicies []types.Resource
subscriptionPolicies []types.Resource
// applicationKeyMappings []types.Resource
revokedTokens []types.Resource
jwtIssuers []types.Resource
}
Expand All @@ -97,12 +94,9 @@ var (
cache envoy_cachev3.SnapshotCache
enforcerCache wso2_cache.SnapshotCache
enforcerJwtIssuerCache wso2_cache.SnapshotCache
// enforcerSubscriptionCache wso2_cache.SnapshotCache
// enforcerApplicationCache wso2_cache.SnapshotCache
enforcerAPICache wso2_cache.SnapshotCache
enforcerApplicationPolicyCache wso2_cache.SnapshotCache
enforcerSubscriptionPolicyCache wso2_cache.SnapshotCache
// enforcerApplicationKeyMappingCache wso2_cache.SnapshotCache
enforcerKeyManagerCache wso2_cache.SnapshotCache
enforcerRevokedTokensCache wso2_cache.SnapshotCache
enforcerThrottleDataCache wso2_cache.SnapshotCache
Expand Down Expand Up @@ -563,48 +557,6 @@ func UpdateEnforcerApis(label string, apis []types.Resource, version string) {
UpdateEnforcerAPIList(label, subAPIList)
}

// // UpdateEnforcerSubscriptions sets new update to the enforcer's Subscriptions
// func UpdateEnforcerSubscriptions(subscriptions *subscription.SubscriptionList) {
// //TODO: (Dinusha) check this hardcoded value
// logger.LoggerXds.Debug("Updating Enforcer Subscription Cache")
// label := commonEnforcerLabel
// subscriptionList := append(enforcerLabelMap[label].subscriptions, subscriptions)

// // TODO: (VirajSalaka) Decide if a map is required to keep version (just to avoid having the same version)
// version, _ := crand.Int(crand.Reader, maxRandomBigInt())
// snap, _ := wso2_cache.NewSnapshot(fmt.Sprint(version), map[wso2_resource.Type][]types.Resource{
// wso2_resource.SubscriptionListType: subscriptionList,
// })
// snap.Consistent()

// errSetSnap := enforcerSubscriptionCache.SetSnapshot(context.Background(), label, snap)
// if errSetSnap != nil {
// logger.LoggerXds.ErrorC(logging.PrintError(logging.Error1414, logging.MAJOR, "Error while setting the snapshot : %v", errSetSnap.Error()))
// }
// enforcerLabelMap[label].subscriptions = subscriptionList
// logger.LoggerXds.Infof("New Subscription cache update for the label: " + label + " version: " + fmt.Sprint(version))
// }

// // UpdateEnforcerApplications sets new update to the enforcer's Applications
// func UpdateEnforcerApplications(applications *subscription.ApplicationList) {
// logger.LoggerXds.Debug("Updating Enforcer Application Cache")
// label := commonEnforcerLabel
// applicationList := append(enforcerLabelMap[label].applications, applications)

// version, _ := crand.Int(crand.Reader, maxRandomBigInt())
// snap, _ := wso2_cache.NewSnapshot(fmt.Sprint(version), map[wso2_resource.Type][]types.Resource{
// wso2_resource.ApplicationListType: applicationList,
// })
// snap.Consistent()

// errSetSnap := enforcerApplicationCache.SetSnapshot(context.Background(), label, snap)
// if errSetSnap != nil {
// logger.LoggerXds.ErrorC(logging.PrintError(logging.Error1414, logging.MAJOR, "Error while setting the snapshot : %v", errSetSnap.Error()))
// }
// enforcerLabelMap[label].applications = applicationList
// logger.LoggerXds.Infof("New Application cache update for the label: " + label + " version: " + fmt.Sprint(version))
// }

// UpdateEnforcerJWTIssuers sets new update to the enforcer's Applications
func UpdateEnforcerJWTIssuers(jwtIssuers *subscription.JWTIssuerList) {
logger.LoggerXds.Debug("Updating Enforcer JWT Issuer Cache")
Expand Down Expand Up @@ -684,26 +636,6 @@ func UpdateEnforcerSubscriptionPolicies(subscriptionPolicies *subscription.Subsc
logger.LoggerXds.Infof("New Subscription Policy cache update for the label: " + label + " version: " + fmt.Sprint(version))
}

// // UpdateEnforcerApplicationKeyMappings sets new update to the enforcer's Application Key Mappings
// func UpdateEnforcerApplicationKeyMappings(applicationKeyMappings *subscription.ApplicationKeyMappingList) {
// logger.LoggerXds.Debug("Updating Application Key Mapping Cache")
// label := commonEnforcerLabel
// applicationKeyMappingList := append(enforcerLabelMap[label].applicationKeyMappings, applicationKeyMappings)

// version, _ := crand.Int(crand.Reader, maxRandomBigInt())
// snap, _ := wso2_cache.NewSnapshot(fmt.Sprint(version), map[wso2_resource.Type][]types.Resource{
// wso2_resource.ApplicationKeyMappingListType: applicationKeyMappingList,
// })
// snap.Consistent()

// errSetSnap := enforcerApplicationKeyMappingCache.SetSnapshot(context.Background(), label, snap)
// if errSetSnap != nil {
// logger.LoggerXds.ErrorC(logging.PrintError(logging.Error1414, logging.MAJOR, "Error while setting the snapshot : %v", errSetSnap.Error()))
// }
// enforcerLabelMap[label].applicationKeyMappings = applicationKeyMappingList
// logger.LoggerXds.Infof("New Application Key Mapping cache update for the label: " + label + " version: " + fmt.Sprint(version))
// }

// UpdateXdsCacheWithLock uses mutex and lock to avoid different go routines updating XDS at the same time
func UpdateXdsCacheWithLock(label string, endpoints []types.Resource, clusters []types.Resource, routes []types.Resource,
listeners []types.Resource) bool {
Expand Down

This file was deleted.

Loading

0 comments on commit 1069553

Please sign in to comment.