Debian Codegraph @

snapshot_get_repository.go

raw
1 // Copyright 2012-present Oliver Eilhard. All rights reserved.
2 // Use of this source code is governed by a MIT-license.
3 // See http://olivere.mit-license.org/license.txt for details.
4
5 package elastic
6
7 import (
8 "context"
9 "encoding/json"
10 "fmt"
11 "net/url"
12 "strings"
13
14 "gopkg.in/olivere/elastic.v5/uritemplates"
15 )
16
17 // SnapshotGetRepositoryService reads a snapshot repository.
18 // See https://www.elastic.co/guide/en/elasticsearch/reference/5.3/modules-snapshots.html
19 // for details.
20 type SnapshotGetRepositoryService struct {
21 client *Client
22 pretty bool
23 repository []string
24 local *bool
25 masterTimeout string
26 }
27
28 // NewSnapshotGetRepositoryService creates a new SnapshotGetRepositoryService.
29 func NewSnapshotGetRepositoryService(client *Client) *SnapshotGetRepositoryService {
30 return &SnapshotGetRepositoryService{
31 client: client,
32 repository: make([]string, 0),
33 }
34 }
35
36 // Repository is the list of repository names.
37 func (s *SnapshotGetRepositoryService) Repository(repositories ...string) *SnapshotGetRepositoryService {
38 s.repository = append(s.repository, repositories...)
39 return s
40 }
41
42 // Local indicates whether to return local information, i.e. do not retrieve the state from master node (default: false).
43 func (s *SnapshotGetRepositoryService) Local(local bool) *SnapshotGetRepositoryService {
44 s.local = &local
45 return s
46 }
47
48 // MasterTimeout specifies an explicit operation timeout for connection to master node.
49 func (s *SnapshotGetRepositoryService) MasterTimeout(masterTimeout string) *SnapshotGetRepositoryService {
50 s.masterTimeout = masterTimeout
51 return s
52 }
53
54 // Pretty indicates that the JSON response be indented and human readable.
55 func (s *SnapshotGetRepositoryService) Pretty(pretty bool) *SnapshotGetRepositoryService {
56 s.pretty = pretty
57 return s
58 }
59
60 // buildURL builds the URL for the operation.
61 func (s *SnapshotGetRepositoryService) buildURL() (string, url.Values, error) {
62 // Build URL
63 var err error
64 var path string
65 if len(s.repository) > 0 {
66 path, err = uritemplates.Expand("/_snapshot/{repository}", map[string]string{
67 "repository": strings.Join(s.repository, ","),
68 })
69 } else {
70 path = "/_snapshot"
71 }
72 if err != nil {
73 return "", url.Values{}, err
74 }
75
76 // Add query string parameters
77 params := url.Values{}
78 if s.pretty {
79 params.Set("pretty", "1")
80 }
81 if s.local != nil {
82 params.Set("local", fmt.Sprintf("%v", *s.local))
83 }
84 if s.masterTimeout != "" {
85 params.Set("master_timeout", s.masterTimeout)
86 }
87 return path, params, nil
88 }
89
90 // Validate checks if the operation is valid.
91 func (s *SnapshotGetRepositoryService) Validate() error {
92 return nil
93 }
94
95 // Do executes the operation.
96 func (s *SnapshotGetRepositoryService) Do(ctx context.Context) (SnapshotGetRepositoryResponse, error) {
97 // Check pre-conditions
98 if err := s.Validate(); err != nil {
99 return nil, err
100 }
101
102 // Get URL for request
103 path, params, err := s.buildURL()
104 if err != nil {
105 return nil, err
106 }
107
108 // Get HTTP response
109 res, err := s.client.PerformRequest(ctx, "GET", path, params, nil)
110 if err != nil {
111 return nil, err
112 }
113
114 // Return operation response
115 var ret SnapshotGetRepositoryResponse
116 if err := json.Unmarshal(res.Body, &ret); err != nil {
117 return nil, err
118 }
119 return ret, nil
120 }
121
122 // SnapshotGetRepositoryResponse is the response of SnapshotGetRepositoryService.Do.
123 type SnapshotGetRepositoryResponse map[string]*SnapshotRepositoryMetaData
124
125 // SnapshotRepositoryMetaData contains all information about
126 // a single snapshot repository.
127 type SnapshotRepositoryMetaData struct {
128 Type string `json:"type"`
129 Settings map[string]interface{} `json:"settings,omitempty"`
130 }