api.cat.plugins.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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 newCatPluginsFunc(t Transport) CatPlugins {
  28. return func(o ...func(*CatPluginsRequest)) (*Response, error) {
  29. var r = CatPluginsRequest{}
  30. for _, f := range o {
  31. f(&r)
  32. }
  33. return r.Do(r.ctx, t)
  34. }
  35. }
  36. // ----- API Definition -------------------------------------------------------
  37. // CatPlugins returns information about installed plugins across nodes node.
  38. //
  39. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-plugins.html.
  40. type CatPlugins func(o ...func(*CatPluginsRequest)) (*Response, error)
  41. // CatPluginsRequest configures the Cat Plugins API request.
  42. type CatPluginsRequest struct {
  43. Format string
  44. H []string
  45. Help *bool
  46. IncludeBootstrap *bool
  47. Local *bool
  48. MasterTimeout time.Duration
  49. S []string
  50. V *bool
  51. Pretty bool
  52. Human bool
  53. ErrorTrace bool
  54. FilterPath []string
  55. Header http.Header
  56. ctx context.Context
  57. }
  58. // Do executes the request and returns response or error.
  59. func (r CatPluginsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
  60. var (
  61. method string
  62. path strings.Builder
  63. params map[string]string
  64. )
  65. method = "GET"
  66. path.Grow(len("/_cat/plugins"))
  67. path.WriteString("/_cat/plugins")
  68. params = make(map[string]string)
  69. if r.Format != "" {
  70. params["format"] = r.Format
  71. }
  72. if len(r.H) > 0 {
  73. params["h"] = strings.Join(r.H, ",")
  74. }
  75. if r.Help != nil {
  76. params["help"] = strconv.FormatBool(*r.Help)
  77. }
  78. if r.IncludeBootstrap != nil {
  79. params["include_bootstrap"] = strconv.FormatBool(*r.IncludeBootstrap)
  80. }
  81. if r.Local != nil {
  82. params["local"] = strconv.FormatBool(*r.Local)
  83. }
  84. if r.MasterTimeout != 0 {
  85. params["master_timeout"] = formatDuration(r.MasterTimeout)
  86. }
  87. if len(r.S) > 0 {
  88. params["s"] = strings.Join(r.S, ",")
  89. }
  90. if r.V != nil {
  91. params["v"] = strconv.FormatBool(*r.V)
  92. }
  93. if r.Pretty {
  94. params["pretty"] = "true"
  95. }
  96. if r.Human {
  97. params["human"] = "true"
  98. }
  99. if r.ErrorTrace {
  100. params["error_trace"] = "true"
  101. }
  102. if len(r.FilterPath) > 0 {
  103. params["filter_path"] = strings.Join(r.FilterPath, ",")
  104. }
  105. req, err := newRequest(method, path.String(), nil)
  106. if err != nil {
  107. return nil, err
  108. }
  109. if len(params) > 0 {
  110. q := req.URL.Query()
  111. for k, v := range params {
  112. q.Set(k, v)
  113. }
  114. req.URL.RawQuery = q.Encode()
  115. }
  116. if len(r.Header) > 0 {
  117. if len(req.Header) == 0 {
  118. req.Header = r.Header
  119. } else {
  120. for k, vv := range r.Header {
  121. for _, v := range vv {
  122. req.Header.Add(k, v)
  123. }
  124. }
  125. }
  126. }
  127. if ctx != nil {
  128. req = req.WithContext(ctx)
  129. }
  130. res, err := transport.Perform(req)
  131. if err != nil {
  132. return nil, err
  133. }
  134. response := Response{
  135. StatusCode: res.StatusCode,
  136. Body: res.Body,
  137. Header: res.Header,
  138. }
  139. return &response, nil
  140. }
  141. // WithContext sets the request context.
  142. func (f CatPlugins) WithContext(v context.Context) func(*CatPluginsRequest) {
  143. return func(r *CatPluginsRequest) {
  144. r.ctx = v
  145. }
  146. }
  147. // WithFormat - a short version of the accept header, e.g. json, yaml.
  148. func (f CatPlugins) WithFormat(v string) func(*CatPluginsRequest) {
  149. return func(r *CatPluginsRequest) {
  150. r.Format = v
  151. }
  152. }
  153. // WithH - comma-separated list of column names to display.
  154. func (f CatPlugins) WithH(v ...string) func(*CatPluginsRequest) {
  155. return func(r *CatPluginsRequest) {
  156. r.H = v
  157. }
  158. }
  159. // WithHelp - return help information.
  160. func (f CatPlugins) WithHelp(v bool) func(*CatPluginsRequest) {
  161. return func(r *CatPluginsRequest) {
  162. r.Help = &v
  163. }
  164. }
  165. // WithIncludeBootstrap - include bootstrap plugins in the response.
  166. func (f CatPlugins) WithIncludeBootstrap(v bool) func(*CatPluginsRequest) {
  167. return func(r *CatPluginsRequest) {
  168. r.IncludeBootstrap = &v
  169. }
  170. }
  171. // WithLocal - return local information, do not retrieve the state from master node (default: false).
  172. func (f CatPlugins) WithLocal(v bool) func(*CatPluginsRequest) {
  173. return func(r *CatPluginsRequest) {
  174. r.Local = &v
  175. }
  176. }
  177. // WithMasterTimeout - explicit operation timeout for connection to master node.
  178. func (f CatPlugins) WithMasterTimeout(v time.Duration) func(*CatPluginsRequest) {
  179. return func(r *CatPluginsRequest) {
  180. r.MasterTimeout = v
  181. }
  182. }
  183. // WithS - comma-separated list of column names or column aliases to sort by.
  184. func (f CatPlugins) WithS(v ...string) func(*CatPluginsRequest) {
  185. return func(r *CatPluginsRequest) {
  186. r.S = v
  187. }
  188. }
  189. // WithV - verbose mode. display column headers.
  190. func (f CatPlugins) WithV(v bool) func(*CatPluginsRequest) {
  191. return func(r *CatPluginsRequest) {
  192. r.V = &v
  193. }
  194. }
  195. // WithPretty makes the response body pretty-printed.
  196. func (f CatPlugins) WithPretty() func(*CatPluginsRequest) {
  197. return func(r *CatPluginsRequest) {
  198. r.Pretty = true
  199. }
  200. }
  201. // WithHuman makes statistical values human-readable.
  202. func (f CatPlugins) WithHuman() func(*CatPluginsRequest) {
  203. return func(r *CatPluginsRequest) {
  204. r.Human = true
  205. }
  206. }
  207. // WithErrorTrace includes the stack trace for errors in the response body.
  208. func (f CatPlugins) WithErrorTrace() func(*CatPluginsRequest) {
  209. return func(r *CatPluginsRequest) {
  210. r.ErrorTrace = true
  211. }
  212. }
  213. // WithFilterPath filters the properties of the response body.
  214. func (f CatPlugins) WithFilterPath(v ...string) func(*CatPluginsRequest) {
  215. return func(r *CatPluginsRequest) {
  216. r.FilterPath = v
  217. }
  218. }
  219. // WithHeader adds the headers to the HTTP request.
  220. func (f CatPlugins) WithHeader(h map[string]string) func(*CatPluginsRequest) {
  221. return func(r *CatPluginsRequest) {
  222. if r.Header == nil {
  223. r.Header = make(http.Header)
  224. }
  225. for k, v := range h {
  226. r.Header.Add(k, v)
  227. }
  228. }
  229. }
  230. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  231. func (f CatPlugins) WithOpaqueID(s string) func(*CatPluginsRequest) {
  232. return func(r *CatPluginsRequest) {
  233. if r.Header == nil {
  234. r.Header = make(http.Header)
  235. }
  236. r.Header.Set("X-Opaque-Id", s)
  237. }
  238. }