1 // 2 // Copyright 2022, Timo Furrer <tuxtimo@gmail.com> 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 "net/http" 20 21 // MetadataService handles communication with the GitLab server instance to 22 // retrieve its metadata information via the GitLab API. 23 // 24 // GitLab API docs: https://docs.gitlab.com/ee/api/metadata.html 25 type MetadataService struct { 26 client *Client 27 } 28 29 // Metadata represents a GitLab instance version. 30 // 31 // GitLab API docs: https://docs.gitlab.com/ee/api/metadata.html 32 type Metadata struct { 33 Version string `json:"version"` 34 Revision string `json:"revision"` 35 KAS struct { 36 Enabled bool `json:"enabled"` 37 ExternalURL string `json:"externalUrl"` 38 Version string `json:"version"` 39 } `json:"kas"` 40 Enterprise bool `json:"enterprise"` 41 } 42 43 func (s Metadata) String() string { 44 return Stringify(s) 45 } 46 47 // GetMetadata gets a GitLab server instance meteadata. 48 // 49 // GitLab API docs: https://docs.gitlab.com/ee/api/metadata.html 50 func (s *MetadataService) GetMetadata(options ...RequestOptionFunc) (*Metadata, *Response, error) { 51 req, err := s.client.NewRequest(http.MethodGet, "metadata", nil, options) 52 if err != nil { 53 return nil, nil, err 54 } 55 56 v := new(Metadata) 57 resp, err := s.client.Do(req, v) 58 if err != nil { 59 return nil, resp, err 60 } 61 62 return v, resp, nil 63 } 64