-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(basic-auth) add endpoint to list all basic-auths #2998
Conversation
kong/plugins/basic-auth/api.lua
Outdated
@@ -52,5 +52,29 @@ return { | |||
DELETE = function(self, dao_factory) | |||
crud.delete(self.basicauth_credential, dao_factory.basicauth_credentials) | |||
end | |||
}, | |||
["/basic-auth/"] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also use the plural form /basic-auths
here as well to stay consistent with what we decided for /key-auths
?
kong/plugins/basic-auth/api.lua
Outdated
}, | ||
["/basic-auth/:credential_id/consumer"] = { | ||
before = function(self, dao_factory, helpers) | ||
local credentials, err = dao_factory.basicauth_credentials:find_all { id = self.params.credential_id } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: we should avoid exceeding the 80 columns limit for long lines as documented in our contribution guidelines. Thanks!
kong/plugins/basic-auth/api.lua
Outdated
crud.paginated_set(self, dao_factory.basicauth_credentials) | ||
end | ||
}, | ||
["/basic-auth/:credential_id/consumer"] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The /consumers/:username_or_id/basic-auth/:credential_username_or_id
endpoint provided by this plugin allows to retrieve a credential based on its username
attribute, or its id
.
Maybe we should allow the same for this endpoint as well? Any reason why we couldn't do so?
local credentials, err = crud.find_by_id_or_field(dao_factory.basicauth_credentials, nil
self.params.credential_username_or_id,
"username")
kong/plugins/basic-auth/api.lua
Outdated
return helpers.responses.send_HTTP_NOT_FOUND() | ||
end | ||
|
||
self.params.credential_key_or_id = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This instruction is not needed since the parameter is called credential_id
in this endpoint. Only if we follow my other suggestion of allowing credential_username_or_id
does it become useful if we rename it properly (not credential_key_*
).
describe("GET", function() | ||
setup(function() | ||
helpers.dao:truncate_table("basicauth_credentials") | ||
assert(helpers.dao.basicauth_credentials:insert { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like this call is further indented for not particular reason?
consumer2 = assert(helpers.dao.consumers:insert { | ||
username = "bob-the-buidler" | ||
}) | ||
assert(helpers.dao.basicauth_credentials:insert { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto: indentation
it("returns 404 for a random non-existing basic-auth id", function() | ||
local res = assert(admin_client:send { | ||
method = "GET", | ||
path = "/basic-auths/" .. utils.uuid() .. "/consumer" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we modified the parameter to be :credential_username_or_id
, we should also add a test case for a non-existing username this test case only covers non-existing id).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
assert.is_table(json.data) | ||
assert.equal(2, #json.data) | ||
assert.equal(2, json.total) | ||
end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will you also add a test case for pagination, like the one I added to /key-auths/
? You can see it here: 18f3a09#diff-a053792566ffb587af457e08fd34ec14R361
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
* `/basic-auths/` to paginate through all basic-auth credentials * `/basic-auths/:credential_id_or_username/consumer` to retrieve the Consumer associated with a credential
b774e56
to
8d013f5
Compare
Awesome, thank you very much for your hard work on those plugins! We are scheduling this for our upcoming 0.11.2 release (as per our CHANGELOG). |
@thibaultcha Thanks for accepting these contributions! |
@thibaultcha couple of things we should do before the upcoming release:
|
Yes to all of these, definitely a must have for the release :) |
* `/basic-auths/` to paginate through all basic-auth credentials * `/basic-auths/:credential_id_or_username/consumer` to retrieve the Consumer associated with a credential See: Kong/kong#2998
* `/basic-auths/` to paginate through all basic-auth credentials * `/basic-auths/:credential_id_or_username/consumer` to retrieve the Consumer associated with a credential See: Kong/kong#2998
* `/basic-auths/` to paginate through all basic-auth credentials * `/basic-auths/:credential_id_or_username/consumer` to retrieve the Consumer associated with a credential See: Kong/kong#2998
* `/basic-auths/` to paginate through all basic-auth credentials * `/basic-auths/:credential_id_or_username/consumer` to retrieve the Consumer associated with a credential See: Kong/kong#2998 From: #553 Signed-off-by: Thibault Charbonnier <thibaultcha@me.com>
* `/basic-auths/` to paginate through all basic-auth credentials * `/basic-auths/:credential_id_or_username/consumer` to retrieve the Consumer associated with a credential See: Kong/kong#2998 From: #553 Signed-off-by: Thibault Charbonnier <thibaultcha@me.com>
* `/basic-auths/` to paginate through all basic-auth credentials * `/basic-auths/:credential_id_or_username/consumer` to retrieve the Consumer associated with a credential See: Kong/kong#2998 From: #553 Signed-off-by: Thibault Charbonnier <thibaultcha@me.com>
Summary
Adding endpoints:
GET /basic-auth
: lists all the basic-auths present in kongGET /basic-auth/:credential_id/consumer
: retrieve a consumer form a credential IDFull changelog
GET /basic-auth
: lists all the basic-auths present in kongGET /basic-auth/:credential_id/consumer
: retrieve a consumer form a credential IDThis is similar to #2955 and #2371