feat(users): add granular scopes support to personal access tokens

What does this MR do?

Adds support for fine-grained personal access tokens, which are created with granular_scopes instead of the classic scopes list.

Request options

GranularScopes []*GranularScopeOptions is added to:

Options struct Endpoint GitLab
CreatePersonalAccessTokenOptions POST /users/:user_id/personal_access_tokens 19.6
CreatePersonalAccessTokenForCurrentUserOptions POST /user/personal_access_tokens 19.2
CreateImpersonationTokenOptions POST /users/:user_id/impersonation_tokens 19.2

GranularScopeOptions has Access, Permissions, GroupIDs and ProjectIDs. GroupIDs and ProjectIDs are only used with selected_memberships access.

Upstream, scopes and granular_scopes cannot be used together.

Responses

GranularScopes []*GranularScope is added to PersonalAccessToken and ImpersonationToken. The response shape is different from the request: each entry has a single project_id or group_id (null when the scope doesn't target one), so it is a separate type. The field is only present for fine-grained tokens and is omitted otherwise.

Because project and group access tokens embed PersonalAccessToken, they also pick up the field.

Testing

  • Request body tests for all three create endpoints.
  • Response unmarshalling for project-, group- and user-targeted granular scopes.
  • Existing tests cover classic tokens, where GranularScopes stays nil.
  • make reviewable

Closes #2338 (closed)

Related to gitlab-org/terraform-provider-gitlab#6868

Edited by Giannis Kepas

Merge request reports

Loading
Loading