Loading runner_controller_tokens.go +37 −25 Original line number Diff line number Diff line Loading @@ -10,32 +10,34 @@ type ( // controller token related methods of the GitLab API. This is an admin-only // endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // Note: This API is experimental and may change or be removed in future versions. // // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/ RunnerControllerTokensServiceInterface interface { // ListRunnerControllerTokens gets a list of runner controller tokens. This is // an admin-only endpoint. // ListRunnerControllerTokens lists all runner controller tokens. This is an // admin-only endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/#list-all-runner-controller-tokens ListRunnerControllerTokens(rid int64, opt *ListRunnerControllerTokensOptions, options ...RequestOptionFunc) ([]*RunnerControllerToken, *Response, error) // GetRunnerControllerToken gets a single runner controller token. This is an // admin-only endpoint. // GetRunnerControllerToken retrieves a single runner controller token. This // is an admin-only endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/#retrieve-a-single-runner-controller-token GetRunnerControllerToken(rid int64, tokenID int64, options ...RequestOptionFunc) (*RunnerControllerToken, *Response, error) // CreateRunnerControllerToken creates a new runner controller token. This is // an admin-only endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/#create-a-runner-controller-token CreateRunnerControllerToken(rid int64, opt *CreateRunnerControllerTokenOptions, options ...RequestOptionFunc) (*RunnerControllerToken, *Response, error) // RotateRunnerControllerToken rotates an existing runner controller token. // This is an admin-only endpoint. // // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/#rotate-a-runner-controller-token RotateRunnerControllerToken(rid int64, tokenID int64, options ...RequestOptionFunc) (*RunnerControllerToken, *Response, error) // RevokeRunnerControllerToken revokes a runner controller token. This is an // admin-only endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/#revoke-a-runner-controller-token RevokeRunnerControllerToken(rid int64, tokenID int64, options ...RequestOptionFunc) (*Response, error) } Loading @@ -43,8 +45,9 @@ type ( // controller token related methods of the GitLab API. This is an admin-only // endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // Note: This API is experimental and may change or be removed in future versions. // // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/ RunnerControllerTokensService struct { client *Client } Loading @@ -53,8 +56,11 @@ type ( var _ RunnerControllerTokensServiceInterface = (*RunnerControllerTokensService)(nil) // RunnerControllerToken represents a GitLab runner controller token. // // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/ type RunnerControllerToken struct { ID int64 `json:"id"` RunnerControllerID int64 `json:"runner_controller_id"` Description string `json:"description"` Token string `json:"token,omitempty"` CreatedAt *time.Time `json:"created_at"` Loading @@ -64,8 +70,7 @@ type RunnerControllerToken struct { // ListRunnerControllerTokensOptions represents the available // ListRunnerControllerTokens() options. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/#list-all-runner-controller-tokens type ListRunnerControllerTokensOptions struct { ListOptions } Loading @@ -88,8 +93,7 @@ func (s *RunnerControllerTokensService) GetRunnerControllerToken(rid int64, toke // CreateRunnerControllerTokenOptions represents the available // CreateRunnerControllerToken() options. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/#create-a-runner-controller-token type CreateRunnerControllerTokenOptions struct { Description *string `url:"description,omitempty" json:"description,omitempty"` } Loading @@ -103,6 +107,14 @@ func (s *RunnerControllerTokensService) CreateRunnerControllerToken(rid int64, o ) } func (s *RunnerControllerTokensService) RotateRunnerControllerToken(rid int64, tokenID int64, options ...RequestOptionFunc) (*RunnerControllerToken, *Response, error) { return do[*RunnerControllerToken](s.client, withMethod(http.MethodPost), withPath("runner_controllers/%d/tokens/%d/rotate", rid, tokenID), withRequestOpts(options...), ) } func (s *RunnerControllerTokensService) RevokeRunnerControllerToken(rid int64, tokenID int64, options ...RequestOptionFunc) (*Response, error) { _, resp, err := do[none](s.client, withMethod(http.MethodDelete), Loading runner_controller_tokens_test.go +33 −0 Original line number Diff line number Diff line Loading @@ -111,6 +111,39 @@ func TestCreateRunnerControllerToken(t *testing.T) { assert.Equal(t, want, token) } func TestRotateRunnerControllerToken(t *testing.T) { t.Parallel() mux, client := setup(t) // GIVEN a runner controller token exists mux.HandleFunc("/api/v4/runner_controllers/1/tokens/1/rotate", func(w http.ResponseWriter, r *http.Request) { // WHEN the rotate endpoint is called with POST testMethod(t, r, http.MethodPost) fmt.Fprint(w, `{ "id": 1, "runner_controller_id": 1, "description": "Rotated Token", "token": "glrct-rotated123", "created_at": "2020-02-14T00:00:00.000Z", "updated_at": "2020-05-20T00:00:00.000Z" }`) }) token, _, err := client.RunnerControllerTokens.RotateRunnerControllerToken(1, 1) assert.NoError(t, err) // THEN the rotated token is returned with a new token value want := &RunnerControllerToken{ ID: 1, RunnerControllerID: 1, Description: "Rotated Token", Token: "glrct-rotated123", CreatedAt: Ptr(time.Date(2020, time.February, 14, 0, 0, 0, 0, time.UTC)), UpdatedAt: Ptr(time.Date(2020, time.May, 20, 0, 0, 0, 0, time.UTC)), } assert.Equal(t, want, token) } func TestRevokeRunnerControllerToken(t *testing.T) { t.Parallel() mux, client := setup(t) Loading runner_controllers.go +40 −32 Original line number Diff line number Diff line Loading @@ -9,46 +9,43 @@ type ( // RunnerControllersServiceInterface handles communication with the runner // controller related methods of the GitLab API. This is an admin-only endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // Note: This API is experimental and may change or be removed in future versions. // // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/ RunnerControllersServiceInterface interface { // ListRunnerControllers gets a list of runner controllers. This is an // admin-only endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/#list-all-runner-controllers ListRunnerControllers(opt *ListRunnerControllersOptions, options ...RequestOptionFunc) ([]*RunnerController, *Response, error) // GetRunnerController gets a single runner controller. This is an admin-only // endpoint. // GetRunnerController retrieves a single runner controller. This is an // admin-only endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/#retrieve-a-single-runner-controller GetRunnerController(rid int64, options ...RequestOptionFunc) (*RunnerController, *Response, error) // CreateRunnerController creates a new runner controller. This is an // CreateRunnerController registers a new runner controller. This is an // admin-only endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/#register-a-runner-controller CreateRunnerController(opt *CreateRunnerControllerOptions, options ...RequestOptionFunc) (*RunnerController, *Response, error) // UpdateRunnerController updates a runner controller. This is an admin-only // endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/#update-a-runner-controller UpdateRunnerController(rid int64, opt *UpdateRunnerControllerOptions, options ...RequestOptionFunc) (*RunnerController, *Response, error) // DeleteRunnerController deletes a runner controller. This is an admin-only // endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/#delete-a-runner-controller DeleteRunnerController(rid int64, options ...RequestOptionFunc) (*Response, error) } // RunnerControllersService handles communication with the runner controller // related methods of the GitLab API. This is an admin-only endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // Note: This API is experimental and may change or be removed in future versions. // // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/ RunnerControllersService struct { client *Client } Loading @@ -56,11 +53,25 @@ type ( var _ RunnerControllersServiceInterface = (*RunnerControllersService)(nil) // RunnerControllerStateValue represents the state of a runner controller. // // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/ type RunnerControllerStateValue string // These constants represent all valid runner controller states. const ( RunnerControllerStateDisabled RunnerControllerStateValue = "disabled" RunnerControllerStateEnabled RunnerControllerStateValue = "enabled" RunnerControllerStateDryRun RunnerControllerStateValue = "dry_run" ) // RunnerController represents a GitLab runner controller. // // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/ type RunnerController struct { ID int64 `json:"id"` Description string `json:"description"` Enabled bool `json:"enabled"` State RunnerControllerStateValue `json:"state"` CreatedAt *time.Time `json:"created_at"` UpdatedAt *time.Time `json:"updated_at"` } Loading @@ -68,8 +79,7 @@ type RunnerController struct { // ListRunnerControllersOptions represents the available // ListRunnerControllers() options. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/#list-all-runner-controllers type ListRunnerControllersOptions struct { ListOptions } Loading @@ -92,11 +102,10 @@ func (s *RunnerControllersService) GetRunnerController(rid int64, options ...Req // CreateRunnerControllerOptions represents the available // CreateRunnerController() options. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/#register-a-runner-controller type CreateRunnerControllerOptions struct { Description *string `url:"description,omitempty" json:"description,omitempty"` Enabled *bool `url:"enabled,omitempty" json:"enabled,omitempty"` State *RunnerControllerStateValue `url:"state,omitempty" json:"state,omitempty"` } func (s *RunnerControllersService) CreateRunnerController(opt *CreateRunnerControllerOptions, options ...RequestOptionFunc) (*RunnerController, *Response, error) { Loading @@ -111,11 +120,10 @@ func (s *RunnerControllersService) CreateRunnerController(opt *CreateRunnerContr // UpdateRunnerControllerOptions represents the available // UpdateRunnerController() options. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/#update-a-runner-controller type UpdateRunnerControllerOptions struct { Description *string `url:"description,omitempty" json:"description,omitempty"` Enabled *bool `url:"enabled,omitempty" json:"enabled,omitempty"` State *RunnerControllerStateValue `url:"state,omitempty" json:"state,omitempty"` } func (s *RunnerControllersService) UpdateRunnerController(rid int64, opt *UpdateRunnerControllerOptions, options ...RequestOptionFunc) (*RunnerController, *Response, error) { Loading runner_controllers_test.go +14 −14 Original line number Diff line number Diff line Loading @@ -19,14 +19,14 @@ func TestListRunnerControllers(t *testing.T) { { "id": 1, "description": "Controller 1", "enabled": true, "state": "enabled", "created_at": "2020-02-14T00:00:00.000Z", "updated_at": "2020-02-15T00:00:00.000Z" }, { "id": 2, "description": "Controller 2", "enabled": false, "state": "disabled", "created_at": "2020-03-14T00:00:00.000Z", "updated_at": "2020-03-15T00:00:00.000Z" } Loading @@ -40,14 +40,14 @@ func TestListRunnerControllers(t *testing.T) { { ID: 1, Description: "Controller 1", Enabled: true, State: RunnerControllerStateEnabled, CreatedAt: Ptr(time.Date(2020, time.February, 14, 0, 0, 0, 0, time.UTC)), UpdatedAt: Ptr(time.Date(2020, time.February, 15, 0, 0, 0, 0, time.UTC)), }, { ID: 2, Description: "Controller 2", Enabled: false, State: RunnerControllerStateDisabled, CreatedAt: Ptr(time.Date(2020, time.March, 14, 0, 0, 0, 0, time.UTC)), UpdatedAt: Ptr(time.Date(2020, time.March, 15, 0, 0, 0, 0, time.UTC)), }, Loading @@ -64,7 +64,7 @@ func TestGetRunnerController(t *testing.T) { fmt.Fprint(w, `{ "id": 1, "description": "Test Controller", "enabled": true, "state": "enabled", "created_at": "2020-02-14T00:00:00.000Z", "updated_at": "2020-02-15T00:00:00.000Z" }`) Loading @@ -76,7 +76,7 @@ func TestGetRunnerController(t *testing.T) { want := &RunnerController{ ID: 1, Description: "Test Controller", Enabled: true, State: RunnerControllerStateEnabled, CreatedAt: Ptr(time.Date(2020, time.February, 14, 0, 0, 0, 0, time.UTC)), UpdatedAt: Ptr(time.Date(2020, time.February, 15, 0, 0, 0, 0, time.UTC)), } Loading @@ -91,12 +91,12 @@ func TestCreateRunnerController(t *testing.T) { testMethod(t, r, http.MethodPost) testBodyJSON(t, r, map[string]any{ "description": "New Controller", "enabled": true, "state": "dry_run", }) fmt.Fprint(w, `{ "id": 3, "description": "New Controller", "enabled": true, "state": "dry_run", "created_at": "2020-04-14T00:00:00.000Z", "updated_at": "2020-04-14T00:00:00.000Z" }`) Loading @@ -104,7 +104,7 @@ func TestCreateRunnerController(t *testing.T) { opt := &CreateRunnerControllerOptions{ Description: Ptr("New Controller"), Enabled: Ptr(true), State: Ptr(RunnerControllerStateDryRun), } controller, _, err := client.RunnerControllers.CreateRunnerController(opt) assert.NoError(t, err) Loading @@ -112,7 +112,7 @@ func TestCreateRunnerController(t *testing.T) { want := &RunnerController{ ID: 3, Description: "New Controller", Enabled: true, State: RunnerControllerStateDryRun, CreatedAt: Ptr(time.Date(2020, time.April, 14, 0, 0, 0, 0, time.UTC)), UpdatedAt: Ptr(time.Date(2020, time.April, 14, 0, 0, 0, 0, time.UTC)), } Loading @@ -127,12 +127,12 @@ func TestUpdateRunnerController(t *testing.T) { testMethod(t, r, http.MethodPut) testBodyJSON(t, r, map[string]any{ "description": "Updated Controller", "enabled": false, "state": "disabled", }) fmt.Fprint(w, `{ "id": 1, "description": "Updated Controller", "enabled": false, "state": "disabled", "created_at": "2020-02-14T00:00:00.000Z", "updated_at": "2020-05-15T00:00:00.000Z" }`) Loading @@ -140,7 +140,7 @@ func TestUpdateRunnerController(t *testing.T) { opt := &UpdateRunnerControllerOptions{ Description: Ptr("Updated Controller"), Enabled: Ptr(false), State: Ptr(RunnerControllerStateDisabled), } controller, _, err := client.RunnerControllers.UpdateRunnerController(1, opt) assert.NoError(t, err) Loading @@ -148,7 +148,7 @@ func TestUpdateRunnerController(t *testing.T) { want := &RunnerController{ ID: 1, Description: "Updated Controller", Enabled: false, State: RunnerControllerStateDisabled, CreatedAt: Ptr(time.Date(2020, time.February, 14, 0, 0, 0, 0, time.UTC)), UpdatedAt: Ptr(time.Date(2020, time.May, 15, 0, 0, 0, 0, time.UTC)), } Loading testing/runner_controller_tokens_mock.go +45 −0 Original line number Diff line number Diff line Loading @@ -217,3 +217,48 @@ func (c *MockRunnerControllerTokensServiceInterfaceRevokeRunnerControllerTokenCa c.Call = c.Call.DoAndReturn(f) return c } // RotateRunnerControllerToken mocks base method. func (m *MockRunnerControllerTokensServiceInterface) RotateRunnerControllerToken(rid, tokenID int64, options ...gitlab.RequestOptionFunc) (*gitlab.RunnerControllerToken, *gitlab.Response, error) { m.ctrl.T.Helper() varargs := []any{rid, tokenID} for _, a := range options { varargs = append(varargs, a) } ret := m.ctrl.Call(m, "RotateRunnerControllerToken", varargs...) ret0, _ := ret[0].(*gitlab.RunnerControllerToken) ret1, _ := ret[1].(*gitlab.Response) ret2, _ := ret[2].(error) return ret0, ret1, ret2 } // RotateRunnerControllerToken indicates an expected call of RotateRunnerControllerToken. func (mr *MockRunnerControllerTokensServiceInterfaceMockRecorder) RotateRunnerControllerToken(rid, tokenID any, options ...any) *MockRunnerControllerTokensServiceInterfaceRotateRunnerControllerTokenCall { mr.mock.ctrl.T.Helper() varargs := append([]any{rid, tokenID}, options...) call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RotateRunnerControllerToken", reflect.TypeOf((*MockRunnerControllerTokensServiceInterface)(nil).RotateRunnerControllerToken), varargs...) return &MockRunnerControllerTokensServiceInterfaceRotateRunnerControllerTokenCall{Call: call} } // MockRunnerControllerTokensServiceInterfaceRotateRunnerControllerTokenCall wrap *gomock.Call type MockRunnerControllerTokensServiceInterfaceRotateRunnerControllerTokenCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return func (c *MockRunnerControllerTokensServiceInterfaceRotateRunnerControllerTokenCall) Return(arg0 *gitlab.RunnerControllerToken, arg1 *gitlab.Response, arg2 error) *MockRunnerControllerTokensServiceInterfaceRotateRunnerControllerTokenCall { c.Call = c.Call.Return(arg0, arg1, arg2) return c } // Do rewrite *gomock.Call.Do func (c *MockRunnerControllerTokensServiceInterfaceRotateRunnerControllerTokenCall) Do(f func(int64, int64, ...gitlab.RequestOptionFunc) (*gitlab.RunnerControllerToken, *gitlab.Response, error)) *MockRunnerControllerTokensServiceInterfaceRotateRunnerControllerTokenCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn func (c *MockRunnerControllerTokensServiceInterfaceRotateRunnerControllerTokenCall) DoAndReturn(f func(int64, int64, ...gitlab.RequestOptionFunc) (*gitlab.RunnerControllerToken, *gitlab.Response, error)) *MockRunnerControllerTokensServiceInterfaceRotateRunnerControllerTokenCall { c.Call = c.Call.DoAndReturn(f) return c } Loading
runner_controller_tokens.go +37 −25 Original line number Diff line number Diff line Loading @@ -10,32 +10,34 @@ type ( // controller token related methods of the GitLab API. This is an admin-only // endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // Note: This API is experimental and may change or be removed in future versions. // // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/ RunnerControllerTokensServiceInterface interface { // ListRunnerControllerTokens gets a list of runner controller tokens. This is // an admin-only endpoint. // ListRunnerControllerTokens lists all runner controller tokens. This is an // admin-only endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/#list-all-runner-controller-tokens ListRunnerControllerTokens(rid int64, opt *ListRunnerControllerTokensOptions, options ...RequestOptionFunc) ([]*RunnerControllerToken, *Response, error) // GetRunnerControllerToken gets a single runner controller token. This is an // admin-only endpoint. // GetRunnerControllerToken retrieves a single runner controller token. This // is an admin-only endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/#retrieve-a-single-runner-controller-token GetRunnerControllerToken(rid int64, tokenID int64, options ...RequestOptionFunc) (*RunnerControllerToken, *Response, error) // CreateRunnerControllerToken creates a new runner controller token. This is // an admin-only endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/#create-a-runner-controller-token CreateRunnerControllerToken(rid int64, opt *CreateRunnerControllerTokenOptions, options ...RequestOptionFunc) (*RunnerControllerToken, *Response, error) // RotateRunnerControllerToken rotates an existing runner controller token. // This is an admin-only endpoint. // // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/#rotate-a-runner-controller-token RotateRunnerControllerToken(rid int64, tokenID int64, options ...RequestOptionFunc) (*RunnerControllerToken, *Response, error) // RevokeRunnerControllerToken revokes a runner controller token. This is an // admin-only endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/#revoke-a-runner-controller-token RevokeRunnerControllerToken(rid int64, tokenID int64, options ...RequestOptionFunc) (*Response, error) } Loading @@ -43,8 +45,9 @@ type ( // controller token related methods of the GitLab API. This is an admin-only // endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // Note: This API is experimental and may change or be removed in future versions. // // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/ RunnerControllerTokensService struct { client *Client } Loading @@ -53,8 +56,11 @@ type ( var _ RunnerControllerTokensServiceInterface = (*RunnerControllerTokensService)(nil) // RunnerControllerToken represents a GitLab runner controller token. // // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/ type RunnerControllerToken struct { ID int64 `json:"id"` RunnerControllerID int64 `json:"runner_controller_id"` Description string `json:"description"` Token string `json:"token,omitempty"` CreatedAt *time.Time `json:"created_at"` Loading @@ -64,8 +70,7 @@ type RunnerControllerToken struct { // ListRunnerControllerTokensOptions represents the available // ListRunnerControllerTokens() options. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/#list-all-runner-controller-tokens type ListRunnerControllerTokensOptions struct { ListOptions } Loading @@ -88,8 +93,7 @@ func (s *RunnerControllerTokensService) GetRunnerControllerToken(rid int64, toke // CreateRunnerControllerTokenOptions represents the available // CreateRunnerControllerToken() options. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controller_tokens/#create-a-runner-controller-token type CreateRunnerControllerTokenOptions struct { Description *string `url:"description,omitempty" json:"description,omitempty"` } Loading @@ -103,6 +107,14 @@ func (s *RunnerControllerTokensService) CreateRunnerControllerToken(rid int64, o ) } func (s *RunnerControllerTokensService) RotateRunnerControllerToken(rid int64, tokenID int64, options ...RequestOptionFunc) (*RunnerControllerToken, *Response, error) { return do[*RunnerControllerToken](s.client, withMethod(http.MethodPost), withPath("runner_controllers/%d/tokens/%d/rotate", rid, tokenID), withRequestOpts(options...), ) } func (s *RunnerControllerTokensService) RevokeRunnerControllerToken(rid int64, tokenID int64, options ...RequestOptionFunc) (*Response, error) { _, resp, err := do[none](s.client, withMethod(http.MethodDelete), Loading
runner_controller_tokens_test.go +33 −0 Original line number Diff line number Diff line Loading @@ -111,6 +111,39 @@ func TestCreateRunnerControllerToken(t *testing.T) { assert.Equal(t, want, token) } func TestRotateRunnerControllerToken(t *testing.T) { t.Parallel() mux, client := setup(t) // GIVEN a runner controller token exists mux.HandleFunc("/api/v4/runner_controllers/1/tokens/1/rotate", func(w http.ResponseWriter, r *http.Request) { // WHEN the rotate endpoint is called with POST testMethod(t, r, http.MethodPost) fmt.Fprint(w, `{ "id": 1, "runner_controller_id": 1, "description": "Rotated Token", "token": "glrct-rotated123", "created_at": "2020-02-14T00:00:00.000Z", "updated_at": "2020-05-20T00:00:00.000Z" }`) }) token, _, err := client.RunnerControllerTokens.RotateRunnerControllerToken(1, 1) assert.NoError(t, err) // THEN the rotated token is returned with a new token value want := &RunnerControllerToken{ ID: 1, RunnerControllerID: 1, Description: "Rotated Token", Token: "glrct-rotated123", CreatedAt: Ptr(time.Date(2020, time.February, 14, 0, 0, 0, 0, time.UTC)), UpdatedAt: Ptr(time.Date(2020, time.May, 20, 0, 0, 0, 0, time.UTC)), } assert.Equal(t, want, token) } func TestRevokeRunnerControllerToken(t *testing.T) { t.Parallel() mux, client := setup(t) Loading
runner_controllers.go +40 −32 Original line number Diff line number Diff line Loading @@ -9,46 +9,43 @@ type ( // RunnerControllersServiceInterface handles communication with the runner // controller related methods of the GitLab API. This is an admin-only endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // Note: This API is experimental and may change or be removed in future versions. // // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/ RunnerControllersServiceInterface interface { // ListRunnerControllers gets a list of runner controllers. This is an // admin-only endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/#list-all-runner-controllers ListRunnerControllers(opt *ListRunnerControllersOptions, options ...RequestOptionFunc) ([]*RunnerController, *Response, error) // GetRunnerController gets a single runner controller. This is an admin-only // endpoint. // GetRunnerController retrieves a single runner controller. This is an // admin-only endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/#retrieve-a-single-runner-controller GetRunnerController(rid int64, options ...RequestOptionFunc) (*RunnerController, *Response, error) // CreateRunnerController creates a new runner controller. This is an // CreateRunnerController registers a new runner controller. This is an // admin-only endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/#register-a-runner-controller CreateRunnerController(opt *CreateRunnerControllerOptions, options ...RequestOptionFunc) (*RunnerController, *Response, error) // UpdateRunnerController updates a runner controller. This is an admin-only // endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/#update-a-runner-controller UpdateRunnerController(rid int64, opt *UpdateRunnerControllerOptions, options ...RequestOptionFunc) (*RunnerController, *Response, error) // DeleteRunnerController deletes a runner controller. This is an admin-only // endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/#delete-a-runner-controller DeleteRunnerController(rid int64, options ...RequestOptionFunc) (*Response, error) } // RunnerControllersService handles communication with the runner controller // related methods of the GitLab API. This is an admin-only endpoint. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // Note: This API is experimental and may change or be removed in future versions. // // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/ RunnerControllersService struct { client *Client } Loading @@ -56,11 +53,25 @@ type ( var _ RunnerControllersServiceInterface = (*RunnerControllersService)(nil) // RunnerControllerStateValue represents the state of a runner controller. // // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/ type RunnerControllerStateValue string // These constants represent all valid runner controller states. const ( RunnerControllerStateDisabled RunnerControllerStateValue = "disabled" RunnerControllerStateEnabled RunnerControllerStateValue = "enabled" RunnerControllerStateDryRun RunnerControllerStateValue = "dry_run" ) // RunnerController represents a GitLab runner controller. // // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/ type RunnerController struct { ID int64 `json:"id"` Description string `json:"description"` Enabled bool `json:"enabled"` State RunnerControllerStateValue `json:"state"` CreatedAt *time.Time `json:"created_at"` UpdatedAt *time.Time `json:"updated_at"` } Loading @@ -68,8 +79,7 @@ type RunnerController struct { // ListRunnerControllersOptions represents the available // ListRunnerControllers() options. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/#list-all-runner-controllers type ListRunnerControllersOptions struct { ListOptions } Loading @@ -92,11 +102,10 @@ func (s *RunnerControllersService) GetRunnerController(rid int64, options ...Req // CreateRunnerControllerOptions represents the available // CreateRunnerController() options. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/#register-a-runner-controller type CreateRunnerControllerOptions struct { Description *string `url:"description,omitempty" json:"description,omitempty"` Enabled *bool `url:"enabled,omitempty" json:"enabled,omitempty"` State *RunnerControllerStateValue `url:"state,omitempty" json:"state,omitempty"` } func (s *RunnerControllersService) CreateRunnerController(opt *CreateRunnerControllerOptions, options ...RequestOptionFunc) (*RunnerController, *Response, error) { Loading @@ -111,11 +120,10 @@ func (s *RunnerControllersService) CreateRunnerController(opt *CreateRunnerContr // UpdateRunnerControllerOptions represents the available // UpdateRunnerController() options. // // GitLab API docs: Documentation not yet available, see // https://gitlab.com/gitlab-org/gitlab/-/issues/581275 // GitLab API docs: https://docs.gitlab.com/api/runner_controllers/#update-a-runner-controller type UpdateRunnerControllerOptions struct { Description *string `url:"description,omitempty" json:"description,omitempty"` Enabled *bool `url:"enabled,omitempty" json:"enabled,omitempty"` State *RunnerControllerStateValue `url:"state,omitempty" json:"state,omitempty"` } func (s *RunnerControllersService) UpdateRunnerController(rid int64, opt *UpdateRunnerControllerOptions, options ...RequestOptionFunc) (*RunnerController, *Response, error) { Loading
runner_controllers_test.go +14 −14 Original line number Diff line number Diff line Loading @@ -19,14 +19,14 @@ func TestListRunnerControllers(t *testing.T) { { "id": 1, "description": "Controller 1", "enabled": true, "state": "enabled", "created_at": "2020-02-14T00:00:00.000Z", "updated_at": "2020-02-15T00:00:00.000Z" }, { "id": 2, "description": "Controller 2", "enabled": false, "state": "disabled", "created_at": "2020-03-14T00:00:00.000Z", "updated_at": "2020-03-15T00:00:00.000Z" } Loading @@ -40,14 +40,14 @@ func TestListRunnerControllers(t *testing.T) { { ID: 1, Description: "Controller 1", Enabled: true, State: RunnerControllerStateEnabled, CreatedAt: Ptr(time.Date(2020, time.February, 14, 0, 0, 0, 0, time.UTC)), UpdatedAt: Ptr(time.Date(2020, time.February, 15, 0, 0, 0, 0, time.UTC)), }, { ID: 2, Description: "Controller 2", Enabled: false, State: RunnerControllerStateDisabled, CreatedAt: Ptr(time.Date(2020, time.March, 14, 0, 0, 0, 0, time.UTC)), UpdatedAt: Ptr(time.Date(2020, time.March, 15, 0, 0, 0, 0, time.UTC)), }, Loading @@ -64,7 +64,7 @@ func TestGetRunnerController(t *testing.T) { fmt.Fprint(w, `{ "id": 1, "description": "Test Controller", "enabled": true, "state": "enabled", "created_at": "2020-02-14T00:00:00.000Z", "updated_at": "2020-02-15T00:00:00.000Z" }`) Loading @@ -76,7 +76,7 @@ func TestGetRunnerController(t *testing.T) { want := &RunnerController{ ID: 1, Description: "Test Controller", Enabled: true, State: RunnerControllerStateEnabled, CreatedAt: Ptr(time.Date(2020, time.February, 14, 0, 0, 0, 0, time.UTC)), UpdatedAt: Ptr(time.Date(2020, time.February, 15, 0, 0, 0, 0, time.UTC)), } Loading @@ -91,12 +91,12 @@ func TestCreateRunnerController(t *testing.T) { testMethod(t, r, http.MethodPost) testBodyJSON(t, r, map[string]any{ "description": "New Controller", "enabled": true, "state": "dry_run", }) fmt.Fprint(w, `{ "id": 3, "description": "New Controller", "enabled": true, "state": "dry_run", "created_at": "2020-04-14T00:00:00.000Z", "updated_at": "2020-04-14T00:00:00.000Z" }`) Loading @@ -104,7 +104,7 @@ func TestCreateRunnerController(t *testing.T) { opt := &CreateRunnerControllerOptions{ Description: Ptr("New Controller"), Enabled: Ptr(true), State: Ptr(RunnerControllerStateDryRun), } controller, _, err := client.RunnerControllers.CreateRunnerController(opt) assert.NoError(t, err) Loading @@ -112,7 +112,7 @@ func TestCreateRunnerController(t *testing.T) { want := &RunnerController{ ID: 3, Description: "New Controller", Enabled: true, State: RunnerControllerStateDryRun, CreatedAt: Ptr(time.Date(2020, time.April, 14, 0, 0, 0, 0, time.UTC)), UpdatedAt: Ptr(time.Date(2020, time.April, 14, 0, 0, 0, 0, time.UTC)), } Loading @@ -127,12 +127,12 @@ func TestUpdateRunnerController(t *testing.T) { testMethod(t, r, http.MethodPut) testBodyJSON(t, r, map[string]any{ "description": "Updated Controller", "enabled": false, "state": "disabled", }) fmt.Fprint(w, `{ "id": 1, "description": "Updated Controller", "enabled": false, "state": "disabled", "created_at": "2020-02-14T00:00:00.000Z", "updated_at": "2020-05-15T00:00:00.000Z" }`) Loading @@ -140,7 +140,7 @@ func TestUpdateRunnerController(t *testing.T) { opt := &UpdateRunnerControllerOptions{ Description: Ptr("Updated Controller"), Enabled: Ptr(false), State: Ptr(RunnerControllerStateDisabled), } controller, _, err := client.RunnerControllers.UpdateRunnerController(1, opt) assert.NoError(t, err) Loading @@ -148,7 +148,7 @@ func TestUpdateRunnerController(t *testing.T) { want := &RunnerController{ ID: 1, Description: "Updated Controller", Enabled: false, State: RunnerControllerStateDisabled, CreatedAt: Ptr(time.Date(2020, time.February, 14, 0, 0, 0, 0, time.UTC)), UpdatedAt: Ptr(time.Date(2020, time.May, 15, 0, 0, 0, 0, time.UTC)), } Loading
testing/runner_controller_tokens_mock.go +45 −0 Original line number Diff line number Diff line Loading @@ -217,3 +217,48 @@ func (c *MockRunnerControllerTokensServiceInterfaceRevokeRunnerControllerTokenCa c.Call = c.Call.DoAndReturn(f) return c } // RotateRunnerControllerToken mocks base method. func (m *MockRunnerControllerTokensServiceInterface) RotateRunnerControllerToken(rid, tokenID int64, options ...gitlab.RequestOptionFunc) (*gitlab.RunnerControllerToken, *gitlab.Response, error) { m.ctrl.T.Helper() varargs := []any{rid, tokenID} for _, a := range options { varargs = append(varargs, a) } ret := m.ctrl.Call(m, "RotateRunnerControllerToken", varargs...) ret0, _ := ret[0].(*gitlab.RunnerControllerToken) ret1, _ := ret[1].(*gitlab.Response) ret2, _ := ret[2].(error) return ret0, ret1, ret2 } // RotateRunnerControllerToken indicates an expected call of RotateRunnerControllerToken. func (mr *MockRunnerControllerTokensServiceInterfaceMockRecorder) RotateRunnerControllerToken(rid, tokenID any, options ...any) *MockRunnerControllerTokensServiceInterfaceRotateRunnerControllerTokenCall { mr.mock.ctrl.T.Helper() varargs := append([]any{rid, tokenID}, options...) call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RotateRunnerControllerToken", reflect.TypeOf((*MockRunnerControllerTokensServiceInterface)(nil).RotateRunnerControllerToken), varargs...) return &MockRunnerControllerTokensServiceInterfaceRotateRunnerControllerTokenCall{Call: call} } // MockRunnerControllerTokensServiceInterfaceRotateRunnerControllerTokenCall wrap *gomock.Call type MockRunnerControllerTokensServiceInterfaceRotateRunnerControllerTokenCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return func (c *MockRunnerControllerTokensServiceInterfaceRotateRunnerControllerTokenCall) Return(arg0 *gitlab.RunnerControllerToken, arg1 *gitlab.Response, arg2 error) *MockRunnerControllerTokensServiceInterfaceRotateRunnerControllerTokenCall { c.Call = c.Call.Return(arg0, arg1, arg2) return c } // Do rewrite *gomock.Call.Do func (c *MockRunnerControllerTokensServiceInterfaceRotateRunnerControllerTokenCall) Do(f func(int64, int64, ...gitlab.RequestOptionFunc) (*gitlab.RunnerControllerToken, *gitlab.Response, error)) *MockRunnerControllerTokensServiceInterfaceRotateRunnerControllerTokenCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn func (c *MockRunnerControllerTokensServiceInterfaceRotateRunnerControllerTokenCall) DoAndReturn(f func(int64, int64, ...gitlab.RequestOptionFunc) (*gitlab.RunnerControllerToken, *gitlab.Response, error)) *MockRunnerControllerTokensServiceInterfaceRotateRunnerControllerTokenCall { c.Call = c.Call.DoAndReturn(f) return c }