Debian Codegraph @

snapshot_verify_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
13 "gopkg.in/olivere/elastic.v5/uritemplates"
14 )
15
16 // SnapshotVerifyRepositoryService verifies a snapshop repository.
17 // See https://www.elastic.co/guide/en/elasticsearch/reference/5.3/modules-snapshots.html
18 // for details.
19 type SnapshotVerifyRepositoryService struct {
20 client *Client
21 pretty bool
22 repository string
23 masterTimeout string
24 timeout string
25 }
26
27 // NewSnapshotVerifyRepositoryService creates a new SnapshotVerifyRepositoryService.
28 func NewSnapshotVerifyRepositoryService(client *Client) *SnapshotVerifyRepositoryService {
29 return &SnapshotVerifyRepositoryService{
30 client: client,
31 }
32 }
33
34 // Repository specifies the repository name.
35 func (s *SnapshotVerifyRepositoryService) Repository(repository string) *SnapshotVerifyRepositoryService {
36 s.repository = repository
37 return s
38 }
39
40 // MasterTimeout is the explicit operation timeout for connection to master node.
41 func (s *SnapshotVerifyRepositoryService) MasterTimeout(masterTimeout string) *SnapshotVerifyRepositoryService {
42 s.masterTimeout = masterTimeout
43 return s
44 }
45
46 // Timeout is an explicit operation timeout.
47 func (s *SnapshotVerifyRepositoryService) Timeout(timeout string) *SnapshotVerifyRepositoryService {
48 s.timeout = timeout
49 return s
50 }
51
52 // Pretty indicates that the JSON response be indented and human readable.
53 func (s *SnapshotVerifyRepositoryService) Pretty(pretty bool) *SnapshotVerifyRepositoryService {
54 s.pretty = pretty
55 return s
56 }
57
58 // buildURL builds the URL for the operation.
59 func (s *SnapshotVerifyRepositoryService) buildURL() (string, url.Values, error) {
60 // Build URL
61 path, err := uritemplates.Expand("/_snapshot/{repository}/_verify", map[string]string{
62 "repository": s.repository,
63 })
64 if err != nil {
65 return "", url.Values{}, err
66 }
67
68 // Add query string parameters
69 params := url.Values{}
70 if s.pretty {
71 params.Set("pretty", "1")
72 }
73 if s.masterTimeout != "" {
74 params.Set("master_timeout", s.masterTimeout)
75 }
76 if s.timeout != "" {
77 params.Set("timeout", s.timeout)
78 }
79 return path, params, nil
80 }
81
82 // Validate checks if the operation is valid.
83 func (s *SnapshotVerifyRepositoryService) Validate() error {
84 var invalid []string
85 if s.repository == "" {
86 invalid = append(invalid, "Repository")
87 }
88 if len(invalid) > 0 {
89 return fmt.Errorf("missing required fields: %v", invalid)
90 }
91 return nil
92 }
93
94 // Do executes the operation.
95 func (s *SnapshotVerifyRepositoryService) Do(ctx context.Context) (*SnapshotVerifyRepositoryResponse, error) {
96 // Check pre-conditions
97 if err := s.Validate(); err != nil {
98 return nil, err
99 }
100
101 // Get URL for request
102 path, params, err := s.buildURL()
103 if err != nil {
104 return nil, err
105 }
106
107 // Get HTTP response
108 res, err := s.client.PerformRequest(ctx, "POST", path, params, nil)
109 if err != nil {
110 return nil, err
111 }
112
113 // Return operation response
114 ret := new(SnapshotVerifyRepositoryResponse)
115 if err := json.Unmarshal(res.Body, ret); err != nil {
116 return nil, err
117 }
118 return ret, nil
119 }
120
121 // SnapshotVerifyRepositoryResponse is the response of SnapshotVerifyRepositoryService.Do.
122 type SnapshotVerifyRepositoryResponse struct {
123 Nodes map[string]*SnapshotVerifyRepositoryNode `json:"nodes"`
124 }
125
126 type SnapshotVerifyRepositoryNode struct {
127 Name string `json:"name"`
128 }