forked from Kong/kong
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: keyauth/basicauth APIs + their tests
- keyauth and basicauth plugins now have their APIs updated and their route feels more RESTful too, they are accessible via /consumers/:consumer/keyauth - A migration was needed to be able to retrieve them per consumer. - Slightly better file structure Related to Kong#98 Former-commit-id: 4c0ff2dc64a7dcb607472fe164c0b97ee5b9bd87
- Loading branch information
1 parent
f546c36
commit cf132dd
Showing
17 changed files
with
550 additions
and
195 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
database/migrations/cassandra/2015-05-22-235608_plugins_fix.lua
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
local Migration = { | ||
name = "2015-05-22-235608_plugins_fix", | ||
|
||
up = function(options) | ||
return [[ | ||
CREATE INDEX IF NOT EXISTS ON keyauth_credentials(consumer_id); | ||
CREATE INDEX IF NOT EXISTS ON basicauth_credentials(consumer_id); | ||
]] | ||
end, | ||
|
||
down = function(options) | ||
return [[ | ||
DROP INDEX keyauth_credentials_consumer_id_idx; | ||
DROP INDEX basicauth_credentials_consumer_id_idx; | ||
]] | ||
end | ||
} | ||
|
||
return Migration |
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
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,11 +1,51 @@ | ||
-- Copyright (C) Mashape, Inc. | ||
local crud = require "kong.api.crud_helpers" | ||
|
||
local BaseController = require "kong.api.routes.base_controller" | ||
return { | ||
["/consumers/:username_or_id/basicauth/"] = { | ||
before = function(self, dao_factory, helpers) | ||
crud.find_consumer_by_username_or_id(self, dao_factory, helpers) | ||
self.params.consumer_id = self.consumer.id | ||
end, | ||
|
||
local BasicAuthCredentials = BaseController:extend() | ||
GET = function(self, dao_factory, helpers) | ||
crud.paginated_set(self, dao_factory.basicauth_credentials) | ||
end, | ||
|
||
function BasicAuthCredentials:new() | ||
BasicAuthCredentials.super.new(self, dao.basicauth_credentials, "basicauth_credentials") | ||
end | ||
PUT = function(self, dao_factory) | ||
crud.put(self.params, dao_factory.basicauth_credentials) | ||
end, | ||
|
||
return BasicAuthCredentials | ||
POST = function(self, dao_factory) | ||
crud.post(self.params, dao_factory.basicauth_credentials) | ||
end | ||
}, | ||
|
||
["/consumers/:username_or_id/basicauth/:id"] = { | ||
before = function(self, dao_factory, helpers) | ||
crud.find_consumer_by_username_or_id(self, dao_factory, helpers) | ||
self.params.consumer_id = self.consumer.id | ||
|
||
local data, err = dao_factory.basicauth_credentials:find_by_keys({ id = self.params.id }) | ||
if err then | ||
return helpers.yield_error(err) | ||
end | ||
|
||
self.credential = data[1] | ||
if not self.credential then | ||
return helpers.responses.send_HTTP_NOT_FOUND() | ||
end | ||
end, | ||
|
||
GET = function(self, dao_factory, helpers) | ||
return helpers.responses.send_HTTP_OK(self.credential) | ||
end, | ||
|
||
PATCH = function(self, dao_factory) | ||
crud.patch(self.params, dao_factory.basicauth_credentials) | ||
end, | ||
|
||
DELETE = function(self, dao_factory) | ||
crud.delete(self.credential.id, dao_factory.basicauth_credentials) | ||
end | ||
} | ||
} |
Oops, something went wrong.