aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/xanzy/go-gitlab/users.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/xanzy/go-gitlab/users.go')
-rw-r--r--vendor/github.com/xanzy/go-gitlab/users.go265
1 files changed, 177 insertions, 88 deletions
diff --git a/vendor/github.com/xanzy/go-gitlab/users.go b/vendor/github.com/xanzy/go-gitlab/users.go
index 350d593..b24f45d 100644
--- a/vendor/github.com/xanzy/go-gitlab/users.go
+++ b/vendor/github.com/xanzy/go-gitlab/users.go
@@ -1,5 +1,5 @@
//
-// Copyright 2015, Sander van Harmelen
+// Copyright 2017, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -25,16 +25,14 @@ import (
// UsersService handles communication with the user related methods of
// the GitLab API.
//
-// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md
+// GitLab API docs: https://docs.gitlab.com/ce/api/users.html
type UsersService struct {
client *Client
}
// User represents a GitLab user.
//
-// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md
+// GitLab API docs: https://docs.gitlab.com/ce/api/users.html
type User struct {
ID int `json:"id"`
Username string `json:"username"`
@@ -70,8 +68,7 @@ type UserIdentity struct {
// ListUsersOptions represents the available ListUsers() options.
//
-// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#list-users
+// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#list-users
type ListUsersOptions struct {
ListOptions
Active *bool `url:"active,omitempty" json:"active,omitempty"`
@@ -81,8 +78,7 @@ type ListUsersOptions struct {
// ListUsers gets a list of users.
//
-// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#list-users
+// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#list-users
func (s *UsersService) ListUsers(opt *ListUsersOptions, options ...OptionFunc) ([]*User, *Response, error) {
req, err := s.client.NewRequest("GET", "users", opt, options)
if err != nil {
@@ -100,8 +96,7 @@ func (s *UsersService) ListUsers(opt *ListUsersOptions, options ...OptionFunc) (
// GetUser gets a single user.
//
-// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#single-user
+// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#single-user
func (s *UsersService) GetUser(user int, options ...OptionFunc) (*User, *Response, error) {
u := fmt.Sprintf("users/%d", user)
@@ -121,30 +116,28 @@ func (s *UsersService) GetUser(user int, options ...OptionFunc) (*User, *Respons
// CreateUserOptions represents the available CreateUser() options.
//
-// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#user-creation
+// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#user-creation
type CreateUserOptions struct {
- Email *string `url:"email,omitempty" json:"email,omitempty"`
- Password *string `url:"password,omitempty" json:"password,omitempty"`
- Username *string `url:"username,omitempty" json:"username,omitempty"`
- Name *string `url:"name,omitempty" json:"name,omitempty"`
- Skype *string `url:"skype,omitempty" json:"skype,omitempty"`
- Linkedin *string `url:"linkedin,omitempty" json:"linkedin,omitempty"`
- Twitter *string `url:"twitter,omitempty" json:"twitter,omitempty"`
- WebsiteURL *string `url:"website_url,omitempty" json:"website_url,omitempty"`
- ProjectsLimit *int `url:"projects_limit,omitempty" json:"projects_limit,omitempty"`
- ExternUID *string `url:"extern_uid,omitempty" json:"extern_uid,omitempty"`
- Provider *string `url:"provider,omitempty" json:"provider,omitempty"`
- Bio *string `url:"bio,omitempty" json:"bio,omitempty"`
- Admin *bool `url:"admin,omitempty" json:"admin,omitempty"`
- CanCreateGroup *bool `url:"can_create_group,omitempty" json:"can_create_group,omitempty"`
- Confirm *bool `url:"confirm,omitempty" json:"confirm,omitempty"`
+ Email *string `url:"email,omitempty" json:"email,omitempty"`
+ Password *string `url:"password,omitempty" json:"password,omitempty"`
+ Username *string `url:"username,omitempty" json:"username,omitempty"`
+ Name *string `url:"name,omitempty" json:"name,omitempty"`
+ Skype *string `url:"skype,omitempty" json:"skype,omitempty"`
+ Linkedin *string `url:"linkedin,omitempty" json:"linkedin,omitempty"`
+ Twitter *string `url:"twitter,omitempty" json:"twitter,omitempty"`
+ WebsiteURL *string `url:"website_url,omitempty" json:"website_url,omitempty"`
+ ProjectsLimit *int `url:"projects_limit,omitempty" json:"projects_limit,omitempty"`
+ ExternUID *string `url:"extern_uid,omitempty" json:"extern_uid,omitempty"`
+ Provider *string `url:"provider,omitempty" json:"provider,omitempty"`
+ Bio *string `url:"bio,omitempty" json:"bio,omitempty"`
+ Admin *bool `url:"admin,omitempty" json:"admin,omitempty"`
+ CanCreateGroup *bool `url:"can_create_group,omitempty" json:"can_create_group,omitempty"`
+ SkipConfirmation *bool `url:"skip_confirmation,omitempty" json:"skip_confirmation,omitempty"`
}
// CreateUser creates a new user. Note only administrators can create new users.
//
-// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#user-creation
+// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#user-creation
func (s *UsersService) CreateUser(opt *CreateUserOptions, options ...OptionFunc) (*User, *Response, error) {
req, err := s.client.NewRequest("POST", "users", opt, options)
if err != nil {
@@ -162,8 +155,7 @@ func (s *UsersService) CreateUser(opt *CreateUserOptions, options ...OptionFunc)
// ModifyUserOptions represents the available ModifyUser() options.
//
-// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#user-modification
+// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#user-modification
type ModifyUserOptions struct {
Email *string `url:"email,omitempty" json:"email,omitempty"`
Password *string `url:"password,omitempty" json:"password,omitempty"`
@@ -184,8 +176,7 @@ type ModifyUserOptions struct {
// ModifyUser modifies an existing user. Only administrators can change attributes
// of a user.
//
-// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#user-modification
+// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#user-modification
func (s *UsersService) ModifyUser(user int, opt *ModifyUserOptions, options ...OptionFunc) (*User, *Response, error) {
u := fmt.Sprintf("users/%d", user)
@@ -209,8 +200,7 @@ func (s *UsersService) ModifyUser(user int, opt *ModifyUserOptions, options ...O
// actually deleted or not. In the former the user is returned and in the
// latter not.
//
-// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#user-deletion
+// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#user-deletion
func (s *UsersService) DeleteUser(user int, options ...OptionFunc) (*Response, error) {
u := fmt.Sprintf("users/%d", user)
@@ -224,8 +214,7 @@ func (s *UsersService) DeleteUser(user int, options ...OptionFunc) (*Response, e
// CurrentUser gets currently authenticated user.
//
-// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#current-user
+// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#current-user
func (s *UsersService) CurrentUser(options ...OptionFunc) (*User, *Response, error) {
req, err := s.client.NewRequest("GET", "user", nil, options)
if err != nil {
@@ -243,8 +232,7 @@ func (s *UsersService) CurrentUser(options ...OptionFunc) (*User, *Response, err
// SSHKey represents a SSH key.
//
-// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#list-ssh-keys
+// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#list-ssh-keys
type SSHKey struct {
ID int `json:"id"`
Title string `json:"title"`
@@ -254,8 +242,7 @@ type SSHKey struct {
// ListSSHKeys gets a list of currently authenticated user's SSH keys.
//
-// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#list-ssh-keys
+// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#list-ssh-keys
func (s *UsersService) ListSSHKeys(options ...OptionFunc) ([]*SSHKey, *Response, error) {
req, err := s.client.NewRequest("GET", "user/keys", nil, options)
if err != nil {
@@ -275,7 +262,7 @@ func (s *UsersService) ListSSHKeys(options ...OptionFunc) ([]*SSHKey, *Response,
// only for admin
//
// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#list-ssh-keys-for-user
+// https://docs.gitlab.com/ce/api/users.html#list-ssh-keys-for-user
func (s *UsersService) ListSSHKeysForUser(user int, options ...OptionFunc) ([]*SSHKey, *Response, error) {
u := fmt.Sprintf("users/%d/keys", user)
@@ -295,10 +282,9 @@ func (s *UsersService) ListSSHKeysForUser(user int, options ...OptionFunc) ([]*S
// GetSSHKey gets a single key.
//
-// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#single-ssh-key
-func (s *UsersService) GetSSHKey(kid int, options ...OptionFunc) (*SSHKey, *Response, error) {
- u := fmt.Sprintf("user/keys/%d", kid)
+// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#single-ssh-key
+func (s *UsersService) GetSSHKey(key int, options ...OptionFunc) (*SSHKey, *Response, error) {
+ u := fmt.Sprintf("user/keys/%d", key)
req, err := s.client.NewRequest("GET", u, nil, options)
if err != nil {
@@ -316,8 +302,7 @@ func (s *UsersService) GetSSHKey(kid int, options ...OptionFunc) (*SSHKey, *Resp
// AddSSHKeyOptions represents the available AddSSHKey() options.
//
-// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/projects.md#add-ssh-key
+// GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#add-ssh-key
type AddSSHKeyOptions struct {
Title *string `url:"title,omitempty" json:"title,omitempty"`
Key *string `url:"key,omitempty" json:"key,omitempty"`
@@ -325,8 +310,7 @@ type AddSSHKeyOptions struct {
// AddSSHKey creates a new key owned by the currently authenticated user.
//
-// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#add-ssh-key
+// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#add-ssh-key
func (s *UsersService) AddSSHKey(opt *AddSSHKeyOptions, options ...OptionFunc) (*SSHKey, *Response, error) {
req, err := s.client.NewRequest("POST", "user/keys", opt, options)
if err != nil {
@@ -345,8 +329,7 @@ func (s *UsersService) AddSSHKey(opt *AddSSHKeyOptions, options ...OptionFunc) (
// AddSSHKeyForUser creates new key owned by specified user. Available only for
// admin.
//
-// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#add-ssh-key-for-user
+// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#add-ssh-key-for-user
func (s *UsersService) AddSSHKeyForUser(user int, opt *AddSSHKeyOptions, options ...OptionFunc) (*SSHKey, *Response, error) {
u := fmt.Sprintf("users/%d/keys", user)
@@ -369,9 +352,9 @@ func (s *UsersService) AddSSHKeyForUser(user int, opt *AddSSHKeyOptions, options
// available results in 200 OK.
//
// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#delete-ssh-key-for-current-owner
-func (s *UsersService) DeleteSSHKey(kid int, options ...OptionFunc) (*Response, error) {
- u := fmt.Sprintf("user/keys/%d", kid)
+// https://docs.gitlab.com/ce/api/users.html#delete-ssh-key-for-current-owner
+func (s *UsersService) DeleteSSHKey(key int, options ...OptionFunc) (*Response, error) {
+ u := fmt.Sprintf("user/keys/%d", key)
req, err := s.client.NewRequest("DELETE", u, nil, options)
if err != nil {
@@ -385,9 +368,9 @@ func (s *UsersService) DeleteSSHKey(kid int, options ...OptionFunc) (*Response,
// for admin.
//
// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#delete-ssh-key-for-given-user
-func (s *UsersService) DeleteSSHKeyForUser(user int, kid int, options ...OptionFunc) (*Response, error) {
- u := fmt.Sprintf("users/%d/keys/%d", user, kid)
+// https://docs.gitlab.com/ce/api/users.html#delete-ssh-key-for-given-user
+func (s *UsersService) DeleteSSHKeyForUser(user, key int, options ...OptionFunc) (*Response, error) {
+ u := fmt.Sprintf("users/%d/keys/%d", user, key)
req, err := s.client.NewRequest("DELETE", u, nil, options)
if err != nil {
@@ -399,12 +382,11 @@ func (s *UsersService) DeleteSSHKeyForUser(user int, kid int, options ...OptionF
// BlockUser blocks the specified user. Available only for admin.
//
-// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#block-user
+// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#block-user
func (s *UsersService) BlockUser(user int, options ...OptionFunc) error {
u := fmt.Sprintf("users/%d/block", user)
- req, err := s.client.NewRequest("PUT", u, nil, options)
+ req, err := s.client.NewRequest("POST", u, nil, options)
if err != nil {
return err
}
@@ -428,12 +410,11 @@ func (s *UsersService) BlockUser(user int, options ...OptionFunc) error {
// UnblockUser unblocks the specified user. Available only for admin.
//
-// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#unblock-user
+// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#unblock-user
func (s *UsersService) UnblockUser(user int, options ...OptionFunc) error {
u := fmt.Sprintf("users/%d/unblock", user)
- req, err := s.client.NewRequest("PUT", u, nil, options)
+ req, err := s.client.NewRequest("POST", u, nil, options)
if err != nil {
return err
}
@@ -465,8 +446,7 @@ type Email struct {
// ListEmails gets a list of currently authenticated user's Emails.
//
-// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#list-emails
+// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#list-emails
func (s *UsersService) ListEmails(options ...OptionFunc) ([]*Email, *Response, error) {
req, err := s.client.NewRequest("GET", "user/emails", nil, options)
if err != nil {
@@ -486,9 +466,9 @@ func (s *UsersService) ListEmails(options ...OptionFunc) ([]*Email, *Response, e
// only for admin
//
// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#list-emails-for-user
-func (s *UsersService) ListEmailsForUser(uid int, options ...OptionFunc) ([]*Email, *Response, error) {
- u := fmt.Sprintf("users/%d/emails", uid)
+// https://docs.gitlab.com/ce/api/users.html#list-emails-for-user
+func (s *UsersService) ListEmailsForUser(user int, options ...OptionFunc) ([]*Email, *Response, error) {
+ u := fmt.Sprintf("users/%d/emails", user)
req, err := s.client.NewRequest("GET", u, nil, options)
if err != nil {
@@ -506,10 +486,9 @@ func (s *UsersService) ListEmailsForUser(uid int, options ...OptionFunc) ([]*Ema
// GetEmail gets a single email.
//
-// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#single-email
-func (s *UsersService) GetEmail(eid int, options ...OptionFunc) (*Email, *Response, error) {
- u := fmt.Sprintf("user/emails/%d", eid)
+// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#single-email
+func (s *UsersService) GetEmail(email int, options ...OptionFunc) (*Email, *Response, error) {
+ u := fmt.Sprintf("user/emails/%d", email)
req, err := s.client.NewRequest("GET", u, nil, options)
if err != nil {
@@ -527,16 +506,14 @@ func (s *UsersService) GetEmail(eid int, options ...OptionFunc) (*Email, *Respon
// AddEmailOptions represents the available AddEmail() options.
//
-// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/projects.md#add-email
+// GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#add-email
type AddEmailOptions struct {
Email *string `url:"email,omitempty" json:"email,omitempty"`
}
// AddEmail creates a new email owned by the currently authenticated user.
//
-// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#add-email
+// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#add-email
func (s *UsersService) AddEmail(opt *AddEmailOptions, options ...OptionFunc) (*Email, *Response, error) {
req, err := s.client.NewRequest("POST", "user/emails", opt, options)
if err != nil {
@@ -555,10 +532,9 @@ func (s *UsersService) AddEmail(opt *AddEmailOptions, options ...OptionFunc) (*E
// AddEmailForUser creates new email owned by specified user. Available only for
// admin.
//
-// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#add-email-for-user
-func (s *UsersService) AddEmailForUser(uid int, opt *AddEmailOptions, options ...OptionFunc) (*Email, *Response, error) {
- u := fmt.Sprintf("users/%d/emails", uid)
+// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#add-email-for-user
+func (s *UsersService) AddEmailForUser(user int, opt *AddEmailOptions, options ...OptionFunc) (*Email, *Response, error) {
+ u := fmt.Sprintf("users/%d/emails", user)
req, err := s.client.NewRequest("POST", u, opt, options)
if err != nil {
@@ -579,9 +555,9 @@ func (s *UsersService) AddEmailForUser(uid int, opt *AddEmailOptions, options ..
// available results in 200 OK.
//
// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#delete-email-for-current-owner
-func (s *UsersService) DeleteEmail(eid int, options ...OptionFunc) (*Response, error) {
- u := fmt.Sprintf("user/emails/%d", eid)
+// https://docs.gitlab.com/ce/api/users.html#delete-email-for-current-owner
+func (s *UsersService) DeleteEmail(email int, options ...OptionFunc) (*Response, error) {
+ u := fmt.Sprintf("user/emails/%d", email)
req, err := s.client.NewRequest("DELETE", u, nil, options)
if err != nil {
@@ -595,9 +571,122 @@ func (s *UsersService) DeleteEmail(eid int, options ...OptionFunc) (*Response, e
// for admin.
//
// GitLab API docs:
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/users.md#delete-email-for-given-user
-func (s *UsersService) DeleteEmailForUser(uid int, eid int, options ...OptionFunc) (*Response, error) {
- u := fmt.Sprintf("users/%d/emails/%d", uid, eid)
+// https://docs.gitlab.com/ce/api/users.html#delete-email-for-given-user
+func (s *UsersService) DeleteEmailForUser(user, email int, options ...OptionFunc) (*Response, error) {
+ u := fmt.Sprintf("users/%d/emails/%d", user, email)
+
+ req, err := s.client.NewRequest("DELETE", u, nil, options)
+ if err != nil {
+ return nil, err
+ }
+
+ return s.client.Do(req, nil)
+}
+
+// ImpersonationToken represents an impersonation token.
+//
+// GitLab API docs:
+// https://docs.gitlab.com/ce/api/users.html#get-all-impersonation-tokens-of-a-user
+type ImpersonationToken struct {
+ ID int `json:"id"`
+ Name string `json:"name"`
+ Active bool `json:"active"`
+ Token string `json:"token"`
+ Scopes []string `json:"scopes"`
+ Revoked bool `json:"revoked"`
+ CreatedAt *time.Time `json:"created_at"`
+ ExpiresAt *time.Time `json:"expires_at"`
+}
+
+// GetAllImpersonationTokensOptions represents the available
+// GetAllImpersonationTokens() options.
+//
+// GitLab API docs:
+// https://docs.gitlab.com/ce/api/users.html#get-all-impersonation-tokens-of-a-user
+type GetAllImpersonationTokensOptions struct {
+ State *string `url:"state,omitempty" json:"state,omitempty"`
+}
+
+// GetAllImpersonationTokens retrieves all impersonation tokens of a user.
+//
+// GitLab API docs:
+// https://docs.gitlab.com/ce/api/users.html#get-all-impersonation-tokens-of-a-user
+func (s *UsersService) GetAllImpersonationTokens(user int, opt *GetAllImpersonationTokensOptions, options ...OptionFunc) ([]*ImpersonationToken, *Response, error) {
+ u := fmt.Sprintf("users/%d/impersonation_tokens", user)
+
+ req, err := s.client.NewRequest("GET", u, opt, options)
+ if err != nil {
+ return nil, nil, err
+ }
+
+ var ts []*ImpersonationToken
+ resp, err := s.client.Do(req, &ts)
+ if err != nil {
+ return nil, resp, err
+ }
+
+ return ts, resp, err
+}
+
+// GetImpersonationToken retrieves an impersonation token of a user.
+//
+// GitLab API docs:
+// https://docs.gitlab.com/ce/api/users.html#get-an-impersonation-token-of-a-user
+func (s *UsersService) GetImpersonationToken(user, token int, options ...OptionFunc) (*ImpersonationToken, *Response, error) {
+ u := fmt.Sprintf("users/%d/impersonation_tokens/%d", user, token)
+
+ req, err := s.client.NewRequest("GET", u, nil, options)
+ if err != nil {
+ return nil, nil, err
+ }
+
+ t := new(ImpersonationToken)
+ resp, err := s.client.Do(req, &t)
+ if err != nil {
+ return nil, resp, err
+ }
+
+ return t, resp, err
+}
+
+// CreateImpersonationTokenOptions represents the available
+// CreateImpersonationToken() options.
+//
+// GitLab API docs:
+// https://docs.gitlab.com/ce/api/users.html#create-an-impersonation-token
+type CreateImpersonationTokenOptions struct {
+ Name *string `url:"name,omitempty" json:"name,omitempty"`
+ Scopes *[]string `url:"scopes,omitempty" json:"scopes,omitempty"`
+ ExpiresAt *time.Time `url:"expires_at,omitempty" json:"expires_at,omitempty"`
+}
+
+// CreateImpersonationToken creates an impersonation token.
+//
+// GitLab API docs:
+// https://docs.gitlab.com/ce/api/users.html#create-an-impersonation-token
+func (s *UsersService) CreateImpersonationToken(user int, opt *CreateImpersonationTokenOptions, options ...OptionFunc) (*ImpersonationToken, *Response, error) {
+ u := fmt.Sprintf("users/%d/impersonation_tokens", user)
+
+ req, err := s.client.NewRequest("POST", u, opt, options)
+ if err != nil {
+ return nil, nil, err
+ }
+
+ t := new(ImpersonationToken)
+ resp, err := s.client.Do(req, &t)
+ if err != nil {
+ return nil, resp, err
+ }
+
+ return t, resp, err
+}
+
+// RevokeImpersonationToken revokes an impersonation token.
+//
+// GitLab API docs:
+// https://docs.gitlab.com/ce/api/users.html#revoke-an-impersonation-token
+func (s *UsersService) RevokeImpersonationToken(user, token int, options ...OptionFunc) (*Response, error) {
+ u := fmt.Sprintf("users/%d/impersonation_tokens/%d", user, token)
req, err := s.client.NewRequest("DELETE", u, nil, options)
if err != nil {