Skip to content
This repository was archived by the owner on Dec 10, 2024. It is now read-only.

Commit 43efaa2

Browse files
authored
Merge pull request #893 from sfang97/instance-cluster-api
Add instance cluster API support
2 parents 3f5c3a9 + e428907 commit 43efaa2

File tree

3 files changed

+154
-0
lines changed

3 files changed

+154
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ to add new and/or missing endpoints. Currently the following services are suppor
4444
- [x] Group Milestones
4545
- [x] Group-Level Variables
4646
- [x] Groups
47+
- [x] Instance Clusters
4748
- [x] Issue Boards
4849
- [x] Issues
4950
- [x] Jobs

gitlab.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ type Client struct {
126126
GroupMilestones *GroupMilestonesService
127127
GroupVariables *GroupVariablesService
128128
Groups *GroupsService
129+
InstanceCluster *InstanceClustersService
129130
IssueLinks *IssueLinksService
130131
Issues *IssuesService
131132
Jobs *JobsService
@@ -281,6 +282,7 @@ func newClient(options ...ClientOptionFunc) (*Client, error) {
281282
c.GroupMilestones = &GroupMilestonesService{client: c}
282283
c.GroupVariables = &GroupVariablesService{client: c}
283284
c.Groups = &GroupsService{client: c}
285+
c.InstanceCluster = &InstanceClustersService{client: c}
284286
c.IssueLinks = &IssueLinksService{client: c}
285287
c.Issues = &IssuesService{client: c, timeStats: timeStats}
286288
c.Jobs = &JobsService{client: c}

instance_clusters.go

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
//
2+
// Copyright 2020, Serena Fang
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+
"time"
22+
)
23+
24+
// InstanceClustersService handles communication with the
25+
// instance clusters related methods of the GitLab API.
26+
//
27+
// GitLab API docs:
28+
// https://docs.gitlab.com/ee/api/instance_clusters.html
29+
type InstanceClustersService struct {
30+
client *Client
31+
}
32+
33+
// InstanceCluster represents a GitLab Instance Cluster.
34+
//
35+
// GitLab API docs: https://docs.gitlab.com/ee/api/instance_clusters.html
36+
type InstanceCluster struct {
37+
ID int `json:"id"`
38+
Name string `json:"name"`
39+
Domain string `json:"domain"`
40+
CreatedAt *time.Time `json:"created_at"`
41+
ProviderType string `json:"provider_type"`
42+
PlatformType string `json:"platform_type"`
43+
EnvironmentScope string `json:"environment_scope"`
44+
ClusterType string `json:"cluster_type"`
45+
User *User `json:"user"`
46+
PlatformKubernetes *PlatformKubernetes `json:"platform_kubernetes"`
47+
ManagementProject *ManagementProject `json:"management_project"`
48+
}
49+
50+
func (v InstanceCluster) String() string {
51+
return Stringify(v)
52+
}
53+
54+
// ListClusters gets a list of all instance clusters.
55+
//
56+
// GitLab API docs:
57+
// https://docs.gitlab.com/ee/api/instance_clusters.html#list-instance-clusters
58+
func (s *InstanceClustersService) ListClusters(options ...RequestOptionFunc) ([]*InstanceCluster, *Response, error) {
59+
u := fmt.Sprintf("admin/clusters")
60+
61+
req, err := s.client.NewRequest("GET", u, nil, options)
62+
if err != nil {
63+
return nil, nil, err
64+
}
65+
66+
var ics []*InstanceCluster
67+
resp, err := s.client.Do(req, &ics)
68+
if err != nil {
69+
return nil, resp, err
70+
}
71+
72+
return ics, resp, err
73+
}
74+
75+
// GetCluster gets an instance cluster.
76+
//
77+
// GitLab API docs:
78+
// https://docs.gitlab.com/ee/api/instance_clusters.html#get-a-single-instance-cluster
79+
func (s *InstanceClustersService) GetCluster(cluster int, options ...RequestOptionFunc) (*InstanceCluster, *Response, error) {
80+
u := fmt.Sprintf("admin/clusters/%d", cluster)
81+
82+
req, err := s.client.NewRequest("GET", u, nil, options)
83+
if err != nil {
84+
return nil, nil, err
85+
}
86+
87+
ic := new(InstanceCluster)
88+
resp, err := s.client.Do(req, &ic)
89+
if err != nil {
90+
return nil, resp, err
91+
}
92+
93+
return ic, resp, err
94+
}
95+
96+
// AddCluster adds an existing cluster to the instance.
97+
//
98+
// GitLab API docs:
99+
// https://docs.gitlab.com/ee/api/instance_clusters.html#add-existing-instance-cluster
100+
func (s *InstanceClustersService) AddCluster(opt *AddClusterOptions, options ...RequestOptionFunc) (*InstanceCluster, *Response, error) {
101+
u := fmt.Sprintf("admin/clusters/add")
102+
103+
req, err := s.client.NewRequest("POST", u, opt, options)
104+
if err != nil {
105+
return nil, nil, err
106+
}
107+
108+
ic := new(InstanceCluster)
109+
resp, err := s.client.Do(req, ic)
110+
if err != nil {
111+
return nil, resp, err
112+
}
113+
114+
return ic, resp, err
115+
}
116+
117+
// EditCluster updates an existing instance cluster.
118+
//
119+
// GitLab API docs:
120+
// https://docs.gitlab.com/ee/api/instance_clusters.html#edit-instance-cluster
121+
func (s *InstanceClustersService) EditCluster(cluster int, opt *EditClusterOptions, options ...RequestOptionFunc) (*InstanceCluster, *Response, error) {
122+
u := fmt.Sprintf("admin/clusters/%d", cluster)
123+
124+
req, err := s.client.NewRequest("PUT", u, opt, options)
125+
if err != nil {
126+
return nil, nil, err
127+
}
128+
129+
ic := new(InstanceCluster)
130+
resp, err := s.client.Do(req, ic)
131+
if err != nil {
132+
return nil, resp, err
133+
}
134+
135+
return ic, resp, err
136+
}
137+
138+
// DeleteCluster deletes an existing instance cluster.
139+
//
140+
// GitLab API docs:
141+
// https://docs.gitlab.com/ee/api/instance_clusters.html#delete-instance-cluster
142+
func (s *InstanceClustersService) DeleteCluster(cluster int, options ...RequestOptionFunc) (*Response, error) {
143+
u := fmt.Sprintf("admin/clusters/%d", cluster)
144+
145+
req, err := s.client.NewRequest("DELETE", u, nil, options)
146+
if err != nil {
147+
return nil, err
148+
}
149+
150+
return s.client.Do(req, nil)
151+
}

0 commit comments

Comments
 (0)