-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugins) convert plugins to routes & services
--- tests(statsd) make statsd plugin work with routes & services --- feat(galileo, ldap) stop using ctx.api Plugins still using it: oauth2, rate limiting, response rate limiting --- use service_id & route_id in rate-limiting plugin --- feat(response-rate-limiting) use route_id & service_id in rrl --- feat(oauth2) use service_id in oauth2 plugin
- Loading branch information
1 parent
5de5803
commit def201f
Showing
31 changed files
with
1,450 additions
and
901 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,72 @@ | ||
local cassandra = require "cassandra" | ||
|
||
|
||
local _Services = {} | ||
|
||
local fmt = string.format | ||
|
||
function _Services:delete(primary_key) | ||
local ok, err_t = self.super.delete(self, primary_key) | ||
if not ok then | ||
return nil, err_t | ||
end | ||
|
||
local plugins = {} | ||
local connector = self.connector | ||
local cluster = connector.cluster | ||
local _Services = {} | ||
|
||
-- retrieve plugins associated with this Service | ||
|
||
local query = "SELECT * FROM plugins WHERE service_id = ? ALLOW FILTERING" | ||
local args = { cassandra.uuid(primary_key.id) } | ||
local function select_by_service_id(cluster, table_name, service_id, errors) | ||
local select_q = fmt("SELECT * FROM %s WHERE service_id = ?", | ||
table_name) | ||
local res = {} | ||
local count = 0 | ||
|
||
for rows, err in cluster:iterate(query, args) do | ||
for rows, err in cluster:iterate(select_q, { cassandra.uuid(service_id) }) do | ||
if err then | ||
return nil, self.errors:database_error("could not fetch plugins " .. | ||
"for Service: " .. err) | ||
return nil, | ||
errors:database_error( | ||
fmt("could not fetch %s for Service: %s", table_name, err)) | ||
end | ||
|
||
for i = 1, #rows do | ||
table.insert(plugins, rows[i]) | ||
count = count + 1 | ||
res[count] = rows[i] | ||
end | ||
end | ||
|
||
-- CASCADE delete associated plugins | ||
return res | ||
end | ||
|
||
local function delete_cascade(connector, table_name, service_id, errors) | ||
local entities = select_by_service_id(connector.cluster, table_name, service_id, errors) | ||
|
||
for i = 1, #entities do | ||
local delete_q = fmt("DELETE from %s WHERE id = ?", table_name) | ||
|
||
for i = 1, #plugins do | ||
local res, err = connector:query("DELETE FROM plugins WHERE id = ?", { | ||
cassandra.uuid(plugins[i].id) | ||
local res, err = connector:query(delete_q, { | ||
cassandra.uuid(entities[i].id) | ||
}, nil, "write") | ||
|
||
if not res then | ||
return nil, self.errors:database_error("could not delete plugin " .. | ||
"associated with Service: " .. err) | ||
return nil, errors:database_error( | ||
fmt("could not delete instance of %s associated with Service: %s", | ||
table_name, err)) | ||
end | ||
end | ||
|
||
return true | ||
end | ||
|
||
|
||
function _Services:delete(primary_key) | ||
local ok, err_t = self.super.delete(self, primary_key) | ||
if not ok then | ||
return nil, err_t | ||
end | ||
|
||
local connector = self.connector | ||
local service_id = primary_key.id | ||
local errors = self.errors | ||
|
||
local ok1, err1 = delete_cascade(connector, "plugins", service_id, errors) | ||
local ok2, err2 = delete_cascade(connector, "oauth2_tokens", service_id, errors) | ||
local ok3, err3 = delete_cascade(connector, "oauth2_authorization_codes", service_id, errors) | ||
|
||
return ok1 and ok2 and ok3, | ||
err1 or err2 or err3 | ||
end | ||
|
||
|
||
return _Services |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.