api.xpack.license.post.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. "io"
  23. "net/http"
  24. "strconv"
  25. "strings"
  26. )
  27. func newLicensePostFunc(t Transport) LicensePost {
  28. return func(o ...func(*LicensePostRequest)) (*Response, error) {
  29. var r = LicensePostRequest{}
  30. for _, f := range o {
  31. f(&r)
  32. }
  33. return r.Do(r.ctx, t)
  34. }
  35. }
  36. // ----- API Definition -------------------------------------------------------
  37. // LicensePost - Updates the license for the cluster.
  38. //
  39. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/update-license.html.
  40. type LicensePost func(o ...func(*LicensePostRequest)) (*Response, error)
  41. // LicensePostRequest configures the License Post API request.
  42. type LicensePostRequest struct {
  43. Body io.Reader
  44. Acknowledge *bool
  45. Pretty bool
  46. Human bool
  47. ErrorTrace bool
  48. FilterPath []string
  49. Header http.Header
  50. ctx context.Context
  51. }
  52. // Do executes the request and returns response or error.
  53. func (r LicensePostRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
  54. var (
  55. method string
  56. path strings.Builder
  57. params map[string]string
  58. )
  59. method = "PUT"
  60. path.Grow(len("/_license"))
  61. path.WriteString("/_license")
  62. params = make(map[string]string)
  63. if r.Acknowledge != nil {
  64. params["acknowledge"] = strconv.FormatBool(*r.Acknowledge)
  65. }
  66. if r.Pretty {
  67. params["pretty"] = "true"
  68. }
  69. if r.Human {
  70. params["human"] = "true"
  71. }
  72. if r.ErrorTrace {
  73. params["error_trace"] = "true"
  74. }
  75. if len(r.FilterPath) > 0 {
  76. params["filter_path"] = strings.Join(r.FilterPath, ",")
  77. }
  78. req, err := newRequest(method, path.String(), r.Body)
  79. if err != nil {
  80. return nil, err
  81. }
  82. if len(params) > 0 {
  83. q := req.URL.Query()
  84. for k, v := range params {
  85. q.Set(k, v)
  86. }
  87. req.URL.RawQuery = q.Encode()
  88. }
  89. if len(r.Header) > 0 {
  90. if len(req.Header) == 0 {
  91. req.Header = r.Header
  92. } else {
  93. for k, vv := range r.Header {
  94. for _, v := range vv {
  95. req.Header.Add(k, v)
  96. }
  97. }
  98. }
  99. }
  100. if r.Body != nil && req.Header.Get(headerContentType) == "" {
  101. req.Header[headerContentType] = headerContentTypeJSON
  102. }
  103. if ctx != nil {
  104. req = req.WithContext(ctx)
  105. }
  106. res, err := transport.Perform(req)
  107. if err != nil {
  108. return nil, err
  109. }
  110. response := Response{
  111. StatusCode: res.StatusCode,
  112. Body: res.Body,
  113. Header: res.Header,
  114. }
  115. return &response, nil
  116. }
  117. // WithContext sets the request context.
  118. func (f LicensePost) WithContext(v context.Context) func(*LicensePostRequest) {
  119. return func(r *LicensePostRequest) {
  120. r.ctx = v
  121. }
  122. }
  123. // WithBody - licenses to be installed.
  124. func (f LicensePost) WithBody(v io.Reader) func(*LicensePostRequest) {
  125. return func(r *LicensePostRequest) {
  126. r.Body = v
  127. }
  128. }
  129. // WithAcknowledge - whether the user has acknowledged acknowledge messages (default: false).
  130. func (f LicensePost) WithAcknowledge(v bool) func(*LicensePostRequest) {
  131. return func(r *LicensePostRequest) {
  132. r.Acknowledge = &v
  133. }
  134. }
  135. // WithPretty makes the response body pretty-printed.
  136. func (f LicensePost) WithPretty() func(*LicensePostRequest) {
  137. return func(r *LicensePostRequest) {
  138. r.Pretty = true
  139. }
  140. }
  141. // WithHuman makes statistical values human-readable.
  142. func (f LicensePost) WithHuman() func(*LicensePostRequest) {
  143. return func(r *LicensePostRequest) {
  144. r.Human = true
  145. }
  146. }
  147. // WithErrorTrace includes the stack trace for errors in the response body.
  148. func (f LicensePost) WithErrorTrace() func(*LicensePostRequest) {
  149. return func(r *LicensePostRequest) {
  150. r.ErrorTrace = true
  151. }
  152. }
  153. // WithFilterPath filters the properties of the response body.
  154. func (f LicensePost) WithFilterPath(v ...string) func(*LicensePostRequest) {
  155. return func(r *LicensePostRequest) {
  156. r.FilterPath = v
  157. }
  158. }
  159. // WithHeader adds the headers to the HTTP request.
  160. func (f LicensePost) WithHeader(h map[string]string) func(*LicensePostRequest) {
  161. return func(r *LicensePostRequest) {
  162. if r.Header == nil {
  163. r.Header = make(http.Header)
  164. }
  165. for k, v := range h {
  166. r.Header.Add(k, v)
  167. }
  168. }
  169. }
  170. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  171. func (f LicensePost) WithOpaqueID(s string) func(*LicensePostRequest) {
  172. return func(r *LicensePostRequest) {
  173. if r.Header == nil {
  174. r.Header = make(http.Header)
  175. }
  176. r.Header.Set("X-Opaque-Id", s)
  177. }
  178. }