...

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

Documentation: github.com/xanzy/go-gitlab

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

View as plain text