Skip to content
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

Merged
merged 1 commit into from
Nov 18, 2017

Conversation

hbagdi
Copy link
Member

@hbagdi hbagdi commented Oct 31, 2017

Summary

Adding endpoints:

  • GET /basic-auth : lists all the basic-auths present in kong
  • GET /basic-auth/:credential_id/consumer : retrieve a consumer form a credential ID

Full changelog

  • GET /basic-auth : lists all the basic-auths present in kong
  • GET /basic-auth/:credential_id/consumer : retrieve a consumer form a credential ID
  • Add related tests

This is similar to #2955 and #2371

@thibaultcha
Copy link
Member

@hbagdi Very nice! Thank you for providing solutions to this issue in an atomic fashion (per plugin) 👍 We will get a look shortly!

We should also resume the review of #2955 very shortly as well, sorry for the delay on our side.

@@ -52,5 +52,29 @@ return {
DELETE = function(self, dao_factory)
crud.delete(self.basicauth_credential, dao_factory.basicauth_credentials)
end
},
["/basic-auth/"] = {
Copy link
Member

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?

},
["/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 }
Copy link
Member

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!

crud.paginated_set(self, dao_factory.basicauth_credentials)
end
},
["/basic-auth/:credential_id/consumer"] = {
Copy link
Member

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")

return helpers.responses.send_HTTP_NOT_FOUND()
end

self.params.credential_key_or_id = nil
Copy link
Member

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 {
Copy link
Member

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto: indentation

@thibaultcha thibaultcha added pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. and removed pr/status/please review labels Nov 1, 2017
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"
Copy link
Member

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).

Copy link
Member Author

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)
Copy link
Member

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

Copy link
Member Author

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
@thibaultcha thibaultcha removed the pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. label Nov 18, 2017
@thibaultcha thibaultcha merged commit 54487be into Kong:master Nov 18, 2017
@thibaultcha
Copy link
Member

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).

@hbagdi
Copy link
Member Author

hbagdi commented Nov 18, 2017

@thibaultcha Thanks for accepting these contributions!
You' have been very patient with minor details I missed often.
Let's look for other features/bugs where I can help out.

@hbagdi
Copy link
Member Author

hbagdi commented Nov 18, 2017

@thibaultcha couple of things we should do before the upcoming release:

@hbagdi hbagdi deleted the list-basic-auths branch November 18, 2017 02:45
@thibaultcha
Copy link
Member

Yes to all of these, definitely a must have for the release :)
We’ll take a look! Thanks for stepping forward with the docs as well.

hbagdi added a commit to hbagdi/getkong.org that referenced this pull request Nov 22, 2017
* `/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
hbagdi added a commit to hbagdi/getkong.org that referenced this pull request Nov 22, 2017
* `/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
hbagdi added a commit to hbagdi/getkong.org that referenced this pull request Nov 22, 2017
* `/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
thibaultcha pushed a commit to Kong/docs.konghq.com that referenced this pull request Nov 23, 2017
* `/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>
thibaultcha pushed a commit to Kong/docs.konghq.com that referenced this pull request Nov 23, 2017
* `/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>
thibaultcha pushed a commit to Kong/docs.konghq.com that referenced this pull request Nov 29, 2017
* `/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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants