-
Notifications
You must be signed in to change notification settings - Fork 108
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
GET and DELETE method for managing api_key #3410
GET and DELETE method for managing api_key #3410
Conversation
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.
I think we need to cover a few holes, and I've got some comments on consistency, but this is a great start.
Ha. I ran into this myself recently, where a defined URI template parameter is optional. The response = self.post(api=API.KEY, {"key": ""} That'll turn the It's fairly easy to run the functional tests on your branch before submitting. I always do
(Although because I'm on RHEL 8 instead of RHEL 9 or Fedora, I need to prefix the runlocal with |
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.
I second Dave's comment: this is a very good start, but it needs some polish. Also, the deletion test raises a concern: I think the ADMIN user should not be receiving FORBIDDEN
, so we need to modify that test to use some other user, fix the CUT so that the ADMIN can delete someone else's key, and add a test which proves it.
lib/pbench/server/database/alembic/versions/e695e86f722a_update_api_key.py
Outdated
Show resolved
Hide resolved
lib/pbench/server/database/alembic/versions/e695e86f722a_update_api_key.py
Outdated
Show resolved
Hide resolved
lib/pbench/server/database/alembic/versions/e695e86f722a_update_api_key.py
Outdated
Show resolved
Hide resolved
lib/pbench/server/database/alembic/versions/1a91bc68d6de_update_api_key.py
Outdated
Show resolved
Hide resolved
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.
I'm not happy about the difference between api_key
in the table vs key
in the .as_json()
response. I think we need to fix that. While I'd actually rather rename the column because api_key
in the api_keys
table seems unnecessary, it'd be easier to just use the "proper" key in .as_json()
. 😆
So just a few comments now, and I've closed virtually all of my previous conversations.
One final comment. I didn't make an issue of this during the PR review; but I think I should have, and I'd really like everyone on the team to start thinking of this along with unit testing. Please consider writing a functional test for this new code. I already created a functional test case to prove that I can create an API key and use it to authenticate a You might consider creating a But, aside from making the suggestion, I won't require changes for that at this point. (Although if you don't, a follow-up PR with functional tests would be great...) |
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 PR is coming along well, but I don't think it's "there" yet.
My foremost concern is that the unit testing seems a little weak (this on top of Dave's excellent point that PR's should include appropriate functional tests along with unit tests). I think that if there were more complete unit tests, some of the items that I'm calling out below might have been self-evident.
- I don't think we have support in this change for Admin users being able to delete other users' keys, and I think we should. This is important functionality, and I think that ignoring it has sent us in an elegant but awkward direction with the currently proposed change.
- I think we need some clarity around the
GET /key
andGET /key/<id>
interfaces. These have a common implementation mostly due to the vagaries of the underlying framework rather than any obvious design intent. I think they need to be teased apart, at least in principle. - We don't seem to be using the
APIKey.query_by_id()
function except in the tests (which don't really need it). If that's the case, then please remove it unless there is a compelling reason to retain it (or, at least, move the definition into the test code). - I don't think the new
pbench_user_token()
fixture is necessary; we have an existing fixture which should suffice. - The assertions in the unit tests around the contents of the key seem like they could use some work. In the cases where we check "all" of them, we're not checking all them (e.g., we don't check the creation date and we frequently don't check the user/username); however, in most cases we don't need to check anything other than the ID or value of the key (just enough to ensure that it's the "right" one).
- Also, the tests which check that we can query and fetch keys by some attribute check that we get all the keys which match but that always amounts to "all the keys there are", which suggests that they aren't as rigorous as the should be. (I'll grant, we don't really need for the tests to be checking whether SQLite works, but we do need to be sure that the CUT is using it properly.)
- The testing of
GET /key?name
seems a little light. I'm not sure that we have any tests which omit thename
parameter (we have one test which specifies an empty string, which I don't think amounts to the same thing).
And, I have a few smaller things, below.
There are also a few lingering items from my earlier review.
|
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.
I suspect that we don't want (in general) to have a single PR create multiple Alembic migration scripts. Could you merge the two scripts (or regenerate a single one)?
lib/pbench/server/database/alembic/versions/8e43d4c470a7_rename_api_key.py
Outdated
Show resolved
Hide resolved
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.
OK, all the big issues have been addressed, and we're down to just medium, small, and nit-level items...so I'm marking this PR as "approved", and I'll leave it up to you to decide whether to address the remainder.
That said, some of the bigger items remaining are:
- Renaming the
name
column todescription
orlabel
. - Polymorphism issues in the
GET
method (particularly its docstring) - Checking in the unit tests for (lack of) collateral affects when deleting keys
lib/pbench/server/database/alembic/versions/1a91bc68d6de_update_api_key.py
Outdated
Show resolved
Hide resolved
lib/pbench/server/database/alembic/versions/1a91bc68d6de_update_api_key.py
Show resolved
Hide resolved
|
I'm assuming these errors are due to changes in the scanners. They both seem to be legitimate, but not very interesting to us... and definitely not related to your changes. The "Javascript" code problem seems to be related to the Tool Meister Prometheus support:
I haven't investigated, but I'm assuming this means we're That is to say, this has nothing to do with your change, and may be configuration changes in the code scanner. We should fix this with another PR; and we can either force your change in regardless of these annoying messages, figure out how to prevent the scanner from complaining about this, or wait for that "fix" to go in. For the Python scanner, this seems to be
This one appears to be because despite the Again, we need to figure out how to either reconfigure the scanners to not care, or fix the root issue, perhaps, as I mentioned, by rewriting this mock as Python. |
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 is looking pretty much done, now. There are just a couple of lingering questions:
- Auditing details.
- Naming of SQL constraints for Alembic.
- My
POST
-with-key question. (@dbutenhof?) - And the annoyance below. 😏
...but we don't have to gate the merge on any of them.
lib/pbench/server/database/alembic/versions/1a91bc68d6de_update_api_key.py
Outdated
Show resolved
Hide resolved
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.
Looks really good
@@ -26,20 +29,74 @@ def __init__(self, config: PbenchServerConfig): | |||
ApiSchema( | |||
ApiMethod.POST, | |||
OperationCode.CREATE, | |||
query_schema=Schema( | |||
Parameter("label", ParamType.STRING, required=False), |
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 default required value is False
but I guess it's fine to be explicit.
792d2c9
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.
Sorry, but I really don't like defining a POST
schema parameter just to reject it, and there happens to be a better way... 😁
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.
Looks like it's only failing due to #3417.
It's merged now, Siddardh you can rebase on main now. |
…None value to unique
Done. Rebased 👍 |
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.
Looks great.
This PR deals with some updation in the
POST
method with/api/v1/key?label=label
where thatlabel
will be associated with the key generatedAdded
GET /api/v1/key
to retrieve the user's keys andDELETE /api/v1/key/{key_id}
to delete a key.Modified the
APIKey
table withid
field as primary_key.