Skip to content

Commit

Permalink
Merge pull request #2614 from Krishanx92/subscription-ratelimit
Browse files Browse the repository at this point in the history
Fix DB event issue
  • Loading branch information
CrowleyRajapakse authored Oct 24, 2024
2 parents e4d3c29 + 46d24a5 commit e32dd7a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions common-controller/internal/database/db_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func (dbDeployer DBDeployer) DeployApplication(application server.Application) e
return deployApplicationwithAttributes(tx, application)
})
server.AddApplication(application)
utils.SendApplicationEvent(constants.ApplicationCreated, application.UUID, application.Name, application.Owner,
application.OrganizationID, application.Attributes)
return nil
}

Expand All @@ -103,6 +105,8 @@ func (dbDeployer DBDeployer) UpdateApplication(application server.Application) e
})
server.DeleteApplication(application.UUID)
server.AddApplication(application)
utils.SendApplicationEvent(constants.ApplicationUpdated, application.UUID, application.Name, application.Owner,
application.OrganizationID, application.Attributes)
return nil
}

Expand All @@ -114,6 +118,8 @@ func (dbDeployer DBDeployer) DeploySubscription(subscription server.Subscription
subscription.SubStatus, subscription.Organization, subscription.RatelimitTier)
})
server.AddSubscription(subscription)
utils.SendSubscriptionEvent(constants.SubscriptionCreated, subscription.UUID, subscription.SubStatus, subscription.Organization,
subscription.SubscribedAPI.Name, subscription.SubscribedAPI.Version, subscription.RatelimitTier)
return nil
}

Expand All @@ -126,6 +132,8 @@ func (dbDeployer DBDeployer) UpdateSubscription(subscription server.Subscription
})
server.DeleteSubscription(subscription.UUID)
server.AddSubscription(subscription)
utils.SendSubscriptionEvent(constants.SubscriptionUpdated, subscription.UUID, subscription.SubStatus, subscription.Organization,
subscription.SubscribedAPI.Name, subscription.SubscribedAPI.Version, subscription.RatelimitTier)
return nil
}

Expand All @@ -137,6 +145,8 @@ func (dbDeployer DBDeployer) DeployApplicationMappings(applicationMapping server
applicationMapping.OrganizationID)
})
server.AddApplicationMapping(applicationMapping)
utils.SendApplicationMappingEvent(constants.ApplicationMappingCreated, applicationMapping.UUID, applicationMapping.ApplicationRef,
applicationMapping.SubscriptionRef, applicationMapping.OrganizationID)
return nil
}

Expand All @@ -155,6 +165,8 @@ func (dbDeployer DBDeployer) DeployKeyMappings(keyMapping server.ApplicationKeyM
})

server.AddApplicationKeyMapping(keyMapping)
utils.SendApplicationKeyMappingEvent(constants.ApplicationKeyMappingCreated, keyMapping.ApplicationUUID, keyMapping.SecurityScheme,
keyMapping.ApplicationIdentifier, keyMapping.KeyType, keyMapping.EnvID, keyMapping.OrganizationID)
return nil
}

Expand Down Expand Up @@ -184,6 +196,7 @@ func (dbDeployer DBDeployer) DeleteApplication(applicationID string) error {
return DeleteApplicationAttributes(tx, applicationID)
})
server.DeleteApplication(applicationID)
utils.SendApplicationEvent(constants.ApplicationDeleted, applicationID, "", "", "", nil)
return nil
}

Expand All @@ -194,6 +207,7 @@ func (dbDeployer DBDeployer) DeleteApplicationMappings(applicationMapping string
return DeleteAppSub(tx, applicationMapping)
})
server.DeleteApplicationMapping(applicationMapping)
utils.SendApplicationMappingEvent(constants.ApplicationMappingDeleted, applicationMapping, "", "", "")
return nil
}

Expand All @@ -206,6 +220,8 @@ func (dbDeployer DBDeployer) UpdateApplicationMappings(applicationMapping server
})
server.DeleteApplicationMapping(applicationMapping.UUID)
server.AddApplicationMapping(applicationMapping)
utils.SendApplicationMappingEvent(constants.ApplicationMappingUpdated, applicationMapping.UUID, applicationMapping.ApplicationRef,
applicationMapping.SubscriptionRef, applicationMapping.OrganizationID)
return nil
}

Expand All @@ -216,6 +232,8 @@ func (dbDeployer DBDeployer) DeleteKeyMappings(keyMapping server.ApplicationKeyM
return DeleteApplicationKeyMapping(tx, keyMapping.ApplicationUUID, keyMapping.SecurityScheme, keyMapping.EnvID)
})
server.DeleteApplicationKeyMapping(keyMapping)
utils.SendApplicationKeyMappingEvent(constants.ApplicationKeyMappingDeleted, keyMapping.ApplicationUUID, keyMapping.SecurityScheme,
keyMapping.ApplicationIdentifier, keyMapping.KeyType, keyMapping.EnvID, keyMapping.OrganizationID)
return nil
}

Expand All @@ -226,6 +244,7 @@ func (dbDeployer DBDeployer) DeleteSubscription(subscriptionID string) error {
return DeleteSubscription(tx, subscriptionID)
})
server.DeleteSubscription(subscriptionID)
utils.SendSubscriptionEvent(constants.SubscriptionDeleted, subscriptionID, "", "", "", "", "")
return nil
}

Expand Down Expand Up @@ -299,6 +318,8 @@ func (dbDeployer DBDeployer) UpdateKeyMappings(keyMapping server.ApplicationKeyM

server.DeleteApplicationKeyMapping(keyMapping)
server.AddApplicationKeyMapping(keyMapping)
utils.SendApplicationKeyMappingEvent(constants.ApplicationKeyMappingUpdated, keyMapping.ApplicationUUID, keyMapping.SecurityScheme,
keyMapping.ApplicationIdentifier, keyMapping.KeyType, keyMapping.EnvID, keyMapping.OrganizationID)
return nil
}

Expand Down

0 comments on commit e32dd7a

Please sign in to comment.