-
Notifications
You must be signed in to change notification settings - Fork 669
feat(job_token_scope): support job token access allowlist API #2767
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
Conversation
|
||
Get a projec's CI/CD job token inbound allowlist:: | ||
|
||
allowlist = scope.allowlist.list() |
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.
Not sure yet about this naming here, but it follows both the endpoint URL and our convention 😕
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.
yeah it would definetly be clearer if it were scope.projects_allowlist
since gitlab have added groups_allowlist
https://docs.gitlab.com/ee/api/project_job_token_scopes.html#get-a-projects-cicd-job-token-allowlist-of-groups
But scope.allowlist
does absolutely match the API design doc so it is probably best overall to be consistent with their docs 🤷
try: | ||
return cast(int, getattr(self, self._id_attr)) | ||
except AttributeError: | ||
return cast(int, getattr(self, "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.
GitLab at it again - create response:
{
"source_project_id": 1,
"target_project_id": 2
}
list response:
{
"id": 4,
"description": null,
"name": "Diaspora Client",
"name_with_namespace": "Diaspora / Diaspora Client",
"path": "diaspora-client",
...
}
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 kind of thinking for the create to not return anything. As the caller appears to use all the values when creating that will be returned. Not sure if that would simplify things or not.
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.
Convention in REST and so far in python-gitlab would be to return the object that has been created. Means that in future if Gitlab add optional things into the contract which get returned back in the POST, user's would get insight into that
0b3e199
to
7b0b22d
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #2767 +/- ##
==========================================
+ Coverage 88.25% 96.42% +8.17%
==========================================
Files 90 90
Lines 5866 5880 +14
==========================================
+ Hits 5177 5670 +493
+ Misses 689 210 -479
Flags with carried forward coverage won't be shown. Click here to find out more.
|
This currently assumes a job token scope as the parent of the allowlist, but I don't think that is correct. I would expect the allowlist to work without retrieving the job token scope first:
Test could look something like this:
|
@Sjord very true, I would at least want to add support for The reason I did it this way was I wanted to follow GitLab's REST API path segment hierarchy. But lately it's making less and less sense to me, so we could also flatten this potentially - I'm not sure, also part of why this is still in draft 😅 thanks for the feedback! |
@nejch FYI if you haven't seen: Gitlab have just merged an update to GraphQL endpoint to add support for adding groups to the And hopefully will be adding the same support to the REST API: https://gitlab.com/gitlab-org/gitlab/-/issues/435903#note_1761348177
|
Thanks @TimKnight-DWP! 🙇 I'm pretty sure they will, because their terraform provider relies on REST. I'll get back to this PR this week. |
Cool - let me know if there's anything I can do to help with this MR @nejch , it's something that's high on our agenda, adding this here and then using from gitlabform to manage our state I'll take a look through Gitlabs MR and see how they intend to handle "Groups" whether it's taking group id (consistent with how projects are added) or something else. And feedback here. |
Design from Gitlab if the pattern is followed from GraphQl, either a new or the existing allowlist endpoint will use
POST I suspect they will add DELETE probably takes group id into the |
Group Allowlist REST API -> https://gitlab.com/gitlab-org/gitlab/-/merge_requests/145069 |
Sorry @Sjord this was already done in another PR as is, but I think we could look into adding a lazy get at least, so we don't require another API call to use the endpoint. |
Changes
Closes #2762.
Adds https://docs.gitlab.com/ee/api/project_job_token_scopes.html#get-a-projects-cicd-job-token-inbound-allowlist
Documentation and testing
Please consider whether this PR needs documentation and tests. This is not required, but highly appreciated: