From fa3ea0c59057f3beaedbe3a06d3e8d256beab803 Mon Sep 17 00:00:00 2001 From: George Wu Date: Mon, 4 Sep 2023 14:08:15 -0700 Subject: [PATCH] Add group access token rotation and project access token rotation. --- group_access_tokens.go | 24 ++++++++++++++++++++++++ project_access_tokens.go | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/group_access_tokens.go b/group_access_tokens.go index 3d42ab531..090e02ace 100644 --- a/group_access_tokens.go +++ b/group_access_tokens.go @@ -145,6 +145,30 @@ func (s *GroupAccessTokensService) CreateGroupAccessToken(gid interface{}, opt * return pat, resp, nil } +// RotateGroupAccessToken revokes a group access token and returns a new group +// access token that expires in one week. +// GitLab API docs: +// https://docs.gitlab.com/ee/api/group_access_tokens.html#rotate-a-group-access-token +func (s *GroupAccessTokensService) RotateGroupAccessToken(gid interface{}, id int, options ...RequestOptionFunc) (*GroupAccessToken, *Response, error) { + groups, err := parseID(gid) + if err != nil { + return nil, nil, err + } + u := fmt.Sprintf("groups/%s/access_tokens/%d/rotate", PathEscape(groups), id) + req, err := s.client.NewRequest(http.MethodPost, u, nil, options) + if err != nil { + return nil, nil, err + } + + gat := new(GroupAccessToken) + resp, err := s.client.Do(req, gat) + if err != nil { + return nil, resp, err + } + + return gat, resp, nil +} + // RevokeGroupAccessToken revokes a group access token. // // GitLab API docs: diff --git a/project_access_tokens.go b/project_access_tokens.go index 9fa510d09..b18c38608 100644 --- a/project_access_tokens.go +++ b/project_access_tokens.go @@ -146,6 +146,30 @@ func (s *ProjectAccessTokensService) CreateProjectAccessToken(pid interface{}, o return pat, resp, nil } +// RotateProjectAccessToken revokes a project access token and returns a new +// project access token that expires in one week. +// GitLab API docs: +// https://docs.gitlab.com/ee/api/project_access_tokens.html#rotate-a-project-access-token +func (s *ProjectAccessTokensService) RotateProjectAccessToken(pid interface{}, id int, options ...RequestOptionFunc) (*ProjectAccessToken, *Response, error) { + projects, err := parseID(pid) + if err != nil { + return nil, nil, err + } + u := fmt.Sprintf("projects/%s/access_tokens/%d/rotate", PathEscape(projects), id) + req, err := s.client.NewRequest(http.MethodPost, u, nil, options) + if err != nil { + return nil, nil, err + } + + pat := new(ProjectAccessToken) + resp, err := s.client.Do(req, pat) + if err != nil { + return nil, resp, err + } + + return pat, resp, nil +} + // RevokeProjectAccessToken revokes a project access token. // // GitLab API docs: