...

Source file src/github.com/xanzy/go-gitlab/runners.go

Documentation: github.com/xanzy/go-gitlab

     1  //
     2  // Copyright 2021, Sander van Harmelen
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  //
    16  
    17  package gitlab
    18  
    19  import (
    20  	"fmt"
    21  	"net/http"
    22  	"time"
    23  )
    24  
    25  // RunnersService handles communication with the runner related methods of the
    26  // GitLab API.
    27  //
    28  // GitLab API docs: https://docs.gitlab.com/ee/api/runners.html
    29  type RunnersService struct {
    30  	client *Client
    31  }
    32  
    33  // Runner represents a GitLab CI Runner.
    34  //
    35  // GitLab API docs: https://docs.gitlab.com/ee/api/runners.html
    36  type Runner struct {
    37  	ID             int        `json:"id"`
    38  	Description    string     `json:"description"`
    39  	Active         bool       `json:"active"`
    40  	Paused         bool       `json:"paused"`
    41  	IsShared       bool       `json:"is_shared"`
    42  	IPAddress      string     `json:"ip_address"`
    43  	RunnerType     string     `json:"runner_type"`
    44  	Name           string     `json:"name"`
    45  	Online         bool       `json:"online"`
    46  	Status         string     `json:"status"`
    47  	Token          string     `json:"token"`
    48  	TokenExpiresAt *time.Time `json:"token_expires_at"`
    49  }
    50  
    51  // RunnerDetails represents the GitLab CI runner details.
    52  //
    53  // GitLab API docs: https://docs.gitlab.com/ee/api/runners.html
    54  type RunnerDetails struct {
    55  	Paused       bool       `json:"paused"`
    56  	Architecture string     `json:"architecture"`
    57  	Description  string     `json:"description"`
    58  	ID           int        `json:"id"`
    59  	IPAddress    string     `json:"ip_address"`
    60  	IsShared     bool       `json:"is_shared"`
    61  	RunnerType   string     `json:"runner_type"`
    62  	ContactedAt  *time.Time `json:"contacted_at"`
    63  	Name         string     `json:"name"`
    64  	Online       bool       `json:"online"`
    65  	Status       string     `json:"status"`
    66  	Platform     string     `json:"platform"`
    67  	Projects     []struct {
    68  		ID                int    `json:"id"`
    69  		Name              string `json:"name"`
    70  		NameWithNamespace string `json:"name_with_namespace"`
    71  		Path              string `json:"path"`
    72  		PathWithNamespace string `json:"path_with_namespace"`
    73  	} `json:"projects"`
    74  	Token          string   `json:"token"`
    75  	Revision       string   `json:"revision"`
    76  	TagList        []string `json:"tag_list"`
    77  	RunUntagged    bool     `json:"run_untagged"`
    78  	Version        string   `json:"version"`
    79  	Locked         bool     `json:"locked"`
    80  	AccessLevel    string   `json:"access_level"`
    81  	MaximumTimeout int      `json:"maximum_timeout"`
    82  	Groups         []struct {
    83  		ID     int    `json:"id"`
    84  		Name   string `json:"name"`
    85  		WebURL string `json:"web_url"`
    86  	} `json:"groups"`
    87  
    88  	// Deprecated: Use Paused instead. (Deprecated in GitLab 14.8)
    89  	Active bool `json:"active"`
    90  }
    91  
    92  // ListRunnersOptions represents the available ListRunners() options.
    93  //
    94  // GitLab API docs:
    95  // https://docs.gitlab.com/ee/api/runners.html#list-owned-runners
    96  type ListRunnersOptions struct {
    97  	ListOptions
    98  	Type    *string   `url:"type,omitempty" json:"type,omitempty"`
    99  	Status  *string   `url:"status,omitempty" json:"status,omitempty"`
   100  	Paused  *bool     `url:"paused,omitempty" json:"paused,omitempty"`
   101  	TagList *[]string `url:"tag_list,comma,omitempty" json:"tag_list,omitempty"`
   102  
   103  	// Deprecated: Use Type or Status instead.
   104  	Scope *string `url:"scope,omitempty" json:"scope,omitempty"`
   105  }
   106  
   107  // ListRunners gets a list of runners accessible by the authenticated user.
   108  //
   109  // GitLab API docs:
   110  // https://docs.gitlab.com/ee/api/runners.html#list-owned-runners
   111  func (s *RunnersService) ListRunners(opt *ListRunnersOptions, options ...RequestOptionFunc) ([]*Runner, *Response, error) {
   112  	req, err := s.client.NewRequest(http.MethodGet, "runners", opt, options)
   113  	if err != nil {
   114  		return nil, nil, err
   115  	}
   116  
   117  	var rs []*Runner
   118  	resp, err := s.client.Do(req, &rs)
   119  	if err != nil {
   120  		return nil, resp, err
   121  	}
   122  
   123  	return rs, resp, nil
   124  }
   125  
   126  // ListAllRunners gets a list of all runners in the GitLab instance. Access is
   127  // restricted to users with admin privileges.
   128  //
   129  // GitLab API docs:
   130  // https://docs.gitlab.com/ee/api/runners.html#list-all-runners
   131  func (s *RunnersService) ListAllRunners(opt *ListRunnersOptions, options ...RequestOptionFunc) ([]*Runner, *Response, error) {
   132  	req, err := s.client.NewRequest(http.MethodGet, "runners/all", opt, options)
   133  	if err != nil {
   134  		return nil, nil, err
   135  	}
   136  
   137  	var rs []*Runner
   138  	resp, err := s.client.Do(req, &rs)
   139  	if err != nil {
   140  		return nil, resp, err
   141  	}
   142  
   143  	return rs, resp, nil
   144  }
   145  
   146  // GetRunnerDetails returns details for given runner.
   147  //
   148  // GitLab API docs:
   149  // https://docs.gitlab.com/ee/api/runners.html#get-runners-details
   150  func (s *RunnersService) GetRunnerDetails(rid interface{}, options ...RequestOptionFunc) (*RunnerDetails, *Response, error) {
   151  	runner, err := parseID(rid)
   152  	if err != nil {
   153  		return nil, nil, err
   154  	}
   155  	u := fmt.Sprintf("runners/%s", runner)
   156  
   157  	req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
   158  	if err != nil {
   159  		return nil, nil, err
   160  	}
   161  
   162  	rs := new(RunnerDetails)
   163  	resp, err := s.client.Do(req, &rs)
   164  	if err != nil {
   165  		return nil, resp, err
   166  	}
   167  
   168  	return rs, resp, nil
   169  }
   170  
   171  // UpdateRunnerDetailsOptions represents the available UpdateRunnerDetails() options.
   172  //
   173  // GitLab API docs:
   174  // https://docs.gitlab.com/ee/api/runners.html#update-runners-details
   175  type UpdateRunnerDetailsOptions struct {
   176  	Description    *string   `url:"description,omitempty" json:"description,omitempty"`
   177  	Paused         *bool     `url:"paused,omitempty" json:"paused,omitempty"`
   178  	TagList        *[]string `url:"tag_list[],omitempty" json:"tag_list,omitempty"`
   179  	RunUntagged    *bool     `url:"run_untagged,omitempty" json:"run_untagged,omitempty"`
   180  	Locked         *bool     `url:"locked,omitempty" json:"locked,omitempty"`
   181  	AccessLevel    *string   `url:"access_level,omitempty" json:"access_level,omitempty"`
   182  	MaximumTimeout *int      `url:"maximum_timeout,omitempty" json:"maximum_timeout,omitempty"`
   183  
   184  	// Deprecated: Use Paused instead. (Deprecated in GitLab 14.8)
   185  	Active *bool `url:"active,omitempty" json:"active,omitempty"`
   186  }
   187  
   188  // UpdateRunnerDetails updates details for a given runner.
   189  //
   190  // GitLab API docs:
   191  // https://docs.gitlab.com/ee/api/runners.html#update-runners-details
   192  func (s *RunnersService) UpdateRunnerDetails(rid interface{}, opt *UpdateRunnerDetailsOptions, options ...RequestOptionFunc) (*RunnerDetails, *Response, error) {
   193  	runner, err := parseID(rid)
   194  	if err != nil {
   195  		return nil, nil, err
   196  	}
   197  	u := fmt.Sprintf("runners/%s", runner)
   198  
   199  	req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
   200  	if err != nil {
   201  		return nil, nil, err
   202  	}
   203  
   204  	rs := new(RunnerDetails)
   205  	resp, err := s.client.Do(req, &rs)
   206  	if err != nil {
   207  		return nil, resp, err
   208  	}
   209  
   210  	return rs, resp, nil
   211  }
   212  
   213  // RemoveRunner removes a runner.
   214  //
   215  // GitLab API docs:
   216  // https://docs.gitlab.com/ee/api/runners.html#delete-a-runner
   217  func (s *RunnersService) RemoveRunner(rid interface{}, options ...RequestOptionFunc) (*Response, error) {
   218  	runner, err := parseID(rid)
   219  	if err != nil {
   220  		return nil, err
   221  	}
   222  	u := fmt.Sprintf("runners/%s", runner)
   223  
   224  	req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
   225  	if err != nil {
   226  		return nil, err
   227  	}
   228  
   229  	return s.client.Do(req, nil)
   230  }
   231  
   232  // ListRunnerJobsOptions represents the available ListRunnerJobs()
   233  // options. Status can be one of: running, success, failed, canceled.
   234  //
   235  // GitLab API docs:
   236  // https://docs.gitlab.com/ee/api/runners.html#list-runners-jobs
   237  type ListRunnerJobsOptions struct {
   238  	ListOptions
   239  	Status  *string `url:"status,omitempty" json:"status,omitempty"`
   240  	OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
   241  	Sort    *string `url:"sort,omitempty" json:"sort,omitempty"`
   242  }
   243  
   244  // ListRunnerJobs gets a list of jobs that are being processed or were processed by specified Runner.
   245  //
   246  // GitLab API docs:
   247  // https://docs.gitlab.com/ee/api/runners.html#list-runners-jobs
   248  func (s *RunnersService) ListRunnerJobs(rid interface{}, opt *ListRunnerJobsOptions, options ...RequestOptionFunc) ([]*Job, *Response, error) {
   249  	runner, err := parseID(rid)
   250  	if err != nil {
   251  		return nil, nil, err
   252  	}
   253  	u := fmt.Sprintf("runners/%s/jobs", runner)
   254  
   255  	req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
   256  	if err != nil {
   257  		return nil, nil, err
   258  	}
   259  
   260  	var rs []*Job
   261  	resp, err := s.client.Do(req, &rs)
   262  	if err != nil {
   263  		return nil, resp, err
   264  	}
   265  
   266  	return rs, resp, nil
   267  }
   268  
   269  // ListProjectRunnersOptions represents the available ListProjectRunners()
   270  // options.
   271  //
   272  // GitLab API docs:
   273  // https://docs.gitlab.com/ee/api/runners.html#list-projects-runners
   274  type ListProjectRunnersOptions ListRunnersOptions
   275  
   276  // ListProjectRunners gets a list of runners accessible by the authenticated user.
   277  //
   278  // GitLab API docs:
   279  // https://docs.gitlab.com/ee/api/runners.html#list-projects-runners
   280  func (s *RunnersService) ListProjectRunners(pid interface{}, opt *ListProjectRunnersOptions, options ...RequestOptionFunc) ([]*Runner, *Response, error) {
   281  	project, err := parseID(pid)
   282  	if err != nil {
   283  		return nil, nil, err
   284  	}
   285  	u := fmt.Sprintf("projects/%s/runners", PathEscape(project))
   286  
   287  	req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
   288  	if err != nil {
   289  		return nil, nil, err
   290  	}
   291  
   292  	var rs []*Runner
   293  	resp, err := s.client.Do(req, &rs)
   294  	if err != nil {
   295  		return nil, resp, err
   296  	}
   297  
   298  	return rs, resp, nil
   299  }
   300  
   301  // EnableProjectRunnerOptions represents the available EnableProjectRunner()
   302  // options.
   303  //
   304  // GitLab API docs:
   305  // https://docs.gitlab.com/ee/api/runners.html#enable-a-runner-in-project
   306  type EnableProjectRunnerOptions struct {
   307  	RunnerID int `json:"runner_id"`
   308  }
   309  
   310  // EnableProjectRunner enables an available specific runner in the project.
   311  //
   312  // GitLab API docs:
   313  // https://docs.gitlab.com/ee/api/runners.html#enable-a-runner-in-project
   314  func (s *RunnersService) EnableProjectRunner(pid interface{}, opt *EnableProjectRunnerOptions, options ...RequestOptionFunc) (*Runner, *Response, error) {
   315  	project, err := parseID(pid)
   316  	if err != nil {
   317  		return nil, nil, err
   318  	}
   319  	u := fmt.Sprintf("projects/%s/runners", PathEscape(project))
   320  
   321  	req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
   322  	if err != nil {
   323  		return nil, nil, err
   324  	}
   325  
   326  	r := new(Runner)
   327  	resp, err := s.client.Do(req, &r)
   328  	if err != nil {
   329  		return nil, resp, err
   330  	}
   331  
   332  	return r, resp, nil
   333  }
   334  
   335  // DisableProjectRunner disables a specific runner from project.
   336  //
   337  // GitLab API docs:
   338  // https://docs.gitlab.com/ee/api/runners.html#disable-a-runner-from-project
   339  func (s *RunnersService) DisableProjectRunner(pid interface{}, runner int, options ...RequestOptionFunc) (*Response, error) {
   340  	project, err := parseID(pid)
   341  	if err != nil {
   342  		return nil, err
   343  	}
   344  	u := fmt.Sprintf("projects/%s/runners/%d", PathEscape(project), runner)
   345  
   346  	req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
   347  	if err != nil {
   348  		return nil, err
   349  	}
   350  
   351  	return s.client.Do(req, nil)
   352  }
   353  
   354  // ListGroupsRunnersOptions represents the available ListGroupsRunners() options.
   355  //
   356  // GitLab API docs:
   357  // https://docs.gitlab.com/ee/api/runners.html#list-groups-runners
   358  type ListGroupsRunnersOptions struct {
   359  	ListOptions
   360  	Type    *string   `url:"type,omitempty" json:"type,omitempty"`
   361  	Status  *string   `url:"status,omitempty" json:"status,omitempty"`
   362  	TagList *[]string `url:"tag_list,comma,omitempty" json:"tag_list,omitempty"`
   363  }
   364  
   365  // ListGroupsRunners lists all runners (specific and shared) available in the
   366  // group as well it’s ancestor groups. Shared runners are listed if at least one
   367  // shared runner is defined.
   368  //
   369  // GitLab API docs:
   370  // https://docs.gitlab.com/ee/api/runners.html#list-groups-runners
   371  func (s *RunnersService) ListGroupsRunners(gid interface{}, opt *ListGroupsRunnersOptions, options ...RequestOptionFunc) ([]*Runner, *Response, error) {
   372  	group, err := parseID(gid)
   373  	if err != nil {
   374  		return nil, nil, err
   375  	}
   376  	u := fmt.Sprintf("groups/%s/runners", PathEscape(group))
   377  
   378  	req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
   379  	if err != nil {
   380  		return nil, nil, err
   381  	}
   382  
   383  	var rs []*Runner
   384  	resp, err := s.client.Do(req, &rs)
   385  	if err != nil {
   386  		return nil, resp, err
   387  	}
   388  
   389  	return rs, resp, nil
   390  }
   391  
   392  // RegisterNewRunnerOptions represents the available RegisterNewRunner()
   393  // options.
   394  //
   395  // GitLab API docs:
   396  // https://docs.gitlab.com/ee/api/runners.html#register-a-new-runner
   397  type RegisterNewRunnerOptions struct {
   398  	Token           *string                       `url:"token" json:"token"`
   399  	Description     *string                       `url:"description,omitempty" json:"description,omitempty"`
   400  	Info            *RegisterNewRunnerInfoOptions `url:"info,omitempty" json:"info,omitempty"`
   401  	Active          *bool                         `url:"active,omitempty" json:"active,omitempty"`
   402  	Paused          *bool                         `url:"paused,omitempty" json:"paused,omitempty"`
   403  	Locked          *bool                         `url:"locked,omitempty" json:"locked,omitempty"`
   404  	RunUntagged     *bool                         `url:"run_untagged,omitempty" json:"run_untagged,omitempty"`
   405  	TagList         *[]string                     `url:"tag_list[],omitempty" json:"tag_list,omitempty"`
   406  	AccessLevel     *string                       `url:"access_level,omitempty" json:"access_level,omitempty"`
   407  	MaximumTimeout  *int                          `url:"maximum_timeout,omitempty" json:"maximum_timeout,omitempty"`
   408  	MaintenanceNote *string                       `url:"maintenance_note,omitempty" json:"maintenance_note,omitempty"`
   409  }
   410  
   411  // RegisterNewRunnerInfoOptions represents the info hashmap parameter in
   412  // RegisterNewRunnerOptions.
   413  //
   414  // GitLab API docs:
   415  // https://docs.gitlab.com/ee/api/runners.html#register-a-new-runner
   416  type RegisterNewRunnerInfoOptions struct {
   417  	Name         *string `url:"name,omitempty" json:"name,omitempty"`
   418  	Version      *string `url:"version,omitempty" json:"version,omitempty"`
   419  	Revision     *string `url:"revision,omitempty" json:"revision,omitempty"`
   420  	Platform     *string `url:"platform,omitempty" json:"platform,omitempty"`
   421  	Architecture *string `url:"architecture,omitempty" json:"architecture,omitempty"`
   422  }
   423  
   424  // RegisterNewRunner registers a new Runner for the instance.
   425  //
   426  // GitLab API docs:
   427  // https://docs.gitlab.com/ee/api/runners.html#register-a-new-runner
   428  func (s *RunnersService) RegisterNewRunner(opt *RegisterNewRunnerOptions, options ...RequestOptionFunc) (*Runner, *Response, error) {
   429  	req, err := s.client.NewRequest(http.MethodPost, "runners", opt, options)
   430  	if err != nil {
   431  		return nil, nil, err
   432  	}
   433  
   434  	r := new(Runner)
   435  	resp, err := s.client.Do(req, &r)
   436  	if err != nil {
   437  		return nil, resp, err
   438  	}
   439  
   440  	return r, resp, nil
   441  }
   442  
   443  // DeleteRegisteredRunnerOptions represents the available
   444  // DeleteRegisteredRunner() options.
   445  //
   446  // GitLab API docs:
   447  // https://docs.gitlab.com/ee/api/runners.html#delete-a-runner-by-authentication-token
   448  type DeleteRegisteredRunnerOptions struct {
   449  	Token *string `url:"token" json:"token"`
   450  }
   451  
   452  // DeleteRegisteredRunner deletes a Runner by Token.
   453  //
   454  // GitLab API docs:
   455  // https://docs.gitlab.com/ee/api/runners.html#delete-a-runner-by-authentication-token
   456  func (s *RunnersService) DeleteRegisteredRunner(opt *DeleteRegisteredRunnerOptions, options ...RequestOptionFunc) (*Response, error) {
   457  	req, err := s.client.NewRequest(http.MethodDelete, "runners", opt, options)
   458  	if err != nil {
   459  		return nil, err
   460  	}
   461  
   462  	return s.client.Do(req, nil)
   463  }
   464  
   465  // DeleteRegisteredRunnerByID deletes a runner by ID.
   466  //
   467  // GitLab API docs:
   468  // https://docs.gitlab.com/ee/api/runners.html#delete-a-runner-by-id
   469  func (s *RunnersService) DeleteRegisteredRunnerByID(rid int, options ...RequestOptionFunc) (*Response, error) {
   470  	req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("runners/%d", rid), nil, options)
   471  	if err != nil {
   472  		return nil, err
   473  	}
   474  
   475  	return s.client.Do(req, nil)
   476  }
   477  
   478  // VerifyRegisteredRunnerOptions represents the available
   479  // VerifyRegisteredRunner() options.
   480  //
   481  // GitLab API docs:
   482  // https://docs.gitlab.com/ee/api/runners.html#verify-authentication-for-a-registered-runner
   483  type VerifyRegisteredRunnerOptions struct {
   484  	Token *string `url:"token" json:"token"`
   485  }
   486  
   487  // VerifyRegisteredRunner registers a new runner for the instance.
   488  //
   489  // GitLab API docs:
   490  // https://docs.gitlab.com/ee/api/runners.html#verify-authentication-for-a-registered-runner
   491  func (s *RunnersService) VerifyRegisteredRunner(opt *VerifyRegisteredRunnerOptions, options ...RequestOptionFunc) (*Response, error) {
   492  	req, err := s.client.NewRequest(http.MethodPost, "runners/verify", opt, options)
   493  	if err != nil {
   494  		return nil, err
   495  	}
   496  
   497  	return s.client.Do(req, nil)
   498  }
   499  
   500  type RunnerRegistrationToken struct {
   501  	Token          *string    `url:"token" json:"token"`
   502  	TokenExpiresAt *time.Time `url:"token_expires_at" json:"token_expires_at"`
   503  }
   504  
   505  // ResetInstanceRunnerRegistrationToken resets the instance runner registration
   506  // token.
   507  //
   508  // GitLab API docs:
   509  // https://docs.gitlab.com/ee/api/runners.html#reset-instances-runner-registration-token
   510  func (s *RunnersService) ResetInstanceRunnerRegistrationToken(options ...RequestOptionFunc) (*RunnerRegistrationToken, *Response, error) {
   511  	req, err := s.client.NewRequest(http.MethodPost, "runners/reset_registration_token", nil, options)
   512  	if err != nil {
   513  		return nil, nil, err
   514  	}
   515  
   516  	r := new(RunnerRegistrationToken)
   517  	resp, err := s.client.Do(req, &r)
   518  	if err != nil {
   519  		return nil, resp, err
   520  	}
   521  
   522  	return r, resp, nil
   523  }
   524  
   525  // ResetGroupRunnerRegistrationToken resets a group's runner registration token.
   526  //
   527  // GitLab API docs:
   528  // https://docs.gitlab.com/ee/api/runners.html#reset-groups-runner-registration-token
   529  func (s *RunnersService) ResetGroupRunnerRegistrationToken(gid interface{}, options ...RequestOptionFunc) (*RunnerRegistrationToken, *Response, error) {
   530  	group, err := parseID(gid)
   531  	if err != nil {
   532  		return nil, nil, err
   533  	}
   534  	u := fmt.Sprintf("groups/%s/runners/reset_registration_token", PathEscape(group))
   535  
   536  	req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
   537  	if err != nil {
   538  		return nil, nil, err
   539  	}
   540  
   541  	r := new(RunnerRegistrationToken)
   542  	resp, err := s.client.Do(req, &r)
   543  	if err != nil {
   544  		return nil, resp, err
   545  	}
   546  
   547  	return r, resp, nil
   548  }
   549  
   550  // ResetGroupRunnerRegistrationToken resets a projects's runner registration token.
   551  //
   552  // GitLab API docs:
   553  // https://docs.gitlab.com/ee/api/runners.html#reset-projects-runner-registration-token
   554  func (s *RunnersService) ResetProjectRunnerRegistrationToken(pid interface{}, options ...RequestOptionFunc) (*RunnerRegistrationToken, *Response, error) {
   555  	project, err := parseID(pid)
   556  	if err != nil {
   557  		return nil, nil, err
   558  	}
   559  	u := fmt.Sprintf("projects/%s/runners/reset_registration_token", PathEscape(project))
   560  	req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
   561  	if err != nil {
   562  		return nil, nil, err
   563  	}
   564  
   565  	r := new(RunnerRegistrationToken)
   566  	resp, err := s.client.Do(req, &r)
   567  	if err != nil {
   568  		return nil, resp, err
   569  	}
   570  
   571  	return r, resp, nil
   572  }
   573  
   574  type RunnerAuthenticationToken struct {
   575  	Token          *string    `url:"token" json:"token"`
   576  	TokenExpiresAt *time.Time `url:"token_expires_at" json:"token_expires_at"`
   577  }
   578  
   579  // ResetRunnerAuthenticationToken resets a runner's authentication token.
   580  //
   581  // GitLab API docs:
   582  // https://docs.gitlab.com/ee/api/runners.html#reset-runners-authentication-token-by-using-the-runner-id
   583  func (s *RunnersService) ResetRunnerAuthenticationToken(rid int, options ...RequestOptionFunc) (*RunnerAuthenticationToken, *Response, error) {
   584  	u := fmt.Sprintf("runners/%d/reset_authentication_token", rid)
   585  	req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
   586  	if err != nil {
   587  		return nil, nil, err
   588  	}
   589  
   590  	r := new(RunnerAuthenticationToken)
   591  	resp, err := s.client.Do(req, &r)
   592  	if err != nil {
   593  		return nil, resp, err
   594  	}
   595  
   596  	return r, resp, nil
   597  }
   598  

View as plain text