api.fleet.global_checkpoints.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. // Licensed to Elasticsearch B.V. under one or more contributor
  2. // license agreements. See the NOTICE file distributed with
  3. // this work for additional information regarding copyright
  4. // ownership. Elasticsearch B.V. licenses this file to you under
  5. // the Apache License, Version 2.0 (the "License"); you may
  6. // not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing,
  12. // software distributed under the License is distributed on an
  13. // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. // KIND, either express or implied. See the License for the
  15. // specific language governing permissions and limitations
  16. // under the License.
  17. //
  18. // Code generated from specification version 7.17.10: DO NOT EDIT
  19. package esapi
  20. import (
  21. "context"
  22. "net/http"
  23. "strconv"
  24. "strings"
  25. "time"
  26. )
  27. func newFleetGlobalCheckpointsFunc(t Transport) FleetGlobalCheckpoints {
  28. return func(index string, o ...func(*FleetGlobalCheckpointsRequest)) (*Response, error) {
  29. var r = FleetGlobalCheckpointsRequest{Index: index}
  30. for _, f := range o {
  31. f(&r)
  32. }
  33. return r.Do(r.ctx, t)
  34. }
  35. }
  36. // ----- API Definition -------------------------------------------------------
  37. // FleetGlobalCheckpoints returns the current global checkpoints for an index. This API is design for internal use by the fleet server project.
  38. //
  39. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/get-global-checkpoints.html.
  40. type FleetGlobalCheckpoints func(index string, o ...func(*FleetGlobalCheckpointsRequest)) (*Response, error)
  41. // FleetGlobalCheckpointsRequest configures the Fleet Global Checkpoints API request.
  42. type FleetGlobalCheckpointsRequest struct {
  43. Index string
  44. Checkpoints []string
  45. Timeout time.Duration
  46. WaitForAdvance *bool
  47. WaitForIndex *bool
  48. Pretty bool
  49. Human bool
  50. ErrorTrace bool
  51. FilterPath []string
  52. Header http.Header
  53. ctx context.Context
  54. }
  55. // Do executes the request and returns response or error.
  56. func (r FleetGlobalCheckpointsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
  57. var (
  58. method string
  59. path strings.Builder
  60. params map[string]string
  61. )
  62. method = "GET"
  63. path.Grow(1 + len(r.Index) + 1 + len("_fleet") + 1 + len("global_checkpoints"))
  64. path.WriteString("/")
  65. path.WriteString(r.Index)
  66. path.WriteString("/")
  67. path.WriteString("_fleet")
  68. path.WriteString("/")
  69. path.WriteString("global_checkpoints")
  70. params = make(map[string]string)
  71. if len(r.Checkpoints) > 0 {
  72. params["checkpoints"] = strings.Join(r.Checkpoints, ",")
  73. }
  74. if r.Timeout != 0 {
  75. params["timeout"] = formatDuration(r.Timeout)
  76. }
  77. if r.WaitForAdvance != nil {
  78. params["wait_for_advance"] = strconv.FormatBool(*r.WaitForAdvance)
  79. }
  80. if r.WaitForIndex != nil {
  81. params["wait_for_index"] = strconv.FormatBool(*r.WaitForIndex)
  82. }
  83. if r.Pretty {
  84. params["pretty"] = "true"
  85. }
  86. if r.Human {
  87. params["human"] = "true"
  88. }
  89. if r.ErrorTrace {
  90. params["error_trace"] = "true"
  91. }
  92. if len(r.FilterPath) > 0 {
  93. params["filter_path"] = strings.Join(r.FilterPath, ",")
  94. }
  95. req, err := newRequest(method, path.String(), nil)
  96. if err != nil {
  97. return nil, err
  98. }
  99. if len(params) > 0 {
  100. q := req.URL.Query()
  101. for k, v := range params {
  102. q.Set(k, v)
  103. }
  104. req.URL.RawQuery = q.Encode()
  105. }
  106. if len(r.Header) > 0 {
  107. if len(req.Header) == 0 {
  108. req.Header = r.Header
  109. } else {
  110. for k, vv := range r.Header {
  111. for _, v := range vv {
  112. req.Header.Add(k, v)
  113. }
  114. }
  115. }
  116. }
  117. if ctx != nil {
  118. req = req.WithContext(ctx)
  119. }
  120. res, err := transport.Perform(req)
  121. if err != nil {
  122. return nil, err
  123. }
  124. response := Response{
  125. StatusCode: res.StatusCode,
  126. Body: res.Body,
  127. Header: res.Header,
  128. }
  129. return &response, nil
  130. }
  131. // WithContext sets the request context.
  132. func (f FleetGlobalCheckpoints) WithContext(v context.Context) func(*FleetGlobalCheckpointsRequest) {
  133. return func(r *FleetGlobalCheckpointsRequest) {
  134. r.ctx = v
  135. }
  136. }
  137. // WithCheckpoints - comma separated list of checkpoints.
  138. func (f FleetGlobalCheckpoints) WithCheckpoints(v ...string) func(*FleetGlobalCheckpointsRequest) {
  139. return func(r *FleetGlobalCheckpointsRequest) {
  140. r.Checkpoints = v
  141. }
  142. }
  143. // WithTimeout - timeout to wait for global checkpoint to advance.
  144. func (f FleetGlobalCheckpoints) WithTimeout(v time.Duration) func(*FleetGlobalCheckpointsRequest) {
  145. return func(r *FleetGlobalCheckpointsRequest) {
  146. r.Timeout = v
  147. }
  148. }
  149. // WithWaitForAdvance - whether to wait for the global checkpoint to advance past the specified current checkpoints.
  150. func (f FleetGlobalCheckpoints) WithWaitForAdvance(v bool) func(*FleetGlobalCheckpointsRequest) {
  151. return func(r *FleetGlobalCheckpointsRequest) {
  152. r.WaitForAdvance = &v
  153. }
  154. }
  155. // WithWaitForIndex - whether to wait for the target index to exist and all primary shards be active.
  156. func (f FleetGlobalCheckpoints) WithWaitForIndex(v bool) func(*FleetGlobalCheckpointsRequest) {
  157. return func(r *FleetGlobalCheckpointsRequest) {
  158. r.WaitForIndex = &v
  159. }
  160. }
  161. // WithPretty makes the response body pretty-printed.
  162. func (f FleetGlobalCheckpoints) WithPretty() func(*FleetGlobalCheckpointsRequest) {
  163. return func(r *FleetGlobalCheckpointsRequest) {
  164. r.Pretty = true
  165. }
  166. }
  167. // WithHuman makes statistical values human-readable.
  168. func (f FleetGlobalCheckpoints) WithHuman() func(*FleetGlobalCheckpointsRequest) {
  169. return func(r *FleetGlobalCheckpointsRequest) {
  170. r.Human = true
  171. }
  172. }
  173. // WithErrorTrace includes the stack trace for errors in the response body.
  174. func (f FleetGlobalCheckpoints) WithErrorTrace() func(*FleetGlobalCheckpointsRequest) {
  175. return func(r *FleetGlobalCheckpointsRequest) {
  176. r.ErrorTrace = true
  177. }
  178. }
  179. // WithFilterPath filters the properties of the response body.
  180. func (f FleetGlobalCheckpoints) WithFilterPath(v ...string) func(*FleetGlobalCheckpointsRequest) {
  181. return func(r *FleetGlobalCheckpointsRequest) {
  182. r.FilterPath = v
  183. }
  184. }
  185. // WithHeader adds the headers to the HTTP request.
  186. func (f FleetGlobalCheckpoints) WithHeader(h map[string]string) func(*FleetGlobalCheckpointsRequest) {
  187. return func(r *FleetGlobalCheckpointsRequest) {
  188. if r.Header == nil {
  189. r.Header = make(http.Header)
  190. }
  191. for k, v := range h {
  192. r.Header.Add(k, v)
  193. }
  194. }
  195. }
  196. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  197. func (f FleetGlobalCheckpoints) WithOpaqueID(s string) func(*FleetGlobalCheckpointsRequest) {
  198. return func(r *FleetGlobalCheckpointsRequest) {
  199. if r.Header == nil {
  200. r.Header = make(http.Header)
  201. }
  202. r.Header.Set("X-Opaque-Id", s)
  203. }
  204. }