From 6d9e0a93cb328dced08286c9b2acca08706971b5 Mon Sep 17 00:00:00 2001 From: simitt Date: Fri, 25 Oct 2019 10:01:28 +0200 Subject: [PATCH 1/8] Add go-elasticsearch dependency Enable requests with the official go elasticsearch library. --- NOTICE.txt | 18 + elasticsearch/client.go | 146 ++ elasticsearch/client_test.go | 106 ++ .../elastic/go-elasticsearch/LICENSE | 201 +++ .../elastic/go-elasticsearch/v8/Dockerfile | 22 + .../elastic/go-elasticsearch/v8/LICENSE | 201 +++ .../elastic/go-elasticsearch/v8/Makefile | 396 ++++++ .../elastic/go-elasticsearch/v8/README.md | 344 +++++ .../elastic/go-elasticsearch/v8/doc.go | 49 + .../go-elasticsearch/v8/elasticsearch.go | 196 +++ .../go-elasticsearch/v8/esapi/api._.go | 761 +++++++++++ .../go-elasticsearch/v8/esapi/api.bulk.go | 328 +++++ .../v8/esapi/api.cat.aliases.go | 280 ++++ .../v8/esapi/api.cat.allocation.go | 307 +++++ .../v8/esapi/api.cat.count.go | 267 ++++ .../v8/esapi/api.cat.fielddata.go | 284 ++++ .../v8/esapi/api.cat.health.go | 276 ++++ .../go-elasticsearch/v8/esapi/api.cat.help.go | 211 +++ .../v8/esapi/api.cat.indices.go | 359 +++++ .../v8/esapi/api.cat.master.go | 277 ++++ .../v8/esapi/api.cat.nodeattrs.go | 277 ++++ .../v8/esapi/api.cat.nodes.go | 316 +++++ .../v8/esapi/api.cat.pending_tasks.go | 290 ++++ .../v8/esapi/api.cat.plugins.go | 277 ++++ .../v8/esapi/api.cat.recovery.go | 323 +++++ .../v8/esapi/api.cat.repositories.go | 277 ++++ .../v8/esapi/api.cat.segments.go | 280 ++++ .../v8/esapi/api.cat.shards.go | 320 +++++ .../v8/esapi/api.cat.snapshots.go | 307 +++++ .../v8/esapi/api.cat.tasks.go | 315 +++++ .../v8/esapi/api.cat.templates.go | 294 ++++ .../v8/esapi/api.cat.thread_pool.go | 308 +++++ .../v8/esapi/api.clear_scroll.go | 215 +++ .../esapi/api.cluster.allocation_explain.go | 226 ++++ .../v8/esapi/api.cluster.get_settings.go | 238 ++++ .../v8/esapi/api.cluster.health.go | 346 +++++ .../v8/esapi/api.cluster.pending_tasks.go | 213 +++ .../v8/esapi/api.cluster.put_settings.go | 232 ++++ .../v8/esapi/api.cluster.remote_info.go | 183 +++ .../v8/esapi/api.cluster.reroute.go | 279 ++++ .../v8/esapi/api.cluster.state.go | 321 +++++ .../v8/esapi/api.cluster.stats.go | 231 ++++ .../go-elasticsearch/v8/esapi/api.count.go | 397 ++++++ .../go-elasticsearch/v8/esapi/api.create.go | 294 ++++ .../go-elasticsearch/v8/esapi/api.delete.go | 298 +++++ .../v8/esapi/api.delete_by_query.go | 614 +++++++++ .../esapi/api.delete_by_query_rethrottle.go | 205 +++ .../v8/esapi/api.delete_script.go | 216 +++ .../go-elasticsearch/v8/esapi/api.exists.go | 323 +++++ .../v8/esapi/api.exists_source.go | 323 +++++ .../go-elasticsearch/v8/esapi/api.explain.go | 364 +++++ .../v8/esapi/api.field_caps.go | 265 ++++ .../go-elasticsearch/v8/esapi/api.get.go | 323 +++++ .../v8/esapi/api.get_script.go | 203 +++ .../v8/esapi/api.get_script_context.go | 181 +++ .../v8/esapi/api.get_source.go | 310 +++++ .../go-elasticsearch/v8/esapi/api.index.go | 345 +++++ .../v8/esapi/api.indices.analyze.go | 217 +++ .../v8/esapi/api.indices.clear_cache.go | 297 ++++ .../v8/esapi/api.indices.clone.go | 248 ++++ .../v8/esapi/api.indices.close.go | 269 ++++ .../v8/esapi/api.indices.create.go | 256 ++++ .../v8/esapi/api.indices.delete.go | 254 ++++ .../v8/esapi/api.indices.delete_alias.go | 220 +++ .../v8/esapi/api.indices.delete_template.go | 216 +++ .../v8/esapi/api.indices.exists.go | 266 ++++ .../v8/esapi/api.indices.exists_alias.go | 256 ++++ .../v8/esapi/api.indices.exists_template.go | 230 ++++ .../v8/esapi/api.indices.exists_type.go | 253 ++++ .../v8/esapi/api.indices.flush.go | 265 ++++ .../v8/esapi/api.indices.flush_synced.go | 241 ++++ .../v8/esapi/api.indices.forcemerge.go | 278 ++++ .../v8/esapi/api.indices.get.go | 293 ++++ .../v8/esapi/api.indices.get_alias.go | 266 ++++ .../v8/esapi/api.indices.get_field_mapping.go | 284 ++++ .../v8/esapi/api.indices.get_mapping.go | 266 ++++ .../v8/esapi/api.indices.get_settings.go | 306 +++++ .../v8/esapi/api.indices.get_template.go | 253 ++++ .../v8/esapi/api.indices.get_upgrade.go | 239 ++++ .../v8/esapi/api.indices.open.go | 269 ++++ .../v8/esapi/api.indices.put_alias.go | 235 ++++ .../v8/esapi/api.indices.put_mapping.go | 265 ++++ .../v8/esapi/api.indices.put_settings.go | 299 +++++ .../v8/esapi/api.indices.put_template.go | 276 ++++ .../v8/esapi/api.indices.recovery.go | 226 ++++ .../v8/esapi/api.indices.refresh.go | 239 ++++ .../v8/esapi/api.indices.rollover.go | 285 ++++ .../v8/esapi/api.indices.segments.go | 252 ++++ .../v8/esapi/api.indices.shard_stores.go | 252 ++++ .../v8/esapi/api.indices.shrink.go | 248 ++++ .../v8/esapi/api.indices.split.go | 248 ++++ .../v8/esapi/api.indices.stats.go | 344 +++++ .../v8/esapi/api.indices.update_aliases.go | 218 +++ .../v8/esapi/api.indices.upgrade.go | 265 ++++ .../v8/esapi/api.indices.validate_query.go | 386 ++++++ .../go-elasticsearch/v8/esapi/api.info.go | 175 +++ .../v8/esapi/api.ingest.delete_pipeline.go | 218 +++ .../v8/esapi/api.ingest.get_pipeline.go | 215 +++ .../v8/esapi/api.ingest.processor_grok.go | 183 +++ .../v8/esapi/api.ingest.put_pipeline.go | 225 ++++ .../v8/esapi/api.ingest.simulate.go | 224 ++++ .../go-elasticsearch/v8/esapi/api.mget.go | 311 +++++ .../go-elasticsearch/v8/esapi/api.msearch.go | 298 +++++ .../v8/esapi/api.msearch_template.go | 274 ++++ .../v8/esapi/api.mtermvectors.go | 371 +++++ .../v8/esapi/api.nodes.hot_threads.go | 283 ++++ .../v8/esapi/api.nodes.info.go | 240 ++++ .../esapi/api.nodes.reload_secure_settings.go | 215 +++ .../v8/esapi/api.nodes.stats.go | 333 +++++ .../v8/esapi/api.nodes.usage.go | 228 ++++ .../go-elasticsearch/v8/esapi/api.ping.go | 183 +++ .../v8/esapi/api.put_script.go | 241 ++++ .../v8/esapi/api.rank_eval.go | 246 ++++ .../go-elasticsearch/v8/esapi/api.reindex.go | 299 +++++ .../v8/esapi/api.reindex_rethrottle.go | 205 +++ .../v8/esapi/api.render_search_template.go | 215 +++ .../v8/esapi/api.scripts_painless_context.go | 151 +++ .../v8/esapi/api.scripts_painless_execute.go | 198 +++ .../go-elasticsearch/v8/esapi/api.scroll.go | 241 ++++ .../go-elasticsearch/v8/esapi/api.search.go | 763 +++++++++++ .../v8/esapi/api.search_shards.go | 278 ++++ .../v8/esapi/api.search_template.go | 379 ++++++ .../esapi/api.snapshot.cleanup_repository.go | 233 ++++ .../v8/esapi/api.snapshot.create.go | 235 ++++ .../esapi/api.snapshot.create_repository.go | 237 ++++ .../v8/esapi/api.snapshot.delete.go | 206 +++ .../esapi/api.snapshot.delete_repository.go | 216 +++ .../v8/esapi/api.snapshot.get.go | 233 ++++ .../v8/esapi/api.snapshot.get_repository.go | 227 ++++ .../v8/esapi/api.snapshot.restore.go | 237 ++++ .../v8/esapi/api.snapshot.status.go | 242 ++++ .../esapi/api.snapshot.verify_repository.go | 218 +++ .../v8/esapi/api.tasks.cancel.go | 240 ++++ .../v8/esapi/api.tasks.get.go | 217 +++ .../v8/esapi/api.tasks.list.go | 277 ++++ .../v8/esapi/api.termvectors.go | 361 +++++ .../go-elasticsearch/v8/esapi/api.update.go | 344 +++++ .../v8/esapi/api.update_by_query.go | 649 +++++++++ .../esapi/api.update_by_query_rethrottle.go | 205 +++ ...pi.xpack.ccr.delete_auto_follow_pattern.go | 190 +++ .../v8/esapi/api.xpack.ccr.follow.go | 211 +++ .../v8/esapi/api.xpack.ccr.follow_info.go | 190 +++ .../v8/esapi/api.xpack.ccr.follow_stats.go | 190 +++ .../v8/esapi/api.xpack.ccr.forget_follower.go | 197 +++ .../api.xpack.ccr.get_auto_follow_pattern.go | 200 +++ ...api.xpack.ccr.pause_auto_follow_pattern.go | 192 +++ .../v8/esapi/api.xpack.ccr.pause_follow.go | 190 +++ .../api.xpack.ccr.put_auto_follow_pattern.go | 197 +++ ...pi.xpack.ccr.resume_auto_follow_pattern.go | 192 +++ .../v8/esapi/api.xpack.ccr.resume_follow.go | 205 +++ .../v8/esapi/api.xpack.ccr.stats.go | 183 +++ .../v8/esapi/api.xpack.ccr.unfollow.go | 190 +++ ....data_frame.delete_data_frame_transform.go | 187 +++ ...ack.data_frame.get_data_frame_transform.go | 223 ++++ ...ta_frame.get_data_frame_transform_stats.go | 225 ++++ ...data_frame.preview_data_frame_transform.go | 172 +++ ...ack.data_frame.put_data_frame_transform.go | 194 +++ ...k.data_frame.start_data_frame_transform.go | 189 +++ ...ck.data_frame.stop_data_frame_transform.go | 216 +++ ....data_frame.update_data_frame_transform.go | 196 +++ ...e_transform_deprecated.delete_transform.go | 205 +++ ...rame_transform_deprecated.get_transform.go | 241 ++++ ...ransform_deprecated.get_transform_stats.go | 233 ++++ ..._transform_deprecated.preview_transform.go | 190 +++ ...rame_transform_deprecated.put_transform.go | 212 +++ ...me_transform_deprecated.start_transform.go | 207 +++ ...ame_transform_deprecated.stop_transform.go | 234 ++++ ...e_transform_deprecated.update_transform.go | 214 +++ .../esapi/api.xpack.enrich.delete_policy.go | 190 +++ .../esapi/api.xpack.enrich.execute_policy.go | 207 +++ .../v8/esapi/api.xpack.enrich.get_policy.go | 200 +++ .../v8/esapi/api.xpack.enrich.put_policy.go | 197 +++ .../v8/esapi/api.xpack.enrich.stats.go | 183 +++ .../v8/esapi/api.xpack.graph.explore.go | 233 ++++ .../esapi/api.xpack.ilm.delete_lifecycle.go | 190 +++ .../esapi/api.xpack.ilm.explain_lifecycle.go | 218 +++ .../v8/esapi/api.xpack.ilm.get_lifecycle.go | 200 +++ .../v8/esapi/api.xpack.ilm.get_status.go | 183 +++ .../v8/esapi/api.xpack.ilm.move_to_step.go | 205 +++ .../v8/esapi/api.xpack.ilm.put_lifecycle.go | 205 +++ .../v8/esapi/api.xpack.ilm.remove_policy.go | 190 +++ .../v8/esapi/api.xpack.ilm.retry.go | 190 +++ .../v8/esapi/api.xpack.ilm.start.go | 183 +++ .../v8/esapi/api.xpack.ilm.stop.go | 183 +++ .../v8/esapi/api.xpack.indices.freeze.go | 269 ++++ ...i.xpack.indices.reload_search_analyzers.go | 229 ++++ .../v8/esapi/api.xpack.indices.unfreeze.go | 269 ++++ .../v8/esapi/api.xpack.license.delete.go | 183 +++ .../v8/esapi/api.xpack.license.get.go | 198 +++ .../api.xpack.license.get_basic_status.go | 183 +++ .../api.xpack.license.get_trial_status.go | 183 +++ .../v8/esapi/api.xpack.license.post.go | 213 +++ .../api.xpack.license.post_start_basic.go | 198 +++ .../api.xpack.license.post_start_trial.go | 211 +++ .../esapi/api.xpack.migration.deprecations.go | 200 +++ .../v8/esapi/api.xpack.ml.close_job.go | 249 ++++ .../v8/esapi/api.xpack.ml.delete_calendar.go | 188 +++ .../api.xpack.ml.delete_calendar_event.go | 193 +++ .../esapi/api.xpack.ml.delete_calendar_job.go | 193 +++ ...pi.xpack.ml.delete_data_frame_analytics.go | 192 +++ .../v8/esapi/api.xpack.ml.delete_datafeed.go | 205 +++ .../esapi/api.xpack.ml.delete_expired_data.go | 181 +++ .../v8/esapi/api.xpack.ml.delete_filter.go | 188 +++ .../v8/esapi/api.xpack.ml.delete_forecast.go | 234 ++++ .../v8/esapi/api.xpack.ml.delete_job.go | 218 +++ .../api.xpack.ml.delete_model_snapshot.go | 195 +++ .../api.xpack.ml.estimate_memory_usage.go | 190 +++ .../esapi/api.xpack.ml.evaluate_data_frame.go | 190 +++ .../esapi/api.xpack.ml.find_file_structure.go | 375 ++++++ .../v8/esapi/api.xpack.ml.flush_job.go | 274 ++++ .../v8/esapi/api.xpack.ml.forecast.go | 218 +++ .../v8/esapi/api.xpack.ml.get_buckets.go | 342 +++++ .../esapi/api.xpack.ml.get_calendar_events.go | 258 ++++ .../v8/esapi/api.xpack.ml.get_calendars.go | 241 ++++ .../v8/esapi/api.xpack.ml.get_categories.go | 252 ++++ .../api.xpack.ml.get_data_frame_analytics.go | 243 ++++ ...xpack.ml.get_data_frame_analytics_stats.go | 245 ++++ .../esapi/api.xpack.ml.get_datafeed_stats.go | 217 +++ .../v8/esapi/api.xpack.ml.get_datafeeds.go | 215 +++ .../v8/esapi/api.xpack.ml.get_filters.go | 226 ++++ .../v8/esapi/api.xpack.ml.get_influencers.go | 316 +++++ .../v8/esapi/api.xpack.ml.get_job_stats.go | 217 +++ .../v8/esapi/api.xpack.ml.get_jobs.go | 215 +++ .../esapi/api.xpack.ml.get_model_snapshots.go | 301 +++++ .../esapi/api.xpack.ml.get_overall_buckets.go | 303 +++++ .../v8/esapi/api.xpack.ml.get_records.go | 316 +++++ .../v8/esapi/api.xpack.ml.info.go | 181 +++ .../v8/esapi/api.xpack.ml.open_job.go | 192 +++ .../api.xpack.ml.post_calendar_events.go | 197 +++ .../v8/esapi/api.xpack.ml.post_data.go | 226 ++++ .../v8/esapi/api.xpack.ml.preview_datafeed.go | 192 +++ .../v8/esapi/api.xpack.ml.put_calendar.go | 203 +++ .../v8/esapi/api.xpack.ml.put_calendar_job.go | 193 +++ .../api.xpack.ml.put_data_frame_analytics.go | 199 +++ .../v8/esapi/api.xpack.ml.put_datafeed.go | 197 +++ .../v8/esapi/api.xpack.ml.put_filter.go | 195 +++ .../v8/esapi/api.xpack.ml.put_job.go | 197 +++ .../api.xpack.ml.revert_model_snapshot.go | 227 ++++ .../v8/esapi/api.xpack.ml.set_upgrade_mode.go | 212 +++ ...api.xpack.ml.start_data_frame_analytics.go | 224 ++++ .../v8/esapi/api.xpack.ml.start_datafeed.go | 248 ++++ .../api.xpack.ml.stop_data_frame_analytics.go | 251 ++++ .../v8/esapi/api.xpack.ml.stop_datafeed.go | 234 ++++ .../v8/esapi/api.xpack.ml.update_datafeed.go | 199 +++ .../v8/esapi/api.xpack.ml.update_filter.go | 197 +++ .../v8/esapi/api.xpack.ml.update_job.go | 199 +++ .../api.xpack.ml.update_model_snapshot.go | 204 +++ .../v8/esapi/api.xpack.ml.validate.go | 188 +++ .../esapi/api.xpack.ml.validate_detector.go | 188 +++ .../v8/esapi/api.xpack.monitoring.bulk.go | 247 ++++ .../v8/esapi/api.xpack.rollup.delete_job.go | 188 +++ .../v8/esapi/api.xpack.rollup.get_jobs.go | 198 +++ .../esapi/api.xpack.rollup.get_rollup_caps.go | 198 +++ .../api.xpack.rollup.get_rollup_index_caps.go | 188 +++ .../v8/esapi/api.xpack.rollup.put_job.go | 195 +++ .../esapi/api.xpack.rollup.rollup_search.go | 234 ++++ .../v8/esapi/api.xpack.rollup.start_job.go | 190 +++ .../v8/esapi/api.xpack.rollup.stop_job.go | 219 +++ .../esapi/api.xpack.security.authenticate.go | 183 +++ .../api.xpack.security.change_password.go | 223 ++++ .../api.xpack.security.clear_cached_realms.go | 206 +++ .../api.xpack.security.clear_cached_roles.go | 192 +++ .../api.xpack.security.create_api_key.go | 204 +++ .../api.xpack.security.delete_privileges.go | 205 +++ .../esapi/api.xpack.security.delete_role.go | 204 +++ .../api.xpack.security.delete_role_mapping.go | 204 +++ .../esapi/api.xpack.security.delete_user.go | 204 +++ .../esapi/api.xpack.security.disable_user.go | 206 +++ .../esapi/api.xpack.security.enable_user.go | 206 +++ .../esapi/api.xpack.security.get_api_key.go | 236 ++++ ...i.xpack.security.get_builtin_privileges.go | 183 +++ .../api.xpack.security.get_privileges.go | 213 +++ .../v8/esapi/api.xpack.security.get_role.go | 200 +++ .../api.xpack.security.get_role_mapping.go | 200 +++ .../v8/esapi/api.xpack.security.get_token.go | 190 +++ .../v8/esapi/api.xpack.security.get_user.go | 200 +++ .../api.xpack.security.get_user_privileges.go | 183 +++ .../api.xpack.security.has_privileges.go | 209 +++ .../api.xpack.security.invalidate_api_key.go | 190 +++ .../api.xpack.security.invalidate_token.go | 190 +++ .../api.xpack.security.put_privileges.go | 202 +++ .../v8/esapi/api.xpack.security.put_role.go | 211 +++ .../api.xpack.security.put_role_mapping.go | 211 +++ .../v8/esapi/api.xpack.security.put_user.go | 211 +++ .../esapi/api.xpack.slm.delete_lifecycle.go | 190 +++ .../esapi/api.xpack.slm.execute_lifecycle.go | 192 +++ .../esapi/api.xpack.slm.execute_retention.go | 183 +++ .../v8/esapi/api.xpack.slm.get_lifecycle.go | 200 +++ .../v8/esapi/api.xpack.slm.get_stats.go | 183 +++ .../v8/esapi/api.xpack.slm.put_lifecycle.go | 205 +++ .../v8/esapi/api.xpack.sql.clear_cursor.go | 188 +++ .../v8/esapi/api.xpack.sql.query.go | 202 +++ .../v8/esapi/api.xpack.sql.translate.go | 188 +++ .../v8/esapi/api.xpack.ssl.certificates.go | 183 +++ .../api.xpack.transform.delete_transform.go | 203 +++ .../api.xpack.transform.get_transform.go | 239 ++++ ...api.xpack.transform.get_transform_stats.go | 231 ++++ .../api.xpack.transform.preview_transform.go | 190 +++ .../api.xpack.transform.put_transform.go | 210 +++ .../api.xpack.transform.start_transform.go | 205 +++ .../api.xpack.transform.stop_transform.go | 232 ++++ .../api.xpack.transform.update_transform.go | 212 +++ .../v8/esapi/api.xpack.watcher.ack_watch.go | 205 +++ .../esapi/api.xpack.watcher.activate_watch.go | 192 +++ .../api.xpack.watcher.deactivate_watch.go | 192 +++ .../esapi/api.xpack.watcher.delete_watch.go | 190 +++ .../esapi/api.xpack.watcher.execute_watch.go | 232 ++++ .../v8/esapi/api.xpack.watcher.get_watch.go | 190 +++ .../v8/esapi/api.xpack.watcher.put_watch.go | 259 ++++ .../v8/esapi/api.xpack.watcher.start.go | 183 +++ .../v8/esapi/api.xpack.watcher.stats.go | 219 +++ .../v8/esapi/api.xpack.watcher.stop.go | 183 +++ .../v8/esapi/api.xpack.xpack.info.go | 197 +++ .../v8/esapi/api.xpack.xpack.usage.go | 196 +++ .../elastic/go-elasticsearch/v8/esapi/doc.go | 95 ++ .../go-elasticsearch/v8/esapi/esapi.go | 49 + .../v8/esapi/esapi.request.go | 31 + .../v8/esapi/esapi.response.go | 80 ++ .../go-elasticsearch/v8/esapi/test/go.mod | 11 + .../go-elasticsearch/v8/estransport/doc.go | 28 + .../v8/estransport/estransport.go | 320 +++++ .../go-elasticsearch/v8/estransport/logger.go | 412 ++++++ .../v8/estransport/selector.go | 58 + .../elastic/go-elasticsearch/v8/esutil/doc.go | 5 + .../go-elasticsearch/v8/esutil/json_reader.go | 82 ++ .../elastic/go-elasticsearch/v8/go.mod | 3 + .../elastic/go-elasticsearch/v8/go.sum | 0 .../cmd/generate/commands/commands.go | 34 + .../generate/commands/gensource/command.go | 280 ++++ .../cmd/generate/commands/gensource/debug.go | 95 ++ .../commands/gensource/descriptions.go | 646 +++++++++ .../generate/commands/gensource/generator.go | 786 +++++++++++ .../cmd/generate/commands/gensource/model.go | 441 ++++++ .../generate/commands/gensource/overrides.go | 109 ++ .../generate/commands/genstruct/command.go | 342 +++++ .../cmd/generate/commands/gentests/command.go | 296 ++++ .../cmd/generate/commands/gentests/debug.go | 100 ++ .../generate/commands/gentests/generator.go | 1189 +++++++++++++++++ .../cmd/generate/commands/gentests/model.go | 897 +++++++++++++ .../cmd/generate/commands/gentests/patches.go | 54 + .../cmd/generate/commands/gentests/skips.go | 218 +++ .../v8/internal/cmd/generate/go.mod | 16 + .../v8/internal/cmd/generate/go.sum | 34 + .../v8/internal/cmd/generate/main.go | 16 + .../internal/cmd/generate/utils/chromatize.go | 41 + .../v8/internal/cmd/generate/utils/debug.go | 82 ++ .../v8/internal/cmd/generate/utils/map.go | 29 + .../internal/cmd/generate/utils/metadata.go | 110 ++ .../v8/internal/cmd/generate/utils/naming.go | 126 ++ .../v8/internal/cmd/generate/utils/strings.go | 19 + .../internal/cmd/generate/utils/terminal.go | 51 + .../v8/internal/version/version.go | 9 + vendor/vendor.json | 7 + 353 files changed, 81396 insertions(+) create mode 100644 elasticsearch/client.go create mode 100644 elasticsearch/client_test.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/LICENSE create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/Dockerfile create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/LICENSE create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/Makefile create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/README.md create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/doc.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/elasticsearch.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api._.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.bulk.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.aliases.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.allocation.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.count.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.fielddata.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.health.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.help.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.indices.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.master.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.nodeattrs.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.nodes.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.pending_tasks.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.plugins.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.recovery.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.repositories.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.segments.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.shards.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.snapshots.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.tasks.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.templates.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.thread_pool.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.clear_scroll.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.allocation_explain.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.get_settings.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.health.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.pending_tasks.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.put_settings.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.remote_info.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.reroute.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.state.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.stats.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.count.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.create.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.delete.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.delete_by_query.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.delete_by_query_rethrottle.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.delete_script.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.exists.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.exists_source.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.explain.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.field_caps.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.get.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.get_script.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.get_script_context.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.get_source.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.index.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.analyze.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.clear_cache.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.clone.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.close.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.create.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.delete.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.delete_alias.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.delete_template.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.exists.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.exists_alias.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.exists_template.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.exists_type.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.flush.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.flush_synced.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.forcemerge.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get_alias.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get_field_mapping.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get_mapping.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get_settings.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get_template.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get_upgrade.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.open.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.put_alias.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.put_mapping.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.put_settings.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.put_template.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.recovery.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.refresh.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.rollover.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.segments.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.shard_stores.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.shrink.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.split.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.stats.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.update_aliases.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.upgrade.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.validate_query.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.info.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.ingest.delete_pipeline.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.ingest.get_pipeline.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.ingest.processor_grok.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.ingest.put_pipeline.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.ingest.simulate.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.mget.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.msearch.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.msearch_template.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.mtermvectors.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.nodes.hot_threads.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.nodes.info.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.nodes.reload_secure_settings.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.nodes.stats.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.nodes.usage.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.ping.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.put_script.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.rank_eval.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.reindex.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.reindex_rethrottle.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.render_search_template.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.scripts_painless_context.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.scripts_painless_execute.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.scroll.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.search.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.search_shards.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.search_template.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.cleanup_repository.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.create.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.create_repository.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.delete.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.delete_repository.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.get.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.get_repository.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.restore.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.status.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.verify_repository.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.tasks.cancel.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.tasks.get.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.tasks.list.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.termvectors.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.update.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.update_by_query.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.update_by_query_rethrottle.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.delete_auto_follow_pattern.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.follow.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.follow_info.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.follow_stats.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.forget_follower.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.get_auto_follow_pattern.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.pause_auto_follow_pattern.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.pause_follow.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.put_auto_follow_pattern.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.resume_auto_follow_pattern.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.resume_follow.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.stats.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.unfollow.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.delete_data_frame_transform.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.get_data_frame_transform.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.get_data_frame_transform_stats.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.preview_data_frame_transform.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.put_data_frame_transform.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.start_data_frame_transform.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.stop_data_frame_transform.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.update_data_frame_transform.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.delete_transform.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.get_transform.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.get_transform_stats.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.preview_transform.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.put_transform.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.start_transform.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.stop_transform.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.update_transform.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.enrich.delete_policy.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.enrich.execute_policy.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.enrich.get_policy.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.enrich.put_policy.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.enrich.stats.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.graph.explore.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.delete_lifecycle.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.explain_lifecycle.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.get_lifecycle.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.get_status.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.move_to_step.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.put_lifecycle.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.remove_policy.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.retry.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.start.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.stop.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.indices.freeze.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.indices.reload_search_analyzers.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.indices.unfreeze.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.delete.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.get.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.get_basic_status.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.get_trial_status.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.post.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.post_start_basic.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.post_start_trial.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.migration.deprecations.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.close_job.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_calendar.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_calendar_event.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_calendar_job.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_data_frame_analytics.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_datafeed.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_expired_data.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_filter.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_forecast.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_job.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_model_snapshot.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.estimate_memory_usage.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.evaluate_data_frame.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.find_file_structure.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.flush_job.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.forecast.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_buckets.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_calendar_events.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_calendars.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_categories.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_data_frame_analytics.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_data_frame_analytics_stats.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_datafeed_stats.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_datafeeds.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_filters.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_influencers.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_job_stats.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_jobs.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_model_snapshots.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_overall_buckets.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_records.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.info.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.open_job.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.post_calendar_events.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.post_data.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.preview_datafeed.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.put_calendar.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.put_calendar_job.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.put_data_frame_analytics.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.put_datafeed.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.put_filter.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.put_job.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.revert_model_snapshot.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.set_upgrade_mode.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.start_data_frame_analytics.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.start_datafeed.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.stop_data_frame_analytics.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.stop_datafeed.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.update_datafeed.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.update_filter.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.update_job.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.update_model_snapshot.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.validate.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.validate_detector.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.monitoring.bulk.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.delete_job.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.get_jobs.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.get_rollup_caps.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.get_rollup_index_caps.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.put_job.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.rollup_search.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.start_job.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.stop_job.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.authenticate.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.change_password.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.clear_cached_realms.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.clear_cached_roles.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.create_api_key.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.delete_privileges.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.delete_role.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.delete_role_mapping.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.delete_user.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.disable_user.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.enable_user.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_api_key.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_builtin_privileges.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_privileges.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_role.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_role_mapping.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_token.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_user.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_user_privileges.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.has_privileges.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.invalidate_api_key.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.invalidate_token.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.put_privileges.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.put_role.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.put_role_mapping.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.put_user.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.delete_lifecycle.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.execute_lifecycle.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.execute_retention.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.get_lifecycle.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.get_stats.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.put_lifecycle.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.sql.clear_cursor.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.sql.query.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.sql.translate.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ssl.certificates.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.delete_transform.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.get_transform.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.get_transform_stats.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.preview_transform.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.put_transform.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.start_transform.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.stop_transform.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.update_transform.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.ack_watch.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.activate_watch.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.deactivate_watch.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.delete_watch.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.execute_watch.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.get_watch.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.put_watch.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.start.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.stats.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.stop.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.xpack.info.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.xpack.usage.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/doc.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/esapi.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/esapi.request.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/esapi.response.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esapi/test/go.mod create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/estransport/doc.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/estransport/estransport.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/estransport/logger.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/estransport/selector.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esutil/doc.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/esutil/json_reader.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/go.mod create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/go.sum create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/commands.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource/command.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource/debug.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource/descriptions.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource/generator.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource/model.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource/overrides.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/genstruct/command.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/command.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/debug.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/generator.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/model.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/patches.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/skips.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/go.mod create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/go.sum create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/main.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/chromatize.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/debug.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/map.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/metadata.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/naming.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/strings.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/terminal.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/internal/version/version.go diff --git a/NOTICE.txt b/NOTICE.txt index 3cf8f8cf093..ea69ba1920e 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -511,6 +511,24 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. +-------------------------------------------------------------------- +Dependency: github.com/elastic/go-elasticsearch +Revision: 8efb73c32e7fa9d1e2e905d9ec112d51382cabf4 +License type (autodetected): Apache-2.0 +./vendor/github.com/elastic/go-elasticsearch/LICENSE: +-------------------------------------------------------------------- +Apache License 2.0 + + +-------------------------------------------------------------------- +Dependency: github.com/elastic/go-elasticsearch/v8 +Revision: 8efb73c32e7fa9d1e2e905d9ec112d51382cabf4 +License type (autodetected): Apache-2.0 +./vendor/github.com/elastic/go-elasticsearch/v8/LICENSE: +-------------------------------------------------------------------- +Apache License 2.0 + + -------------------------------------------------------------------- Dependency: github.com/elastic/go-lumber Revision: 616041e345fc33c97bc0eb0fa6b388aa07bca3e1 diff --git a/elasticsearch/client.go b/elasticsearch/client.go new file mode 100644 index 00000000000..ed6a381acf0 --- /dev/null +++ b/elasticsearch/client.go @@ -0,0 +1,146 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package elasticsearch + +import ( + "net/http" + "net/url" + "strings" + "time" + + "github.com/pkg/errors" + + "github.com/elastic/beats/libbeat/common" + "github.com/elastic/beats/libbeat/common/transport/tlscommon" + "github.com/elastic/beats/libbeat/outputs/transport" + + goelasticsearch "github.com/elastic/go-elasticsearch/v8" +) + +const ( + prefixHTTP = "http" + prefixHTTPSchema = prefixHTTP + "://" + esDefaultPort = 9200 +) + +var ( + errInvalidHosts = errors.New("`Hosts` must at least contain one hostname") + errConfigMissing = errors.New("config missing") +) + +// Config holds all configurable fields that are used to create a Client +type Config struct { + Hosts Hosts `config:"hosts" validate:"required"` + Protocol string `config:"protocol"` + Path string `config:"path"` + ProxyURL string `config:"proxy_url"` + ProxyDisable bool `config:"proxy_disable"` + Timeout time.Duration `config:"timeout"` + TLS *tlscommon.Config `config:"ssl"` +} + +// Hosts is an array of host strings and needs to have at least one entry +type Hosts []string + +// NewClient creates an elasticsearch client from given config +func NewClient(config *Config) (*goelasticsearch.Client, error) { + if config == nil { + return nil, errConfigMissing + } + + //following logic is inspired by libbeat functionality + + var err error + proxy, err := httpProxyURL(config) + if err != nil { + return nil, err + } + + addresses, err := addresses(config) + if err != nil { + return nil, err + } + + dialer, tlsDialer, err := dialer(config) + if err != nil { + return nil, err + } + + return goelasticsearch.NewClient(goelasticsearch.Config{ + Addresses: addresses, + Transport: &http.Transport{ + Proxy: proxy, + Dial: dialer.Dial, + DialTLS: tlsDialer.Dial, + }, + }) +} + +// Validate ensures Hosts instance has at least one entry +func (h Hosts) Validate() error { + if len(h) == 0 { + return errInvalidHosts + } + return nil +} + +func httpProxyURL(cfg *Config) (func(*http.Request) (*url.URL, error), error) { + if cfg.ProxyDisable { + return nil, nil + } + + if cfg.ProxyURL == "" { + return http.ProxyFromEnvironment, nil + } + + proxyStr := cfg.ProxyURL + if !strings.HasPrefix(proxyStr, prefixHTTP) { + proxyStr = prefixHTTPSchema + proxyStr + } + u, err := url.Parse(proxyStr) + if err != nil { + return nil, err + } + return http.ProxyURL(u), nil +} + +func addresses(cfg *Config) ([]string, error) { + var addresses []string + for _, host := range cfg.Hosts { + address, err := common.MakeURL(cfg.Protocol, cfg.Path, host, esDefaultPort) + if err != nil { + return nil, err + } + addresses = append(addresses, address) + } + return addresses, nil +} + +func dialer(cfg *Config) (transport.Dialer, transport.Dialer, error) { + var tlsConfig *tlscommon.TLSConfig + var err error + if cfg.TLS.IsEnabled() { + if tlsConfig, err = tlscommon.LoadTLSConfig(cfg.TLS); err != nil { + return nil, nil, err + } + } + + dialer := transport.NetDialer(cfg.Timeout) + tlsDialer, err := transport.TLSDialer(dialer, tlsConfig, cfg.Timeout) + return dialer, tlsDialer, err +} diff --git a/elasticsearch/client_test.go b/elasticsearch/client_test.go new file mode 100644 index 00000000000..28d660dab73 --- /dev/null +++ b/elasticsearch/client_test.go @@ -0,0 +1,106 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package elasticsearch + +import ( + "net/http" + "net/http/httptest" + "os" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestClient(t *testing.T) { + t.Run("no config", func(t *testing.T) { + goESClient, err := NewClient(nil) + assert.Error(t, err) + assert.Nil(t, goESClient) + }) + + t.Run("valid config", func(t *testing.T) { + cfg := Config{Hosts: Hosts{"localhost:9200", "localhost:9201"}} + goESClient, err := NewClient(&cfg) + require.NoError(t, err) + assert.NotNil(t, goESClient) + }) +} + +func TestClient_httpProxyUrl(t *testing.T) { + t.Run("proxy disabled", func(t *testing.T) { + proxy, err := httpProxyURL(&Config{ProxyDisable: true}) + require.Nil(t, err) + assert.Nil(t, proxy) + }) + + t.Run("proxy from ENV", func(t *testing.T) { + // set env var for http proxy + os.Setenv("HTTP_PROXY", "proxy") + + // create proxy function + proxy, err := httpProxyURL(&Config{}) + require.Nil(t, err) + // ensure proxy function is called and check url + url, err := proxy(httptest.NewRequest(http.MethodGet, "http://example.com", nil)) + require.Nil(t, err) + assert.Equal(t, "http://proxy", url.String()) + }) + + t.Run("proxy from URL", func(t *testing.T) { + // set env var for http proxy + os.Setenv("HTTP_PROXY", "proxy") + + // create proxy function from URL without `http` prefix + proxy, err := httpProxyURL(&Config{ProxyURL: "foo"}) + require.Nil(t, err) + // ensure proxy function is called and check url + url, err := proxy(httptest.NewRequest(http.MethodGet, "http://example.com/", nil)) + require.Nil(t, err) + assert.Equal(t, "http://foo", url.String()) + + // create proxy function from URL with `http` prefix + proxy, err = httpProxyURL(&Config{ProxyURL: "http://foo"}) + require.Nil(t, err) + // ensure proxy function is called and check url + url, err = proxy(httptest.NewRequest(http.MethodGet, "http://example.com/", nil)) + require.Nil(t, err) + assert.Equal(t, "http://foo", url.String()) + }) +} + +func TestClient_addresses(t *testing.T) { + t.Run("no protocol and path", func(t *testing.T) { + addresses, err := addresses(&Config{Hosts: []string{ + "http://localhost", "http://localhost:9300", "localhost", "192.0.0.1", "192.0.0.2:8080"}}) + require.NoError(t, err) + expected := []string{"http://localhost:9200", "http://localhost:9300", + "http://localhost:9200", "http://192.0.0.1:9200", "http://192.0.0.2:8080"} + assert.ElementsMatch(t, expected, addresses) + }) + + t.Run("with protocol and path", func(t *testing.T) { + addresses, err := addresses(&Config{Protocol: "https", Path: "xyz", + Hosts: []string{"http://localhost", "http://localhost:9300/abc", + "localhost/abc", "192.0.0.2:8080"}}) + require.NoError(t, err) + expected := []string{"http://localhost:9200/xyz", "http://localhost:9300/abc", + "https://localhost:9200/abc", "https://192.0.0.2:8080/xyz"} + assert.ElementsMatch(t, expected, addresses) + }) +} diff --git a/vendor/github.com/elastic/go-elasticsearch/LICENSE b/vendor/github.com/elastic/go-elasticsearch/LICENSE new file mode 100644 index 00000000000..b1a731fb5a3 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2018 Elasticsearch BV + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/Dockerfile b/vendor/github.com/elastic/go-elasticsearch/v8/Dockerfile new file mode 100644 index 00000000000..acf4a79e340 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/Dockerfile @@ -0,0 +1,22 @@ +# $ docker build --file Dockerfile --tag elastic/go-elasticsearch . +# +# $ docker run -it --network elasticsearch --volume $PWD/tmp:/tmp:rw --rm elastic/go-elasticsearch gotestsum --format=short-verbose --junitfile=/tmp/integration-junit.xml -- --cover --coverprofile=/tmp/integration-coverage.out --tags='integration' -v ./... +# + +ARG VERSION=1-alpine +FROM golang:${VERSION} + +RUN apk add --no-cache --quiet make curl git jq unzip tree && \ + go get -u golang.org/x/lint/golint && \ + curl -sSL --retry 3 --retry-connrefused https://github.com/gotestyourself/gotestsum/releases/download/v0.3.5/gotestsum_0.3.5_linux_amd64.tar.gz | tar -xz -C /usr/local/bin gotestsum + +VOLUME ["/tmp"] + +ENV CGO_ENABLED=0 +ENV TERM xterm-256color + +WORKDIR /go-elasticsearch +COPY . . + +RUN go mod download && go mod vendor && \ + cd internal/cmd/generate && go mod download && go mod vendor diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/LICENSE b/vendor/github.com/elastic/go-elasticsearch/v8/LICENSE new file mode 100644 index 00000000000..b1a731fb5a3 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2018 Elasticsearch BV + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/Makefile b/vendor/github.com/elastic/go-elasticsearch/v8/Makefile new file mode 100644 index 00000000000..6d09e6bfe47 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/Makefile @@ -0,0 +1,396 @@ +##@ Test +test-unit: ## Run unit tests + @echo "\033[2m→ Running unit tests...\033[0m" +ifdef race + $(eval testunitargs += "-race") +endif + $(eval testunitargs += "-cover" "-coverprofile=tmp/unit.cov" "./...") + @mkdir -p tmp + @if which gotestsum > /dev/null 2>&1 ; then \ + echo "gotestsum --format=short-verbose --junitfile=tmp/unit-report.xml --" $(testunitargs); \ + gotestsum --format=short-verbose --junitfile=tmp/unit-report.xml -- $(testunitargs); \ + else \ + echo "go test -v" $(testunitargs); \ + go test -v $(testunitargs); \ + fi; +test: test-unit + +test-integ: ## Run integration tests + @echo "\033[2m→ Running integration tests...\033[0m" + $(eval testintegtags += "integration") +ifdef multinode + $(eval testintegtags += "multinode") +endif +ifdef race + $(eval testintegargs += "-race") +endif + $(eval testintegargs += "-cover" "-coverprofile=tmp/integration-client.cov" "-tags='$(testintegtags)'" "-timeout=1h") + @mkdir -p tmp + @if which gotestsum > /dev/null 2>&1 ; then \ + echo "gotestsum --format=short-verbose --junitfile=tmp/integration-report.xml --" $(testintegargs); \ + gotestsum --format=short-verbose --junitfile=tmp/integration-report.xml -- $(testintegargs) "."; \ + gotestsum --format=short-verbose --junitfile=tmp/integration-report.xml -- $(testintegargs) "./estransport" "./esapi" "./esutil"; \ + else \ + echo "go test -v" $(testintegargs) "."; \ + go test -v $(testintegargs) "./estransport" "./esapi" "./esutil"; \ + fi; + +test-api: ## Run generated API integration tests + @mkdir -p tmp +ifdef race + $(eval testapiargs += "-race") +endif + $(eval testapiargs += "-cover" "-coverpkg=github.com/elastic/go-elasticsearch/v8/esapi" "-coverprofile=$(PWD)/tmp/integration-api.cov" "-tags='integration'" "-timeout=1h") +ifdef flavor +else + $(eval flavor='core') +endif + @echo "\033[2m→ Running API integration tests for [$(flavor)]...\033[0m" +ifeq ($(flavor), xpack) + @{ \ + set -e ; \ + trap "git checkout $(PWD)/esapi/test/go.mod" SIGINT SIGTERM EXIT; \ + export ELASTICSEARCH_URL='https://elastic:elastic@localhost:9200' && \ + if which gotestsum > /dev/null 2>&1 ; then \ + cd esapi/test && \ + gotestsum --format=short-verbose --junitfile=$(PWD)/tmp/integration-api-report.xml -- $(testapiargs) $(PWD)/esapi/test/xpack/*_test.go && \ + gotestsum --format=short-verbose --junitfile=$(PWD)/tmp/integration-api-report.xml -- $(testapiargs) $(PWD)/esapi/test/xpack/ml/*_test.go && \ + gotestsum --format=short-verbose --junitfile=$(PWD)/tmp/integration-api-report.xml -- $(testapiargs) $(PWD)/esapi/test/xpack/ml-crud/*_test.go; \ + else \ + echo "go test -v" $(testapiargs); \ + cd esapi/test && \ + go test -v $(testapiargs) $(PWD)/esapi/test/xpack/*_test.go && \ + go test -v $(testapiargs) $(PWD)/esapi/test/xpack/ml/*_test.go && \ + go test -v $(testapiargs) $(PWD)/esapi/test/xpack/ml-crud/*_test.go; \ + fi; \ + } +else + $(eval testapiargs += $(PWD)/esapi/test/*_test.go) + @{ \ + set -e ; \ + trap "git checkout $(PWD)/esapi/test/go.mod" SIGINT SIGTERM EXIT; \ + if which gotestsum > /dev/null 2>&1 ; then \ + cd esapi/test && gotestsum --format=short-verbose --junitfile=$(PWD)/tmp/integration-api-report.xml -- $(testapiargs); \ + else \ + echo "go test -v" $(testapiargs); \ + cd esapi/test && go test -v $(testapiargs); \ + fi; \ + } +endif + +test-bench: ## Run benchmarks + @echo "\033[2m→ Running benchmarks...\033[0m" + go test -run=none -bench=. -benchmem ./... + +test-examples: ## Execute the _examples + @echo "\033[2m→ Testing the examples...\033[0m" + @{ \ + set -e ; \ + trap "git checkout _examples/**/go.mod" SIGINT SIGTERM EXIT; \ + for f in _examples/*.go; do \ + echo "\033[2m────────────────────────────────────────────────────────────────────────────────"; \ + echo "\033[1m$$f\033[0m"; \ + echo "\033[2m────────────────────────────────────────────────────────────────────────────────\033[0m"; \ + (go run $$f && true) || \ + ( \ + echo "\033[31m────────────────────────────────────────────────────────────────────────────────\033[0m"; \ + echo "\033[31;1m⨯ ERROR\033[0m"; \ + false; \ + ); \ + done; \ + \ + for f in _examples/*/; do \ + echo "\033[2m────────────────────────────────────────────────────────────────────────────────\033[0m"; \ + echo "\033[1m$$f\033[0m"; \ + echo "\033[2m────────────────────────────────────────────────────────────────────────────────\033[0m"; \ + (cd $$f && make test && true) || \ + ( \ + echo "\033[31m────────────────────────────────────────────────────────────────────────────────\033[0m"; \ + echo "\033[31;1m⨯ ERROR\033[0m"; \ + false; \ + ); \ + done; \ + echo "\033[32m────────────────────────────────────────────────────────────────────────────────\033[0m"; \ + \ + echo "\033[32;1mSUCCESS\033[0m"; \ + } + +test-coverage: ## Generate test coverage report + @echo "\033[2m→ Generating test coverage report...\033[0m" + @go tool cover -html=tmp/unit.cov -o tmp/coverage.html + @go tool cover -func=tmp/unit.cov | 'grep' -v 'esapi/api\.' | sed 's/github.com\/elastic\/go-elasticsearch\///g' + @echo "--------------------------------------------------------------------------------\nopen tmp/coverage.html\n" + +##@ Development +lint: ## Run lint on the package + @echo "\033[2m→ Running lint...\033[0m" + go vet github.com/elastic/go-elasticsearch/... + go list github.com/elastic/go-elasticsearch/... | 'grep' -v internal | xargs golint -set_exit_status + +apidiff: ## Display API incompabilities + @if ! command -v apidiff > /dev/null; then \ + echo "\033[31;1mERROR: apidiff not installed\033[0m"; \ + echo "go get -u github.com/go-modules-by-example/apidiff"; \ + echo "\033[2m→ https://github.com/go-modules-by-example/index/blob/master/019_apidiff/README.md\033[0m\n"; \ + false; \ + fi; + @rm -rf tmp/apidiff-OLD tmp/apidiff-NEW + @git clone --quiet --local .git/ tmp/apidiff-OLD + @mkdir -p tmp/apidiff-NEW + @tar -c --exclude .git --exclude tmp --exclude cmd . | tar -x -C tmp/apidiff-NEW + @echo "\033[2m→ Running apidiff...\033[0m" + @echo "tmp/apidiff-OLD/esapi tmp/apidiff-NEW/esapi" + @{ \ + set -e ; \ + output=$$(apidiff tmp/apidiff-OLD/esapi tmp/apidiff-NEW/esapi); \ + echo "\n$$output\n"; \ + if echo $$output | grep -i -e 'incompatible' - > /dev/null 2>&1; then \ + echo "\n\033[31;1mFAILURE\033[0m\n"; \ + false; \ + else \ + echo "\033[32;1mSUCCESS\033[0m"; \ + fi; \ + } + +backport: ## Backport one or more commits from master into version branches +ifeq ($(origin commits), undefined) + @echo "Missing commit(s), exiting..." + @exit 2 +endif +ifndef branches + $(eval branches_list = '7.x' '6.x' '5.x') +else + $(eval branches_list = $(shell echo $(branches) | tr ',' ' ') ) +endif + $(eval commits_list = $(shell echo $(commits) | tr ',' ' ')) + @echo "\033[2m→ Backporting commits [$(commits)]\033[0m" + @{ \ + set -e -o pipefail; \ + for commit in $(commits_list); do \ + git show --pretty='%h | %s' --no-patch $$commit; \ + done; \ + echo ""; \ + for branch in $(branches_list); do \ + echo "\033[2m→ $$branch\033[0m"; \ + git checkout $$branch; \ + for commit in $(commits_list); do \ + git cherry-pick -x $$commit; \ + done; \ + git status --short --branch; \ + echo ""; \ + done; \ + echo "\033[2m→ Push updates to Github:\033[0m"; \ + for branch in $(branches_list); do \ + echo "git push --verbose origin $$branch"; \ + done; \ + } + +release: ## Release a new version to Github + $(eval branch = $(shell git rev-parse --abbrev-ref HEAD)) + $(eval current_version = $(shell cat internal/version/version.go | sed -Ee 's/const Client = "(.*)"/\1/' | tail -1)) + @echo "\033[2m→ [$(branch)] Current version: $(current_version)...\033[0m" +ifndef version + @echo "\033[31m[!] Missing version argument, exiting...\033[0m" + @exit 2 +endif +ifeq ($(version), "") + @echo "\033[31m[!] Empty version argument, exiting...\033[0m" + @exit 2 +endif + @echo "\033[2m→ [$(branch)] Creating version $(version)...\033[0m" + @{ \ + set -e -o pipefail; \ + cp internal/version/version.go internal/version/version.go.OLD && \ + cat internal/version/version.go.OLD | sed -e 's/Client = ".*"/Client = "$(version)"/' > internal/version/version.go && \ + rm internal/version/version.go.OLD && \ + go vet internal/version/version.go && \ + go fmt internal/version/version.go && \ + git diff --color-words internal/version/version.go | tail -n 1; \ + } + @{ \ + set -e -o pipefail; \ + echo "\033[2m→ Commit and create Git tag? (y/n): \033[0m\c"; \ + read continue; \ + if [[ $$continue == "y" ]]; then \ + git add internal/version/version.go && \ + git commit --no-status --quiet --message "Release $(version)" && \ + git tag --annotate v$(version) --message 'Release $(version)'; \ + echo "\033[2m→ Push `git show --pretty='%h (%s)' --no-patch HEAD` to Github:\033[0m\n"; \ + echo "\033[1m git push origin HEAD && git push origin v$(version)\033[0m\n"; \ + else \ + echo "Aborting..."; \ + exit 1; \ + fi; \ + } + +godoc: ## Display documentation for the package + @echo "\033[2m→ Generating documentation...\033[0m" + @echo "open http://localhost:6060/pkg/github.com/elastic/go-elasticsearch/\n" + mkdir -p /tmp/tmpgoroot/doc + rm -rf /tmp/tmpgopath/src/github.com/elastic/go-elasticsearch + mkdir -p /tmp/tmpgopath/src/github.com/elastic/go-elasticsearch + tar -c --exclude='.git' --exclude='tmp' . | tar -x -C /tmp/tmpgopath/src/github.com/elastic/go-elasticsearch + GOROOT=/tmp/tmpgoroot/ GOPATH=/tmp/tmpgopath/ godoc -http=localhost:6060 -play + +cluster: ## Launch an Elasticsearch cluster with Docker + $(eval version ?= "elasticsearch-oss:8.0.0-SNAPSHOT") +ifeq ($(origin nodes), undefined) + $(eval nodes = 1) +endif + @echo "\033[2m→ Launching" $(nodes) "node(s) of" $(version) "...\033[0m" +ifeq ($(shell test $(nodes) && test $(nodes) -gt 1; echo $$?),0) + $(eval detached ?= "true") +else + $(eval detached ?= "false") +endif +ifdef version +ifneq (,$(findstring oss,$(version))) +else + $(eval xpack_env += --env "ELASTIC_PASSWORD=elastic") + $(eval xpack_env += --env "xpack.license.self_generated.type=trial") + $(eval xpack_env += --env "xpack.security.enabled=true") + $(eval xpack_env += --env "xpack.security.http.ssl.enabled=true") + $(eval xpack_env += --env "xpack.security.http.ssl.verification_mode=certificate") + $(eval xpack_env += --env "xpack.security.http.ssl.key=certs/testnode.key") + $(eval xpack_env += --env "xpack.security.http.ssl.certificate=certs/testnode.crt") + $(eval xpack_env += --env "xpack.security.http.ssl.certificate_authorities=certs/ca.crt") + $(eval xpack_env += --env "xpack.security.transport.ssl.enabled=true") + $(eval xpack_env += --env "xpack.security.transport.ssl.key=certs/testnode.key") + $(eval xpack_env += --env "xpack.security.transport.ssl.certificate=certs/testnode.crt") + $(eval xpack_env += --env "xpack.security.transport.ssl.certificate_authorities=certs/ca.crt") + $(eval xpack_volumes += --volume "$(PWD)/.jenkins/certs/testnode.crt:/usr/share/elasticsearch/config/certs/testnode.crt") + $(eval xpack_volumes += --volume "$(PWD)/.jenkins/certs/testnode.key:/usr/share/elasticsearch/config/certs/testnode.key") + $(eval xpack_volumes += --volume "$(PWD)/.jenkins/certs/ca.crt:/usr/share/elasticsearch/config/certs/ca.crt") +endif +endif + @docker network inspect elasticsearch > /dev/null 2>&1 || docker network create elasticsearch; + @{ \ + for n in `seq 1 $(nodes)`; do \ + if [[ -z "$$port" ]]; then \ + hostport=$$((9199+$$n)); \ + else \ + hostport=$$port; \ + fi; \ + docker run \ + --name "es$$n" \ + --network elasticsearch \ + --env "node.name=es$$n" \ + --env "cluster.name=go-elasticsearch" \ + --env "cluster.initial_master_nodes=es1" \ + --env "discovery.seed_hosts=es1" \ + --env "cluster.routing.allocation.disk.threshold_enabled=false" \ + --env "bootstrap.memory_lock=true" \ + --env "node.attr.testattr=test" \ + --env "path.repo=/tmp" \ + --env "repositories.url.allowed_urls=http://snapshot.test*" \ + --env ES_JAVA_OPTS="-Xms1g -Xmx1g" \ + $(xpack_env) \ + --volume `echo $(version) | tr -C "[:alnum:]" '-'`-node-$$n-data:/usr/share/elasticsearch/data \ + $(xpack_volumes) \ + --publish $$hostport:9200 \ + --ulimit nofile=65536:65536 \ + --ulimit memlock=-1:-1 \ + --detach=$(detached) \ + --rm \ + docker.elastic.co/elasticsearch/$(version); \ + done \ + } +ifdef detached + @{ \ + echo "\033[2m→ Waiting for the cluster...\033[0m"; \ + docker run --network elasticsearch --rm appropriate/curl --max-time 120 --retry 120 --retry-delay 1 --retry-connrefused --show-error --silent http://es1:9200; \ + output="\033[2m→ Cluster ready; to remove containers:"; \ + output="$$output docker rm -f"; \ + for n in `seq 1 $(nodes)`; do \ + output="$$output es$$n"; \ + done; \ + echo "$$output\033[0m"; \ + } +endif + +cluster-update: ## Update the Docker image + $(eval version ?= "elasticsearch-oss:8.0.0-SNAPSHOT") + @echo "\033[2m→ Updating the Docker image...\033[0m" + @docker pull docker.elastic.co/elasticsearch/$(version); + +cluster-clean: ## Remove unused Docker volumes and networks + @echo "\033[2m→ Cleaning up Docker assets...\033[0m" + docker volume prune --force + docker network prune --force + +docker: ## Build the Docker image and run it + docker build --file Dockerfile --tag elastic/go-elasticsearch . + docker run -it --network elasticsearch --volume $(PWD)/tmp:/tmp:rw,delegated --rm elastic/go-elasticsearch + +##@ Generator +gen-api: ## Generate the API package from the JSON specification + $(eval input ?= tmp/elasticsearch) + $(eval output ?= esapi) +ifdef debug + $(eval args += --debug) +endif +ifdef ELASTICSEARCH_VERSION + $(eval version = $(ELASTICSEARCH_VERSION)) +else + $(eval version = $(shell cat "$(input)/buildSrc/version.properties" | grep 'elasticsearch' | cut -d '=' -f 2 | tr -d ' ')) +endif +ifdef ELASTICSEARCH_BUILD_HASH + $(eval build_hash = $(ELASTICSEARCH_BUILD_HASH)) +else + $(eval build_hash = $(shell git --git-dir='$(input)/.git' rev-parse --short HEAD)) +endif + @echo "\033[2m→ Generating API package from specification ($(version):$(build_hash))...\033[0m" + @{ \ + set -e; \ + trap "git checkout $(PWD)/internal/cmd/generate/go.mod" SIGINT SIGTERM EXIT; \ + export ELASTICSEARCH_VERSION=$(version) && \ + export ELASTICSEARCH_BUILD_HASH=$(build_hash) && \ + cd internal/cmd/generate && \ + go run main.go apisource --input '$(PWD)/$(input)/rest-api-spec/src/main/resources/rest-api-spec/api/*.json' --output '$(PWD)/$(output)' $(args) && \ + go run main.go apisource --input '$(PWD)/$(input)/x-pack/plugin/src/test/resources/rest-api-spec/api/*.json' --output '$(PWD)/$(output)' $(args) && \ + go run main.go apistruct --output '$(PWD)/$(output)'; \ + } + +gen-tests: ## Generate the API tests from the YAML specification + $(eval input ?= tmp/elasticsearch) + $(eval output ?= esapi/test) +ifdef debug + $(eval args += --debug) +endif +ifdef ELASTICSEARCH_VERSION + $(eval version = $(ELASTICSEARCH_VERSION)) +else + $(eval version = $(shell cat "$(input)/buildSrc/version.properties" | grep 'elasticsearch' | cut -d '=' -f 2 | tr -d ' ')) +endif +ifdef ELASTICSEARCH_BUILD_HASH + $(eval build_hash = $(ELASTICSEARCH_BUILD_HASH)) +else + $(eval build_hash = $(shell git --git-dir='$(input)/.git' rev-parse --short HEAD)) +endif + @echo "\033[2m→ Generating API tests from specification ($(version):$(build_hash))...\033[0m" + @{ \ + set -e; \ + trap "git checkout $(PWD)/internal/cmd/generate/go.mod" SIGINT SIGTERM EXIT; \ + export ELASTICSEARCH_VERSION=$(version) && \ + export ELASTICSEARCH_BUILD_HASH=$(build_hash) && \ + rm -rf $(output)/*_test.go && \ + rm -rf $(output)/xpack && \ + cd internal/cmd/generate && \ + go generate ./... && \ + go run main.go apitests --input '$(PWD)/$(input)/rest-api-spec/src/main/resources/rest-api-spec/test/**/*.y*ml' --output '$(PWD)/$(output)' $(args) && \ + go run main.go apitests --input '$(PWD)/$(input)/x-pack/plugin/src/test/resources/rest-api-spec/test/**/*.yml' --output '$(PWD)/$(output)/xpack' $(args) && \ + go run main.go apitests --input '$(PWD)/$(input)/x-pack/plugin/src/test/resources/rest-api-spec/test/**/**/*.yml' --output '$(PWD)/$(output)/xpack' $(args) && \ + mkdir -p '$(PWD)/esapi/test/xpack/ml' && \ + mkdir -p '$(PWD)/esapi/test/xpack/ml-crud' && \ + mv $(PWD)/esapi/test/xpack/xpack_ml* $(PWD)/esapi/test/xpack/ml/ && \ + mv $(PWD)/esapi/test/xpack/ml/xpack_ml__jobs_crud_test.go $(PWD)/esapi/test/xpack/ml-crud/; \ + } + +##@ Other +#------------------------------------------------------------------------------ +help: ## Display help + @awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) +#------------- -------------- + +.DEFAULT_GOAL := help +.PHONY: help apidiff backport cluster cluster-clean cluster-update coverage docker examples gen-api gen-tests godoc lint release test test-api test-bench test-integ test-unit diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/README.md b/vendor/github.com/elastic/go-elasticsearch/v8/README.md new file mode 100644 index 00000000000..0731efd178e --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/README.md @@ -0,0 +1,344 @@ +# go-elasticsearch + +The official Go client for [Elasticsearch](https://www.elastic.co/products/elasticsearch). + +[![GoDoc](https://godoc.org/github.com/elastic/go-elasticsearch?status.svg)](http://godoc.org/github.com/elastic/go-elasticsearch) +[![Travis-CI](https://travis-ci.org/elastic/go-elasticsearch.svg?branch=master)](https://travis-ci.org/elastic/go-elasticsearch) +[![Go Report Card](https://goreportcard.com/badge/github.com/elastic/go-elasticsearch)](https://goreportcard.com/report/github.com/elastic/go-elasticsearch) +[![codecov.io](https://codecov.io/github/elastic/go-elasticsearch/coverage.svg?branch=master)](https://codecov.io/gh/elastic/go-elasticsearch?branch=master) + +## Compatibility + +The client major versions correspond to the compatible Elasticsearch major versions: to connect to Elasticsearch `7.x`, use a [`7.x`](https://github.com/elastic/go-elasticsearch/tree/7.x) version of the client, to connect to Elasticsearch `6.x`, use a [`6.x`](https://github.com/elastic/go-elasticsearch/tree/6.x) version of the client. + +When using Go modules, include the version in the import path, and specify either an explicit version or a branch: + + require github.com/elastic/go-elasticsearch/v7 7.x + require github.com/elastic/go-elasticsearch/v7 7.0.0 + +It's possible to use multiple versions of the client in a single project: + + // go.mod + github.com/elastic/go-elasticsearch/v6 6.x + github.com/elastic/go-elasticsearch/v7 7.x + + // main.go + import ( + elasticsearch6 "github.com/elastic/go-elasticsearch/v6" + elasticsearch7 "github.com/elastic/go-elasticsearch/v7" + ) + // ... + es6, _ := elasticsearch6.NewDefaultClient() + es7, _ := elasticsearch7.NewDefaultClient() + +The `master` branch of the client is compatible with the current `master` branch of Elasticsearch. + + + +## Installation + +Add the package to your `go.mod` file: + + require github.com/elastic/go-elasticsearch/v8 master + +Or, clone the repository: + + git clone --branch master https://github.com/elastic/go-elasticsearch.git $GOPATH/src/github.com/elastic/go-elasticsearch + +A complete example: + +```bash +mkdir my-elasticsearch-app && cd my-elasticsearch-app + +cat > go.mod <<-END + module my-elasticsearch-app + + require github.com/elastic/go-elasticsearch/v8 master +END + +cat > main.go <<-END + package main + + import ( + "log" + + "github.com/elastic/go-elasticsearch/v8" + ) + + func main() { + es, _ := elasticsearch.NewDefaultClient() + log.Println(elasticsearch.Version) + log.Println(es.Info()) + } +END + +go run main.go +``` + + + + +## Usage + +The `elasticsearch` package ties together two separate packages for calling the Elasticsearch APIs and transferring data over HTTP: `esapi` and `estransport`, respectively. + +Use the `elasticsearch.NewDefaultClient()` function to create the client with the default settings. + +```golang +es, err := elasticsearch.NewDefaultClient() +if err != nil { + log.Fatalf("Error creating the client: %s", err) +} + +res, err := es.Info() +if err != nil { + log.Fatalf("Error getting response: %s", err) +} + +log.Println(res) + +// [200 OK] { +// "name" : "node-1", +// "cluster_name" : "go-elasticsearch" +// ... +``` + +When you export the `ELASTICSEARCH_URL` environment variable, +it will be used to set the cluster endpoint(s). Separate multiple adresses by a comma. + +To set the cluster endpoint(s) programatically, pass them in the configuration object +to the `elasticsearch.NewClient()` function. + +```golang +cfg := elasticsearch.Config{ + Addresses: []string{ + "http://localhost:9200", + "http://localhost:9201", + }, +} +es, err := elasticsearch.NewClient(cfg) +// ... +``` + +To configure the HTTP settings, pass a [`http.Transport`](https://golang.org/pkg/net/http/#Transport) +object in the configuration object (the values are for illustrative purposes only). + +```golang +cfg := elasticsearch.Config{ + Transport: &http.Transport{ + MaxIdleConnsPerHost: 10, + ResponseHeaderTimeout: time.Second, + DialContext: (&net.Dialer{Timeout: time.Second}).DialContext, + TLSClientConfig: &tls.Config{ + MinVersion: tls.VersionTLS11, + // ... + }, + }, +} + +es, err := elasticsearch.NewClient(cfg) +// ... +``` + +See the [`_examples/configuration.go`](_examples/configuration.go) and +[`_examples/customization.go`](_examples/customization.go) files for +more examples of configuration and customization of the client. + +The following example demonstrates a more complex usage. It fetches the Elasticsearch version from the cluster, indexes a couple of documents concurrently, and prints the search results, using a lightweight wrapper around the response body. + +```golang +// $ go run _examples/main.go + +package main + +import ( + "bytes" + "context" + "encoding/json" + "log" + "strconv" + "strings" + "sync" + + "github.com/elastic/go-elasticsearch/v8" + "github.com/elastic/go-elasticsearch/v8/esapi" +) + +func main() { + log.SetFlags(0) + + var ( + r map[string]interface{} + wg sync.WaitGroup + ) + + // Initialize a client with the default settings. + // + // An `ELASTICSEARCH_URL` environment variable will be used when exported. + // + es, err := elasticsearch.NewDefaultClient() + if err != nil { + log.Fatalf("Error creating the client: %s", err) + } + + // 1. Get cluster info + // + res, err := es.Info() + if err != nil { + log.Fatalf("Error getting response: %s", err) + } + // Check response status + if res.IsError() { + log.Fatalf("Error: %s", res.String()) + } + // Deserialize the response into a map. + if err := json.NewDecoder(res.Body).Decode(&r); err != nil { + log.Fatalf("Error parsing the response body: %s", err) + } + // Print client and server version numbers. + log.Printf("Client: %s", elasticsearch.Version) + log.Printf("Server: %s", r["version"].(map[string]interface{})["number"]) + log.Println(strings.Repeat("~", 37)) + + // 2. Index documents concurrently + // + for i, title := range []string{"Test One", "Test Two"} { + wg.Add(1) + + go func(i int, title string) { + defer wg.Done() + + // Build the request body. + var b strings.Builder + b.WriteString(`{"title" : "`) + b.WriteString(title) + b.WriteString(`"}`) + + // Set up the request object. + req := esapi.IndexRequest{ + Index: "test", + DocumentID: strconv.Itoa(i + 1), + Body: strings.NewReader(b.String()), + Refresh: "true", + } + + // Perform the request with the client. + res, err := req.Do(context.Background(), es) + if err != nil { + log.Fatalf("Error getting response: %s", err) + } + defer res.Body.Close() + + if res.IsError() { + log.Printf("[%s] Error indexing document ID=%d", res.Status(), i+1) + } else { + // Deserialize the response into a map. + var r map[string]interface{} + if err := json.NewDecoder(res.Body).Decode(&r); err != nil { + log.Printf("Error parsing the response body: %s", err) + } else { + // Print the response status and indexed document version. + log.Printf("[%s] %s; version=%d", res.Status(), r["result"], int(r["_version"].(float64))) + } + } + }(i, title) + } + wg.Wait() + + log.Println(strings.Repeat("-", 37)) + + // 3. Search for the indexed documents + // + // Build the request body. + var buf bytes.Buffer + query := map[string]interface{}{ + "query": map[string]interface{}{ + "match": map[string]interface{}{ + "title": "test", + }, + }, + } + if err := json.NewEncoder(&buf).Encode(query); err != nil { + log.Fatalf("Error encoding query: %s", err) + } + + // Perform the search request. + res, err = es.Search( + es.Search.WithContext(context.Background()), + es.Search.WithIndex("test"), + es.Search.WithBody(&buf), + es.Search.WithTrackTotalHits(true), + es.Search.WithPretty(), + ) + if err != nil { + log.Fatalf("Error getting response: %s", err) + } + defer res.Body.Close() + + if res.IsError() { + var e map[string]interface{} + if err := json.NewDecoder(res.Body).Decode(&e); err != nil { + log.Fatalf("Error parsing the response body: %s", err) + } else { + // Print the response status and error information. + log.Fatalf("[%s] %s: %s", + res.Status(), + e["error"].(map[string]interface{})["type"], + e["error"].(map[string]interface{})["reason"], + ) + } + } + + if err := json.NewDecoder(res.Body).Decode(&r); err != nil { + log.Fatalf("Error parsing the response body: %s", err) + } + // Print the response status, number of results, and request duration. + log.Printf( + "[%s] %d hits; took: %dms", + res.Status(), + int(r["hits"].(map[string]interface{})["total"].(map[string]interface{})["value"].(float64)), + int(r["took"].(float64)), + ) + // Print the ID and document source for each hit. + for _, hit := range r["hits"].(map[string]interface{})["hits"].([]interface{}) { + log.Printf(" * ID=%s, %s", hit.(map[string]interface{})["_id"], hit.(map[string]interface{})["_source"]) + } + + log.Println(strings.Repeat("=", 37)) +} + +// Client: 8.0.0-SNAPSHOT +// Server: 8.0.0-SNAPSHOT +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// [201 Created] updated; version=1 +// [201 Created] updated; version=1 +// ------------------------------------- +// [200 OK] 2 hits; took: 5ms +// * ID=1, map[title:Test One] +// * ID=2, map[title:Test Two] +// ===================================== +``` + +As you see in the example above, the `esapi` package allows to call the Elasticsearch APIs in two distinct ways: either by creating a struct, such as `IndexRequest`, and calling its `Do()` method by passing it a context and the client, or by calling the `Search()` function on the client directly, using the option functions such as `WithIndex()`. See more information and examples in the +[package documentation](https://godoc.org/github.com/elastic/go-elasticsearch/esapi). + +The `estransport` package handles the transfer of data to and from Elasticsearch. At the moment, the implementation is really minimal: it only round-robins across the configured cluster endpoints. In future, more features — retrying failed requests, ignoring certain status codes, auto-discovering nodes in the cluster, and so on — will be added. + + + +## Helpers + +The `esutil` package provides convenience helpers for working with the client. At the moment, it provides the +`esutil.JSONReader()` helper function. + + + +## Examples + +The **[`_examples`](./_examples)** folder contains a number of recipes and comprehensive examples to get you started with the client, including configuration and customization of the client, mocking the transport for unit tests, embedding the client in a custom type, building queries, performing requests, and parsing the responses. + + + +## License + +(c) 2019 Elasticsearch. Licensed under the Apache License, Version 2.0. diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/doc.go b/vendor/github.com/elastic/go-elasticsearch/v8/doc.go new file mode 100644 index 00000000000..853036c0268 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/doc.go @@ -0,0 +1,49 @@ +/* +Package elasticsearch provides a Go client for Elasticsearch. + +Create the client with the NewDefaultClient function: + + elasticsearch.NewDefaultClient() + +The ELASTICSEARCH_URL environment variable is used instead of the default URL, when set. +Use a comma to separate multiple URLs. + +To configure the client, pass a Config object to the NewClient function: + + cfg := elasticsearch.Config{ + Addresses: []string{ + "http://localhost:9200", + "http://localhost:9201", + }, + Username: "foo", + Password: "bar", + Transport: &http.Transport{ + MaxIdleConnsPerHost: 10, + ResponseHeaderTimeout: time.Second, + DialContext: (&net.Dialer{Timeout: time.Second}).DialContext, + TLSClientConfig: &tls.Config{ + MinVersion: tls.VersionTLS11, + }, + }, + } + + elasticsearch.NewClient(cfg) + +When using the Elastic Service (https://elastic.co/cloud), you can use CloudID instead of Addresses. + +See the elasticsearch_integration_test.go file and the _examples folder for more information. + +Call the Elasticsearch APIs by invoking the corresponding methods on the client: + + res, err := es.Info() + if err != nil { + log.Fatalf("Error getting response: %s", err) + } + + log.Println(res) + +See the github.com/elastic/go-elasticsearch/esapi package for more information about using the API. + +See the github.com/elastic/go-elasticsearch/estransport package for more information about configuring the transport. +*/ +package elasticsearch diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/elasticsearch.go b/vendor/github.com/elastic/go-elasticsearch/v8/elasticsearch.go new file mode 100644 index 00000000000..d7a8b8cebff --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/elasticsearch.go @@ -0,0 +1,196 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package elasticsearch + +import ( + "encoding/base64" + "errors" + "fmt" + "net/http" + "net/url" + "os" + "strings" + "time" + + "github.com/elastic/go-elasticsearch/v8/esapi" + "github.com/elastic/go-elasticsearch/v8/estransport" + "github.com/elastic/go-elasticsearch/v8/internal/version" +) + +const ( + defaultURL = "http://localhost:9200" +) + +// Version returns the package version as a string. +// +const Version = version.Client + +// Config represents the client configuration. +// +type Config struct { + Addresses []string // A list of Elasticsearch nodes to use. + Username string // Username for HTTP Basic Authentication. + Password string // Password for HTTP Basic Authentication. + + CloudID string // Endpoint for the Elastic Service (https://elastic.co/cloud). + APIKey string // Base64-encoded token for authorization; if set, overrides username and password. + + RetryOnStatus []int // List of status codes for retry. Default: 502, 503, 504. + DisableRetry bool // Default: false. + EnableRetryOnTimeout bool // Default: false. + MaxRetries int // Default: 3. + + RetryBackoff func(attempt int) time.Duration // Optional backoff duration. Default: nil. + + Transport http.RoundTripper // The HTTP transport object. + Logger estransport.Logger // The logger object. +} + +// Client represents the Elasticsearch client. +// +type Client struct { + *esapi.API // Embeds the API methods + Transport estransport.Interface +} + +// NewDefaultClient creates a new client with default options. +// +// It will use http://localhost:9200 as the default address. +// +// It will use the ELASTICSEARCH_URL environment variable, if set, +// to configure the addresses; use a comma to separate multiple URLs. +// +func NewDefaultClient() (*Client, error) { + return NewClient(Config{}) +} + +// NewClient creates a new client with configuration from cfg. +// +// It will use http://localhost:9200 as the default address. +// +// It will use the ELASTICSEARCH_URL environment variable, if set, +// to configure the addresses; use a comma to separate multiple URLs. +// +// It's an error to set both cfg.Addresses and the ELASTICSEARCH_URL +// environment variable. +// +func NewClient(cfg Config) (*Client, error) { + var addrs []string + + envAddrs := addrsFromEnvironment() + + if len(envAddrs) > 0 && len(cfg.Addresses) > 0 { + return nil, errors.New("cannot create client: both ELASTICSEARCH_URL and Addresses are set") + } + + if len(envAddrs) > 0 && cfg.CloudID != "" { + return nil, errors.New("cannot create client: both ELASTICSEARCH_URL and CloudID are set") + } + + if len(cfg.Addresses) > 0 && cfg.CloudID != "" { + return nil, errors.New("cannot create client: both Adresses and CloudID are set") + } + + if cfg.CloudID != "" { + cloudAddrs, err := addrFromCloudID(cfg.CloudID) + if err != nil { + return nil, fmt.Errorf("cannot create client: cannot parse CloudID: %s", err) + } + addrs = append(addrs, cloudAddrs) + } else { + if len(envAddrs) > 0 { + addrs = append(envAddrs, envAddrs...) + } + if len(cfg.Addresses) > 0 { + addrs = append(envAddrs, cfg.Addresses...) + } + } + + urls, err := addrsToURLs(addrs) + if err != nil { + return nil, fmt.Errorf("cannot create client: %s", err) + } + + if len(urls) == 0 { + u, _ := url.Parse(defaultURL) // errcheck exclude + urls = append(urls, u) + } + + tp := estransport.New(estransport.Config{ + URLs: urls, + Username: cfg.Username, + Password: cfg.Password, + APIKey: cfg.APIKey, + + RetryOnStatus: cfg.RetryOnStatus, + DisableRetry: cfg.DisableRetry, + EnableRetryOnTimeout: cfg.EnableRetryOnTimeout, + MaxRetries: cfg.MaxRetries, + RetryBackoff: cfg.RetryBackoff, + + Transport: cfg.Transport, + Logger: cfg.Logger, + }) + + return &Client{Transport: tp, API: esapi.New(tp)}, nil +} + +// Perform delegates to Transport to execute a request and return a response. +// +func (c *Client) Perform(req *http.Request) (*http.Response, error) { + return c.Transport.Perform(req) +} + +// addrsFromEnvironment returns a list of addresses by splitting +// the ELASTICSEARCH_URL environment variable with comma, or an empty list. +// +func addrsFromEnvironment() []string { + var addrs []string + + if envURLs, ok := os.LookupEnv("ELASTICSEARCH_URL"); ok && envURLs != "" { + list := strings.Split(envURLs, ",") + for _, u := range list { + addrs = append(addrs, strings.TrimSpace(u)) + } + } + + return addrs +} + +// addrsToURLs creates a list of url.URL structures from url list. +// +func addrsToURLs(addrs []string) ([]*url.URL, error) { + var urls []*url.URL + for _, addr := range addrs { + u, err := url.Parse(strings.TrimRight(addr, "/")) + if err != nil { + return nil, fmt.Errorf("cannot parse url: %v", err) + } + + urls = append(urls, u) + } + return urls, nil +} + +// addrFromCloudID extracts the Elasticsearch URL from CloudID. +// See: https://www.elastic.co/guide/en/cloud/current/ec-cloud-id.html +// +func addrFromCloudID(input string) (string, error) { + var ( + port = 9243 + scheme = "https://" + ) + + values := strings.Split(input, ":") + if len(values) != 2 { + return "", fmt.Errorf("unexpected format: %q", input) + } + data, err := base64.StdEncoding.DecodeString(values[1]) + if err != nil { + return "", err + } + parts := strings.Split(string(data), "$") + return fmt.Sprintf("%s%s.%s:%d", scheme, parts[1], parts[0], port), nil +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api._.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api._.go new file mode 100644 index 00000000000..51d9da6eba1 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api._.go @@ -0,0 +1,761 @@ +// Code generated from specification version 8.0.0 (c60139a345a): DO NOT EDIT + +package esapi + +// API contains the Elasticsearch APIs +// +type API struct { + Cat *Cat + Cluster *Cluster + Indices *Indices + Ingest *Ingest + Nodes *Nodes + Remote *Remote + Snapshot *Snapshot + Tasks *Tasks + CCR *CCR + ILM *ILM + License *License + Migration *Migration + ML *ML + Monitoring *Monitoring + Rollup *Rollup + Security *Security + SQL *SQL + SSL *SSL + Watcher *Watcher + XPack *XPack + + Bulk Bulk + ClearScroll ClearScroll + Count Count + Create Create + DataFrameDeleteDataFrameTransform DataFrameDeleteDataFrameTransform + DataFrameGetDataFrameTransform DataFrameGetDataFrameTransform + DataFrameGetDataFrameTransformStats DataFrameGetDataFrameTransformStats + DataFramePreviewDataFrameTransform DataFramePreviewDataFrameTransform + DataFramePutDataFrameTransform DataFramePutDataFrameTransform + DataFrameStartDataFrameTransform DataFrameStartDataFrameTransform + DataFrameStopDataFrameTransform DataFrameStopDataFrameTransform + DataFrameTransformDeprecatedDeleteTransform DataFrameTransformDeprecatedDeleteTransform + DataFrameTransformDeprecatedGetTransform DataFrameTransformDeprecatedGetTransform + DataFrameTransformDeprecatedGetTransformStats DataFrameTransformDeprecatedGetTransformStats + DataFrameTransformDeprecatedPreviewTransform DataFrameTransformDeprecatedPreviewTransform + DataFrameTransformDeprecatedPutTransform DataFrameTransformDeprecatedPutTransform + DataFrameTransformDeprecatedStartTransform DataFrameTransformDeprecatedStartTransform + DataFrameTransformDeprecatedStopTransform DataFrameTransformDeprecatedStopTransform + DataFrameTransformDeprecatedUpdateTransform DataFrameTransformDeprecatedUpdateTransform + DataFrameUpdateDataFrameTransform DataFrameUpdateDataFrameTransform + DeleteByQuery DeleteByQuery + DeleteByQueryRethrottle DeleteByQueryRethrottle + Delete Delete + DeleteScript DeleteScript + EnrichDeletePolicy EnrichDeletePolicy + EnrichExecutePolicy EnrichExecutePolicy + EnrichGetPolicy EnrichGetPolicy + EnrichPutPolicy EnrichPutPolicy + EnrichStats EnrichStats + Exists Exists + ExistsSource ExistsSource + Explain Explain + FieldCaps FieldCaps + Get Get + GetScriptContext GetScriptContext + GetScript GetScript + GetSource GetSource + GraphExplore GraphExplore + Index Index + Info Info + Mget Mget + Msearch Msearch + MsearchTemplate MsearchTemplate + Mtermvectors Mtermvectors + Ping Ping + PutScript PutScript + RankEval RankEval + Reindex Reindex + ReindexRethrottle ReindexRethrottle + RenderSearchTemplate RenderSearchTemplate + ScriptsPainlessContext ScriptsPainlessContext + ScriptsPainlessExecute ScriptsPainlessExecute + Scroll Scroll + Search Search + SearchShards SearchShards + SearchTemplate SearchTemplate + SlmDeleteLifecycle SlmDeleteLifecycle + SlmExecuteLifecycle SlmExecuteLifecycle + SlmExecuteRetention SlmExecuteRetention + SlmGetLifecycle SlmGetLifecycle + SlmGetStats SlmGetStats + SlmPutLifecycle SlmPutLifecycle + Termvectors Termvectors + TransformDeleteTransform TransformDeleteTransform + TransformGetTransform TransformGetTransform + TransformGetTransformStats TransformGetTransformStats + TransformPreviewTransform TransformPreviewTransform + TransformPutTransform TransformPutTransform + TransformStartTransform TransformStartTransform + TransformStopTransform TransformStopTransform + TransformUpdateTransform TransformUpdateTransform + UpdateByQuery UpdateByQuery + UpdateByQueryRethrottle UpdateByQueryRethrottle + Update Update +} + +// Cat contains the Cat APIs +type Cat struct { + Aliases CatAliases + Allocation CatAllocation + Count CatCount + Fielddata CatFielddata + Health CatHealth + Help CatHelp + Indices CatIndices + Master CatMaster + Nodeattrs CatNodeattrs + Nodes CatNodes + PendingTasks CatPendingTasks + Plugins CatPlugins + Recovery CatRecovery + Repositories CatRepositories + Segments CatSegments + Shards CatShards + Snapshots CatSnapshots + Tasks CatTasks + Templates CatTemplates + ThreadPool CatThreadPool +} + +// Cluster contains the Cluster APIs +type Cluster struct { + AllocationExplain ClusterAllocationExplain + GetSettings ClusterGetSettings + Health ClusterHealth + PendingTasks ClusterPendingTasks + PutSettings ClusterPutSettings + RemoteInfo ClusterRemoteInfo + Reroute ClusterReroute + State ClusterState + Stats ClusterStats +} + +// Indices contains the Indices APIs +type Indices struct { + Analyze IndicesAnalyze + ClearCache IndicesClearCache + Clone IndicesClone + Close IndicesClose + Create IndicesCreate + DeleteAlias IndicesDeleteAlias + Delete IndicesDelete + DeleteTemplate IndicesDeleteTemplate + ExistsAlias IndicesExistsAlias + ExistsDocumentType IndicesExistsDocumentType + Exists IndicesExists + ExistsTemplate IndicesExistsTemplate + Flush IndicesFlush + FlushSynced IndicesFlushSynced + Forcemerge IndicesForcemerge + Freeze IndicesFreeze + GetAlias IndicesGetAlias + GetFieldMapping IndicesGetFieldMapping + GetMapping IndicesGetMapping + Get IndicesGet + GetSettings IndicesGetSettings + GetTemplate IndicesGetTemplate + GetUpgrade IndicesGetUpgrade + Open IndicesOpen + PutAlias IndicesPutAlias + PutMapping IndicesPutMapping + PutSettings IndicesPutSettings + PutTemplate IndicesPutTemplate + Recovery IndicesRecovery + Refresh IndicesRefresh + ReloadSearchAnalyzers IndicesReloadSearchAnalyzers + Rollover IndicesRollover + Segments IndicesSegments + ShardStores IndicesShardStores + Shrink IndicesShrink + Split IndicesSplit + Stats IndicesStats + Unfreeze IndicesUnfreeze + UpdateAliases IndicesUpdateAliases + Upgrade IndicesUpgrade + ValidateQuery IndicesValidateQuery +} + +// Ingest contains the Ingest APIs +type Ingest struct { + DeletePipeline IngestDeletePipeline + GetPipeline IngestGetPipeline + ProcessorGrok IngestProcessorGrok + PutPipeline IngestPutPipeline + Simulate IngestSimulate +} + +// Nodes contains the Nodes APIs +type Nodes struct { + HotThreads NodesHotThreads + Info NodesInfo + ReloadSecureSettings NodesReloadSecureSettings + Stats NodesStats + Usage NodesUsage +} + +// Remote contains the Remote APIs +type Remote struct { +} + +// Snapshot contains the Snapshot APIs +type Snapshot struct { + CleanupRepository SnapshotCleanupRepository + CreateRepository SnapshotCreateRepository + Create SnapshotCreate + DeleteRepository SnapshotDeleteRepository + Delete SnapshotDelete + GetRepository SnapshotGetRepository + Get SnapshotGet + Restore SnapshotRestore + Status SnapshotStatus + VerifyRepository SnapshotVerifyRepository +} + +// Tasks contains the Tasks APIs +type Tasks struct { + Cancel TasksCancel + Get TasksGet + List TasksList +} + +// CCR contains the CCR APIs +type CCR struct { + DeleteAutoFollowPattern CCRDeleteAutoFollowPattern + FollowInfo CCRFollowInfo + Follow CCRFollow + FollowStats CCRFollowStats + ForgetFollower CCRForgetFollower + GetAutoFollowPattern CCRGetAutoFollowPattern + PauseAutoFollowPattern CCRPauseAutoFollowPattern + PauseFollow CCRPauseFollow + PutAutoFollowPattern CCRPutAutoFollowPattern + ResumeAutoFollowPattern CCRResumeAutoFollowPattern + ResumeFollow CCRResumeFollow + Stats CCRStats + Unfollow CCRUnfollow +} + +// ILM contains the ILM APIs +type ILM struct { + DeleteLifecycle ILMDeleteLifecycle + ExplainLifecycle ILMExplainLifecycle + GetLifecycle ILMGetLifecycle + GetStatus ILMGetStatus + MoveToStep ILMMoveToStep + PutLifecycle ILMPutLifecycle + RemovePolicy ILMRemovePolicy + Retry ILMRetry + Start ILMStart + Stop ILMStop +} + +// License contains the License APIs +type License struct { + Delete LicenseDelete + GetBasicStatus LicenseGetBasicStatus + Get LicenseGet + GetTrialStatus LicenseGetTrialStatus + Post LicensePost + PostStartBasic LicensePostStartBasic + PostStartTrial LicensePostStartTrial +} + +// Migration contains the Migration APIs +type Migration struct { + Deprecations MigrationDeprecations +} + +// ML contains the ML APIs +type ML struct { + CloseJob MLCloseJob + DeleteCalendarEvent MLDeleteCalendarEvent + DeleteCalendarJob MLDeleteCalendarJob + DeleteCalendar MLDeleteCalendar + DeleteDataFrameAnalytics MLDeleteDataFrameAnalytics + DeleteDatafeed MLDeleteDatafeed + DeleteExpiredData MLDeleteExpiredData + DeleteFilter MLDeleteFilter + DeleteForecast MLDeleteForecast + DeleteJob MLDeleteJob + DeleteModelSnapshot MLDeleteModelSnapshot + EstimateMemoryUsage MLEstimateMemoryUsage + EvaluateDataFrame MLEvaluateDataFrame + FindFileStructure MLFindFileStructure + FlushJob MLFlushJob + Forecast MLForecast + GetBuckets MLGetBuckets + GetCalendarEvents MLGetCalendarEvents + GetCalendars MLGetCalendars + GetCategories MLGetCategories + GetDataFrameAnalytics MLGetDataFrameAnalytics + GetDataFrameAnalyticsStats MLGetDataFrameAnalyticsStats + GetDatafeedStats MLGetDatafeedStats + GetDatafeeds MLGetDatafeeds + GetFilters MLGetFilters + GetInfluencers MLGetInfluencers + GetJobStats MLGetJobStats + GetJobs MLGetJobs + GetModelSnapshots MLGetModelSnapshots + GetOverallBuckets MLGetOverallBuckets + GetRecords MLGetRecords + Info MLInfo + OpenJob MLOpenJob + PostCalendarEvents MLPostCalendarEvents + PostData MLPostData + PreviewDatafeed MLPreviewDatafeed + PutCalendarJob MLPutCalendarJob + PutCalendar MLPutCalendar + PutDataFrameAnalytics MLPutDataFrameAnalytics + PutDatafeed MLPutDatafeed + PutFilter MLPutFilter + PutJob MLPutJob + RevertModelSnapshot MLRevertModelSnapshot + SetUpgradeMode MLSetUpgradeMode + StartDataFrameAnalytics MLStartDataFrameAnalytics + StartDatafeed MLStartDatafeed + StopDataFrameAnalytics MLStopDataFrameAnalytics + StopDatafeed MLStopDatafeed + UpdateDatafeed MLUpdateDatafeed + UpdateFilter MLUpdateFilter + UpdateJob MLUpdateJob + UpdateModelSnapshot MLUpdateModelSnapshot + ValidateDetector MLValidateDetector + Validate MLValidate +} + +// Monitoring contains the Monitoring APIs +type Monitoring struct { + Bulk MonitoringBulk +} + +// Rollup contains the Rollup APIs +type Rollup struct { + DeleteJob RollupDeleteJob + GetJobs RollupGetJobs + GetCaps RollupGetRollupCaps + GetIndexCaps RollupGetRollupIndexCaps + PutJob RollupPutJob + Search RollupRollupSearch + StartJob RollupStartJob + StopJob RollupStopJob +} + +// Security contains the Security APIs +type Security struct { + Authenticate SecurityAuthenticate + ChangePassword SecurityChangePassword + ClearCachedRealms SecurityClearCachedRealms + ClearCachedRoles SecurityClearCachedRoles + CreateAPIKey SecurityCreateAPIKey + DeletePrivileges SecurityDeletePrivileges + DeleteRoleMapping SecurityDeleteRoleMapping + DeleteRole SecurityDeleteRole + DeleteUser SecurityDeleteUser + DisableUser SecurityDisableUser + EnableUser SecurityEnableUser + GetAPIKey SecurityGetAPIKey + GetBuiltinPrivileges SecurityGetBuiltinPrivileges + GetPrivileges SecurityGetPrivileges + GetRoleMapping SecurityGetRoleMapping + GetRole SecurityGetRole + GetToken SecurityGetToken + GetUserPrivileges SecurityGetUserPrivileges + GetUser SecurityGetUser + HasPrivileges SecurityHasPrivileges + InvalidateAPIKey SecurityInvalidateAPIKey + InvalidateToken SecurityInvalidateToken + PutPrivileges SecurityPutPrivileges + PutRoleMapping SecurityPutRoleMapping + PutRole SecurityPutRole + PutUser SecurityPutUser +} + +// SQL contains the SQL APIs +type SQL struct { + ClearCursor SQLClearCursor + Query SQLQuery + Translate SQLTranslate +} + +// SSL contains the SSL APIs +type SSL struct { + Certificates SSLCertificates +} + +// Watcher contains the Watcher APIs +type Watcher struct { + AckWatch WatcherAckWatch + ActivateWatch WatcherActivateWatch + DeactivateWatch WatcherDeactivateWatch + DeleteWatch WatcherDeleteWatch + ExecuteWatch WatcherExecuteWatch + GetWatch WatcherGetWatch + PutWatch WatcherPutWatch + Start WatcherStart + Stats WatcherStats + Stop WatcherStop +} + +// XPack contains the XPack APIs +type XPack struct { + Info XPackInfo + Usage XPackUsage +} + +// New creates new API +// +func New(t Transport) *API { + return &API{ + Bulk: newBulkFunc(t), + ClearScroll: newClearScrollFunc(t), + Count: newCountFunc(t), + Create: newCreateFunc(t), + DataFrameDeleteDataFrameTransform: newDataFrameDeleteDataFrameTransformFunc(t), + DataFrameGetDataFrameTransform: newDataFrameGetDataFrameTransformFunc(t), + DataFrameGetDataFrameTransformStats: newDataFrameGetDataFrameTransformStatsFunc(t), + DataFramePreviewDataFrameTransform: newDataFramePreviewDataFrameTransformFunc(t), + DataFramePutDataFrameTransform: newDataFramePutDataFrameTransformFunc(t), + DataFrameStartDataFrameTransform: newDataFrameStartDataFrameTransformFunc(t), + DataFrameStopDataFrameTransform: newDataFrameStopDataFrameTransformFunc(t), + DataFrameTransformDeprecatedDeleteTransform: newDataFrameTransformDeprecatedDeleteTransformFunc(t), + DataFrameTransformDeprecatedGetTransform: newDataFrameTransformDeprecatedGetTransformFunc(t), + DataFrameTransformDeprecatedGetTransformStats: newDataFrameTransformDeprecatedGetTransformStatsFunc(t), + DataFrameTransformDeprecatedPreviewTransform: newDataFrameTransformDeprecatedPreviewTransformFunc(t), + DataFrameTransformDeprecatedPutTransform: newDataFrameTransformDeprecatedPutTransformFunc(t), + DataFrameTransformDeprecatedStartTransform: newDataFrameTransformDeprecatedStartTransformFunc(t), + DataFrameTransformDeprecatedStopTransform: newDataFrameTransformDeprecatedStopTransformFunc(t), + DataFrameTransformDeprecatedUpdateTransform: newDataFrameTransformDeprecatedUpdateTransformFunc(t), + DataFrameUpdateDataFrameTransform: newDataFrameUpdateDataFrameTransformFunc(t), + DeleteByQuery: newDeleteByQueryFunc(t), + DeleteByQueryRethrottle: newDeleteByQueryRethrottleFunc(t), + Delete: newDeleteFunc(t), + DeleteScript: newDeleteScriptFunc(t), + EnrichDeletePolicy: newEnrichDeletePolicyFunc(t), + EnrichExecutePolicy: newEnrichExecutePolicyFunc(t), + EnrichGetPolicy: newEnrichGetPolicyFunc(t), + EnrichPutPolicy: newEnrichPutPolicyFunc(t), + EnrichStats: newEnrichStatsFunc(t), + Exists: newExistsFunc(t), + ExistsSource: newExistsSourceFunc(t), + Explain: newExplainFunc(t), + FieldCaps: newFieldCapsFunc(t), + Get: newGetFunc(t), + GetScriptContext: newGetScriptContextFunc(t), + GetScript: newGetScriptFunc(t), + GetSource: newGetSourceFunc(t), + GraphExplore: newGraphExploreFunc(t), + Index: newIndexFunc(t), + Info: newInfoFunc(t), + Mget: newMgetFunc(t), + Msearch: newMsearchFunc(t), + MsearchTemplate: newMsearchTemplateFunc(t), + Mtermvectors: newMtermvectorsFunc(t), + Ping: newPingFunc(t), + PutScript: newPutScriptFunc(t), + RankEval: newRankEvalFunc(t), + Reindex: newReindexFunc(t), + ReindexRethrottle: newReindexRethrottleFunc(t), + RenderSearchTemplate: newRenderSearchTemplateFunc(t), + ScriptsPainlessContext: newScriptsPainlessContextFunc(t), + ScriptsPainlessExecute: newScriptsPainlessExecuteFunc(t), + Scroll: newScrollFunc(t), + Search: newSearchFunc(t), + SearchShards: newSearchShardsFunc(t), + SearchTemplate: newSearchTemplateFunc(t), + SlmDeleteLifecycle: newSlmDeleteLifecycleFunc(t), + SlmExecuteLifecycle: newSlmExecuteLifecycleFunc(t), + SlmExecuteRetention: newSlmExecuteRetentionFunc(t), + SlmGetLifecycle: newSlmGetLifecycleFunc(t), + SlmGetStats: newSlmGetStatsFunc(t), + SlmPutLifecycle: newSlmPutLifecycleFunc(t), + Termvectors: newTermvectorsFunc(t), + TransformDeleteTransform: newTransformDeleteTransformFunc(t), + TransformGetTransform: newTransformGetTransformFunc(t), + TransformGetTransformStats: newTransformGetTransformStatsFunc(t), + TransformPreviewTransform: newTransformPreviewTransformFunc(t), + TransformPutTransform: newTransformPutTransformFunc(t), + TransformStartTransform: newTransformStartTransformFunc(t), + TransformStopTransform: newTransformStopTransformFunc(t), + TransformUpdateTransform: newTransformUpdateTransformFunc(t), + UpdateByQuery: newUpdateByQueryFunc(t), + UpdateByQueryRethrottle: newUpdateByQueryRethrottleFunc(t), + Update: newUpdateFunc(t), + Cat: &Cat{ + Aliases: newCatAliasesFunc(t), + Allocation: newCatAllocationFunc(t), + Count: newCatCountFunc(t), + Fielddata: newCatFielddataFunc(t), + Health: newCatHealthFunc(t), + Help: newCatHelpFunc(t), + Indices: newCatIndicesFunc(t), + Master: newCatMasterFunc(t), + Nodeattrs: newCatNodeattrsFunc(t), + Nodes: newCatNodesFunc(t), + PendingTasks: newCatPendingTasksFunc(t), + Plugins: newCatPluginsFunc(t), + Recovery: newCatRecoveryFunc(t), + Repositories: newCatRepositoriesFunc(t), + Segments: newCatSegmentsFunc(t), + Shards: newCatShardsFunc(t), + Snapshots: newCatSnapshotsFunc(t), + Tasks: newCatTasksFunc(t), + Templates: newCatTemplatesFunc(t), + ThreadPool: newCatThreadPoolFunc(t), + }, + Cluster: &Cluster{ + AllocationExplain: newClusterAllocationExplainFunc(t), + GetSettings: newClusterGetSettingsFunc(t), + Health: newClusterHealthFunc(t), + PendingTasks: newClusterPendingTasksFunc(t), + PutSettings: newClusterPutSettingsFunc(t), + RemoteInfo: newClusterRemoteInfoFunc(t), + Reroute: newClusterRerouteFunc(t), + State: newClusterStateFunc(t), + Stats: newClusterStatsFunc(t), + }, + Indices: &Indices{ + Analyze: newIndicesAnalyzeFunc(t), + ClearCache: newIndicesClearCacheFunc(t), + Clone: newIndicesCloneFunc(t), + Close: newIndicesCloseFunc(t), + Create: newIndicesCreateFunc(t), + DeleteAlias: newIndicesDeleteAliasFunc(t), + Delete: newIndicesDeleteFunc(t), + DeleteTemplate: newIndicesDeleteTemplateFunc(t), + ExistsAlias: newIndicesExistsAliasFunc(t), + ExistsDocumentType: newIndicesExistsDocumentTypeFunc(t), + Exists: newIndicesExistsFunc(t), + ExistsTemplate: newIndicesExistsTemplateFunc(t), + Flush: newIndicesFlushFunc(t), + FlushSynced: newIndicesFlushSyncedFunc(t), + Forcemerge: newIndicesForcemergeFunc(t), + Freeze: newIndicesFreezeFunc(t), + GetAlias: newIndicesGetAliasFunc(t), + GetFieldMapping: newIndicesGetFieldMappingFunc(t), + GetMapping: newIndicesGetMappingFunc(t), + Get: newIndicesGetFunc(t), + GetSettings: newIndicesGetSettingsFunc(t), + GetTemplate: newIndicesGetTemplateFunc(t), + GetUpgrade: newIndicesGetUpgradeFunc(t), + Open: newIndicesOpenFunc(t), + PutAlias: newIndicesPutAliasFunc(t), + PutMapping: newIndicesPutMappingFunc(t), + PutSettings: newIndicesPutSettingsFunc(t), + PutTemplate: newIndicesPutTemplateFunc(t), + Recovery: newIndicesRecoveryFunc(t), + Refresh: newIndicesRefreshFunc(t), + ReloadSearchAnalyzers: newIndicesReloadSearchAnalyzersFunc(t), + Rollover: newIndicesRolloverFunc(t), + Segments: newIndicesSegmentsFunc(t), + ShardStores: newIndicesShardStoresFunc(t), + Shrink: newIndicesShrinkFunc(t), + Split: newIndicesSplitFunc(t), + Stats: newIndicesStatsFunc(t), + Unfreeze: newIndicesUnfreezeFunc(t), + UpdateAliases: newIndicesUpdateAliasesFunc(t), + Upgrade: newIndicesUpgradeFunc(t), + ValidateQuery: newIndicesValidateQueryFunc(t), + }, + Ingest: &Ingest{ + DeletePipeline: newIngestDeletePipelineFunc(t), + GetPipeline: newIngestGetPipelineFunc(t), + ProcessorGrok: newIngestProcessorGrokFunc(t), + PutPipeline: newIngestPutPipelineFunc(t), + Simulate: newIngestSimulateFunc(t), + }, + Nodes: &Nodes{ + HotThreads: newNodesHotThreadsFunc(t), + Info: newNodesInfoFunc(t), + ReloadSecureSettings: newNodesReloadSecureSettingsFunc(t), + Stats: newNodesStatsFunc(t), + Usage: newNodesUsageFunc(t), + }, + Remote: &Remote{}, + Snapshot: &Snapshot{ + CleanupRepository: newSnapshotCleanupRepositoryFunc(t), + CreateRepository: newSnapshotCreateRepositoryFunc(t), + Create: newSnapshotCreateFunc(t), + DeleteRepository: newSnapshotDeleteRepositoryFunc(t), + Delete: newSnapshotDeleteFunc(t), + GetRepository: newSnapshotGetRepositoryFunc(t), + Get: newSnapshotGetFunc(t), + Restore: newSnapshotRestoreFunc(t), + Status: newSnapshotStatusFunc(t), + VerifyRepository: newSnapshotVerifyRepositoryFunc(t), + }, + Tasks: &Tasks{ + Cancel: newTasksCancelFunc(t), + Get: newTasksGetFunc(t), + List: newTasksListFunc(t), + }, + CCR: &CCR{ + DeleteAutoFollowPattern: newCCRDeleteAutoFollowPatternFunc(t), + FollowInfo: newCCRFollowInfoFunc(t), + Follow: newCCRFollowFunc(t), + FollowStats: newCCRFollowStatsFunc(t), + ForgetFollower: newCCRForgetFollowerFunc(t), + GetAutoFollowPattern: newCCRGetAutoFollowPatternFunc(t), + PauseAutoFollowPattern: newCCRPauseAutoFollowPatternFunc(t), + PauseFollow: newCCRPauseFollowFunc(t), + PutAutoFollowPattern: newCCRPutAutoFollowPatternFunc(t), + ResumeAutoFollowPattern: newCCRResumeAutoFollowPatternFunc(t), + ResumeFollow: newCCRResumeFollowFunc(t), + Stats: newCCRStatsFunc(t), + Unfollow: newCCRUnfollowFunc(t), + }, + ILM: &ILM{ + DeleteLifecycle: newILMDeleteLifecycleFunc(t), + ExplainLifecycle: newILMExplainLifecycleFunc(t), + GetLifecycle: newILMGetLifecycleFunc(t), + GetStatus: newILMGetStatusFunc(t), + MoveToStep: newILMMoveToStepFunc(t), + PutLifecycle: newILMPutLifecycleFunc(t), + RemovePolicy: newILMRemovePolicyFunc(t), + Retry: newILMRetryFunc(t), + Start: newILMStartFunc(t), + Stop: newILMStopFunc(t), + }, + License: &License{ + Delete: newLicenseDeleteFunc(t), + GetBasicStatus: newLicenseGetBasicStatusFunc(t), + Get: newLicenseGetFunc(t), + GetTrialStatus: newLicenseGetTrialStatusFunc(t), + Post: newLicensePostFunc(t), + PostStartBasic: newLicensePostStartBasicFunc(t), + PostStartTrial: newLicensePostStartTrialFunc(t), + }, + Migration: &Migration{ + Deprecations: newMigrationDeprecationsFunc(t), + }, + ML: &ML{ + CloseJob: newMLCloseJobFunc(t), + DeleteCalendarEvent: newMLDeleteCalendarEventFunc(t), + DeleteCalendarJob: newMLDeleteCalendarJobFunc(t), + DeleteCalendar: newMLDeleteCalendarFunc(t), + DeleteDataFrameAnalytics: newMLDeleteDataFrameAnalyticsFunc(t), + DeleteDatafeed: newMLDeleteDatafeedFunc(t), + DeleteExpiredData: newMLDeleteExpiredDataFunc(t), + DeleteFilter: newMLDeleteFilterFunc(t), + DeleteForecast: newMLDeleteForecastFunc(t), + DeleteJob: newMLDeleteJobFunc(t), + DeleteModelSnapshot: newMLDeleteModelSnapshotFunc(t), + EstimateMemoryUsage: newMLEstimateMemoryUsageFunc(t), + EvaluateDataFrame: newMLEvaluateDataFrameFunc(t), + FindFileStructure: newMLFindFileStructureFunc(t), + FlushJob: newMLFlushJobFunc(t), + Forecast: newMLForecastFunc(t), + GetBuckets: newMLGetBucketsFunc(t), + GetCalendarEvents: newMLGetCalendarEventsFunc(t), + GetCalendars: newMLGetCalendarsFunc(t), + GetCategories: newMLGetCategoriesFunc(t), + GetDataFrameAnalytics: newMLGetDataFrameAnalyticsFunc(t), + GetDataFrameAnalyticsStats: newMLGetDataFrameAnalyticsStatsFunc(t), + GetDatafeedStats: newMLGetDatafeedStatsFunc(t), + GetDatafeeds: newMLGetDatafeedsFunc(t), + GetFilters: newMLGetFiltersFunc(t), + GetInfluencers: newMLGetInfluencersFunc(t), + GetJobStats: newMLGetJobStatsFunc(t), + GetJobs: newMLGetJobsFunc(t), + GetModelSnapshots: newMLGetModelSnapshotsFunc(t), + GetOverallBuckets: newMLGetOverallBucketsFunc(t), + GetRecords: newMLGetRecordsFunc(t), + Info: newMLInfoFunc(t), + OpenJob: newMLOpenJobFunc(t), + PostCalendarEvents: newMLPostCalendarEventsFunc(t), + PostData: newMLPostDataFunc(t), + PreviewDatafeed: newMLPreviewDatafeedFunc(t), + PutCalendarJob: newMLPutCalendarJobFunc(t), + PutCalendar: newMLPutCalendarFunc(t), + PutDataFrameAnalytics: newMLPutDataFrameAnalyticsFunc(t), + PutDatafeed: newMLPutDatafeedFunc(t), + PutFilter: newMLPutFilterFunc(t), + PutJob: newMLPutJobFunc(t), + RevertModelSnapshot: newMLRevertModelSnapshotFunc(t), + SetUpgradeMode: newMLSetUpgradeModeFunc(t), + StartDataFrameAnalytics: newMLStartDataFrameAnalyticsFunc(t), + StartDatafeed: newMLStartDatafeedFunc(t), + StopDataFrameAnalytics: newMLStopDataFrameAnalyticsFunc(t), + StopDatafeed: newMLStopDatafeedFunc(t), + UpdateDatafeed: newMLUpdateDatafeedFunc(t), + UpdateFilter: newMLUpdateFilterFunc(t), + UpdateJob: newMLUpdateJobFunc(t), + UpdateModelSnapshot: newMLUpdateModelSnapshotFunc(t), + ValidateDetector: newMLValidateDetectorFunc(t), + Validate: newMLValidateFunc(t), + }, + Monitoring: &Monitoring{ + Bulk: newMonitoringBulkFunc(t), + }, + Rollup: &Rollup{ + DeleteJob: newRollupDeleteJobFunc(t), + GetJobs: newRollupGetJobsFunc(t), + GetCaps: newRollupGetRollupCapsFunc(t), + GetIndexCaps: newRollupGetRollupIndexCapsFunc(t), + PutJob: newRollupPutJobFunc(t), + Search: newRollupRollupSearchFunc(t), + StartJob: newRollupStartJobFunc(t), + StopJob: newRollupStopJobFunc(t), + }, + Security: &Security{ + Authenticate: newSecurityAuthenticateFunc(t), + ChangePassword: newSecurityChangePasswordFunc(t), + ClearCachedRealms: newSecurityClearCachedRealmsFunc(t), + ClearCachedRoles: newSecurityClearCachedRolesFunc(t), + CreateAPIKey: newSecurityCreateAPIKeyFunc(t), + DeletePrivileges: newSecurityDeletePrivilegesFunc(t), + DeleteRoleMapping: newSecurityDeleteRoleMappingFunc(t), + DeleteRole: newSecurityDeleteRoleFunc(t), + DeleteUser: newSecurityDeleteUserFunc(t), + DisableUser: newSecurityDisableUserFunc(t), + EnableUser: newSecurityEnableUserFunc(t), + GetAPIKey: newSecurityGetAPIKeyFunc(t), + GetBuiltinPrivileges: newSecurityGetBuiltinPrivilegesFunc(t), + GetPrivileges: newSecurityGetPrivilegesFunc(t), + GetRoleMapping: newSecurityGetRoleMappingFunc(t), + GetRole: newSecurityGetRoleFunc(t), + GetToken: newSecurityGetTokenFunc(t), + GetUserPrivileges: newSecurityGetUserPrivilegesFunc(t), + GetUser: newSecurityGetUserFunc(t), + HasPrivileges: newSecurityHasPrivilegesFunc(t), + InvalidateAPIKey: newSecurityInvalidateAPIKeyFunc(t), + InvalidateToken: newSecurityInvalidateTokenFunc(t), + PutPrivileges: newSecurityPutPrivilegesFunc(t), + PutRoleMapping: newSecurityPutRoleMappingFunc(t), + PutRole: newSecurityPutRoleFunc(t), + PutUser: newSecurityPutUserFunc(t), + }, + SQL: &SQL{ + ClearCursor: newSQLClearCursorFunc(t), + Query: newSQLQueryFunc(t), + Translate: newSQLTranslateFunc(t), + }, + SSL: &SSL{ + Certificates: newSSLCertificatesFunc(t), + }, + Watcher: &Watcher{ + AckWatch: newWatcherAckWatchFunc(t), + ActivateWatch: newWatcherActivateWatchFunc(t), + DeactivateWatch: newWatcherDeactivateWatchFunc(t), + DeleteWatch: newWatcherDeleteWatchFunc(t), + ExecuteWatch: newWatcherExecuteWatchFunc(t), + GetWatch: newWatcherGetWatchFunc(t), + PutWatch: newWatcherPutWatchFunc(t), + Start: newWatcherStartFunc(t), + Stats: newWatcherStatsFunc(t), + Stop: newWatcherStopFunc(t), + }, + XPack: &XPack{ + Info: newXPackInfoFunc(t), + Usage: newXPackUsageFunc(t), + }, + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.bulk.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.bulk.go new file mode 100644 index 00000000000..1637d3a83e2 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.bulk.go @@ -0,0 +1,328 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" + "time" +) + +func newBulkFunc(t Transport) Bulk { + return func(body io.Reader, o ...func(*BulkRequest)) (*Response, error) { + var r = BulkRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// Bulk allows to perform multiple index/update/delete operations in a single request. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html. +// +type Bulk func(body io.Reader, o ...func(*BulkRequest)) (*Response, error) + +// BulkRequest configures the Bulk API request. +// +type BulkRequest struct { + Index string + DocumentType string + + Body io.Reader + + Pipeline string + Refresh string + Routing string + Source []string + SourceExcludes []string + SourceIncludes []string + Timeout time.Duration + WaitForActiveShards string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r BulkRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len(r.Index) + 1 + len(r.DocumentType) + 1 + len("_bulk")) + if r.Index != "" { + path.WriteString("/") + path.WriteString(r.Index) + } + if r.DocumentType != "" { + path.WriteString("/") + path.WriteString(r.DocumentType) + } + path.WriteString("/") + path.WriteString("_bulk") + + params = make(map[string]string) + + if r.Pipeline != "" { + params["pipeline"] = r.Pipeline + } + + if r.Refresh != "" { + params["refresh"] = r.Refresh + } + + if r.Routing != "" { + params["routing"] = r.Routing + } + + if len(r.Source) > 0 { + params["_source"] = strings.Join(r.Source, ",") + } + + if len(r.SourceExcludes) > 0 { + params["_source_excludes"] = strings.Join(r.SourceExcludes, ",") + } + + if len(r.SourceIncludes) > 0 { + params["_source_includes"] = strings.Join(r.SourceIncludes, ",") + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.DocumentType != "" { + params["type"] = r.DocumentType + } + + if r.WaitForActiveShards != "" { + params["wait_for_active_shards"] = r.WaitForActiveShards + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f Bulk) WithContext(v context.Context) func(*BulkRequest) { + return func(r *BulkRequest) { + r.ctx = v + } +} + +// WithIndex - default index for items which don't provide one. +// +func (f Bulk) WithIndex(v string) func(*BulkRequest) { + return func(r *BulkRequest) { + r.Index = v + } +} + +// WithDocumentType - default document type for items which don't provide one. +// +func (f Bulk) WithDocumentType(v string) func(*BulkRequest) { + return func(r *BulkRequest) { + r.DocumentType = v + } +} + +// WithPipeline - the pipeline ID to preprocess incoming documents with. +// +func (f Bulk) WithPipeline(v string) func(*BulkRequest) { + return func(r *BulkRequest) { + r.Pipeline = v + } +} + +// WithRefresh - if `true` then refresh the effected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` (the default) then do nothing with refreshes.. +// +func (f Bulk) WithRefresh(v string) func(*BulkRequest) { + return func(r *BulkRequest) { + r.Refresh = v + } +} + +// WithRouting - specific routing value. +// +func (f Bulk) WithRouting(v string) func(*BulkRequest) { + return func(r *BulkRequest) { + r.Routing = v + } +} + +// WithSource - true or false to return the _source field or not, or default list of fields to return, can be overridden on each sub-request. +// +func (f Bulk) WithSource(v ...string) func(*BulkRequest) { + return func(r *BulkRequest) { + r.Source = v + } +} + +// WithSourceExcludes - default list of fields to exclude from the returned _source field, can be overridden on each sub-request. +// +func (f Bulk) WithSourceExcludes(v ...string) func(*BulkRequest) { + return func(r *BulkRequest) { + r.SourceExcludes = v + } +} + +// WithSourceIncludes - default list of fields to extract and return from the _source field, can be overridden on each sub-request. +// +func (f Bulk) WithSourceIncludes(v ...string) func(*BulkRequest) { + return func(r *BulkRequest) { + r.SourceIncludes = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f Bulk) WithTimeout(v time.Duration) func(*BulkRequest) { + return func(r *BulkRequest) { + r.Timeout = v + } +} + +// WithWaitForActiveShards - sets the number of shard copies that must be active before proceeding with the bulk operation. defaults to 1, meaning the primary shard only. set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1). +// +func (f Bulk) WithWaitForActiveShards(v string) func(*BulkRequest) { + return func(r *BulkRequest) { + r.WaitForActiveShards = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f Bulk) WithPretty() func(*BulkRequest) { + return func(r *BulkRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f Bulk) WithHuman() func(*BulkRequest) { + return func(r *BulkRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f Bulk) WithErrorTrace() func(*BulkRequest) { + return func(r *BulkRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f Bulk) WithFilterPath(v ...string) func(*BulkRequest) { + return func(r *BulkRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f Bulk) WithHeader(h map[string]string) func(*BulkRequest) { + return func(r *BulkRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f Bulk) WithOpaqueID(s string) func(*BulkRequest) { + return func(r *BulkRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.aliases.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.aliases.go new file mode 100644 index 00000000000..ecb9a435331 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.aliases.go @@ -0,0 +1,280 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newCatAliasesFunc(t Transport) CatAliases { + return func(o ...func(*CatAliasesRequest)) (*Response, error) { + var r = CatAliasesRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CatAliases shows information about currently configured aliases to indices including filter and routing infos. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-alias.html. +// +type CatAliases func(o ...func(*CatAliasesRequest)) (*Response, error) + +// CatAliasesRequest configures the Cat Aliases API request. +// +type CatAliasesRequest struct { + Name []string + + Format string + H []string + Help *bool + Local *bool + S []string + V *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CatAliasesRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_cat") + 1 + len("aliases") + 1 + len(strings.Join(r.Name, ","))) + path.WriteString("/") + path.WriteString("_cat") + path.WriteString("/") + path.WriteString("aliases") + if len(r.Name) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Name, ",")) + } + + params = make(map[string]string) + + if r.Format != "" { + params["format"] = r.Format + } + + if len(r.H) > 0 { + params["h"] = strings.Join(r.H, ",") + } + + if r.Help != nil { + params["help"] = strconv.FormatBool(*r.Help) + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if len(r.S) > 0 { + params["s"] = strings.Join(r.S, ",") + } + + if r.V != nil { + params["v"] = strconv.FormatBool(*r.V) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CatAliases) WithContext(v context.Context) func(*CatAliasesRequest) { + return func(r *CatAliasesRequest) { + r.ctx = v + } +} + +// WithName - a list of alias names to return. +// +func (f CatAliases) WithName(v ...string) func(*CatAliasesRequest) { + return func(r *CatAliasesRequest) { + r.Name = v + } +} + +// WithFormat - a short version of the accept header, e.g. json, yaml. +// +func (f CatAliases) WithFormat(v string) func(*CatAliasesRequest) { + return func(r *CatAliasesRequest) { + r.Format = v + } +} + +// WithH - comma-separated list of column names to display. +// +func (f CatAliases) WithH(v ...string) func(*CatAliasesRequest) { + return func(r *CatAliasesRequest) { + r.H = v + } +} + +// WithHelp - return help information. +// +func (f CatAliases) WithHelp(v bool) func(*CatAliasesRequest) { + return func(r *CatAliasesRequest) { + r.Help = &v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f CatAliases) WithLocal(v bool) func(*CatAliasesRequest) { + return func(r *CatAliasesRequest) { + r.Local = &v + } +} + +// WithS - comma-separated list of column names or column aliases to sort by. +// +func (f CatAliases) WithS(v ...string) func(*CatAliasesRequest) { + return func(r *CatAliasesRequest) { + r.S = v + } +} + +// WithV - verbose mode. display column headers. +// +func (f CatAliases) WithV(v bool) func(*CatAliasesRequest) { + return func(r *CatAliasesRequest) { + r.V = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CatAliases) WithPretty() func(*CatAliasesRequest) { + return func(r *CatAliasesRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CatAliases) WithHuman() func(*CatAliasesRequest) { + return func(r *CatAliasesRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CatAliases) WithErrorTrace() func(*CatAliasesRequest) { + return func(r *CatAliasesRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CatAliases) WithFilterPath(v ...string) func(*CatAliasesRequest) { + return func(r *CatAliasesRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CatAliases) WithHeader(h map[string]string) func(*CatAliasesRequest) { + return func(r *CatAliasesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CatAliases) WithOpaqueID(s string) func(*CatAliasesRequest) { + return func(r *CatAliasesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.allocation.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.allocation.go new file mode 100644 index 00000000000..eed8fc6092d --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.allocation.go @@ -0,0 +1,307 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newCatAllocationFunc(t Transport) CatAllocation { + return func(o ...func(*CatAllocationRequest)) (*Response, error) { + var r = CatAllocationRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CatAllocation provides a snapshot of how many shards are allocated to each data node and how much disk space they are using. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-allocation.html. +// +type CatAllocation func(o ...func(*CatAllocationRequest)) (*Response, error) + +// CatAllocationRequest configures the Cat Allocation API request. +// +type CatAllocationRequest struct { + NodeID []string + + Bytes string + Format string + H []string + Help *bool + Local *bool + MasterTimeout time.Duration + S []string + V *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CatAllocationRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_cat") + 1 + len("allocation") + 1 + len(strings.Join(r.NodeID, ","))) + path.WriteString("/") + path.WriteString("_cat") + path.WriteString("/") + path.WriteString("allocation") + if len(r.NodeID) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.NodeID, ",")) + } + + params = make(map[string]string) + + if r.Bytes != "" { + params["bytes"] = r.Bytes + } + + if r.Format != "" { + params["format"] = r.Format + } + + if len(r.H) > 0 { + params["h"] = strings.Join(r.H, ",") + } + + if r.Help != nil { + params["help"] = strconv.FormatBool(*r.Help) + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if len(r.S) > 0 { + params["s"] = strings.Join(r.S, ",") + } + + if r.V != nil { + params["v"] = strconv.FormatBool(*r.V) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CatAllocation) WithContext(v context.Context) func(*CatAllocationRequest) { + return func(r *CatAllocationRequest) { + r.ctx = v + } +} + +// WithNodeID - a list of node ids or names to limit the returned information. +// +func (f CatAllocation) WithNodeID(v ...string) func(*CatAllocationRequest) { + return func(r *CatAllocationRequest) { + r.NodeID = v + } +} + +// WithBytes - the unit in which to display byte values. +// +func (f CatAllocation) WithBytes(v string) func(*CatAllocationRequest) { + return func(r *CatAllocationRequest) { + r.Bytes = v + } +} + +// WithFormat - a short version of the accept header, e.g. json, yaml. +// +func (f CatAllocation) WithFormat(v string) func(*CatAllocationRequest) { + return func(r *CatAllocationRequest) { + r.Format = v + } +} + +// WithH - comma-separated list of column names to display. +// +func (f CatAllocation) WithH(v ...string) func(*CatAllocationRequest) { + return func(r *CatAllocationRequest) { + r.H = v + } +} + +// WithHelp - return help information. +// +func (f CatAllocation) WithHelp(v bool) func(*CatAllocationRequest) { + return func(r *CatAllocationRequest) { + r.Help = &v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f CatAllocation) WithLocal(v bool) func(*CatAllocationRequest) { + return func(r *CatAllocationRequest) { + r.Local = &v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f CatAllocation) WithMasterTimeout(v time.Duration) func(*CatAllocationRequest) { + return func(r *CatAllocationRequest) { + r.MasterTimeout = v + } +} + +// WithS - comma-separated list of column names or column aliases to sort by. +// +func (f CatAllocation) WithS(v ...string) func(*CatAllocationRequest) { + return func(r *CatAllocationRequest) { + r.S = v + } +} + +// WithV - verbose mode. display column headers. +// +func (f CatAllocation) WithV(v bool) func(*CatAllocationRequest) { + return func(r *CatAllocationRequest) { + r.V = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CatAllocation) WithPretty() func(*CatAllocationRequest) { + return func(r *CatAllocationRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CatAllocation) WithHuman() func(*CatAllocationRequest) { + return func(r *CatAllocationRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CatAllocation) WithErrorTrace() func(*CatAllocationRequest) { + return func(r *CatAllocationRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CatAllocation) WithFilterPath(v ...string) func(*CatAllocationRequest) { + return func(r *CatAllocationRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CatAllocation) WithHeader(h map[string]string) func(*CatAllocationRequest) { + return func(r *CatAllocationRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CatAllocation) WithOpaqueID(s string) func(*CatAllocationRequest) { + return func(r *CatAllocationRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.count.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.count.go new file mode 100644 index 00000000000..e95a25f5c75 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.count.go @@ -0,0 +1,267 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newCatCountFunc(t Transport) CatCount { + return func(o ...func(*CatCountRequest)) (*Response, error) { + var r = CatCountRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CatCount provides quick access to the document count of the entire cluster, or individual indices. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-count.html. +// +type CatCount func(o ...func(*CatCountRequest)) (*Response, error) + +// CatCountRequest configures the Cat Count API request. +// +type CatCountRequest struct { + Index []string + + Format string + H []string + Help *bool + S []string + V *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CatCountRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_cat") + 1 + len("count") + 1 + len(strings.Join(r.Index, ","))) + path.WriteString("/") + path.WriteString("_cat") + path.WriteString("/") + path.WriteString("count") + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + + params = make(map[string]string) + + if r.Format != "" { + params["format"] = r.Format + } + + if len(r.H) > 0 { + params["h"] = strings.Join(r.H, ",") + } + + if r.Help != nil { + params["help"] = strconv.FormatBool(*r.Help) + } + + if len(r.S) > 0 { + params["s"] = strings.Join(r.S, ",") + } + + if r.V != nil { + params["v"] = strconv.FormatBool(*r.V) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CatCount) WithContext(v context.Context) func(*CatCountRequest) { + return func(r *CatCountRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names to limit the returned information. +// +func (f CatCount) WithIndex(v ...string) func(*CatCountRequest) { + return func(r *CatCountRequest) { + r.Index = v + } +} + +// WithFormat - a short version of the accept header, e.g. json, yaml. +// +func (f CatCount) WithFormat(v string) func(*CatCountRequest) { + return func(r *CatCountRequest) { + r.Format = v + } +} + +// WithH - comma-separated list of column names to display. +// +func (f CatCount) WithH(v ...string) func(*CatCountRequest) { + return func(r *CatCountRequest) { + r.H = v + } +} + +// WithHelp - return help information. +// +func (f CatCount) WithHelp(v bool) func(*CatCountRequest) { + return func(r *CatCountRequest) { + r.Help = &v + } +} + +// WithS - comma-separated list of column names or column aliases to sort by. +// +func (f CatCount) WithS(v ...string) func(*CatCountRequest) { + return func(r *CatCountRequest) { + r.S = v + } +} + +// WithV - verbose mode. display column headers. +// +func (f CatCount) WithV(v bool) func(*CatCountRequest) { + return func(r *CatCountRequest) { + r.V = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CatCount) WithPretty() func(*CatCountRequest) { + return func(r *CatCountRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CatCount) WithHuman() func(*CatCountRequest) { + return func(r *CatCountRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CatCount) WithErrorTrace() func(*CatCountRequest) { + return func(r *CatCountRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CatCount) WithFilterPath(v ...string) func(*CatCountRequest) { + return func(r *CatCountRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CatCount) WithHeader(h map[string]string) func(*CatCountRequest) { + return func(r *CatCountRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CatCount) WithOpaqueID(s string) func(*CatCountRequest) { + return func(r *CatCountRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.fielddata.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.fielddata.go new file mode 100644 index 00000000000..a41c8698396 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.fielddata.go @@ -0,0 +1,284 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newCatFielddataFunc(t Transport) CatFielddata { + return func(o ...func(*CatFielddataRequest)) (*Response, error) { + var r = CatFielddataRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CatFielddata shows how much heap memory is currently being used by fielddata on every data node in the cluster. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-fielddata.html. +// +type CatFielddata func(o ...func(*CatFielddataRequest)) (*Response, error) + +// CatFielddataRequest configures the Cat Fielddata API request. +// +type CatFielddataRequest struct { + Fields []string + + Bytes string + Format string + H []string + Help *bool + S []string + V *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CatFielddataRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_cat") + 1 + len("fielddata") + 1 + len(strings.Join(r.Fields, ","))) + path.WriteString("/") + path.WriteString("_cat") + path.WriteString("/") + path.WriteString("fielddata") + if len(r.Fields) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Fields, ",")) + } + + params = make(map[string]string) + + if r.Bytes != "" { + params["bytes"] = r.Bytes + } + + if len(r.Fields) > 0 { + params["fields"] = strings.Join(r.Fields, ",") + } + + if r.Format != "" { + params["format"] = r.Format + } + + if len(r.H) > 0 { + params["h"] = strings.Join(r.H, ",") + } + + if r.Help != nil { + params["help"] = strconv.FormatBool(*r.Help) + } + + if len(r.S) > 0 { + params["s"] = strings.Join(r.S, ",") + } + + if r.V != nil { + params["v"] = strconv.FormatBool(*r.V) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CatFielddata) WithContext(v context.Context) func(*CatFielddataRequest) { + return func(r *CatFielddataRequest) { + r.ctx = v + } +} + +// WithFields - a list of fields to return the fielddata size. +// +func (f CatFielddata) WithFields(v ...string) func(*CatFielddataRequest) { + return func(r *CatFielddataRequest) { + r.Fields = v + } +} + +// WithBytes - the unit in which to display byte values. +// +func (f CatFielddata) WithBytes(v string) func(*CatFielddataRequest) { + return func(r *CatFielddataRequest) { + r.Bytes = v + } +} + +// WithFormat - a short version of the accept header, e.g. json, yaml. +// +func (f CatFielddata) WithFormat(v string) func(*CatFielddataRequest) { + return func(r *CatFielddataRequest) { + r.Format = v + } +} + +// WithH - comma-separated list of column names to display. +// +func (f CatFielddata) WithH(v ...string) func(*CatFielddataRequest) { + return func(r *CatFielddataRequest) { + r.H = v + } +} + +// WithHelp - return help information. +// +func (f CatFielddata) WithHelp(v bool) func(*CatFielddataRequest) { + return func(r *CatFielddataRequest) { + r.Help = &v + } +} + +// WithS - comma-separated list of column names or column aliases to sort by. +// +func (f CatFielddata) WithS(v ...string) func(*CatFielddataRequest) { + return func(r *CatFielddataRequest) { + r.S = v + } +} + +// WithV - verbose mode. display column headers. +// +func (f CatFielddata) WithV(v bool) func(*CatFielddataRequest) { + return func(r *CatFielddataRequest) { + r.V = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CatFielddata) WithPretty() func(*CatFielddataRequest) { + return func(r *CatFielddataRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CatFielddata) WithHuman() func(*CatFielddataRequest) { + return func(r *CatFielddataRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CatFielddata) WithErrorTrace() func(*CatFielddataRequest) { + return func(r *CatFielddataRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CatFielddata) WithFilterPath(v ...string) func(*CatFielddataRequest) { + return func(r *CatFielddataRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CatFielddata) WithHeader(h map[string]string) func(*CatFielddataRequest) { + return func(r *CatFielddataRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CatFielddata) WithOpaqueID(s string) func(*CatFielddataRequest) { + return func(r *CatFielddataRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.health.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.health.go new file mode 100644 index 00000000000..d7276ede3e5 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.health.go @@ -0,0 +1,276 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newCatHealthFunc(t Transport) CatHealth { + return func(o ...func(*CatHealthRequest)) (*Response, error) { + var r = CatHealthRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CatHealth returns a concise representation of the cluster health. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-health.html. +// +type CatHealth func(o ...func(*CatHealthRequest)) (*Response, error) + +// CatHealthRequest configures the Cat Health API request. +// +type CatHealthRequest struct { + Format string + H []string + Help *bool + S []string + Time string + Ts *bool + V *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CatHealthRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_cat/health")) + path.WriteString("/_cat/health") + + params = make(map[string]string) + + if r.Format != "" { + params["format"] = r.Format + } + + if len(r.H) > 0 { + params["h"] = strings.Join(r.H, ",") + } + + if r.Help != nil { + params["help"] = strconv.FormatBool(*r.Help) + } + + if len(r.S) > 0 { + params["s"] = strings.Join(r.S, ",") + } + + if r.Time != "" { + params["time"] = r.Time + } + + if r.Ts != nil { + params["ts"] = strconv.FormatBool(*r.Ts) + } + + if r.V != nil { + params["v"] = strconv.FormatBool(*r.V) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CatHealth) WithContext(v context.Context) func(*CatHealthRequest) { + return func(r *CatHealthRequest) { + r.ctx = v + } +} + +// WithFormat - a short version of the accept header, e.g. json, yaml. +// +func (f CatHealth) WithFormat(v string) func(*CatHealthRequest) { + return func(r *CatHealthRequest) { + r.Format = v + } +} + +// WithH - comma-separated list of column names to display. +// +func (f CatHealth) WithH(v ...string) func(*CatHealthRequest) { + return func(r *CatHealthRequest) { + r.H = v + } +} + +// WithHelp - return help information. +// +func (f CatHealth) WithHelp(v bool) func(*CatHealthRequest) { + return func(r *CatHealthRequest) { + r.Help = &v + } +} + +// WithS - comma-separated list of column names or column aliases to sort by. +// +func (f CatHealth) WithS(v ...string) func(*CatHealthRequest) { + return func(r *CatHealthRequest) { + r.S = v + } +} + +// WithTime - the unit in which to display time values. +// +func (f CatHealth) WithTime(v string) func(*CatHealthRequest) { + return func(r *CatHealthRequest) { + r.Time = v + } +} + +// WithTs - set to false to disable timestamping. +// +func (f CatHealth) WithTs(v bool) func(*CatHealthRequest) { + return func(r *CatHealthRequest) { + r.Ts = &v + } +} + +// WithV - verbose mode. display column headers. +// +func (f CatHealth) WithV(v bool) func(*CatHealthRequest) { + return func(r *CatHealthRequest) { + r.V = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CatHealth) WithPretty() func(*CatHealthRequest) { + return func(r *CatHealthRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CatHealth) WithHuman() func(*CatHealthRequest) { + return func(r *CatHealthRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CatHealth) WithErrorTrace() func(*CatHealthRequest) { + return func(r *CatHealthRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CatHealth) WithFilterPath(v ...string) func(*CatHealthRequest) { + return func(r *CatHealthRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CatHealth) WithHeader(h map[string]string) func(*CatHealthRequest) { + return func(r *CatHealthRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CatHealth) WithOpaqueID(s string) func(*CatHealthRequest) { + return func(r *CatHealthRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.help.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.help.go new file mode 100644 index 00000000000..9232b895f2e --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.help.go @@ -0,0 +1,211 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newCatHelpFunc(t Transport) CatHelp { + return func(o ...func(*CatHelpRequest)) (*Response, error) { + var r = CatHelpRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CatHelp returns help for the Cat APIs. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat.html. +// +type CatHelp func(o ...func(*CatHelpRequest)) (*Response, error) + +// CatHelpRequest configures the Cat Help API request. +// +type CatHelpRequest struct { + Help *bool + S []string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CatHelpRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_cat")) + path.WriteString("/_cat") + + params = make(map[string]string) + + if r.Help != nil { + params["help"] = strconv.FormatBool(*r.Help) + } + + if len(r.S) > 0 { + params["s"] = strings.Join(r.S, ",") + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CatHelp) WithContext(v context.Context) func(*CatHelpRequest) { + return func(r *CatHelpRequest) { + r.ctx = v + } +} + +// WithHelp - return help information. +// +func (f CatHelp) WithHelp(v bool) func(*CatHelpRequest) { + return func(r *CatHelpRequest) { + r.Help = &v + } +} + +// WithS - comma-separated list of column names or column aliases to sort by. +// +func (f CatHelp) WithS(v ...string) func(*CatHelpRequest) { + return func(r *CatHelpRequest) { + r.S = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CatHelp) WithPretty() func(*CatHelpRequest) { + return func(r *CatHelpRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CatHelp) WithHuman() func(*CatHelpRequest) { + return func(r *CatHelpRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CatHelp) WithErrorTrace() func(*CatHelpRequest) { + return func(r *CatHelpRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CatHelp) WithFilterPath(v ...string) func(*CatHelpRequest) { + return func(r *CatHelpRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CatHelp) WithHeader(h map[string]string) func(*CatHelpRequest) { + return func(r *CatHelpRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CatHelp) WithOpaqueID(s string) func(*CatHelpRequest) { + return func(r *CatHelpRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.indices.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.indices.go new file mode 100644 index 00000000000..14df4be32fc --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.indices.go @@ -0,0 +1,359 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newCatIndicesFunc(t Transport) CatIndices { + return func(o ...func(*CatIndicesRequest)) (*Response, error) { + var r = CatIndicesRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CatIndices returns information about indices: number of primaries and replicas, document counts, disk size, ... +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-indices.html. +// +type CatIndices func(o ...func(*CatIndicesRequest)) (*Response, error) + +// CatIndicesRequest configures the Cat Indices API request. +// +type CatIndicesRequest struct { + Index []string + + Bytes string + Format string + H []string + Health string + Help *bool + IncludeUnloadedSegments *bool + Local *bool + MasterTimeout time.Duration + Pri *bool + S []string + Time string + V *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CatIndicesRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_cat") + 1 + len("indices") + 1 + len(strings.Join(r.Index, ","))) + path.WriteString("/") + path.WriteString("_cat") + path.WriteString("/") + path.WriteString("indices") + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + + params = make(map[string]string) + + if r.Bytes != "" { + params["bytes"] = r.Bytes + } + + if r.Format != "" { + params["format"] = r.Format + } + + if len(r.H) > 0 { + params["h"] = strings.Join(r.H, ",") + } + + if r.Health != "" { + params["health"] = r.Health + } + + if r.Help != nil { + params["help"] = strconv.FormatBool(*r.Help) + } + + if r.IncludeUnloadedSegments != nil { + params["include_unloaded_segments"] = strconv.FormatBool(*r.IncludeUnloadedSegments) + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Pri != nil { + params["pri"] = strconv.FormatBool(*r.Pri) + } + + if len(r.S) > 0 { + params["s"] = strings.Join(r.S, ",") + } + + if r.Time != "" { + params["time"] = r.Time + } + + if r.V != nil { + params["v"] = strconv.FormatBool(*r.V) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CatIndices) WithContext(v context.Context) func(*CatIndicesRequest) { + return func(r *CatIndicesRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names to limit the returned information. +// +func (f CatIndices) WithIndex(v ...string) func(*CatIndicesRequest) { + return func(r *CatIndicesRequest) { + r.Index = v + } +} + +// WithBytes - the unit in which to display byte values. +// +func (f CatIndices) WithBytes(v string) func(*CatIndicesRequest) { + return func(r *CatIndicesRequest) { + r.Bytes = v + } +} + +// WithFormat - a short version of the accept header, e.g. json, yaml. +// +func (f CatIndices) WithFormat(v string) func(*CatIndicesRequest) { + return func(r *CatIndicesRequest) { + r.Format = v + } +} + +// WithH - comma-separated list of column names to display. +// +func (f CatIndices) WithH(v ...string) func(*CatIndicesRequest) { + return func(r *CatIndicesRequest) { + r.H = v + } +} + +// WithHealth - a health status ("green", "yellow", or "red" to filter only indices matching the specified health status. +// +func (f CatIndices) WithHealth(v string) func(*CatIndicesRequest) { + return func(r *CatIndicesRequest) { + r.Health = v + } +} + +// WithHelp - return help information. +// +func (f CatIndices) WithHelp(v bool) func(*CatIndicesRequest) { + return func(r *CatIndicesRequest) { + r.Help = &v + } +} + +// WithIncludeUnloadedSegments - if set to true segment stats will include stats for segments that are not currently loaded into memory. +// +func (f CatIndices) WithIncludeUnloadedSegments(v bool) func(*CatIndicesRequest) { + return func(r *CatIndicesRequest) { + r.IncludeUnloadedSegments = &v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f CatIndices) WithLocal(v bool) func(*CatIndicesRequest) { + return func(r *CatIndicesRequest) { + r.Local = &v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f CatIndices) WithMasterTimeout(v time.Duration) func(*CatIndicesRequest) { + return func(r *CatIndicesRequest) { + r.MasterTimeout = v + } +} + +// WithPri - set to true to return stats only for primary shards. +// +func (f CatIndices) WithPri(v bool) func(*CatIndicesRequest) { + return func(r *CatIndicesRequest) { + r.Pri = &v + } +} + +// WithS - comma-separated list of column names or column aliases to sort by. +// +func (f CatIndices) WithS(v ...string) func(*CatIndicesRequest) { + return func(r *CatIndicesRequest) { + r.S = v + } +} + +// WithTime - the unit in which to display time values. +// +func (f CatIndices) WithTime(v string) func(*CatIndicesRequest) { + return func(r *CatIndicesRequest) { + r.Time = v + } +} + +// WithV - verbose mode. display column headers. +// +func (f CatIndices) WithV(v bool) func(*CatIndicesRequest) { + return func(r *CatIndicesRequest) { + r.V = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CatIndices) WithPretty() func(*CatIndicesRequest) { + return func(r *CatIndicesRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CatIndices) WithHuman() func(*CatIndicesRequest) { + return func(r *CatIndicesRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CatIndices) WithErrorTrace() func(*CatIndicesRequest) { + return func(r *CatIndicesRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CatIndices) WithFilterPath(v ...string) func(*CatIndicesRequest) { + return func(r *CatIndicesRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CatIndices) WithHeader(h map[string]string) func(*CatIndicesRequest) { + return func(r *CatIndicesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CatIndices) WithOpaqueID(s string) func(*CatIndicesRequest) { + return func(r *CatIndicesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.master.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.master.go new file mode 100644 index 00000000000..f42c1fb018c --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.master.go @@ -0,0 +1,277 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newCatMasterFunc(t Transport) CatMaster { + return func(o ...func(*CatMasterRequest)) (*Response, error) { + var r = CatMasterRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CatMaster returns information about the master node. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-master.html. +// +type CatMaster func(o ...func(*CatMasterRequest)) (*Response, error) + +// CatMasterRequest configures the Cat Master API request. +// +type CatMasterRequest struct { + Format string + H []string + Help *bool + Local *bool + MasterTimeout time.Duration + S []string + V *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CatMasterRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_cat/master")) + path.WriteString("/_cat/master") + + params = make(map[string]string) + + if r.Format != "" { + params["format"] = r.Format + } + + if len(r.H) > 0 { + params["h"] = strings.Join(r.H, ",") + } + + if r.Help != nil { + params["help"] = strconv.FormatBool(*r.Help) + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if len(r.S) > 0 { + params["s"] = strings.Join(r.S, ",") + } + + if r.V != nil { + params["v"] = strconv.FormatBool(*r.V) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CatMaster) WithContext(v context.Context) func(*CatMasterRequest) { + return func(r *CatMasterRequest) { + r.ctx = v + } +} + +// WithFormat - a short version of the accept header, e.g. json, yaml. +// +func (f CatMaster) WithFormat(v string) func(*CatMasterRequest) { + return func(r *CatMasterRequest) { + r.Format = v + } +} + +// WithH - comma-separated list of column names to display. +// +func (f CatMaster) WithH(v ...string) func(*CatMasterRequest) { + return func(r *CatMasterRequest) { + r.H = v + } +} + +// WithHelp - return help information. +// +func (f CatMaster) WithHelp(v bool) func(*CatMasterRequest) { + return func(r *CatMasterRequest) { + r.Help = &v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f CatMaster) WithLocal(v bool) func(*CatMasterRequest) { + return func(r *CatMasterRequest) { + r.Local = &v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f CatMaster) WithMasterTimeout(v time.Duration) func(*CatMasterRequest) { + return func(r *CatMasterRequest) { + r.MasterTimeout = v + } +} + +// WithS - comma-separated list of column names or column aliases to sort by. +// +func (f CatMaster) WithS(v ...string) func(*CatMasterRequest) { + return func(r *CatMasterRequest) { + r.S = v + } +} + +// WithV - verbose mode. display column headers. +// +func (f CatMaster) WithV(v bool) func(*CatMasterRequest) { + return func(r *CatMasterRequest) { + r.V = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CatMaster) WithPretty() func(*CatMasterRequest) { + return func(r *CatMasterRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CatMaster) WithHuman() func(*CatMasterRequest) { + return func(r *CatMasterRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CatMaster) WithErrorTrace() func(*CatMasterRequest) { + return func(r *CatMasterRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CatMaster) WithFilterPath(v ...string) func(*CatMasterRequest) { + return func(r *CatMasterRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CatMaster) WithHeader(h map[string]string) func(*CatMasterRequest) { + return func(r *CatMasterRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CatMaster) WithOpaqueID(s string) func(*CatMasterRequest) { + return func(r *CatMasterRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.nodeattrs.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.nodeattrs.go new file mode 100644 index 00000000000..ba2c6700351 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.nodeattrs.go @@ -0,0 +1,277 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newCatNodeattrsFunc(t Transport) CatNodeattrs { + return func(o ...func(*CatNodeattrsRequest)) (*Response, error) { + var r = CatNodeattrsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CatNodeattrs returns information about custom node attributes. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-nodeattrs.html. +// +type CatNodeattrs func(o ...func(*CatNodeattrsRequest)) (*Response, error) + +// CatNodeattrsRequest configures the Cat Nodeattrs API request. +// +type CatNodeattrsRequest struct { + Format string + H []string + Help *bool + Local *bool + MasterTimeout time.Duration + S []string + V *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CatNodeattrsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_cat/nodeattrs")) + path.WriteString("/_cat/nodeattrs") + + params = make(map[string]string) + + if r.Format != "" { + params["format"] = r.Format + } + + if len(r.H) > 0 { + params["h"] = strings.Join(r.H, ",") + } + + if r.Help != nil { + params["help"] = strconv.FormatBool(*r.Help) + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if len(r.S) > 0 { + params["s"] = strings.Join(r.S, ",") + } + + if r.V != nil { + params["v"] = strconv.FormatBool(*r.V) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CatNodeattrs) WithContext(v context.Context) func(*CatNodeattrsRequest) { + return func(r *CatNodeattrsRequest) { + r.ctx = v + } +} + +// WithFormat - a short version of the accept header, e.g. json, yaml. +// +func (f CatNodeattrs) WithFormat(v string) func(*CatNodeattrsRequest) { + return func(r *CatNodeattrsRequest) { + r.Format = v + } +} + +// WithH - comma-separated list of column names to display. +// +func (f CatNodeattrs) WithH(v ...string) func(*CatNodeattrsRequest) { + return func(r *CatNodeattrsRequest) { + r.H = v + } +} + +// WithHelp - return help information. +// +func (f CatNodeattrs) WithHelp(v bool) func(*CatNodeattrsRequest) { + return func(r *CatNodeattrsRequest) { + r.Help = &v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f CatNodeattrs) WithLocal(v bool) func(*CatNodeattrsRequest) { + return func(r *CatNodeattrsRequest) { + r.Local = &v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f CatNodeattrs) WithMasterTimeout(v time.Duration) func(*CatNodeattrsRequest) { + return func(r *CatNodeattrsRequest) { + r.MasterTimeout = v + } +} + +// WithS - comma-separated list of column names or column aliases to sort by. +// +func (f CatNodeattrs) WithS(v ...string) func(*CatNodeattrsRequest) { + return func(r *CatNodeattrsRequest) { + r.S = v + } +} + +// WithV - verbose mode. display column headers. +// +func (f CatNodeattrs) WithV(v bool) func(*CatNodeattrsRequest) { + return func(r *CatNodeattrsRequest) { + r.V = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CatNodeattrs) WithPretty() func(*CatNodeattrsRequest) { + return func(r *CatNodeattrsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CatNodeattrs) WithHuman() func(*CatNodeattrsRequest) { + return func(r *CatNodeattrsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CatNodeattrs) WithErrorTrace() func(*CatNodeattrsRequest) { + return func(r *CatNodeattrsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CatNodeattrs) WithFilterPath(v ...string) func(*CatNodeattrsRequest) { + return func(r *CatNodeattrsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CatNodeattrs) WithHeader(h map[string]string) func(*CatNodeattrsRequest) { + return func(r *CatNodeattrsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CatNodeattrs) WithOpaqueID(s string) func(*CatNodeattrsRequest) { + return func(r *CatNodeattrsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.nodes.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.nodes.go new file mode 100644 index 00000000000..911282a10a6 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.nodes.go @@ -0,0 +1,316 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newCatNodesFunc(t Transport) CatNodes { + return func(o ...func(*CatNodesRequest)) (*Response, error) { + var r = CatNodesRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CatNodes returns basic statistics about performance of cluster nodes. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-nodes.html. +// +type CatNodes func(o ...func(*CatNodesRequest)) (*Response, error) + +// CatNodesRequest configures the Cat Nodes API request. +// +type CatNodesRequest struct { + Bytes string + Format string + FullID *bool + H []string + Help *bool + Local *bool + MasterTimeout time.Duration + S []string + Time string + V *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CatNodesRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_cat/nodes")) + path.WriteString("/_cat/nodes") + + params = make(map[string]string) + + if r.Bytes != "" { + params["bytes"] = r.Bytes + } + + if r.Format != "" { + params["format"] = r.Format + } + + if r.FullID != nil { + params["full_id"] = strconv.FormatBool(*r.FullID) + } + + if len(r.H) > 0 { + params["h"] = strings.Join(r.H, ",") + } + + if r.Help != nil { + params["help"] = strconv.FormatBool(*r.Help) + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if len(r.S) > 0 { + params["s"] = strings.Join(r.S, ",") + } + + if r.Time != "" { + params["time"] = r.Time + } + + if r.V != nil { + params["v"] = strconv.FormatBool(*r.V) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CatNodes) WithContext(v context.Context) func(*CatNodesRequest) { + return func(r *CatNodesRequest) { + r.ctx = v + } +} + +// WithBytes - the unit in which to display byte values. +// +func (f CatNodes) WithBytes(v string) func(*CatNodesRequest) { + return func(r *CatNodesRequest) { + r.Bytes = v + } +} + +// WithFormat - a short version of the accept header, e.g. json, yaml. +// +func (f CatNodes) WithFormat(v string) func(*CatNodesRequest) { + return func(r *CatNodesRequest) { + r.Format = v + } +} + +// WithFullID - return the full node ID instead of the shortened version (default: false). +// +func (f CatNodes) WithFullID(v bool) func(*CatNodesRequest) { + return func(r *CatNodesRequest) { + r.FullID = &v + } +} + +// WithH - comma-separated list of column names to display. +// +func (f CatNodes) WithH(v ...string) func(*CatNodesRequest) { + return func(r *CatNodesRequest) { + r.H = v + } +} + +// WithHelp - return help information. +// +func (f CatNodes) WithHelp(v bool) func(*CatNodesRequest) { + return func(r *CatNodesRequest) { + r.Help = &v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f CatNodes) WithLocal(v bool) func(*CatNodesRequest) { + return func(r *CatNodesRequest) { + r.Local = &v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f CatNodes) WithMasterTimeout(v time.Duration) func(*CatNodesRequest) { + return func(r *CatNodesRequest) { + r.MasterTimeout = v + } +} + +// WithS - comma-separated list of column names or column aliases to sort by. +// +func (f CatNodes) WithS(v ...string) func(*CatNodesRequest) { + return func(r *CatNodesRequest) { + r.S = v + } +} + +// WithTime - the unit in which to display time values. +// +func (f CatNodes) WithTime(v string) func(*CatNodesRequest) { + return func(r *CatNodesRequest) { + r.Time = v + } +} + +// WithV - verbose mode. display column headers. +// +func (f CatNodes) WithV(v bool) func(*CatNodesRequest) { + return func(r *CatNodesRequest) { + r.V = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CatNodes) WithPretty() func(*CatNodesRequest) { + return func(r *CatNodesRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CatNodes) WithHuman() func(*CatNodesRequest) { + return func(r *CatNodesRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CatNodes) WithErrorTrace() func(*CatNodesRequest) { + return func(r *CatNodesRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CatNodes) WithFilterPath(v ...string) func(*CatNodesRequest) { + return func(r *CatNodesRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CatNodes) WithHeader(h map[string]string) func(*CatNodesRequest) { + return func(r *CatNodesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CatNodes) WithOpaqueID(s string) func(*CatNodesRequest) { + return func(r *CatNodesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.pending_tasks.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.pending_tasks.go new file mode 100644 index 00000000000..7cdedd0fd88 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.pending_tasks.go @@ -0,0 +1,290 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newCatPendingTasksFunc(t Transport) CatPendingTasks { + return func(o ...func(*CatPendingTasksRequest)) (*Response, error) { + var r = CatPendingTasksRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CatPendingTasks returns a concise representation of the cluster pending tasks. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-pending-tasks.html. +// +type CatPendingTasks func(o ...func(*CatPendingTasksRequest)) (*Response, error) + +// CatPendingTasksRequest configures the Cat Pending Tasks API request. +// +type CatPendingTasksRequest struct { + Format string + H []string + Help *bool + Local *bool + MasterTimeout time.Duration + S []string + Time string + V *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CatPendingTasksRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_cat/pending_tasks")) + path.WriteString("/_cat/pending_tasks") + + params = make(map[string]string) + + if r.Format != "" { + params["format"] = r.Format + } + + if len(r.H) > 0 { + params["h"] = strings.Join(r.H, ",") + } + + if r.Help != nil { + params["help"] = strconv.FormatBool(*r.Help) + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if len(r.S) > 0 { + params["s"] = strings.Join(r.S, ",") + } + + if r.Time != "" { + params["time"] = r.Time + } + + if r.V != nil { + params["v"] = strconv.FormatBool(*r.V) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CatPendingTasks) WithContext(v context.Context) func(*CatPendingTasksRequest) { + return func(r *CatPendingTasksRequest) { + r.ctx = v + } +} + +// WithFormat - a short version of the accept header, e.g. json, yaml. +// +func (f CatPendingTasks) WithFormat(v string) func(*CatPendingTasksRequest) { + return func(r *CatPendingTasksRequest) { + r.Format = v + } +} + +// WithH - comma-separated list of column names to display. +// +func (f CatPendingTasks) WithH(v ...string) func(*CatPendingTasksRequest) { + return func(r *CatPendingTasksRequest) { + r.H = v + } +} + +// WithHelp - return help information. +// +func (f CatPendingTasks) WithHelp(v bool) func(*CatPendingTasksRequest) { + return func(r *CatPendingTasksRequest) { + r.Help = &v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f CatPendingTasks) WithLocal(v bool) func(*CatPendingTasksRequest) { + return func(r *CatPendingTasksRequest) { + r.Local = &v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f CatPendingTasks) WithMasterTimeout(v time.Duration) func(*CatPendingTasksRequest) { + return func(r *CatPendingTasksRequest) { + r.MasterTimeout = v + } +} + +// WithS - comma-separated list of column names or column aliases to sort by. +// +func (f CatPendingTasks) WithS(v ...string) func(*CatPendingTasksRequest) { + return func(r *CatPendingTasksRequest) { + r.S = v + } +} + +// WithTime - the unit in which to display time values. +// +func (f CatPendingTasks) WithTime(v string) func(*CatPendingTasksRequest) { + return func(r *CatPendingTasksRequest) { + r.Time = v + } +} + +// WithV - verbose mode. display column headers. +// +func (f CatPendingTasks) WithV(v bool) func(*CatPendingTasksRequest) { + return func(r *CatPendingTasksRequest) { + r.V = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CatPendingTasks) WithPretty() func(*CatPendingTasksRequest) { + return func(r *CatPendingTasksRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CatPendingTasks) WithHuman() func(*CatPendingTasksRequest) { + return func(r *CatPendingTasksRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CatPendingTasks) WithErrorTrace() func(*CatPendingTasksRequest) { + return func(r *CatPendingTasksRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CatPendingTasks) WithFilterPath(v ...string) func(*CatPendingTasksRequest) { + return func(r *CatPendingTasksRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CatPendingTasks) WithHeader(h map[string]string) func(*CatPendingTasksRequest) { + return func(r *CatPendingTasksRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CatPendingTasks) WithOpaqueID(s string) func(*CatPendingTasksRequest) { + return func(r *CatPendingTasksRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.plugins.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.plugins.go new file mode 100644 index 00000000000..fc2c92c4f2f --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.plugins.go @@ -0,0 +1,277 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newCatPluginsFunc(t Transport) CatPlugins { + return func(o ...func(*CatPluginsRequest)) (*Response, error) { + var r = CatPluginsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CatPlugins returns information about installed plugins across nodes node. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-plugins.html. +// +type CatPlugins func(o ...func(*CatPluginsRequest)) (*Response, error) + +// CatPluginsRequest configures the Cat Plugins API request. +// +type CatPluginsRequest struct { + Format string + H []string + Help *bool + Local *bool + MasterTimeout time.Duration + S []string + V *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CatPluginsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_cat/plugins")) + path.WriteString("/_cat/plugins") + + params = make(map[string]string) + + if r.Format != "" { + params["format"] = r.Format + } + + if len(r.H) > 0 { + params["h"] = strings.Join(r.H, ",") + } + + if r.Help != nil { + params["help"] = strconv.FormatBool(*r.Help) + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if len(r.S) > 0 { + params["s"] = strings.Join(r.S, ",") + } + + if r.V != nil { + params["v"] = strconv.FormatBool(*r.V) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CatPlugins) WithContext(v context.Context) func(*CatPluginsRequest) { + return func(r *CatPluginsRequest) { + r.ctx = v + } +} + +// WithFormat - a short version of the accept header, e.g. json, yaml. +// +func (f CatPlugins) WithFormat(v string) func(*CatPluginsRequest) { + return func(r *CatPluginsRequest) { + r.Format = v + } +} + +// WithH - comma-separated list of column names to display. +// +func (f CatPlugins) WithH(v ...string) func(*CatPluginsRequest) { + return func(r *CatPluginsRequest) { + r.H = v + } +} + +// WithHelp - return help information. +// +func (f CatPlugins) WithHelp(v bool) func(*CatPluginsRequest) { + return func(r *CatPluginsRequest) { + r.Help = &v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f CatPlugins) WithLocal(v bool) func(*CatPluginsRequest) { + return func(r *CatPluginsRequest) { + r.Local = &v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f CatPlugins) WithMasterTimeout(v time.Duration) func(*CatPluginsRequest) { + return func(r *CatPluginsRequest) { + r.MasterTimeout = v + } +} + +// WithS - comma-separated list of column names or column aliases to sort by. +// +func (f CatPlugins) WithS(v ...string) func(*CatPluginsRequest) { + return func(r *CatPluginsRequest) { + r.S = v + } +} + +// WithV - verbose mode. display column headers. +// +func (f CatPlugins) WithV(v bool) func(*CatPluginsRequest) { + return func(r *CatPluginsRequest) { + r.V = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CatPlugins) WithPretty() func(*CatPluginsRequest) { + return func(r *CatPluginsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CatPlugins) WithHuman() func(*CatPluginsRequest) { + return func(r *CatPluginsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CatPlugins) WithErrorTrace() func(*CatPluginsRequest) { + return func(r *CatPluginsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CatPlugins) WithFilterPath(v ...string) func(*CatPluginsRequest) { + return func(r *CatPluginsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CatPlugins) WithHeader(h map[string]string) func(*CatPluginsRequest) { + return func(r *CatPluginsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CatPlugins) WithOpaqueID(s string) func(*CatPluginsRequest) { + return func(r *CatPluginsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.recovery.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.recovery.go new file mode 100644 index 00000000000..2af7694c161 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.recovery.go @@ -0,0 +1,323 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newCatRecoveryFunc(t Transport) CatRecovery { + return func(o ...func(*CatRecoveryRequest)) (*Response, error) { + var r = CatRecoveryRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CatRecovery returns information about index shard recoveries, both on-going completed. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-recovery.html. +// +type CatRecovery func(o ...func(*CatRecoveryRequest)) (*Response, error) + +// CatRecoveryRequest configures the Cat Recovery API request. +// +type CatRecoveryRequest struct { + Index []string + + ActiveOnly *bool + Bytes string + Detailed *bool + Format string + H []string + Help *bool + S []string + Time string + V *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CatRecoveryRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_cat") + 1 + len("recovery") + 1 + len(strings.Join(r.Index, ","))) + path.WriteString("/") + path.WriteString("_cat") + path.WriteString("/") + path.WriteString("recovery") + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + + params = make(map[string]string) + + if r.ActiveOnly != nil { + params["active_only"] = strconv.FormatBool(*r.ActiveOnly) + } + + if r.Bytes != "" { + params["bytes"] = r.Bytes + } + + if r.Detailed != nil { + params["detailed"] = strconv.FormatBool(*r.Detailed) + } + + if r.Format != "" { + params["format"] = r.Format + } + + if len(r.H) > 0 { + params["h"] = strings.Join(r.H, ",") + } + + if r.Help != nil { + params["help"] = strconv.FormatBool(*r.Help) + } + + if len(r.Index) > 0 { + params["index"] = strings.Join(r.Index, ",") + } + + if len(r.S) > 0 { + params["s"] = strings.Join(r.S, ",") + } + + if r.Time != "" { + params["time"] = r.Time + } + + if r.V != nil { + params["v"] = strconv.FormatBool(*r.V) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CatRecovery) WithContext(v context.Context) func(*CatRecoveryRequest) { + return func(r *CatRecoveryRequest) { + r.ctx = v + } +} + +// WithIndex - comma-separated list or wildcard expression of index names to limit the returned information. +// +func (f CatRecovery) WithIndex(v ...string) func(*CatRecoveryRequest) { + return func(r *CatRecoveryRequest) { + r.Index = v + } +} + +// WithActiveOnly - if `true`, the response only includes ongoing shard recoveries. +// +func (f CatRecovery) WithActiveOnly(v bool) func(*CatRecoveryRequest) { + return func(r *CatRecoveryRequest) { + r.ActiveOnly = &v + } +} + +// WithBytes - the unit in which to display byte values. +// +func (f CatRecovery) WithBytes(v string) func(*CatRecoveryRequest) { + return func(r *CatRecoveryRequest) { + r.Bytes = v + } +} + +// WithDetailed - if `true`, the response includes detailed information about shard recoveries. +// +func (f CatRecovery) WithDetailed(v bool) func(*CatRecoveryRequest) { + return func(r *CatRecoveryRequest) { + r.Detailed = &v + } +} + +// WithFormat - a short version of the accept header, e.g. json, yaml. +// +func (f CatRecovery) WithFormat(v string) func(*CatRecoveryRequest) { + return func(r *CatRecoveryRequest) { + r.Format = v + } +} + +// WithH - comma-separated list of column names to display. +// +func (f CatRecovery) WithH(v ...string) func(*CatRecoveryRequest) { + return func(r *CatRecoveryRequest) { + r.H = v + } +} + +// WithHelp - return help information. +// +func (f CatRecovery) WithHelp(v bool) func(*CatRecoveryRequest) { + return func(r *CatRecoveryRequest) { + r.Help = &v + } +} + +// WithS - comma-separated list of column names or column aliases to sort by. +// +func (f CatRecovery) WithS(v ...string) func(*CatRecoveryRequest) { + return func(r *CatRecoveryRequest) { + r.S = v + } +} + +// WithTime - the unit in which to display time values. +// +func (f CatRecovery) WithTime(v string) func(*CatRecoveryRequest) { + return func(r *CatRecoveryRequest) { + r.Time = v + } +} + +// WithV - verbose mode. display column headers. +// +func (f CatRecovery) WithV(v bool) func(*CatRecoveryRequest) { + return func(r *CatRecoveryRequest) { + r.V = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CatRecovery) WithPretty() func(*CatRecoveryRequest) { + return func(r *CatRecoveryRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CatRecovery) WithHuman() func(*CatRecoveryRequest) { + return func(r *CatRecoveryRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CatRecovery) WithErrorTrace() func(*CatRecoveryRequest) { + return func(r *CatRecoveryRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CatRecovery) WithFilterPath(v ...string) func(*CatRecoveryRequest) { + return func(r *CatRecoveryRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CatRecovery) WithHeader(h map[string]string) func(*CatRecoveryRequest) { + return func(r *CatRecoveryRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CatRecovery) WithOpaqueID(s string) func(*CatRecoveryRequest) { + return func(r *CatRecoveryRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.repositories.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.repositories.go new file mode 100644 index 00000000000..9ad925e3963 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.repositories.go @@ -0,0 +1,277 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newCatRepositoriesFunc(t Transport) CatRepositories { + return func(o ...func(*CatRepositoriesRequest)) (*Response, error) { + var r = CatRepositoriesRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CatRepositories returns information about snapshot repositories registered in the cluster. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-repositories.html. +// +type CatRepositories func(o ...func(*CatRepositoriesRequest)) (*Response, error) + +// CatRepositoriesRequest configures the Cat Repositories API request. +// +type CatRepositoriesRequest struct { + Format string + H []string + Help *bool + Local *bool + MasterTimeout time.Duration + S []string + V *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CatRepositoriesRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_cat/repositories")) + path.WriteString("/_cat/repositories") + + params = make(map[string]string) + + if r.Format != "" { + params["format"] = r.Format + } + + if len(r.H) > 0 { + params["h"] = strings.Join(r.H, ",") + } + + if r.Help != nil { + params["help"] = strconv.FormatBool(*r.Help) + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if len(r.S) > 0 { + params["s"] = strings.Join(r.S, ",") + } + + if r.V != nil { + params["v"] = strconv.FormatBool(*r.V) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CatRepositories) WithContext(v context.Context) func(*CatRepositoriesRequest) { + return func(r *CatRepositoriesRequest) { + r.ctx = v + } +} + +// WithFormat - a short version of the accept header, e.g. json, yaml. +// +func (f CatRepositories) WithFormat(v string) func(*CatRepositoriesRequest) { + return func(r *CatRepositoriesRequest) { + r.Format = v + } +} + +// WithH - comma-separated list of column names to display. +// +func (f CatRepositories) WithH(v ...string) func(*CatRepositoriesRequest) { + return func(r *CatRepositoriesRequest) { + r.H = v + } +} + +// WithHelp - return help information. +// +func (f CatRepositories) WithHelp(v bool) func(*CatRepositoriesRequest) { + return func(r *CatRepositoriesRequest) { + r.Help = &v + } +} + +// WithLocal - return local information, do not retrieve the state from master node. +// +func (f CatRepositories) WithLocal(v bool) func(*CatRepositoriesRequest) { + return func(r *CatRepositoriesRequest) { + r.Local = &v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f CatRepositories) WithMasterTimeout(v time.Duration) func(*CatRepositoriesRequest) { + return func(r *CatRepositoriesRequest) { + r.MasterTimeout = v + } +} + +// WithS - comma-separated list of column names or column aliases to sort by. +// +func (f CatRepositories) WithS(v ...string) func(*CatRepositoriesRequest) { + return func(r *CatRepositoriesRequest) { + r.S = v + } +} + +// WithV - verbose mode. display column headers. +// +func (f CatRepositories) WithV(v bool) func(*CatRepositoriesRequest) { + return func(r *CatRepositoriesRequest) { + r.V = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CatRepositories) WithPretty() func(*CatRepositoriesRequest) { + return func(r *CatRepositoriesRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CatRepositories) WithHuman() func(*CatRepositoriesRequest) { + return func(r *CatRepositoriesRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CatRepositories) WithErrorTrace() func(*CatRepositoriesRequest) { + return func(r *CatRepositoriesRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CatRepositories) WithFilterPath(v ...string) func(*CatRepositoriesRequest) { + return func(r *CatRepositoriesRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CatRepositories) WithHeader(h map[string]string) func(*CatRepositoriesRequest) { + return func(r *CatRepositoriesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CatRepositories) WithOpaqueID(s string) func(*CatRepositoriesRequest) { + return func(r *CatRepositoriesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.segments.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.segments.go new file mode 100644 index 00000000000..126259df86d --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.segments.go @@ -0,0 +1,280 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newCatSegmentsFunc(t Transport) CatSegments { + return func(o ...func(*CatSegmentsRequest)) (*Response, error) { + var r = CatSegmentsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CatSegments provides low-level information about the segments in the shards of an index. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-segments.html. +// +type CatSegments func(o ...func(*CatSegmentsRequest)) (*Response, error) + +// CatSegmentsRequest configures the Cat Segments API request. +// +type CatSegmentsRequest struct { + Index []string + + Bytes string + Format string + H []string + Help *bool + S []string + V *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CatSegmentsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_cat") + 1 + len("segments") + 1 + len(strings.Join(r.Index, ","))) + path.WriteString("/") + path.WriteString("_cat") + path.WriteString("/") + path.WriteString("segments") + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + + params = make(map[string]string) + + if r.Bytes != "" { + params["bytes"] = r.Bytes + } + + if r.Format != "" { + params["format"] = r.Format + } + + if len(r.H) > 0 { + params["h"] = strings.Join(r.H, ",") + } + + if r.Help != nil { + params["help"] = strconv.FormatBool(*r.Help) + } + + if len(r.S) > 0 { + params["s"] = strings.Join(r.S, ",") + } + + if r.V != nil { + params["v"] = strconv.FormatBool(*r.V) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CatSegments) WithContext(v context.Context) func(*CatSegmentsRequest) { + return func(r *CatSegmentsRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names to limit the returned information. +// +func (f CatSegments) WithIndex(v ...string) func(*CatSegmentsRequest) { + return func(r *CatSegmentsRequest) { + r.Index = v + } +} + +// WithBytes - the unit in which to display byte values. +// +func (f CatSegments) WithBytes(v string) func(*CatSegmentsRequest) { + return func(r *CatSegmentsRequest) { + r.Bytes = v + } +} + +// WithFormat - a short version of the accept header, e.g. json, yaml. +// +func (f CatSegments) WithFormat(v string) func(*CatSegmentsRequest) { + return func(r *CatSegmentsRequest) { + r.Format = v + } +} + +// WithH - comma-separated list of column names to display. +// +func (f CatSegments) WithH(v ...string) func(*CatSegmentsRequest) { + return func(r *CatSegmentsRequest) { + r.H = v + } +} + +// WithHelp - return help information. +// +func (f CatSegments) WithHelp(v bool) func(*CatSegmentsRequest) { + return func(r *CatSegmentsRequest) { + r.Help = &v + } +} + +// WithS - comma-separated list of column names or column aliases to sort by. +// +func (f CatSegments) WithS(v ...string) func(*CatSegmentsRequest) { + return func(r *CatSegmentsRequest) { + r.S = v + } +} + +// WithV - verbose mode. display column headers. +// +func (f CatSegments) WithV(v bool) func(*CatSegmentsRequest) { + return func(r *CatSegmentsRequest) { + r.V = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CatSegments) WithPretty() func(*CatSegmentsRequest) { + return func(r *CatSegmentsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CatSegments) WithHuman() func(*CatSegmentsRequest) { + return func(r *CatSegmentsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CatSegments) WithErrorTrace() func(*CatSegmentsRequest) { + return func(r *CatSegmentsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CatSegments) WithFilterPath(v ...string) func(*CatSegmentsRequest) { + return func(r *CatSegmentsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CatSegments) WithHeader(h map[string]string) func(*CatSegmentsRequest) { + return func(r *CatSegmentsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CatSegments) WithOpaqueID(s string) func(*CatSegmentsRequest) { + return func(r *CatSegmentsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.shards.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.shards.go new file mode 100644 index 00000000000..548106ab191 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.shards.go @@ -0,0 +1,320 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newCatShardsFunc(t Transport) CatShards { + return func(o ...func(*CatShardsRequest)) (*Response, error) { + var r = CatShardsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CatShards provides a detailed view of shard allocation on nodes. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-shards.html. +// +type CatShards func(o ...func(*CatShardsRequest)) (*Response, error) + +// CatShardsRequest configures the Cat Shards API request. +// +type CatShardsRequest struct { + Index []string + + Bytes string + Format string + H []string + Help *bool + Local *bool + MasterTimeout time.Duration + S []string + Time string + V *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CatShardsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_cat") + 1 + len("shards") + 1 + len(strings.Join(r.Index, ","))) + path.WriteString("/") + path.WriteString("_cat") + path.WriteString("/") + path.WriteString("shards") + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + + params = make(map[string]string) + + if r.Bytes != "" { + params["bytes"] = r.Bytes + } + + if r.Format != "" { + params["format"] = r.Format + } + + if len(r.H) > 0 { + params["h"] = strings.Join(r.H, ",") + } + + if r.Help != nil { + params["help"] = strconv.FormatBool(*r.Help) + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if len(r.S) > 0 { + params["s"] = strings.Join(r.S, ",") + } + + if r.Time != "" { + params["time"] = r.Time + } + + if r.V != nil { + params["v"] = strconv.FormatBool(*r.V) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CatShards) WithContext(v context.Context) func(*CatShardsRequest) { + return func(r *CatShardsRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names to limit the returned information. +// +func (f CatShards) WithIndex(v ...string) func(*CatShardsRequest) { + return func(r *CatShardsRequest) { + r.Index = v + } +} + +// WithBytes - the unit in which to display byte values. +// +func (f CatShards) WithBytes(v string) func(*CatShardsRequest) { + return func(r *CatShardsRequest) { + r.Bytes = v + } +} + +// WithFormat - a short version of the accept header, e.g. json, yaml. +// +func (f CatShards) WithFormat(v string) func(*CatShardsRequest) { + return func(r *CatShardsRequest) { + r.Format = v + } +} + +// WithH - comma-separated list of column names to display. +// +func (f CatShards) WithH(v ...string) func(*CatShardsRequest) { + return func(r *CatShardsRequest) { + r.H = v + } +} + +// WithHelp - return help information. +// +func (f CatShards) WithHelp(v bool) func(*CatShardsRequest) { + return func(r *CatShardsRequest) { + r.Help = &v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f CatShards) WithLocal(v bool) func(*CatShardsRequest) { + return func(r *CatShardsRequest) { + r.Local = &v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f CatShards) WithMasterTimeout(v time.Duration) func(*CatShardsRequest) { + return func(r *CatShardsRequest) { + r.MasterTimeout = v + } +} + +// WithS - comma-separated list of column names or column aliases to sort by. +// +func (f CatShards) WithS(v ...string) func(*CatShardsRequest) { + return func(r *CatShardsRequest) { + r.S = v + } +} + +// WithTime - the unit in which to display time values. +// +func (f CatShards) WithTime(v string) func(*CatShardsRequest) { + return func(r *CatShardsRequest) { + r.Time = v + } +} + +// WithV - verbose mode. display column headers. +// +func (f CatShards) WithV(v bool) func(*CatShardsRequest) { + return func(r *CatShardsRequest) { + r.V = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CatShards) WithPretty() func(*CatShardsRequest) { + return func(r *CatShardsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CatShards) WithHuman() func(*CatShardsRequest) { + return func(r *CatShardsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CatShards) WithErrorTrace() func(*CatShardsRequest) { + return func(r *CatShardsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CatShards) WithFilterPath(v ...string) func(*CatShardsRequest) { + return func(r *CatShardsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CatShards) WithHeader(h map[string]string) func(*CatShardsRequest) { + return func(r *CatShardsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CatShards) WithOpaqueID(s string) func(*CatShardsRequest) { + return func(r *CatShardsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.snapshots.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.snapshots.go new file mode 100644 index 00000000000..947e44ee95c --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.snapshots.go @@ -0,0 +1,307 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newCatSnapshotsFunc(t Transport) CatSnapshots { + return func(o ...func(*CatSnapshotsRequest)) (*Response, error) { + var r = CatSnapshotsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CatSnapshots returns all snapshots in a specific repository. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-snapshots.html. +// +type CatSnapshots func(o ...func(*CatSnapshotsRequest)) (*Response, error) + +// CatSnapshotsRequest configures the Cat Snapshots API request. +// +type CatSnapshotsRequest struct { + Repository []string + + Format string + H []string + Help *bool + IgnoreUnavailable *bool + MasterTimeout time.Duration + S []string + Time string + V *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CatSnapshotsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_cat") + 1 + len("snapshots") + 1 + len(strings.Join(r.Repository, ","))) + path.WriteString("/") + path.WriteString("_cat") + path.WriteString("/") + path.WriteString("snapshots") + if len(r.Repository) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Repository, ",")) + } + + params = make(map[string]string) + + if r.Format != "" { + params["format"] = r.Format + } + + if len(r.H) > 0 { + params["h"] = strings.Join(r.H, ",") + } + + if r.Help != nil { + params["help"] = strconv.FormatBool(*r.Help) + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if len(r.S) > 0 { + params["s"] = strings.Join(r.S, ",") + } + + if r.Time != "" { + params["time"] = r.Time + } + + if r.V != nil { + params["v"] = strconv.FormatBool(*r.V) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CatSnapshots) WithContext(v context.Context) func(*CatSnapshotsRequest) { + return func(r *CatSnapshotsRequest) { + r.ctx = v + } +} + +// WithRepository - name of repository from which to fetch the snapshot information. +// +func (f CatSnapshots) WithRepository(v ...string) func(*CatSnapshotsRequest) { + return func(r *CatSnapshotsRequest) { + r.Repository = v + } +} + +// WithFormat - a short version of the accept header, e.g. json, yaml. +// +func (f CatSnapshots) WithFormat(v string) func(*CatSnapshotsRequest) { + return func(r *CatSnapshotsRequest) { + r.Format = v + } +} + +// WithH - comma-separated list of column names to display. +// +func (f CatSnapshots) WithH(v ...string) func(*CatSnapshotsRequest) { + return func(r *CatSnapshotsRequest) { + r.H = v + } +} + +// WithHelp - return help information. +// +func (f CatSnapshots) WithHelp(v bool) func(*CatSnapshotsRequest) { + return func(r *CatSnapshotsRequest) { + r.Help = &v + } +} + +// WithIgnoreUnavailable - set to true to ignore unavailable snapshots. +// +func (f CatSnapshots) WithIgnoreUnavailable(v bool) func(*CatSnapshotsRequest) { + return func(r *CatSnapshotsRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f CatSnapshots) WithMasterTimeout(v time.Duration) func(*CatSnapshotsRequest) { + return func(r *CatSnapshotsRequest) { + r.MasterTimeout = v + } +} + +// WithS - comma-separated list of column names or column aliases to sort by. +// +func (f CatSnapshots) WithS(v ...string) func(*CatSnapshotsRequest) { + return func(r *CatSnapshotsRequest) { + r.S = v + } +} + +// WithTime - the unit in which to display time values. +// +func (f CatSnapshots) WithTime(v string) func(*CatSnapshotsRequest) { + return func(r *CatSnapshotsRequest) { + r.Time = v + } +} + +// WithV - verbose mode. display column headers. +// +func (f CatSnapshots) WithV(v bool) func(*CatSnapshotsRequest) { + return func(r *CatSnapshotsRequest) { + r.V = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CatSnapshots) WithPretty() func(*CatSnapshotsRequest) { + return func(r *CatSnapshotsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CatSnapshots) WithHuman() func(*CatSnapshotsRequest) { + return func(r *CatSnapshotsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CatSnapshots) WithErrorTrace() func(*CatSnapshotsRequest) { + return func(r *CatSnapshotsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CatSnapshots) WithFilterPath(v ...string) func(*CatSnapshotsRequest) { + return func(r *CatSnapshotsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CatSnapshots) WithHeader(h map[string]string) func(*CatSnapshotsRequest) { + return func(r *CatSnapshotsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CatSnapshots) WithOpaqueID(s string) func(*CatSnapshotsRequest) { + return func(r *CatSnapshotsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.tasks.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.tasks.go new file mode 100644 index 00000000000..5d9f95affbc --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.tasks.go @@ -0,0 +1,315 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newCatTasksFunc(t Transport) CatTasks { + return func(o ...func(*CatTasksRequest)) (*Response, error) { + var r = CatTasksRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CatTasks returns information about the tasks currently executing on one or more nodes in the cluster. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html. +// +type CatTasks func(o ...func(*CatTasksRequest)) (*Response, error) + +// CatTasksRequest configures the Cat Tasks API request. +// +type CatTasksRequest struct { + Actions []string + Detailed *bool + Format string + H []string + Help *bool + NodeID []string + ParentTask *int + S []string + Time string + V *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CatTasksRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_cat/tasks")) + path.WriteString("/_cat/tasks") + + params = make(map[string]string) + + if len(r.Actions) > 0 { + params["actions"] = strings.Join(r.Actions, ",") + } + + if r.Detailed != nil { + params["detailed"] = strconv.FormatBool(*r.Detailed) + } + + if r.Format != "" { + params["format"] = r.Format + } + + if len(r.H) > 0 { + params["h"] = strings.Join(r.H, ",") + } + + if r.Help != nil { + params["help"] = strconv.FormatBool(*r.Help) + } + + if len(r.NodeID) > 0 { + params["node_id"] = strings.Join(r.NodeID, ",") + } + + if r.ParentTask != nil { + params["parent_task"] = strconv.FormatInt(int64(*r.ParentTask), 10) + } + + if len(r.S) > 0 { + params["s"] = strings.Join(r.S, ",") + } + + if r.Time != "" { + params["time"] = r.Time + } + + if r.V != nil { + params["v"] = strconv.FormatBool(*r.V) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CatTasks) WithContext(v context.Context) func(*CatTasksRequest) { + return func(r *CatTasksRequest) { + r.ctx = v + } +} + +// WithActions - a list of actions that should be returned. leave empty to return all.. +// +func (f CatTasks) WithActions(v ...string) func(*CatTasksRequest) { + return func(r *CatTasksRequest) { + r.Actions = v + } +} + +// WithDetailed - return detailed task information (default: false). +// +func (f CatTasks) WithDetailed(v bool) func(*CatTasksRequest) { + return func(r *CatTasksRequest) { + r.Detailed = &v + } +} + +// WithFormat - a short version of the accept header, e.g. json, yaml. +// +func (f CatTasks) WithFormat(v string) func(*CatTasksRequest) { + return func(r *CatTasksRequest) { + r.Format = v + } +} + +// WithH - comma-separated list of column names to display. +// +func (f CatTasks) WithH(v ...string) func(*CatTasksRequest) { + return func(r *CatTasksRequest) { + r.H = v + } +} + +// WithHelp - return help information. +// +func (f CatTasks) WithHelp(v bool) func(*CatTasksRequest) { + return func(r *CatTasksRequest) { + r.Help = &v + } +} + +// WithNodeID - a list of node ids or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes. +// +func (f CatTasks) WithNodeID(v ...string) func(*CatTasksRequest) { + return func(r *CatTasksRequest) { + r.NodeID = v + } +} + +// WithParentTask - return tasks with specified parent task ID. set to -1 to return all.. +// +func (f CatTasks) WithParentTask(v int) func(*CatTasksRequest) { + return func(r *CatTasksRequest) { + r.ParentTask = &v + } +} + +// WithS - comma-separated list of column names or column aliases to sort by. +// +func (f CatTasks) WithS(v ...string) func(*CatTasksRequest) { + return func(r *CatTasksRequest) { + r.S = v + } +} + +// WithTime - the unit in which to display time values. +// +func (f CatTasks) WithTime(v string) func(*CatTasksRequest) { + return func(r *CatTasksRequest) { + r.Time = v + } +} + +// WithV - verbose mode. display column headers. +// +func (f CatTasks) WithV(v bool) func(*CatTasksRequest) { + return func(r *CatTasksRequest) { + r.V = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CatTasks) WithPretty() func(*CatTasksRequest) { + return func(r *CatTasksRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CatTasks) WithHuman() func(*CatTasksRequest) { + return func(r *CatTasksRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CatTasks) WithErrorTrace() func(*CatTasksRequest) { + return func(r *CatTasksRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CatTasks) WithFilterPath(v ...string) func(*CatTasksRequest) { + return func(r *CatTasksRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CatTasks) WithHeader(h map[string]string) func(*CatTasksRequest) { + return func(r *CatTasksRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CatTasks) WithOpaqueID(s string) func(*CatTasksRequest) { + return func(r *CatTasksRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.templates.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.templates.go new file mode 100644 index 00000000000..e42d5eba3d1 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.templates.go @@ -0,0 +1,294 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newCatTemplatesFunc(t Transport) CatTemplates { + return func(o ...func(*CatTemplatesRequest)) (*Response, error) { + var r = CatTemplatesRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CatTemplates returns information about existing templates. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-templates.html. +// +type CatTemplates func(o ...func(*CatTemplatesRequest)) (*Response, error) + +// CatTemplatesRequest configures the Cat Templates API request. +// +type CatTemplatesRequest struct { + Name string + + Format string + H []string + Help *bool + Local *bool + MasterTimeout time.Duration + S []string + V *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CatTemplatesRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_cat") + 1 + len("templates") + 1 + len(r.Name)) + path.WriteString("/") + path.WriteString("_cat") + path.WriteString("/") + path.WriteString("templates") + if r.Name != "" { + path.WriteString("/") + path.WriteString(r.Name) + } + + params = make(map[string]string) + + if r.Format != "" { + params["format"] = r.Format + } + + if len(r.H) > 0 { + params["h"] = strings.Join(r.H, ",") + } + + if r.Help != nil { + params["help"] = strconv.FormatBool(*r.Help) + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if len(r.S) > 0 { + params["s"] = strings.Join(r.S, ",") + } + + if r.V != nil { + params["v"] = strconv.FormatBool(*r.V) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CatTemplates) WithContext(v context.Context) func(*CatTemplatesRequest) { + return func(r *CatTemplatesRequest) { + r.ctx = v + } +} + +// WithName - a pattern that returned template names must match. +// +func (f CatTemplates) WithName(v string) func(*CatTemplatesRequest) { + return func(r *CatTemplatesRequest) { + r.Name = v + } +} + +// WithFormat - a short version of the accept header, e.g. json, yaml. +// +func (f CatTemplates) WithFormat(v string) func(*CatTemplatesRequest) { + return func(r *CatTemplatesRequest) { + r.Format = v + } +} + +// WithH - comma-separated list of column names to display. +// +func (f CatTemplates) WithH(v ...string) func(*CatTemplatesRequest) { + return func(r *CatTemplatesRequest) { + r.H = v + } +} + +// WithHelp - return help information. +// +func (f CatTemplates) WithHelp(v bool) func(*CatTemplatesRequest) { + return func(r *CatTemplatesRequest) { + r.Help = &v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f CatTemplates) WithLocal(v bool) func(*CatTemplatesRequest) { + return func(r *CatTemplatesRequest) { + r.Local = &v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f CatTemplates) WithMasterTimeout(v time.Duration) func(*CatTemplatesRequest) { + return func(r *CatTemplatesRequest) { + r.MasterTimeout = v + } +} + +// WithS - comma-separated list of column names or column aliases to sort by. +// +func (f CatTemplates) WithS(v ...string) func(*CatTemplatesRequest) { + return func(r *CatTemplatesRequest) { + r.S = v + } +} + +// WithV - verbose mode. display column headers. +// +func (f CatTemplates) WithV(v bool) func(*CatTemplatesRequest) { + return func(r *CatTemplatesRequest) { + r.V = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CatTemplates) WithPretty() func(*CatTemplatesRequest) { + return func(r *CatTemplatesRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CatTemplates) WithHuman() func(*CatTemplatesRequest) { + return func(r *CatTemplatesRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CatTemplates) WithErrorTrace() func(*CatTemplatesRequest) { + return func(r *CatTemplatesRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CatTemplates) WithFilterPath(v ...string) func(*CatTemplatesRequest) { + return func(r *CatTemplatesRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CatTemplates) WithHeader(h map[string]string) func(*CatTemplatesRequest) { + return func(r *CatTemplatesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CatTemplates) WithOpaqueID(s string) func(*CatTemplatesRequest) { + return func(r *CatTemplatesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.thread_pool.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.thread_pool.go new file mode 100644 index 00000000000..8aa582821e0 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cat.thread_pool.go @@ -0,0 +1,308 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newCatThreadPoolFunc(t Transport) CatThreadPool { + return func(o ...func(*CatThreadPoolRequest)) (*Response, error) { + var r = CatThreadPoolRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CatThreadPool returns cluster-wide thread pool statistics per node. +// By default the active, queue and rejected statistics are returned for all thread pools. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-thread-pool.html. +// +type CatThreadPool func(o ...func(*CatThreadPoolRequest)) (*Response, error) + +// CatThreadPoolRequest configures the Cat Thread Pool API request. +// +type CatThreadPoolRequest struct { + ThreadPoolPatterns []string + + Format string + H []string + Help *bool + Local *bool + MasterTimeout time.Duration + S []string + Size string + V *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CatThreadPoolRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_cat") + 1 + len("thread_pool") + 1 + len(strings.Join(r.ThreadPoolPatterns, ","))) + path.WriteString("/") + path.WriteString("_cat") + path.WriteString("/") + path.WriteString("thread_pool") + if len(r.ThreadPoolPatterns) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.ThreadPoolPatterns, ",")) + } + + params = make(map[string]string) + + if r.Format != "" { + params["format"] = r.Format + } + + if len(r.H) > 0 { + params["h"] = strings.Join(r.H, ",") + } + + if r.Help != nil { + params["help"] = strconv.FormatBool(*r.Help) + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if len(r.S) > 0 { + params["s"] = strings.Join(r.S, ",") + } + + if r.Size != "" { + params["size"] = r.Size + } + + if r.V != nil { + params["v"] = strconv.FormatBool(*r.V) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CatThreadPool) WithContext(v context.Context) func(*CatThreadPoolRequest) { + return func(r *CatThreadPoolRequest) { + r.ctx = v + } +} + +// WithThreadPoolPatterns - a list of regular-expressions to filter the thread pools in the output. +// +func (f CatThreadPool) WithThreadPoolPatterns(v ...string) func(*CatThreadPoolRequest) { + return func(r *CatThreadPoolRequest) { + r.ThreadPoolPatterns = v + } +} + +// WithFormat - a short version of the accept header, e.g. json, yaml. +// +func (f CatThreadPool) WithFormat(v string) func(*CatThreadPoolRequest) { + return func(r *CatThreadPoolRequest) { + r.Format = v + } +} + +// WithH - comma-separated list of column names to display. +// +func (f CatThreadPool) WithH(v ...string) func(*CatThreadPoolRequest) { + return func(r *CatThreadPoolRequest) { + r.H = v + } +} + +// WithHelp - return help information. +// +func (f CatThreadPool) WithHelp(v bool) func(*CatThreadPoolRequest) { + return func(r *CatThreadPoolRequest) { + r.Help = &v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f CatThreadPool) WithLocal(v bool) func(*CatThreadPoolRequest) { + return func(r *CatThreadPoolRequest) { + r.Local = &v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f CatThreadPool) WithMasterTimeout(v time.Duration) func(*CatThreadPoolRequest) { + return func(r *CatThreadPoolRequest) { + r.MasterTimeout = v + } +} + +// WithS - comma-separated list of column names or column aliases to sort by. +// +func (f CatThreadPool) WithS(v ...string) func(*CatThreadPoolRequest) { + return func(r *CatThreadPoolRequest) { + r.S = v + } +} + +// WithSize - the multiplier in which to display values. +// +func (f CatThreadPool) WithSize(v string) func(*CatThreadPoolRequest) { + return func(r *CatThreadPoolRequest) { + r.Size = v + } +} + +// WithV - verbose mode. display column headers. +// +func (f CatThreadPool) WithV(v bool) func(*CatThreadPoolRequest) { + return func(r *CatThreadPoolRequest) { + r.V = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CatThreadPool) WithPretty() func(*CatThreadPoolRequest) { + return func(r *CatThreadPoolRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CatThreadPool) WithHuman() func(*CatThreadPoolRequest) { + return func(r *CatThreadPoolRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CatThreadPool) WithErrorTrace() func(*CatThreadPoolRequest) { + return func(r *CatThreadPoolRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CatThreadPool) WithFilterPath(v ...string) func(*CatThreadPoolRequest) { + return func(r *CatThreadPoolRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CatThreadPool) WithHeader(h map[string]string) func(*CatThreadPoolRequest) { + return func(r *CatThreadPoolRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CatThreadPool) WithOpaqueID(s string) func(*CatThreadPoolRequest) { + return func(r *CatThreadPoolRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.clear_scroll.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.clear_scroll.go new file mode 100644 index 00000000000..609257f5f36 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.clear_scroll.go @@ -0,0 +1,215 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newClearScrollFunc(t Transport) ClearScroll { + return func(o ...func(*ClearScrollRequest)) (*Response, error) { + var r = ClearScrollRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// ClearScroll explicitly clears the search context for a scroll. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-body.html#_clear_scroll_api. +// +type ClearScroll func(o ...func(*ClearScrollRequest)) (*Response, error) + +// ClearScrollRequest configures the Clear Scroll API request. +// +type ClearScrollRequest struct { + Body io.Reader + + ScrollID []string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ClearScrollRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_search") + 1 + len("scroll") + 1 + len(strings.Join(r.ScrollID, ","))) + path.WriteString("/") + path.WriteString("_search") + path.WriteString("/") + path.WriteString("scroll") + if len(r.ScrollID) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.ScrollID, ",")) + } + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f ClearScroll) WithContext(v context.Context) func(*ClearScrollRequest) { + return func(r *ClearScrollRequest) { + r.ctx = v + } +} + +// WithBody - A comma-separated list of scroll IDs to clear if none was specified via the scroll_id parameter. +// +func (f ClearScroll) WithBody(v io.Reader) func(*ClearScrollRequest) { + return func(r *ClearScrollRequest) { + r.Body = v + } +} + +// WithScrollID - a list of scroll ids to clear. +// +func (f ClearScroll) WithScrollID(v ...string) func(*ClearScrollRequest) { + return func(r *ClearScrollRequest) { + r.ScrollID = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f ClearScroll) WithPretty() func(*ClearScrollRequest) { + return func(r *ClearScrollRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f ClearScroll) WithHuman() func(*ClearScrollRequest) { + return func(r *ClearScrollRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ClearScroll) WithErrorTrace() func(*ClearScrollRequest) { + return func(r *ClearScrollRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f ClearScroll) WithFilterPath(v ...string) func(*ClearScrollRequest) { + return func(r *ClearScrollRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f ClearScroll) WithHeader(h map[string]string) func(*ClearScrollRequest) { + return func(r *ClearScrollRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f ClearScroll) WithOpaqueID(s string) func(*ClearScrollRequest) { + return func(r *ClearScrollRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.allocation_explain.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.allocation_explain.go new file mode 100644 index 00000000000..d441a68f07d --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.allocation_explain.go @@ -0,0 +1,226 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newClusterAllocationExplainFunc(t Transport) ClusterAllocationExplain { + return func(o ...func(*ClusterAllocationExplainRequest)) (*Response, error) { + var r = ClusterAllocationExplainRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// ClusterAllocationExplain provides explanations for shard allocations in the cluster. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-allocation-explain.html. +// +type ClusterAllocationExplain func(o ...func(*ClusterAllocationExplainRequest)) (*Response, error) + +// ClusterAllocationExplainRequest configures the Cluster Allocation Explain API request. +// +type ClusterAllocationExplainRequest struct { + Body io.Reader + + IncludeDiskInfo *bool + IncludeYesDecisions *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ClusterAllocationExplainRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_cluster/allocation/explain")) + path.WriteString("/_cluster/allocation/explain") + + params = make(map[string]string) + + if r.IncludeDiskInfo != nil { + params["include_disk_info"] = strconv.FormatBool(*r.IncludeDiskInfo) + } + + if r.IncludeYesDecisions != nil { + params["include_yes_decisions"] = strconv.FormatBool(*r.IncludeYesDecisions) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f ClusterAllocationExplain) WithContext(v context.Context) func(*ClusterAllocationExplainRequest) { + return func(r *ClusterAllocationExplainRequest) { + r.ctx = v + } +} + +// WithBody - The index, shard, and primary flag to explain. Empty means 'explain the first unassigned shard'. +// +func (f ClusterAllocationExplain) WithBody(v io.Reader) func(*ClusterAllocationExplainRequest) { + return func(r *ClusterAllocationExplainRequest) { + r.Body = v + } +} + +// WithIncludeDiskInfo - return information about disk usage and shard sizes (default: false). +// +func (f ClusterAllocationExplain) WithIncludeDiskInfo(v bool) func(*ClusterAllocationExplainRequest) { + return func(r *ClusterAllocationExplainRequest) { + r.IncludeDiskInfo = &v + } +} + +// WithIncludeYesDecisions - return 'yes' decisions in explanation (default: false). +// +func (f ClusterAllocationExplain) WithIncludeYesDecisions(v bool) func(*ClusterAllocationExplainRequest) { + return func(r *ClusterAllocationExplainRequest) { + r.IncludeYesDecisions = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f ClusterAllocationExplain) WithPretty() func(*ClusterAllocationExplainRequest) { + return func(r *ClusterAllocationExplainRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f ClusterAllocationExplain) WithHuman() func(*ClusterAllocationExplainRequest) { + return func(r *ClusterAllocationExplainRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ClusterAllocationExplain) WithErrorTrace() func(*ClusterAllocationExplainRequest) { + return func(r *ClusterAllocationExplainRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f ClusterAllocationExplain) WithFilterPath(v ...string) func(*ClusterAllocationExplainRequest) { + return func(r *ClusterAllocationExplainRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f ClusterAllocationExplain) WithHeader(h map[string]string) func(*ClusterAllocationExplainRequest) { + return func(r *ClusterAllocationExplainRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f ClusterAllocationExplain) WithOpaqueID(s string) func(*ClusterAllocationExplainRequest) { + return func(r *ClusterAllocationExplainRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.get_settings.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.get_settings.go new file mode 100644 index 00000000000..6a89b469672 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.get_settings.go @@ -0,0 +1,238 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newClusterGetSettingsFunc(t Transport) ClusterGetSettings { + return func(o ...func(*ClusterGetSettingsRequest)) (*Response, error) { + var r = ClusterGetSettingsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// ClusterGetSettings returns cluster settings. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-update-settings.html. +// +type ClusterGetSettings func(o ...func(*ClusterGetSettingsRequest)) (*Response, error) + +// ClusterGetSettingsRequest configures the Cluster Get Settings API request. +// +type ClusterGetSettingsRequest struct { + FlatSettings *bool + IncludeDefaults *bool + MasterTimeout time.Duration + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ClusterGetSettingsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_cluster/settings")) + path.WriteString("/_cluster/settings") + + params = make(map[string]string) + + if r.FlatSettings != nil { + params["flat_settings"] = strconv.FormatBool(*r.FlatSettings) + } + + if r.IncludeDefaults != nil { + params["include_defaults"] = strconv.FormatBool(*r.IncludeDefaults) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f ClusterGetSettings) WithContext(v context.Context) func(*ClusterGetSettingsRequest) { + return func(r *ClusterGetSettingsRequest) { + r.ctx = v + } +} + +// WithFlatSettings - return settings in flat format (default: false). +// +func (f ClusterGetSettings) WithFlatSettings(v bool) func(*ClusterGetSettingsRequest) { + return func(r *ClusterGetSettingsRequest) { + r.FlatSettings = &v + } +} + +// WithIncludeDefaults - whether to return all default clusters setting.. +// +func (f ClusterGetSettings) WithIncludeDefaults(v bool) func(*ClusterGetSettingsRequest) { + return func(r *ClusterGetSettingsRequest) { + r.IncludeDefaults = &v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f ClusterGetSettings) WithMasterTimeout(v time.Duration) func(*ClusterGetSettingsRequest) { + return func(r *ClusterGetSettingsRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f ClusterGetSettings) WithTimeout(v time.Duration) func(*ClusterGetSettingsRequest) { + return func(r *ClusterGetSettingsRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f ClusterGetSettings) WithPretty() func(*ClusterGetSettingsRequest) { + return func(r *ClusterGetSettingsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f ClusterGetSettings) WithHuman() func(*ClusterGetSettingsRequest) { + return func(r *ClusterGetSettingsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ClusterGetSettings) WithErrorTrace() func(*ClusterGetSettingsRequest) { + return func(r *ClusterGetSettingsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f ClusterGetSettings) WithFilterPath(v ...string) func(*ClusterGetSettingsRequest) { + return func(r *ClusterGetSettingsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f ClusterGetSettings) WithHeader(h map[string]string) func(*ClusterGetSettingsRequest) { + return func(r *ClusterGetSettingsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f ClusterGetSettings) WithOpaqueID(s string) func(*ClusterGetSettingsRequest) { + return func(r *ClusterGetSettingsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.health.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.health.go new file mode 100644 index 00000000000..a579b0b21bd --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.health.go @@ -0,0 +1,346 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newClusterHealthFunc(t Transport) ClusterHealth { + return func(o ...func(*ClusterHealthRequest)) (*Response, error) { + var r = ClusterHealthRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// ClusterHealth returns basic information about the health of the cluster. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-health.html. +// +type ClusterHealth func(o ...func(*ClusterHealthRequest)) (*Response, error) + +// ClusterHealthRequest configures the Cluster Health API request. +// +type ClusterHealthRequest struct { + Index []string + + ExpandWildcards string + Level string + Local *bool + MasterTimeout time.Duration + Timeout time.Duration + WaitForActiveShards string + WaitForEvents string + WaitForNoInitializingShards *bool + WaitForNoRelocatingShards *bool + WaitForNodes string + WaitForStatus string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ClusterHealthRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_cluster") + 1 + len("health") + 1 + len(strings.Join(r.Index, ","))) + path.WriteString("/") + path.WriteString("_cluster") + path.WriteString("/") + path.WriteString("health") + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + + params = make(map[string]string) + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.Level != "" { + params["level"] = r.Level + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.WaitForActiveShards != "" { + params["wait_for_active_shards"] = r.WaitForActiveShards + } + + if r.WaitForEvents != "" { + params["wait_for_events"] = r.WaitForEvents + } + + if r.WaitForNoInitializingShards != nil { + params["wait_for_no_initializing_shards"] = strconv.FormatBool(*r.WaitForNoInitializingShards) + } + + if r.WaitForNoRelocatingShards != nil { + params["wait_for_no_relocating_shards"] = strconv.FormatBool(*r.WaitForNoRelocatingShards) + } + + if r.WaitForNodes != "" { + params["wait_for_nodes"] = r.WaitForNodes + } + + if r.WaitForStatus != "" { + params["wait_for_status"] = r.WaitForStatus + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f ClusterHealth) WithContext(v context.Context) func(*ClusterHealthRequest) { + return func(r *ClusterHealthRequest) { + r.ctx = v + } +} + +// WithIndex - limit the information returned to a specific index. +// +func (f ClusterHealth) WithIndex(v ...string) func(*ClusterHealthRequest) { + return func(r *ClusterHealthRequest) { + r.Index = v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f ClusterHealth) WithExpandWildcards(v string) func(*ClusterHealthRequest) { + return func(r *ClusterHealthRequest) { + r.ExpandWildcards = v + } +} + +// WithLevel - specify the level of detail for returned information. +// +func (f ClusterHealth) WithLevel(v string) func(*ClusterHealthRequest) { + return func(r *ClusterHealthRequest) { + r.Level = v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f ClusterHealth) WithLocal(v bool) func(*ClusterHealthRequest) { + return func(r *ClusterHealthRequest) { + r.Local = &v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f ClusterHealth) WithMasterTimeout(v time.Duration) func(*ClusterHealthRequest) { + return func(r *ClusterHealthRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f ClusterHealth) WithTimeout(v time.Duration) func(*ClusterHealthRequest) { + return func(r *ClusterHealthRequest) { + r.Timeout = v + } +} + +// WithWaitForActiveShards - wait until the specified number of shards is active. +// +func (f ClusterHealth) WithWaitForActiveShards(v string) func(*ClusterHealthRequest) { + return func(r *ClusterHealthRequest) { + r.WaitForActiveShards = v + } +} + +// WithWaitForEvents - wait until all currently queued events with the given priority are processed. +// +func (f ClusterHealth) WithWaitForEvents(v string) func(*ClusterHealthRequest) { + return func(r *ClusterHealthRequest) { + r.WaitForEvents = v + } +} + +// WithWaitForNoInitializingShards - whether to wait until there are no initializing shards in the cluster. +// +func (f ClusterHealth) WithWaitForNoInitializingShards(v bool) func(*ClusterHealthRequest) { + return func(r *ClusterHealthRequest) { + r.WaitForNoInitializingShards = &v + } +} + +// WithWaitForNoRelocatingShards - whether to wait until there are no relocating shards in the cluster. +// +func (f ClusterHealth) WithWaitForNoRelocatingShards(v bool) func(*ClusterHealthRequest) { + return func(r *ClusterHealthRequest) { + r.WaitForNoRelocatingShards = &v + } +} + +// WithWaitForNodes - wait until the specified number of nodes is available. +// +func (f ClusterHealth) WithWaitForNodes(v string) func(*ClusterHealthRequest) { + return func(r *ClusterHealthRequest) { + r.WaitForNodes = v + } +} + +// WithWaitForStatus - wait until cluster is in a specific state. +// +func (f ClusterHealth) WithWaitForStatus(v string) func(*ClusterHealthRequest) { + return func(r *ClusterHealthRequest) { + r.WaitForStatus = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f ClusterHealth) WithPretty() func(*ClusterHealthRequest) { + return func(r *ClusterHealthRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f ClusterHealth) WithHuman() func(*ClusterHealthRequest) { + return func(r *ClusterHealthRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ClusterHealth) WithErrorTrace() func(*ClusterHealthRequest) { + return func(r *ClusterHealthRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f ClusterHealth) WithFilterPath(v ...string) func(*ClusterHealthRequest) { + return func(r *ClusterHealthRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f ClusterHealth) WithHeader(h map[string]string) func(*ClusterHealthRequest) { + return func(r *ClusterHealthRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f ClusterHealth) WithOpaqueID(s string) func(*ClusterHealthRequest) { + return func(r *ClusterHealthRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.pending_tasks.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.pending_tasks.go new file mode 100644 index 00000000000..33fa789ed21 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.pending_tasks.go @@ -0,0 +1,213 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newClusterPendingTasksFunc(t Transport) ClusterPendingTasks { + return func(o ...func(*ClusterPendingTasksRequest)) (*Response, error) { + var r = ClusterPendingTasksRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// ClusterPendingTasks returns a list of any cluster-level changes (e.g. create index, update mapping, +// allocate or fail shard) which have not yet been executed. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-pending.html. +// +type ClusterPendingTasks func(o ...func(*ClusterPendingTasksRequest)) (*Response, error) + +// ClusterPendingTasksRequest configures the Cluster Pending Tasks API request. +// +type ClusterPendingTasksRequest struct { + Local *bool + MasterTimeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ClusterPendingTasksRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_cluster/pending_tasks")) + path.WriteString("/_cluster/pending_tasks") + + params = make(map[string]string) + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f ClusterPendingTasks) WithContext(v context.Context) func(*ClusterPendingTasksRequest) { + return func(r *ClusterPendingTasksRequest) { + r.ctx = v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f ClusterPendingTasks) WithLocal(v bool) func(*ClusterPendingTasksRequest) { + return func(r *ClusterPendingTasksRequest) { + r.Local = &v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f ClusterPendingTasks) WithMasterTimeout(v time.Duration) func(*ClusterPendingTasksRequest) { + return func(r *ClusterPendingTasksRequest) { + r.MasterTimeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f ClusterPendingTasks) WithPretty() func(*ClusterPendingTasksRequest) { + return func(r *ClusterPendingTasksRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f ClusterPendingTasks) WithHuman() func(*ClusterPendingTasksRequest) { + return func(r *ClusterPendingTasksRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ClusterPendingTasks) WithErrorTrace() func(*ClusterPendingTasksRequest) { + return func(r *ClusterPendingTasksRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f ClusterPendingTasks) WithFilterPath(v ...string) func(*ClusterPendingTasksRequest) { + return func(r *ClusterPendingTasksRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f ClusterPendingTasks) WithHeader(h map[string]string) func(*ClusterPendingTasksRequest) { + return func(r *ClusterPendingTasksRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f ClusterPendingTasks) WithOpaqueID(s string) func(*ClusterPendingTasksRequest) { + return func(r *ClusterPendingTasksRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.put_settings.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.put_settings.go new file mode 100644 index 00000000000..75ebca4f232 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.put_settings.go @@ -0,0 +1,232 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" + "time" +) + +func newClusterPutSettingsFunc(t Transport) ClusterPutSettings { + return func(body io.Reader, o ...func(*ClusterPutSettingsRequest)) (*Response, error) { + var r = ClusterPutSettingsRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// ClusterPutSettings updates the cluster settings. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-update-settings.html. +// +type ClusterPutSettings func(body io.Reader, o ...func(*ClusterPutSettingsRequest)) (*Response, error) + +// ClusterPutSettingsRequest configures the Cluster Put Settings API request. +// +type ClusterPutSettingsRequest struct { + Body io.Reader + + FlatSettings *bool + MasterTimeout time.Duration + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ClusterPutSettingsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(len("/_cluster/settings")) + path.WriteString("/_cluster/settings") + + params = make(map[string]string) + + if r.FlatSettings != nil { + params["flat_settings"] = strconv.FormatBool(*r.FlatSettings) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f ClusterPutSettings) WithContext(v context.Context) func(*ClusterPutSettingsRequest) { + return func(r *ClusterPutSettingsRequest) { + r.ctx = v + } +} + +// WithFlatSettings - return settings in flat format (default: false). +// +func (f ClusterPutSettings) WithFlatSettings(v bool) func(*ClusterPutSettingsRequest) { + return func(r *ClusterPutSettingsRequest) { + r.FlatSettings = &v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f ClusterPutSettings) WithMasterTimeout(v time.Duration) func(*ClusterPutSettingsRequest) { + return func(r *ClusterPutSettingsRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f ClusterPutSettings) WithTimeout(v time.Duration) func(*ClusterPutSettingsRequest) { + return func(r *ClusterPutSettingsRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f ClusterPutSettings) WithPretty() func(*ClusterPutSettingsRequest) { + return func(r *ClusterPutSettingsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f ClusterPutSettings) WithHuman() func(*ClusterPutSettingsRequest) { + return func(r *ClusterPutSettingsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ClusterPutSettings) WithErrorTrace() func(*ClusterPutSettingsRequest) { + return func(r *ClusterPutSettingsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f ClusterPutSettings) WithFilterPath(v ...string) func(*ClusterPutSettingsRequest) { + return func(r *ClusterPutSettingsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f ClusterPutSettings) WithHeader(h map[string]string) func(*ClusterPutSettingsRequest) { + return func(r *ClusterPutSettingsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f ClusterPutSettings) WithOpaqueID(s string) func(*ClusterPutSettingsRequest) { + return func(r *ClusterPutSettingsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.remote_info.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.remote_info.go new file mode 100644 index 00000000000..4f7979f77c3 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.remote_info.go @@ -0,0 +1,183 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newClusterRemoteInfoFunc(t Transport) ClusterRemoteInfo { + return func(o ...func(*ClusterRemoteInfoRequest)) (*Response, error) { + var r = ClusterRemoteInfoRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// ClusterRemoteInfo returns the information about configured remote clusters. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-remote-info.html. +// +type ClusterRemoteInfo func(o ...func(*ClusterRemoteInfoRequest)) (*Response, error) + +// ClusterRemoteInfoRequest configures the Cluster Remote Info API request. +// +type ClusterRemoteInfoRequest struct { + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ClusterRemoteInfoRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_remote/info")) + path.WriteString("/_remote/info") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f ClusterRemoteInfo) WithContext(v context.Context) func(*ClusterRemoteInfoRequest) { + return func(r *ClusterRemoteInfoRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f ClusterRemoteInfo) WithPretty() func(*ClusterRemoteInfoRequest) { + return func(r *ClusterRemoteInfoRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f ClusterRemoteInfo) WithHuman() func(*ClusterRemoteInfoRequest) { + return func(r *ClusterRemoteInfoRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ClusterRemoteInfo) WithErrorTrace() func(*ClusterRemoteInfoRequest) { + return func(r *ClusterRemoteInfoRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f ClusterRemoteInfo) WithFilterPath(v ...string) func(*ClusterRemoteInfoRequest) { + return func(r *ClusterRemoteInfoRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f ClusterRemoteInfo) WithHeader(h map[string]string) func(*ClusterRemoteInfoRequest) { + return func(r *ClusterRemoteInfoRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f ClusterRemoteInfo) WithOpaqueID(s string) func(*ClusterRemoteInfoRequest) { + return func(r *ClusterRemoteInfoRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.reroute.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.reroute.go new file mode 100644 index 00000000000..34772e2de97 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.reroute.go @@ -0,0 +1,279 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" + "time" +) + +func newClusterRerouteFunc(t Transport) ClusterReroute { + return func(o ...func(*ClusterRerouteRequest)) (*Response, error) { + var r = ClusterRerouteRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// ClusterReroute allows to manually change the allocation of individual shards in the cluster. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-reroute.html. +// +type ClusterReroute func(o ...func(*ClusterRerouteRequest)) (*Response, error) + +// ClusterRerouteRequest configures the Cluster Reroute API request. +// +type ClusterRerouteRequest struct { + Body io.Reader + + DryRun *bool + Explain *bool + MasterTimeout time.Duration + Metric []string + RetryFailed *bool + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ClusterRerouteRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(len("/_cluster/reroute")) + path.WriteString("/_cluster/reroute") + + params = make(map[string]string) + + if r.DryRun != nil { + params["dry_run"] = strconv.FormatBool(*r.DryRun) + } + + if r.Explain != nil { + params["explain"] = strconv.FormatBool(*r.Explain) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if len(r.Metric) > 0 { + params["metric"] = strings.Join(r.Metric, ",") + } + + if r.RetryFailed != nil { + params["retry_failed"] = strconv.FormatBool(*r.RetryFailed) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f ClusterReroute) WithContext(v context.Context) func(*ClusterRerouteRequest) { + return func(r *ClusterRerouteRequest) { + r.ctx = v + } +} + +// WithBody - The definition of `commands` to perform (`move`, `cancel`, `allocate`). +// +func (f ClusterReroute) WithBody(v io.Reader) func(*ClusterRerouteRequest) { + return func(r *ClusterRerouteRequest) { + r.Body = v + } +} + +// WithDryRun - simulate the operation only and return the resulting state. +// +func (f ClusterReroute) WithDryRun(v bool) func(*ClusterRerouteRequest) { + return func(r *ClusterRerouteRequest) { + r.DryRun = &v + } +} + +// WithExplain - return an explanation of why the commands can or cannot be executed. +// +func (f ClusterReroute) WithExplain(v bool) func(*ClusterRerouteRequest) { + return func(r *ClusterRerouteRequest) { + r.Explain = &v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f ClusterReroute) WithMasterTimeout(v time.Duration) func(*ClusterRerouteRequest) { + return func(r *ClusterRerouteRequest) { + r.MasterTimeout = v + } +} + +// WithMetric - limit the information returned to the specified metrics. defaults to all but metadata. +// +func (f ClusterReroute) WithMetric(v ...string) func(*ClusterRerouteRequest) { + return func(r *ClusterRerouteRequest) { + r.Metric = v + } +} + +// WithRetryFailed - retries allocation of shards that are blocked due to too many subsequent allocation failures. +// +func (f ClusterReroute) WithRetryFailed(v bool) func(*ClusterRerouteRequest) { + return func(r *ClusterRerouteRequest) { + r.RetryFailed = &v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f ClusterReroute) WithTimeout(v time.Duration) func(*ClusterRerouteRequest) { + return func(r *ClusterRerouteRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f ClusterReroute) WithPretty() func(*ClusterRerouteRequest) { + return func(r *ClusterRerouteRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f ClusterReroute) WithHuman() func(*ClusterRerouteRequest) { + return func(r *ClusterRerouteRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ClusterReroute) WithErrorTrace() func(*ClusterRerouteRequest) { + return func(r *ClusterRerouteRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f ClusterReroute) WithFilterPath(v ...string) func(*ClusterRerouteRequest) { + return func(r *ClusterRerouteRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f ClusterReroute) WithHeader(h map[string]string) func(*ClusterRerouteRequest) { + return func(r *ClusterRerouteRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f ClusterReroute) WithOpaqueID(s string) func(*ClusterRerouteRequest) { + return func(r *ClusterRerouteRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.state.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.state.go new file mode 100644 index 00000000000..2a1161e7270 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.state.go @@ -0,0 +1,321 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newClusterStateFunc(t Transport) ClusterState { + return func(o ...func(*ClusterStateRequest)) (*Response, error) { + var r = ClusterStateRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// ClusterState returns a comprehensive information about the state of the cluster. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-state.html. +// +type ClusterState func(o ...func(*ClusterStateRequest)) (*Response, error) + +// ClusterStateRequest configures the Cluster State API request. +// +type ClusterStateRequest struct { + Index []string + + Metric []string + + AllowNoIndices *bool + ExpandWildcards string + FlatSettings *bool + IgnoreUnavailable *bool + Local *bool + MasterTimeout time.Duration + WaitForMetadataVersion *int + WaitForTimeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ClusterStateRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_cluster") + 1 + len("state") + 1 + len(strings.Join(r.Metric, ",")) + 1 + len(strings.Join(r.Index, ","))) + path.WriteString("/") + path.WriteString("_cluster") + path.WriteString("/") + path.WriteString("state") + if len(r.Metric) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Metric, ",")) + } + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.FlatSettings != nil { + params["flat_settings"] = strconv.FormatBool(*r.FlatSettings) + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.WaitForMetadataVersion != nil { + params["wait_for_metadata_version"] = strconv.FormatInt(int64(*r.WaitForMetadataVersion), 10) + } + + if r.WaitForTimeout != 0 { + params["wait_for_timeout"] = formatDuration(r.WaitForTimeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f ClusterState) WithContext(v context.Context) func(*ClusterStateRequest) { + return func(r *ClusterStateRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names; use _all to perform the operation on all indices. +// +func (f ClusterState) WithIndex(v ...string) func(*ClusterStateRequest) { + return func(r *ClusterStateRequest) { + r.Index = v + } +} + +// WithMetric - limit the information returned to the specified metrics. +// +func (f ClusterState) WithMetric(v ...string) func(*ClusterStateRequest) { + return func(r *ClusterStateRequest) { + r.Metric = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f ClusterState) WithAllowNoIndices(v bool) func(*ClusterStateRequest) { + return func(r *ClusterStateRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f ClusterState) WithExpandWildcards(v string) func(*ClusterStateRequest) { + return func(r *ClusterStateRequest) { + r.ExpandWildcards = v + } +} + +// WithFlatSettings - return settings in flat format (default: false). +// +func (f ClusterState) WithFlatSettings(v bool) func(*ClusterStateRequest) { + return func(r *ClusterStateRequest) { + r.FlatSettings = &v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f ClusterState) WithIgnoreUnavailable(v bool) func(*ClusterStateRequest) { + return func(r *ClusterStateRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f ClusterState) WithLocal(v bool) func(*ClusterStateRequest) { + return func(r *ClusterStateRequest) { + r.Local = &v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f ClusterState) WithMasterTimeout(v time.Duration) func(*ClusterStateRequest) { + return func(r *ClusterStateRequest) { + r.MasterTimeout = v + } +} + +// WithWaitForMetadataVersion - wait for the metadata version to be equal or greater than the specified metadata version. +// +func (f ClusterState) WithWaitForMetadataVersion(v int) func(*ClusterStateRequest) { + return func(r *ClusterStateRequest) { + r.WaitForMetadataVersion = &v + } +} + +// WithWaitForTimeout - the maximum time to wait for wait_for_metadata_version before timing out. +// +func (f ClusterState) WithWaitForTimeout(v time.Duration) func(*ClusterStateRequest) { + return func(r *ClusterStateRequest) { + r.WaitForTimeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f ClusterState) WithPretty() func(*ClusterStateRequest) { + return func(r *ClusterStateRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f ClusterState) WithHuman() func(*ClusterStateRequest) { + return func(r *ClusterStateRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ClusterState) WithErrorTrace() func(*ClusterStateRequest) { + return func(r *ClusterStateRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f ClusterState) WithFilterPath(v ...string) func(*ClusterStateRequest) { + return func(r *ClusterStateRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f ClusterState) WithHeader(h map[string]string) func(*ClusterStateRequest) { + return func(r *ClusterStateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f ClusterState) WithOpaqueID(s string) func(*ClusterStateRequest) { + return func(r *ClusterStateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.stats.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.stats.go new file mode 100644 index 00000000000..f0dcc6a94af --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.cluster.stats.go @@ -0,0 +1,231 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newClusterStatsFunc(t Transport) ClusterStats { + return func(o ...func(*ClusterStatsRequest)) (*Response, error) { + var r = ClusterStatsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// ClusterStats returns high-level overview of cluster statistics. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-stats.html. +// +type ClusterStats func(o ...func(*ClusterStatsRequest)) (*Response, error) + +// ClusterStatsRequest configures the Cluster Stats API request. +// +type ClusterStatsRequest struct { + NodeID []string + + FlatSettings *bool + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ClusterStatsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/nodes/_cluster/stats/nodes/") + len(strings.Join(r.NodeID, ","))) + path.WriteString("/") + path.WriteString("_cluster") + path.WriteString("/") + path.WriteString("stats") + if len(r.NodeID) > 0 { + path.WriteString("/") + path.WriteString("nodes") + path.WriteString("/") + path.WriteString(strings.Join(r.NodeID, ",")) + } + + params = make(map[string]string) + + if r.FlatSettings != nil { + params["flat_settings"] = strconv.FormatBool(*r.FlatSettings) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f ClusterStats) WithContext(v context.Context) func(*ClusterStatsRequest) { + return func(r *ClusterStatsRequest) { + r.ctx = v + } +} + +// WithNodeID - a list of node ids or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes. +// +func (f ClusterStats) WithNodeID(v ...string) func(*ClusterStatsRequest) { + return func(r *ClusterStatsRequest) { + r.NodeID = v + } +} + +// WithFlatSettings - return settings in flat format (default: false). +// +func (f ClusterStats) WithFlatSettings(v bool) func(*ClusterStatsRequest) { + return func(r *ClusterStatsRequest) { + r.FlatSettings = &v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f ClusterStats) WithTimeout(v time.Duration) func(*ClusterStatsRequest) { + return func(r *ClusterStatsRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f ClusterStats) WithPretty() func(*ClusterStatsRequest) { + return func(r *ClusterStatsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f ClusterStats) WithHuman() func(*ClusterStatsRequest) { + return func(r *ClusterStatsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ClusterStats) WithErrorTrace() func(*ClusterStatsRequest) { + return func(r *ClusterStatsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f ClusterStats) WithFilterPath(v ...string) func(*ClusterStatsRequest) { + return func(r *ClusterStatsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f ClusterStats) WithHeader(h map[string]string) func(*ClusterStatsRequest) { + return func(r *ClusterStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f ClusterStats) WithOpaqueID(s string) func(*ClusterStatsRequest) { + return func(r *ClusterStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.count.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.count.go new file mode 100644 index 00000000000..f37a8083371 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.count.go @@ -0,0 +1,397 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newCountFunc(t Transport) Count { + return func(o ...func(*CountRequest)) (*Response, error) { + var r = CountRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// Count returns number of documents matching a query. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/search-count.html. +// +type Count func(o ...func(*CountRequest)) (*Response, error) + +// CountRequest configures the Count API request. +// +type CountRequest struct { + Index []string + + Body io.Reader + + AllowNoIndices *bool + Analyzer string + AnalyzeWildcard *bool + DefaultOperator string + Df string + ExpandWildcards string + IgnoreThrottled *bool + IgnoreUnavailable *bool + Lenient *bool + MinScore *int + Preference string + Query string + Routing []string + TerminateAfter *int + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CountRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_count")) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_count") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.Analyzer != "" { + params["analyzer"] = r.Analyzer + } + + if r.AnalyzeWildcard != nil { + params["analyze_wildcard"] = strconv.FormatBool(*r.AnalyzeWildcard) + } + + if r.DefaultOperator != "" { + params["default_operator"] = r.DefaultOperator + } + + if r.Df != "" { + params["df"] = r.Df + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.IgnoreThrottled != nil { + params["ignore_throttled"] = strconv.FormatBool(*r.IgnoreThrottled) + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.Lenient != nil { + params["lenient"] = strconv.FormatBool(*r.Lenient) + } + + if r.MinScore != nil { + params["min_score"] = strconv.FormatInt(int64(*r.MinScore), 10) + } + + if r.Preference != "" { + params["preference"] = r.Preference + } + + if r.Query != "" { + params["q"] = r.Query + } + + if len(r.Routing) > 0 { + params["routing"] = strings.Join(r.Routing, ",") + } + + if r.TerminateAfter != nil { + params["terminate_after"] = strconv.FormatInt(int64(*r.TerminateAfter), 10) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f Count) WithContext(v context.Context) func(*CountRequest) { + return func(r *CountRequest) { + r.ctx = v + } +} + +// WithBody - A query to restrict the results specified with the Query DSL (optional). +// +func (f Count) WithBody(v io.Reader) func(*CountRequest) { + return func(r *CountRequest) { + r.Body = v + } +} + +// WithIndex - a list of indices to restrict the results. +// +func (f Count) WithIndex(v ...string) func(*CountRequest) { + return func(r *CountRequest) { + r.Index = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f Count) WithAllowNoIndices(v bool) func(*CountRequest) { + return func(r *CountRequest) { + r.AllowNoIndices = &v + } +} + +// WithAnalyzer - the analyzer to use for the query string. +// +func (f Count) WithAnalyzer(v string) func(*CountRequest) { + return func(r *CountRequest) { + r.Analyzer = v + } +} + +// WithAnalyzeWildcard - specify whether wildcard and prefix queries should be analyzed (default: false). +// +func (f Count) WithAnalyzeWildcard(v bool) func(*CountRequest) { + return func(r *CountRequest) { + r.AnalyzeWildcard = &v + } +} + +// WithDefaultOperator - the default operator for query string query (and or or). +// +func (f Count) WithDefaultOperator(v string) func(*CountRequest) { + return func(r *CountRequest) { + r.DefaultOperator = v + } +} + +// WithDf - the field to use as default where no field prefix is given in the query string. +// +func (f Count) WithDf(v string) func(*CountRequest) { + return func(r *CountRequest) { + r.Df = v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f Count) WithExpandWildcards(v string) func(*CountRequest) { + return func(r *CountRequest) { + r.ExpandWildcards = v + } +} + +// WithIgnoreThrottled - whether specified concrete, expanded or aliased indices should be ignored when throttled. +// +func (f Count) WithIgnoreThrottled(v bool) func(*CountRequest) { + return func(r *CountRequest) { + r.IgnoreThrottled = &v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f Count) WithIgnoreUnavailable(v bool) func(*CountRequest) { + return func(r *CountRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithLenient - specify whether format-based query failures (such as providing text to a numeric field) should be ignored. +// +func (f Count) WithLenient(v bool) func(*CountRequest) { + return func(r *CountRequest) { + r.Lenient = &v + } +} + +// WithMinScore - include only documents with a specific `_score` value in the result. +// +func (f Count) WithMinScore(v int) func(*CountRequest) { + return func(r *CountRequest) { + r.MinScore = &v + } +} + +// WithPreference - specify the node or shard the operation should be performed on (default: random). +// +func (f Count) WithPreference(v string) func(*CountRequest) { + return func(r *CountRequest) { + r.Preference = v + } +} + +// WithQuery - query in the lucene query string syntax. +// +func (f Count) WithQuery(v string) func(*CountRequest) { + return func(r *CountRequest) { + r.Query = v + } +} + +// WithRouting - a list of specific routing values. +// +func (f Count) WithRouting(v ...string) func(*CountRequest) { + return func(r *CountRequest) { + r.Routing = v + } +} + +// WithTerminateAfter - the maximum count for each shard, upon reaching which the query execution will terminate early. +// +func (f Count) WithTerminateAfter(v int) func(*CountRequest) { + return func(r *CountRequest) { + r.TerminateAfter = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f Count) WithPretty() func(*CountRequest) { + return func(r *CountRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f Count) WithHuman() func(*CountRequest) { + return func(r *CountRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f Count) WithErrorTrace() func(*CountRequest) { + return func(r *CountRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f Count) WithFilterPath(v ...string) func(*CountRequest) { + return func(r *CountRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f Count) WithHeader(h map[string]string) func(*CountRequest) { + return func(r *CountRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f Count) WithOpaqueID(s string) func(*CountRequest) { + return func(r *CountRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.create.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.create.go new file mode 100644 index 00000000000..d76f20a99af --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.create.go @@ -0,0 +1,294 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" + "time" +) + +func newCreateFunc(t Transport) Create { + return func(index string, id string, body io.Reader, o ...func(*CreateRequest)) (*Response, error) { + var r = CreateRequest{Index: index, DocumentID: id, Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// Create creates a new document in the index. +// +// Returns a 409 response when a document with a same ID already exists in the index. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html. +// +type Create func(index string, id string, body io.Reader, o ...func(*CreateRequest)) (*Response, error) + +// CreateRequest configures the Create API request. +// +type CreateRequest struct { + Index string + DocumentID string + + Body io.Reader + + Pipeline string + Refresh string + Routing string + Timeout time.Duration + Version *int + VersionType string + WaitForActiveShards string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CreateRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len(r.Index) + 1 + len("_create") + 1 + len(r.DocumentID)) + path.WriteString("/") + path.WriteString(r.Index) + path.WriteString("/") + path.WriteString("_create") + path.WriteString("/") + path.WriteString(r.DocumentID) + + params = make(map[string]string) + + if r.Pipeline != "" { + params["pipeline"] = r.Pipeline + } + + if r.Refresh != "" { + params["refresh"] = r.Refresh + } + + if r.Routing != "" { + params["routing"] = r.Routing + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Version != nil { + params["version"] = strconv.FormatInt(int64(*r.Version), 10) + } + + if r.VersionType != "" { + params["version_type"] = r.VersionType + } + + if r.WaitForActiveShards != "" { + params["wait_for_active_shards"] = r.WaitForActiveShards + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f Create) WithContext(v context.Context) func(*CreateRequest) { + return func(r *CreateRequest) { + r.ctx = v + } +} + +// WithPipeline - the pipeline ID to preprocess incoming documents with. +// +func (f Create) WithPipeline(v string) func(*CreateRequest) { + return func(r *CreateRequest) { + r.Pipeline = v + } +} + +// WithRefresh - if `true` then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` (the default) then do nothing with refreshes.. +// +func (f Create) WithRefresh(v string) func(*CreateRequest) { + return func(r *CreateRequest) { + r.Refresh = v + } +} + +// WithRouting - specific routing value. +// +func (f Create) WithRouting(v string) func(*CreateRequest) { + return func(r *CreateRequest) { + r.Routing = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f Create) WithTimeout(v time.Duration) func(*CreateRequest) { + return func(r *CreateRequest) { + r.Timeout = v + } +} + +// WithVersion - explicit version number for concurrency control. +// +func (f Create) WithVersion(v int) func(*CreateRequest) { + return func(r *CreateRequest) { + r.Version = &v + } +} + +// WithVersionType - specific version type. +// +func (f Create) WithVersionType(v string) func(*CreateRequest) { + return func(r *CreateRequest) { + r.VersionType = v + } +} + +// WithWaitForActiveShards - sets the number of shard copies that must be active before proceeding with the index operation. defaults to 1, meaning the primary shard only. set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1). +// +func (f Create) WithWaitForActiveShards(v string) func(*CreateRequest) { + return func(r *CreateRequest) { + r.WaitForActiveShards = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f Create) WithPretty() func(*CreateRequest) { + return func(r *CreateRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f Create) WithHuman() func(*CreateRequest) { + return func(r *CreateRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f Create) WithErrorTrace() func(*CreateRequest) { + return func(r *CreateRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f Create) WithFilterPath(v ...string) func(*CreateRequest) { + return func(r *CreateRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f Create) WithHeader(h map[string]string) func(*CreateRequest) { + return func(r *CreateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f Create) WithOpaqueID(s string) func(*CreateRequest) { + return func(r *CreateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.delete.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.delete.go new file mode 100644 index 00000000000..2bac9054f23 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.delete.go @@ -0,0 +1,298 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newDeleteFunc(t Transport) Delete { + return func(index string, id string, o ...func(*DeleteRequest)) (*Response, error) { + var r = DeleteRequest{Index: index, DocumentID: id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// Delete removes a document from the index. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete.html. +// +type Delete func(index string, id string, o ...func(*DeleteRequest)) (*Response, error) + +// DeleteRequest configures the Delete API request. +// +type DeleteRequest struct { + Index string + DocumentID string + + IfPrimaryTerm *int + IfSeqNo *int + Refresh string + Routing string + Timeout time.Duration + Version *int + VersionType string + WaitForActiveShards string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r DeleteRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len(r.Index) + 1 + len("_doc") + 1 + len(r.DocumentID)) + path.WriteString("/") + path.WriteString(r.Index) + path.WriteString("/") + path.WriteString("_doc") + path.WriteString("/") + path.WriteString(r.DocumentID) + + params = make(map[string]string) + + if r.IfPrimaryTerm != nil { + params["if_primary_term"] = strconv.FormatInt(int64(*r.IfPrimaryTerm), 10) + } + + if r.IfSeqNo != nil { + params["if_seq_no"] = strconv.FormatInt(int64(*r.IfSeqNo), 10) + } + + if r.Refresh != "" { + params["refresh"] = r.Refresh + } + + if r.Routing != "" { + params["routing"] = r.Routing + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Version != nil { + params["version"] = strconv.FormatInt(int64(*r.Version), 10) + } + + if r.VersionType != "" { + params["version_type"] = r.VersionType + } + + if r.WaitForActiveShards != "" { + params["wait_for_active_shards"] = r.WaitForActiveShards + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f Delete) WithContext(v context.Context) func(*DeleteRequest) { + return func(r *DeleteRequest) { + r.ctx = v + } +} + +// WithIfPrimaryTerm - only perform the delete operation if the last operation that has changed the document has the specified primary term. +// +func (f Delete) WithIfPrimaryTerm(v int) func(*DeleteRequest) { + return func(r *DeleteRequest) { + r.IfPrimaryTerm = &v + } +} + +// WithIfSeqNo - only perform the delete operation if the last operation that has changed the document has the specified sequence number. +// +func (f Delete) WithIfSeqNo(v int) func(*DeleteRequest) { + return func(r *DeleteRequest) { + r.IfSeqNo = &v + } +} + +// WithRefresh - if `true` then refresh the effected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` (the default) then do nothing with refreshes.. +// +func (f Delete) WithRefresh(v string) func(*DeleteRequest) { + return func(r *DeleteRequest) { + r.Refresh = v + } +} + +// WithRouting - specific routing value. +// +func (f Delete) WithRouting(v string) func(*DeleteRequest) { + return func(r *DeleteRequest) { + r.Routing = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f Delete) WithTimeout(v time.Duration) func(*DeleteRequest) { + return func(r *DeleteRequest) { + r.Timeout = v + } +} + +// WithVersion - explicit version number for concurrency control. +// +func (f Delete) WithVersion(v int) func(*DeleteRequest) { + return func(r *DeleteRequest) { + r.Version = &v + } +} + +// WithVersionType - specific version type. +// +func (f Delete) WithVersionType(v string) func(*DeleteRequest) { + return func(r *DeleteRequest) { + r.VersionType = v + } +} + +// WithWaitForActiveShards - sets the number of shard copies that must be active before proceeding with the delete operation. defaults to 1, meaning the primary shard only. set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1). +// +func (f Delete) WithWaitForActiveShards(v string) func(*DeleteRequest) { + return func(r *DeleteRequest) { + r.WaitForActiveShards = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f Delete) WithPretty() func(*DeleteRequest) { + return func(r *DeleteRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f Delete) WithHuman() func(*DeleteRequest) { + return func(r *DeleteRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f Delete) WithErrorTrace() func(*DeleteRequest) { + return func(r *DeleteRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f Delete) WithFilterPath(v ...string) func(*DeleteRequest) { + return func(r *DeleteRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f Delete) WithHeader(h map[string]string) func(*DeleteRequest) { + return func(r *DeleteRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f Delete) WithOpaqueID(s string) func(*DeleteRequest) { + return func(r *DeleteRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.delete_by_query.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.delete_by_query.go new file mode 100644 index 00000000000..e931a474dc6 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.delete_by_query.go @@ -0,0 +1,614 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" + "time" +) + +func newDeleteByQueryFunc(t Transport) DeleteByQuery { + return func(index []string, body io.Reader, o ...func(*DeleteByQueryRequest)) (*Response, error) { + var r = DeleteByQueryRequest{Index: index, Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// DeleteByQuery deletes documents matching the provided query. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete-by-query.html. +// +type DeleteByQuery func(index []string, body io.Reader, o ...func(*DeleteByQueryRequest)) (*Response, error) + +// DeleteByQueryRequest configures the Delete By Query API request. +// +type DeleteByQueryRequest struct { + Index []string + + Body io.Reader + + AllowNoIndices *bool + Analyzer string + AnalyzeWildcard *bool + Conflicts string + DefaultOperator string + Df string + ExpandWildcards string + From *int + IgnoreUnavailable *bool + Lenient *bool + MaxDocs *int + Preference string + Query string + Refresh *bool + RequestCache *bool + RequestsPerSecond *int + Routing []string + Scroll time.Duration + ScrollSize *int + SearchTimeout time.Duration + SearchType string + Slices *int + Sort []string + Source []string + SourceExcludes []string + SourceIncludes []string + Stats []string + TerminateAfter *int + Timeout time.Duration + Version *bool + WaitForActiveShards string + WaitForCompletion *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r DeleteByQueryRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_delete_by_query")) + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + path.WriteString("/") + path.WriteString("_delete_by_query") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.Analyzer != "" { + params["analyzer"] = r.Analyzer + } + + if r.AnalyzeWildcard != nil { + params["analyze_wildcard"] = strconv.FormatBool(*r.AnalyzeWildcard) + } + + if r.Conflicts != "" { + params["conflicts"] = r.Conflicts + } + + if r.DefaultOperator != "" { + params["default_operator"] = r.DefaultOperator + } + + if r.Df != "" { + params["df"] = r.Df + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.From != nil { + params["from"] = strconv.FormatInt(int64(*r.From), 10) + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.Lenient != nil { + params["lenient"] = strconv.FormatBool(*r.Lenient) + } + + if r.MaxDocs != nil { + params["max_docs"] = strconv.FormatInt(int64(*r.MaxDocs), 10) + } + + if r.Preference != "" { + params["preference"] = r.Preference + } + + if r.Query != "" { + params["q"] = r.Query + } + + if r.Refresh != nil { + params["refresh"] = strconv.FormatBool(*r.Refresh) + } + + if r.RequestCache != nil { + params["request_cache"] = strconv.FormatBool(*r.RequestCache) + } + + if r.RequestsPerSecond != nil { + params["requests_per_second"] = strconv.FormatInt(int64(*r.RequestsPerSecond), 10) + } + + if len(r.Routing) > 0 { + params["routing"] = strings.Join(r.Routing, ",") + } + + if r.Scroll != 0 { + params["scroll"] = formatDuration(r.Scroll) + } + + if r.ScrollSize != nil { + params["scroll_size"] = strconv.FormatInt(int64(*r.ScrollSize), 10) + } + + if r.SearchTimeout != 0 { + params["search_timeout"] = formatDuration(r.SearchTimeout) + } + + if r.SearchType != "" { + params["search_type"] = r.SearchType + } + + if r.Slices != nil { + params["slices"] = strconv.FormatInt(int64(*r.Slices), 10) + } + + if len(r.Sort) > 0 { + params["sort"] = strings.Join(r.Sort, ",") + } + + if len(r.Source) > 0 { + params["_source"] = strings.Join(r.Source, ",") + } + + if len(r.SourceExcludes) > 0 { + params["_source_excludes"] = strings.Join(r.SourceExcludes, ",") + } + + if len(r.SourceIncludes) > 0 { + params["_source_includes"] = strings.Join(r.SourceIncludes, ",") + } + + if len(r.Stats) > 0 { + params["stats"] = strings.Join(r.Stats, ",") + } + + if r.TerminateAfter != nil { + params["terminate_after"] = strconv.FormatInt(int64(*r.TerminateAfter), 10) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Version != nil { + params["version"] = strconv.FormatBool(*r.Version) + } + + if r.WaitForActiveShards != "" { + params["wait_for_active_shards"] = r.WaitForActiveShards + } + + if r.WaitForCompletion != nil { + params["wait_for_completion"] = strconv.FormatBool(*r.WaitForCompletion) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f DeleteByQuery) WithContext(v context.Context) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.ctx = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f DeleteByQuery) WithAllowNoIndices(v bool) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.AllowNoIndices = &v + } +} + +// WithAnalyzer - the analyzer to use for the query string. +// +func (f DeleteByQuery) WithAnalyzer(v string) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.Analyzer = v + } +} + +// WithAnalyzeWildcard - specify whether wildcard and prefix queries should be analyzed (default: false). +// +func (f DeleteByQuery) WithAnalyzeWildcard(v bool) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.AnalyzeWildcard = &v + } +} + +// WithConflicts - what to do when the delete by query hits version conflicts?. +// +func (f DeleteByQuery) WithConflicts(v string) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.Conflicts = v + } +} + +// WithDefaultOperator - the default operator for query string query (and or or). +// +func (f DeleteByQuery) WithDefaultOperator(v string) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.DefaultOperator = v + } +} + +// WithDf - the field to use as default where no field prefix is given in the query string. +// +func (f DeleteByQuery) WithDf(v string) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.Df = v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f DeleteByQuery) WithExpandWildcards(v string) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.ExpandWildcards = v + } +} + +// WithFrom - starting offset (default: 0). +// +func (f DeleteByQuery) WithFrom(v int) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.From = &v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f DeleteByQuery) WithIgnoreUnavailable(v bool) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithLenient - specify whether format-based query failures (such as providing text to a numeric field) should be ignored. +// +func (f DeleteByQuery) WithLenient(v bool) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.Lenient = &v + } +} + +// WithMaxDocs - maximum number of documents to process (default: all documents). +// +func (f DeleteByQuery) WithMaxDocs(v int) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.MaxDocs = &v + } +} + +// WithPreference - specify the node or shard the operation should be performed on (default: random). +// +func (f DeleteByQuery) WithPreference(v string) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.Preference = v + } +} + +// WithQuery - query in the lucene query string syntax. +// +func (f DeleteByQuery) WithQuery(v string) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.Query = v + } +} + +// WithRefresh - should the effected indexes be refreshed?. +// +func (f DeleteByQuery) WithRefresh(v bool) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.Refresh = &v + } +} + +// WithRequestCache - specify if request cache should be used for this request or not, defaults to index level setting. +// +func (f DeleteByQuery) WithRequestCache(v bool) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.RequestCache = &v + } +} + +// WithRequestsPerSecond - the throttle for this request in sub-requests per second. -1 means no throttle.. +// +func (f DeleteByQuery) WithRequestsPerSecond(v int) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.RequestsPerSecond = &v + } +} + +// WithRouting - a list of specific routing values. +// +func (f DeleteByQuery) WithRouting(v ...string) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.Routing = v + } +} + +// WithScroll - specify how long a consistent view of the index should be maintained for scrolled search. +// +func (f DeleteByQuery) WithScroll(v time.Duration) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.Scroll = v + } +} + +// WithScrollSize - size on the scroll request powering the delete by query. +// +func (f DeleteByQuery) WithScrollSize(v int) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.ScrollSize = &v + } +} + +// WithSearchTimeout - explicit timeout for each search request. defaults to no timeout.. +// +func (f DeleteByQuery) WithSearchTimeout(v time.Duration) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.SearchTimeout = v + } +} + +// WithSearchType - search operation type. +// +func (f DeleteByQuery) WithSearchType(v string) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.SearchType = v + } +} + +// WithSlices - the number of slices this task should be divided into. defaults to 1 meaning the task isn't sliced into subtasks.. +// +func (f DeleteByQuery) WithSlices(v int) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.Slices = &v + } +} + +// WithSort - a list of : pairs. +// +func (f DeleteByQuery) WithSort(v ...string) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.Sort = v + } +} + +// WithSource - true or false to return the _source field or not, or a list of fields to return. +// +func (f DeleteByQuery) WithSource(v ...string) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.Source = v + } +} + +// WithSourceExcludes - a list of fields to exclude from the returned _source field. +// +func (f DeleteByQuery) WithSourceExcludes(v ...string) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.SourceExcludes = v + } +} + +// WithSourceIncludes - a list of fields to extract and return from the _source field. +// +func (f DeleteByQuery) WithSourceIncludes(v ...string) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.SourceIncludes = v + } +} + +// WithStats - specific 'tag' of the request for logging and statistical purposes. +// +func (f DeleteByQuery) WithStats(v ...string) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.Stats = v + } +} + +// WithTerminateAfter - the maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early.. +// +func (f DeleteByQuery) WithTerminateAfter(v int) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.TerminateAfter = &v + } +} + +// WithTimeout - time each individual bulk request should wait for shards that are unavailable.. +// +func (f DeleteByQuery) WithTimeout(v time.Duration) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.Timeout = v + } +} + +// WithVersion - specify whether to return document version as part of a hit. +// +func (f DeleteByQuery) WithVersion(v bool) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.Version = &v + } +} + +// WithWaitForActiveShards - sets the number of shard copies that must be active before proceeding with the delete by query operation. defaults to 1, meaning the primary shard only. set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1). +// +func (f DeleteByQuery) WithWaitForActiveShards(v string) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.WaitForActiveShards = v + } +} + +// WithWaitForCompletion - should the request should block until the delete by query is complete.. +// +func (f DeleteByQuery) WithWaitForCompletion(v bool) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.WaitForCompletion = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f DeleteByQuery) WithPretty() func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f DeleteByQuery) WithHuman() func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f DeleteByQuery) WithErrorTrace() func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f DeleteByQuery) WithFilterPath(v ...string) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f DeleteByQuery) WithHeader(h map[string]string) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f DeleteByQuery) WithOpaqueID(s string) func(*DeleteByQueryRequest) { + return func(r *DeleteByQueryRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.delete_by_query_rethrottle.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.delete_by_query_rethrottle.go new file mode 100644 index 00000000000..8a293053608 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.delete_by_query_rethrottle.go @@ -0,0 +1,205 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newDeleteByQueryRethrottleFunc(t Transport) DeleteByQueryRethrottle { + return func(task_id string, requests_per_second *int, o ...func(*DeleteByQueryRethrottleRequest)) (*Response, error) { + var r = DeleteByQueryRethrottleRequest{TaskID: task_id, RequestsPerSecond: requests_per_second} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// DeleteByQueryRethrottle changes the number of requests per second for a particular Delete By Query operation. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html. +// +type DeleteByQueryRethrottle func(task_id string, requests_per_second *int, o ...func(*DeleteByQueryRethrottleRequest)) (*Response, error) + +// DeleteByQueryRethrottleRequest configures the Delete By Query Rethrottle API request. +// +type DeleteByQueryRethrottleRequest struct { + TaskID string + + RequestsPerSecond *int + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r DeleteByQueryRethrottleRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_delete_by_query") + 1 + len(r.TaskID) + 1 + len("_rethrottle")) + path.WriteString("/") + path.WriteString("_delete_by_query") + path.WriteString("/") + path.WriteString(r.TaskID) + path.WriteString("/") + path.WriteString("_rethrottle") + + params = make(map[string]string) + + if r.RequestsPerSecond != nil { + params["requests_per_second"] = strconv.FormatInt(int64(*r.RequestsPerSecond), 10) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f DeleteByQueryRethrottle) WithContext(v context.Context) func(*DeleteByQueryRethrottleRequest) { + return func(r *DeleteByQueryRethrottleRequest) { + r.ctx = v + } +} + +// WithRequestsPerSecond - the throttle to set on this request in floating sub-requests per second. -1 means set no throttle.. +// +func (f DeleteByQueryRethrottle) WithRequestsPerSecond(v int) func(*DeleteByQueryRethrottleRequest) { + return func(r *DeleteByQueryRethrottleRequest) { + r.RequestsPerSecond = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f DeleteByQueryRethrottle) WithPretty() func(*DeleteByQueryRethrottleRequest) { + return func(r *DeleteByQueryRethrottleRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f DeleteByQueryRethrottle) WithHuman() func(*DeleteByQueryRethrottleRequest) { + return func(r *DeleteByQueryRethrottleRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f DeleteByQueryRethrottle) WithErrorTrace() func(*DeleteByQueryRethrottleRequest) { + return func(r *DeleteByQueryRethrottleRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f DeleteByQueryRethrottle) WithFilterPath(v ...string) func(*DeleteByQueryRethrottleRequest) { + return func(r *DeleteByQueryRethrottleRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f DeleteByQueryRethrottle) WithHeader(h map[string]string) func(*DeleteByQueryRethrottleRequest) { + return func(r *DeleteByQueryRethrottleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f DeleteByQueryRethrottle) WithOpaqueID(s string) func(*DeleteByQueryRethrottleRequest) { + return func(r *DeleteByQueryRethrottleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.delete_script.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.delete_script.go new file mode 100644 index 00000000000..a53fdafb32b --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.delete_script.go @@ -0,0 +1,216 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" + "time" +) + +func newDeleteScriptFunc(t Transport) DeleteScript { + return func(id string, o ...func(*DeleteScriptRequest)) (*Response, error) { + var r = DeleteScriptRequest{ScriptID: id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// DeleteScript deletes a script. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html. +// +type DeleteScript func(id string, o ...func(*DeleteScriptRequest)) (*Response, error) + +// DeleteScriptRequest configures the Delete Script API request. +// +type DeleteScriptRequest struct { + ScriptID string + + MasterTimeout time.Duration + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r DeleteScriptRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_scripts") + 1 + len(r.ScriptID)) + path.WriteString("/") + path.WriteString("_scripts") + path.WriteString("/") + path.WriteString(r.ScriptID) + + params = make(map[string]string) + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f DeleteScript) WithContext(v context.Context) func(*DeleteScriptRequest) { + return func(r *DeleteScriptRequest) { + r.ctx = v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f DeleteScript) WithMasterTimeout(v time.Duration) func(*DeleteScriptRequest) { + return func(r *DeleteScriptRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f DeleteScript) WithTimeout(v time.Duration) func(*DeleteScriptRequest) { + return func(r *DeleteScriptRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f DeleteScript) WithPretty() func(*DeleteScriptRequest) { + return func(r *DeleteScriptRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f DeleteScript) WithHuman() func(*DeleteScriptRequest) { + return func(r *DeleteScriptRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f DeleteScript) WithErrorTrace() func(*DeleteScriptRequest) { + return func(r *DeleteScriptRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f DeleteScript) WithFilterPath(v ...string) func(*DeleteScriptRequest) { + return func(r *DeleteScriptRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f DeleteScript) WithHeader(h map[string]string) func(*DeleteScriptRequest) { + return func(r *DeleteScriptRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f DeleteScript) WithOpaqueID(s string) func(*DeleteScriptRequest) { + return func(r *DeleteScriptRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.exists.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.exists.go new file mode 100644 index 00000000000..ce7d6da6857 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.exists.go @@ -0,0 +1,323 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newExistsFunc(t Transport) Exists { + return func(index string, id string, o ...func(*ExistsRequest)) (*Response, error) { + var r = ExistsRequest{Index: index, DocumentID: id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// Exists returns information about whether a document exists in an index. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html. +// +type Exists func(index string, id string, o ...func(*ExistsRequest)) (*Response, error) + +// ExistsRequest configures the Exists API request. +// +type ExistsRequest struct { + Index string + DocumentID string + + Preference string + Realtime *bool + Refresh *bool + Routing string + Source []string + SourceExcludes []string + SourceIncludes []string + StoredFields []string + Version *int + VersionType string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ExistsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "HEAD" + + path.Grow(1 + len(r.Index) + 1 + len("_doc") + 1 + len(r.DocumentID)) + path.WriteString("/") + path.WriteString(r.Index) + path.WriteString("/") + path.WriteString("_doc") + path.WriteString("/") + path.WriteString(r.DocumentID) + + params = make(map[string]string) + + if r.Preference != "" { + params["preference"] = r.Preference + } + + if r.Realtime != nil { + params["realtime"] = strconv.FormatBool(*r.Realtime) + } + + if r.Refresh != nil { + params["refresh"] = strconv.FormatBool(*r.Refresh) + } + + if r.Routing != "" { + params["routing"] = r.Routing + } + + if len(r.Source) > 0 { + params["_source"] = strings.Join(r.Source, ",") + } + + if len(r.SourceExcludes) > 0 { + params["_source_excludes"] = strings.Join(r.SourceExcludes, ",") + } + + if len(r.SourceIncludes) > 0 { + params["_source_includes"] = strings.Join(r.SourceIncludes, ",") + } + + if len(r.StoredFields) > 0 { + params["stored_fields"] = strings.Join(r.StoredFields, ",") + } + + if r.Version != nil { + params["version"] = strconv.FormatInt(int64(*r.Version), 10) + } + + if r.VersionType != "" { + params["version_type"] = r.VersionType + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f Exists) WithContext(v context.Context) func(*ExistsRequest) { + return func(r *ExistsRequest) { + r.ctx = v + } +} + +// WithPreference - specify the node or shard the operation should be performed on (default: random). +// +func (f Exists) WithPreference(v string) func(*ExistsRequest) { + return func(r *ExistsRequest) { + r.Preference = v + } +} + +// WithRealtime - specify whether to perform the operation in realtime or search mode. +// +func (f Exists) WithRealtime(v bool) func(*ExistsRequest) { + return func(r *ExistsRequest) { + r.Realtime = &v + } +} + +// WithRefresh - refresh the shard containing the document before performing the operation. +// +func (f Exists) WithRefresh(v bool) func(*ExistsRequest) { + return func(r *ExistsRequest) { + r.Refresh = &v + } +} + +// WithRouting - specific routing value. +// +func (f Exists) WithRouting(v string) func(*ExistsRequest) { + return func(r *ExistsRequest) { + r.Routing = v + } +} + +// WithSource - true or false to return the _source field or not, or a list of fields to return. +// +func (f Exists) WithSource(v ...string) func(*ExistsRequest) { + return func(r *ExistsRequest) { + r.Source = v + } +} + +// WithSourceExcludes - a list of fields to exclude from the returned _source field. +// +func (f Exists) WithSourceExcludes(v ...string) func(*ExistsRequest) { + return func(r *ExistsRequest) { + r.SourceExcludes = v + } +} + +// WithSourceIncludes - a list of fields to extract and return from the _source field. +// +func (f Exists) WithSourceIncludes(v ...string) func(*ExistsRequest) { + return func(r *ExistsRequest) { + r.SourceIncludes = v + } +} + +// WithStoredFields - a list of stored fields to return in the response. +// +func (f Exists) WithStoredFields(v ...string) func(*ExistsRequest) { + return func(r *ExistsRequest) { + r.StoredFields = v + } +} + +// WithVersion - explicit version number for concurrency control. +// +func (f Exists) WithVersion(v int) func(*ExistsRequest) { + return func(r *ExistsRequest) { + r.Version = &v + } +} + +// WithVersionType - specific version type. +// +func (f Exists) WithVersionType(v string) func(*ExistsRequest) { + return func(r *ExistsRequest) { + r.VersionType = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f Exists) WithPretty() func(*ExistsRequest) { + return func(r *ExistsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f Exists) WithHuman() func(*ExistsRequest) { + return func(r *ExistsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f Exists) WithErrorTrace() func(*ExistsRequest) { + return func(r *ExistsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f Exists) WithFilterPath(v ...string) func(*ExistsRequest) { + return func(r *ExistsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f Exists) WithHeader(h map[string]string) func(*ExistsRequest) { + return func(r *ExistsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f Exists) WithOpaqueID(s string) func(*ExistsRequest) { + return func(r *ExistsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.exists_source.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.exists_source.go new file mode 100644 index 00000000000..41da2935e0b --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.exists_source.go @@ -0,0 +1,323 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newExistsSourceFunc(t Transport) ExistsSource { + return func(index string, id string, o ...func(*ExistsSourceRequest)) (*Response, error) { + var r = ExistsSourceRequest{Index: index, DocumentID: id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// ExistsSource returns information about whether a document source exists in an index. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html. +// +type ExistsSource func(index string, id string, o ...func(*ExistsSourceRequest)) (*Response, error) + +// ExistsSourceRequest configures the Exists Source API request. +// +type ExistsSourceRequest struct { + Index string + DocumentType string + DocumentID string + + Preference string + Realtime *bool + Refresh *bool + Routing string + Source []string + SourceExcludes []string + SourceIncludes []string + Version *int + VersionType string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ExistsSourceRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "HEAD" + + path.Grow(1 + len(r.Index) + 1 + len(r.DocumentType) + 1 + len(r.DocumentID) + 1 + len("_source")) + path.WriteString("/") + path.WriteString(r.Index) + if r.DocumentType != "" { + path.WriteString("/") + path.WriteString(r.DocumentType) + } + path.WriteString("/") + path.WriteString(r.DocumentID) + path.WriteString("/") + path.WriteString("_source") + + params = make(map[string]string) + + if r.Preference != "" { + params["preference"] = r.Preference + } + + if r.Realtime != nil { + params["realtime"] = strconv.FormatBool(*r.Realtime) + } + + if r.Refresh != nil { + params["refresh"] = strconv.FormatBool(*r.Refresh) + } + + if r.Routing != "" { + params["routing"] = r.Routing + } + + if len(r.Source) > 0 { + params["_source"] = strings.Join(r.Source, ",") + } + + if len(r.SourceExcludes) > 0 { + params["_source_excludes"] = strings.Join(r.SourceExcludes, ",") + } + + if len(r.SourceIncludes) > 0 { + params["_source_includes"] = strings.Join(r.SourceIncludes, ",") + } + + if r.Version != nil { + params["version"] = strconv.FormatInt(int64(*r.Version), 10) + } + + if r.VersionType != "" { + params["version_type"] = r.VersionType + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f ExistsSource) WithContext(v context.Context) func(*ExistsSourceRequest) { + return func(r *ExistsSourceRequest) { + r.ctx = v + } +} + +// WithDocumentType - the type of the document; deprecated and optional starting with 7.0. +// +func (f ExistsSource) WithDocumentType(v string) func(*ExistsSourceRequest) { + return func(r *ExistsSourceRequest) { + r.DocumentType = v + } +} + +// WithPreference - specify the node or shard the operation should be performed on (default: random). +// +func (f ExistsSource) WithPreference(v string) func(*ExistsSourceRequest) { + return func(r *ExistsSourceRequest) { + r.Preference = v + } +} + +// WithRealtime - specify whether to perform the operation in realtime or search mode. +// +func (f ExistsSource) WithRealtime(v bool) func(*ExistsSourceRequest) { + return func(r *ExistsSourceRequest) { + r.Realtime = &v + } +} + +// WithRefresh - refresh the shard containing the document before performing the operation. +// +func (f ExistsSource) WithRefresh(v bool) func(*ExistsSourceRequest) { + return func(r *ExistsSourceRequest) { + r.Refresh = &v + } +} + +// WithRouting - specific routing value. +// +func (f ExistsSource) WithRouting(v string) func(*ExistsSourceRequest) { + return func(r *ExistsSourceRequest) { + r.Routing = v + } +} + +// WithSource - true or false to return the _source field or not, or a list of fields to return. +// +func (f ExistsSource) WithSource(v ...string) func(*ExistsSourceRequest) { + return func(r *ExistsSourceRequest) { + r.Source = v + } +} + +// WithSourceExcludes - a list of fields to exclude from the returned _source field. +// +func (f ExistsSource) WithSourceExcludes(v ...string) func(*ExistsSourceRequest) { + return func(r *ExistsSourceRequest) { + r.SourceExcludes = v + } +} + +// WithSourceIncludes - a list of fields to extract and return from the _source field. +// +func (f ExistsSource) WithSourceIncludes(v ...string) func(*ExistsSourceRequest) { + return func(r *ExistsSourceRequest) { + r.SourceIncludes = v + } +} + +// WithVersion - explicit version number for concurrency control. +// +func (f ExistsSource) WithVersion(v int) func(*ExistsSourceRequest) { + return func(r *ExistsSourceRequest) { + r.Version = &v + } +} + +// WithVersionType - specific version type. +// +func (f ExistsSource) WithVersionType(v string) func(*ExistsSourceRequest) { + return func(r *ExistsSourceRequest) { + r.VersionType = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f ExistsSource) WithPretty() func(*ExistsSourceRequest) { + return func(r *ExistsSourceRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f ExistsSource) WithHuman() func(*ExistsSourceRequest) { + return func(r *ExistsSourceRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ExistsSource) WithErrorTrace() func(*ExistsSourceRequest) { + return func(r *ExistsSourceRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f ExistsSource) WithFilterPath(v ...string) func(*ExistsSourceRequest) { + return func(r *ExistsSourceRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f ExistsSource) WithHeader(h map[string]string) func(*ExistsSourceRequest) { + return func(r *ExistsSourceRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f ExistsSource) WithOpaqueID(s string) func(*ExistsSourceRequest) { + return func(r *ExistsSourceRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.explain.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.explain.go new file mode 100644 index 00000000000..cdf1c3774ee --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.explain.go @@ -0,0 +1,364 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newExplainFunc(t Transport) Explain { + return func(index string, id string, o ...func(*ExplainRequest)) (*Response, error) { + var r = ExplainRequest{Index: index, DocumentID: id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// Explain returns information about why a specific matches (or doesn't match) a query. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/search-explain.html. +// +type Explain func(index string, id string, o ...func(*ExplainRequest)) (*Response, error) + +// ExplainRequest configures the Explain API request. +// +type ExplainRequest struct { + Index string + DocumentID string + + Body io.Reader + + Analyzer string + AnalyzeWildcard *bool + DefaultOperator string + Df string + Lenient *bool + Preference string + Query string + Routing string + Source []string + SourceExcludes []string + SourceIncludes []string + StoredFields []string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ExplainRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(r.Index) + 1 + len("_explain") + 1 + len(r.DocumentID)) + path.WriteString("/") + path.WriteString(r.Index) + path.WriteString("/") + path.WriteString("_explain") + path.WriteString("/") + path.WriteString(r.DocumentID) + + params = make(map[string]string) + + if r.Analyzer != "" { + params["analyzer"] = r.Analyzer + } + + if r.AnalyzeWildcard != nil { + params["analyze_wildcard"] = strconv.FormatBool(*r.AnalyzeWildcard) + } + + if r.DefaultOperator != "" { + params["default_operator"] = r.DefaultOperator + } + + if r.Df != "" { + params["df"] = r.Df + } + + if r.Lenient != nil { + params["lenient"] = strconv.FormatBool(*r.Lenient) + } + + if r.Preference != "" { + params["preference"] = r.Preference + } + + if r.Query != "" { + params["q"] = r.Query + } + + if r.Routing != "" { + params["routing"] = r.Routing + } + + if len(r.Source) > 0 { + params["_source"] = strings.Join(r.Source, ",") + } + + if len(r.SourceExcludes) > 0 { + params["_source_excludes"] = strings.Join(r.SourceExcludes, ",") + } + + if len(r.SourceIncludes) > 0 { + params["_source_includes"] = strings.Join(r.SourceIncludes, ",") + } + + if len(r.StoredFields) > 0 { + params["stored_fields"] = strings.Join(r.StoredFields, ",") + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f Explain) WithContext(v context.Context) func(*ExplainRequest) { + return func(r *ExplainRequest) { + r.ctx = v + } +} + +// WithBody - The query definition using the Query DSL. +// +func (f Explain) WithBody(v io.Reader) func(*ExplainRequest) { + return func(r *ExplainRequest) { + r.Body = v + } +} + +// WithAnalyzer - the analyzer for the query string query. +// +func (f Explain) WithAnalyzer(v string) func(*ExplainRequest) { + return func(r *ExplainRequest) { + r.Analyzer = v + } +} + +// WithAnalyzeWildcard - specify whether wildcards and prefix queries in the query string query should be analyzed (default: false). +// +func (f Explain) WithAnalyzeWildcard(v bool) func(*ExplainRequest) { + return func(r *ExplainRequest) { + r.AnalyzeWildcard = &v + } +} + +// WithDefaultOperator - the default operator for query string query (and or or). +// +func (f Explain) WithDefaultOperator(v string) func(*ExplainRequest) { + return func(r *ExplainRequest) { + r.DefaultOperator = v + } +} + +// WithDf - the default field for query string query (default: _all). +// +func (f Explain) WithDf(v string) func(*ExplainRequest) { + return func(r *ExplainRequest) { + r.Df = v + } +} + +// WithLenient - specify whether format-based query failures (such as providing text to a numeric field) should be ignored. +// +func (f Explain) WithLenient(v bool) func(*ExplainRequest) { + return func(r *ExplainRequest) { + r.Lenient = &v + } +} + +// WithPreference - specify the node or shard the operation should be performed on (default: random). +// +func (f Explain) WithPreference(v string) func(*ExplainRequest) { + return func(r *ExplainRequest) { + r.Preference = v + } +} + +// WithQuery - query in the lucene query string syntax. +// +func (f Explain) WithQuery(v string) func(*ExplainRequest) { + return func(r *ExplainRequest) { + r.Query = v + } +} + +// WithRouting - specific routing value. +// +func (f Explain) WithRouting(v string) func(*ExplainRequest) { + return func(r *ExplainRequest) { + r.Routing = v + } +} + +// WithSource - true or false to return the _source field or not, or a list of fields to return. +// +func (f Explain) WithSource(v ...string) func(*ExplainRequest) { + return func(r *ExplainRequest) { + r.Source = v + } +} + +// WithSourceExcludes - a list of fields to exclude from the returned _source field. +// +func (f Explain) WithSourceExcludes(v ...string) func(*ExplainRequest) { + return func(r *ExplainRequest) { + r.SourceExcludes = v + } +} + +// WithSourceIncludes - a list of fields to extract and return from the _source field. +// +func (f Explain) WithSourceIncludes(v ...string) func(*ExplainRequest) { + return func(r *ExplainRequest) { + r.SourceIncludes = v + } +} + +// WithStoredFields - a list of stored fields to return in the response. +// +func (f Explain) WithStoredFields(v ...string) func(*ExplainRequest) { + return func(r *ExplainRequest) { + r.StoredFields = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f Explain) WithPretty() func(*ExplainRequest) { + return func(r *ExplainRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f Explain) WithHuman() func(*ExplainRequest) { + return func(r *ExplainRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f Explain) WithErrorTrace() func(*ExplainRequest) { + return func(r *ExplainRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f Explain) WithFilterPath(v ...string) func(*ExplainRequest) { + return func(r *ExplainRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f Explain) WithHeader(h map[string]string) func(*ExplainRequest) { + return func(r *ExplainRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f Explain) WithOpaqueID(s string) func(*ExplainRequest) { + return func(r *ExplainRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.field_caps.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.field_caps.go new file mode 100644 index 00000000000..752cd07c479 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.field_caps.go @@ -0,0 +1,265 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newFieldCapsFunc(t Transport) FieldCaps { + return func(o ...func(*FieldCapsRequest)) (*Response, error) { + var r = FieldCapsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// FieldCaps returns the information about the capabilities of fields among multiple indices. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/search-field-caps.html. +// +type FieldCaps func(o ...func(*FieldCapsRequest)) (*Response, error) + +// FieldCapsRequest configures the Field Caps API request. +// +type FieldCapsRequest struct { + Index []string + + AllowNoIndices *bool + ExpandWildcards string + Fields []string + IgnoreUnavailable *bool + IncludeUnmapped *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r FieldCapsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_field_caps")) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_field_caps") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if len(r.Fields) > 0 { + params["fields"] = strings.Join(r.Fields, ",") + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.IncludeUnmapped != nil { + params["include_unmapped"] = strconv.FormatBool(*r.IncludeUnmapped) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f FieldCaps) WithContext(v context.Context) func(*FieldCapsRequest) { + return func(r *FieldCapsRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names; use _all to perform the operation on all indices. +// +func (f FieldCaps) WithIndex(v ...string) func(*FieldCapsRequest) { + return func(r *FieldCapsRequest) { + r.Index = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f FieldCaps) WithAllowNoIndices(v bool) func(*FieldCapsRequest) { + return func(r *FieldCapsRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f FieldCaps) WithExpandWildcards(v string) func(*FieldCapsRequest) { + return func(r *FieldCapsRequest) { + r.ExpandWildcards = v + } +} + +// WithFields - a list of field names. +// +func (f FieldCaps) WithFields(v ...string) func(*FieldCapsRequest) { + return func(r *FieldCapsRequest) { + r.Fields = v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f FieldCaps) WithIgnoreUnavailable(v bool) func(*FieldCapsRequest) { + return func(r *FieldCapsRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithIncludeUnmapped - indicates whether unmapped fields should be included in the response.. +// +func (f FieldCaps) WithIncludeUnmapped(v bool) func(*FieldCapsRequest) { + return func(r *FieldCapsRequest) { + r.IncludeUnmapped = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f FieldCaps) WithPretty() func(*FieldCapsRequest) { + return func(r *FieldCapsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f FieldCaps) WithHuman() func(*FieldCapsRequest) { + return func(r *FieldCapsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f FieldCaps) WithErrorTrace() func(*FieldCapsRequest) { + return func(r *FieldCapsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f FieldCaps) WithFilterPath(v ...string) func(*FieldCapsRequest) { + return func(r *FieldCapsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f FieldCaps) WithHeader(h map[string]string) func(*FieldCapsRequest) { + return func(r *FieldCapsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f FieldCaps) WithOpaqueID(s string) func(*FieldCapsRequest) { + return func(r *FieldCapsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.get.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.get.go new file mode 100644 index 00000000000..2851f2bbb17 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.get.go @@ -0,0 +1,323 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newGetFunc(t Transport) Get { + return func(index string, id string, o ...func(*GetRequest)) (*Response, error) { + var r = GetRequest{Index: index, DocumentID: id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// Get returns a document. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html. +// +type Get func(index string, id string, o ...func(*GetRequest)) (*Response, error) + +// GetRequest configures the Get API request. +// +type GetRequest struct { + Index string + DocumentID string + + Preference string + Realtime *bool + Refresh *bool + Routing string + Source []string + SourceExcludes []string + SourceIncludes []string + StoredFields []string + Version *int + VersionType string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r GetRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(r.Index) + 1 + len("_doc") + 1 + len(r.DocumentID)) + path.WriteString("/") + path.WriteString(r.Index) + path.WriteString("/") + path.WriteString("_doc") + path.WriteString("/") + path.WriteString(r.DocumentID) + + params = make(map[string]string) + + if r.Preference != "" { + params["preference"] = r.Preference + } + + if r.Realtime != nil { + params["realtime"] = strconv.FormatBool(*r.Realtime) + } + + if r.Refresh != nil { + params["refresh"] = strconv.FormatBool(*r.Refresh) + } + + if r.Routing != "" { + params["routing"] = r.Routing + } + + if len(r.Source) > 0 { + params["_source"] = strings.Join(r.Source, ",") + } + + if len(r.SourceExcludes) > 0 { + params["_source_excludes"] = strings.Join(r.SourceExcludes, ",") + } + + if len(r.SourceIncludes) > 0 { + params["_source_includes"] = strings.Join(r.SourceIncludes, ",") + } + + if len(r.StoredFields) > 0 { + params["stored_fields"] = strings.Join(r.StoredFields, ",") + } + + if r.Version != nil { + params["version"] = strconv.FormatInt(int64(*r.Version), 10) + } + + if r.VersionType != "" { + params["version_type"] = r.VersionType + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f Get) WithContext(v context.Context) func(*GetRequest) { + return func(r *GetRequest) { + r.ctx = v + } +} + +// WithPreference - specify the node or shard the operation should be performed on (default: random). +// +func (f Get) WithPreference(v string) func(*GetRequest) { + return func(r *GetRequest) { + r.Preference = v + } +} + +// WithRealtime - specify whether to perform the operation in realtime or search mode. +// +func (f Get) WithRealtime(v bool) func(*GetRequest) { + return func(r *GetRequest) { + r.Realtime = &v + } +} + +// WithRefresh - refresh the shard containing the document before performing the operation. +// +func (f Get) WithRefresh(v bool) func(*GetRequest) { + return func(r *GetRequest) { + r.Refresh = &v + } +} + +// WithRouting - specific routing value. +// +func (f Get) WithRouting(v string) func(*GetRequest) { + return func(r *GetRequest) { + r.Routing = v + } +} + +// WithSource - true or false to return the _source field or not, or a list of fields to return. +// +func (f Get) WithSource(v ...string) func(*GetRequest) { + return func(r *GetRequest) { + r.Source = v + } +} + +// WithSourceExcludes - a list of fields to exclude from the returned _source field. +// +func (f Get) WithSourceExcludes(v ...string) func(*GetRequest) { + return func(r *GetRequest) { + r.SourceExcludes = v + } +} + +// WithSourceIncludes - a list of fields to extract and return from the _source field. +// +func (f Get) WithSourceIncludes(v ...string) func(*GetRequest) { + return func(r *GetRequest) { + r.SourceIncludes = v + } +} + +// WithStoredFields - a list of stored fields to return in the response. +// +func (f Get) WithStoredFields(v ...string) func(*GetRequest) { + return func(r *GetRequest) { + r.StoredFields = v + } +} + +// WithVersion - explicit version number for concurrency control. +// +func (f Get) WithVersion(v int) func(*GetRequest) { + return func(r *GetRequest) { + r.Version = &v + } +} + +// WithVersionType - specific version type. +// +func (f Get) WithVersionType(v string) func(*GetRequest) { + return func(r *GetRequest) { + r.VersionType = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f Get) WithPretty() func(*GetRequest) { + return func(r *GetRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f Get) WithHuman() func(*GetRequest) { + return func(r *GetRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f Get) WithErrorTrace() func(*GetRequest) { + return func(r *GetRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f Get) WithFilterPath(v ...string) func(*GetRequest) { + return func(r *GetRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f Get) WithHeader(h map[string]string) func(*GetRequest) { + return func(r *GetRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f Get) WithOpaqueID(s string) func(*GetRequest) { + return func(r *GetRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.get_script.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.get_script.go new file mode 100644 index 00000000000..c092c72c930 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.get_script.go @@ -0,0 +1,203 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" + "time" +) + +func newGetScriptFunc(t Transport) GetScript { + return func(id string, o ...func(*GetScriptRequest)) (*Response, error) { + var r = GetScriptRequest{ScriptID: id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// GetScript returns a script. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html. +// +type GetScript func(id string, o ...func(*GetScriptRequest)) (*Response, error) + +// GetScriptRequest configures the Get Script API request. +// +type GetScriptRequest struct { + ScriptID string + + MasterTimeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r GetScriptRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_scripts") + 1 + len(r.ScriptID)) + path.WriteString("/") + path.WriteString("_scripts") + path.WriteString("/") + path.WriteString(r.ScriptID) + + params = make(map[string]string) + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f GetScript) WithContext(v context.Context) func(*GetScriptRequest) { + return func(r *GetScriptRequest) { + r.ctx = v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f GetScript) WithMasterTimeout(v time.Duration) func(*GetScriptRequest) { + return func(r *GetScriptRequest) { + r.MasterTimeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f GetScript) WithPretty() func(*GetScriptRequest) { + return func(r *GetScriptRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f GetScript) WithHuman() func(*GetScriptRequest) { + return func(r *GetScriptRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f GetScript) WithErrorTrace() func(*GetScriptRequest) { + return func(r *GetScriptRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f GetScript) WithFilterPath(v ...string) func(*GetScriptRequest) { + return func(r *GetScriptRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f GetScript) WithHeader(h map[string]string) func(*GetScriptRequest) { + return func(r *GetScriptRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f GetScript) WithOpaqueID(s string) func(*GetScriptRequest) { + return func(r *GetScriptRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.get_script_context.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.get_script_context.go new file mode 100644 index 00000000000..f292dfcd694 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.get_script_context.go @@ -0,0 +1,181 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newGetScriptContextFunc(t Transport) GetScriptContext { + return func(o ...func(*GetScriptContextRequest)) (*Response, error) { + var r = GetScriptContextRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// GetScriptContext returns all script contexts. +// +type GetScriptContext func(o ...func(*GetScriptContextRequest)) (*Response, error) + +// GetScriptContextRequest configures the Get Script Context API request. +// +type GetScriptContextRequest struct { + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r GetScriptContextRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_script_context")) + path.WriteString("/_script_context") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f GetScriptContext) WithContext(v context.Context) func(*GetScriptContextRequest) { + return func(r *GetScriptContextRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f GetScriptContext) WithPretty() func(*GetScriptContextRequest) { + return func(r *GetScriptContextRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f GetScriptContext) WithHuman() func(*GetScriptContextRequest) { + return func(r *GetScriptContextRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f GetScriptContext) WithErrorTrace() func(*GetScriptContextRequest) { + return func(r *GetScriptContextRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f GetScriptContext) WithFilterPath(v ...string) func(*GetScriptContextRequest) { + return func(r *GetScriptContextRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f GetScriptContext) WithHeader(h map[string]string) func(*GetScriptContextRequest) { + return func(r *GetScriptContextRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f GetScriptContext) WithOpaqueID(s string) func(*GetScriptContextRequest) { + return func(r *GetScriptContextRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.get_source.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.get_source.go new file mode 100644 index 00000000000..fb2ce2aad1f --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.get_source.go @@ -0,0 +1,310 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newGetSourceFunc(t Transport) GetSource { + return func(index string, id string, o ...func(*GetSourceRequest)) (*Response, error) { + var r = GetSourceRequest{Index: index, DocumentID: id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// GetSource returns the source of a document. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html. +// +type GetSource func(index string, id string, o ...func(*GetSourceRequest)) (*Response, error) + +// GetSourceRequest configures the Get Source API request. +// +type GetSourceRequest struct { + Index string + DocumentID string + + Preference string + Realtime *bool + Refresh *bool + Routing string + Source []string + SourceExcludes []string + SourceIncludes []string + Version *int + VersionType string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r GetSourceRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(r.Index) + 1 + len("_source") + 1 + len(r.DocumentID)) + path.WriteString("/") + path.WriteString(r.Index) + path.WriteString("/") + path.WriteString("_source") + path.WriteString("/") + path.WriteString(r.DocumentID) + + params = make(map[string]string) + + if r.Preference != "" { + params["preference"] = r.Preference + } + + if r.Realtime != nil { + params["realtime"] = strconv.FormatBool(*r.Realtime) + } + + if r.Refresh != nil { + params["refresh"] = strconv.FormatBool(*r.Refresh) + } + + if r.Routing != "" { + params["routing"] = r.Routing + } + + if len(r.Source) > 0 { + params["_source"] = strings.Join(r.Source, ",") + } + + if len(r.SourceExcludes) > 0 { + params["_source_excludes"] = strings.Join(r.SourceExcludes, ",") + } + + if len(r.SourceIncludes) > 0 { + params["_source_includes"] = strings.Join(r.SourceIncludes, ",") + } + + if r.Version != nil { + params["version"] = strconv.FormatInt(int64(*r.Version), 10) + } + + if r.VersionType != "" { + params["version_type"] = r.VersionType + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f GetSource) WithContext(v context.Context) func(*GetSourceRequest) { + return func(r *GetSourceRequest) { + r.ctx = v + } +} + +// WithPreference - specify the node or shard the operation should be performed on (default: random). +// +func (f GetSource) WithPreference(v string) func(*GetSourceRequest) { + return func(r *GetSourceRequest) { + r.Preference = v + } +} + +// WithRealtime - specify whether to perform the operation in realtime or search mode. +// +func (f GetSource) WithRealtime(v bool) func(*GetSourceRequest) { + return func(r *GetSourceRequest) { + r.Realtime = &v + } +} + +// WithRefresh - refresh the shard containing the document before performing the operation. +// +func (f GetSource) WithRefresh(v bool) func(*GetSourceRequest) { + return func(r *GetSourceRequest) { + r.Refresh = &v + } +} + +// WithRouting - specific routing value. +// +func (f GetSource) WithRouting(v string) func(*GetSourceRequest) { + return func(r *GetSourceRequest) { + r.Routing = v + } +} + +// WithSource - true or false to return the _source field or not, or a list of fields to return. +// +func (f GetSource) WithSource(v ...string) func(*GetSourceRequest) { + return func(r *GetSourceRequest) { + r.Source = v + } +} + +// WithSourceExcludes - a list of fields to exclude from the returned _source field. +// +func (f GetSource) WithSourceExcludes(v ...string) func(*GetSourceRequest) { + return func(r *GetSourceRequest) { + r.SourceExcludes = v + } +} + +// WithSourceIncludes - a list of fields to extract and return from the _source field. +// +func (f GetSource) WithSourceIncludes(v ...string) func(*GetSourceRequest) { + return func(r *GetSourceRequest) { + r.SourceIncludes = v + } +} + +// WithVersion - explicit version number for concurrency control. +// +func (f GetSource) WithVersion(v int) func(*GetSourceRequest) { + return func(r *GetSourceRequest) { + r.Version = &v + } +} + +// WithVersionType - specific version type. +// +func (f GetSource) WithVersionType(v string) func(*GetSourceRequest) { + return func(r *GetSourceRequest) { + r.VersionType = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f GetSource) WithPretty() func(*GetSourceRequest) { + return func(r *GetSourceRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f GetSource) WithHuman() func(*GetSourceRequest) { + return func(r *GetSourceRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f GetSource) WithErrorTrace() func(*GetSourceRequest) { + return func(r *GetSourceRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f GetSource) WithFilterPath(v ...string) func(*GetSourceRequest) { + return func(r *GetSourceRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f GetSource) WithHeader(h map[string]string) func(*GetSourceRequest) { + return func(r *GetSourceRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f GetSource) WithOpaqueID(s string) func(*GetSourceRequest) { + return func(r *GetSourceRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.index.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.index.go new file mode 100644 index 00000000000..42a349084f5 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.index.go @@ -0,0 +1,345 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" + "time" +) + +func newIndexFunc(t Transport) Index { + return func(index string, body io.Reader, o ...func(*IndexRequest)) (*Response, error) { + var r = IndexRequest{Index: index, Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// Index creates or updates a document in an index. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html. +// +type Index func(index string, body io.Reader, o ...func(*IndexRequest)) (*Response, error) + +// IndexRequest configures the Index API request. +// +type IndexRequest struct { + Index string + DocumentID string + + Body io.Reader + + IfPrimaryTerm *int + IfSeqNo *int + OpType string + Pipeline string + Refresh string + Routing string + Timeout time.Duration + Version *int + VersionType string + WaitForActiveShards string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndexRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + if r.DocumentID != "" { + method = "PUT" + } else { + method = "POST" + } + + path.Grow(1 + len(r.Index) + 1 + len("_doc") + 1 + len(r.DocumentID)) + path.WriteString("/") + path.WriteString(r.Index) + path.WriteString("/") + path.WriteString("_doc") + if r.DocumentID != "" { + path.WriteString("/") + path.WriteString(r.DocumentID) + } + + params = make(map[string]string) + + if r.IfPrimaryTerm != nil { + params["if_primary_term"] = strconv.FormatInt(int64(*r.IfPrimaryTerm), 10) + } + + if r.IfSeqNo != nil { + params["if_seq_no"] = strconv.FormatInt(int64(*r.IfSeqNo), 10) + } + + if r.OpType != "" { + params["op_type"] = r.OpType + } + + if r.Pipeline != "" { + params["pipeline"] = r.Pipeline + } + + if r.Refresh != "" { + params["refresh"] = r.Refresh + } + + if r.Routing != "" { + params["routing"] = r.Routing + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Version != nil { + params["version"] = strconv.FormatInt(int64(*r.Version), 10) + } + + if r.VersionType != "" { + params["version_type"] = r.VersionType + } + + if r.WaitForActiveShards != "" { + params["wait_for_active_shards"] = r.WaitForActiveShards + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f Index) WithContext(v context.Context) func(*IndexRequest) { + return func(r *IndexRequest) { + r.ctx = v + } +} + +// WithDocumentID - document ID. +// +func (f Index) WithDocumentID(v string) func(*IndexRequest) { + return func(r *IndexRequest) { + r.DocumentID = v + } +} + +// WithIfPrimaryTerm - only perform the index operation if the last operation that has changed the document has the specified primary term. +// +func (f Index) WithIfPrimaryTerm(v int) func(*IndexRequest) { + return func(r *IndexRequest) { + r.IfPrimaryTerm = &v + } +} + +// WithIfSeqNo - only perform the index operation if the last operation that has changed the document has the specified sequence number. +// +func (f Index) WithIfSeqNo(v int) func(*IndexRequest) { + return func(r *IndexRequest) { + r.IfSeqNo = &v + } +} + +// WithOpType - explicit operation type. defaults to `index` for requests with an explicit document ID, and to `create`for requests without an explicit document ID. +// +func (f Index) WithOpType(v string) func(*IndexRequest) { + return func(r *IndexRequest) { + r.OpType = v + } +} + +// WithPipeline - the pipeline ID to preprocess incoming documents with. +// +func (f Index) WithPipeline(v string) func(*IndexRequest) { + return func(r *IndexRequest) { + r.Pipeline = v + } +} + +// WithRefresh - if `true` then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` (the default) then do nothing with refreshes.. +// +func (f Index) WithRefresh(v string) func(*IndexRequest) { + return func(r *IndexRequest) { + r.Refresh = v + } +} + +// WithRouting - specific routing value. +// +func (f Index) WithRouting(v string) func(*IndexRequest) { + return func(r *IndexRequest) { + r.Routing = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f Index) WithTimeout(v time.Duration) func(*IndexRequest) { + return func(r *IndexRequest) { + r.Timeout = v + } +} + +// WithVersion - explicit version number for concurrency control. +// +func (f Index) WithVersion(v int) func(*IndexRequest) { + return func(r *IndexRequest) { + r.Version = &v + } +} + +// WithVersionType - specific version type. +// +func (f Index) WithVersionType(v string) func(*IndexRequest) { + return func(r *IndexRequest) { + r.VersionType = v + } +} + +// WithWaitForActiveShards - sets the number of shard copies that must be active before proceeding with the index operation. defaults to 1, meaning the primary shard only. set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1). +// +func (f Index) WithWaitForActiveShards(v string) func(*IndexRequest) { + return func(r *IndexRequest) { + r.WaitForActiveShards = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f Index) WithPretty() func(*IndexRequest) { + return func(r *IndexRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f Index) WithHuman() func(*IndexRequest) { + return func(r *IndexRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f Index) WithErrorTrace() func(*IndexRequest) { + return func(r *IndexRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f Index) WithFilterPath(v ...string) func(*IndexRequest) { + return func(r *IndexRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f Index) WithHeader(h map[string]string) func(*IndexRequest) { + return func(r *IndexRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f Index) WithOpaqueID(s string) func(*IndexRequest) { + return func(r *IndexRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.analyze.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.analyze.go new file mode 100644 index 00000000000..3dea9ef73bc --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.analyze.go @@ -0,0 +1,217 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newIndicesAnalyzeFunc(t Transport) IndicesAnalyze { + return func(o ...func(*IndicesAnalyzeRequest)) (*Response, error) { + var r = IndicesAnalyzeRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesAnalyze performs the analysis process on a text and return the tokens breakdown of the text. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-analyze.html. +// +type IndicesAnalyze func(o ...func(*IndicesAnalyzeRequest)) (*Response, error) + +// IndicesAnalyzeRequest configures the Indices Analyze API request. +// +type IndicesAnalyzeRequest struct { + Index string + + Body io.Reader + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesAnalyzeRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(r.Index) + 1 + len("_analyze")) + if r.Index != "" { + path.WriteString("/") + path.WriteString(r.Index) + } + path.WriteString("/") + path.WriteString("_analyze") + + params = make(map[string]string) + + if r.Index != "" { + params["index"] = r.Index + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesAnalyze) WithContext(v context.Context) func(*IndicesAnalyzeRequest) { + return func(r *IndicesAnalyzeRequest) { + r.ctx = v + } +} + +// WithBody - Define analyzer/tokenizer parameters and the text on which the analysis should be performed. +// +func (f IndicesAnalyze) WithBody(v io.Reader) func(*IndicesAnalyzeRequest) { + return func(r *IndicesAnalyzeRequest) { + r.Body = v + } +} + +// WithIndex - the name of the index to scope the operation. +// +func (f IndicesAnalyze) WithIndex(v string) func(*IndicesAnalyzeRequest) { + return func(r *IndicesAnalyzeRequest) { + r.Index = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesAnalyze) WithPretty() func(*IndicesAnalyzeRequest) { + return func(r *IndicesAnalyzeRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesAnalyze) WithHuman() func(*IndicesAnalyzeRequest) { + return func(r *IndicesAnalyzeRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesAnalyze) WithErrorTrace() func(*IndicesAnalyzeRequest) { + return func(r *IndicesAnalyzeRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesAnalyze) WithFilterPath(v ...string) func(*IndicesAnalyzeRequest) { + return func(r *IndicesAnalyzeRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesAnalyze) WithHeader(h map[string]string) func(*IndicesAnalyzeRequest) { + return func(r *IndicesAnalyzeRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesAnalyze) WithOpaqueID(s string) func(*IndicesAnalyzeRequest) { + return func(r *IndicesAnalyzeRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.clear_cache.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.clear_cache.go new file mode 100644 index 00000000000..5607f18df3b --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.clear_cache.go @@ -0,0 +1,297 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newIndicesClearCacheFunc(t Transport) IndicesClearCache { + return func(o ...func(*IndicesClearCacheRequest)) (*Response, error) { + var r = IndicesClearCacheRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesClearCache clears all or specific caches for one or more indices. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clearcache.html. +// +type IndicesClearCache func(o ...func(*IndicesClearCacheRequest)) (*Response, error) + +// IndicesClearCacheRequest configures the Indices Clear Cache API request. +// +type IndicesClearCacheRequest struct { + Index []string + + AllowNoIndices *bool + ExpandWildcards string + Fielddata *bool + Fields []string + IgnoreUnavailable *bool + Query *bool + Request *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesClearCacheRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_cache") + 1 + len("clear")) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_cache") + path.WriteString("/") + path.WriteString("clear") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.Fielddata != nil { + params["fielddata"] = strconv.FormatBool(*r.Fielddata) + } + + if len(r.Fields) > 0 { + params["fields"] = strings.Join(r.Fields, ",") + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if len(r.Index) > 0 { + params["index"] = strings.Join(r.Index, ",") + } + + if r.Query != nil { + params["query"] = strconv.FormatBool(*r.Query) + } + + if r.Request != nil { + params["request"] = strconv.FormatBool(*r.Request) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesClearCache) WithContext(v context.Context) func(*IndicesClearCacheRequest) { + return func(r *IndicesClearCacheRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index name to limit the operation. +// +func (f IndicesClearCache) WithIndex(v ...string) func(*IndicesClearCacheRequest) { + return func(r *IndicesClearCacheRequest) { + r.Index = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f IndicesClearCache) WithAllowNoIndices(v bool) func(*IndicesClearCacheRequest) { + return func(r *IndicesClearCacheRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f IndicesClearCache) WithExpandWildcards(v string) func(*IndicesClearCacheRequest) { + return func(r *IndicesClearCacheRequest) { + r.ExpandWildcards = v + } +} + +// WithFielddata - clear field data. +// +func (f IndicesClearCache) WithFielddata(v bool) func(*IndicesClearCacheRequest) { + return func(r *IndicesClearCacheRequest) { + r.Fielddata = &v + } +} + +// WithFields - a list of fields to clear when using the `fielddata` parameter (default: all). +// +func (f IndicesClearCache) WithFields(v ...string) func(*IndicesClearCacheRequest) { + return func(r *IndicesClearCacheRequest) { + r.Fields = v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f IndicesClearCache) WithIgnoreUnavailable(v bool) func(*IndicesClearCacheRequest) { + return func(r *IndicesClearCacheRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithQuery - clear query caches. +// +func (f IndicesClearCache) WithQuery(v bool) func(*IndicesClearCacheRequest) { + return func(r *IndicesClearCacheRequest) { + r.Query = &v + } +} + +// WithRequest - clear request cache. +// +func (f IndicesClearCache) WithRequest(v bool) func(*IndicesClearCacheRequest) { + return func(r *IndicesClearCacheRequest) { + r.Request = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesClearCache) WithPretty() func(*IndicesClearCacheRequest) { + return func(r *IndicesClearCacheRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesClearCache) WithHuman() func(*IndicesClearCacheRequest) { + return func(r *IndicesClearCacheRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesClearCache) WithErrorTrace() func(*IndicesClearCacheRequest) { + return func(r *IndicesClearCacheRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesClearCache) WithFilterPath(v ...string) func(*IndicesClearCacheRequest) { + return func(r *IndicesClearCacheRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesClearCache) WithHeader(h map[string]string) func(*IndicesClearCacheRequest) { + return func(r *IndicesClearCacheRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesClearCache) WithOpaqueID(s string) func(*IndicesClearCacheRequest) { + return func(r *IndicesClearCacheRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.clone.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.clone.go new file mode 100644 index 00000000000..deed9ace4f9 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.clone.go @@ -0,0 +1,248 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" + "time" +) + +func newIndicesCloneFunc(t Transport) IndicesClone { + return func(index string, target string, o ...func(*IndicesCloneRequest)) (*Response, error) { + var r = IndicesCloneRequest{Index: index, Target: target} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesClone clones an index +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clone-index.html. +// +type IndicesClone func(index string, target string, o ...func(*IndicesCloneRequest)) (*Response, error) + +// IndicesCloneRequest configures the Indices Clone API request. +// +type IndicesCloneRequest struct { + Index string + + Body io.Reader + + Target string + + MasterTimeout time.Duration + Timeout time.Duration + WaitForActiveShards string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesCloneRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len(r.Index) + 1 + len("_clone") + 1 + len(r.Target)) + path.WriteString("/") + path.WriteString(r.Index) + path.WriteString("/") + path.WriteString("_clone") + path.WriteString("/") + path.WriteString(r.Target) + + params = make(map[string]string) + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.WaitForActiveShards != "" { + params["wait_for_active_shards"] = r.WaitForActiveShards + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesClone) WithContext(v context.Context) func(*IndicesCloneRequest) { + return func(r *IndicesCloneRequest) { + r.ctx = v + } +} + +// WithBody - The configuration for the target index (`settings` and `aliases`). +// +func (f IndicesClone) WithBody(v io.Reader) func(*IndicesCloneRequest) { + return func(r *IndicesCloneRequest) { + r.Body = v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f IndicesClone) WithMasterTimeout(v time.Duration) func(*IndicesCloneRequest) { + return func(r *IndicesCloneRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f IndicesClone) WithTimeout(v time.Duration) func(*IndicesCloneRequest) { + return func(r *IndicesCloneRequest) { + r.Timeout = v + } +} + +// WithWaitForActiveShards - set the number of active shards to wait for on the cloned index before the operation returns.. +// +func (f IndicesClone) WithWaitForActiveShards(v string) func(*IndicesCloneRequest) { + return func(r *IndicesCloneRequest) { + r.WaitForActiveShards = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesClone) WithPretty() func(*IndicesCloneRequest) { + return func(r *IndicesCloneRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesClone) WithHuman() func(*IndicesCloneRequest) { + return func(r *IndicesCloneRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesClone) WithErrorTrace() func(*IndicesCloneRequest) { + return func(r *IndicesCloneRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesClone) WithFilterPath(v ...string) func(*IndicesCloneRequest) { + return func(r *IndicesCloneRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesClone) WithHeader(h map[string]string) func(*IndicesCloneRequest) { + return func(r *IndicesCloneRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesClone) WithOpaqueID(s string) func(*IndicesCloneRequest) { + return func(r *IndicesCloneRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.close.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.close.go new file mode 100644 index 00000000000..5ed67a53c04 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.close.go @@ -0,0 +1,269 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newIndicesCloseFunc(t Transport) IndicesClose { + return func(index []string, o ...func(*IndicesCloseRequest)) (*Response, error) { + var r = IndicesCloseRequest{Index: index} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesClose closes an index. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html. +// +type IndicesClose func(index []string, o ...func(*IndicesCloseRequest)) (*Response, error) + +// IndicesCloseRequest configures the Indices Close API request. +// +type IndicesCloseRequest struct { + Index []string + + AllowNoIndices *bool + ExpandWildcards string + IgnoreUnavailable *bool + MasterTimeout time.Duration + Timeout time.Duration + WaitForActiveShards string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesCloseRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_close")) + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + path.WriteString("/") + path.WriteString("_close") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.WaitForActiveShards != "" { + params["wait_for_active_shards"] = r.WaitForActiveShards + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesClose) WithContext(v context.Context) func(*IndicesCloseRequest) { + return func(r *IndicesCloseRequest) { + r.ctx = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f IndicesClose) WithAllowNoIndices(v bool) func(*IndicesCloseRequest) { + return func(r *IndicesCloseRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f IndicesClose) WithExpandWildcards(v string) func(*IndicesCloseRequest) { + return func(r *IndicesCloseRequest) { + r.ExpandWildcards = v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f IndicesClose) WithIgnoreUnavailable(v bool) func(*IndicesCloseRequest) { + return func(r *IndicesCloseRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f IndicesClose) WithMasterTimeout(v time.Duration) func(*IndicesCloseRequest) { + return func(r *IndicesCloseRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f IndicesClose) WithTimeout(v time.Duration) func(*IndicesCloseRequest) { + return func(r *IndicesCloseRequest) { + r.Timeout = v + } +} + +// WithWaitForActiveShards - sets the number of active shards to wait for before the operation returns.. +// +func (f IndicesClose) WithWaitForActiveShards(v string) func(*IndicesCloseRequest) { + return func(r *IndicesCloseRequest) { + r.WaitForActiveShards = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesClose) WithPretty() func(*IndicesCloseRequest) { + return func(r *IndicesCloseRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesClose) WithHuman() func(*IndicesCloseRequest) { + return func(r *IndicesCloseRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesClose) WithErrorTrace() func(*IndicesCloseRequest) { + return func(r *IndicesCloseRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesClose) WithFilterPath(v ...string) func(*IndicesCloseRequest) { + return func(r *IndicesCloseRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesClose) WithHeader(h map[string]string) func(*IndicesCloseRequest) { + return func(r *IndicesCloseRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesClose) WithOpaqueID(s string) func(*IndicesCloseRequest) { + return func(r *IndicesCloseRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.create.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.create.go new file mode 100644 index 00000000000..4d2c7ed30ea --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.create.go @@ -0,0 +1,256 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" + "time" +) + +func newIndicesCreateFunc(t Transport) IndicesCreate { + return func(index string, o ...func(*IndicesCreateRequest)) (*Response, error) { + var r = IndicesCreateRequest{Index: index} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesCreate creates an index with optional settings and mappings. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-create-index.html. +// +type IndicesCreate func(index string, o ...func(*IndicesCreateRequest)) (*Response, error) + +// IndicesCreateRequest configures the Indices Create API request. +// +type IndicesCreateRequest struct { + Index string + + Body io.Reader + + IncludeTypeName *bool + MasterTimeout time.Duration + Timeout time.Duration + WaitForActiveShards string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesCreateRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len(r.Index)) + path.WriteString("/") + path.WriteString(r.Index) + + params = make(map[string]string) + + if r.IncludeTypeName != nil { + params["include_type_name"] = strconv.FormatBool(*r.IncludeTypeName) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.WaitForActiveShards != "" { + params["wait_for_active_shards"] = r.WaitForActiveShards + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesCreate) WithContext(v context.Context) func(*IndicesCreateRequest) { + return func(r *IndicesCreateRequest) { + r.ctx = v + } +} + +// WithBody - The configuration for the index (`settings` and `mappings`). +// +func (f IndicesCreate) WithBody(v io.Reader) func(*IndicesCreateRequest) { + return func(r *IndicesCreateRequest) { + r.Body = v + } +} + +// WithIncludeTypeName - whether a type should be expected in the body of the mappings.. +// +func (f IndicesCreate) WithIncludeTypeName(v bool) func(*IndicesCreateRequest) { + return func(r *IndicesCreateRequest) { + r.IncludeTypeName = &v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f IndicesCreate) WithMasterTimeout(v time.Duration) func(*IndicesCreateRequest) { + return func(r *IndicesCreateRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f IndicesCreate) WithTimeout(v time.Duration) func(*IndicesCreateRequest) { + return func(r *IndicesCreateRequest) { + r.Timeout = v + } +} + +// WithWaitForActiveShards - set the number of active shards to wait for before the operation returns.. +// +func (f IndicesCreate) WithWaitForActiveShards(v string) func(*IndicesCreateRequest) { + return func(r *IndicesCreateRequest) { + r.WaitForActiveShards = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesCreate) WithPretty() func(*IndicesCreateRequest) { + return func(r *IndicesCreateRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesCreate) WithHuman() func(*IndicesCreateRequest) { + return func(r *IndicesCreateRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesCreate) WithErrorTrace() func(*IndicesCreateRequest) { + return func(r *IndicesCreateRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesCreate) WithFilterPath(v ...string) func(*IndicesCreateRequest) { + return func(r *IndicesCreateRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesCreate) WithHeader(h map[string]string) func(*IndicesCreateRequest) { + return func(r *IndicesCreateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesCreate) WithOpaqueID(s string) func(*IndicesCreateRequest) { + return func(r *IndicesCreateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.delete.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.delete.go new file mode 100644 index 00000000000..0e401123674 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.delete.go @@ -0,0 +1,254 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newIndicesDeleteFunc(t Transport) IndicesDelete { + return func(index []string, o ...func(*IndicesDeleteRequest)) (*Response, error) { + var r = IndicesDeleteRequest{Index: index} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesDelete deletes an index. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-delete-index.html. +// +type IndicesDelete func(index []string, o ...func(*IndicesDeleteRequest)) (*Response, error) + +// IndicesDeleteRequest configures the Indices Delete API request. +// +type IndicesDeleteRequest struct { + Index []string + + AllowNoIndices *bool + ExpandWildcards string + IgnoreUnavailable *bool + MasterTimeout time.Duration + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesDeleteRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len(strings.Join(r.Index, ","))) + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesDelete) WithContext(v context.Context) func(*IndicesDeleteRequest) { + return func(r *IndicesDeleteRequest) { + r.ctx = v + } +} + +// WithAllowNoIndices - ignore if a wildcard expression resolves to no concrete indices (default: false). +// +func (f IndicesDelete) WithAllowNoIndices(v bool) func(*IndicesDeleteRequest) { + return func(r *IndicesDeleteRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether wildcard expressions should get expanded to open or closed indices (default: open). +// +func (f IndicesDelete) WithExpandWildcards(v string) func(*IndicesDeleteRequest) { + return func(r *IndicesDeleteRequest) { + r.ExpandWildcards = v + } +} + +// WithIgnoreUnavailable - ignore unavailable indexes (default: false). +// +func (f IndicesDelete) WithIgnoreUnavailable(v bool) func(*IndicesDeleteRequest) { + return func(r *IndicesDeleteRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f IndicesDelete) WithMasterTimeout(v time.Duration) func(*IndicesDeleteRequest) { + return func(r *IndicesDeleteRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f IndicesDelete) WithTimeout(v time.Duration) func(*IndicesDeleteRequest) { + return func(r *IndicesDeleteRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesDelete) WithPretty() func(*IndicesDeleteRequest) { + return func(r *IndicesDeleteRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesDelete) WithHuman() func(*IndicesDeleteRequest) { + return func(r *IndicesDeleteRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesDelete) WithErrorTrace() func(*IndicesDeleteRequest) { + return func(r *IndicesDeleteRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesDelete) WithFilterPath(v ...string) func(*IndicesDeleteRequest) { + return func(r *IndicesDeleteRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesDelete) WithHeader(h map[string]string) func(*IndicesDeleteRequest) { + return func(r *IndicesDeleteRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesDelete) WithOpaqueID(s string) func(*IndicesDeleteRequest) { + return func(r *IndicesDeleteRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.delete_alias.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.delete_alias.go new file mode 100644 index 00000000000..56ab9f61521 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.delete_alias.go @@ -0,0 +1,220 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" + "time" +) + +func newIndicesDeleteAliasFunc(t Transport) IndicesDeleteAlias { + return func(index []string, name []string, o ...func(*IndicesDeleteAliasRequest)) (*Response, error) { + var r = IndicesDeleteAliasRequest{Index: index, Name: name} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesDeleteAlias deletes an alias. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html. +// +type IndicesDeleteAlias func(index []string, name []string, o ...func(*IndicesDeleteAliasRequest)) (*Response, error) + +// IndicesDeleteAliasRequest configures the Indices Delete Alias API request. +// +type IndicesDeleteAliasRequest struct { + Index []string + + Name []string + + MasterTimeout time.Duration + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesDeleteAliasRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_aliases") + 1 + len(strings.Join(r.Name, ","))) + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + path.WriteString("/") + path.WriteString("_aliases") + path.WriteString("/") + path.WriteString(strings.Join(r.Name, ",")) + + params = make(map[string]string) + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesDeleteAlias) WithContext(v context.Context) func(*IndicesDeleteAliasRequest) { + return func(r *IndicesDeleteAliasRequest) { + r.ctx = v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f IndicesDeleteAlias) WithMasterTimeout(v time.Duration) func(*IndicesDeleteAliasRequest) { + return func(r *IndicesDeleteAliasRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit timestamp for the document. +// +func (f IndicesDeleteAlias) WithTimeout(v time.Duration) func(*IndicesDeleteAliasRequest) { + return func(r *IndicesDeleteAliasRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesDeleteAlias) WithPretty() func(*IndicesDeleteAliasRequest) { + return func(r *IndicesDeleteAliasRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesDeleteAlias) WithHuman() func(*IndicesDeleteAliasRequest) { + return func(r *IndicesDeleteAliasRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesDeleteAlias) WithErrorTrace() func(*IndicesDeleteAliasRequest) { + return func(r *IndicesDeleteAliasRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesDeleteAlias) WithFilterPath(v ...string) func(*IndicesDeleteAliasRequest) { + return func(r *IndicesDeleteAliasRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesDeleteAlias) WithHeader(h map[string]string) func(*IndicesDeleteAliasRequest) { + return func(r *IndicesDeleteAliasRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesDeleteAlias) WithOpaqueID(s string) func(*IndicesDeleteAliasRequest) { + return func(r *IndicesDeleteAliasRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.delete_template.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.delete_template.go new file mode 100644 index 00000000000..7d2f5ea5a74 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.delete_template.go @@ -0,0 +1,216 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" + "time" +) + +func newIndicesDeleteTemplateFunc(t Transport) IndicesDeleteTemplate { + return func(name string, o ...func(*IndicesDeleteTemplateRequest)) (*Response, error) { + var r = IndicesDeleteTemplateRequest{Name: name} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesDeleteTemplate deletes an index template. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html. +// +type IndicesDeleteTemplate func(name string, o ...func(*IndicesDeleteTemplateRequest)) (*Response, error) + +// IndicesDeleteTemplateRequest configures the Indices Delete Template API request. +// +type IndicesDeleteTemplateRequest struct { + Name string + + MasterTimeout time.Duration + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesDeleteTemplateRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_template") + 1 + len(r.Name)) + path.WriteString("/") + path.WriteString("_template") + path.WriteString("/") + path.WriteString(r.Name) + + params = make(map[string]string) + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesDeleteTemplate) WithContext(v context.Context) func(*IndicesDeleteTemplateRequest) { + return func(r *IndicesDeleteTemplateRequest) { + r.ctx = v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f IndicesDeleteTemplate) WithMasterTimeout(v time.Duration) func(*IndicesDeleteTemplateRequest) { + return func(r *IndicesDeleteTemplateRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f IndicesDeleteTemplate) WithTimeout(v time.Duration) func(*IndicesDeleteTemplateRequest) { + return func(r *IndicesDeleteTemplateRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesDeleteTemplate) WithPretty() func(*IndicesDeleteTemplateRequest) { + return func(r *IndicesDeleteTemplateRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesDeleteTemplate) WithHuman() func(*IndicesDeleteTemplateRequest) { + return func(r *IndicesDeleteTemplateRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesDeleteTemplate) WithErrorTrace() func(*IndicesDeleteTemplateRequest) { + return func(r *IndicesDeleteTemplateRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesDeleteTemplate) WithFilterPath(v ...string) func(*IndicesDeleteTemplateRequest) { + return func(r *IndicesDeleteTemplateRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesDeleteTemplate) WithHeader(h map[string]string) func(*IndicesDeleteTemplateRequest) { + return func(r *IndicesDeleteTemplateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesDeleteTemplate) WithOpaqueID(s string) func(*IndicesDeleteTemplateRequest) { + return func(r *IndicesDeleteTemplateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.exists.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.exists.go new file mode 100644 index 00000000000..1e328d7897d --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.exists.go @@ -0,0 +1,266 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newIndicesExistsFunc(t Transport) IndicesExists { + return func(index []string, o ...func(*IndicesExistsRequest)) (*Response, error) { + var r = IndicesExistsRequest{Index: index} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesExists returns information about whether a particular index exists. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-exists.html. +// +type IndicesExists func(index []string, o ...func(*IndicesExistsRequest)) (*Response, error) + +// IndicesExistsRequest configures the Indices Exists API request. +// +type IndicesExistsRequest struct { + Index []string + + AllowNoIndices *bool + ExpandWildcards string + FlatSettings *bool + IgnoreUnavailable *bool + IncludeDefaults *bool + Local *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesExistsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "HEAD" + + path.Grow(1 + len(strings.Join(r.Index, ","))) + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.FlatSettings != nil { + params["flat_settings"] = strconv.FormatBool(*r.FlatSettings) + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.IncludeDefaults != nil { + params["include_defaults"] = strconv.FormatBool(*r.IncludeDefaults) + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesExists) WithContext(v context.Context) func(*IndicesExistsRequest) { + return func(r *IndicesExistsRequest) { + r.ctx = v + } +} + +// WithAllowNoIndices - ignore if a wildcard expression resolves to no concrete indices (default: false). +// +func (f IndicesExists) WithAllowNoIndices(v bool) func(*IndicesExistsRequest) { + return func(r *IndicesExistsRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether wildcard expressions should get expanded to open or closed indices (default: open). +// +func (f IndicesExists) WithExpandWildcards(v string) func(*IndicesExistsRequest) { + return func(r *IndicesExistsRequest) { + r.ExpandWildcards = v + } +} + +// WithFlatSettings - return settings in flat format (default: false). +// +func (f IndicesExists) WithFlatSettings(v bool) func(*IndicesExistsRequest) { + return func(r *IndicesExistsRequest) { + r.FlatSettings = &v + } +} + +// WithIgnoreUnavailable - ignore unavailable indexes (default: false). +// +func (f IndicesExists) WithIgnoreUnavailable(v bool) func(*IndicesExistsRequest) { + return func(r *IndicesExistsRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithIncludeDefaults - whether to return all default setting for each of the indices.. +// +func (f IndicesExists) WithIncludeDefaults(v bool) func(*IndicesExistsRequest) { + return func(r *IndicesExistsRequest) { + r.IncludeDefaults = &v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f IndicesExists) WithLocal(v bool) func(*IndicesExistsRequest) { + return func(r *IndicesExistsRequest) { + r.Local = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesExists) WithPretty() func(*IndicesExistsRequest) { + return func(r *IndicesExistsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesExists) WithHuman() func(*IndicesExistsRequest) { + return func(r *IndicesExistsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesExists) WithErrorTrace() func(*IndicesExistsRequest) { + return func(r *IndicesExistsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesExists) WithFilterPath(v ...string) func(*IndicesExistsRequest) { + return func(r *IndicesExistsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesExists) WithHeader(h map[string]string) func(*IndicesExistsRequest) { + return func(r *IndicesExistsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesExists) WithOpaqueID(s string) func(*IndicesExistsRequest) { + return func(r *IndicesExistsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.exists_alias.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.exists_alias.go new file mode 100644 index 00000000000..485339ab813 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.exists_alias.go @@ -0,0 +1,256 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newIndicesExistsAliasFunc(t Transport) IndicesExistsAlias { + return func(name []string, o ...func(*IndicesExistsAliasRequest)) (*Response, error) { + var r = IndicesExistsAliasRequest{Name: name} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesExistsAlias returns information about whether a particular alias exists. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html. +// +type IndicesExistsAlias func(name []string, o ...func(*IndicesExistsAliasRequest)) (*Response, error) + +// IndicesExistsAliasRequest configures the Indices Exists Alias API request. +// +type IndicesExistsAliasRequest struct { + Index []string + + Name []string + + AllowNoIndices *bool + ExpandWildcards string + IgnoreUnavailable *bool + Local *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesExistsAliasRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "HEAD" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_alias") + 1 + len(strings.Join(r.Name, ","))) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_alias") + path.WriteString("/") + path.WriteString(strings.Join(r.Name, ",")) + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesExistsAlias) WithContext(v context.Context) func(*IndicesExistsAliasRequest) { + return func(r *IndicesExistsAliasRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names to filter aliases. +// +func (f IndicesExistsAlias) WithIndex(v ...string) func(*IndicesExistsAliasRequest) { + return func(r *IndicesExistsAliasRequest) { + r.Index = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f IndicesExistsAlias) WithAllowNoIndices(v bool) func(*IndicesExistsAliasRequest) { + return func(r *IndicesExistsAliasRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f IndicesExistsAlias) WithExpandWildcards(v string) func(*IndicesExistsAliasRequest) { + return func(r *IndicesExistsAliasRequest) { + r.ExpandWildcards = v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f IndicesExistsAlias) WithIgnoreUnavailable(v bool) func(*IndicesExistsAliasRequest) { + return func(r *IndicesExistsAliasRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f IndicesExistsAlias) WithLocal(v bool) func(*IndicesExistsAliasRequest) { + return func(r *IndicesExistsAliasRequest) { + r.Local = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesExistsAlias) WithPretty() func(*IndicesExistsAliasRequest) { + return func(r *IndicesExistsAliasRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesExistsAlias) WithHuman() func(*IndicesExistsAliasRequest) { + return func(r *IndicesExistsAliasRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesExistsAlias) WithErrorTrace() func(*IndicesExistsAliasRequest) { + return func(r *IndicesExistsAliasRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesExistsAlias) WithFilterPath(v ...string) func(*IndicesExistsAliasRequest) { + return func(r *IndicesExistsAliasRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesExistsAlias) WithHeader(h map[string]string) func(*IndicesExistsAliasRequest) { + return func(r *IndicesExistsAliasRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesExistsAlias) WithOpaqueID(s string) func(*IndicesExistsAliasRequest) { + return func(r *IndicesExistsAliasRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.exists_template.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.exists_template.go new file mode 100644 index 00000000000..946be6c6bf8 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.exists_template.go @@ -0,0 +1,230 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newIndicesExistsTemplateFunc(t Transport) IndicesExistsTemplate { + return func(name []string, o ...func(*IndicesExistsTemplateRequest)) (*Response, error) { + var r = IndicesExistsTemplateRequest{Name: name} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesExistsTemplate returns information about whether a particular index template exists. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html. +// +type IndicesExistsTemplate func(name []string, o ...func(*IndicesExistsTemplateRequest)) (*Response, error) + +// IndicesExistsTemplateRequest configures the Indices Exists Template API request. +// +type IndicesExistsTemplateRequest struct { + Name []string + + FlatSettings *bool + Local *bool + MasterTimeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesExistsTemplateRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "HEAD" + + path.Grow(1 + len("_template") + 1 + len(strings.Join(r.Name, ","))) + path.WriteString("/") + path.WriteString("_template") + path.WriteString("/") + path.WriteString(strings.Join(r.Name, ",")) + + params = make(map[string]string) + + if r.FlatSettings != nil { + params["flat_settings"] = strconv.FormatBool(*r.FlatSettings) + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesExistsTemplate) WithContext(v context.Context) func(*IndicesExistsTemplateRequest) { + return func(r *IndicesExistsTemplateRequest) { + r.ctx = v + } +} + +// WithFlatSettings - return settings in flat format (default: false). +// +func (f IndicesExistsTemplate) WithFlatSettings(v bool) func(*IndicesExistsTemplateRequest) { + return func(r *IndicesExistsTemplateRequest) { + r.FlatSettings = &v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f IndicesExistsTemplate) WithLocal(v bool) func(*IndicesExistsTemplateRequest) { + return func(r *IndicesExistsTemplateRequest) { + r.Local = &v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f IndicesExistsTemplate) WithMasterTimeout(v time.Duration) func(*IndicesExistsTemplateRequest) { + return func(r *IndicesExistsTemplateRequest) { + r.MasterTimeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesExistsTemplate) WithPretty() func(*IndicesExistsTemplateRequest) { + return func(r *IndicesExistsTemplateRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesExistsTemplate) WithHuman() func(*IndicesExistsTemplateRequest) { + return func(r *IndicesExistsTemplateRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesExistsTemplate) WithErrorTrace() func(*IndicesExistsTemplateRequest) { + return func(r *IndicesExistsTemplateRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesExistsTemplate) WithFilterPath(v ...string) func(*IndicesExistsTemplateRequest) { + return func(r *IndicesExistsTemplateRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesExistsTemplate) WithHeader(h map[string]string) func(*IndicesExistsTemplateRequest) { + return func(r *IndicesExistsTemplateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesExistsTemplate) WithOpaqueID(s string) func(*IndicesExistsTemplateRequest) { + return func(r *IndicesExistsTemplateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.exists_type.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.exists_type.go new file mode 100644 index 00000000000..cabd7e764de --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.exists_type.go @@ -0,0 +1,253 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newIndicesExistsDocumentTypeFunc(t Transport) IndicesExistsDocumentType { + return func(index []string, o ...func(*IndicesExistsDocumentTypeRequest)) (*Response, error) { + var r = IndicesExistsDocumentTypeRequest{Index: index} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesExistsDocumentType returns information about whether a particular document type exists. (DEPRECATED) +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-types-exists.html. +// +type IndicesExistsDocumentType func(index []string, o ...func(*IndicesExistsDocumentTypeRequest)) (*Response, error) + +// IndicesExistsDocumentTypeRequest configures the Indices Exists Document Type API request. +// +type IndicesExistsDocumentTypeRequest struct { + Index []string + DocumentType []string + + AllowNoIndices *bool + ExpandWildcards string + IgnoreUnavailable *bool + Local *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesExistsDocumentTypeRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "HEAD" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_mapping") + 1 + len(strings.Join(r.DocumentType, ","))) + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + path.WriteString("/") + path.WriteString("_mapping") + path.WriteString("/") + path.WriteString(strings.Join(r.DocumentType, ",")) + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesExistsDocumentType) WithContext(v context.Context) func(*IndicesExistsDocumentTypeRequest) { + return func(r *IndicesExistsDocumentTypeRequest) { + r.ctx = v + } +} + +// WithDocumentType - a list of document types to check. +// +func (f IndicesExistsDocumentType) WithDocumentType(v ...string) func(*IndicesExistsDocumentTypeRequest) { + return func(r *IndicesExistsDocumentTypeRequest) { + r.DocumentType = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f IndicesExistsDocumentType) WithAllowNoIndices(v bool) func(*IndicesExistsDocumentTypeRequest) { + return func(r *IndicesExistsDocumentTypeRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f IndicesExistsDocumentType) WithExpandWildcards(v string) func(*IndicesExistsDocumentTypeRequest) { + return func(r *IndicesExistsDocumentTypeRequest) { + r.ExpandWildcards = v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f IndicesExistsDocumentType) WithIgnoreUnavailable(v bool) func(*IndicesExistsDocumentTypeRequest) { + return func(r *IndicesExistsDocumentTypeRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f IndicesExistsDocumentType) WithLocal(v bool) func(*IndicesExistsDocumentTypeRequest) { + return func(r *IndicesExistsDocumentTypeRequest) { + r.Local = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesExistsDocumentType) WithPretty() func(*IndicesExistsDocumentTypeRequest) { + return func(r *IndicesExistsDocumentTypeRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesExistsDocumentType) WithHuman() func(*IndicesExistsDocumentTypeRequest) { + return func(r *IndicesExistsDocumentTypeRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesExistsDocumentType) WithErrorTrace() func(*IndicesExistsDocumentTypeRequest) { + return func(r *IndicesExistsDocumentTypeRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesExistsDocumentType) WithFilterPath(v ...string) func(*IndicesExistsDocumentTypeRequest) { + return func(r *IndicesExistsDocumentTypeRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesExistsDocumentType) WithHeader(h map[string]string) func(*IndicesExistsDocumentTypeRequest) { + return func(r *IndicesExistsDocumentTypeRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesExistsDocumentType) WithOpaqueID(s string) func(*IndicesExistsDocumentTypeRequest) { + return func(r *IndicesExistsDocumentTypeRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.flush.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.flush.go new file mode 100644 index 00000000000..38ff48c9244 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.flush.go @@ -0,0 +1,265 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newIndicesFlushFunc(t Transport) IndicesFlush { + return func(o ...func(*IndicesFlushRequest)) (*Response, error) { + var r = IndicesFlushRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesFlush performs the flush operation on one or more indices. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-flush.html. +// +type IndicesFlush func(o ...func(*IndicesFlushRequest)) (*Response, error) + +// IndicesFlushRequest configures the Indices Flush API request. +// +type IndicesFlushRequest struct { + Index []string + + AllowNoIndices *bool + ExpandWildcards string + Force *bool + IgnoreUnavailable *bool + WaitIfOngoing *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesFlushRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_flush")) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_flush") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.Force != nil { + params["force"] = strconv.FormatBool(*r.Force) + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.WaitIfOngoing != nil { + params["wait_if_ongoing"] = strconv.FormatBool(*r.WaitIfOngoing) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesFlush) WithContext(v context.Context) func(*IndicesFlushRequest) { + return func(r *IndicesFlushRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names; use _all for all indices. +// +func (f IndicesFlush) WithIndex(v ...string) func(*IndicesFlushRequest) { + return func(r *IndicesFlushRequest) { + r.Index = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f IndicesFlush) WithAllowNoIndices(v bool) func(*IndicesFlushRequest) { + return func(r *IndicesFlushRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f IndicesFlush) WithExpandWildcards(v string) func(*IndicesFlushRequest) { + return func(r *IndicesFlushRequest) { + r.ExpandWildcards = v + } +} + +// WithForce - whether a flush should be forced even if it is not necessarily needed ie. if no changes will be committed to the index. this is useful if transaction log ids should be incremented even if no uncommitted changes are present. (this setting can be considered as internal). +// +func (f IndicesFlush) WithForce(v bool) func(*IndicesFlushRequest) { + return func(r *IndicesFlushRequest) { + r.Force = &v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f IndicesFlush) WithIgnoreUnavailable(v bool) func(*IndicesFlushRequest) { + return func(r *IndicesFlushRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithWaitIfOngoing - if set to true the flush operation will block until the flush can be executed if another flush operation is already executing. the default is true. if set to false the flush will be skipped iff if another flush operation is already running.. +// +func (f IndicesFlush) WithWaitIfOngoing(v bool) func(*IndicesFlushRequest) { + return func(r *IndicesFlushRequest) { + r.WaitIfOngoing = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesFlush) WithPretty() func(*IndicesFlushRequest) { + return func(r *IndicesFlushRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesFlush) WithHuman() func(*IndicesFlushRequest) { + return func(r *IndicesFlushRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesFlush) WithErrorTrace() func(*IndicesFlushRequest) { + return func(r *IndicesFlushRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesFlush) WithFilterPath(v ...string) func(*IndicesFlushRequest) { + return func(r *IndicesFlushRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesFlush) WithHeader(h map[string]string) func(*IndicesFlushRequest) { + return func(r *IndicesFlushRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesFlush) WithOpaqueID(s string) func(*IndicesFlushRequest) { + return func(r *IndicesFlushRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.flush_synced.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.flush_synced.go new file mode 100644 index 00000000000..801a6b6c5ba --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.flush_synced.go @@ -0,0 +1,241 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newIndicesFlushSyncedFunc(t Transport) IndicesFlushSynced { + return func(o ...func(*IndicesFlushSyncedRequest)) (*Response, error) { + var r = IndicesFlushSyncedRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesFlushSynced performs a synced flush operation on one or more indices. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-synced-flush-api.html. +// +type IndicesFlushSynced func(o ...func(*IndicesFlushSyncedRequest)) (*Response, error) + +// IndicesFlushSyncedRequest configures the Indices Flush Synced API request. +// +type IndicesFlushSyncedRequest struct { + Index []string + + AllowNoIndices *bool + ExpandWildcards string + IgnoreUnavailable *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesFlushSyncedRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_flush") + 1 + len("synced")) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_flush") + path.WriteString("/") + path.WriteString("synced") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesFlushSynced) WithContext(v context.Context) func(*IndicesFlushSyncedRequest) { + return func(r *IndicesFlushSyncedRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names; use _all for all indices. +// +func (f IndicesFlushSynced) WithIndex(v ...string) func(*IndicesFlushSyncedRequest) { + return func(r *IndicesFlushSyncedRequest) { + r.Index = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f IndicesFlushSynced) WithAllowNoIndices(v bool) func(*IndicesFlushSyncedRequest) { + return func(r *IndicesFlushSyncedRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f IndicesFlushSynced) WithExpandWildcards(v string) func(*IndicesFlushSyncedRequest) { + return func(r *IndicesFlushSyncedRequest) { + r.ExpandWildcards = v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f IndicesFlushSynced) WithIgnoreUnavailable(v bool) func(*IndicesFlushSyncedRequest) { + return func(r *IndicesFlushSyncedRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesFlushSynced) WithPretty() func(*IndicesFlushSyncedRequest) { + return func(r *IndicesFlushSyncedRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesFlushSynced) WithHuman() func(*IndicesFlushSyncedRequest) { + return func(r *IndicesFlushSyncedRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesFlushSynced) WithErrorTrace() func(*IndicesFlushSyncedRequest) { + return func(r *IndicesFlushSyncedRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesFlushSynced) WithFilterPath(v ...string) func(*IndicesFlushSyncedRequest) { + return func(r *IndicesFlushSyncedRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesFlushSynced) WithHeader(h map[string]string) func(*IndicesFlushSyncedRequest) { + return func(r *IndicesFlushSyncedRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesFlushSynced) WithOpaqueID(s string) func(*IndicesFlushSyncedRequest) { + return func(r *IndicesFlushSyncedRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.forcemerge.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.forcemerge.go new file mode 100644 index 00000000000..a130f92e3f4 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.forcemerge.go @@ -0,0 +1,278 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newIndicesForcemergeFunc(t Transport) IndicesForcemerge { + return func(o ...func(*IndicesForcemergeRequest)) (*Response, error) { + var r = IndicesForcemergeRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesForcemerge performs the force merge operation on one or more indices. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-forcemerge.html. +// +type IndicesForcemerge func(o ...func(*IndicesForcemergeRequest)) (*Response, error) + +// IndicesForcemergeRequest configures the Indices Forcemerge API request. +// +type IndicesForcemergeRequest struct { + Index []string + + AllowNoIndices *bool + ExpandWildcards string + Flush *bool + IgnoreUnavailable *bool + MaxNumSegments *int + OnlyExpungeDeletes *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesForcemergeRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_forcemerge")) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_forcemerge") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.Flush != nil { + params["flush"] = strconv.FormatBool(*r.Flush) + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.MaxNumSegments != nil { + params["max_num_segments"] = strconv.FormatInt(int64(*r.MaxNumSegments), 10) + } + + if r.OnlyExpungeDeletes != nil { + params["only_expunge_deletes"] = strconv.FormatBool(*r.OnlyExpungeDeletes) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesForcemerge) WithContext(v context.Context) func(*IndicesForcemergeRequest) { + return func(r *IndicesForcemergeRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names; use _all to perform the operation on all indices. +// +func (f IndicesForcemerge) WithIndex(v ...string) func(*IndicesForcemergeRequest) { + return func(r *IndicesForcemergeRequest) { + r.Index = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f IndicesForcemerge) WithAllowNoIndices(v bool) func(*IndicesForcemergeRequest) { + return func(r *IndicesForcemergeRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f IndicesForcemerge) WithExpandWildcards(v string) func(*IndicesForcemergeRequest) { + return func(r *IndicesForcemergeRequest) { + r.ExpandWildcards = v + } +} + +// WithFlush - specify whether the index should be flushed after performing the operation (default: true). +// +func (f IndicesForcemerge) WithFlush(v bool) func(*IndicesForcemergeRequest) { + return func(r *IndicesForcemergeRequest) { + r.Flush = &v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f IndicesForcemerge) WithIgnoreUnavailable(v bool) func(*IndicesForcemergeRequest) { + return func(r *IndicesForcemergeRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithMaxNumSegments - the number of segments the index should be merged into (default: dynamic). +// +func (f IndicesForcemerge) WithMaxNumSegments(v int) func(*IndicesForcemergeRequest) { + return func(r *IndicesForcemergeRequest) { + r.MaxNumSegments = &v + } +} + +// WithOnlyExpungeDeletes - specify whether the operation should only expunge deleted documents. +// +func (f IndicesForcemerge) WithOnlyExpungeDeletes(v bool) func(*IndicesForcemergeRequest) { + return func(r *IndicesForcemergeRequest) { + r.OnlyExpungeDeletes = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesForcemerge) WithPretty() func(*IndicesForcemergeRequest) { + return func(r *IndicesForcemergeRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesForcemerge) WithHuman() func(*IndicesForcemergeRequest) { + return func(r *IndicesForcemergeRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesForcemerge) WithErrorTrace() func(*IndicesForcemergeRequest) { + return func(r *IndicesForcemergeRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesForcemerge) WithFilterPath(v ...string) func(*IndicesForcemergeRequest) { + return func(r *IndicesForcemergeRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesForcemerge) WithHeader(h map[string]string) func(*IndicesForcemergeRequest) { + return func(r *IndicesForcemergeRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesForcemerge) WithOpaqueID(s string) func(*IndicesForcemergeRequest) { + return func(r *IndicesForcemergeRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get.go new file mode 100644 index 00000000000..588807d00f3 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get.go @@ -0,0 +1,293 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newIndicesGetFunc(t Transport) IndicesGet { + return func(index []string, o ...func(*IndicesGetRequest)) (*Response, error) { + var r = IndicesGetRequest{Index: index} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesGet returns information about one or more indices. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-index.html. +// +type IndicesGet func(index []string, o ...func(*IndicesGetRequest)) (*Response, error) + +// IndicesGetRequest configures the Indices Get API request. +// +type IndicesGetRequest struct { + Index []string + + AllowNoIndices *bool + ExpandWildcards string + FlatSettings *bool + IgnoreUnavailable *bool + IncludeDefaults *bool + IncludeTypeName *bool + Local *bool + MasterTimeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesGetRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(strings.Join(r.Index, ","))) + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.FlatSettings != nil { + params["flat_settings"] = strconv.FormatBool(*r.FlatSettings) + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.IncludeDefaults != nil { + params["include_defaults"] = strconv.FormatBool(*r.IncludeDefaults) + } + + if r.IncludeTypeName != nil { + params["include_type_name"] = strconv.FormatBool(*r.IncludeTypeName) + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesGet) WithContext(v context.Context) func(*IndicesGetRequest) { + return func(r *IndicesGetRequest) { + r.ctx = v + } +} + +// WithAllowNoIndices - ignore if a wildcard expression resolves to no concrete indices (default: false). +// +func (f IndicesGet) WithAllowNoIndices(v bool) func(*IndicesGetRequest) { + return func(r *IndicesGetRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether wildcard expressions should get expanded to open or closed indices (default: open). +// +func (f IndicesGet) WithExpandWildcards(v string) func(*IndicesGetRequest) { + return func(r *IndicesGetRequest) { + r.ExpandWildcards = v + } +} + +// WithFlatSettings - return settings in flat format (default: false). +// +func (f IndicesGet) WithFlatSettings(v bool) func(*IndicesGetRequest) { + return func(r *IndicesGetRequest) { + r.FlatSettings = &v + } +} + +// WithIgnoreUnavailable - ignore unavailable indexes (default: false). +// +func (f IndicesGet) WithIgnoreUnavailable(v bool) func(*IndicesGetRequest) { + return func(r *IndicesGetRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithIncludeDefaults - whether to return all default setting for each of the indices.. +// +func (f IndicesGet) WithIncludeDefaults(v bool) func(*IndicesGetRequest) { + return func(r *IndicesGetRequest) { + r.IncludeDefaults = &v + } +} + +// WithIncludeTypeName - whether to add the type name to the response (default: false). +// +func (f IndicesGet) WithIncludeTypeName(v bool) func(*IndicesGetRequest) { + return func(r *IndicesGetRequest) { + r.IncludeTypeName = &v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f IndicesGet) WithLocal(v bool) func(*IndicesGetRequest) { + return func(r *IndicesGetRequest) { + r.Local = &v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f IndicesGet) WithMasterTimeout(v time.Duration) func(*IndicesGetRequest) { + return func(r *IndicesGetRequest) { + r.MasterTimeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesGet) WithPretty() func(*IndicesGetRequest) { + return func(r *IndicesGetRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesGet) WithHuman() func(*IndicesGetRequest) { + return func(r *IndicesGetRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesGet) WithErrorTrace() func(*IndicesGetRequest) { + return func(r *IndicesGetRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesGet) WithFilterPath(v ...string) func(*IndicesGetRequest) { + return func(r *IndicesGetRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesGet) WithHeader(h map[string]string) func(*IndicesGetRequest) { + return func(r *IndicesGetRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesGet) WithOpaqueID(s string) func(*IndicesGetRequest) { + return func(r *IndicesGetRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get_alias.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get_alias.go new file mode 100644 index 00000000000..004d3308371 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get_alias.go @@ -0,0 +1,266 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newIndicesGetAliasFunc(t Transport) IndicesGetAlias { + return func(o ...func(*IndicesGetAliasRequest)) (*Response, error) { + var r = IndicesGetAliasRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesGetAlias returns an alias. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html. +// +type IndicesGetAlias func(o ...func(*IndicesGetAliasRequest)) (*Response, error) + +// IndicesGetAliasRequest configures the Indices Get Alias API request. +// +type IndicesGetAliasRequest struct { + Index []string + + Name []string + + AllowNoIndices *bool + ExpandWildcards string + IgnoreUnavailable *bool + Local *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesGetAliasRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_alias") + 1 + len(strings.Join(r.Name, ","))) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_alias") + if len(r.Name) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Name, ",")) + } + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesGetAlias) WithContext(v context.Context) func(*IndicesGetAliasRequest) { + return func(r *IndicesGetAliasRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names to filter aliases. +// +func (f IndicesGetAlias) WithIndex(v ...string) func(*IndicesGetAliasRequest) { + return func(r *IndicesGetAliasRequest) { + r.Index = v + } +} + +// WithName - a list of alias names to return. +// +func (f IndicesGetAlias) WithName(v ...string) func(*IndicesGetAliasRequest) { + return func(r *IndicesGetAliasRequest) { + r.Name = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f IndicesGetAlias) WithAllowNoIndices(v bool) func(*IndicesGetAliasRequest) { + return func(r *IndicesGetAliasRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f IndicesGetAlias) WithExpandWildcards(v string) func(*IndicesGetAliasRequest) { + return func(r *IndicesGetAliasRequest) { + r.ExpandWildcards = v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f IndicesGetAlias) WithIgnoreUnavailable(v bool) func(*IndicesGetAliasRequest) { + return func(r *IndicesGetAliasRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f IndicesGetAlias) WithLocal(v bool) func(*IndicesGetAliasRequest) { + return func(r *IndicesGetAliasRequest) { + r.Local = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesGetAlias) WithPretty() func(*IndicesGetAliasRequest) { + return func(r *IndicesGetAliasRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesGetAlias) WithHuman() func(*IndicesGetAliasRequest) { + return func(r *IndicesGetAliasRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesGetAlias) WithErrorTrace() func(*IndicesGetAliasRequest) { + return func(r *IndicesGetAliasRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesGetAlias) WithFilterPath(v ...string) func(*IndicesGetAliasRequest) { + return func(r *IndicesGetAliasRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesGetAlias) WithHeader(h map[string]string) func(*IndicesGetAliasRequest) { + return func(r *IndicesGetAliasRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesGetAlias) WithOpaqueID(s string) func(*IndicesGetAliasRequest) { + return func(r *IndicesGetAliasRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get_field_mapping.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get_field_mapping.go new file mode 100644 index 00000000000..be3f1b744de --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get_field_mapping.go @@ -0,0 +1,284 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newIndicesGetFieldMappingFunc(t Transport) IndicesGetFieldMapping { + return func(fields []string, o ...func(*IndicesGetFieldMappingRequest)) (*Response, error) { + var r = IndicesGetFieldMappingRequest{Fields: fields} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesGetFieldMapping returns mapping for one or more fields. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-field-mapping.html. +// +type IndicesGetFieldMapping func(fields []string, o ...func(*IndicesGetFieldMappingRequest)) (*Response, error) + +// IndicesGetFieldMappingRequest configures the Indices Get Field Mapping API request. +// +type IndicesGetFieldMappingRequest struct { + Index []string + + Fields []string + + AllowNoIndices *bool + ExpandWildcards string + IgnoreUnavailable *bool + IncludeDefaults *bool + IncludeTypeName *bool + Local *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesGetFieldMappingRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_mapping") + 1 + len("field") + 1 + len(strings.Join(r.Fields, ","))) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_mapping") + path.WriteString("/") + path.WriteString("field") + path.WriteString("/") + path.WriteString(strings.Join(r.Fields, ",")) + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.IncludeDefaults != nil { + params["include_defaults"] = strconv.FormatBool(*r.IncludeDefaults) + } + + if r.IncludeTypeName != nil { + params["include_type_name"] = strconv.FormatBool(*r.IncludeTypeName) + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesGetFieldMapping) WithContext(v context.Context) func(*IndicesGetFieldMappingRequest) { + return func(r *IndicesGetFieldMappingRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names. +// +func (f IndicesGetFieldMapping) WithIndex(v ...string) func(*IndicesGetFieldMappingRequest) { + return func(r *IndicesGetFieldMappingRequest) { + r.Index = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f IndicesGetFieldMapping) WithAllowNoIndices(v bool) func(*IndicesGetFieldMappingRequest) { + return func(r *IndicesGetFieldMappingRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f IndicesGetFieldMapping) WithExpandWildcards(v string) func(*IndicesGetFieldMappingRequest) { + return func(r *IndicesGetFieldMappingRequest) { + r.ExpandWildcards = v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f IndicesGetFieldMapping) WithIgnoreUnavailable(v bool) func(*IndicesGetFieldMappingRequest) { + return func(r *IndicesGetFieldMappingRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithIncludeDefaults - whether the default mapping values should be returned as well. +// +func (f IndicesGetFieldMapping) WithIncludeDefaults(v bool) func(*IndicesGetFieldMappingRequest) { + return func(r *IndicesGetFieldMappingRequest) { + r.IncludeDefaults = &v + } +} + +// WithIncludeTypeName - whether a type should be returned in the body of the mappings.. +// +func (f IndicesGetFieldMapping) WithIncludeTypeName(v bool) func(*IndicesGetFieldMappingRequest) { + return func(r *IndicesGetFieldMappingRequest) { + r.IncludeTypeName = &v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f IndicesGetFieldMapping) WithLocal(v bool) func(*IndicesGetFieldMappingRequest) { + return func(r *IndicesGetFieldMappingRequest) { + r.Local = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesGetFieldMapping) WithPretty() func(*IndicesGetFieldMappingRequest) { + return func(r *IndicesGetFieldMappingRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesGetFieldMapping) WithHuman() func(*IndicesGetFieldMappingRequest) { + return func(r *IndicesGetFieldMappingRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesGetFieldMapping) WithErrorTrace() func(*IndicesGetFieldMappingRequest) { + return func(r *IndicesGetFieldMappingRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesGetFieldMapping) WithFilterPath(v ...string) func(*IndicesGetFieldMappingRequest) { + return func(r *IndicesGetFieldMappingRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesGetFieldMapping) WithHeader(h map[string]string) func(*IndicesGetFieldMappingRequest) { + return func(r *IndicesGetFieldMappingRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesGetFieldMapping) WithOpaqueID(s string) func(*IndicesGetFieldMappingRequest) { + return func(r *IndicesGetFieldMappingRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get_mapping.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get_mapping.go new file mode 100644 index 00000000000..0fe32f1faa8 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get_mapping.go @@ -0,0 +1,266 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newIndicesGetMappingFunc(t Transport) IndicesGetMapping { + return func(o ...func(*IndicesGetMappingRequest)) (*Response, error) { + var r = IndicesGetMappingRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesGetMapping returns mappings for one or more indices. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-mapping.html. +// +type IndicesGetMapping func(o ...func(*IndicesGetMappingRequest)) (*Response, error) + +// IndicesGetMappingRequest configures the Indices Get Mapping API request. +// +type IndicesGetMappingRequest struct { + Index []string + + AllowNoIndices *bool + ExpandWildcards string + IgnoreUnavailable *bool + Local *bool + MasterTimeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesGetMappingRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_mapping")) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_mapping") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesGetMapping) WithContext(v context.Context) func(*IndicesGetMappingRequest) { + return func(r *IndicesGetMappingRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names. +// +func (f IndicesGetMapping) WithIndex(v ...string) func(*IndicesGetMappingRequest) { + return func(r *IndicesGetMappingRequest) { + r.Index = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f IndicesGetMapping) WithAllowNoIndices(v bool) func(*IndicesGetMappingRequest) { + return func(r *IndicesGetMappingRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f IndicesGetMapping) WithExpandWildcards(v string) func(*IndicesGetMappingRequest) { + return func(r *IndicesGetMappingRequest) { + r.ExpandWildcards = v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f IndicesGetMapping) WithIgnoreUnavailable(v bool) func(*IndicesGetMappingRequest) { + return func(r *IndicesGetMappingRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f IndicesGetMapping) WithLocal(v bool) func(*IndicesGetMappingRequest) { + return func(r *IndicesGetMappingRequest) { + r.Local = &v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f IndicesGetMapping) WithMasterTimeout(v time.Duration) func(*IndicesGetMappingRequest) { + return func(r *IndicesGetMappingRequest) { + r.MasterTimeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesGetMapping) WithPretty() func(*IndicesGetMappingRequest) { + return func(r *IndicesGetMappingRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesGetMapping) WithHuman() func(*IndicesGetMappingRequest) { + return func(r *IndicesGetMappingRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesGetMapping) WithErrorTrace() func(*IndicesGetMappingRequest) { + return func(r *IndicesGetMappingRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesGetMapping) WithFilterPath(v ...string) func(*IndicesGetMappingRequest) { + return func(r *IndicesGetMappingRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesGetMapping) WithHeader(h map[string]string) func(*IndicesGetMappingRequest) { + return func(r *IndicesGetMappingRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesGetMapping) WithOpaqueID(s string) func(*IndicesGetMappingRequest) { + return func(r *IndicesGetMappingRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get_settings.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get_settings.go new file mode 100644 index 00000000000..ec27d5228b2 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get_settings.go @@ -0,0 +1,306 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newIndicesGetSettingsFunc(t Transport) IndicesGetSettings { + return func(o ...func(*IndicesGetSettingsRequest)) (*Response, error) { + var r = IndicesGetSettingsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesGetSettings returns settings for one or more indices. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-settings.html. +// +type IndicesGetSettings func(o ...func(*IndicesGetSettingsRequest)) (*Response, error) + +// IndicesGetSettingsRequest configures the Indices Get Settings API request. +// +type IndicesGetSettingsRequest struct { + Index []string + + Name []string + + AllowNoIndices *bool + ExpandWildcards string + FlatSettings *bool + IgnoreUnavailable *bool + IncludeDefaults *bool + Local *bool + MasterTimeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesGetSettingsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_settings") + 1 + len(strings.Join(r.Name, ","))) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_settings") + if len(r.Name) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Name, ",")) + } + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.FlatSettings != nil { + params["flat_settings"] = strconv.FormatBool(*r.FlatSettings) + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.IncludeDefaults != nil { + params["include_defaults"] = strconv.FormatBool(*r.IncludeDefaults) + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesGetSettings) WithContext(v context.Context) func(*IndicesGetSettingsRequest) { + return func(r *IndicesGetSettingsRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names; use _all to perform the operation on all indices. +// +func (f IndicesGetSettings) WithIndex(v ...string) func(*IndicesGetSettingsRequest) { + return func(r *IndicesGetSettingsRequest) { + r.Index = v + } +} + +// WithName - the name of the settings that should be included. +// +func (f IndicesGetSettings) WithName(v ...string) func(*IndicesGetSettingsRequest) { + return func(r *IndicesGetSettingsRequest) { + r.Name = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f IndicesGetSettings) WithAllowNoIndices(v bool) func(*IndicesGetSettingsRequest) { + return func(r *IndicesGetSettingsRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f IndicesGetSettings) WithExpandWildcards(v string) func(*IndicesGetSettingsRequest) { + return func(r *IndicesGetSettingsRequest) { + r.ExpandWildcards = v + } +} + +// WithFlatSettings - return settings in flat format (default: false). +// +func (f IndicesGetSettings) WithFlatSettings(v bool) func(*IndicesGetSettingsRequest) { + return func(r *IndicesGetSettingsRequest) { + r.FlatSettings = &v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f IndicesGetSettings) WithIgnoreUnavailable(v bool) func(*IndicesGetSettingsRequest) { + return func(r *IndicesGetSettingsRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithIncludeDefaults - whether to return all default setting for each of the indices.. +// +func (f IndicesGetSettings) WithIncludeDefaults(v bool) func(*IndicesGetSettingsRequest) { + return func(r *IndicesGetSettingsRequest) { + r.IncludeDefaults = &v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f IndicesGetSettings) WithLocal(v bool) func(*IndicesGetSettingsRequest) { + return func(r *IndicesGetSettingsRequest) { + r.Local = &v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f IndicesGetSettings) WithMasterTimeout(v time.Duration) func(*IndicesGetSettingsRequest) { + return func(r *IndicesGetSettingsRequest) { + r.MasterTimeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesGetSettings) WithPretty() func(*IndicesGetSettingsRequest) { + return func(r *IndicesGetSettingsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesGetSettings) WithHuman() func(*IndicesGetSettingsRequest) { + return func(r *IndicesGetSettingsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesGetSettings) WithErrorTrace() func(*IndicesGetSettingsRequest) { + return func(r *IndicesGetSettingsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesGetSettings) WithFilterPath(v ...string) func(*IndicesGetSettingsRequest) { + return func(r *IndicesGetSettingsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesGetSettings) WithHeader(h map[string]string) func(*IndicesGetSettingsRequest) { + return func(r *IndicesGetSettingsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesGetSettings) WithOpaqueID(s string) func(*IndicesGetSettingsRequest) { + return func(r *IndicesGetSettingsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get_template.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get_template.go new file mode 100644 index 00000000000..316c3b8aca4 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get_template.go @@ -0,0 +1,253 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newIndicesGetTemplateFunc(t Transport) IndicesGetTemplate { + return func(o ...func(*IndicesGetTemplateRequest)) (*Response, error) { + var r = IndicesGetTemplateRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesGetTemplate returns an index template. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html. +// +type IndicesGetTemplate func(o ...func(*IndicesGetTemplateRequest)) (*Response, error) + +// IndicesGetTemplateRequest configures the Indices Get Template API request. +// +type IndicesGetTemplateRequest struct { + Name []string + + FlatSettings *bool + IncludeTypeName *bool + Local *bool + MasterTimeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesGetTemplateRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_template") + 1 + len(strings.Join(r.Name, ","))) + path.WriteString("/") + path.WriteString("_template") + if len(r.Name) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Name, ",")) + } + + params = make(map[string]string) + + if r.FlatSettings != nil { + params["flat_settings"] = strconv.FormatBool(*r.FlatSettings) + } + + if r.IncludeTypeName != nil { + params["include_type_name"] = strconv.FormatBool(*r.IncludeTypeName) + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesGetTemplate) WithContext(v context.Context) func(*IndicesGetTemplateRequest) { + return func(r *IndicesGetTemplateRequest) { + r.ctx = v + } +} + +// WithName - the comma separated names of the index templates. +// +func (f IndicesGetTemplate) WithName(v ...string) func(*IndicesGetTemplateRequest) { + return func(r *IndicesGetTemplateRequest) { + r.Name = v + } +} + +// WithFlatSettings - return settings in flat format (default: false). +// +func (f IndicesGetTemplate) WithFlatSettings(v bool) func(*IndicesGetTemplateRequest) { + return func(r *IndicesGetTemplateRequest) { + r.FlatSettings = &v + } +} + +// WithIncludeTypeName - whether a type should be returned in the body of the mappings.. +// +func (f IndicesGetTemplate) WithIncludeTypeName(v bool) func(*IndicesGetTemplateRequest) { + return func(r *IndicesGetTemplateRequest) { + r.IncludeTypeName = &v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f IndicesGetTemplate) WithLocal(v bool) func(*IndicesGetTemplateRequest) { + return func(r *IndicesGetTemplateRequest) { + r.Local = &v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f IndicesGetTemplate) WithMasterTimeout(v time.Duration) func(*IndicesGetTemplateRequest) { + return func(r *IndicesGetTemplateRequest) { + r.MasterTimeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesGetTemplate) WithPretty() func(*IndicesGetTemplateRequest) { + return func(r *IndicesGetTemplateRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesGetTemplate) WithHuman() func(*IndicesGetTemplateRequest) { + return func(r *IndicesGetTemplateRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesGetTemplate) WithErrorTrace() func(*IndicesGetTemplateRequest) { + return func(r *IndicesGetTemplateRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesGetTemplate) WithFilterPath(v ...string) func(*IndicesGetTemplateRequest) { + return func(r *IndicesGetTemplateRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesGetTemplate) WithHeader(h map[string]string) func(*IndicesGetTemplateRequest) { + return func(r *IndicesGetTemplateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesGetTemplate) WithOpaqueID(s string) func(*IndicesGetTemplateRequest) { + return func(r *IndicesGetTemplateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get_upgrade.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get_upgrade.go new file mode 100644 index 00000000000..cf59e1d6f4b --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.get_upgrade.go @@ -0,0 +1,239 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newIndicesGetUpgradeFunc(t Transport) IndicesGetUpgrade { + return func(o ...func(*IndicesGetUpgradeRequest)) (*Response, error) { + var r = IndicesGetUpgradeRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesGetUpgrade the _upgrade API is no longer useful and will be removed. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-upgrade.html. +// +type IndicesGetUpgrade func(o ...func(*IndicesGetUpgradeRequest)) (*Response, error) + +// IndicesGetUpgradeRequest configures the Indices Get Upgrade API request. +// +type IndicesGetUpgradeRequest struct { + Index []string + + AllowNoIndices *bool + ExpandWildcards string + IgnoreUnavailable *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesGetUpgradeRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_upgrade")) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_upgrade") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesGetUpgrade) WithContext(v context.Context) func(*IndicesGetUpgradeRequest) { + return func(r *IndicesGetUpgradeRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names; use _all to perform the operation on all indices. +// +func (f IndicesGetUpgrade) WithIndex(v ...string) func(*IndicesGetUpgradeRequest) { + return func(r *IndicesGetUpgradeRequest) { + r.Index = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f IndicesGetUpgrade) WithAllowNoIndices(v bool) func(*IndicesGetUpgradeRequest) { + return func(r *IndicesGetUpgradeRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f IndicesGetUpgrade) WithExpandWildcards(v string) func(*IndicesGetUpgradeRequest) { + return func(r *IndicesGetUpgradeRequest) { + r.ExpandWildcards = v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f IndicesGetUpgrade) WithIgnoreUnavailable(v bool) func(*IndicesGetUpgradeRequest) { + return func(r *IndicesGetUpgradeRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesGetUpgrade) WithPretty() func(*IndicesGetUpgradeRequest) { + return func(r *IndicesGetUpgradeRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesGetUpgrade) WithHuman() func(*IndicesGetUpgradeRequest) { + return func(r *IndicesGetUpgradeRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesGetUpgrade) WithErrorTrace() func(*IndicesGetUpgradeRequest) { + return func(r *IndicesGetUpgradeRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesGetUpgrade) WithFilterPath(v ...string) func(*IndicesGetUpgradeRequest) { + return func(r *IndicesGetUpgradeRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesGetUpgrade) WithHeader(h map[string]string) func(*IndicesGetUpgradeRequest) { + return func(r *IndicesGetUpgradeRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesGetUpgrade) WithOpaqueID(s string) func(*IndicesGetUpgradeRequest) { + return func(r *IndicesGetUpgradeRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.open.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.open.go new file mode 100644 index 00000000000..9994f55bc85 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.open.go @@ -0,0 +1,269 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newIndicesOpenFunc(t Transport) IndicesOpen { + return func(index []string, o ...func(*IndicesOpenRequest)) (*Response, error) { + var r = IndicesOpenRequest{Index: index} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesOpen opens an index. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html. +// +type IndicesOpen func(index []string, o ...func(*IndicesOpenRequest)) (*Response, error) + +// IndicesOpenRequest configures the Indices Open API request. +// +type IndicesOpenRequest struct { + Index []string + + AllowNoIndices *bool + ExpandWildcards string + IgnoreUnavailable *bool + MasterTimeout time.Duration + Timeout time.Duration + WaitForActiveShards string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesOpenRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_open")) + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + path.WriteString("/") + path.WriteString("_open") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.WaitForActiveShards != "" { + params["wait_for_active_shards"] = r.WaitForActiveShards + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesOpen) WithContext(v context.Context) func(*IndicesOpenRequest) { + return func(r *IndicesOpenRequest) { + r.ctx = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f IndicesOpen) WithAllowNoIndices(v bool) func(*IndicesOpenRequest) { + return func(r *IndicesOpenRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f IndicesOpen) WithExpandWildcards(v string) func(*IndicesOpenRequest) { + return func(r *IndicesOpenRequest) { + r.ExpandWildcards = v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f IndicesOpen) WithIgnoreUnavailable(v bool) func(*IndicesOpenRequest) { + return func(r *IndicesOpenRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f IndicesOpen) WithMasterTimeout(v time.Duration) func(*IndicesOpenRequest) { + return func(r *IndicesOpenRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f IndicesOpen) WithTimeout(v time.Duration) func(*IndicesOpenRequest) { + return func(r *IndicesOpenRequest) { + r.Timeout = v + } +} + +// WithWaitForActiveShards - sets the number of active shards to wait for before the operation returns.. +// +func (f IndicesOpen) WithWaitForActiveShards(v string) func(*IndicesOpenRequest) { + return func(r *IndicesOpenRequest) { + r.WaitForActiveShards = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesOpen) WithPretty() func(*IndicesOpenRequest) { + return func(r *IndicesOpenRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesOpen) WithHuman() func(*IndicesOpenRequest) { + return func(r *IndicesOpenRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesOpen) WithErrorTrace() func(*IndicesOpenRequest) { + return func(r *IndicesOpenRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesOpen) WithFilterPath(v ...string) func(*IndicesOpenRequest) { + return func(r *IndicesOpenRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesOpen) WithHeader(h map[string]string) func(*IndicesOpenRequest) { + return func(r *IndicesOpenRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesOpen) WithOpaqueID(s string) func(*IndicesOpenRequest) { + return func(r *IndicesOpenRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.put_alias.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.put_alias.go new file mode 100644 index 00000000000..021d33130e0 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.put_alias.go @@ -0,0 +1,235 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" + "time" +) + +func newIndicesPutAliasFunc(t Transport) IndicesPutAlias { + return func(index []string, name string, o ...func(*IndicesPutAliasRequest)) (*Response, error) { + var r = IndicesPutAliasRequest{Index: index, Name: name} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesPutAlias creates or updates an alias. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html. +// +type IndicesPutAlias func(index []string, name string, o ...func(*IndicesPutAliasRequest)) (*Response, error) + +// IndicesPutAliasRequest configures the Indices Put Alias API request. +// +type IndicesPutAliasRequest struct { + Index []string + + Body io.Reader + + Name string + + MasterTimeout time.Duration + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesPutAliasRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_aliases") + 1 + len(r.Name)) + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + path.WriteString("/") + path.WriteString("_aliases") + path.WriteString("/") + path.WriteString(r.Name) + + params = make(map[string]string) + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesPutAlias) WithContext(v context.Context) func(*IndicesPutAliasRequest) { + return func(r *IndicesPutAliasRequest) { + r.ctx = v + } +} + +// WithBody - The settings for the alias, such as `routing` or `filter`. +// +func (f IndicesPutAlias) WithBody(v io.Reader) func(*IndicesPutAliasRequest) { + return func(r *IndicesPutAliasRequest) { + r.Body = v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f IndicesPutAlias) WithMasterTimeout(v time.Duration) func(*IndicesPutAliasRequest) { + return func(r *IndicesPutAliasRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit timestamp for the document. +// +func (f IndicesPutAlias) WithTimeout(v time.Duration) func(*IndicesPutAliasRequest) { + return func(r *IndicesPutAliasRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesPutAlias) WithPretty() func(*IndicesPutAliasRequest) { + return func(r *IndicesPutAliasRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesPutAlias) WithHuman() func(*IndicesPutAliasRequest) { + return func(r *IndicesPutAliasRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesPutAlias) WithErrorTrace() func(*IndicesPutAliasRequest) { + return func(r *IndicesPutAliasRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesPutAlias) WithFilterPath(v ...string) func(*IndicesPutAliasRequest) { + return func(r *IndicesPutAliasRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesPutAlias) WithHeader(h map[string]string) func(*IndicesPutAliasRequest) { + return func(r *IndicesPutAliasRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesPutAlias) WithOpaqueID(s string) func(*IndicesPutAliasRequest) { + return func(r *IndicesPutAliasRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.put_mapping.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.put_mapping.go new file mode 100644 index 00000000000..187f311d182 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.put_mapping.go @@ -0,0 +1,265 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" + "time" +) + +func newIndicesPutMappingFunc(t Transport) IndicesPutMapping { + return func(index []string, body io.Reader, o ...func(*IndicesPutMappingRequest)) (*Response, error) { + var r = IndicesPutMappingRequest{Index: index, Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesPutMapping updates the index mappings. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-put-mapping.html. +// +type IndicesPutMapping func(index []string, body io.Reader, o ...func(*IndicesPutMappingRequest)) (*Response, error) + +// IndicesPutMappingRequest configures the Indices Put Mapping API request. +// +type IndicesPutMappingRequest struct { + Index []string + + Body io.Reader + + AllowNoIndices *bool + ExpandWildcards string + IgnoreUnavailable *bool + MasterTimeout time.Duration + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesPutMappingRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(len(strings.Join(r.Index, ",")) + len("/_mapping") + 1) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_mapping") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesPutMapping) WithContext(v context.Context) func(*IndicesPutMappingRequest) { + return func(r *IndicesPutMappingRequest) { + r.ctx = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f IndicesPutMapping) WithAllowNoIndices(v bool) func(*IndicesPutMappingRequest) { + return func(r *IndicesPutMappingRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f IndicesPutMapping) WithExpandWildcards(v string) func(*IndicesPutMappingRequest) { + return func(r *IndicesPutMappingRequest) { + r.ExpandWildcards = v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f IndicesPutMapping) WithIgnoreUnavailable(v bool) func(*IndicesPutMappingRequest) { + return func(r *IndicesPutMappingRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f IndicesPutMapping) WithMasterTimeout(v time.Duration) func(*IndicesPutMappingRequest) { + return func(r *IndicesPutMappingRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f IndicesPutMapping) WithTimeout(v time.Duration) func(*IndicesPutMappingRequest) { + return func(r *IndicesPutMappingRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesPutMapping) WithPretty() func(*IndicesPutMappingRequest) { + return func(r *IndicesPutMappingRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesPutMapping) WithHuman() func(*IndicesPutMappingRequest) { + return func(r *IndicesPutMappingRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesPutMapping) WithErrorTrace() func(*IndicesPutMappingRequest) { + return func(r *IndicesPutMappingRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesPutMapping) WithFilterPath(v ...string) func(*IndicesPutMappingRequest) { + return func(r *IndicesPutMappingRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesPutMapping) WithHeader(h map[string]string) func(*IndicesPutMappingRequest) { + return func(r *IndicesPutMappingRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesPutMapping) WithOpaqueID(s string) func(*IndicesPutMappingRequest) { + return func(r *IndicesPutMappingRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.put_settings.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.put_settings.go new file mode 100644 index 00000000000..a3406e40d2a --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.put_settings.go @@ -0,0 +1,299 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" + "time" +) + +func newIndicesPutSettingsFunc(t Transport) IndicesPutSettings { + return func(body io.Reader, o ...func(*IndicesPutSettingsRequest)) (*Response, error) { + var r = IndicesPutSettingsRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesPutSettings updates the index settings. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-update-settings.html. +// +type IndicesPutSettings func(body io.Reader, o ...func(*IndicesPutSettingsRequest)) (*Response, error) + +// IndicesPutSettingsRequest configures the Indices Put Settings API request. +// +type IndicesPutSettingsRequest struct { + Index []string + + Body io.Reader + + AllowNoIndices *bool + ExpandWildcards string + FlatSettings *bool + IgnoreUnavailable *bool + MasterTimeout time.Duration + PreserveExisting *bool + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesPutSettingsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_settings")) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_settings") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.FlatSettings != nil { + params["flat_settings"] = strconv.FormatBool(*r.FlatSettings) + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.PreserveExisting != nil { + params["preserve_existing"] = strconv.FormatBool(*r.PreserveExisting) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesPutSettings) WithContext(v context.Context) func(*IndicesPutSettingsRequest) { + return func(r *IndicesPutSettingsRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names; use _all to perform the operation on all indices. +// +func (f IndicesPutSettings) WithIndex(v ...string) func(*IndicesPutSettingsRequest) { + return func(r *IndicesPutSettingsRequest) { + r.Index = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f IndicesPutSettings) WithAllowNoIndices(v bool) func(*IndicesPutSettingsRequest) { + return func(r *IndicesPutSettingsRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f IndicesPutSettings) WithExpandWildcards(v string) func(*IndicesPutSettingsRequest) { + return func(r *IndicesPutSettingsRequest) { + r.ExpandWildcards = v + } +} + +// WithFlatSettings - return settings in flat format (default: false). +// +func (f IndicesPutSettings) WithFlatSettings(v bool) func(*IndicesPutSettingsRequest) { + return func(r *IndicesPutSettingsRequest) { + r.FlatSettings = &v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f IndicesPutSettings) WithIgnoreUnavailable(v bool) func(*IndicesPutSettingsRequest) { + return func(r *IndicesPutSettingsRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f IndicesPutSettings) WithMasterTimeout(v time.Duration) func(*IndicesPutSettingsRequest) { + return func(r *IndicesPutSettingsRequest) { + r.MasterTimeout = v + } +} + +// WithPreserveExisting - whether to update existing settings. if set to `true` existing settings on an index remain unchanged, the default is `false`. +// +func (f IndicesPutSettings) WithPreserveExisting(v bool) func(*IndicesPutSettingsRequest) { + return func(r *IndicesPutSettingsRequest) { + r.PreserveExisting = &v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f IndicesPutSettings) WithTimeout(v time.Duration) func(*IndicesPutSettingsRequest) { + return func(r *IndicesPutSettingsRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesPutSettings) WithPretty() func(*IndicesPutSettingsRequest) { + return func(r *IndicesPutSettingsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesPutSettings) WithHuman() func(*IndicesPutSettingsRequest) { + return func(r *IndicesPutSettingsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesPutSettings) WithErrorTrace() func(*IndicesPutSettingsRequest) { + return func(r *IndicesPutSettingsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesPutSettings) WithFilterPath(v ...string) func(*IndicesPutSettingsRequest) { + return func(r *IndicesPutSettingsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesPutSettings) WithHeader(h map[string]string) func(*IndicesPutSettingsRequest) { + return func(r *IndicesPutSettingsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesPutSettings) WithOpaqueID(s string) func(*IndicesPutSettingsRequest) { + return func(r *IndicesPutSettingsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.put_template.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.put_template.go new file mode 100644 index 00000000000..4cfb284694e --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.put_template.go @@ -0,0 +1,276 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" + "time" +) + +func newIndicesPutTemplateFunc(t Transport) IndicesPutTemplate { + return func(name string, body io.Reader, o ...func(*IndicesPutTemplateRequest)) (*Response, error) { + var r = IndicesPutTemplateRequest{Name: name, Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesPutTemplate creates or updates an index template. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html. +// +type IndicesPutTemplate func(name string, body io.Reader, o ...func(*IndicesPutTemplateRequest)) (*Response, error) + +// IndicesPutTemplateRequest configures the Indices Put Template API request. +// +type IndicesPutTemplateRequest struct { + Body io.Reader + + Name string + + Create *bool + FlatSettings *bool + IncludeTypeName *bool + MasterTimeout time.Duration + Order *int + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesPutTemplateRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_template") + 1 + len(r.Name)) + path.WriteString("/") + path.WriteString("_template") + path.WriteString("/") + path.WriteString(r.Name) + + params = make(map[string]string) + + if r.Create != nil { + params["create"] = strconv.FormatBool(*r.Create) + } + + if r.FlatSettings != nil { + params["flat_settings"] = strconv.FormatBool(*r.FlatSettings) + } + + if r.IncludeTypeName != nil { + params["include_type_name"] = strconv.FormatBool(*r.IncludeTypeName) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Order != nil { + params["order"] = strconv.FormatInt(int64(*r.Order), 10) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesPutTemplate) WithContext(v context.Context) func(*IndicesPutTemplateRequest) { + return func(r *IndicesPutTemplateRequest) { + r.ctx = v + } +} + +// WithCreate - whether the index template should only be added if new or can also replace an existing one. +// +func (f IndicesPutTemplate) WithCreate(v bool) func(*IndicesPutTemplateRequest) { + return func(r *IndicesPutTemplateRequest) { + r.Create = &v + } +} + +// WithFlatSettings - return settings in flat format (default: false). +// +func (f IndicesPutTemplate) WithFlatSettings(v bool) func(*IndicesPutTemplateRequest) { + return func(r *IndicesPutTemplateRequest) { + r.FlatSettings = &v + } +} + +// WithIncludeTypeName - whether a type should be returned in the body of the mappings.. +// +func (f IndicesPutTemplate) WithIncludeTypeName(v bool) func(*IndicesPutTemplateRequest) { + return func(r *IndicesPutTemplateRequest) { + r.IncludeTypeName = &v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f IndicesPutTemplate) WithMasterTimeout(v time.Duration) func(*IndicesPutTemplateRequest) { + return func(r *IndicesPutTemplateRequest) { + r.MasterTimeout = v + } +} + +// WithOrder - the order for this template when merging multiple matching ones (higher numbers are merged later, overriding the lower numbers). +// +func (f IndicesPutTemplate) WithOrder(v int) func(*IndicesPutTemplateRequest) { + return func(r *IndicesPutTemplateRequest) { + r.Order = &v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f IndicesPutTemplate) WithTimeout(v time.Duration) func(*IndicesPutTemplateRequest) { + return func(r *IndicesPutTemplateRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesPutTemplate) WithPretty() func(*IndicesPutTemplateRequest) { + return func(r *IndicesPutTemplateRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesPutTemplate) WithHuman() func(*IndicesPutTemplateRequest) { + return func(r *IndicesPutTemplateRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesPutTemplate) WithErrorTrace() func(*IndicesPutTemplateRequest) { + return func(r *IndicesPutTemplateRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesPutTemplate) WithFilterPath(v ...string) func(*IndicesPutTemplateRequest) { + return func(r *IndicesPutTemplateRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesPutTemplate) WithHeader(h map[string]string) func(*IndicesPutTemplateRequest) { + return func(r *IndicesPutTemplateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesPutTemplate) WithOpaqueID(s string) func(*IndicesPutTemplateRequest) { + return func(r *IndicesPutTemplateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.recovery.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.recovery.go new file mode 100644 index 00000000000..ee39ece3994 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.recovery.go @@ -0,0 +1,226 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newIndicesRecoveryFunc(t Transport) IndicesRecovery { + return func(o ...func(*IndicesRecoveryRequest)) (*Response, error) { + var r = IndicesRecoveryRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesRecovery returns information about ongoing index shard recoveries. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-recovery.html. +// +type IndicesRecovery func(o ...func(*IndicesRecoveryRequest)) (*Response, error) + +// IndicesRecoveryRequest configures the Indices Recovery API request. +// +type IndicesRecoveryRequest struct { + Index []string + + ActiveOnly *bool + Detailed *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesRecoveryRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_recovery")) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_recovery") + + params = make(map[string]string) + + if r.ActiveOnly != nil { + params["active_only"] = strconv.FormatBool(*r.ActiveOnly) + } + + if r.Detailed != nil { + params["detailed"] = strconv.FormatBool(*r.Detailed) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesRecovery) WithContext(v context.Context) func(*IndicesRecoveryRequest) { + return func(r *IndicesRecoveryRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names; use _all to perform the operation on all indices. +// +func (f IndicesRecovery) WithIndex(v ...string) func(*IndicesRecoveryRequest) { + return func(r *IndicesRecoveryRequest) { + r.Index = v + } +} + +// WithActiveOnly - display only those recoveries that are currently on-going. +// +func (f IndicesRecovery) WithActiveOnly(v bool) func(*IndicesRecoveryRequest) { + return func(r *IndicesRecoveryRequest) { + r.ActiveOnly = &v + } +} + +// WithDetailed - whether to display detailed information about shard recovery. +// +func (f IndicesRecovery) WithDetailed(v bool) func(*IndicesRecoveryRequest) { + return func(r *IndicesRecoveryRequest) { + r.Detailed = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesRecovery) WithPretty() func(*IndicesRecoveryRequest) { + return func(r *IndicesRecoveryRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesRecovery) WithHuman() func(*IndicesRecoveryRequest) { + return func(r *IndicesRecoveryRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesRecovery) WithErrorTrace() func(*IndicesRecoveryRequest) { + return func(r *IndicesRecoveryRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesRecovery) WithFilterPath(v ...string) func(*IndicesRecoveryRequest) { + return func(r *IndicesRecoveryRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesRecovery) WithHeader(h map[string]string) func(*IndicesRecoveryRequest) { + return func(r *IndicesRecoveryRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesRecovery) WithOpaqueID(s string) func(*IndicesRecoveryRequest) { + return func(r *IndicesRecoveryRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.refresh.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.refresh.go new file mode 100644 index 00000000000..ee40a41ff58 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.refresh.go @@ -0,0 +1,239 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newIndicesRefreshFunc(t Transport) IndicesRefresh { + return func(o ...func(*IndicesRefreshRequest)) (*Response, error) { + var r = IndicesRefreshRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesRefresh performs the refresh operation in one or more indices. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-refresh.html. +// +type IndicesRefresh func(o ...func(*IndicesRefreshRequest)) (*Response, error) + +// IndicesRefreshRequest configures the Indices Refresh API request. +// +type IndicesRefreshRequest struct { + Index []string + + AllowNoIndices *bool + ExpandWildcards string + IgnoreUnavailable *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesRefreshRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_refresh")) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_refresh") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesRefresh) WithContext(v context.Context) func(*IndicesRefreshRequest) { + return func(r *IndicesRefreshRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names; use _all to perform the operation on all indices. +// +func (f IndicesRefresh) WithIndex(v ...string) func(*IndicesRefreshRequest) { + return func(r *IndicesRefreshRequest) { + r.Index = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f IndicesRefresh) WithAllowNoIndices(v bool) func(*IndicesRefreshRequest) { + return func(r *IndicesRefreshRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f IndicesRefresh) WithExpandWildcards(v string) func(*IndicesRefreshRequest) { + return func(r *IndicesRefreshRequest) { + r.ExpandWildcards = v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f IndicesRefresh) WithIgnoreUnavailable(v bool) func(*IndicesRefreshRequest) { + return func(r *IndicesRefreshRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesRefresh) WithPretty() func(*IndicesRefreshRequest) { + return func(r *IndicesRefreshRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesRefresh) WithHuman() func(*IndicesRefreshRequest) { + return func(r *IndicesRefreshRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesRefresh) WithErrorTrace() func(*IndicesRefreshRequest) { + return func(r *IndicesRefreshRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesRefresh) WithFilterPath(v ...string) func(*IndicesRefreshRequest) { + return func(r *IndicesRefreshRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesRefresh) WithHeader(h map[string]string) func(*IndicesRefreshRequest) { + return func(r *IndicesRefreshRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesRefresh) WithOpaqueID(s string) func(*IndicesRefreshRequest) { + return func(r *IndicesRefreshRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.rollover.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.rollover.go new file mode 100644 index 00000000000..14b7f285ebb --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.rollover.go @@ -0,0 +1,285 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" + "time" +) + +func newIndicesRolloverFunc(t Transport) IndicesRollover { + return func(alias string, o ...func(*IndicesRolloverRequest)) (*Response, error) { + var r = IndicesRolloverRequest{Alias: alias} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesRollover updates an alias to point to a new index when the existing index +// is considered to be too large or too old. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-rollover-index.html. +// +type IndicesRollover func(alias string, o ...func(*IndicesRolloverRequest)) (*Response, error) + +// IndicesRolloverRequest configures the Indices Rollover API request. +// +type IndicesRolloverRequest struct { + Body io.Reader + + Alias string + NewIndex string + + DryRun *bool + IncludeTypeName *bool + MasterTimeout time.Duration + Timeout time.Duration + WaitForActiveShards string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesRolloverRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len(r.Alias) + 1 + len("_rollover") + 1 + len(r.NewIndex)) + path.WriteString("/") + path.WriteString(r.Alias) + path.WriteString("/") + path.WriteString("_rollover") + if r.NewIndex != "" { + path.WriteString("/") + path.WriteString(r.NewIndex) + } + + params = make(map[string]string) + + if r.DryRun != nil { + params["dry_run"] = strconv.FormatBool(*r.DryRun) + } + + if r.IncludeTypeName != nil { + params["include_type_name"] = strconv.FormatBool(*r.IncludeTypeName) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.WaitForActiveShards != "" { + params["wait_for_active_shards"] = r.WaitForActiveShards + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesRollover) WithContext(v context.Context) func(*IndicesRolloverRequest) { + return func(r *IndicesRolloverRequest) { + r.ctx = v + } +} + +// WithBody - The conditions that needs to be met for executing rollover. +// +func (f IndicesRollover) WithBody(v io.Reader) func(*IndicesRolloverRequest) { + return func(r *IndicesRolloverRequest) { + r.Body = v + } +} + +// WithNewIndex - the name of the rollover index. +// +func (f IndicesRollover) WithNewIndex(v string) func(*IndicesRolloverRequest) { + return func(r *IndicesRolloverRequest) { + r.NewIndex = v + } +} + +// WithDryRun - if set to true the rollover action will only be validated but not actually performed even if a condition matches. the default is false. +// +func (f IndicesRollover) WithDryRun(v bool) func(*IndicesRolloverRequest) { + return func(r *IndicesRolloverRequest) { + r.DryRun = &v + } +} + +// WithIncludeTypeName - whether a type should be included in the body of the mappings.. +// +func (f IndicesRollover) WithIncludeTypeName(v bool) func(*IndicesRolloverRequest) { + return func(r *IndicesRolloverRequest) { + r.IncludeTypeName = &v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f IndicesRollover) WithMasterTimeout(v time.Duration) func(*IndicesRolloverRequest) { + return func(r *IndicesRolloverRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f IndicesRollover) WithTimeout(v time.Duration) func(*IndicesRolloverRequest) { + return func(r *IndicesRolloverRequest) { + r.Timeout = v + } +} + +// WithWaitForActiveShards - set the number of active shards to wait for on the newly created rollover index before the operation returns.. +// +func (f IndicesRollover) WithWaitForActiveShards(v string) func(*IndicesRolloverRequest) { + return func(r *IndicesRolloverRequest) { + r.WaitForActiveShards = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesRollover) WithPretty() func(*IndicesRolloverRequest) { + return func(r *IndicesRolloverRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesRollover) WithHuman() func(*IndicesRolloverRequest) { + return func(r *IndicesRolloverRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesRollover) WithErrorTrace() func(*IndicesRolloverRequest) { + return func(r *IndicesRolloverRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesRollover) WithFilterPath(v ...string) func(*IndicesRolloverRequest) { + return func(r *IndicesRolloverRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesRollover) WithHeader(h map[string]string) func(*IndicesRolloverRequest) { + return func(r *IndicesRolloverRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesRollover) WithOpaqueID(s string) func(*IndicesRolloverRequest) { + return func(r *IndicesRolloverRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.segments.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.segments.go new file mode 100644 index 00000000000..6e96fce0606 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.segments.go @@ -0,0 +1,252 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newIndicesSegmentsFunc(t Transport) IndicesSegments { + return func(o ...func(*IndicesSegmentsRequest)) (*Response, error) { + var r = IndicesSegmentsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesSegments provides low-level information about segments in a Lucene index. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-segments.html. +// +type IndicesSegments func(o ...func(*IndicesSegmentsRequest)) (*Response, error) + +// IndicesSegmentsRequest configures the Indices Segments API request. +// +type IndicesSegmentsRequest struct { + Index []string + + AllowNoIndices *bool + ExpandWildcards string + IgnoreUnavailable *bool + Verbose *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesSegmentsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_segments")) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_segments") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.Verbose != nil { + params["verbose"] = strconv.FormatBool(*r.Verbose) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesSegments) WithContext(v context.Context) func(*IndicesSegmentsRequest) { + return func(r *IndicesSegmentsRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names; use _all to perform the operation on all indices. +// +func (f IndicesSegments) WithIndex(v ...string) func(*IndicesSegmentsRequest) { + return func(r *IndicesSegmentsRequest) { + r.Index = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f IndicesSegments) WithAllowNoIndices(v bool) func(*IndicesSegmentsRequest) { + return func(r *IndicesSegmentsRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f IndicesSegments) WithExpandWildcards(v string) func(*IndicesSegmentsRequest) { + return func(r *IndicesSegmentsRequest) { + r.ExpandWildcards = v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f IndicesSegments) WithIgnoreUnavailable(v bool) func(*IndicesSegmentsRequest) { + return func(r *IndicesSegmentsRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithVerbose - includes detailed memory usage by lucene.. +// +func (f IndicesSegments) WithVerbose(v bool) func(*IndicesSegmentsRequest) { + return func(r *IndicesSegmentsRequest) { + r.Verbose = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesSegments) WithPretty() func(*IndicesSegmentsRequest) { + return func(r *IndicesSegmentsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesSegments) WithHuman() func(*IndicesSegmentsRequest) { + return func(r *IndicesSegmentsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesSegments) WithErrorTrace() func(*IndicesSegmentsRequest) { + return func(r *IndicesSegmentsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesSegments) WithFilterPath(v ...string) func(*IndicesSegmentsRequest) { + return func(r *IndicesSegmentsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesSegments) WithHeader(h map[string]string) func(*IndicesSegmentsRequest) { + return func(r *IndicesSegmentsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesSegments) WithOpaqueID(s string) func(*IndicesSegmentsRequest) { + return func(r *IndicesSegmentsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.shard_stores.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.shard_stores.go new file mode 100644 index 00000000000..834f4eec66c --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.shard_stores.go @@ -0,0 +1,252 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newIndicesShardStoresFunc(t Transport) IndicesShardStores { + return func(o ...func(*IndicesShardStoresRequest)) (*Response, error) { + var r = IndicesShardStoresRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesShardStores provides store information for shard copies of indices. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-shards-stores.html. +// +type IndicesShardStores func(o ...func(*IndicesShardStoresRequest)) (*Response, error) + +// IndicesShardStoresRequest configures the Indices Shard Stores API request. +// +type IndicesShardStoresRequest struct { + Index []string + + AllowNoIndices *bool + ExpandWildcards string + IgnoreUnavailable *bool + Status []string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesShardStoresRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_shard_stores")) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_shard_stores") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if len(r.Status) > 0 { + params["status"] = strings.Join(r.Status, ",") + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesShardStores) WithContext(v context.Context) func(*IndicesShardStoresRequest) { + return func(r *IndicesShardStoresRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names; use _all to perform the operation on all indices. +// +func (f IndicesShardStores) WithIndex(v ...string) func(*IndicesShardStoresRequest) { + return func(r *IndicesShardStoresRequest) { + r.Index = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f IndicesShardStores) WithAllowNoIndices(v bool) func(*IndicesShardStoresRequest) { + return func(r *IndicesShardStoresRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f IndicesShardStores) WithExpandWildcards(v string) func(*IndicesShardStoresRequest) { + return func(r *IndicesShardStoresRequest) { + r.ExpandWildcards = v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f IndicesShardStores) WithIgnoreUnavailable(v bool) func(*IndicesShardStoresRequest) { + return func(r *IndicesShardStoresRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithStatus - a list of statuses used to filter on shards to get store information for. +// +func (f IndicesShardStores) WithStatus(v ...string) func(*IndicesShardStoresRequest) { + return func(r *IndicesShardStoresRequest) { + r.Status = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesShardStores) WithPretty() func(*IndicesShardStoresRequest) { + return func(r *IndicesShardStoresRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesShardStores) WithHuman() func(*IndicesShardStoresRequest) { + return func(r *IndicesShardStoresRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesShardStores) WithErrorTrace() func(*IndicesShardStoresRequest) { + return func(r *IndicesShardStoresRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesShardStores) WithFilterPath(v ...string) func(*IndicesShardStoresRequest) { + return func(r *IndicesShardStoresRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesShardStores) WithHeader(h map[string]string) func(*IndicesShardStoresRequest) { + return func(r *IndicesShardStoresRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesShardStores) WithOpaqueID(s string) func(*IndicesShardStoresRequest) { + return func(r *IndicesShardStoresRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.shrink.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.shrink.go new file mode 100644 index 00000000000..733dc535c8d --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.shrink.go @@ -0,0 +1,248 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" + "time" +) + +func newIndicesShrinkFunc(t Transport) IndicesShrink { + return func(index string, target string, o ...func(*IndicesShrinkRequest)) (*Response, error) { + var r = IndicesShrinkRequest{Index: index, Target: target} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesShrink allow to shrink an existing index into a new index with fewer primary shards. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-shrink-index.html. +// +type IndicesShrink func(index string, target string, o ...func(*IndicesShrinkRequest)) (*Response, error) + +// IndicesShrinkRequest configures the Indices Shrink API request. +// +type IndicesShrinkRequest struct { + Index string + + Body io.Reader + + Target string + + MasterTimeout time.Duration + Timeout time.Duration + WaitForActiveShards string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesShrinkRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len(r.Index) + 1 + len("_shrink") + 1 + len(r.Target)) + path.WriteString("/") + path.WriteString(r.Index) + path.WriteString("/") + path.WriteString("_shrink") + path.WriteString("/") + path.WriteString(r.Target) + + params = make(map[string]string) + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.WaitForActiveShards != "" { + params["wait_for_active_shards"] = r.WaitForActiveShards + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesShrink) WithContext(v context.Context) func(*IndicesShrinkRequest) { + return func(r *IndicesShrinkRequest) { + r.ctx = v + } +} + +// WithBody - The configuration for the target index (`settings` and `aliases`). +// +func (f IndicesShrink) WithBody(v io.Reader) func(*IndicesShrinkRequest) { + return func(r *IndicesShrinkRequest) { + r.Body = v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f IndicesShrink) WithMasterTimeout(v time.Duration) func(*IndicesShrinkRequest) { + return func(r *IndicesShrinkRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f IndicesShrink) WithTimeout(v time.Duration) func(*IndicesShrinkRequest) { + return func(r *IndicesShrinkRequest) { + r.Timeout = v + } +} + +// WithWaitForActiveShards - set the number of active shards to wait for on the shrunken index before the operation returns.. +// +func (f IndicesShrink) WithWaitForActiveShards(v string) func(*IndicesShrinkRequest) { + return func(r *IndicesShrinkRequest) { + r.WaitForActiveShards = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesShrink) WithPretty() func(*IndicesShrinkRequest) { + return func(r *IndicesShrinkRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesShrink) WithHuman() func(*IndicesShrinkRequest) { + return func(r *IndicesShrinkRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesShrink) WithErrorTrace() func(*IndicesShrinkRequest) { + return func(r *IndicesShrinkRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesShrink) WithFilterPath(v ...string) func(*IndicesShrinkRequest) { + return func(r *IndicesShrinkRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesShrink) WithHeader(h map[string]string) func(*IndicesShrinkRequest) { + return func(r *IndicesShrinkRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesShrink) WithOpaqueID(s string) func(*IndicesShrinkRequest) { + return func(r *IndicesShrinkRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.split.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.split.go new file mode 100644 index 00000000000..dbbb46b46a8 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.split.go @@ -0,0 +1,248 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" + "time" +) + +func newIndicesSplitFunc(t Transport) IndicesSplit { + return func(index string, target string, o ...func(*IndicesSplitRequest)) (*Response, error) { + var r = IndicesSplitRequest{Index: index, Target: target} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesSplit allows you to split an existing index into a new index with more primary shards. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-split-index.html. +// +type IndicesSplit func(index string, target string, o ...func(*IndicesSplitRequest)) (*Response, error) + +// IndicesSplitRequest configures the Indices Split API request. +// +type IndicesSplitRequest struct { + Index string + + Body io.Reader + + Target string + + MasterTimeout time.Duration + Timeout time.Duration + WaitForActiveShards string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesSplitRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len(r.Index) + 1 + len("_split") + 1 + len(r.Target)) + path.WriteString("/") + path.WriteString(r.Index) + path.WriteString("/") + path.WriteString("_split") + path.WriteString("/") + path.WriteString(r.Target) + + params = make(map[string]string) + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.WaitForActiveShards != "" { + params["wait_for_active_shards"] = r.WaitForActiveShards + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesSplit) WithContext(v context.Context) func(*IndicesSplitRequest) { + return func(r *IndicesSplitRequest) { + r.ctx = v + } +} + +// WithBody - The configuration for the target index (`settings` and `aliases`). +// +func (f IndicesSplit) WithBody(v io.Reader) func(*IndicesSplitRequest) { + return func(r *IndicesSplitRequest) { + r.Body = v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f IndicesSplit) WithMasterTimeout(v time.Duration) func(*IndicesSplitRequest) { + return func(r *IndicesSplitRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f IndicesSplit) WithTimeout(v time.Duration) func(*IndicesSplitRequest) { + return func(r *IndicesSplitRequest) { + r.Timeout = v + } +} + +// WithWaitForActiveShards - set the number of active shards to wait for on the shrunken index before the operation returns.. +// +func (f IndicesSplit) WithWaitForActiveShards(v string) func(*IndicesSplitRequest) { + return func(r *IndicesSplitRequest) { + r.WaitForActiveShards = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesSplit) WithPretty() func(*IndicesSplitRequest) { + return func(r *IndicesSplitRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesSplit) WithHuman() func(*IndicesSplitRequest) { + return func(r *IndicesSplitRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesSplit) WithErrorTrace() func(*IndicesSplitRequest) { + return func(r *IndicesSplitRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesSplit) WithFilterPath(v ...string) func(*IndicesSplitRequest) { + return func(r *IndicesSplitRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesSplit) WithHeader(h map[string]string) func(*IndicesSplitRequest) { + return func(r *IndicesSplitRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesSplit) WithOpaqueID(s string) func(*IndicesSplitRequest) { + return func(r *IndicesSplitRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.stats.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.stats.go new file mode 100644 index 00000000000..9ca2bb904fb --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.stats.go @@ -0,0 +1,344 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newIndicesStatsFunc(t Transport) IndicesStats { + return func(o ...func(*IndicesStatsRequest)) (*Response, error) { + var r = IndicesStatsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesStats provides statistics on operations happening in an index. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-stats.html. +// +type IndicesStats func(o ...func(*IndicesStatsRequest)) (*Response, error) + +// IndicesStatsRequest configures the Indices Stats API request. +// +type IndicesStatsRequest struct { + Index []string + + Metric []string + + CompletionFields []string + ExpandWildcards string + FielddataFields []string + Fields []string + ForbidClosedIndices *bool + Groups []string + IncludeSegmentFileSizes *bool + IncludeUnloadedSegments *bool + Level string + Types []string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesStatsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_stats") + 1 + len(strings.Join(r.Metric, ","))) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_stats") + if len(r.Metric) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Metric, ",")) + } + + params = make(map[string]string) + + if len(r.CompletionFields) > 0 { + params["completion_fields"] = strings.Join(r.CompletionFields, ",") + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if len(r.FielddataFields) > 0 { + params["fielddata_fields"] = strings.Join(r.FielddataFields, ",") + } + + if len(r.Fields) > 0 { + params["fields"] = strings.Join(r.Fields, ",") + } + + if r.ForbidClosedIndices != nil { + params["forbid_closed_indices"] = strconv.FormatBool(*r.ForbidClosedIndices) + } + + if len(r.Groups) > 0 { + params["groups"] = strings.Join(r.Groups, ",") + } + + if r.IncludeSegmentFileSizes != nil { + params["include_segment_file_sizes"] = strconv.FormatBool(*r.IncludeSegmentFileSizes) + } + + if r.IncludeUnloadedSegments != nil { + params["include_unloaded_segments"] = strconv.FormatBool(*r.IncludeUnloadedSegments) + } + + if r.Level != "" { + params["level"] = r.Level + } + + if len(r.Types) > 0 { + params["types"] = strings.Join(r.Types, ",") + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesStats) WithContext(v context.Context) func(*IndicesStatsRequest) { + return func(r *IndicesStatsRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names; use _all to perform the operation on all indices. +// +func (f IndicesStats) WithIndex(v ...string) func(*IndicesStatsRequest) { + return func(r *IndicesStatsRequest) { + r.Index = v + } +} + +// WithMetric - limit the information returned the specific metrics.. +// +func (f IndicesStats) WithMetric(v ...string) func(*IndicesStatsRequest) { + return func(r *IndicesStatsRequest) { + r.Metric = v + } +} + +// WithCompletionFields - a list of fields for `fielddata` and `suggest` index metric (supports wildcards). +// +func (f IndicesStats) WithCompletionFields(v ...string) func(*IndicesStatsRequest) { + return func(r *IndicesStatsRequest) { + r.CompletionFields = v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f IndicesStats) WithExpandWildcards(v string) func(*IndicesStatsRequest) { + return func(r *IndicesStatsRequest) { + r.ExpandWildcards = v + } +} + +// WithFielddataFields - a list of fields for `fielddata` index metric (supports wildcards). +// +func (f IndicesStats) WithFielddataFields(v ...string) func(*IndicesStatsRequest) { + return func(r *IndicesStatsRequest) { + r.FielddataFields = v + } +} + +// WithFields - a list of fields for `fielddata` and `completion` index metric (supports wildcards). +// +func (f IndicesStats) WithFields(v ...string) func(*IndicesStatsRequest) { + return func(r *IndicesStatsRequest) { + r.Fields = v + } +} + +// WithForbidClosedIndices - if set to false stats will also collected from closed indices if explicitly specified or if expand_wildcards expands to closed indices. +// +func (f IndicesStats) WithForbidClosedIndices(v bool) func(*IndicesStatsRequest) { + return func(r *IndicesStatsRequest) { + r.ForbidClosedIndices = &v + } +} + +// WithGroups - a list of search groups for `search` index metric. +// +func (f IndicesStats) WithGroups(v ...string) func(*IndicesStatsRequest) { + return func(r *IndicesStatsRequest) { + r.Groups = v + } +} + +// WithIncludeSegmentFileSizes - whether to report the aggregated disk usage of each one of the lucene index files (only applies if segment stats are requested). +// +func (f IndicesStats) WithIncludeSegmentFileSizes(v bool) func(*IndicesStatsRequest) { + return func(r *IndicesStatsRequest) { + r.IncludeSegmentFileSizes = &v + } +} + +// WithIncludeUnloadedSegments - if set to true segment stats will include stats for segments that are not currently loaded into memory. +// +func (f IndicesStats) WithIncludeUnloadedSegments(v bool) func(*IndicesStatsRequest) { + return func(r *IndicesStatsRequest) { + r.IncludeUnloadedSegments = &v + } +} + +// WithLevel - return stats aggregated at cluster, index or shard level. +// +func (f IndicesStats) WithLevel(v string) func(*IndicesStatsRequest) { + return func(r *IndicesStatsRequest) { + r.Level = v + } +} + +// WithTypes - a list of document types for the `indexing` index metric. +// +func (f IndicesStats) WithTypes(v ...string) func(*IndicesStatsRequest) { + return func(r *IndicesStatsRequest) { + r.Types = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesStats) WithPretty() func(*IndicesStatsRequest) { + return func(r *IndicesStatsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesStats) WithHuman() func(*IndicesStatsRequest) { + return func(r *IndicesStatsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesStats) WithErrorTrace() func(*IndicesStatsRequest) { + return func(r *IndicesStatsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesStats) WithFilterPath(v ...string) func(*IndicesStatsRequest) { + return func(r *IndicesStatsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesStats) WithHeader(h map[string]string) func(*IndicesStatsRequest) { + return func(r *IndicesStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesStats) WithOpaqueID(s string) func(*IndicesStatsRequest) { + return func(r *IndicesStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.update_aliases.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.update_aliases.go new file mode 100644 index 00000000000..75612d95735 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.update_aliases.go @@ -0,0 +1,218 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" + "time" +) + +func newIndicesUpdateAliasesFunc(t Transport) IndicesUpdateAliases { + return func(body io.Reader, o ...func(*IndicesUpdateAliasesRequest)) (*Response, error) { + var r = IndicesUpdateAliasesRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesUpdateAliases updates index aliases. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html. +// +type IndicesUpdateAliases func(body io.Reader, o ...func(*IndicesUpdateAliasesRequest)) (*Response, error) + +// IndicesUpdateAliasesRequest configures the Indices Update Aliases API request. +// +type IndicesUpdateAliasesRequest struct { + Body io.Reader + + MasterTimeout time.Duration + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesUpdateAliasesRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(len("/_aliases")) + path.WriteString("/_aliases") + + params = make(map[string]string) + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesUpdateAliases) WithContext(v context.Context) func(*IndicesUpdateAliasesRequest) { + return func(r *IndicesUpdateAliasesRequest) { + r.ctx = v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f IndicesUpdateAliases) WithMasterTimeout(v time.Duration) func(*IndicesUpdateAliasesRequest) { + return func(r *IndicesUpdateAliasesRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - request timeout. +// +func (f IndicesUpdateAliases) WithTimeout(v time.Duration) func(*IndicesUpdateAliasesRequest) { + return func(r *IndicesUpdateAliasesRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesUpdateAliases) WithPretty() func(*IndicesUpdateAliasesRequest) { + return func(r *IndicesUpdateAliasesRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesUpdateAliases) WithHuman() func(*IndicesUpdateAliasesRequest) { + return func(r *IndicesUpdateAliasesRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesUpdateAliases) WithErrorTrace() func(*IndicesUpdateAliasesRequest) { + return func(r *IndicesUpdateAliasesRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesUpdateAliases) WithFilterPath(v ...string) func(*IndicesUpdateAliasesRequest) { + return func(r *IndicesUpdateAliasesRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesUpdateAliases) WithHeader(h map[string]string) func(*IndicesUpdateAliasesRequest) { + return func(r *IndicesUpdateAliasesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesUpdateAliases) WithOpaqueID(s string) func(*IndicesUpdateAliasesRequest) { + return func(r *IndicesUpdateAliasesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.upgrade.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.upgrade.go new file mode 100644 index 00000000000..950e100ab5f --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.upgrade.go @@ -0,0 +1,265 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newIndicesUpgradeFunc(t Transport) IndicesUpgrade { + return func(o ...func(*IndicesUpgradeRequest)) (*Response, error) { + var r = IndicesUpgradeRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesUpgrade the _upgrade API is no longer useful and will be removed. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-upgrade.html. +// +type IndicesUpgrade func(o ...func(*IndicesUpgradeRequest)) (*Response, error) + +// IndicesUpgradeRequest configures the Indices Upgrade API request. +// +type IndicesUpgradeRequest struct { + Index []string + + AllowNoIndices *bool + ExpandWildcards string + IgnoreUnavailable *bool + OnlyAncientSegments *bool + WaitForCompletion *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesUpgradeRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_upgrade")) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_upgrade") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.OnlyAncientSegments != nil { + params["only_ancient_segments"] = strconv.FormatBool(*r.OnlyAncientSegments) + } + + if r.WaitForCompletion != nil { + params["wait_for_completion"] = strconv.FormatBool(*r.WaitForCompletion) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesUpgrade) WithContext(v context.Context) func(*IndicesUpgradeRequest) { + return func(r *IndicesUpgradeRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names; use _all to perform the operation on all indices. +// +func (f IndicesUpgrade) WithIndex(v ...string) func(*IndicesUpgradeRequest) { + return func(r *IndicesUpgradeRequest) { + r.Index = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f IndicesUpgrade) WithAllowNoIndices(v bool) func(*IndicesUpgradeRequest) { + return func(r *IndicesUpgradeRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f IndicesUpgrade) WithExpandWildcards(v string) func(*IndicesUpgradeRequest) { + return func(r *IndicesUpgradeRequest) { + r.ExpandWildcards = v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f IndicesUpgrade) WithIgnoreUnavailable(v bool) func(*IndicesUpgradeRequest) { + return func(r *IndicesUpgradeRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithOnlyAncientSegments - if true, only ancient (an older lucene major release) segments will be upgraded. +// +func (f IndicesUpgrade) WithOnlyAncientSegments(v bool) func(*IndicesUpgradeRequest) { + return func(r *IndicesUpgradeRequest) { + r.OnlyAncientSegments = &v + } +} + +// WithWaitForCompletion - specify whether the request should block until the all segments are upgraded (default: false). +// +func (f IndicesUpgrade) WithWaitForCompletion(v bool) func(*IndicesUpgradeRequest) { + return func(r *IndicesUpgradeRequest) { + r.WaitForCompletion = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesUpgrade) WithPretty() func(*IndicesUpgradeRequest) { + return func(r *IndicesUpgradeRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesUpgrade) WithHuman() func(*IndicesUpgradeRequest) { + return func(r *IndicesUpgradeRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesUpgrade) WithErrorTrace() func(*IndicesUpgradeRequest) { + return func(r *IndicesUpgradeRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesUpgrade) WithFilterPath(v ...string) func(*IndicesUpgradeRequest) { + return func(r *IndicesUpgradeRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesUpgrade) WithHeader(h map[string]string) func(*IndicesUpgradeRequest) { + return func(r *IndicesUpgradeRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesUpgrade) WithOpaqueID(s string) func(*IndicesUpgradeRequest) { + return func(r *IndicesUpgradeRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.validate_query.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.validate_query.go new file mode 100644 index 00000000000..543f6bf0a14 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.indices.validate_query.go @@ -0,0 +1,386 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newIndicesValidateQueryFunc(t Transport) IndicesValidateQuery { + return func(o ...func(*IndicesValidateQueryRequest)) (*Response, error) { + var r = IndicesValidateQueryRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesValidateQuery allows a user to validate a potentially expensive query without executing it. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/search-validate.html. +// +type IndicesValidateQuery func(o ...func(*IndicesValidateQueryRequest)) (*Response, error) + +// IndicesValidateQueryRequest configures the Indices Validate Query API request. +// +type IndicesValidateQueryRequest struct { + Index []string + DocumentType []string + + Body io.Reader + + AllowNoIndices *bool + AllShards *bool + Analyzer string + AnalyzeWildcard *bool + DefaultOperator string + Df string + ExpandWildcards string + Explain *bool + IgnoreUnavailable *bool + Lenient *bool + Query string + Rewrite *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesValidateQueryRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len(strings.Join(r.DocumentType, ",")) + 1 + len("_validate") + 1 + len("query")) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + if len(r.DocumentType) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.DocumentType, ",")) + } + path.WriteString("/") + path.WriteString("_validate") + path.WriteString("/") + path.WriteString("query") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.AllShards != nil { + params["all_shards"] = strconv.FormatBool(*r.AllShards) + } + + if r.Analyzer != "" { + params["analyzer"] = r.Analyzer + } + + if r.AnalyzeWildcard != nil { + params["analyze_wildcard"] = strconv.FormatBool(*r.AnalyzeWildcard) + } + + if r.DefaultOperator != "" { + params["default_operator"] = r.DefaultOperator + } + + if r.Df != "" { + params["df"] = r.Df + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.Explain != nil { + params["explain"] = strconv.FormatBool(*r.Explain) + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.Lenient != nil { + params["lenient"] = strconv.FormatBool(*r.Lenient) + } + + if r.Query != "" { + params["q"] = r.Query + } + + if r.Rewrite != nil { + params["rewrite"] = strconv.FormatBool(*r.Rewrite) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesValidateQuery) WithContext(v context.Context) func(*IndicesValidateQueryRequest) { + return func(r *IndicesValidateQueryRequest) { + r.ctx = v + } +} + +// WithBody - The query definition specified with the Query DSL. +// +func (f IndicesValidateQuery) WithBody(v io.Reader) func(*IndicesValidateQueryRequest) { + return func(r *IndicesValidateQueryRequest) { + r.Body = v + } +} + +// WithIndex - a list of index names to restrict the operation; use _all to perform the operation on all indices. +// +func (f IndicesValidateQuery) WithIndex(v ...string) func(*IndicesValidateQueryRequest) { + return func(r *IndicesValidateQueryRequest) { + r.Index = v + } +} + +// WithDocumentType - a list of document types to restrict the operation; leave empty to perform the operation on all types. +// +func (f IndicesValidateQuery) WithDocumentType(v ...string) func(*IndicesValidateQueryRequest) { + return func(r *IndicesValidateQueryRequest) { + r.DocumentType = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f IndicesValidateQuery) WithAllowNoIndices(v bool) func(*IndicesValidateQueryRequest) { + return func(r *IndicesValidateQueryRequest) { + r.AllowNoIndices = &v + } +} + +// WithAllShards - execute validation on all shards instead of one random shard per index. +// +func (f IndicesValidateQuery) WithAllShards(v bool) func(*IndicesValidateQueryRequest) { + return func(r *IndicesValidateQueryRequest) { + r.AllShards = &v + } +} + +// WithAnalyzer - the analyzer to use for the query string. +// +func (f IndicesValidateQuery) WithAnalyzer(v string) func(*IndicesValidateQueryRequest) { + return func(r *IndicesValidateQueryRequest) { + r.Analyzer = v + } +} + +// WithAnalyzeWildcard - specify whether wildcard and prefix queries should be analyzed (default: false). +// +func (f IndicesValidateQuery) WithAnalyzeWildcard(v bool) func(*IndicesValidateQueryRequest) { + return func(r *IndicesValidateQueryRequest) { + r.AnalyzeWildcard = &v + } +} + +// WithDefaultOperator - the default operator for query string query (and or or). +// +func (f IndicesValidateQuery) WithDefaultOperator(v string) func(*IndicesValidateQueryRequest) { + return func(r *IndicesValidateQueryRequest) { + r.DefaultOperator = v + } +} + +// WithDf - the field to use as default where no field prefix is given in the query string. +// +func (f IndicesValidateQuery) WithDf(v string) func(*IndicesValidateQueryRequest) { + return func(r *IndicesValidateQueryRequest) { + r.Df = v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f IndicesValidateQuery) WithExpandWildcards(v string) func(*IndicesValidateQueryRequest) { + return func(r *IndicesValidateQueryRequest) { + r.ExpandWildcards = v + } +} + +// WithExplain - return detailed information about the error. +// +func (f IndicesValidateQuery) WithExplain(v bool) func(*IndicesValidateQueryRequest) { + return func(r *IndicesValidateQueryRequest) { + r.Explain = &v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f IndicesValidateQuery) WithIgnoreUnavailable(v bool) func(*IndicesValidateQueryRequest) { + return func(r *IndicesValidateQueryRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithLenient - specify whether format-based query failures (such as providing text to a numeric field) should be ignored. +// +func (f IndicesValidateQuery) WithLenient(v bool) func(*IndicesValidateQueryRequest) { + return func(r *IndicesValidateQueryRequest) { + r.Lenient = &v + } +} + +// WithQuery - query in the lucene query string syntax. +// +func (f IndicesValidateQuery) WithQuery(v string) func(*IndicesValidateQueryRequest) { + return func(r *IndicesValidateQueryRequest) { + r.Query = v + } +} + +// WithRewrite - provide a more detailed explanation showing the actual lucene query that will be executed.. +// +func (f IndicesValidateQuery) WithRewrite(v bool) func(*IndicesValidateQueryRequest) { + return func(r *IndicesValidateQueryRequest) { + r.Rewrite = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesValidateQuery) WithPretty() func(*IndicesValidateQueryRequest) { + return func(r *IndicesValidateQueryRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesValidateQuery) WithHuman() func(*IndicesValidateQueryRequest) { + return func(r *IndicesValidateQueryRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesValidateQuery) WithErrorTrace() func(*IndicesValidateQueryRequest) { + return func(r *IndicesValidateQueryRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesValidateQuery) WithFilterPath(v ...string) func(*IndicesValidateQueryRequest) { + return func(r *IndicesValidateQueryRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesValidateQuery) WithHeader(h map[string]string) func(*IndicesValidateQueryRequest) { + return func(r *IndicesValidateQueryRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesValidateQuery) WithOpaqueID(s string) func(*IndicesValidateQueryRequest) { + return func(r *IndicesValidateQueryRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.info.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.info.go new file mode 100644 index 00000000000..5bfb61c2257 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.info.go @@ -0,0 +1,175 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newInfoFunc(t Transport) Info { + return func(o ...func(*InfoRequest)) (*Response, error) { + var r = InfoRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// Info returns basic information about the cluster. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html. +// +type Info func(o ...func(*InfoRequest)) (*Response, error) + +// InfoRequest configures the Info API request. +// +type InfoRequest struct { + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r InfoRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/")) + path.WriteString("/") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f Info) WithContext(v context.Context) func(*InfoRequest) { + return func(r *InfoRequest) { + r.ctx = v + } +} + +// WithHuman makes statistical values human-readable. +// +func (f Info) WithHuman() func(*InfoRequest) { + return func(r *InfoRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f Info) WithErrorTrace() func(*InfoRequest) { + return func(r *InfoRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f Info) WithFilterPath(v ...string) func(*InfoRequest) { + return func(r *InfoRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f Info) WithHeader(h map[string]string) func(*InfoRequest) { + return func(r *InfoRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f Info) WithOpaqueID(s string) func(*InfoRequest) { + return func(r *InfoRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.ingest.delete_pipeline.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.ingest.delete_pipeline.go new file mode 100644 index 00000000000..cdc7d25bc74 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.ingest.delete_pipeline.go @@ -0,0 +1,218 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" + "time" +) + +func newIngestDeletePipelineFunc(t Transport) IngestDeletePipeline { + return func(id string, o ...func(*IngestDeletePipelineRequest)) (*Response, error) { + var r = IngestDeletePipelineRequest{PipelineID: id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IngestDeletePipeline deletes a pipeline. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/delete-pipeline-api.html. +// +type IngestDeletePipeline func(id string, o ...func(*IngestDeletePipelineRequest)) (*Response, error) + +// IngestDeletePipelineRequest configures the Ingest Delete Pipeline API request. +// +type IngestDeletePipelineRequest struct { + PipelineID string + + MasterTimeout time.Duration + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IngestDeletePipelineRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_ingest") + 1 + len("pipeline") + 1 + len(r.PipelineID)) + path.WriteString("/") + path.WriteString("_ingest") + path.WriteString("/") + path.WriteString("pipeline") + path.WriteString("/") + path.WriteString(r.PipelineID) + + params = make(map[string]string) + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IngestDeletePipeline) WithContext(v context.Context) func(*IngestDeletePipelineRequest) { + return func(r *IngestDeletePipelineRequest) { + r.ctx = v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f IngestDeletePipeline) WithMasterTimeout(v time.Duration) func(*IngestDeletePipelineRequest) { + return func(r *IngestDeletePipelineRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f IngestDeletePipeline) WithTimeout(v time.Duration) func(*IngestDeletePipelineRequest) { + return func(r *IngestDeletePipelineRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IngestDeletePipeline) WithPretty() func(*IngestDeletePipelineRequest) { + return func(r *IngestDeletePipelineRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IngestDeletePipeline) WithHuman() func(*IngestDeletePipelineRequest) { + return func(r *IngestDeletePipelineRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IngestDeletePipeline) WithErrorTrace() func(*IngestDeletePipelineRequest) { + return func(r *IngestDeletePipelineRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IngestDeletePipeline) WithFilterPath(v ...string) func(*IngestDeletePipelineRequest) { + return func(r *IngestDeletePipelineRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IngestDeletePipeline) WithHeader(h map[string]string) func(*IngestDeletePipelineRequest) { + return func(r *IngestDeletePipelineRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IngestDeletePipeline) WithOpaqueID(s string) func(*IngestDeletePipelineRequest) { + return func(r *IngestDeletePipelineRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.ingest.get_pipeline.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.ingest.get_pipeline.go new file mode 100644 index 00000000000..b65a867ba23 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.ingest.get_pipeline.go @@ -0,0 +1,215 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" + "time" +) + +func newIngestGetPipelineFunc(t Transport) IngestGetPipeline { + return func(o ...func(*IngestGetPipelineRequest)) (*Response, error) { + var r = IngestGetPipelineRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IngestGetPipeline returns a pipeline. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/get-pipeline-api.html. +// +type IngestGetPipeline func(o ...func(*IngestGetPipelineRequest)) (*Response, error) + +// IngestGetPipelineRequest configures the Ingest Get Pipeline API request. +// +type IngestGetPipelineRequest struct { + PipelineID string + + MasterTimeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IngestGetPipelineRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_ingest") + 1 + len("pipeline") + 1 + len(r.PipelineID)) + path.WriteString("/") + path.WriteString("_ingest") + path.WriteString("/") + path.WriteString("pipeline") + if r.PipelineID != "" { + path.WriteString("/") + path.WriteString(r.PipelineID) + } + + params = make(map[string]string) + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IngestGetPipeline) WithContext(v context.Context) func(*IngestGetPipelineRequest) { + return func(r *IngestGetPipelineRequest) { + r.ctx = v + } +} + +// WithPipelineID - comma separated list of pipeline ids. wildcards supported. +// +func (f IngestGetPipeline) WithPipelineID(v string) func(*IngestGetPipelineRequest) { + return func(r *IngestGetPipelineRequest) { + r.PipelineID = v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f IngestGetPipeline) WithMasterTimeout(v time.Duration) func(*IngestGetPipelineRequest) { + return func(r *IngestGetPipelineRequest) { + r.MasterTimeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IngestGetPipeline) WithPretty() func(*IngestGetPipelineRequest) { + return func(r *IngestGetPipelineRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IngestGetPipeline) WithHuman() func(*IngestGetPipelineRequest) { + return func(r *IngestGetPipelineRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IngestGetPipeline) WithErrorTrace() func(*IngestGetPipelineRequest) { + return func(r *IngestGetPipelineRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IngestGetPipeline) WithFilterPath(v ...string) func(*IngestGetPipelineRequest) { + return func(r *IngestGetPipelineRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IngestGetPipeline) WithHeader(h map[string]string) func(*IngestGetPipelineRequest) { + return func(r *IngestGetPipelineRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IngestGetPipeline) WithOpaqueID(s string) func(*IngestGetPipelineRequest) { + return func(r *IngestGetPipelineRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.ingest.processor_grok.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.ingest.processor_grok.go new file mode 100644 index 00000000000..a5d325af19a --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.ingest.processor_grok.go @@ -0,0 +1,183 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newIngestProcessorGrokFunc(t Transport) IngestProcessorGrok { + return func(o ...func(*IngestProcessorGrokRequest)) (*Response, error) { + var r = IngestProcessorGrokRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IngestProcessorGrok returns a list of the built-in patterns. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/grok-processor.html#grok-processor-rest-get. +// +type IngestProcessorGrok func(o ...func(*IngestProcessorGrokRequest)) (*Response, error) + +// IngestProcessorGrokRequest configures the Ingest Processor Grok API request. +// +type IngestProcessorGrokRequest struct { + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IngestProcessorGrokRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_ingest/processor/grok")) + path.WriteString("/_ingest/processor/grok") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IngestProcessorGrok) WithContext(v context.Context) func(*IngestProcessorGrokRequest) { + return func(r *IngestProcessorGrokRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IngestProcessorGrok) WithPretty() func(*IngestProcessorGrokRequest) { + return func(r *IngestProcessorGrokRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IngestProcessorGrok) WithHuman() func(*IngestProcessorGrokRequest) { + return func(r *IngestProcessorGrokRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IngestProcessorGrok) WithErrorTrace() func(*IngestProcessorGrokRequest) { + return func(r *IngestProcessorGrokRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IngestProcessorGrok) WithFilterPath(v ...string) func(*IngestProcessorGrokRequest) { + return func(r *IngestProcessorGrokRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IngestProcessorGrok) WithHeader(h map[string]string) func(*IngestProcessorGrokRequest) { + return func(r *IngestProcessorGrokRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IngestProcessorGrok) WithOpaqueID(s string) func(*IngestProcessorGrokRequest) { + return func(r *IngestProcessorGrokRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.ingest.put_pipeline.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.ingest.put_pipeline.go new file mode 100644 index 00000000000..175af3e73cd --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.ingest.put_pipeline.go @@ -0,0 +1,225 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" + "time" +) + +func newIngestPutPipelineFunc(t Transport) IngestPutPipeline { + return func(id string, body io.Reader, o ...func(*IngestPutPipelineRequest)) (*Response, error) { + var r = IngestPutPipelineRequest{PipelineID: id, Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IngestPutPipeline creates or updates a pipeline. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/put-pipeline-api.html. +// +type IngestPutPipeline func(id string, body io.Reader, o ...func(*IngestPutPipelineRequest)) (*Response, error) + +// IngestPutPipelineRequest configures the Ingest Put Pipeline API request. +// +type IngestPutPipelineRequest struct { + PipelineID string + + Body io.Reader + + MasterTimeout time.Duration + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IngestPutPipelineRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_ingest") + 1 + len("pipeline") + 1 + len(r.PipelineID)) + path.WriteString("/") + path.WriteString("_ingest") + path.WriteString("/") + path.WriteString("pipeline") + path.WriteString("/") + path.WriteString(r.PipelineID) + + params = make(map[string]string) + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IngestPutPipeline) WithContext(v context.Context) func(*IngestPutPipelineRequest) { + return func(r *IngestPutPipelineRequest) { + r.ctx = v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f IngestPutPipeline) WithMasterTimeout(v time.Duration) func(*IngestPutPipelineRequest) { + return func(r *IngestPutPipelineRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f IngestPutPipeline) WithTimeout(v time.Duration) func(*IngestPutPipelineRequest) { + return func(r *IngestPutPipelineRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IngestPutPipeline) WithPretty() func(*IngestPutPipelineRequest) { + return func(r *IngestPutPipelineRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IngestPutPipeline) WithHuman() func(*IngestPutPipelineRequest) { + return func(r *IngestPutPipelineRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IngestPutPipeline) WithErrorTrace() func(*IngestPutPipelineRequest) { + return func(r *IngestPutPipelineRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IngestPutPipeline) WithFilterPath(v ...string) func(*IngestPutPipelineRequest) { + return func(r *IngestPutPipelineRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IngestPutPipeline) WithHeader(h map[string]string) func(*IngestPutPipelineRequest) { + return func(r *IngestPutPipelineRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IngestPutPipeline) WithOpaqueID(s string) func(*IngestPutPipelineRequest) { + return func(r *IngestPutPipelineRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.ingest.simulate.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.ingest.simulate.go new file mode 100644 index 00000000000..02bae0591fd --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.ingest.simulate.go @@ -0,0 +1,224 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newIngestSimulateFunc(t Transport) IngestSimulate { + return func(body io.Reader, o ...func(*IngestSimulateRequest)) (*Response, error) { + var r = IngestSimulateRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IngestSimulate allows to simulate a pipeline with example documents. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/simulate-pipeline-api.html. +// +type IngestSimulate func(body io.Reader, o ...func(*IngestSimulateRequest)) (*Response, error) + +// IngestSimulateRequest configures the Ingest Simulate API request. +// +type IngestSimulateRequest struct { + PipelineID string + + Body io.Reader + + Verbose *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IngestSimulateRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_ingest") + 1 + len("pipeline") + 1 + len(r.PipelineID) + 1 + len("_simulate")) + path.WriteString("/") + path.WriteString("_ingest") + path.WriteString("/") + path.WriteString("pipeline") + if r.PipelineID != "" { + path.WriteString("/") + path.WriteString(r.PipelineID) + } + path.WriteString("/") + path.WriteString("_simulate") + + params = make(map[string]string) + + if r.Verbose != nil { + params["verbose"] = strconv.FormatBool(*r.Verbose) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IngestSimulate) WithContext(v context.Context) func(*IngestSimulateRequest) { + return func(r *IngestSimulateRequest) { + r.ctx = v + } +} + +// WithPipelineID - pipeline ID. +// +func (f IngestSimulate) WithPipelineID(v string) func(*IngestSimulateRequest) { + return func(r *IngestSimulateRequest) { + r.PipelineID = v + } +} + +// WithVerbose - verbose mode. display data output for each processor in executed pipeline. +// +func (f IngestSimulate) WithVerbose(v bool) func(*IngestSimulateRequest) { + return func(r *IngestSimulateRequest) { + r.Verbose = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IngestSimulate) WithPretty() func(*IngestSimulateRequest) { + return func(r *IngestSimulateRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IngestSimulate) WithHuman() func(*IngestSimulateRequest) { + return func(r *IngestSimulateRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IngestSimulate) WithErrorTrace() func(*IngestSimulateRequest) { + return func(r *IngestSimulateRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IngestSimulate) WithFilterPath(v ...string) func(*IngestSimulateRequest) { + return func(r *IngestSimulateRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IngestSimulate) WithHeader(h map[string]string) func(*IngestSimulateRequest) { + return func(r *IngestSimulateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IngestSimulate) WithOpaqueID(s string) func(*IngestSimulateRequest) { + return func(r *IngestSimulateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.mget.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.mget.go new file mode 100644 index 00000000000..5a4a54cb8c8 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.mget.go @@ -0,0 +1,311 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newMgetFunc(t Transport) Mget { + return func(body io.Reader, o ...func(*MgetRequest)) (*Response, error) { + var r = MgetRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// Mget allows to get multiple documents in one request. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-get.html. +// +type Mget func(body io.Reader, o ...func(*MgetRequest)) (*Response, error) + +// MgetRequest configures the Mget API request. +// +type MgetRequest struct { + Index string + + Body io.Reader + + Preference string + Realtime *bool + Refresh *bool + Routing string + Source []string + SourceExcludes []string + SourceIncludes []string + StoredFields []string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MgetRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(r.Index) + 1 + len("_mget")) + if r.Index != "" { + path.WriteString("/") + path.WriteString(r.Index) + } + path.WriteString("/") + path.WriteString("_mget") + + params = make(map[string]string) + + if r.Preference != "" { + params["preference"] = r.Preference + } + + if r.Realtime != nil { + params["realtime"] = strconv.FormatBool(*r.Realtime) + } + + if r.Refresh != nil { + params["refresh"] = strconv.FormatBool(*r.Refresh) + } + + if r.Routing != "" { + params["routing"] = r.Routing + } + + if len(r.Source) > 0 { + params["_source"] = strings.Join(r.Source, ",") + } + + if len(r.SourceExcludes) > 0 { + params["_source_excludes"] = strings.Join(r.SourceExcludes, ",") + } + + if len(r.SourceIncludes) > 0 { + params["_source_includes"] = strings.Join(r.SourceIncludes, ",") + } + + if len(r.StoredFields) > 0 { + params["stored_fields"] = strings.Join(r.StoredFields, ",") + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f Mget) WithContext(v context.Context) func(*MgetRequest) { + return func(r *MgetRequest) { + r.ctx = v + } +} + +// WithIndex - the name of the index. +// +func (f Mget) WithIndex(v string) func(*MgetRequest) { + return func(r *MgetRequest) { + r.Index = v + } +} + +// WithPreference - specify the node or shard the operation should be performed on (default: random). +// +func (f Mget) WithPreference(v string) func(*MgetRequest) { + return func(r *MgetRequest) { + r.Preference = v + } +} + +// WithRealtime - specify whether to perform the operation in realtime or search mode. +// +func (f Mget) WithRealtime(v bool) func(*MgetRequest) { + return func(r *MgetRequest) { + r.Realtime = &v + } +} + +// WithRefresh - refresh the shard containing the document before performing the operation. +// +func (f Mget) WithRefresh(v bool) func(*MgetRequest) { + return func(r *MgetRequest) { + r.Refresh = &v + } +} + +// WithRouting - specific routing value. +// +func (f Mget) WithRouting(v string) func(*MgetRequest) { + return func(r *MgetRequest) { + r.Routing = v + } +} + +// WithSource - true or false to return the _source field or not, or a list of fields to return. +// +func (f Mget) WithSource(v ...string) func(*MgetRequest) { + return func(r *MgetRequest) { + r.Source = v + } +} + +// WithSourceExcludes - a list of fields to exclude from the returned _source field. +// +func (f Mget) WithSourceExcludes(v ...string) func(*MgetRequest) { + return func(r *MgetRequest) { + r.SourceExcludes = v + } +} + +// WithSourceIncludes - a list of fields to extract and return from the _source field. +// +func (f Mget) WithSourceIncludes(v ...string) func(*MgetRequest) { + return func(r *MgetRequest) { + r.SourceIncludes = v + } +} + +// WithStoredFields - a list of stored fields to return in the response. +// +func (f Mget) WithStoredFields(v ...string) func(*MgetRequest) { + return func(r *MgetRequest) { + r.StoredFields = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f Mget) WithPretty() func(*MgetRequest) { + return func(r *MgetRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f Mget) WithHuman() func(*MgetRequest) { + return func(r *MgetRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f Mget) WithErrorTrace() func(*MgetRequest) { + return func(r *MgetRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f Mget) WithFilterPath(v ...string) func(*MgetRequest) { + return func(r *MgetRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f Mget) WithHeader(h map[string]string) func(*MgetRequest) { + return func(r *MgetRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f Mget) WithOpaqueID(s string) func(*MgetRequest) { + return func(r *MgetRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.msearch.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.msearch.go new file mode 100644 index 00000000000..e23a054fd88 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.msearch.go @@ -0,0 +1,298 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newMsearchFunc(t Transport) Msearch { + return func(body io.Reader, o ...func(*MsearchRequest)) (*Response, error) { + var r = MsearchRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// Msearch allows to execute several search operations in one request. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/search-multi-search.html. +// +type Msearch func(body io.Reader, o ...func(*MsearchRequest)) (*Response, error) + +// MsearchRequest configures the Msearch API request. +// +type MsearchRequest struct { + Index []string + + Body io.Reader + + CcsMinimizeRoundtrips *bool + MaxConcurrentSearches *int + MaxConcurrentShardRequests *int + PreFilterShardSize *int + RestTotalHitsAsInt *bool + SearchType string + TypedKeys *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MsearchRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_msearch")) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_msearch") + + params = make(map[string]string) + + if r.CcsMinimizeRoundtrips != nil { + params["ccs_minimize_roundtrips"] = strconv.FormatBool(*r.CcsMinimizeRoundtrips) + } + + if r.MaxConcurrentSearches != nil { + params["max_concurrent_searches"] = strconv.FormatInt(int64(*r.MaxConcurrentSearches), 10) + } + + if r.MaxConcurrentShardRequests != nil { + params["max_concurrent_shard_requests"] = strconv.FormatInt(int64(*r.MaxConcurrentShardRequests), 10) + } + + if r.PreFilterShardSize != nil { + params["pre_filter_shard_size"] = strconv.FormatInt(int64(*r.PreFilterShardSize), 10) + } + + if r.RestTotalHitsAsInt != nil { + params["rest_total_hits_as_int"] = strconv.FormatBool(*r.RestTotalHitsAsInt) + } + + if r.SearchType != "" { + params["search_type"] = r.SearchType + } + + if r.TypedKeys != nil { + params["typed_keys"] = strconv.FormatBool(*r.TypedKeys) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f Msearch) WithContext(v context.Context) func(*MsearchRequest) { + return func(r *MsearchRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names to use as default. +// +func (f Msearch) WithIndex(v ...string) func(*MsearchRequest) { + return func(r *MsearchRequest) { + r.Index = v + } +} + +// WithCcsMinimizeRoundtrips - indicates whether network round-trips should be minimized as part of cross-cluster search requests execution. +// +func (f Msearch) WithCcsMinimizeRoundtrips(v bool) func(*MsearchRequest) { + return func(r *MsearchRequest) { + r.CcsMinimizeRoundtrips = &v + } +} + +// WithMaxConcurrentSearches - controls the maximum number of concurrent searches the multi search api will execute. +// +func (f Msearch) WithMaxConcurrentSearches(v int) func(*MsearchRequest) { + return func(r *MsearchRequest) { + r.MaxConcurrentSearches = &v + } +} + +// WithMaxConcurrentShardRequests - the number of concurrent shard requests each sub search executes concurrently per node. this value should be used to limit the impact of the search on the cluster in order to limit the number of concurrent shard requests. +// +func (f Msearch) WithMaxConcurrentShardRequests(v int) func(*MsearchRequest) { + return func(r *MsearchRequest) { + r.MaxConcurrentShardRequests = &v + } +} + +// WithPreFilterShardSize - a threshold that enforces a pre-filter roundtrip to prefilter search shards based on query rewriting if the number of shards the search request expands to exceeds the threshold. this filter roundtrip can limit the number of shards significantly if for instance a shard can not match any documents based on it's rewrite method ie. if date filters are mandatory to match but the shard bounds and the query are disjoint.. +// +func (f Msearch) WithPreFilterShardSize(v int) func(*MsearchRequest) { + return func(r *MsearchRequest) { + r.PreFilterShardSize = &v + } +} + +// WithRestTotalHitsAsInt - indicates whether hits.total should be rendered as an integer or an object in the rest search response. +// +func (f Msearch) WithRestTotalHitsAsInt(v bool) func(*MsearchRequest) { + return func(r *MsearchRequest) { + r.RestTotalHitsAsInt = &v + } +} + +// WithSearchType - search operation type. +// +func (f Msearch) WithSearchType(v string) func(*MsearchRequest) { + return func(r *MsearchRequest) { + r.SearchType = v + } +} + +// WithTypedKeys - specify whether aggregation and suggester names should be prefixed by their respective types in the response. +// +func (f Msearch) WithTypedKeys(v bool) func(*MsearchRequest) { + return func(r *MsearchRequest) { + r.TypedKeys = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f Msearch) WithPretty() func(*MsearchRequest) { + return func(r *MsearchRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f Msearch) WithHuman() func(*MsearchRequest) { + return func(r *MsearchRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f Msearch) WithErrorTrace() func(*MsearchRequest) { + return func(r *MsearchRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f Msearch) WithFilterPath(v ...string) func(*MsearchRequest) { + return func(r *MsearchRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f Msearch) WithHeader(h map[string]string) func(*MsearchRequest) { + return func(r *MsearchRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f Msearch) WithOpaqueID(s string) func(*MsearchRequest) { + return func(r *MsearchRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.msearch_template.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.msearch_template.go new file mode 100644 index 00000000000..e52608840e2 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.msearch_template.go @@ -0,0 +1,274 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newMsearchTemplateFunc(t Transport) MsearchTemplate { + return func(body io.Reader, o ...func(*MsearchTemplateRequest)) (*Response, error) { + var r = MsearchTemplateRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MsearchTemplate allows to execute several search template operations in one request. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html. +// +type MsearchTemplate func(body io.Reader, o ...func(*MsearchTemplateRequest)) (*Response, error) + +// MsearchTemplateRequest configures the Msearch Template API request. +// +type MsearchTemplateRequest struct { + Index []string + + Body io.Reader + + CcsMinimizeRoundtrips *bool + MaxConcurrentSearches *int + RestTotalHitsAsInt *bool + SearchType string + TypedKeys *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MsearchTemplateRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_msearch") + 1 + len("template")) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_msearch") + path.WriteString("/") + path.WriteString("template") + + params = make(map[string]string) + + if r.CcsMinimizeRoundtrips != nil { + params["ccs_minimize_roundtrips"] = strconv.FormatBool(*r.CcsMinimizeRoundtrips) + } + + if r.MaxConcurrentSearches != nil { + params["max_concurrent_searches"] = strconv.FormatInt(int64(*r.MaxConcurrentSearches), 10) + } + + if r.RestTotalHitsAsInt != nil { + params["rest_total_hits_as_int"] = strconv.FormatBool(*r.RestTotalHitsAsInt) + } + + if r.SearchType != "" { + params["search_type"] = r.SearchType + } + + if r.TypedKeys != nil { + params["typed_keys"] = strconv.FormatBool(*r.TypedKeys) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MsearchTemplate) WithContext(v context.Context) func(*MsearchTemplateRequest) { + return func(r *MsearchTemplateRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names to use as default. +// +func (f MsearchTemplate) WithIndex(v ...string) func(*MsearchTemplateRequest) { + return func(r *MsearchTemplateRequest) { + r.Index = v + } +} + +// WithCcsMinimizeRoundtrips - indicates whether network round-trips should be minimized as part of cross-cluster search requests execution. +// +func (f MsearchTemplate) WithCcsMinimizeRoundtrips(v bool) func(*MsearchTemplateRequest) { + return func(r *MsearchTemplateRequest) { + r.CcsMinimizeRoundtrips = &v + } +} + +// WithMaxConcurrentSearches - controls the maximum number of concurrent searches the multi search api will execute. +// +func (f MsearchTemplate) WithMaxConcurrentSearches(v int) func(*MsearchTemplateRequest) { + return func(r *MsearchTemplateRequest) { + r.MaxConcurrentSearches = &v + } +} + +// WithRestTotalHitsAsInt - indicates whether hits.total should be rendered as an integer or an object in the rest search response. +// +func (f MsearchTemplate) WithRestTotalHitsAsInt(v bool) func(*MsearchTemplateRequest) { + return func(r *MsearchTemplateRequest) { + r.RestTotalHitsAsInt = &v + } +} + +// WithSearchType - search operation type. +// +func (f MsearchTemplate) WithSearchType(v string) func(*MsearchTemplateRequest) { + return func(r *MsearchTemplateRequest) { + r.SearchType = v + } +} + +// WithTypedKeys - specify whether aggregation and suggester names should be prefixed by their respective types in the response. +// +func (f MsearchTemplate) WithTypedKeys(v bool) func(*MsearchTemplateRequest) { + return func(r *MsearchTemplateRequest) { + r.TypedKeys = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MsearchTemplate) WithPretty() func(*MsearchTemplateRequest) { + return func(r *MsearchTemplateRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MsearchTemplate) WithHuman() func(*MsearchTemplateRequest) { + return func(r *MsearchTemplateRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MsearchTemplate) WithErrorTrace() func(*MsearchTemplateRequest) { + return func(r *MsearchTemplateRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MsearchTemplate) WithFilterPath(v ...string) func(*MsearchTemplateRequest) { + return func(r *MsearchTemplateRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MsearchTemplate) WithHeader(h map[string]string) func(*MsearchTemplateRequest) { + return func(r *MsearchTemplateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MsearchTemplate) WithOpaqueID(s string) func(*MsearchTemplateRequest) { + return func(r *MsearchTemplateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.mtermvectors.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.mtermvectors.go new file mode 100644 index 00000000000..5127c5f8972 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.mtermvectors.go @@ -0,0 +1,371 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newMtermvectorsFunc(t Transport) Mtermvectors { + return func(o ...func(*MtermvectorsRequest)) (*Response, error) { + var r = MtermvectorsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// Mtermvectors returns multiple termvectors in one request. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-termvectors.html. +// +type Mtermvectors func(o ...func(*MtermvectorsRequest)) (*Response, error) + +// MtermvectorsRequest configures the Mtermvectors API request. +// +type MtermvectorsRequest struct { + Index string + + Body io.Reader + + Fields []string + FieldStatistics *bool + Ids []string + Offsets *bool + Payloads *bool + Positions *bool + Preference string + Realtime *bool + Routing string + TermStatistics *bool + Version *int + VersionType string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MtermvectorsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(r.Index) + 1 + len("_mtermvectors")) + if r.Index != "" { + path.WriteString("/") + path.WriteString(r.Index) + } + path.WriteString("/") + path.WriteString("_mtermvectors") + + params = make(map[string]string) + + if len(r.Fields) > 0 { + params["fields"] = strings.Join(r.Fields, ",") + } + + if r.FieldStatistics != nil { + params["field_statistics"] = strconv.FormatBool(*r.FieldStatistics) + } + + if len(r.Ids) > 0 { + params["ids"] = strings.Join(r.Ids, ",") + } + + if r.Offsets != nil { + params["offsets"] = strconv.FormatBool(*r.Offsets) + } + + if r.Payloads != nil { + params["payloads"] = strconv.FormatBool(*r.Payloads) + } + + if r.Positions != nil { + params["positions"] = strconv.FormatBool(*r.Positions) + } + + if r.Preference != "" { + params["preference"] = r.Preference + } + + if r.Realtime != nil { + params["realtime"] = strconv.FormatBool(*r.Realtime) + } + + if r.Routing != "" { + params["routing"] = r.Routing + } + + if r.TermStatistics != nil { + params["term_statistics"] = strconv.FormatBool(*r.TermStatistics) + } + + if r.Version != nil { + params["version"] = strconv.FormatInt(int64(*r.Version), 10) + } + + if r.VersionType != "" { + params["version_type"] = r.VersionType + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f Mtermvectors) WithContext(v context.Context) func(*MtermvectorsRequest) { + return func(r *MtermvectorsRequest) { + r.ctx = v + } +} + +// WithBody - Define ids, documents, parameters or a list of parameters per document here. You must at least provide a list of document ids. See documentation.. +// +func (f Mtermvectors) WithBody(v io.Reader) func(*MtermvectorsRequest) { + return func(r *MtermvectorsRequest) { + r.Body = v + } +} + +// WithIndex - the index in which the document resides.. +// +func (f Mtermvectors) WithIndex(v string) func(*MtermvectorsRequest) { + return func(r *MtermvectorsRequest) { + r.Index = v + } +} + +// WithFields - a list of fields to return. applies to all returned documents unless otherwise specified in body "params" or "docs".. +// +func (f Mtermvectors) WithFields(v ...string) func(*MtermvectorsRequest) { + return func(r *MtermvectorsRequest) { + r.Fields = v + } +} + +// WithFieldStatistics - specifies if document count, sum of document frequencies and sum of total term frequencies should be returned. applies to all returned documents unless otherwise specified in body "params" or "docs".. +// +func (f Mtermvectors) WithFieldStatistics(v bool) func(*MtermvectorsRequest) { + return func(r *MtermvectorsRequest) { + r.FieldStatistics = &v + } +} + +// WithIds - a list of documents ids. you must define ids as parameter or set "ids" or "docs" in the request body. +// +func (f Mtermvectors) WithIds(v ...string) func(*MtermvectorsRequest) { + return func(r *MtermvectorsRequest) { + r.Ids = v + } +} + +// WithOffsets - specifies if term offsets should be returned. applies to all returned documents unless otherwise specified in body "params" or "docs".. +// +func (f Mtermvectors) WithOffsets(v bool) func(*MtermvectorsRequest) { + return func(r *MtermvectorsRequest) { + r.Offsets = &v + } +} + +// WithPayloads - specifies if term payloads should be returned. applies to all returned documents unless otherwise specified in body "params" or "docs".. +// +func (f Mtermvectors) WithPayloads(v bool) func(*MtermvectorsRequest) { + return func(r *MtermvectorsRequest) { + r.Payloads = &v + } +} + +// WithPositions - specifies if term positions should be returned. applies to all returned documents unless otherwise specified in body "params" or "docs".. +// +func (f Mtermvectors) WithPositions(v bool) func(*MtermvectorsRequest) { + return func(r *MtermvectorsRequest) { + r.Positions = &v + } +} + +// WithPreference - specify the node or shard the operation should be performed on (default: random) .applies to all returned documents unless otherwise specified in body "params" or "docs".. +// +func (f Mtermvectors) WithPreference(v string) func(*MtermvectorsRequest) { + return func(r *MtermvectorsRequest) { + r.Preference = v + } +} + +// WithRealtime - specifies if requests are real-time as opposed to near-real-time (default: true).. +// +func (f Mtermvectors) WithRealtime(v bool) func(*MtermvectorsRequest) { + return func(r *MtermvectorsRequest) { + r.Realtime = &v + } +} + +// WithRouting - specific routing value. applies to all returned documents unless otherwise specified in body "params" or "docs".. +// +func (f Mtermvectors) WithRouting(v string) func(*MtermvectorsRequest) { + return func(r *MtermvectorsRequest) { + r.Routing = v + } +} + +// WithTermStatistics - specifies if total term frequency and document frequency should be returned. applies to all returned documents unless otherwise specified in body "params" or "docs".. +// +func (f Mtermvectors) WithTermStatistics(v bool) func(*MtermvectorsRequest) { + return func(r *MtermvectorsRequest) { + r.TermStatistics = &v + } +} + +// WithVersion - explicit version number for concurrency control. +// +func (f Mtermvectors) WithVersion(v int) func(*MtermvectorsRequest) { + return func(r *MtermvectorsRequest) { + r.Version = &v + } +} + +// WithVersionType - specific version type. +// +func (f Mtermvectors) WithVersionType(v string) func(*MtermvectorsRequest) { + return func(r *MtermvectorsRequest) { + r.VersionType = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f Mtermvectors) WithPretty() func(*MtermvectorsRequest) { + return func(r *MtermvectorsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f Mtermvectors) WithHuman() func(*MtermvectorsRequest) { + return func(r *MtermvectorsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f Mtermvectors) WithErrorTrace() func(*MtermvectorsRequest) { + return func(r *MtermvectorsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f Mtermvectors) WithFilterPath(v ...string) func(*MtermvectorsRequest) { + return func(r *MtermvectorsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f Mtermvectors) WithHeader(h map[string]string) func(*MtermvectorsRequest) { + return func(r *MtermvectorsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f Mtermvectors) WithOpaqueID(s string) func(*MtermvectorsRequest) { + return func(r *MtermvectorsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.nodes.hot_threads.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.nodes.hot_threads.go new file mode 100644 index 00000000000..4835dbb9ee9 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.nodes.hot_threads.go @@ -0,0 +1,283 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newNodesHotThreadsFunc(t Transport) NodesHotThreads { + return func(o ...func(*NodesHotThreadsRequest)) (*Response, error) { + var r = NodesHotThreadsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// NodesHotThreads returns information about hot threads on each node in the cluster. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-hot-threads.html. +// +type NodesHotThreads func(o ...func(*NodesHotThreadsRequest)) (*Response, error) + +// NodesHotThreadsRequest configures the Nodes Hot Threads API request. +// +type NodesHotThreadsRequest struct { + NodeID []string + + IgnoreIdleThreads *bool + Interval time.Duration + Snapshots *int + Threads *int + Timeout time.Duration + DocumentType string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r NodesHotThreadsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_cluster") + 1 + len("nodes") + 1 + len(strings.Join(r.NodeID, ",")) + 1 + len("hot_threads")) + path.WriteString("/") + path.WriteString("_cluster") + path.WriteString("/") + path.WriteString("nodes") + if len(r.NodeID) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.NodeID, ",")) + } + path.WriteString("/") + path.WriteString("hot_threads") + + params = make(map[string]string) + + if r.IgnoreIdleThreads != nil { + params["ignore_idle_threads"] = strconv.FormatBool(*r.IgnoreIdleThreads) + } + + if r.Interval != 0 { + params["interval"] = formatDuration(r.Interval) + } + + if r.Snapshots != nil { + params["snapshots"] = strconv.FormatInt(int64(*r.Snapshots), 10) + } + + if r.Threads != nil { + params["threads"] = strconv.FormatInt(int64(*r.Threads), 10) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.DocumentType != "" { + params["type"] = r.DocumentType + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f NodesHotThreads) WithContext(v context.Context) func(*NodesHotThreadsRequest) { + return func(r *NodesHotThreadsRequest) { + r.ctx = v + } +} + +// WithNodeID - a list of node ids or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes. +// +func (f NodesHotThreads) WithNodeID(v ...string) func(*NodesHotThreadsRequest) { + return func(r *NodesHotThreadsRequest) { + r.NodeID = v + } +} + +// WithIgnoreIdleThreads - don't show threads that are in known-idle places, such as waiting on a socket select or pulling from an empty task queue (default: true). +// +func (f NodesHotThreads) WithIgnoreIdleThreads(v bool) func(*NodesHotThreadsRequest) { + return func(r *NodesHotThreadsRequest) { + r.IgnoreIdleThreads = &v + } +} + +// WithInterval - the interval for the second sampling of threads. +// +func (f NodesHotThreads) WithInterval(v time.Duration) func(*NodesHotThreadsRequest) { + return func(r *NodesHotThreadsRequest) { + r.Interval = v + } +} + +// WithSnapshots - number of samples of thread stacktrace (default: 10). +// +func (f NodesHotThreads) WithSnapshots(v int) func(*NodesHotThreadsRequest) { + return func(r *NodesHotThreadsRequest) { + r.Snapshots = &v + } +} + +// WithThreads - specify the number of threads to provide information for (default: 3). +// +func (f NodesHotThreads) WithThreads(v int) func(*NodesHotThreadsRequest) { + return func(r *NodesHotThreadsRequest) { + r.Threads = &v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f NodesHotThreads) WithTimeout(v time.Duration) func(*NodesHotThreadsRequest) { + return func(r *NodesHotThreadsRequest) { + r.Timeout = v + } +} + +// WithDocumentType - the type to sample (default: cpu). +// +func (f NodesHotThreads) WithDocumentType(v string) func(*NodesHotThreadsRequest) { + return func(r *NodesHotThreadsRequest) { + r.DocumentType = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f NodesHotThreads) WithPretty() func(*NodesHotThreadsRequest) { + return func(r *NodesHotThreadsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f NodesHotThreads) WithHuman() func(*NodesHotThreadsRequest) { + return func(r *NodesHotThreadsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f NodesHotThreads) WithErrorTrace() func(*NodesHotThreadsRequest) { + return func(r *NodesHotThreadsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f NodesHotThreads) WithFilterPath(v ...string) func(*NodesHotThreadsRequest) { + return func(r *NodesHotThreadsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f NodesHotThreads) WithHeader(h map[string]string) func(*NodesHotThreadsRequest) { + return func(r *NodesHotThreadsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f NodesHotThreads) WithOpaqueID(s string) func(*NodesHotThreadsRequest) { + return func(r *NodesHotThreadsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.nodes.info.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.nodes.info.go new file mode 100644 index 00000000000..159ed3c886b --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.nodes.info.go @@ -0,0 +1,240 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newNodesInfoFunc(t Transport) NodesInfo { + return func(o ...func(*NodesInfoRequest)) (*Response, error) { + var r = NodesInfoRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// NodesInfo returns information about nodes in the cluster. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-info.html. +// +type NodesInfo func(o ...func(*NodesInfoRequest)) (*Response, error) + +// NodesInfoRequest configures the Nodes Info API request. +// +type NodesInfoRequest struct { + Metric []string + NodeID []string + + FlatSettings *bool + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r NodesInfoRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_nodes") + 1 + len(strings.Join(r.NodeID, ",")) + 1 + len(strings.Join(r.Metric, ","))) + path.WriteString("/") + path.WriteString("_nodes") + if len(r.NodeID) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.NodeID, ",")) + } + if len(r.Metric) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Metric, ",")) + } + + params = make(map[string]string) + + if r.FlatSettings != nil { + params["flat_settings"] = strconv.FormatBool(*r.FlatSettings) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f NodesInfo) WithContext(v context.Context) func(*NodesInfoRequest) { + return func(r *NodesInfoRequest) { + r.ctx = v + } +} + +// WithMetric - a list of metrics you wish returned. leave empty to return all.. +// +func (f NodesInfo) WithMetric(v ...string) func(*NodesInfoRequest) { + return func(r *NodesInfoRequest) { + r.Metric = v + } +} + +// WithNodeID - a list of node ids or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes. +// +func (f NodesInfo) WithNodeID(v ...string) func(*NodesInfoRequest) { + return func(r *NodesInfoRequest) { + r.NodeID = v + } +} + +// WithFlatSettings - return settings in flat format (default: false). +// +func (f NodesInfo) WithFlatSettings(v bool) func(*NodesInfoRequest) { + return func(r *NodesInfoRequest) { + r.FlatSettings = &v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f NodesInfo) WithTimeout(v time.Duration) func(*NodesInfoRequest) { + return func(r *NodesInfoRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f NodesInfo) WithPretty() func(*NodesInfoRequest) { + return func(r *NodesInfoRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f NodesInfo) WithHuman() func(*NodesInfoRequest) { + return func(r *NodesInfoRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f NodesInfo) WithErrorTrace() func(*NodesInfoRequest) { + return func(r *NodesInfoRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f NodesInfo) WithFilterPath(v ...string) func(*NodesInfoRequest) { + return func(r *NodesInfoRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f NodesInfo) WithHeader(h map[string]string) func(*NodesInfoRequest) { + return func(r *NodesInfoRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f NodesInfo) WithOpaqueID(s string) func(*NodesInfoRequest) { + return func(r *NodesInfoRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.nodes.reload_secure_settings.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.nodes.reload_secure_settings.go new file mode 100644 index 00000000000..8d3c60ce8ab --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.nodes.reload_secure_settings.go @@ -0,0 +1,215 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" + "time" +) + +func newNodesReloadSecureSettingsFunc(t Transport) NodesReloadSecureSettings { + return func(o ...func(*NodesReloadSecureSettingsRequest)) (*Response, error) { + var r = NodesReloadSecureSettingsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// NodesReloadSecureSettings reloads secure settings. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/secure-settings.html#reloadable-secure-settings. +// +type NodesReloadSecureSettings func(o ...func(*NodesReloadSecureSettingsRequest)) (*Response, error) + +// NodesReloadSecureSettingsRequest configures the Nodes Reload Secure Settings API request. +// +type NodesReloadSecureSettingsRequest struct { + NodeID []string + + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r NodesReloadSecureSettingsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_nodes") + 1 + len(strings.Join(r.NodeID, ",")) + 1 + len("reload_secure_settings")) + path.WriteString("/") + path.WriteString("_nodes") + if len(r.NodeID) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.NodeID, ",")) + } + path.WriteString("/") + path.WriteString("reload_secure_settings") + + params = make(map[string]string) + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f NodesReloadSecureSettings) WithContext(v context.Context) func(*NodesReloadSecureSettingsRequest) { + return func(r *NodesReloadSecureSettingsRequest) { + r.ctx = v + } +} + +// WithNodeID - a list of node ids to span the reload/reinit call. should stay empty because reloading usually involves all cluster nodes.. +// +func (f NodesReloadSecureSettings) WithNodeID(v ...string) func(*NodesReloadSecureSettingsRequest) { + return func(r *NodesReloadSecureSettingsRequest) { + r.NodeID = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f NodesReloadSecureSettings) WithTimeout(v time.Duration) func(*NodesReloadSecureSettingsRequest) { + return func(r *NodesReloadSecureSettingsRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f NodesReloadSecureSettings) WithPretty() func(*NodesReloadSecureSettingsRequest) { + return func(r *NodesReloadSecureSettingsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f NodesReloadSecureSettings) WithHuman() func(*NodesReloadSecureSettingsRequest) { + return func(r *NodesReloadSecureSettingsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f NodesReloadSecureSettings) WithErrorTrace() func(*NodesReloadSecureSettingsRequest) { + return func(r *NodesReloadSecureSettingsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f NodesReloadSecureSettings) WithFilterPath(v ...string) func(*NodesReloadSecureSettingsRequest) { + return func(r *NodesReloadSecureSettingsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f NodesReloadSecureSettings) WithHeader(h map[string]string) func(*NodesReloadSecureSettingsRequest) { + return func(r *NodesReloadSecureSettingsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f NodesReloadSecureSettings) WithOpaqueID(s string) func(*NodesReloadSecureSettingsRequest) { + return func(r *NodesReloadSecureSettingsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.nodes.stats.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.nodes.stats.go new file mode 100644 index 00000000000..4d9447708af --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.nodes.stats.go @@ -0,0 +1,333 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newNodesStatsFunc(t Transport) NodesStats { + return func(o ...func(*NodesStatsRequest)) (*Response, error) { + var r = NodesStatsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// NodesStats returns statistical information about nodes in the cluster. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-stats.html. +// +type NodesStats func(o ...func(*NodesStatsRequest)) (*Response, error) + +// NodesStatsRequest configures the Nodes Stats API request. +// +type NodesStatsRequest struct { + IndexMetric []string + Metric []string + NodeID []string + + CompletionFields []string + FielddataFields []string + Fields []string + Groups *bool + IncludeSegmentFileSizes *bool + Level string + Timeout time.Duration + Types []string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r NodesStatsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_nodes") + 1 + len(strings.Join(r.NodeID, ",")) + 1 + len("stats") + 1 + len(strings.Join(r.Metric, ",")) + 1 + len(strings.Join(r.IndexMetric, ","))) + path.WriteString("/") + path.WriteString("_nodes") + if len(r.NodeID) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.NodeID, ",")) + } + path.WriteString("/") + path.WriteString("stats") + if len(r.Metric) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Metric, ",")) + } + if len(r.IndexMetric) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.IndexMetric, ",")) + } + + params = make(map[string]string) + + if len(r.CompletionFields) > 0 { + params["completion_fields"] = strings.Join(r.CompletionFields, ",") + } + + if len(r.FielddataFields) > 0 { + params["fielddata_fields"] = strings.Join(r.FielddataFields, ",") + } + + if len(r.Fields) > 0 { + params["fields"] = strings.Join(r.Fields, ",") + } + + if r.Groups != nil { + params["groups"] = strconv.FormatBool(*r.Groups) + } + + if r.IncludeSegmentFileSizes != nil { + params["include_segment_file_sizes"] = strconv.FormatBool(*r.IncludeSegmentFileSizes) + } + + if r.Level != "" { + params["level"] = r.Level + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if len(r.Types) > 0 { + params["types"] = strings.Join(r.Types, ",") + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f NodesStats) WithContext(v context.Context) func(*NodesStatsRequest) { + return func(r *NodesStatsRequest) { + r.ctx = v + } +} + +// WithIndexMetric - limit the information returned for `indices` metric to the specific index metrics. isn't used if `indices` (or `all`) metric isn't specified.. +// +func (f NodesStats) WithIndexMetric(v ...string) func(*NodesStatsRequest) { + return func(r *NodesStatsRequest) { + r.IndexMetric = v + } +} + +// WithMetric - limit the information returned to the specified metrics. +// +func (f NodesStats) WithMetric(v ...string) func(*NodesStatsRequest) { + return func(r *NodesStatsRequest) { + r.Metric = v + } +} + +// WithNodeID - a list of node ids or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes. +// +func (f NodesStats) WithNodeID(v ...string) func(*NodesStatsRequest) { + return func(r *NodesStatsRequest) { + r.NodeID = v + } +} + +// WithCompletionFields - a list of fields for `fielddata` and `suggest` index metric (supports wildcards). +// +func (f NodesStats) WithCompletionFields(v ...string) func(*NodesStatsRequest) { + return func(r *NodesStatsRequest) { + r.CompletionFields = v + } +} + +// WithFielddataFields - a list of fields for `fielddata` index metric (supports wildcards). +// +func (f NodesStats) WithFielddataFields(v ...string) func(*NodesStatsRequest) { + return func(r *NodesStatsRequest) { + r.FielddataFields = v + } +} + +// WithFields - a list of fields for `fielddata` and `completion` index metric (supports wildcards). +// +func (f NodesStats) WithFields(v ...string) func(*NodesStatsRequest) { + return func(r *NodesStatsRequest) { + r.Fields = v + } +} + +// WithGroups - a list of search groups for `search` index metric. +// +func (f NodesStats) WithGroups(v bool) func(*NodesStatsRequest) { + return func(r *NodesStatsRequest) { + r.Groups = &v + } +} + +// WithIncludeSegmentFileSizes - whether to report the aggregated disk usage of each one of the lucene index files (only applies if segment stats are requested). +// +func (f NodesStats) WithIncludeSegmentFileSizes(v bool) func(*NodesStatsRequest) { + return func(r *NodesStatsRequest) { + r.IncludeSegmentFileSizes = &v + } +} + +// WithLevel - return indices stats aggregated at index, node or shard level. +// +func (f NodesStats) WithLevel(v string) func(*NodesStatsRequest) { + return func(r *NodesStatsRequest) { + r.Level = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f NodesStats) WithTimeout(v time.Duration) func(*NodesStatsRequest) { + return func(r *NodesStatsRequest) { + r.Timeout = v + } +} + +// WithTypes - a list of document types for the `indexing` index metric. +// +func (f NodesStats) WithTypes(v ...string) func(*NodesStatsRequest) { + return func(r *NodesStatsRequest) { + r.Types = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f NodesStats) WithPretty() func(*NodesStatsRequest) { + return func(r *NodesStatsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f NodesStats) WithHuman() func(*NodesStatsRequest) { + return func(r *NodesStatsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f NodesStats) WithErrorTrace() func(*NodesStatsRequest) { + return func(r *NodesStatsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f NodesStats) WithFilterPath(v ...string) func(*NodesStatsRequest) { + return func(r *NodesStatsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f NodesStats) WithHeader(h map[string]string) func(*NodesStatsRequest) { + return func(r *NodesStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f NodesStats) WithOpaqueID(s string) func(*NodesStatsRequest) { + return func(r *NodesStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.nodes.usage.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.nodes.usage.go new file mode 100644 index 00000000000..e163065de56 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.nodes.usage.go @@ -0,0 +1,228 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" + "time" +) + +func newNodesUsageFunc(t Transport) NodesUsage { + return func(o ...func(*NodesUsageRequest)) (*Response, error) { + var r = NodesUsageRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// NodesUsage returns low-level information about REST actions usage on nodes. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-usage.html. +// +type NodesUsage func(o ...func(*NodesUsageRequest)) (*Response, error) + +// NodesUsageRequest configures the Nodes Usage API request. +// +type NodesUsageRequest struct { + Metric []string + NodeID []string + + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r NodesUsageRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_nodes") + 1 + len(strings.Join(r.NodeID, ",")) + 1 + len("usage") + 1 + len(strings.Join(r.Metric, ","))) + path.WriteString("/") + path.WriteString("_nodes") + if len(r.NodeID) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.NodeID, ",")) + } + path.WriteString("/") + path.WriteString("usage") + if len(r.Metric) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Metric, ",")) + } + + params = make(map[string]string) + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f NodesUsage) WithContext(v context.Context) func(*NodesUsageRequest) { + return func(r *NodesUsageRequest) { + r.ctx = v + } +} + +// WithMetric - limit the information returned to the specified metrics. +// +func (f NodesUsage) WithMetric(v ...string) func(*NodesUsageRequest) { + return func(r *NodesUsageRequest) { + r.Metric = v + } +} + +// WithNodeID - a list of node ids or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes. +// +func (f NodesUsage) WithNodeID(v ...string) func(*NodesUsageRequest) { + return func(r *NodesUsageRequest) { + r.NodeID = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f NodesUsage) WithTimeout(v time.Duration) func(*NodesUsageRequest) { + return func(r *NodesUsageRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f NodesUsage) WithPretty() func(*NodesUsageRequest) { + return func(r *NodesUsageRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f NodesUsage) WithHuman() func(*NodesUsageRequest) { + return func(r *NodesUsageRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f NodesUsage) WithErrorTrace() func(*NodesUsageRequest) { + return func(r *NodesUsageRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f NodesUsage) WithFilterPath(v ...string) func(*NodesUsageRequest) { + return func(r *NodesUsageRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f NodesUsage) WithHeader(h map[string]string) func(*NodesUsageRequest) { + return func(r *NodesUsageRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f NodesUsage) WithOpaqueID(s string) func(*NodesUsageRequest) { + return func(r *NodesUsageRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.ping.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.ping.go new file mode 100644 index 00000000000..d7f64525dad --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.ping.go @@ -0,0 +1,183 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newPingFunc(t Transport) Ping { + return func(o ...func(*PingRequest)) (*Response, error) { + var r = PingRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// Ping returns whether the cluster is running. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html. +// +type Ping func(o ...func(*PingRequest)) (*Response, error) + +// PingRequest configures the Ping API request. +// +type PingRequest struct { + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r PingRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "HEAD" + + path.Grow(len("/")) + path.WriteString("/") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f Ping) WithContext(v context.Context) func(*PingRequest) { + return func(r *PingRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f Ping) WithPretty() func(*PingRequest) { + return func(r *PingRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f Ping) WithHuman() func(*PingRequest) { + return func(r *PingRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f Ping) WithErrorTrace() func(*PingRequest) { + return func(r *PingRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f Ping) WithFilterPath(v ...string) func(*PingRequest) { + return func(r *PingRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f Ping) WithHeader(h map[string]string) func(*PingRequest) { + return func(r *PingRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f Ping) WithOpaqueID(s string) func(*PingRequest) { + return func(r *PingRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.put_script.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.put_script.go new file mode 100644 index 00000000000..d046f722b8a --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.put_script.go @@ -0,0 +1,241 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" + "time" +) + +func newPutScriptFunc(t Transport) PutScript { + return func(id string, body io.Reader, o ...func(*PutScriptRequest)) (*Response, error) { + var r = PutScriptRequest{ScriptID: id, Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// PutScript creates or updates a script. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html. +// +type PutScript func(id string, body io.Reader, o ...func(*PutScriptRequest)) (*Response, error) + +// PutScriptRequest configures the Put Script API request. +// +type PutScriptRequest struct { + ScriptID string + + Body io.Reader + + ScriptContext string + + MasterTimeout time.Duration + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r PutScriptRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_scripts") + 1 + len(r.ScriptID) + 1 + len(r.ScriptContext)) + path.WriteString("/") + path.WriteString("_scripts") + path.WriteString("/") + path.WriteString(r.ScriptID) + if r.ScriptContext != "" { + path.WriteString("/") + path.WriteString(r.ScriptContext) + } + + params = make(map[string]string) + + if r.ScriptContext != "" { + params["context"] = r.ScriptContext + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f PutScript) WithContext(v context.Context) func(*PutScriptRequest) { + return func(r *PutScriptRequest) { + r.ctx = v + } +} + +// WithScriptContext - script context. +// +func (f PutScript) WithScriptContext(v string) func(*PutScriptRequest) { + return func(r *PutScriptRequest) { + r.ScriptContext = v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f PutScript) WithMasterTimeout(v time.Duration) func(*PutScriptRequest) { + return func(r *PutScriptRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f PutScript) WithTimeout(v time.Duration) func(*PutScriptRequest) { + return func(r *PutScriptRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f PutScript) WithPretty() func(*PutScriptRequest) { + return func(r *PutScriptRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f PutScript) WithHuman() func(*PutScriptRequest) { + return func(r *PutScriptRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f PutScript) WithErrorTrace() func(*PutScriptRequest) { + return func(r *PutScriptRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f PutScript) WithFilterPath(v ...string) func(*PutScriptRequest) { + return func(r *PutScriptRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f PutScript) WithHeader(h map[string]string) func(*PutScriptRequest) { + return func(r *PutScriptRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f PutScript) WithOpaqueID(s string) func(*PutScriptRequest) { + return func(r *PutScriptRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.rank_eval.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.rank_eval.go new file mode 100644 index 00000000000..ae852e726fc --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.rank_eval.go @@ -0,0 +1,246 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newRankEvalFunc(t Transport) RankEval { + return func(body io.Reader, o ...func(*RankEvalRequest)) (*Response, error) { + var r = RankEvalRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// RankEval allows to evaluate the quality of ranked search results over a set of typical search queries +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/search-rank-eval.html. +// +type RankEval func(body io.Reader, o ...func(*RankEvalRequest)) (*Response, error) + +// RankEvalRequest configures the Rank Eval API request. +// +type RankEvalRequest struct { + Index []string + + Body io.Reader + + AllowNoIndices *bool + ExpandWildcards string + IgnoreUnavailable *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r RankEvalRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_rank_eval")) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_rank_eval") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f RankEval) WithContext(v context.Context) func(*RankEvalRequest) { + return func(r *RankEvalRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names to search; use _all to perform the operation on all indices. +// +func (f RankEval) WithIndex(v ...string) func(*RankEvalRequest) { + return func(r *RankEvalRequest) { + r.Index = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f RankEval) WithAllowNoIndices(v bool) func(*RankEvalRequest) { + return func(r *RankEvalRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f RankEval) WithExpandWildcards(v string) func(*RankEvalRequest) { + return func(r *RankEvalRequest) { + r.ExpandWildcards = v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f RankEval) WithIgnoreUnavailable(v bool) func(*RankEvalRequest) { + return func(r *RankEvalRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f RankEval) WithPretty() func(*RankEvalRequest) { + return func(r *RankEvalRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f RankEval) WithHuman() func(*RankEvalRequest) { + return func(r *RankEvalRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f RankEval) WithErrorTrace() func(*RankEvalRequest) { + return func(r *RankEvalRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f RankEval) WithFilterPath(v ...string) func(*RankEvalRequest) { + return func(r *RankEvalRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f RankEval) WithHeader(h map[string]string) func(*RankEvalRequest) { + return func(r *RankEvalRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f RankEval) WithOpaqueID(s string) func(*RankEvalRequest) { + return func(r *RankEvalRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.reindex.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.reindex.go new file mode 100644 index 00000000000..54bc9383d93 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.reindex.go @@ -0,0 +1,299 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" + "time" +) + +func newReindexFunc(t Transport) Reindex { + return func(body io.Reader, o ...func(*ReindexRequest)) (*Response, error) { + var r = ReindexRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// Reindex allows to copy documents from one index to another, optionally filtering the source +// documents by a query, changing the destination index settings, or fetching the +// documents from a remote cluster. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-reindex.html. +// +type Reindex func(body io.Reader, o ...func(*ReindexRequest)) (*Response, error) + +// ReindexRequest configures the Reindex API request. +// +type ReindexRequest struct { + Body io.Reader + + MaxDocs *int + Refresh *bool + RequestsPerSecond *int + Scroll time.Duration + Slices *int + Timeout time.Duration + WaitForActiveShards string + WaitForCompletion *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ReindexRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(len("/_reindex")) + path.WriteString("/_reindex") + + params = make(map[string]string) + + if r.MaxDocs != nil { + params["max_docs"] = strconv.FormatInt(int64(*r.MaxDocs), 10) + } + + if r.Refresh != nil { + params["refresh"] = strconv.FormatBool(*r.Refresh) + } + + if r.RequestsPerSecond != nil { + params["requests_per_second"] = strconv.FormatInt(int64(*r.RequestsPerSecond), 10) + } + + if r.Scroll != 0 { + params["scroll"] = formatDuration(r.Scroll) + } + + if r.Slices != nil { + params["slices"] = strconv.FormatInt(int64(*r.Slices), 10) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.WaitForActiveShards != "" { + params["wait_for_active_shards"] = r.WaitForActiveShards + } + + if r.WaitForCompletion != nil { + params["wait_for_completion"] = strconv.FormatBool(*r.WaitForCompletion) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f Reindex) WithContext(v context.Context) func(*ReindexRequest) { + return func(r *ReindexRequest) { + r.ctx = v + } +} + +// WithMaxDocs - maximum number of documents to process (default: all documents). +// +func (f Reindex) WithMaxDocs(v int) func(*ReindexRequest) { + return func(r *ReindexRequest) { + r.MaxDocs = &v + } +} + +// WithRefresh - should the effected indexes be refreshed?. +// +func (f Reindex) WithRefresh(v bool) func(*ReindexRequest) { + return func(r *ReindexRequest) { + r.Refresh = &v + } +} + +// WithRequestsPerSecond - the throttle to set on this request in sub-requests per second. -1 means no throttle.. +// +func (f Reindex) WithRequestsPerSecond(v int) func(*ReindexRequest) { + return func(r *ReindexRequest) { + r.RequestsPerSecond = &v + } +} + +// WithScroll - control how long to keep the search context alive. +// +func (f Reindex) WithScroll(v time.Duration) func(*ReindexRequest) { + return func(r *ReindexRequest) { + r.Scroll = v + } +} + +// WithSlices - the number of slices this task should be divided into. defaults to 1 meaning the task isn't sliced into subtasks.. +// +func (f Reindex) WithSlices(v int) func(*ReindexRequest) { + return func(r *ReindexRequest) { + r.Slices = &v + } +} + +// WithTimeout - time each individual bulk request should wait for shards that are unavailable.. +// +func (f Reindex) WithTimeout(v time.Duration) func(*ReindexRequest) { + return func(r *ReindexRequest) { + r.Timeout = v + } +} + +// WithWaitForActiveShards - sets the number of shard copies that must be active before proceeding with the reindex operation. defaults to 1, meaning the primary shard only. set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1). +// +func (f Reindex) WithWaitForActiveShards(v string) func(*ReindexRequest) { + return func(r *ReindexRequest) { + r.WaitForActiveShards = v + } +} + +// WithWaitForCompletion - should the request should block until the reindex is complete.. +// +func (f Reindex) WithWaitForCompletion(v bool) func(*ReindexRequest) { + return func(r *ReindexRequest) { + r.WaitForCompletion = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f Reindex) WithPretty() func(*ReindexRequest) { + return func(r *ReindexRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f Reindex) WithHuman() func(*ReindexRequest) { + return func(r *ReindexRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f Reindex) WithErrorTrace() func(*ReindexRequest) { + return func(r *ReindexRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f Reindex) WithFilterPath(v ...string) func(*ReindexRequest) { + return func(r *ReindexRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f Reindex) WithHeader(h map[string]string) func(*ReindexRequest) { + return func(r *ReindexRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f Reindex) WithOpaqueID(s string) func(*ReindexRequest) { + return func(r *ReindexRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.reindex_rethrottle.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.reindex_rethrottle.go new file mode 100644 index 00000000000..a6f26b7a06e --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.reindex_rethrottle.go @@ -0,0 +1,205 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newReindexRethrottleFunc(t Transport) ReindexRethrottle { + return func(task_id string, requests_per_second *int, o ...func(*ReindexRethrottleRequest)) (*Response, error) { + var r = ReindexRethrottleRequest{TaskID: task_id, RequestsPerSecond: requests_per_second} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// ReindexRethrottle changes the number of requests per second for a particular Reindex operation. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-reindex.html. +// +type ReindexRethrottle func(task_id string, requests_per_second *int, o ...func(*ReindexRethrottleRequest)) (*Response, error) + +// ReindexRethrottleRequest configures the Reindex Rethrottle API request. +// +type ReindexRethrottleRequest struct { + TaskID string + + RequestsPerSecond *int + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ReindexRethrottleRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_reindex") + 1 + len(r.TaskID) + 1 + len("_rethrottle")) + path.WriteString("/") + path.WriteString("_reindex") + path.WriteString("/") + path.WriteString(r.TaskID) + path.WriteString("/") + path.WriteString("_rethrottle") + + params = make(map[string]string) + + if r.RequestsPerSecond != nil { + params["requests_per_second"] = strconv.FormatInt(int64(*r.RequestsPerSecond), 10) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f ReindexRethrottle) WithContext(v context.Context) func(*ReindexRethrottleRequest) { + return func(r *ReindexRethrottleRequest) { + r.ctx = v + } +} + +// WithRequestsPerSecond - the throttle to set on this request in floating sub-requests per second. -1 means set no throttle.. +// +func (f ReindexRethrottle) WithRequestsPerSecond(v int) func(*ReindexRethrottleRequest) { + return func(r *ReindexRethrottleRequest) { + r.RequestsPerSecond = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f ReindexRethrottle) WithPretty() func(*ReindexRethrottleRequest) { + return func(r *ReindexRethrottleRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f ReindexRethrottle) WithHuman() func(*ReindexRethrottleRequest) { + return func(r *ReindexRethrottleRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ReindexRethrottle) WithErrorTrace() func(*ReindexRethrottleRequest) { + return func(r *ReindexRethrottleRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f ReindexRethrottle) WithFilterPath(v ...string) func(*ReindexRethrottleRequest) { + return func(r *ReindexRethrottleRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f ReindexRethrottle) WithHeader(h map[string]string) func(*ReindexRethrottleRequest) { + return func(r *ReindexRethrottleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f ReindexRethrottle) WithOpaqueID(s string) func(*ReindexRethrottleRequest) { + return func(r *ReindexRethrottleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.render_search_template.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.render_search_template.go new file mode 100644 index 00000000000..d6e7304191a --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.render_search_template.go @@ -0,0 +1,215 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newRenderSearchTemplateFunc(t Transport) RenderSearchTemplate { + return func(o ...func(*RenderSearchTemplateRequest)) (*Response, error) { + var r = RenderSearchTemplateRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// RenderSearchTemplate allows to use the Mustache language to pre-render a search definition. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html#_validating_templates. +// +type RenderSearchTemplate func(o ...func(*RenderSearchTemplateRequest)) (*Response, error) + +// RenderSearchTemplateRequest configures the Render Search Template API request. +// +type RenderSearchTemplateRequest struct { + TemplateID string + + Body io.Reader + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r RenderSearchTemplateRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_render") + 1 + len("template") + 1 + len(r.TemplateID)) + path.WriteString("/") + path.WriteString("_render") + path.WriteString("/") + path.WriteString("template") + if r.TemplateID != "" { + path.WriteString("/") + path.WriteString(r.TemplateID) + } + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f RenderSearchTemplate) WithContext(v context.Context) func(*RenderSearchTemplateRequest) { + return func(r *RenderSearchTemplateRequest) { + r.ctx = v + } +} + +// WithBody - The search definition template and its params. +// +func (f RenderSearchTemplate) WithBody(v io.Reader) func(*RenderSearchTemplateRequest) { + return func(r *RenderSearchTemplateRequest) { + r.Body = v + } +} + +// WithTemplateID - the ID of the stored search template. +// +func (f RenderSearchTemplate) WithTemplateID(v string) func(*RenderSearchTemplateRequest) { + return func(r *RenderSearchTemplateRequest) { + r.TemplateID = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f RenderSearchTemplate) WithPretty() func(*RenderSearchTemplateRequest) { + return func(r *RenderSearchTemplateRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f RenderSearchTemplate) WithHuman() func(*RenderSearchTemplateRequest) { + return func(r *RenderSearchTemplateRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f RenderSearchTemplate) WithErrorTrace() func(*RenderSearchTemplateRequest) { + return func(r *RenderSearchTemplateRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f RenderSearchTemplate) WithFilterPath(v ...string) func(*RenderSearchTemplateRequest) { + return func(r *RenderSearchTemplateRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f RenderSearchTemplate) WithHeader(h map[string]string) func(*RenderSearchTemplateRequest) { + return func(r *RenderSearchTemplateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f RenderSearchTemplate) WithOpaqueID(s string) func(*RenderSearchTemplateRequest) { + return func(r *RenderSearchTemplateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.scripts_painless_context.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.scripts_painless_context.go new file mode 100644 index 00000000000..21c2987a4ff --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.scripts_painless_context.go @@ -0,0 +1,151 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package esapi + +import ( + "context" + "strings" +) + +func newScriptsPainlessContextFunc(t Transport) ScriptsPainlessContext { + return func(o ...func(*ScriptsPainlessContextRequest)) (*Response, error) { + var r = ScriptsPainlessContextRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// ScriptsPainlessContext allows to query context information. +// +type ScriptsPainlessContext func(o ...func(*ScriptsPainlessContextRequest)) (*Response, error) + +// ScriptsPainlessContextRequest configures the Scripts Painless Context API request. +// +type ScriptsPainlessContextRequest struct { + ScriptContext string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ScriptsPainlessContextRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_scripts/painless/_context")) + path.WriteString("/_scripts/painless/_context") + + params = make(map[string]string) + + if r.ScriptContext != "" { + params["context"] = r.ScriptContext + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, _ := newRequest(method, path.String(), nil) + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f ScriptsPainlessContext) WithContext(v context.Context) func(*ScriptsPainlessContextRequest) { + return func(r *ScriptsPainlessContextRequest) { + r.ctx = v + } +} + +// WithScriptContext - select a specific context to retrieve api information about. +// +func (f ScriptsPainlessContext) WithScriptContext(v string) func(*ScriptsPainlessContextRequest) { + return func(r *ScriptsPainlessContextRequest) { + r.ScriptContext = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f ScriptsPainlessContext) WithPretty() func(*ScriptsPainlessContextRequest) { + return func(r *ScriptsPainlessContextRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f ScriptsPainlessContext) WithHuman() func(*ScriptsPainlessContextRequest) { + return func(r *ScriptsPainlessContextRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ScriptsPainlessContext) WithErrorTrace() func(*ScriptsPainlessContextRequest) { + return func(r *ScriptsPainlessContextRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f ScriptsPainlessContext) WithFilterPath(v ...string) func(*ScriptsPainlessContextRequest) { + return func(r *ScriptsPainlessContextRequest) { + r.FilterPath = v + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.scripts_painless_execute.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.scripts_painless_execute.go new file mode 100644 index 00000000000..98852b0eceb --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.scripts_painless_execute.go @@ -0,0 +1,198 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newScriptsPainlessExecuteFunc(t Transport) ScriptsPainlessExecute { + return func(o ...func(*ScriptsPainlessExecuteRequest)) (*Response, error) { + var r = ScriptsPainlessExecuteRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// ScriptsPainlessExecute allows an arbitrary script to be executed and a result to be returned +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-execute-api.html. +// +type ScriptsPainlessExecute func(o ...func(*ScriptsPainlessExecuteRequest)) (*Response, error) + +// ScriptsPainlessExecuteRequest configures the Scripts Painless Execute API request. +// +type ScriptsPainlessExecuteRequest struct { + Body io.Reader + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ScriptsPainlessExecuteRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_scripts/painless/_execute")) + path.WriteString("/_scripts/painless/_execute") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f ScriptsPainlessExecute) WithContext(v context.Context) func(*ScriptsPainlessExecuteRequest) { + return func(r *ScriptsPainlessExecuteRequest) { + r.ctx = v + } +} + +// WithBody - The script to execute. +// +func (f ScriptsPainlessExecute) WithBody(v io.Reader) func(*ScriptsPainlessExecuteRequest) { + return func(r *ScriptsPainlessExecuteRequest) { + r.Body = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f ScriptsPainlessExecute) WithPretty() func(*ScriptsPainlessExecuteRequest) { + return func(r *ScriptsPainlessExecuteRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f ScriptsPainlessExecute) WithHuman() func(*ScriptsPainlessExecuteRequest) { + return func(r *ScriptsPainlessExecuteRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ScriptsPainlessExecute) WithErrorTrace() func(*ScriptsPainlessExecuteRequest) { + return func(r *ScriptsPainlessExecuteRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f ScriptsPainlessExecute) WithFilterPath(v ...string) func(*ScriptsPainlessExecuteRequest) { + return func(r *ScriptsPainlessExecuteRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f ScriptsPainlessExecute) WithHeader(h map[string]string) func(*ScriptsPainlessExecuteRequest) { + return func(r *ScriptsPainlessExecuteRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f ScriptsPainlessExecute) WithOpaqueID(s string) func(*ScriptsPainlessExecuteRequest) { + return func(r *ScriptsPainlessExecuteRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.scroll.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.scroll.go new file mode 100644 index 00000000000..cbf4d048a57 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.scroll.go @@ -0,0 +1,241 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" + "time" +) + +func newScrollFunc(t Transport) Scroll { + return func(o ...func(*ScrollRequest)) (*Response, error) { + var r = ScrollRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// Scroll allows to retrieve a large numbers of results from a single search request. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-body.html#request-body-search-scroll. +// +type Scroll func(o ...func(*ScrollRequest)) (*Response, error) + +// ScrollRequest configures the Scroll API request. +// +type ScrollRequest struct { + Body io.Reader + + ScrollID string + + RestTotalHitsAsInt *bool + Scroll time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ScrollRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_search/scroll")) + path.WriteString("/_search/scroll") + + params = make(map[string]string) + + if r.RestTotalHitsAsInt != nil { + params["rest_total_hits_as_int"] = strconv.FormatBool(*r.RestTotalHitsAsInt) + } + + if r.Scroll != 0 { + params["scroll"] = formatDuration(r.Scroll) + } + + if r.ScrollID != "" { + params["scroll_id"] = r.ScrollID + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f Scroll) WithContext(v context.Context) func(*ScrollRequest) { + return func(r *ScrollRequest) { + r.ctx = v + } +} + +// WithBody - The scroll ID if not passed by URL or query parameter.. +// +func (f Scroll) WithBody(v io.Reader) func(*ScrollRequest) { + return func(r *ScrollRequest) { + r.Body = v + } +} + +// WithScrollID - the scroll ID. +// +func (f Scroll) WithScrollID(v string) func(*ScrollRequest) { + return func(r *ScrollRequest) { + r.ScrollID = v + } +} + +// WithRestTotalHitsAsInt - indicates whether hits.total should be rendered as an integer or an object in the rest search response. +// +func (f Scroll) WithRestTotalHitsAsInt(v bool) func(*ScrollRequest) { + return func(r *ScrollRequest) { + r.RestTotalHitsAsInt = &v + } +} + +// WithScroll - specify how long a consistent view of the index should be maintained for scrolled search. +// +func (f Scroll) WithScroll(v time.Duration) func(*ScrollRequest) { + return func(r *ScrollRequest) { + r.Scroll = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f Scroll) WithPretty() func(*ScrollRequest) { + return func(r *ScrollRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f Scroll) WithHuman() func(*ScrollRequest) { + return func(r *ScrollRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f Scroll) WithErrorTrace() func(*ScrollRequest) { + return func(r *ScrollRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f Scroll) WithFilterPath(v ...string) func(*ScrollRequest) { + return func(r *ScrollRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f Scroll) WithHeader(h map[string]string) func(*ScrollRequest) { + return func(r *ScrollRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f Scroll) WithOpaqueID(s string) func(*ScrollRequest) { + return func(r *ScrollRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.search.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.search.go new file mode 100644 index 00000000000..81d1795ce79 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.search.go @@ -0,0 +1,763 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "fmt" + "io" + "net/http" + "strconv" + "strings" + "time" +) + +func newSearchFunc(t Transport) Search { + return func(o ...func(*SearchRequest)) (*Response, error) { + var r = SearchRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// Search returns results matching a query. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/search-search.html. +// +type Search func(o ...func(*SearchRequest)) (*Response, error) + +// SearchRequest configures the Search API request. +// +type SearchRequest struct { + Index []string + + Body io.Reader + + AllowNoIndices *bool + AllowPartialSearchResults *bool + Analyzer string + AnalyzeWildcard *bool + BatchedReduceSize *int + CcsMinimizeRoundtrips *bool + DefaultOperator string + Df string + DocvalueFields []string + ExpandWildcards string + Explain *bool + From *int + IgnoreThrottled *bool + IgnoreUnavailable *bool + Lenient *bool + MaxConcurrentShardRequests *int + Preference string + PreFilterShardSize *int + Query string + RequestCache *bool + RestTotalHitsAsInt *bool + Routing []string + Scroll time.Duration + SearchType string + SeqNoPrimaryTerm *bool + Size *int + Sort []string + Source []string + SourceExcludes []string + SourceIncludes []string + Stats []string + StoredFields []string + SuggestField string + SuggestMode string + SuggestSize *int + SuggestText string + TerminateAfter *int + Timeout time.Duration + TrackScores *bool + TrackTotalHits interface{} + TypedKeys *bool + Version *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SearchRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_search")) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_search") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.AllowPartialSearchResults != nil { + params["allow_partial_search_results"] = strconv.FormatBool(*r.AllowPartialSearchResults) + } + + if r.Analyzer != "" { + params["analyzer"] = r.Analyzer + } + + if r.AnalyzeWildcard != nil { + params["analyze_wildcard"] = strconv.FormatBool(*r.AnalyzeWildcard) + } + + if r.BatchedReduceSize != nil { + params["batched_reduce_size"] = strconv.FormatInt(int64(*r.BatchedReduceSize), 10) + } + + if r.CcsMinimizeRoundtrips != nil { + params["ccs_minimize_roundtrips"] = strconv.FormatBool(*r.CcsMinimizeRoundtrips) + } + + if r.DefaultOperator != "" { + params["default_operator"] = r.DefaultOperator + } + + if r.Df != "" { + params["df"] = r.Df + } + + if len(r.DocvalueFields) > 0 { + params["docvalue_fields"] = strings.Join(r.DocvalueFields, ",") + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.Explain != nil { + params["explain"] = strconv.FormatBool(*r.Explain) + } + + if r.From != nil { + params["from"] = strconv.FormatInt(int64(*r.From), 10) + } + + if r.IgnoreThrottled != nil { + params["ignore_throttled"] = strconv.FormatBool(*r.IgnoreThrottled) + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.Lenient != nil { + params["lenient"] = strconv.FormatBool(*r.Lenient) + } + + if r.MaxConcurrentShardRequests != nil { + params["max_concurrent_shard_requests"] = strconv.FormatInt(int64(*r.MaxConcurrentShardRequests), 10) + } + + if r.Preference != "" { + params["preference"] = r.Preference + } + + if r.PreFilterShardSize != nil { + params["pre_filter_shard_size"] = strconv.FormatInt(int64(*r.PreFilterShardSize), 10) + } + + if r.Query != "" { + params["q"] = r.Query + } + + if r.RequestCache != nil { + params["request_cache"] = strconv.FormatBool(*r.RequestCache) + } + + if r.RestTotalHitsAsInt != nil { + params["rest_total_hits_as_int"] = strconv.FormatBool(*r.RestTotalHitsAsInt) + } + + if len(r.Routing) > 0 { + params["routing"] = strings.Join(r.Routing, ",") + } + + if r.Scroll != 0 { + params["scroll"] = formatDuration(r.Scroll) + } + + if r.SearchType != "" { + params["search_type"] = r.SearchType + } + + if r.SeqNoPrimaryTerm != nil { + params["seq_no_primary_term"] = strconv.FormatBool(*r.SeqNoPrimaryTerm) + } + + if r.Size != nil { + params["size"] = strconv.FormatInt(int64(*r.Size), 10) + } + + if len(r.Sort) > 0 { + params["sort"] = strings.Join(r.Sort, ",") + } + + if len(r.Source) > 0 { + params["_source"] = strings.Join(r.Source, ",") + } + + if len(r.SourceExcludes) > 0 { + params["_source_excludes"] = strings.Join(r.SourceExcludes, ",") + } + + if len(r.SourceIncludes) > 0 { + params["_source_includes"] = strings.Join(r.SourceIncludes, ",") + } + + if len(r.Stats) > 0 { + params["stats"] = strings.Join(r.Stats, ",") + } + + if len(r.StoredFields) > 0 { + params["stored_fields"] = strings.Join(r.StoredFields, ",") + } + + if r.SuggestField != "" { + params["suggest_field"] = r.SuggestField + } + + if r.SuggestMode != "" { + params["suggest_mode"] = r.SuggestMode + } + + if r.SuggestSize != nil { + params["suggest_size"] = strconv.FormatInt(int64(*r.SuggestSize), 10) + } + + if r.SuggestText != "" { + params["suggest_text"] = r.SuggestText + } + + if r.TerminateAfter != nil { + params["terminate_after"] = strconv.FormatInt(int64(*r.TerminateAfter), 10) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.TrackScores != nil { + params["track_scores"] = strconv.FormatBool(*r.TrackScores) + } + + if r.TrackTotalHits != nil { + params["track_total_hits"] = fmt.Sprintf("%v", r.TrackTotalHits) + } + + if r.TypedKeys != nil { + params["typed_keys"] = strconv.FormatBool(*r.TypedKeys) + } + + if r.Version != nil { + params["version"] = strconv.FormatBool(*r.Version) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f Search) WithContext(v context.Context) func(*SearchRequest) { + return func(r *SearchRequest) { + r.ctx = v + } +} + +// WithBody - The search definition using the Query DSL. +// +func (f Search) WithBody(v io.Reader) func(*SearchRequest) { + return func(r *SearchRequest) { + r.Body = v + } +} + +// WithIndex - a list of index names to search; use _all to perform the operation on all indices. +// +func (f Search) WithIndex(v ...string) func(*SearchRequest) { + return func(r *SearchRequest) { + r.Index = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f Search) WithAllowNoIndices(v bool) func(*SearchRequest) { + return func(r *SearchRequest) { + r.AllowNoIndices = &v + } +} + +// WithAllowPartialSearchResults - indicate if an error should be returned if there is a partial search failure or timeout. +// +func (f Search) WithAllowPartialSearchResults(v bool) func(*SearchRequest) { + return func(r *SearchRequest) { + r.AllowPartialSearchResults = &v + } +} + +// WithAnalyzer - the analyzer to use for the query string. +// +func (f Search) WithAnalyzer(v string) func(*SearchRequest) { + return func(r *SearchRequest) { + r.Analyzer = v + } +} + +// WithAnalyzeWildcard - specify whether wildcard and prefix queries should be analyzed (default: false). +// +func (f Search) WithAnalyzeWildcard(v bool) func(*SearchRequest) { + return func(r *SearchRequest) { + r.AnalyzeWildcard = &v + } +} + +// WithBatchedReduceSize - the number of shard results that should be reduced at once on the coordinating node. this value should be used as a protection mechanism to reduce the memory overhead per search request if the potential number of shards in the request can be large.. +// +func (f Search) WithBatchedReduceSize(v int) func(*SearchRequest) { + return func(r *SearchRequest) { + r.BatchedReduceSize = &v + } +} + +// WithCcsMinimizeRoundtrips - indicates whether network round-trips should be minimized as part of cross-cluster search requests execution. +// +func (f Search) WithCcsMinimizeRoundtrips(v bool) func(*SearchRequest) { + return func(r *SearchRequest) { + r.CcsMinimizeRoundtrips = &v + } +} + +// WithDefaultOperator - the default operator for query string query (and or or). +// +func (f Search) WithDefaultOperator(v string) func(*SearchRequest) { + return func(r *SearchRequest) { + r.DefaultOperator = v + } +} + +// WithDf - the field to use as default where no field prefix is given in the query string. +// +func (f Search) WithDf(v string) func(*SearchRequest) { + return func(r *SearchRequest) { + r.Df = v + } +} + +// WithDocvalueFields - a list of fields to return as the docvalue representation of a field for each hit. +// +func (f Search) WithDocvalueFields(v ...string) func(*SearchRequest) { + return func(r *SearchRequest) { + r.DocvalueFields = v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f Search) WithExpandWildcards(v string) func(*SearchRequest) { + return func(r *SearchRequest) { + r.ExpandWildcards = v + } +} + +// WithExplain - specify whether to return detailed information about score computation as part of a hit. +// +func (f Search) WithExplain(v bool) func(*SearchRequest) { + return func(r *SearchRequest) { + r.Explain = &v + } +} + +// WithFrom - starting offset (default: 0). +// +func (f Search) WithFrom(v int) func(*SearchRequest) { + return func(r *SearchRequest) { + r.From = &v + } +} + +// WithIgnoreThrottled - whether specified concrete, expanded or aliased indices should be ignored when throttled. +// +func (f Search) WithIgnoreThrottled(v bool) func(*SearchRequest) { + return func(r *SearchRequest) { + r.IgnoreThrottled = &v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f Search) WithIgnoreUnavailable(v bool) func(*SearchRequest) { + return func(r *SearchRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithLenient - specify whether format-based query failures (such as providing text to a numeric field) should be ignored. +// +func (f Search) WithLenient(v bool) func(*SearchRequest) { + return func(r *SearchRequest) { + r.Lenient = &v + } +} + +// WithMaxConcurrentShardRequests - the number of concurrent shard requests per node this search executes concurrently. this value should be used to limit the impact of the search on the cluster in order to limit the number of concurrent shard requests. +// +func (f Search) WithMaxConcurrentShardRequests(v int) func(*SearchRequest) { + return func(r *SearchRequest) { + r.MaxConcurrentShardRequests = &v + } +} + +// WithPreference - specify the node or shard the operation should be performed on (default: random). +// +func (f Search) WithPreference(v string) func(*SearchRequest) { + return func(r *SearchRequest) { + r.Preference = v + } +} + +// WithPreFilterShardSize - a threshold that enforces a pre-filter roundtrip to prefilter search shards based on query rewriting if the number of shards the search request expands to exceeds the threshold. this filter roundtrip can limit the number of shards significantly if for instance a shard can not match any documents based on it's rewrite method ie. if date filters are mandatory to match but the shard bounds and the query are disjoint.. +// +func (f Search) WithPreFilterShardSize(v int) func(*SearchRequest) { + return func(r *SearchRequest) { + r.PreFilterShardSize = &v + } +} + +// WithQuery - query in the lucene query string syntax. +// +func (f Search) WithQuery(v string) func(*SearchRequest) { + return func(r *SearchRequest) { + r.Query = v + } +} + +// WithRequestCache - specify if request cache should be used for this request or not, defaults to index level setting. +// +func (f Search) WithRequestCache(v bool) func(*SearchRequest) { + return func(r *SearchRequest) { + r.RequestCache = &v + } +} + +// WithRestTotalHitsAsInt - indicates whether hits.total should be rendered as an integer or an object in the rest search response. +// +func (f Search) WithRestTotalHitsAsInt(v bool) func(*SearchRequest) { + return func(r *SearchRequest) { + r.RestTotalHitsAsInt = &v + } +} + +// WithRouting - a list of specific routing values. +// +func (f Search) WithRouting(v ...string) func(*SearchRequest) { + return func(r *SearchRequest) { + r.Routing = v + } +} + +// WithScroll - specify how long a consistent view of the index should be maintained for scrolled search. +// +func (f Search) WithScroll(v time.Duration) func(*SearchRequest) { + return func(r *SearchRequest) { + r.Scroll = v + } +} + +// WithSearchType - search operation type. +// +func (f Search) WithSearchType(v string) func(*SearchRequest) { + return func(r *SearchRequest) { + r.SearchType = v + } +} + +// WithSeqNoPrimaryTerm - specify whether to return sequence number and primary term of the last modification of each hit. +// +func (f Search) WithSeqNoPrimaryTerm(v bool) func(*SearchRequest) { + return func(r *SearchRequest) { + r.SeqNoPrimaryTerm = &v + } +} + +// WithSize - number of hits to return (default: 10). +// +func (f Search) WithSize(v int) func(*SearchRequest) { + return func(r *SearchRequest) { + r.Size = &v + } +} + +// WithSort - a list of : pairs. +// +func (f Search) WithSort(v ...string) func(*SearchRequest) { + return func(r *SearchRequest) { + r.Sort = v + } +} + +// WithSource - true or false to return the _source field or not, or a list of fields to return. +// +func (f Search) WithSource(v ...string) func(*SearchRequest) { + return func(r *SearchRequest) { + r.Source = v + } +} + +// WithSourceExcludes - a list of fields to exclude from the returned _source field. +// +func (f Search) WithSourceExcludes(v ...string) func(*SearchRequest) { + return func(r *SearchRequest) { + r.SourceExcludes = v + } +} + +// WithSourceIncludes - a list of fields to extract and return from the _source field. +// +func (f Search) WithSourceIncludes(v ...string) func(*SearchRequest) { + return func(r *SearchRequest) { + r.SourceIncludes = v + } +} + +// WithStats - specific 'tag' of the request for logging and statistical purposes. +// +func (f Search) WithStats(v ...string) func(*SearchRequest) { + return func(r *SearchRequest) { + r.Stats = v + } +} + +// WithStoredFields - a list of stored fields to return as part of a hit. +// +func (f Search) WithStoredFields(v ...string) func(*SearchRequest) { + return func(r *SearchRequest) { + r.StoredFields = v + } +} + +// WithSuggestField - specify which field to use for suggestions. +// +func (f Search) WithSuggestField(v string) func(*SearchRequest) { + return func(r *SearchRequest) { + r.SuggestField = v + } +} + +// WithSuggestMode - specify suggest mode. +// +func (f Search) WithSuggestMode(v string) func(*SearchRequest) { + return func(r *SearchRequest) { + r.SuggestMode = v + } +} + +// WithSuggestSize - how many suggestions to return in response. +// +func (f Search) WithSuggestSize(v int) func(*SearchRequest) { + return func(r *SearchRequest) { + r.SuggestSize = &v + } +} + +// WithSuggestText - the source text for which the suggestions should be returned. +// +func (f Search) WithSuggestText(v string) func(*SearchRequest) { + return func(r *SearchRequest) { + r.SuggestText = v + } +} + +// WithTerminateAfter - the maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early.. +// +func (f Search) WithTerminateAfter(v int) func(*SearchRequest) { + return func(r *SearchRequest) { + r.TerminateAfter = &v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f Search) WithTimeout(v time.Duration) func(*SearchRequest) { + return func(r *SearchRequest) { + r.Timeout = v + } +} + +// WithTrackScores - whether to calculate and return scores even if they are not used for sorting. +// +func (f Search) WithTrackScores(v bool) func(*SearchRequest) { + return func(r *SearchRequest) { + r.TrackScores = &v + } +} + +// WithTrackTotalHits - indicate if the number of documents that match the query should be tracked. +// +func (f Search) WithTrackTotalHits(v interface{}) func(*SearchRequest) { + return func(r *SearchRequest) { + r.TrackTotalHits = v + } +} + +// WithTypedKeys - specify whether aggregation and suggester names should be prefixed by their respective types in the response. +// +func (f Search) WithTypedKeys(v bool) func(*SearchRequest) { + return func(r *SearchRequest) { + r.TypedKeys = &v + } +} + +// WithVersion - specify whether to return document version as part of a hit. +// +func (f Search) WithVersion(v bool) func(*SearchRequest) { + return func(r *SearchRequest) { + r.Version = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f Search) WithPretty() func(*SearchRequest) { + return func(r *SearchRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f Search) WithHuman() func(*SearchRequest) { + return func(r *SearchRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f Search) WithErrorTrace() func(*SearchRequest) { + return func(r *SearchRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f Search) WithFilterPath(v ...string) func(*SearchRequest) { + return func(r *SearchRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f Search) WithHeader(h map[string]string) func(*SearchRequest) { + return func(r *SearchRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f Search) WithOpaqueID(s string) func(*SearchRequest) { + return func(r *SearchRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.search_shards.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.search_shards.go new file mode 100644 index 00000000000..a97c6581904 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.search_shards.go @@ -0,0 +1,278 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newSearchShardsFunc(t Transport) SearchShards { + return func(o ...func(*SearchShardsRequest)) (*Response, error) { + var r = SearchShardsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SearchShards returns information about the indices and shards that a search request would be executed against. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/search-shards.html. +// +type SearchShards func(o ...func(*SearchShardsRequest)) (*Response, error) + +// SearchShardsRequest configures the Search Shards API request. +// +type SearchShardsRequest struct { + Index []string + + AllowNoIndices *bool + ExpandWildcards string + IgnoreUnavailable *bool + Local *bool + Preference string + Routing string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SearchShardsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_search_shards")) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_search_shards") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.Preference != "" { + params["preference"] = r.Preference + } + + if r.Routing != "" { + params["routing"] = r.Routing + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SearchShards) WithContext(v context.Context) func(*SearchShardsRequest) { + return func(r *SearchShardsRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names to search; use _all to perform the operation on all indices. +// +func (f SearchShards) WithIndex(v ...string) func(*SearchShardsRequest) { + return func(r *SearchShardsRequest) { + r.Index = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f SearchShards) WithAllowNoIndices(v bool) func(*SearchShardsRequest) { + return func(r *SearchShardsRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f SearchShards) WithExpandWildcards(v string) func(*SearchShardsRequest) { + return func(r *SearchShardsRequest) { + r.ExpandWildcards = v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f SearchShards) WithIgnoreUnavailable(v bool) func(*SearchShardsRequest) { + return func(r *SearchShardsRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f SearchShards) WithLocal(v bool) func(*SearchShardsRequest) { + return func(r *SearchShardsRequest) { + r.Local = &v + } +} + +// WithPreference - specify the node or shard the operation should be performed on (default: random). +// +func (f SearchShards) WithPreference(v string) func(*SearchShardsRequest) { + return func(r *SearchShardsRequest) { + r.Preference = v + } +} + +// WithRouting - specific routing value. +// +func (f SearchShards) WithRouting(v string) func(*SearchShardsRequest) { + return func(r *SearchShardsRequest) { + r.Routing = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SearchShards) WithPretty() func(*SearchShardsRequest) { + return func(r *SearchShardsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SearchShards) WithHuman() func(*SearchShardsRequest) { + return func(r *SearchShardsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SearchShards) WithErrorTrace() func(*SearchShardsRequest) { + return func(r *SearchShardsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SearchShards) WithFilterPath(v ...string) func(*SearchShardsRequest) { + return func(r *SearchShardsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SearchShards) WithHeader(h map[string]string) func(*SearchShardsRequest) { + return func(r *SearchShardsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SearchShards) WithOpaqueID(s string) func(*SearchShardsRequest) { + return func(r *SearchShardsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.search_template.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.search_template.go new file mode 100644 index 00000000000..a2a6348903c --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.search_template.go @@ -0,0 +1,379 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" + "time" +) + +func newSearchTemplateFunc(t Transport) SearchTemplate { + return func(body io.Reader, o ...func(*SearchTemplateRequest)) (*Response, error) { + var r = SearchTemplateRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SearchTemplate allows to use the Mustache language to pre-render a search definition. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html. +// +type SearchTemplate func(body io.Reader, o ...func(*SearchTemplateRequest)) (*Response, error) + +// SearchTemplateRequest configures the Search Template API request. +// +type SearchTemplateRequest struct { + Index []string + + Body io.Reader + + AllowNoIndices *bool + CcsMinimizeRoundtrips *bool + ExpandWildcards string + Explain *bool + IgnoreThrottled *bool + IgnoreUnavailable *bool + Preference string + Profile *bool + RestTotalHitsAsInt *bool + Routing []string + Scroll time.Duration + SearchType string + TypedKeys *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SearchTemplateRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_search") + 1 + len("template")) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_search") + path.WriteString("/") + path.WriteString("template") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.CcsMinimizeRoundtrips != nil { + params["ccs_minimize_roundtrips"] = strconv.FormatBool(*r.CcsMinimizeRoundtrips) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.Explain != nil { + params["explain"] = strconv.FormatBool(*r.Explain) + } + + if r.IgnoreThrottled != nil { + params["ignore_throttled"] = strconv.FormatBool(*r.IgnoreThrottled) + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.Preference != "" { + params["preference"] = r.Preference + } + + if r.Profile != nil { + params["profile"] = strconv.FormatBool(*r.Profile) + } + + if r.RestTotalHitsAsInt != nil { + params["rest_total_hits_as_int"] = strconv.FormatBool(*r.RestTotalHitsAsInt) + } + + if len(r.Routing) > 0 { + params["routing"] = strings.Join(r.Routing, ",") + } + + if r.Scroll != 0 { + params["scroll"] = formatDuration(r.Scroll) + } + + if r.SearchType != "" { + params["search_type"] = r.SearchType + } + + if r.TypedKeys != nil { + params["typed_keys"] = strconv.FormatBool(*r.TypedKeys) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SearchTemplate) WithContext(v context.Context) func(*SearchTemplateRequest) { + return func(r *SearchTemplateRequest) { + r.ctx = v + } +} + +// WithIndex - a list of index names to search; use _all to perform the operation on all indices. +// +func (f SearchTemplate) WithIndex(v ...string) func(*SearchTemplateRequest) { + return func(r *SearchTemplateRequest) { + r.Index = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f SearchTemplate) WithAllowNoIndices(v bool) func(*SearchTemplateRequest) { + return func(r *SearchTemplateRequest) { + r.AllowNoIndices = &v + } +} + +// WithCcsMinimizeRoundtrips - indicates whether network round-trips should be minimized as part of cross-cluster search requests execution. +// +func (f SearchTemplate) WithCcsMinimizeRoundtrips(v bool) func(*SearchTemplateRequest) { + return func(r *SearchTemplateRequest) { + r.CcsMinimizeRoundtrips = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f SearchTemplate) WithExpandWildcards(v string) func(*SearchTemplateRequest) { + return func(r *SearchTemplateRequest) { + r.ExpandWildcards = v + } +} + +// WithExplain - specify whether to return detailed information about score computation as part of a hit. +// +func (f SearchTemplate) WithExplain(v bool) func(*SearchTemplateRequest) { + return func(r *SearchTemplateRequest) { + r.Explain = &v + } +} + +// WithIgnoreThrottled - whether specified concrete, expanded or aliased indices should be ignored when throttled. +// +func (f SearchTemplate) WithIgnoreThrottled(v bool) func(*SearchTemplateRequest) { + return func(r *SearchTemplateRequest) { + r.IgnoreThrottled = &v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f SearchTemplate) WithIgnoreUnavailable(v bool) func(*SearchTemplateRequest) { + return func(r *SearchTemplateRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithPreference - specify the node or shard the operation should be performed on (default: random). +// +func (f SearchTemplate) WithPreference(v string) func(*SearchTemplateRequest) { + return func(r *SearchTemplateRequest) { + r.Preference = v + } +} + +// WithProfile - specify whether to profile the query execution. +// +func (f SearchTemplate) WithProfile(v bool) func(*SearchTemplateRequest) { + return func(r *SearchTemplateRequest) { + r.Profile = &v + } +} + +// WithRestTotalHitsAsInt - indicates whether hits.total should be rendered as an integer or an object in the rest search response. +// +func (f SearchTemplate) WithRestTotalHitsAsInt(v bool) func(*SearchTemplateRequest) { + return func(r *SearchTemplateRequest) { + r.RestTotalHitsAsInt = &v + } +} + +// WithRouting - a list of specific routing values. +// +func (f SearchTemplate) WithRouting(v ...string) func(*SearchTemplateRequest) { + return func(r *SearchTemplateRequest) { + r.Routing = v + } +} + +// WithScroll - specify how long a consistent view of the index should be maintained for scrolled search. +// +func (f SearchTemplate) WithScroll(v time.Duration) func(*SearchTemplateRequest) { + return func(r *SearchTemplateRequest) { + r.Scroll = v + } +} + +// WithSearchType - search operation type. +// +func (f SearchTemplate) WithSearchType(v string) func(*SearchTemplateRequest) { + return func(r *SearchTemplateRequest) { + r.SearchType = v + } +} + +// WithTypedKeys - specify whether aggregation and suggester names should be prefixed by their respective types in the response. +// +func (f SearchTemplate) WithTypedKeys(v bool) func(*SearchTemplateRequest) { + return func(r *SearchTemplateRequest) { + r.TypedKeys = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SearchTemplate) WithPretty() func(*SearchTemplateRequest) { + return func(r *SearchTemplateRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SearchTemplate) WithHuman() func(*SearchTemplateRequest) { + return func(r *SearchTemplateRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SearchTemplate) WithErrorTrace() func(*SearchTemplateRequest) { + return func(r *SearchTemplateRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SearchTemplate) WithFilterPath(v ...string) func(*SearchTemplateRequest) { + return func(r *SearchTemplateRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SearchTemplate) WithHeader(h map[string]string) func(*SearchTemplateRequest) { + return func(r *SearchTemplateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SearchTemplate) WithOpaqueID(s string) func(*SearchTemplateRequest) { + return func(r *SearchTemplateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.cleanup_repository.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.cleanup_repository.go new file mode 100644 index 00000000000..33b44037773 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.cleanup_repository.go @@ -0,0 +1,233 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" + "time" +) + +func newSnapshotCleanupRepositoryFunc(t Transport) SnapshotCleanupRepository { + return func(repository string, o ...func(*SnapshotCleanupRepositoryRequest)) (*Response, error) { + var r = SnapshotCleanupRepositoryRequest{Repository: repository} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SnapshotCleanupRepository removes stale data from repository. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html. +// +type SnapshotCleanupRepository func(repository string, o ...func(*SnapshotCleanupRepositoryRequest)) (*Response, error) + +// SnapshotCleanupRepositoryRequest configures the Snapshot Cleanup Repository API request. +// +type SnapshotCleanupRepositoryRequest struct { + Body io.Reader + + Repository string + + MasterTimeout time.Duration + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SnapshotCleanupRepositoryRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_snapshot") + 1 + len(r.Repository) + 1 + len("_cleanup")) + path.WriteString("/") + path.WriteString("_snapshot") + path.WriteString("/") + path.WriteString(r.Repository) + path.WriteString("/") + path.WriteString("_cleanup") + + params = make(map[string]string) + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SnapshotCleanupRepository) WithContext(v context.Context) func(*SnapshotCleanupRepositoryRequest) { + return func(r *SnapshotCleanupRepositoryRequest) { + r.ctx = v + } +} + +// WithBody - . +// +func (f SnapshotCleanupRepository) WithBody(v io.Reader) func(*SnapshotCleanupRepositoryRequest) { + return func(r *SnapshotCleanupRepositoryRequest) { + r.Body = v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f SnapshotCleanupRepository) WithMasterTimeout(v time.Duration) func(*SnapshotCleanupRepositoryRequest) { + return func(r *SnapshotCleanupRepositoryRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f SnapshotCleanupRepository) WithTimeout(v time.Duration) func(*SnapshotCleanupRepositoryRequest) { + return func(r *SnapshotCleanupRepositoryRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SnapshotCleanupRepository) WithPretty() func(*SnapshotCleanupRepositoryRequest) { + return func(r *SnapshotCleanupRepositoryRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SnapshotCleanupRepository) WithHuman() func(*SnapshotCleanupRepositoryRequest) { + return func(r *SnapshotCleanupRepositoryRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SnapshotCleanupRepository) WithErrorTrace() func(*SnapshotCleanupRepositoryRequest) { + return func(r *SnapshotCleanupRepositoryRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SnapshotCleanupRepository) WithFilterPath(v ...string) func(*SnapshotCleanupRepositoryRequest) { + return func(r *SnapshotCleanupRepositoryRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SnapshotCleanupRepository) WithHeader(h map[string]string) func(*SnapshotCleanupRepositoryRequest) { + return func(r *SnapshotCleanupRepositoryRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SnapshotCleanupRepository) WithOpaqueID(s string) func(*SnapshotCleanupRepositoryRequest) { + return func(r *SnapshotCleanupRepositoryRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.create.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.create.go new file mode 100644 index 00000000000..f82a25e7145 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.create.go @@ -0,0 +1,235 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" + "time" +) + +func newSnapshotCreateFunc(t Transport) SnapshotCreate { + return func(repository string, snapshot string, o ...func(*SnapshotCreateRequest)) (*Response, error) { + var r = SnapshotCreateRequest{Repository: repository, Snapshot: snapshot} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SnapshotCreate creates a snapshot in a repository. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html. +// +type SnapshotCreate func(repository string, snapshot string, o ...func(*SnapshotCreateRequest)) (*Response, error) + +// SnapshotCreateRequest configures the Snapshot Create API request. +// +type SnapshotCreateRequest struct { + Body io.Reader + + Repository string + Snapshot string + + MasterTimeout time.Duration + WaitForCompletion *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SnapshotCreateRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_snapshot") + 1 + len(r.Repository) + 1 + len(r.Snapshot)) + path.WriteString("/") + path.WriteString("_snapshot") + path.WriteString("/") + path.WriteString(r.Repository) + path.WriteString("/") + path.WriteString(r.Snapshot) + + params = make(map[string]string) + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.WaitForCompletion != nil { + params["wait_for_completion"] = strconv.FormatBool(*r.WaitForCompletion) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SnapshotCreate) WithContext(v context.Context) func(*SnapshotCreateRequest) { + return func(r *SnapshotCreateRequest) { + r.ctx = v + } +} + +// WithBody - The snapshot definition. +// +func (f SnapshotCreate) WithBody(v io.Reader) func(*SnapshotCreateRequest) { + return func(r *SnapshotCreateRequest) { + r.Body = v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f SnapshotCreate) WithMasterTimeout(v time.Duration) func(*SnapshotCreateRequest) { + return func(r *SnapshotCreateRequest) { + r.MasterTimeout = v + } +} + +// WithWaitForCompletion - should this request wait until the operation has completed before returning. +// +func (f SnapshotCreate) WithWaitForCompletion(v bool) func(*SnapshotCreateRequest) { + return func(r *SnapshotCreateRequest) { + r.WaitForCompletion = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SnapshotCreate) WithPretty() func(*SnapshotCreateRequest) { + return func(r *SnapshotCreateRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SnapshotCreate) WithHuman() func(*SnapshotCreateRequest) { + return func(r *SnapshotCreateRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SnapshotCreate) WithErrorTrace() func(*SnapshotCreateRequest) { + return func(r *SnapshotCreateRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SnapshotCreate) WithFilterPath(v ...string) func(*SnapshotCreateRequest) { + return func(r *SnapshotCreateRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SnapshotCreate) WithHeader(h map[string]string) func(*SnapshotCreateRequest) { + return func(r *SnapshotCreateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SnapshotCreate) WithOpaqueID(s string) func(*SnapshotCreateRequest) { + return func(r *SnapshotCreateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.create_repository.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.create_repository.go new file mode 100644 index 00000000000..c1c2c7520b8 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.create_repository.go @@ -0,0 +1,237 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" + "time" +) + +func newSnapshotCreateRepositoryFunc(t Transport) SnapshotCreateRepository { + return func(repository string, body io.Reader, o ...func(*SnapshotCreateRepositoryRequest)) (*Response, error) { + var r = SnapshotCreateRepositoryRequest{Repository: repository, Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SnapshotCreateRepository creates a repository. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html. +// +type SnapshotCreateRepository func(repository string, body io.Reader, o ...func(*SnapshotCreateRepositoryRequest)) (*Response, error) + +// SnapshotCreateRepositoryRequest configures the Snapshot Create Repository API request. +// +type SnapshotCreateRepositoryRequest struct { + Body io.Reader + + Repository string + + MasterTimeout time.Duration + Timeout time.Duration + Verify *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SnapshotCreateRepositoryRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_snapshot") + 1 + len(r.Repository)) + path.WriteString("/") + path.WriteString("_snapshot") + path.WriteString("/") + path.WriteString(r.Repository) + + params = make(map[string]string) + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Verify != nil { + params["verify"] = strconv.FormatBool(*r.Verify) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SnapshotCreateRepository) WithContext(v context.Context) func(*SnapshotCreateRepositoryRequest) { + return func(r *SnapshotCreateRepositoryRequest) { + r.ctx = v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f SnapshotCreateRepository) WithMasterTimeout(v time.Duration) func(*SnapshotCreateRepositoryRequest) { + return func(r *SnapshotCreateRepositoryRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f SnapshotCreateRepository) WithTimeout(v time.Duration) func(*SnapshotCreateRepositoryRequest) { + return func(r *SnapshotCreateRepositoryRequest) { + r.Timeout = v + } +} + +// WithVerify - whether to verify the repository after creation. +// +func (f SnapshotCreateRepository) WithVerify(v bool) func(*SnapshotCreateRepositoryRequest) { + return func(r *SnapshotCreateRepositoryRequest) { + r.Verify = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SnapshotCreateRepository) WithPretty() func(*SnapshotCreateRepositoryRequest) { + return func(r *SnapshotCreateRepositoryRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SnapshotCreateRepository) WithHuman() func(*SnapshotCreateRepositoryRequest) { + return func(r *SnapshotCreateRepositoryRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SnapshotCreateRepository) WithErrorTrace() func(*SnapshotCreateRepositoryRequest) { + return func(r *SnapshotCreateRepositoryRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SnapshotCreateRepository) WithFilterPath(v ...string) func(*SnapshotCreateRepositoryRequest) { + return func(r *SnapshotCreateRepositoryRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SnapshotCreateRepository) WithHeader(h map[string]string) func(*SnapshotCreateRepositoryRequest) { + return func(r *SnapshotCreateRepositoryRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SnapshotCreateRepository) WithOpaqueID(s string) func(*SnapshotCreateRepositoryRequest) { + return func(r *SnapshotCreateRepositoryRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.delete.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.delete.go new file mode 100644 index 00000000000..d6d53b9c55a --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.delete.go @@ -0,0 +1,206 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" + "time" +) + +func newSnapshotDeleteFunc(t Transport) SnapshotDelete { + return func(repository string, snapshot string, o ...func(*SnapshotDeleteRequest)) (*Response, error) { + var r = SnapshotDeleteRequest{Repository: repository, Snapshot: snapshot} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SnapshotDelete deletes a snapshot. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html. +// +type SnapshotDelete func(repository string, snapshot string, o ...func(*SnapshotDeleteRequest)) (*Response, error) + +// SnapshotDeleteRequest configures the Snapshot Delete API request. +// +type SnapshotDeleteRequest struct { + Repository string + Snapshot string + + MasterTimeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SnapshotDeleteRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_snapshot") + 1 + len(r.Repository) + 1 + len(r.Snapshot)) + path.WriteString("/") + path.WriteString("_snapshot") + path.WriteString("/") + path.WriteString(r.Repository) + path.WriteString("/") + path.WriteString(r.Snapshot) + + params = make(map[string]string) + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SnapshotDelete) WithContext(v context.Context) func(*SnapshotDeleteRequest) { + return func(r *SnapshotDeleteRequest) { + r.ctx = v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f SnapshotDelete) WithMasterTimeout(v time.Duration) func(*SnapshotDeleteRequest) { + return func(r *SnapshotDeleteRequest) { + r.MasterTimeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SnapshotDelete) WithPretty() func(*SnapshotDeleteRequest) { + return func(r *SnapshotDeleteRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SnapshotDelete) WithHuman() func(*SnapshotDeleteRequest) { + return func(r *SnapshotDeleteRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SnapshotDelete) WithErrorTrace() func(*SnapshotDeleteRequest) { + return func(r *SnapshotDeleteRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SnapshotDelete) WithFilterPath(v ...string) func(*SnapshotDeleteRequest) { + return func(r *SnapshotDeleteRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SnapshotDelete) WithHeader(h map[string]string) func(*SnapshotDeleteRequest) { + return func(r *SnapshotDeleteRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SnapshotDelete) WithOpaqueID(s string) func(*SnapshotDeleteRequest) { + return func(r *SnapshotDeleteRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.delete_repository.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.delete_repository.go new file mode 100644 index 00000000000..3d5b48cecdd --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.delete_repository.go @@ -0,0 +1,216 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" + "time" +) + +func newSnapshotDeleteRepositoryFunc(t Transport) SnapshotDeleteRepository { + return func(repository []string, o ...func(*SnapshotDeleteRepositoryRequest)) (*Response, error) { + var r = SnapshotDeleteRepositoryRequest{Repository: repository} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SnapshotDeleteRepository deletes a repository. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html. +// +type SnapshotDeleteRepository func(repository []string, o ...func(*SnapshotDeleteRepositoryRequest)) (*Response, error) + +// SnapshotDeleteRepositoryRequest configures the Snapshot Delete Repository API request. +// +type SnapshotDeleteRepositoryRequest struct { + Repository []string + + MasterTimeout time.Duration + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SnapshotDeleteRepositoryRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_snapshot") + 1 + len(strings.Join(r.Repository, ","))) + path.WriteString("/") + path.WriteString("_snapshot") + path.WriteString("/") + path.WriteString(strings.Join(r.Repository, ",")) + + params = make(map[string]string) + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SnapshotDeleteRepository) WithContext(v context.Context) func(*SnapshotDeleteRepositoryRequest) { + return func(r *SnapshotDeleteRepositoryRequest) { + r.ctx = v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f SnapshotDeleteRepository) WithMasterTimeout(v time.Duration) func(*SnapshotDeleteRepositoryRequest) { + return func(r *SnapshotDeleteRepositoryRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f SnapshotDeleteRepository) WithTimeout(v time.Duration) func(*SnapshotDeleteRepositoryRequest) { + return func(r *SnapshotDeleteRepositoryRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SnapshotDeleteRepository) WithPretty() func(*SnapshotDeleteRepositoryRequest) { + return func(r *SnapshotDeleteRepositoryRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SnapshotDeleteRepository) WithHuman() func(*SnapshotDeleteRepositoryRequest) { + return func(r *SnapshotDeleteRepositoryRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SnapshotDeleteRepository) WithErrorTrace() func(*SnapshotDeleteRepositoryRequest) { + return func(r *SnapshotDeleteRepositoryRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SnapshotDeleteRepository) WithFilterPath(v ...string) func(*SnapshotDeleteRepositoryRequest) { + return func(r *SnapshotDeleteRepositoryRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SnapshotDeleteRepository) WithHeader(h map[string]string) func(*SnapshotDeleteRepositoryRequest) { + return func(r *SnapshotDeleteRepositoryRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SnapshotDeleteRepository) WithOpaqueID(s string) func(*SnapshotDeleteRepositoryRequest) { + return func(r *SnapshotDeleteRepositoryRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.get.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.get.go new file mode 100644 index 00000000000..69f7614b8d6 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.get.go @@ -0,0 +1,233 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newSnapshotGetFunc(t Transport) SnapshotGet { + return func(repository string, snapshot []string, o ...func(*SnapshotGetRequest)) (*Response, error) { + var r = SnapshotGetRequest{Repository: repository, Snapshot: snapshot} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SnapshotGet returns information about a snapshot. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html. +// +type SnapshotGet func(repository string, snapshot []string, o ...func(*SnapshotGetRequest)) (*Response, error) + +// SnapshotGetRequest configures the Snapshot Get API request. +// +type SnapshotGetRequest struct { + Repository string + Snapshot []string + + IgnoreUnavailable *bool + MasterTimeout time.Duration + Verbose *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SnapshotGetRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_snapshot") + 1 + len(r.Repository) + 1 + len(strings.Join(r.Snapshot, ","))) + path.WriteString("/") + path.WriteString("_snapshot") + path.WriteString("/") + path.WriteString(r.Repository) + path.WriteString("/") + path.WriteString(strings.Join(r.Snapshot, ",")) + + params = make(map[string]string) + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Verbose != nil { + params["verbose"] = strconv.FormatBool(*r.Verbose) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SnapshotGet) WithContext(v context.Context) func(*SnapshotGetRequest) { + return func(r *SnapshotGetRequest) { + r.ctx = v + } +} + +// WithIgnoreUnavailable - whether to ignore unavailable snapshots, defaults to false which means a snapshotmissingexception is thrown. +// +func (f SnapshotGet) WithIgnoreUnavailable(v bool) func(*SnapshotGetRequest) { + return func(r *SnapshotGetRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f SnapshotGet) WithMasterTimeout(v time.Duration) func(*SnapshotGetRequest) { + return func(r *SnapshotGetRequest) { + r.MasterTimeout = v + } +} + +// WithVerbose - whether to show verbose snapshot info or only show the basic info found in the repository index blob. +// +func (f SnapshotGet) WithVerbose(v bool) func(*SnapshotGetRequest) { + return func(r *SnapshotGetRequest) { + r.Verbose = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SnapshotGet) WithPretty() func(*SnapshotGetRequest) { + return func(r *SnapshotGetRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SnapshotGet) WithHuman() func(*SnapshotGetRequest) { + return func(r *SnapshotGetRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SnapshotGet) WithErrorTrace() func(*SnapshotGetRequest) { + return func(r *SnapshotGetRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SnapshotGet) WithFilterPath(v ...string) func(*SnapshotGetRequest) { + return func(r *SnapshotGetRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SnapshotGet) WithHeader(h map[string]string) func(*SnapshotGetRequest) { + return func(r *SnapshotGetRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SnapshotGet) WithOpaqueID(s string) func(*SnapshotGetRequest) { + return func(r *SnapshotGetRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.get_repository.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.get_repository.go new file mode 100644 index 00000000000..e38370f2204 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.get_repository.go @@ -0,0 +1,227 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newSnapshotGetRepositoryFunc(t Transport) SnapshotGetRepository { + return func(o ...func(*SnapshotGetRepositoryRequest)) (*Response, error) { + var r = SnapshotGetRepositoryRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SnapshotGetRepository returns information about a repository. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html. +// +type SnapshotGetRepository func(o ...func(*SnapshotGetRepositoryRequest)) (*Response, error) + +// SnapshotGetRepositoryRequest configures the Snapshot Get Repository API request. +// +type SnapshotGetRepositoryRequest struct { + Repository []string + + Local *bool + MasterTimeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SnapshotGetRepositoryRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_snapshot") + 1 + len(strings.Join(r.Repository, ","))) + path.WriteString("/") + path.WriteString("_snapshot") + if len(r.Repository) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Repository, ",")) + } + + params = make(map[string]string) + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SnapshotGetRepository) WithContext(v context.Context) func(*SnapshotGetRepositoryRequest) { + return func(r *SnapshotGetRepositoryRequest) { + r.ctx = v + } +} + +// WithRepository - a list of repository names. +// +func (f SnapshotGetRepository) WithRepository(v ...string) func(*SnapshotGetRepositoryRequest) { + return func(r *SnapshotGetRepositoryRequest) { + r.Repository = v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f SnapshotGetRepository) WithLocal(v bool) func(*SnapshotGetRepositoryRequest) { + return func(r *SnapshotGetRepositoryRequest) { + r.Local = &v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f SnapshotGetRepository) WithMasterTimeout(v time.Duration) func(*SnapshotGetRepositoryRequest) { + return func(r *SnapshotGetRepositoryRequest) { + r.MasterTimeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SnapshotGetRepository) WithPretty() func(*SnapshotGetRepositoryRequest) { + return func(r *SnapshotGetRepositoryRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SnapshotGetRepository) WithHuman() func(*SnapshotGetRepositoryRequest) { + return func(r *SnapshotGetRepositoryRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SnapshotGetRepository) WithErrorTrace() func(*SnapshotGetRepositoryRequest) { + return func(r *SnapshotGetRepositoryRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SnapshotGetRepository) WithFilterPath(v ...string) func(*SnapshotGetRepositoryRequest) { + return func(r *SnapshotGetRepositoryRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SnapshotGetRepository) WithHeader(h map[string]string) func(*SnapshotGetRepositoryRequest) { + return func(r *SnapshotGetRepositoryRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SnapshotGetRepository) WithOpaqueID(s string) func(*SnapshotGetRepositoryRequest) { + return func(r *SnapshotGetRepositoryRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.restore.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.restore.go new file mode 100644 index 00000000000..5464ccc3863 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.restore.go @@ -0,0 +1,237 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" + "time" +) + +func newSnapshotRestoreFunc(t Transport) SnapshotRestore { + return func(repository string, snapshot string, o ...func(*SnapshotRestoreRequest)) (*Response, error) { + var r = SnapshotRestoreRequest{Repository: repository, Snapshot: snapshot} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SnapshotRestore restores a snapshot. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html. +// +type SnapshotRestore func(repository string, snapshot string, o ...func(*SnapshotRestoreRequest)) (*Response, error) + +// SnapshotRestoreRequest configures the Snapshot Restore API request. +// +type SnapshotRestoreRequest struct { + Body io.Reader + + Repository string + Snapshot string + + MasterTimeout time.Duration + WaitForCompletion *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SnapshotRestoreRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_snapshot") + 1 + len(r.Repository) + 1 + len(r.Snapshot) + 1 + len("_restore")) + path.WriteString("/") + path.WriteString("_snapshot") + path.WriteString("/") + path.WriteString(r.Repository) + path.WriteString("/") + path.WriteString(r.Snapshot) + path.WriteString("/") + path.WriteString("_restore") + + params = make(map[string]string) + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.WaitForCompletion != nil { + params["wait_for_completion"] = strconv.FormatBool(*r.WaitForCompletion) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SnapshotRestore) WithContext(v context.Context) func(*SnapshotRestoreRequest) { + return func(r *SnapshotRestoreRequest) { + r.ctx = v + } +} + +// WithBody - Details of what to restore. +// +func (f SnapshotRestore) WithBody(v io.Reader) func(*SnapshotRestoreRequest) { + return func(r *SnapshotRestoreRequest) { + r.Body = v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f SnapshotRestore) WithMasterTimeout(v time.Duration) func(*SnapshotRestoreRequest) { + return func(r *SnapshotRestoreRequest) { + r.MasterTimeout = v + } +} + +// WithWaitForCompletion - should this request wait until the operation has completed before returning. +// +func (f SnapshotRestore) WithWaitForCompletion(v bool) func(*SnapshotRestoreRequest) { + return func(r *SnapshotRestoreRequest) { + r.WaitForCompletion = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SnapshotRestore) WithPretty() func(*SnapshotRestoreRequest) { + return func(r *SnapshotRestoreRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SnapshotRestore) WithHuman() func(*SnapshotRestoreRequest) { + return func(r *SnapshotRestoreRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SnapshotRestore) WithErrorTrace() func(*SnapshotRestoreRequest) { + return func(r *SnapshotRestoreRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SnapshotRestore) WithFilterPath(v ...string) func(*SnapshotRestoreRequest) { + return func(r *SnapshotRestoreRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SnapshotRestore) WithHeader(h map[string]string) func(*SnapshotRestoreRequest) { + return func(r *SnapshotRestoreRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SnapshotRestore) WithOpaqueID(s string) func(*SnapshotRestoreRequest) { + return func(r *SnapshotRestoreRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.status.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.status.go new file mode 100644 index 00000000000..ba093cde354 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.status.go @@ -0,0 +1,242 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newSnapshotStatusFunc(t Transport) SnapshotStatus { + return func(o ...func(*SnapshotStatusRequest)) (*Response, error) { + var r = SnapshotStatusRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SnapshotStatus returns information about the status of a snapshot. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html. +// +type SnapshotStatus func(o ...func(*SnapshotStatusRequest)) (*Response, error) + +// SnapshotStatusRequest configures the Snapshot Status API request. +// +type SnapshotStatusRequest struct { + Repository string + Snapshot []string + + IgnoreUnavailable *bool + MasterTimeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SnapshotStatusRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_snapshot") + 1 + len(r.Repository) + 1 + len(strings.Join(r.Snapshot, ",")) + 1 + len("_status")) + path.WriteString("/") + path.WriteString("_snapshot") + if r.Repository != "" { + path.WriteString("/") + path.WriteString(r.Repository) + } + if len(r.Snapshot) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Snapshot, ",")) + } + path.WriteString("/") + path.WriteString("_status") + + params = make(map[string]string) + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SnapshotStatus) WithContext(v context.Context) func(*SnapshotStatusRequest) { + return func(r *SnapshotStatusRequest) { + r.ctx = v + } +} + +// WithRepository - a repository name. +// +func (f SnapshotStatus) WithRepository(v string) func(*SnapshotStatusRequest) { + return func(r *SnapshotStatusRequest) { + r.Repository = v + } +} + +// WithSnapshot - a list of snapshot names. +// +func (f SnapshotStatus) WithSnapshot(v ...string) func(*SnapshotStatusRequest) { + return func(r *SnapshotStatusRequest) { + r.Snapshot = v + } +} + +// WithIgnoreUnavailable - whether to ignore unavailable snapshots, defaults to false which means a snapshotmissingexception is thrown. +// +func (f SnapshotStatus) WithIgnoreUnavailable(v bool) func(*SnapshotStatusRequest) { + return func(r *SnapshotStatusRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f SnapshotStatus) WithMasterTimeout(v time.Duration) func(*SnapshotStatusRequest) { + return func(r *SnapshotStatusRequest) { + r.MasterTimeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SnapshotStatus) WithPretty() func(*SnapshotStatusRequest) { + return func(r *SnapshotStatusRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SnapshotStatus) WithHuman() func(*SnapshotStatusRequest) { + return func(r *SnapshotStatusRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SnapshotStatus) WithErrorTrace() func(*SnapshotStatusRequest) { + return func(r *SnapshotStatusRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SnapshotStatus) WithFilterPath(v ...string) func(*SnapshotStatusRequest) { + return func(r *SnapshotStatusRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SnapshotStatus) WithHeader(h map[string]string) func(*SnapshotStatusRequest) { + return func(r *SnapshotStatusRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SnapshotStatus) WithOpaqueID(s string) func(*SnapshotStatusRequest) { + return func(r *SnapshotStatusRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.verify_repository.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.verify_repository.go new file mode 100644 index 00000000000..3d51808c1c3 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.snapshot.verify_repository.go @@ -0,0 +1,218 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" + "time" +) + +func newSnapshotVerifyRepositoryFunc(t Transport) SnapshotVerifyRepository { + return func(repository string, o ...func(*SnapshotVerifyRepositoryRequest)) (*Response, error) { + var r = SnapshotVerifyRepositoryRequest{Repository: repository} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SnapshotVerifyRepository verifies a repository. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html. +// +type SnapshotVerifyRepository func(repository string, o ...func(*SnapshotVerifyRepositoryRequest)) (*Response, error) + +// SnapshotVerifyRepositoryRequest configures the Snapshot Verify Repository API request. +// +type SnapshotVerifyRepositoryRequest struct { + Repository string + + MasterTimeout time.Duration + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SnapshotVerifyRepositoryRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_snapshot") + 1 + len(r.Repository) + 1 + len("_verify")) + path.WriteString("/") + path.WriteString("_snapshot") + path.WriteString("/") + path.WriteString(r.Repository) + path.WriteString("/") + path.WriteString("_verify") + + params = make(map[string]string) + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SnapshotVerifyRepository) WithContext(v context.Context) func(*SnapshotVerifyRepositoryRequest) { + return func(r *SnapshotVerifyRepositoryRequest) { + r.ctx = v + } +} + +// WithMasterTimeout - explicit operation timeout for connection to master node. +// +func (f SnapshotVerifyRepository) WithMasterTimeout(v time.Duration) func(*SnapshotVerifyRepositoryRequest) { + return func(r *SnapshotVerifyRepositoryRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f SnapshotVerifyRepository) WithTimeout(v time.Duration) func(*SnapshotVerifyRepositoryRequest) { + return func(r *SnapshotVerifyRepositoryRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SnapshotVerifyRepository) WithPretty() func(*SnapshotVerifyRepositoryRequest) { + return func(r *SnapshotVerifyRepositoryRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SnapshotVerifyRepository) WithHuman() func(*SnapshotVerifyRepositoryRequest) { + return func(r *SnapshotVerifyRepositoryRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SnapshotVerifyRepository) WithErrorTrace() func(*SnapshotVerifyRepositoryRequest) { + return func(r *SnapshotVerifyRepositoryRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SnapshotVerifyRepository) WithFilterPath(v ...string) func(*SnapshotVerifyRepositoryRequest) { + return func(r *SnapshotVerifyRepositoryRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SnapshotVerifyRepository) WithHeader(h map[string]string) func(*SnapshotVerifyRepositoryRequest) { + return func(r *SnapshotVerifyRepositoryRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SnapshotVerifyRepository) WithOpaqueID(s string) func(*SnapshotVerifyRepositoryRequest) { + return func(r *SnapshotVerifyRepositoryRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.tasks.cancel.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.tasks.cancel.go new file mode 100644 index 00000000000..da8f8151fb9 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.tasks.cancel.go @@ -0,0 +1,240 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newTasksCancelFunc(t Transport) TasksCancel { + return func(o ...func(*TasksCancelRequest)) (*Response, error) { + var r = TasksCancelRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// TasksCancel cancels a task, if it can be cancelled through an API. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html. +// +type TasksCancel func(o ...func(*TasksCancelRequest)) (*Response, error) + +// TasksCancelRequest configures the Tasks Cancel API request. +// +type TasksCancelRequest struct { + TaskID string + + Actions []string + Nodes []string + ParentTaskID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r TasksCancelRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_tasks") + 1 + len(r.TaskID) + 1 + len("_cancel")) + path.WriteString("/") + path.WriteString("_tasks") + if r.TaskID != "" { + path.WriteString("/") + path.WriteString(r.TaskID) + } + path.WriteString("/") + path.WriteString("_cancel") + + params = make(map[string]string) + + if len(r.Actions) > 0 { + params["actions"] = strings.Join(r.Actions, ",") + } + + if len(r.Nodes) > 0 { + params["nodes"] = strings.Join(r.Nodes, ",") + } + + if r.ParentTaskID != "" { + params["parent_task_id"] = r.ParentTaskID + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f TasksCancel) WithContext(v context.Context) func(*TasksCancelRequest) { + return func(r *TasksCancelRequest) { + r.ctx = v + } +} + +// WithTaskID - cancel the task with specified task ID (node_id:task_number). +// +func (f TasksCancel) WithTaskID(v string) func(*TasksCancelRequest) { + return func(r *TasksCancelRequest) { + r.TaskID = v + } +} + +// WithActions - a list of actions that should be cancelled. leave empty to cancel all.. +// +func (f TasksCancel) WithActions(v ...string) func(*TasksCancelRequest) { + return func(r *TasksCancelRequest) { + r.Actions = v + } +} + +// WithNodes - a list of node ids or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes. +// +func (f TasksCancel) WithNodes(v ...string) func(*TasksCancelRequest) { + return func(r *TasksCancelRequest) { + r.Nodes = v + } +} + +// WithParentTaskID - cancel tasks with specified parent task ID (node_id:task_number). set to -1 to cancel all.. +// +func (f TasksCancel) WithParentTaskID(v string) func(*TasksCancelRequest) { + return func(r *TasksCancelRequest) { + r.ParentTaskID = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f TasksCancel) WithPretty() func(*TasksCancelRequest) { + return func(r *TasksCancelRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f TasksCancel) WithHuman() func(*TasksCancelRequest) { + return func(r *TasksCancelRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f TasksCancel) WithErrorTrace() func(*TasksCancelRequest) { + return func(r *TasksCancelRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f TasksCancel) WithFilterPath(v ...string) func(*TasksCancelRequest) { + return func(r *TasksCancelRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f TasksCancel) WithHeader(h map[string]string) func(*TasksCancelRequest) { + return func(r *TasksCancelRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f TasksCancel) WithOpaqueID(s string) func(*TasksCancelRequest) { + return func(r *TasksCancelRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.tasks.get.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.tasks.get.go new file mode 100644 index 00000000000..4a8402e74d4 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.tasks.get.go @@ -0,0 +1,217 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newTasksGetFunc(t Transport) TasksGet { + return func(task_id string, o ...func(*TasksGetRequest)) (*Response, error) { + var r = TasksGetRequest{TaskID: task_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// TasksGet returns information about a task. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html. +// +type TasksGet func(task_id string, o ...func(*TasksGetRequest)) (*Response, error) + +// TasksGetRequest configures the Tasks Get API request. +// +type TasksGetRequest struct { + TaskID string + + Timeout time.Duration + WaitForCompletion *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r TasksGetRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_tasks") + 1 + len(r.TaskID)) + path.WriteString("/") + path.WriteString("_tasks") + path.WriteString("/") + path.WriteString(r.TaskID) + + params = make(map[string]string) + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.WaitForCompletion != nil { + params["wait_for_completion"] = strconv.FormatBool(*r.WaitForCompletion) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f TasksGet) WithContext(v context.Context) func(*TasksGetRequest) { + return func(r *TasksGetRequest) { + r.ctx = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f TasksGet) WithTimeout(v time.Duration) func(*TasksGetRequest) { + return func(r *TasksGetRequest) { + r.Timeout = v + } +} + +// WithWaitForCompletion - wait for the matching tasks to complete (default: false). +// +func (f TasksGet) WithWaitForCompletion(v bool) func(*TasksGetRequest) { + return func(r *TasksGetRequest) { + r.WaitForCompletion = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f TasksGet) WithPretty() func(*TasksGetRequest) { + return func(r *TasksGetRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f TasksGet) WithHuman() func(*TasksGetRequest) { + return func(r *TasksGetRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f TasksGet) WithErrorTrace() func(*TasksGetRequest) { + return func(r *TasksGetRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f TasksGet) WithFilterPath(v ...string) func(*TasksGetRequest) { + return func(r *TasksGetRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f TasksGet) WithHeader(h map[string]string) func(*TasksGetRequest) { + return func(r *TasksGetRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f TasksGet) WithOpaqueID(s string) func(*TasksGetRequest) { + return func(r *TasksGetRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.tasks.list.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.tasks.list.go new file mode 100644 index 00000000000..a575d8101c3 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.tasks.list.go @@ -0,0 +1,277 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newTasksListFunc(t Transport) TasksList { + return func(o ...func(*TasksListRequest)) (*Response, error) { + var r = TasksListRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// TasksList returns a list of tasks. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html. +// +type TasksList func(o ...func(*TasksListRequest)) (*Response, error) + +// TasksListRequest configures the Tasks List API request. +// +type TasksListRequest struct { + Actions []string + Detailed *bool + GroupBy string + Nodes []string + ParentTaskID string + Timeout time.Duration + WaitForCompletion *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r TasksListRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_tasks")) + path.WriteString("/_tasks") + + params = make(map[string]string) + + if len(r.Actions) > 0 { + params["actions"] = strings.Join(r.Actions, ",") + } + + if r.Detailed != nil { + params["detailed"] = strconv.FormatBool(*r.Detailed) + } + + if r.GroupBy != "" { + params["group_by"] = r.GroupBy + } + + if len(r.Nodes) > 0 { + params["nodes"] = strings.Join(r.Nodes, ",") + } + + if r.ParentTaskID != "" { + params["parent_task_id"] = r.ParentTaskID + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.WaitForCompletion != nil { + params["wait_for_completion"] = strconv.FormatBool(*r.WaitForCompletion) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f TasksList) WithContext(v context.Context) func(*TasksListRequest) { + return func(r *TasksListRequest) { + r.ctx = v + } +} + +// WithActions - a list of actions that should be returned. leave empty to return all.. +// +func (f TasksList) WithActions(v ...string) func(*TasksListRequest) { + return func(r *TasksListRequest) { + r.Actions = v + } +} + +// WithDetailed - return detailed task information (default: false). +// +func (f TasksList) WithDetailed(v bool) func(*TasksListRequest) { + return func(r *TasksListRequest) { + r.Detailed = &v + } +} + +// WithGroupBy - group tasks by nodes or parent/child relationships. +// +func (f TasksList) WithGroupBy(v string) func(*TasksListRequest) { + return func(r *TasksListRequest) { + r.GroupBy = v + } +} + +// WithNodes - a list of node ids or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes. +// +func (f TasksList) WithNodes(v ...string) func(*TasksListRequest) { + return func(r *TasksListRequest) { + r.Nodes = v + } +} + +// WithParentTaskID - return tasks with specified parent task ID (node_id:task_number). set to -1 to return all.. +// +func (f TasksList) WithParentTaskID(v string) func(*TasksListRequest) { + return func(r *TasksListRequest) { + r.ParentTaskID = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f TasksList) WithTimeout(v time.Duration) func(*TasksListRequest) { + return func(r *TasksListRequest) { + r.Timeout = v + } +} + +// WithWaitForCompletion - wait for the matching tasks to complete (default: false). +// +func (f TasksList) WithWaitForCompletion(v bool) func(*TasksListRequest) { + return func(r *TasksListRequest) { + r.WaitForCompletion = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f TasksList) WithPretty() func(*TasksListRequest) { + return func(r *TasksListRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f TasksList) WithHuman() func(*TasksListRequest) { + return func(r *TasksListRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f TasksList) WithErrorTrace() func(*TasksListRequest) { + return func(r *TasksListRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f TasksList) WithFilterPath(v ...string) func(*TasksListRequest) { + return func(r *TasksListRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f TasksList) WithHeader(h map[string]string) func(*TasksListRequest) { + return func(r *TasksListRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f TasksList) WithOpaqueID(s string) func(*TasksListRequest) { + return func(r *TasksListRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.termvectors.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.termvectors.go new file mode 100644 index 00000000000..2fdd5604a41 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.termvectors.go @@ -0,0 +1,361 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newTermvectorsFunc(t Transport) Termvectors { + return func(index string, o ...func(*TermvectorsRequest)) (*Response, error) { + var r = TermvectorsRequest{Index: index} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// Termvectors returns information and statistics about terms in the fields of a particular document. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-termvectors.html. +// +type Termvectors func(index string, o ...func(*TermvectorsRequest)) (*Response, error) + +// TermvectorsRequest configures the Termvectors API request. +// +type TermvectorsRequest struct { + Index string + DocumentID string + + Body io.Reader + + Fields []string + FieldStatistics *bool + Offsets *bool + Payloads *bool + Positions *bool + Preference string + Realtime *bool + Routing string + TermStatistics *bool + Version *int + VersionType string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r TermvectorsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(r.Index) + 1 + len("_termvectors") + 1 + len(r.DocumentID)) + path.WriteString("/") + path.WriteString(r.Index) + path.WriteString("/") + path.WriteString("_termvectors") + if r.DocumentID != "" { + path.WriteString("/") + path.WriteString(r.DocumentID) + } + + params = make(map[string]string) + + if len(r.Fields) > 0 { + params["fields"] = strings.Join(r.Fields, ",") + } + + if r.FieldStatistics != nil { + params["field_statistics"] = strconv.FormatBool(*r.FieldStatistics) + } + + if r.Offsets != nil { + params["offsets"] = strconv.FormatBool(*r.Offsets) + } + + if r.Payloads != nil { + params["payloads"] = strconv.FormatBool(*r.Payloads) + } + + if r.Positions != nil { + params["positions"] = strconv.FormatBool(*r.Positions) + } + + if r.Preference != "" { + params["preference"] = r.Preference + } + + if r.Realtime != nil { + params["realtime"] = strconv.FormatBool(*r.Realtime) + } + + if r.Routing != "" { + params["routing"] = r.Routing + } + + if r.TermStatistics != nil { + params["term_statistics"] = strconv.FormatBool(*r.TermStatistics) + } + + if r.Version != nil { + params["version"] = strconv.FormatInt(int64(*r.Version), 10) + } + + if r.VersionType != "" { + params["version_type"] = r.VersionType + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f Termvectors) WithContext(v context.Context) func(*TermvectorsRequest) { + return func(r *TermvectorsRequest) { + r.ctx = v + } +} + +// WithBody - Define parameters and or supply a document to get termvectors for. See documentation.. +// +func (f Termvectors) WithBody(v io.Reader) func(*TermvectorsRequest) { + return func(r *TermvectorsRequest) { + r.Body = v + } +} + +// WithDocumentID - the ID of the document, when not specified a doc param should be supplied.. +// +func (f Termvectors) WithDocumentID(v string) func(*TermvectorsRequest) { + return func(r *TermvectorsRequest) { + r.DocumentID = v + } +} + +// WithFields - a list of fields to return.. +// +func (f Termvectors) WithFields(v ...string) func(*TermvectorsRequest) { + return func(r *TermvectorsRequest) { + r.Fields = v + } +} + +// WithFieldStatistics - specifies if document count, sum of document frequencies and sum of total term frequencies should be returned.. +// +func (f Termvectors) WithFieldStatistics(v bool) func(*TermvectorsRequest) { + return func(r *TermvectorsRequest) { + r.FieldStatistics = &v + } +} + +// WithOffsets - specifies if term offsets should be returned.. +// +func (f Termvectors) WithOffsets(v bool) func(*TermvectorsRequest) { + return func(r *TermvectorsRequest) { + r.Offsets = &v + } +} + +// WithPayloads - specifies if term payloads should be returned.. +// +func (f Termvectors) WithPayloads(v bool) func(*TermvectorsRequest) { + return func(r *TermvectorsRequest) { + r.Payloads = &v + } +} + +// WithPositions - specifies if term positions should be returned.. +// +func (f Termvectors) WithPositions(v bool) func(*TermvectorsRequest) { + return func(r *TermvectorsRequest) { + r.Positions = &v + } +} + +// WithPreference - specify the node or shard the operation should be performed on (default: random).. +// +func (f Termvectors) WithPreference(v string) func(*TermvectorsRequest) { + return func(r *TermvectorsRequest) { + r.Preference = v + } +} + +// WithRealtime - specifies if request is real-time as opposed to near-real-time (default: true).. +// +func (f Termvectors) WithRealtime(v bool) func(*TermvectorsRequest) { + return func(r *TermvectorsRequest) { + r.Realtime = &v + } +} + +// WithRouting - specific routing value.. +// +func (f Termvectors) WithRouting(v string) func(*TermvectorsRequest) { + return func(r *TermvectorsRequest) { + r.Routing = v + } +} + +// WithTermStatistics - specifies if total term frequency and document frequency should be returned.. +// +func (f Termvectors) WithTermStatistics(v bool) func(*TermvectorsRequest) { + return func(r *TermvectorsRequest) { + r.TermStatistics = &v + } +} + +// WithVersion - explicit version number for concurrency control. +// +func (f Termvectors) WithVersion(v int) func(*TermvectorsRequest) { + return func(r *TermvectorsRequest) { + r.Version = &v + } +} + +// WithVersionType - specific version type. +// +func (f Termvectors) WithVersionType(v string) func(*TermvectorsRequest) { + return func(r *TermvectorsRequest) { + r.VersionType = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f Termvectors) WithPretty() func(*TermvectorsRequest) { + return func(r *TermvectorsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f Termvectors) WithHuman() func(*TermvectorsRequest) { + return func(r *TermvectorsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f Termvectors) WithErrorTrace() func(*TermvectorsRequest) { + return func(r *TermvectorsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f Termvectors) WithFilterPath(v ...string) func(*TermvectorsRequest) { + return func(r *TermvectorsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f Termvectors) WithHeader(h map[string]string) func(*TermvectorsRequest) { + return func(r *TermvectorsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f Termvectors) WithOpaqueID(s string) func(*TermvectorsRequest) { + return func(r *TermvectorsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.update.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.update.go new file mode 100644 index 00000000000..61da3a4ed1f --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.update.go @@ -0,0 +1,344 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" + "time" +) + +func newUpdateFunc(t Transport) Update { + return func(index string, id string, body io.Reader, o ...func(*UpdateRequest)) (*Response, error) { + var r = UpdateRequest{Index: index, DocumentID: id, Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// Update updates a document with a script or partial document. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-update.html. +// +type Update func(index string, id string, body io.Reader, o ...func(*UpdateRequest)) (*Response, error) + +// UpdateRequest configures the Update API request. +// +type UpdateRequest struct { + Index string + DocumentID string + + Body io.Reader + + IfPrimaryTerm *int + IfSeqNo *int + Lang string + Refresh string + RetryOnConflict *int + Routing string + Source []string + SourceExcludes []string + SourceIncludes []string + Timeout time.Duration + WaitForActiveShards string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r UpdateRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len(r.Index) + 1 + len("_update") + 1 + len(r.DocumentID)) + path.WriteString("/") + path.WriteString(r.Index) + path.WriteString("/") + path.WriteString("_update") + path.WriteString("/") + path.WriteString(r.DocumentID) + + params = make(map[string]string) + + if r.IfPrimaryTerm != nil { + params["if_primary_term"] = strconv.FormatInt(int64(*r.IfPrimaryTerm), 10) + } + + if r.IfSeqNo != nil { + params["if_seq_no"] = strconv.FormatInt(int64(*r.IfSeqNo), 10) + } + + if r.Lang != "" { + params["lang"] = r.Lang + } + + if r.Refresh != "" { + params["refresh"] = r.Refresh + } + + if r.RetryOnConflict != nil { + params["retry_on_conflict"] = strconv.FormatInt(int64(*r.RetryOnConflict), 10) + } + + if r.Routing != "" { + params["routing"] = r.Routing + } + + if len(r.Source) > 0 { + params["_source"] = strings.Join(r.Source, ",") + } + + if len(r.SourceExcludes) > 0 { + params["_source_excludes"] = strings.Join(r.SourceExcludes, ",") + } + + if len(r.SourceIncludes) > 0 { + params["_source_includes"] = strings.Join(r.SourceIncludes, ",") + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.WaitForActiveShards != "" { + params["wait_for_active_shards"] = r.WaitForActiveShards + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f Update) WithContext(v context.Context) func(*UpdateRequest) { + return func(r *UpdateRequest) { + r.ctx = v + } +} + +// WithIfPrimaryTerm - only perform the update operation if the last operation that has changed the document has the specified primary term. +// +func (f Update) WithIfPrimaryTerm(v int) func(*UpdateRequest) { + return func(r *UpdateRequest) { + r.IfPrimaryTerm = &v + } +} + +// WithIfSeqNo - only perform the update operation if the last operation that has changed the document has the specified sequence number. +// +func (f Update) WithIfSeqNo(v int) func(*UpdateRequest) { + return func(r *UpdateRequest) { + r.IfSeqNo = &v + } +} + +// WithLang - the script language (default: painless). +// +func (f Update) WithLang(v string) func(*UpdateRequest) { + return func(r *UpdateRequest) { + r.Lang = v + } +} + +// WithRefresh - if `true` then refresh the effected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` (the default) then do nothing with refreshes.. +// +func (f Update) WithRefresh(v string) func(*UpdateRequest) { + return func(r *UpdateRequest) { + r.Refresh = v + } +} + +// WithRetryOnConflict - specify how many times should the operation be retried when a conflict occurs (default: 0). +// +func (f Update) WithRetryOnConflict(v int) func(*UpdateRequest) { + return func(r *UpdateRequest) { + r.RetryOnConflict = &v + } +} + +// WithRouting - specific routing value. +// +func (f Update) WithRouting(v string) func(*UpdateRequest) { + return func(r *UpdateRequest) { + r.Routing = v + } +} + +// WithSource - true or false to return the _source field or not, or a list of fields to return. +// +func (f Update) WithSource(v ...string) func(*UpdateRequest) { + return func(r *UpdateRequest) { + r.Source = v + } +} + +// WithSourceExcludes - a list of fields to exclude from the returned _source field. +// +func (f Update) WithSourceExcludes(v ...string) func(*UpdateRequest) { + return func(r *UpdateRequest) { + r.SourceExcludes = v + } +} + +// WithSourceIncludes - a list of fields to extract and return from the _source field. +// +func (f Update) WithSourceIncludes(v ...string) func(*UpdateRequest) { + return func(r *UpdateRequest) { + r.SourceIncludes = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f Update) WithTimeout(v time.Duration) func(*UpdateRequest) { + return func(r *UpdateRequest) { + r.Timeout = v + } +} + +// WithWaitForActiveShards - sets the number of shard copies that must be active before proceeding with the update operation. defaults to 1, meaning the primary shard only. set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1). +// +func (f Update) WithWaitForActiveShards(v string) func(*UpdateRequest) { + return func(r *UpdateRequest) { + r.WaitForActiveShards = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f Update) WithPretty() func(*UpdateRequest) { + return func(r *UpdateRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f Update) WithHuman() func(*UpdateRequest) { + return func(r *UpdateRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f Update) WithErrorTrace() func(*UpdateRequest) { + return func(r *UpdateRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f Update) WithFilterPath(v ...string) func(*UpdateRequest) { + return func(r *UpdateRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f Update) WithHeader(h map[string]string) func(*UpdateRequest) { + return func(r *UpdateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f Update) WithOpaqueID(s string) func(*UpdateRequest) { + return func(r *UpdateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.update_by_query.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.update_by_query.go new file mode 100644 index 00000000000..21bfd4326ba --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.update_by_query.go @@ -0,0 +1,649 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" + "time" +) + +func newUpdateByQueryFunc(t Transport) UpdateByQuery { + return func(index []string, o ...func(*UpdateByQueryRequest)) (*Response, error) { + var r = UpdateByQueryRequest{Index: index} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// UpdateByQuery performs an update on every document in the index without changing the source, +// for example to pick up a mapping change. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-update-by-query.html. +// +type UpdateByQuery func(index []string, o ...func(*UpdateByQueryRequest)) (*Response, error) + +// UpdateByQueryRequest configures the Update By Query API request. +// +type UpdateByQueryRequest struct { + Index []string + + Body io.Reader + + AllowNoIndices *bool + Analyzer string + AnalyzeWildcard *bool + Conflicts string + DefaultOperator string + Df string + ExpandWildcards string + From *int + IgnoreUnavailable *bool + Lenient *bool + MaxDocs *int + Pipeline string + Preference string + Query string + Refresh *bool + RequestCache *bool + RequestsPerSecond *int + Routing []string + Scroll time.Duration + ScrollSize *int + SearchTimeout time.Duration + SearchType string + Slices *int + Sort []string + Source []string + SourceExcludes []string + SourceIncludes []string + Stats []string + TerminateAfter *int + Timeout time.Duration + Version *bool + VersionType *bool + WaitForActiveShards string + WaitForCompletion *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r UpdateByQueryRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_update_by_query")) + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + path.WriteString("/") + path.WriteString("_update_by_query") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.Analyzer != "" { + params["analyzer"] = r.Analyzer + } + + if r.AnalyzeWildcard != nil { + params["analyze_wildcard"] = strconv.FormatBool(*r.AnalyzeWildcard) + } + + if r.Conflicts != "" { + params["conflicts"] = r.Conflicts + } + + if r.DefaultOperator != "" { + params["default_operator"] = r.DefaultOperator + } + + if r.Df != "" { + params["df"] = r.Df + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.From != nil { + params["from"] = strconv.FormatInt(int64(*r.From), 10) + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.Lenient != nil { + params["lenient"] = strconv.FormatBool(*r.Lenient) + } + + if r.MaxDocs != nil { + params["max_docs"] = strconv.FormatInt(int64(*r.MaxDocs), 10) + } + + if r.Pipeline != "" { + params["pipeline"] = r.Pipeline + } + + if r.Preference != "" { + params["preference"] = r.Preference + } + + if r.Query != "" { + params["q"] = r.Query + } + + if r.Refresh != nil { + params["refresh"] = strconv.FormatBool(*r.Refresh) + } + + if r.RequestCache != nil { + params["request_cache"] = strconv.FormatBool(*r.RequestCache) + } + + if r.RequestsPerSecond != nil { + params["requests_per_second"] = strconv.FormatInt(int64(*r.RequestsPerSecond), 10) + } + + if len(r.Routing) > 0 { + params["routing"] = strings.Join(r.Routing, ",") + } + + if r.Scroll != 0 { + params["scroll"] = formatDuration(r.Scroll) + } + + if r.ScrollSize != nil { + params["scroll_size"] = strconv.FormatInt(int64(*r.ScrollSize), 10) + } + + if r.SearchTimeout != 0 { + params["search_timeout"] = formatDuration(r.SearchTimeout) + } + + if r.SearchType != "" { + params["search_type"] = r.SearchType + } + + if r.Slices != nil { + params["slices"] = strconv.FormatInt(int64(*r.Slices), 10) + } + + if len(r.Sort) > 0 { + params["sort"] = strings.Join(r.Sort, ",") + } + + if len(r.Source) > 0 { + params["_source"] = strings.Join(r.Source, ",") + } + + if len(r.SourceExcludes) > 0 { + params["_source_excludes"] = strings.Join(r.SourceExcludes, ",") + } + + if len(r.SourceIncludes) > 0 { + params["_source_includes"] = strings.Join(r.SourceIncludes, ",") + } + + if len(r.Stats) > 0 { + params["stats"] = strings.Join(r.Stats, ",") + } + + if r.TerminateAfter != nil { + params["terminate_after"] = strconv.FormatInt(int64(*r.TerminateAfter), 10) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Version != nil { + params["version"] = strconv.FormatBool(*r.Version) + } + + if r.VersionType != nil { + params["version_type"] = strconv.FormatBool(*r.VersionType) + } + + if r.WaitForActiveShards != "" { + params["wait_for_active_shards"] = r.WaitForActiveShards + } + + if r.WaitForCompletion != nil { + params["wait_for_completion"] = strconv.FormatBool(*r.WaitForCompletion) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f UpdateByQuery) WithContext(v context.Context) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.ctx = v + } +} + +// WithBody - The search definition using the Query DSL. +// +func (f UpdateByQuery) WithBody(v io.Reader) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.Body = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f UpdateByQuery) WithAllowNoIndices(v bool) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.AllowNoIndices = &v + } +} + +// WithAnalyzer - the analyzer to use for the query string. +// +func (f UpdateByQuery) WithAnalyzer(v string) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.Analyzer = v + } +} + +// WithAnalyzeWildcard - specify whether wildcard and prefix queries should be analyzed (default: false). +// +func (f UpdateByQuery) WithAnalyzeWildcard(v bool) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.AnalyzeWildcard = &v + } +} + +// WithConflicts - what to do when the update by query hits version conflicts?. +// +func (f UpdateByQuery) WithConflicts(v string) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.Conflicts = v + } +} + +// WithDefaultOperator - the default operator for query string query (and or or). +// +func (f UpdateByQuery) WithDefaultOperator(v string) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.DefaultOperator = v + } +} + +// WithDf - the field to use as default where no field prefix is given in the query string. +// +func (f UpdateByQuery) WithDf(v string) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.Df = v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f UpdateByQuery) WithExpandWildcards(v string) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.ExpandWildcards = v + } +} + +// WithFrom - starting offset (default: 0). +// +func (f UpdateByQuery) WithFrom(v int) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.From = &v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f UpdateByQuery) WithIgnoreUnavailable(v bool) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithLenient - specify whether format-based query failures (such as providing text to a numeric field) should be ignored. +// +func (f UpdateByQuery) WithLenient(v bool) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.Lenient = &v + } +} + +// WithMaxDocs - maximum number of documents to process (default: all documents). +// +func (f UpdateByQuery) WithMaxDocs(v int) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.MaxDocs = &v + } +} + +// WithPipeline - ingest pipeline to set on index requests made by this action. (default: none). +// +func (f UpdateByQuery) WithPipeline(v string) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.Pipeline = v + } +} + +// WithPreference - specify the node or shard the operation should be performed on (default: random). +// +func (f UpdateByQuery) WithPreference(v string) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.Preference = v + } +} + +// WithQuery - query in the lucene query string syntax. +// +func (f UpdateByQuery) WithQuery(v string) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.Query = v + } +} + +// WithRefresh - should the effected indexes be refreshed?. +// +func (f UpdateByQuery) WithRefresh(v bool) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.Refresh = &v + } +} + +// WithRequestCache - specify if request cache should be used for this request or not, defaults to index level setting. +// +func (f UpdateByQuery) WithRequestCache(v bool) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.RequestCache = &v + } +} + +// WithRequestsPerSecond - the throttle to set on this request in sub-requests per second. -1 means no throttle.. +// +func (f UpdateByQuery) WithRequestsPerSecond(v int) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.RequestsPerSecond = &v + } +} + +// WithRouting - a list of specific routing values. +// +func (f UpdateByQuery) WithRouting(v ...string) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.Routing = v + } +} + +// WithScroll - specify how long a consistent view of the index should be maintained for scrolled search. +// +func (f UpdateByQuery) WithScroll(v time.Duration) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.Scroll = v + } +} + +// WithScrollSize - size on the scroll request powering the update by query. +// +func (f UpdateByQuery) WithScrollSize(v int) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.ScrollSize = &v + } +} + +// WithSearchTimeout - explicit timeout for each search request. defaults to no timeout.. +// +func (f UpdateByQuery) WithSearchTimeout(v time.Duration) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.SearchTimeout = v + } +} + +// WithSearchType - search operation type. +// +func (f UpdateByQuery) WithSearchType(v string) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.SearchType = v + } +} + +// WithSlices - the number of slices this task should be divided into. defaults to 1 meaning the task isn't sliced into subtasks.. +// +func (f UpdateByQuery) WithSlices(v int) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.Slices = &v + } +} + +// WithSort - a list of : pairs. +// +func (f UpdateByQuery) WithSort(v ...string) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.Sort = v + } +} + +// WithSource - true or false to return the _source field or not, or a list of fields to return. +// +func (f UpdateByQuery) WithSource(v ...string) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.Source = v + } +} + +// WithSourceExcludes - a list of fields to exclude from the returned _source field. +// +func (f UpdateByQuery) WithSourceExcludes(v ...string) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.SourceExcludes = v + } +} + +// WithSourceIncludes - a list of fields to extract and return from the _source field. +// +func (f UpdateByQuery) WithSourceIncludes(v ...string) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.SourceIncludes = v + } +} + +// WithStats - specific 'tag' of the request for logging and statistical purposes. +// +func (f UpdateByQuery) WithStats(v ...string) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.Stats = v + } +} + +// WithTerminateAfter - the maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early.. +// +func (f UpdateByQuery) WithTerminateAfter(v int) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.TerminateAfter = &v + } +} + +// WithTimeout - time each individual bulk request should wait for shards that are unavailable.. +// +func (f UpdateByQuery) WithTimeout(v time.Duration) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.Timeout = v + } +} + +// WithVersion - specify whether to return document version as part of a hit. +// +func (f UpdateByQuery) WithVersion(v bool) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.Version = &v + } +} + +// WithVersionType - should the document increment the version number (internal) on hit or not (reindex). +// +func (f UpdateByQuery) WithVersionType(v bool) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.VersionType = &v + } +} + +// WithWaitForActiveShards - sets the number of shard copies that must be active before proceeding with the update by query operation. defaults to 1, meaning the primary shard only. set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1). +// +func (f UpdateByQuery) WithWaitForActiveShards(v string) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.WaitForActiveShards = v + } +} + +// WithWaitForCompletion - should the request should block until the update by query operation is complete.. +// +func (f UpdateByQuery) WithWaitForCompletion(v bool) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.WaitForCompletion = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f UpdateByQuery) WithPretty() func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f UpdateByQuery) WithHuman() func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f UpdateByQuery) WithErrorTrace() func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f UpdateByQuery) WithFilterPath(v ...string) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f UpdateByQuery) WithHeader(h map[string]string) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f UpdateByQuery) WithOpaqueID(s string) func(*UpdateByQueryRequest) { + return func(r *UpdateByQueryRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.update_by_query_rethrottle.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.update_by_query_rethrottle.go new file mode 100644 index 00000000000..c116d13c134 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.update_by_query_rethrottle.go @@ -0,0 +1,205 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newUpdateByQueryRethrottleFunc(t Transport) UpdateByQueryRethrottle { + return func(task_id string, requests_per_second *int, o ...func(*UpdateByQueryRethrottleRequest)) (*Response, error) { + var r = UpdateByQueryRethrottleRequest{TaskID: task_id, RequestsPerSecond: requests_per_second} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// UpdateByQueryRethrottle changes the number of requests per second for a particular Update By Query operation. +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html. +// +type UpdateByQueryRethrottle func(task_id string, requests_per_second *int, o ...func(*UpdateByQueryRethrottleRequest)) (*Response, error) + +// UpdateByQueryRethrottleRequest configures the Update By Query Rethrottle API request. +// +type UpdateByQueryRethrottleRequest struct { + TaskID string + + RequestsPerSecond *int + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r UpdateByQueryRethrottleRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_update_by_query") + 1 + len(r.TaskID) + 1 + len("_rethrottle")) + path.WriteString("/") + path.WriteString("_update_by_query") + path.WriteString("/") + path.WriteString(r.TaskID) + path.WriteString("/") + path.WriteString("_rethrottle") + + params = make(map[string]string) + + if r.RequestsPerSecond != nil { + params["requests_per_second"] = strconv.FormatInt(int64(*r.RequestsPerSecond), 10) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f UpdateByQueryRethrottle) WithContext(v context.Context) func(*UpdateByQueryRethrottleRequest) { + return func(r *UpdateByQueryRethrottleRequest) { + r.ctx = v + } +} + +// WithRequestsPerSecond - the throttle to set on this request in floating sub-requests per second. -1 means set no throttle.. +// +func (f UpdateByQueryRethrottle) WithRequestsPerSecond(v int) func(*UpdateByQueryRethrottleRequest) { + return func(r *UpdateByQueryRethrottleRequest) { + r.RequestsPerSecond = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f UpdateByQueryRethrottle) WithPretty() func(*UpdateByQueryRethrottleRequest) { + return func(r *UpdateByQueryRethrottleRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f UpdateByQueryRethrottle) WithHuman() func(*UpdateByQueryRethrottleRequest) { + return func(r *UpdateByQueryRethrottleRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f UpdateByQueryRethrottle) WithErrorTrace() func(*UpdateByQueryRethrottleRequest) { + return func(r *UpdateByQueryRethrottleRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f UpdateByQueryRethrottle) WithFilterPath(v ...string) func(*UpdateByQueryRethrottleRequest) { + return func(r *UpdateByQueryRethrottleRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f UpdateByQueryRethrottle) WithHeader(h map[string]string) func(*UpdateByQueryRethrottleRequest) { + return func(r *UpdateByQueryRethrottleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f UpdateByQueryRethrottle) WithOpaqueID(s string) func(*UpdateByQueryRethrottleRequest) { + return func(r *UpdateByQueryRethrottleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.delete_auto_follow_pattern.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.delete_auto_follow_pattern.go new file mode 100644 index 00000000000..face591f3af --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.delete_auto_follow_pattern.go @@ -0,0 +1,190 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newCCRDeleteAutoFollowPatternFunc(t Transport) CCRDeleteAutoFollowPattern { + return func(name string, o ...func(*CCRDeleteAutoFollowPatternRequest)) (*Response, error) { + var r = CCRDeleteAutoFollowPatternRequest{Name: name} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CCRDeleteAutoFollowPattern - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-delete-auto-follow-pattern.html. +// +type CCRDeleteAutoFollowPattern func(name string, o ...func(*CCRDeleteAutoFollowPatternRequest)) (*Response, error) + +// CCRDeleteAutoFollowPatternRequest configures the CCR Delete Auto Follow Pattern API request. +// +type CCRDeleteAutoFollowPatternRequest struct { + Name string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CCRDeleteAutoFollowPatternRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_ccr") + 1 + len("auto_follow") + 1 + len(r.Name)) + path.WriteString("/") + path.WriteString("_ccr") + path.WriteString("/") + path.WriteString("auto_follow") + path.WriteString("/") + path.WriteString(r.Name) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CCRDeleteAutoFollowPattern) WithContext(v context.Context) func(*CCRDeleteAutoFollowPatternRequest) { + return func(r *CCRDeleteAutoFollowPatternRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CCRDeleteAutoFollowPattern) WithPretty() func(*CCRDeleteAutoFollowPatternRequest) { + return func(r *CCRDeleteAutoFollowPatternRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CCRDeleteAutoFollowPattern) WithHuman() func(*CCRDeleteAutoFollowPatternRequest) { + return func(r *CCRDeleteAutoFollowPatternRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CCRDeleteAutoFollowPattern) WithErrorTrace() func(*CCRDeleteAutoFollowPatternRequest) { + return func(r *CCRDeleteAutoFollowPatternRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CCRDeleteAutoFollowPattern) WithFilterPath(v ...string) func(*CCRDeleteAutoFollowPatternRequest) { + return func(r *CCRDeleteAutoFollowPatternRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CCRDeleteAutoFollowPattern) WithHeader(h map[string]string) func(*CCRDeleteAutoFollowPatternRequest) { + return func(r *CCRDeleteAutoFollowPatternRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CCRDeleteAutoFollowPattern) WithOpaqueID(s string) func(*CCRDeleteAutoFollowPatternRequest) { + return func(r *CCRDeleteAutoFollowPatternRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.follow.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.follow.go new file mode 100644 index 00000000000..32a8d9815dd --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.follow.go @@ -0,0 +1,211 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newCCRFollowFunc(t Transport) CCRFollow { + return func(index string, body io.Reader, o ...func(*CCRFollowRequest)) (*Response, error) { + var r = CCRFollowRequest{Index: index, Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CCRFollow - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-put-follow.html. +// +type CCRFollow func(index string, body io.Reader, o ...func(*CCRFollowRequest)) (*Response, error) + +// CCRFollowRequest configures the CCR Follow API request. +// +type CCRFollowRequest struct { + Index string + + Body io.Reader + + WaitForActiveShards string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CCRFollowRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len(r.Index) + 1 + len("_ccr") + 1 + len("follow")) + path.WriteString("/") + path.WriteString(r.Index) + path.WriteString("/") + path.WriteString("_ccr") + path.WriteString("/") + path.WriteString("follow") + + params = make(map[string]string) + + if r.WaitForActiveShards != "" { + params["wait_for_active_shards"] = r.WaitForActiveShards + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CCRFollow) WithContext(v context.Context) func(*CCRFollowRequest) { + return func(r *CCRFollowRequest) { + r.ctx = v + } +} + +// WithWaitForActiveShards - sets the number of shard copies that must be active before returning. defaults to 0. set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1). +// +func (f CCRFollow) WithWaitForActiveShards(v string) func(*CCRFollowRequest) { + return func(r *CCRFollowRequest) { + r.WaitForActiveShards = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CCRFollow) WithPretty() func(*CCRFollowRequest) { + return func(r *CCRFollowRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CCRFollow) WithHuman() func(*CCRFollowRequest) { + return func(r *CCRFollowRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CCRFollow) WithErrorTrace() func(*CCRFollowRequest) { + return func(r *CCRFollowRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CCRFollow) WithFilterPath(v ...string) func(*CCRFollowRequest) { + return func(r *CCRFollowRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CCRFollow) WithHeader(h map[string]string) func(*CCRFollowRequest) { + return func(r *CCRFollowRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CCRFollow) WithOpaqueID(s string) func(*CCRFollowRequest) { + return func(r *CCRFollowRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.follow_info.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.follow_info.go new file mode 100644 index 00000000000..662d7458eef --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.follow_info.go @@ -0,0 +1,190 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newCCRFollowInfoFunc(t Transport) CCRFollowInfo { + return func(index []string, o ...func(*CCRFollowInfoRequest)) (*Response, error) { + var r = CCRFollowInfoRequest{Index: index} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CCRFollowInfo - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-info.html. +// +type CCRFollowInfo func(index []string, o ...func(*CCRFollowInfoRequest)) (*Response, error) + +// CCRFollowInfoRequest configures the CCR Follow Info API request. +// +type CCRFollowInfoRequest struct { + Index []string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CCRFollowInfoRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_ccr") + 1 + len("info")) + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + path.WriteString("/") + path.WriteString("_ccr") + path.WriteString("/") + path.WriteString("info") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CCRFollowInfo) WithContext(v context.Context) func(*CCRFollowInfoRequest) { + return func(r *CCRFollowInfoRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CCRFollowInfo) WithPretty() func(*CCRFollowInfoRequest) { + return func(r *CCRFollowInfoRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CCRFollowInfo) WithHuman() func(*CCRFollowInfoRequest) { + return func(r *CCRFollowInfoRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CCRFollowInfo) WithErrorTrace() func(*CCRFollowInfoRequest) { + return func(r *CCRFollowInfoRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CCRFollowInfo) WithFilterPath(v ...string) func(*CCRFollowInfoRequest) { + return func(r *CCRFollowInfoRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CCRFollowInfo) WithHeader(h map[string]string) func(*CCRFollowInfoRequest) { + return func(r *CCRFollowInfoRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CCRFollowInfo) WithOpaqueID(s string) func(*CCRFollowInfoRequest) { + return func(r *CCRFollowInfoRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.follow_stats.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.follow_stats.go new file mode 100644 index 00000000000..1b9f0622206 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.follow_stats.go @@ -0,0 +1,190 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newCCRFollowStatsFunc(t Transport) CCRFollowStats { + return func(index []string, o ...func(*CCRFollowStatsRequest)) (*Response, error) { + var r = CCRFollowStatsRequest{Index: index} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CCRFollowStats - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-stats.html. +// +type CCRFollowStats func(index []string, o ...func(*CCRFollowStatsRequest)) (*Response, error) + +// CCRFollowStatsRequest configures the CCR Follow Stats API request. +// +type CCRFollowStatsRequest struct { + Index []string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CCRFollowStatsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_ccr") + 1 + len("stats")) + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + path.WriteString("/") + path.WriteString("_ccr") + path.WriteString("/") + path.WriteString("stats") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CCRFollowStats) WithContext(v context.Context) func(*CCRFollowStatsRequest) { + return func(r *CCRFollowStatsRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CCRFollowStats) WithPretty() func(*CCRFollowStatsRequest) { + return func(r *CCRFollowStatsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CCRFollowStats) WithHuman() func(*CCRFollowStatsRequest) { + return func(r *CCRFollowStatsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CCRFollowStats) WithErrorTrace() func(*CCRFollowStatsRequest) { + return func(r *CCRFollowStatsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CCRFollowStats) WithFilterPath(v ...string) func(*CCRFollowStatsRequest) { + return func(r *CCRFollowStatsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CCRFollowStats) WithHeader(h map[string]string) func(*CCRFollowStatsRequest) { + return func(r *CCRFollowStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CCRFollowStats) WithOpaqueID(s string) func(*CCRFollowStatsRequest) { + return func(r *CCRFollowStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.forget_follower.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.forget_follower.go new file mode 100644 index 00000000000..060210264a0 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.forget_follower.go @@ -0,0 +1,197 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newCCRForgetFollowerFunc(t Transport) CCRForgetFollower { + return func(index string, body io.Reader, o ...func(*CCRForgetFollowerRequest)) (*Response, error) { + var r = CCRForgetFollowerRequest{Index: index, Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CCRForgetFollower - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current. +// +type CCRForgetFollower func(index string, body io.Reader, o ...func(*CCRForgetFollowerRequest)) (*Response, error) + +// CCRForgetFollowerRequest configures the CCR Forget Follower API request. +// +type CCRForgetFollowerRequest struct { + Index string + + Body io.Reader + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CCRForgetFollowerRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len(r.Index) + 1 + len("_ccr") + 1 + len("forget_follower")) + path.WriteString("/") + path.WriteString(r.Index) + path.WriteString("/") + path.WriteString("_ccr") + path.WriteString("/") + path.WriteString("forget_follower") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CCRForgetFollower) WithContext(v context.Context) func(*CCRForgetFollowerRequest) { + return func(r *CCRForgetFollowerRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CCRForgetFollower) WithPretty() func(*CCRForgetFollowerRequest) { + return func(r *CCRForgetFollowerRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CCRForgetFollower) WithHuman() func(*CCRForgetFollowerRequest) { + return func(r *CCRForgetFollowerRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CCRForgetFollower) WithErrorTrace() func(*CCRForgetFollowerRequest) { + return func(r *CCRForgetFollowerRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CCRForgetFollower) WithFilterPath(v ...string) func(*CCRForgetFollowerRequest) { + return func(r *CCRForgetFollowerRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CCRForgetFollower) WithHeader(h map[string]string) func(*CCRForgetFollowerRequest) { + return func(r *CCRForgetFollowerRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CCRForgetFollower) WithOpaqueID(s string) func(*CCRForgetFollowerRequest) { + return func(r *CCRForgetFollowerRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.get_auto_follow_pattern.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.get_auto_follow_pattern.go new file mode 100644 index 00000000000..3a300bcf867 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.get_auto_follow_pattern.go @@ -0,0 +1,200 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newCCRGetAutoFollowPatternFunc(t Transport) CCRGetAutoFollowPattern { + return func(o ...func(*CCRGetAutoFollowPatternRequest)) (*Response, error) { + var r = CCRGetAutoFollowPatternRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CCRGetAutoFollowPattern - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-auto-follow-pattern.html. +// +type CCRGetAutoFollowPattern func(o ...func(*CCRGetAutoFollowPatternRequest)) (*Response, error) + +// CCRGetAutoFollowPatternRequest configures the CCR Get Auto Follow Pattern API request. +// +type CCRGetAutoFollowPatternRequest struct { + Name string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CCRGetAutoFollowPatternRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_ccr") + 1 + len("auto_follow") + 1 + len(r.Name)) + path.WriteString("/") + path.WriteString("_ccr") + path.WriteString("/") + path.WriteString("auto_follow") + if r.Name != "" { + path.WriteString("/") + path.WriteString(r.Name) + } + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CCRGetAutoFollowPattern) WithContext(v context.Context) func(*CCRGetAutoFollowPatternRequest) { + return func(r *CCRGetAutoFollowPatternRequest) { + r.ctx = v + } +} + +// WithName - the name of the auto follow pattern.. +// +func (f CCRGetAutoFollowPattern) WithName(v string) func(*CCRGetAutoFollowPatternRequest) { + return func(r *CCRGetAutoFollowPatternRequest) { + r.Name = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CCRGetAutoFollowPattern) WithPretty() func(*CCRGetAutoFollowPatternRequest) { + return func(r *CCRGetAutoFollowPatternRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CCRGetAutoFollowPattern) WithHuman() func(*CCRGetAutoFollowPatternRequest) { + return func(r *CCRGetAutoFollowPatternRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CCRGetAutoFollowPattern) WithErrorTrace() func(*CCRGetAutoFollowPatternRequest) { + return func(r *CCRGetAutoFollowPatternRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CCRGetAutoFollowPattern) WithFilterPath(v ...string) func(*CCRGetAutoFollowPatternRequest) { + return func(r *CCRGetAutoFollowPatternRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CCRGetAutoFollowPattern) WithHeader(h map[string]string) func(*CCRGetAutoFollowPatternRequest) { + return func(r *CCRGetAutoFollowPatternRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CCRGetAutoFollowPattern) WithOpaqueID(s string) func(*CCRGetAutoFollowPatternRequest) { + return func(r *CCRGetAutoFollowPatternRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.pause_auto_follow_pattern.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.pause_auto_follow_pattern.go new file mode 100644 index 00000000000..1a7eb418b88 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.pause_auto_follow_pattern.go @@ -0,0 +1,192 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newCCRPauseAutoFollowPatternFunc(t Transport) CCRPauseAutoFollowPattern { + return func(name string, o ...func(*CCRPauseAutoFollowPatternRequest)) (*Response, error) { + var r = CCRPauseAutoFollowPatternRequest{Name: name} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CCRPauseAutoFollowPattern - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-pause-auto-follow-pattern.html. +// +type CCRPauseAutoFollowPattern func(name string, o ...func(*CCRPauseAutoFollowPatternRequest)) (*Response, error) + +// CCRPauseAutoFollowPatternRequest configures the CCR Pause Auto Follow Pattern API request. +// +type CCRPauseAutoFollowPatternRequest struct { + Name string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CCRPauseAutoFollowPatternRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_ccr") + 1 + len("auto_follow") + 1 + len(r.Name) + 1 + len("pause")) + path.WriteString("/") + path.WriteString("_ccr") + path.WriteString("/") + path.WriteString("auto_follow") + path.WriteString("/") + path.WriteString(r.Name) + path.WriteString("/") + path.WriteString("pause") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CCRPauseAutoFollowPattern) WithContext(v context.Context) func(*CCRPauseAutoFollowPatternRequest) { + return func(r *CCRPauseAutoFollowPatternRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CCRPauseAutoFollowPattern) WithPretty() func(*CCRPauseAutoFollowPatternRequest) { + return func(r *CCRPauseAutoFollowPatternRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CCRPauseAutoFollowPattern) WithHuman() func(*CCRPauseAutoFollowPatternRequest) { + return func(r *CCRPauseAutoFollowPatternRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CCRPauseAutoFollowPattern) WithErrorTrace() func(*CCRPauseAutoFollowPatternRequest) { + return func(r *CCRPauseAutoFollowPatternRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CCRPauseAutoFollowPattern) WithFilterPath(v ...string) func(*CCRPauseAutoFollowPatternRequest) { + return func(r *CCRPauseAutoFollowPatternRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CCRPauseAutoFollowPattern) WithHeader(h map[string]string) func(*CCRPauseAutoFollowPatternRequest) { + return func(r *CCRPauseAutoFollowPatternRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CCRPauseAutoFollowPattern) WithOpaqueID(s string) func(*CCRPauseAutoFollowPatternRequest) { + return func(r *CCRPauseAutoFollowPatternRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.pause_follow.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.pause_follow.go new file mode 100644 index 00000000000..32642a0b7c6 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.pause_follow.go @@ -0,0 +1,190 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newCCRPauseFollowFunc(t Transport) CCRPauseFollow { + return func(index string, o ...func(*CCRPauseFollowRequest)) (*Response, error) { + var r = CCRPauseFollowRequest{Index: index} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CCRPauseFollow - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-post-pause-follow.html. +// +type CCRPauseFollow func(index string, o ...func(*CCRPauseFollowRequest)) (*Response, error) + +// CCRPauseFollowRequest configures the CCR Pause Follow API request. +// +type CCRPauseFollowRequest struct { + Index string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CCRPauseFollowRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len(r.Index) + 1 + len("_ccr") + 1 + len("pause_follow")) + path.WriteString("/") + path.WriteString(r.Index) + path.WriteString("/") + path.WriteString("_ccr") + path.WriteString("/") + path.WriteString("pause_follow") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CCRPauseFollow) WithContext(v context.Context) func(*CCRPauseFollowRequest) { + return func(r *CCRPauseFollowRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CCRPauseFollow) WithPretty() func(*CCRPauseFollowRequest) { + return func(r *CCRPauseFollowRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CCRPauseFollow) WithHuman() func(*CCRPauseFollowRequest) { + return func(r *CCRPauseFollowRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CCRPauseFollow) WithErrorTrace() func(*CCRPauseFollowRequest) { + return func(r *CCRPauseFollowRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CCRPauseFollow) WithFilterPath(v ...string) func(*CCRPauseFollowRequest) { + return func(r *CCRPauseFollowRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CCRPauseFollow) WithHeader(h map[string]string) func(*CCRPauseFollowRequest) { + return func(r *CCRPauseFollowRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CCRPauseFollow) WithOpaqueID(s string) func(*CCRPauseFollowRequest) { + return func(r *CCRPauseFollowRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.put_auto_follow_pattern.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.put_auto_follow_pattern.go new file mode 100644 index 00000000000..ae307512776 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.put_auto_follow_pattern.go @@ -0,0 +1,197 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newCCRPutAutoFollowPatternFunc(t Transport) CCRPutAutoFollowPattern { + return func(name string, body io.Reader, o ...func(*CCRPutAutoFollowPatternRequest)) (*Response, error) { + var r = CCRPutAutoFollowPatternRequest{Name: name, Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CCRPutAutoFollowPattern - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-put-auto-follow-pattern.html. +// +type CCRPutAutoFollowPattern func(name string, body io.Reader, o ...func(*CCRPutAutoFollowPatternRequest)) (*Response, error) + +// CCRPutAutoFollowPatternRequest configures the CCR Put Auto Follow Pattern API request. +// +type CCRPutAutoFollowPatternRequest struct { + Body io.Reader + + Name string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CCRPutAutoFollowPatternRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_ccr") + 1 + len("auto_follow") + 1 + len(r.Name)) + path.WriteString("/") + path.WriteString("_ccr") + path.WriteString("/") + path.WriteString("auto_follow") + path.WriteString("/") + path.WriteString(r.Name) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CCRPutAutoFollowPattern) WithContext(v context.Context) func(*CCRPutAutoFollowPatternRequest) { + return func(r *CCRPutAutoFollowPatternRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CCRPutAutoFollowPattern) WithPretty() func(*CCRPutAutoFollowPatternRequest) { + return func(r *CCRPutAutoFollowPatternRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CCRPutAutoFollowPattern) WithHuman() func(*CCRPutAutoFollowPatternRequest) { + return func(r *CCRPutAutoFollowPatternRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CCRPutAutoFollowPattern) WithErrorTrace() func(*CCRPutAutoFollowPatternRequest) { + return func(r *CCRPutAutoFollowPatternRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CCRPutAutoFollowPattern) WithFilterPath(v ...string) func(*CCRPutAutoFollowPatternRequest) { + return func(r *CCRPutAutoFollowPatternRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CCRPutAutoFollowPattern) WithHeader(h map[string]string) func(*CCRPutAutoFollowPatternRequest) { + return func(r *CCRPutAutoFollowPatternRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CCRPutAutoFollowPattern) WithOpaqueID(s string) func(*CCRPutAutoFollowPatternRequest) { + return func(r *CCRPutAutoFollowPatternRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.resume_auto_follow_pattern.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.resume_auto_follow_pattern.go new file mode 100644 index 00000000000..e1e859c5409 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.resume_auto_follow_pattern.go @@ -0,0 +1,192 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newCCRResumeAutoFollowPatternFunc(t Transport) CCRResumeAutoFollowPattern { + return func(name string, o ...func(*CCRResumeAutoFollowPatternRequest)) (*Response, error) { + var r = CCRResumeAutoFollowPatternRequest{Name: name} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CCRResumeAutoFollowPattern - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-resume-auto-follow-pattern.html. +// +type CCRResumeAutoFollowPattern func(name string, o ...func(*CCRResumeAutoFollowPatternRequest)) (*Response, error) + +// CCRResumeAutoFollowPatternRequest configures the CCR Resume Auto Follow Pattern API request. +// +type CCRResumeAutoFollowPatternRequest struct { + Name string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CCRResumeAutoFollowPatternRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_ccr") + 1 + len("auto_follow") + 1 + len(r.Name) + 1 + len("resume")) + path.WriteString("/") + path.WriteString("_ccr") + path.WriteString("/") + path.WriteString("auto_follow") + path.WriteString("/") + path.WriteString(r.Name) + path.WriteString("/") + path.WriteString("resume") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CCRResumeAutoFollowPattern) WithContext(v context.Context) func(*CCRResumeAutoFollowPatternRequest) { + return func(r *CCRResumeAutoFollowPatternRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CCRResumeAutoFollowPattern) WithPretty() func(*CCRResumeAutoFollowPatternRequest) { + return func(r *CCRResumeAutoFollowPatternRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CCRResumeAutoFollowPattern) WithHuman() func(*CCRResumeAutoFollowPatternRequest) { + return func(r *CCRResumeAutoFollowPatternRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CCRResumeAutoFollowPattern) WithErrorTrace() func(*CCRResumeAutoFollowPatternRequest) { + return func(r *CCRResumeAutoFollowPatternRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CCRResumeAutoFollowPattern) WithFilterPath(v ...string) func(*CCRResumeAutoFollowPatternRequest) { + return func(r *CCRResumeAutoFollowPatternRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CCRResumeAutoFollowPattern) WithHeader(h map[string]string) func(*CCRResumeAutoFollowPatternRequest) { + return func(r *CCRResumeAutoFollowPatternRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CCRResumeAutoFollowPattern) WithOpaqueID(s string) func(*CCRResumeAutoFollowPatternRequest) { + return func(r *CCRResumeAutoFollowPatternRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.resume_follow.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.resume_follow.go new file mode 100644 index 00000000000..550914d8194 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.resume_follow.go @@ -0,0 +1,205 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newCCRResumeFollowFunc(t Transport) CCRResumeFollow { + return func(index string, o ...func(*CCRResumeFollowRequest)) (*Response, error) { + var r = CCRResumeFollowRequest{Index: index} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CCRResumeFollow - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-post-resume-follow.html. +// +type CCRResumeFollow func(index string, o ...func(*CCRResumeFollowRequest)) (*Response, error) + +// CCRResumeFollowRequest configures the CCR Resume Follow API request. +// +type CCRResumeFollowRequest struct { + Index string + + Body io.Reader + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CCRResumeFollowRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len(r.Index) + 1 + len("_ccr") + 1 + len("resume_follow")) + path.WriteString("/") + path.WriteString(r.Index) + path.WriteString("/") + path.WriteString("_ccr") + path.WriteString("/") + path.WriteString("resume_follow") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CCRResumeFollow) WithContext(v context.Context) func(*CCRResumeFollowRequest) { + return func(r *CCRResumeFollowRequest) { + r.ctx = v + } +} + +// WithBody - The name of the leader index and other optional ccr related parameters. +// +func (f CCRResumeFollow) WithBody(v io.Reader) func(*CCRResumeFollowRequest) { + return func(r *CCRResumeFollowRequest) { + r.Body = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CCRResumeFollow) WithPretty() func(*CCRResumeFollowRequest) { + return func(r *CCRResumeFollowRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CCRResumeFollow) WithHuman() func(*CCRResumeFollowRequest) { + return func(r *CCRResumeFollowRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CCRResumeFollow) WithErrorTrace() func(*CCRResumeFollowRequest) { + return func(r *CCRResumeFollowRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CCRResumeFollow) WithFilterPath(v ...string) func(*CCRResumeFollowRequest) { + return func(r *CCRResumeFollowRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CCRResumeFollow) WithHeader(h map[string]string) func(*CCRResumeFollowRequest) { + return func(r *CCRResumeFollowRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CCRResumeFollow) WithOpaqueID(s string) func(*CCRResumeFollowRequest) { + return func(r *CCRResumeFollowRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.stats.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.stats.go new file mode 100644 index 00000000000..ea989bbdb2d --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.stats.go @@ -0,0 +1,183 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newCCRStatsFunc(t Transport) CCRStats { + return func(o ...func(*CCRStatsRequest)) (*Response, error) { + var r = CCRStatsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CCRStats - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-stats.html. +// +type CCRStats func(o ...func(*CCRStatsRequest)) (*Response, error) + +// CCRStatsRequest configures the CCR Stats API request. +// +type CCRStatsRequest struct { + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CCRStatsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_ccr/stats")) + path.WriteString("/_ccr/stats") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CCRStats) WithContext(v context.Context) func(*CCRStatsRequest) { + return func(r *CCRStatsRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CCRStats) WithPretty() func(*CCRStatsRequest) { + return func(r *CCRStatsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CCRStats) WithHuman() func(*CCRStatsRequest) { + return func(r *CCRStatsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CCRStats) WithErrorTrace() func(*CCRStatsRequest) { + return func(r *CCRStatsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CCRStats) WithFilterPath(v ...string) func(*CCRStatsRequest) { + return func(r *CCRStatsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CCRStats) WithHeader(h map[string]string) func(*CCRStatsRequest) { + return func(r *CCRStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CCRStats) WithOpaqueID(s string) func(*CCRStatsRequest) { + return func(r *CCRStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.unfollow.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.unfollow.go new file mode 100644 index 00000000000..34a4545f736 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ccr.unfollow.go @@ -0,0 +1,190 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newCCRUnfollowFunc(t Transport) CCRUnfollow { + return func(index string, o ...func(*CCRUnfollowRequest)) (*Response, error) { + var r = CCRUnfollowRequest{Index: index} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// CCRUnfollow - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current. +// +type CCRUnfollow func(index string, o ...func(*CCRUnfollowRequest)) (*Response, error) + +// CCRUnfollowRequest configures the CCR Unfollow API request. +// +type CCRUnfollowRequest struct { + Index string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r CCRUnfollowRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len(r.Index) + 1 + len("_ccr") + 1 + len("unfollow")) + path.WriteString("/") + path.WriteString(r.Index) + path.WriteString("/") + path.WriteString("_ccr") + path.WriteString("/") + path.WriteString("unfollow") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f CCRUnfollow) WithContext(v context.Context) func(*CCRUnfollowRequest) { + return func(r *CCRUnfollowRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f CCRUnfollow) WithPretty() func(*CCRUnfollowRequest) { + return func(r *CCRUnfollowRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f CCRUnfollow) WithHuman() func(*CCRUnfollowRequest) { + return func(r *CCRUnfollowRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f CCRUnfollow) WithErrorTrace() func(*CCRUnfollowRequest) { + return func(r *CCRUnfollowRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f CCRUnfollow) WithFilterPath(v ...string) func(*CCRUnfollowRequest) { + return func(r *CCRUnfollowRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f CCRUnfollow) WithHeader(h map[string]string) func(*CCRUnfollowRequest) { + return func(r *CCRUnfollowRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f CCRUnfollow) WithOpaqueID(s string) func(*CCRUnfollowRequest) { + return func(r *CCRUnfollowRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.delete_data_frame_transform.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.delete_data_frame_transform.go new file mode 100644 index 00000000000..917fe6191be --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.delete_data_frame_transform.go @@ -0,0 +1,187 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newDataFrameDeleteDataFrameTransformFunc(t Transport) DataFrameDeleteDataFrameTransform { + return func(transform_id string, o ...func(*DataFrameDeleteDataFrameTransformRequest)) (*Response, error) { + var r = DataFrameDeleteDataFrameTransformRequest{TransformID: transform_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// DataFrameDeleteDataFrameTransform - https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-data-frame-transform.html +// +type DataFrameDeleteDataFrameTransform func(transform_id string, o ...func(*DataFrameDeleteDataFrameTransformRequest)) (*Response, error) + +// DataFrameDeleteDataFrameTransformRequest configures the Data Frame Delete Data Frame Transform API request. +// +type DataFrameDeleteDataFrameTransformRequest struct { + TransformID string + + Force *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r DataFrameDeleteDataFrameTransformRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_data_frame") + 1 + len("transforms") + 1 + len(r.TransformID)) + path.WriteString("/") + path.WriteString("_data_frame") + path.WriteString("/") + path.WriteString("transforms") + path.WriteString("/") + path.WriteString(r.TransformID) + + params = make(map[string]string) + + if r.Force != nil { + params["force"] = strconv.FormatBool(*r.Force) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, _ := newRequest(method, path.String(), nil) + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f DataFrameDeleteDataFrameTransform) WithContext(v context.Context) func(*DataFrameDeleteDataFrameTransformRequest) { + return func(r *DataFrameDeleteDataFrameTransformRequest) { + r.ctx = v + } +} + +// WithForce - when `true`, the transform is deleted regardless of its current state. the default value is `false`, meaning that the transform must be `stopped` before it can be deleted.. +// +func (f DataFrameDeleteDataFrameTransform) WithForce(v bool) func(*DataFrameDeleteDataFrameTransformRequest) { + return func(r *DataFrameDeleteDataFrameTransformRequest) { + r.Force = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f DataFrameDeleteDataFrameTransform) WithPretty() func(*DataFrameDeleteDataFrameTransformRequest) { + return func(r *DataFrameDeleteDataFrameTransformRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f DataFrameDeleteDataFrameTransform) WithHuman() func(*DataFrameDeleteDataFrameTransformRequest) { + return func(r *DataFrameDeleteDataFrameTransformRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f DataFrameDeleteDataFrameTransform) WithErrorTrace() func(*DataFrameDeleteDataFrameTransformRequest) { + return func(r *DataFrameDeleteDataFrameTransformRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f DataFrameDeleteDataFrameTransform) WithFilterPath(v ...string) func(*DataFrameDeleteDataFrameTransformRequest) { + return func(r *DataFrameDeleteDataFrameTransformRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f DataFrameDeleteDataFrameTransform) WithHeader(h map[string]string) func(*DataFrameDeleteDataFrameTransformRequest) { + return func(r *DataFrameDeleteDataFrameTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.get_data_frame_transform.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.get_data_frame_transform.go new file mode 100644 index 00000000000..0b29224974a --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.get_data_frame_transform.go @@ -0,0 +1,223 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newDataFrameGetDataFrameTransformFunc(t Transport) DataFrameGetDataFrameTransform { + return func(o ...func(*DataFrameGetDataFrameTransformRequest)) (*Response, error) { + var r = DataFrameGetDataFrameTransformRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// DataFrameGetDataFrameTransform - https://www.elastic.co/guide/en/elasticsearch/reference/current/get-data-frame-transform.html +// +type DataFrameGetDataFrameTransform func(o ...func(*DataFrameGetDataFrameTransformRequest)) (*Response, error) + +// DataFrameGetDataFrameTransformRequest configures the Data Frame Get Data Frame Transform API request. +// +type DataFrameGetDataFrameTransformRequest struct { + TransformID string + + AllowNoMatch *bool + From *int + Size *int + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r DataFrameGetDataFrameTransformRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_data_frame") + 1 + len("transforms") + 1 + len(r.TransformID)) + path.WriteString("/") + path.WriteString("_data_frame") + path.WriteString("/") + path.WriteString("transforms") + if r.TransformID != "" { + path.WriteString("/") + path.WriteString(r.TransformID) + } + + params = make(map[string]string) + + if r.AllowNoMatch != nil { + params["allow_no_match"] = strconv.FormatBool(*r.AllowNoMatch) + } + + if r.From != nil { + params["from"] = strconv.FormatInt(int64(*r.From), 10) + } + + if r.Size != nil { + params["size"] = strconv.FormatInt(int64(*r.Size), 10) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, _ := newRequest(method, path.String(), nil) + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f DataFrameGetDataFrameTransform) WithContext(v context.Context) func(*DataFrameGetDataFrameTransformRequest) { + return func(r *DataFrameGetDataFrameTransformRequest) { + r.ctx = v + } +} + +// WithTransformID - the ID or comma delimited list of ID expressions of the transforms to get, '_all' or '*' implies get all transforms. +// +func (f DataFrameGetDataFrameTransform) WithTransformID(v string) func(*DataFrameGetDataFrameTransformRequest) { + return func(r *DataFrameGetDataFrameTransformRequest) { + r.TransformID = v + } +} + +// WithAllowNoMatch - whether to ignore if a wildcard expression matches no data frame transforms. (this includes `_all` string or when no data frame transforms have been specified). +// +func (f DataFrameGetDataFrameTransform) WithAllowNoMatch(v bool) func(*DataFrameGetDataFrameTransformRequest) { + return func(r *DataFrameGetDataFrameTransformRequest) { + r.AllowNoMatch = &v + } +} + +// WithFrom - skips a number of transform configs, defaults to 0. +// +func (f DataFrameGetDataFrameTransform) WithFrom(v int) func(*DataFrameGetDataFrameTransformRequest) { + return func(r *DataFrameGetDataFrameTransformRequest) { + r.From = &v + } +} + +// WithSize - specifies a max number of transforms to get, defaults to 100. +// +func (f DataFrameGetDataFrameTransform) WithSize(v int) func(*DataFrameGetDataFrameTransformRequest) { + return func(r *DataFrameGetDataFrameTransformRequest) { + r.Size = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f DataFrameGetDataFrameTransform) WithPretty() func(*DataFrameGetDataFrameTransformRequest) { + return func(r *DataFrameGetDataFrameTransformRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f DataFrameGetDataFrameTransform) WithHuman() func(*DataFrameGetDataFrameTransformRequest) { + return func(r *DataFrameGetDataFrameTransformRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f DataFrameGetDataFrameTransform) WithErrorTrace() func(*DataFrameGetDataFrameTransformRequest) { + return func(r *DataFrameGetDataFrameTransformRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f DataFrameGetDataFrameTransform) WithFilterPath(v ...string) func(*DataFrameGetDataFrameTransformRequest) { + return func(r *DataFrameGetDataFrameTransformRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f DataFrameGetDataFrameTransform) WithHeader(h map[string]string) func(*DataFrameGetDataFrameTransformRequest) { + return func(r *DataFrameGetDataFrameTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.get_data_frame_transform_stats.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.get_data_frame_transform_stats.go new file mode 100644 index 00000000000..1b5a65e83a9 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.get_data_frame_transform_stats.go @@ -0,0 +1,225 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newDataFrameGetDataFrameTransformStatsFunc(t Transport) DataFrameGetDataFrameTransformStats { + return func(o ...func(*DataFrameGetDataFrameTransformStatsRequest)) (*Response, error) { + var r = DataFrameGetDataFrameTransformStatsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// DataFrameGetDataFrameTransformStats - https://www.elastic.co/guide/en/elasticsearch/reference/current/get-data-frame-transform-stats.html +// +type DataFrameGetDataFrameTransformStats func(o ...func(*DataFrameGetDataFrameTransformStatsRequest)) (*Response, error) + +// DataFrameGetDataFrameTransformStatsRequest configures the Data Frame Get Data Frame Transform Stats API request. +// +type DataFrameGetDataFrameTransformStatsRequest struct { + TransformID string + + AllowNoMatch *bool + From *int + Size *int + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r DataFrameGetDataFrameTransformStatsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_data_frame") + 1 + len("transforms") + 1 + len(r.TransformID) + 1 + len("_stats")) + path.WriteString("/") + path.WriteString("_data_frame") + path.WriteString("/") + path.WriteString("transforms") + if r.TransformID != "" { + path.WriteString("/") + path.WriteString(r.TransformID) + } + path.WriteString("/") + path.WriteString("_stats") + + params = make(map[string]string) + + if r.AllowNoMatch != nil { + params["allow_no_match"] = strconv.FormatBool(*r.AllowNoMatch) + } + + if r.From != nil { + params["from"] = strconv.FormatInt(int64(*r.From), 10) + } + + if r.Size != nil { + params["size"] = strconv.FormatInt(int64(*r.Size), 10) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, _ := newRequest(method, path.String(), nil) + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f DataFrameGetDataFrameTransformStats) WithContext(v context.Context) func(*DataFrameGetDataFrameTransformStatsRequest) { + return func(r *DataFrameGetDataFrameTransformStatsRequest) { + r.ctx = v + } +} + +// WithTransformID - the ID of the transform for which to get stats. '_all' or '*' implies all transforms. +// +func (f DataFrameGetDataFrameTransformStats) WithTransformID(v string) func(*DataFrameGetDataFrameTransformStatsRequest) { + return func(r *DataFrameGetDataFrameTransformStatsRequest) { + r.TransformID = v + } +} + +// WithAllowNoMatch - whether to ignore if a wildcard expression matches no data frame transforms. (this includes `_all` string or when no data frame transforms have been specified). +// +func (f DataFrameGetDataFrameTransformStats) WithAllowNoMatch(v bool) func(*DataFrameGetDataFrameTransformStatsRequest) { + return func(r *DataFrameGetDataFrameTransformStatsRequest) { + r.AllowNoMatch = &v + } +} + +// WithFrom - skips a number of transform stats, defaults to 0. +// +func (f DataFrameGetDataFrameTransformStats) WithFrom(v int) func(*DataFrameGetDataFrameTransformStatsRequest) { + return func(r *DataFrameGetDataFrameTransformStatsRequest) { + r.From = &v + } +} + +// WithSize - specifies a max number of transform stats to get, defaults to 100. +// +func (f DataFrameGetDataFrameTransformStats) WithSize(v int) func(*DataFrameGetDataFrameTransformStatsRequest) { + return func(r *DataFrameGetDataFrameTransformStatsRequest) { + r.Size = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f DataFrameGetDataFrameTransformStats) WithPretty() func(*DataFrameGetDataFrameTransformStatsRequest) { + return func(r *DataFrameGetDataFrameTransformStatsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f DataFrameGetDataFrameTransformStats) WithHuman() func(*DataFrameGetDataFrameTransformStatsRequest) { + return func(r *DataFrameGetDataFrameTransformStatsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f DataFrameGetDataFrameTransformStats) WithErrorTrace() func(*DataFrameGetDataFrameTransformStatsRequest) { + return func(r *DataFrameGetDataFrameTransformStatsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f DataFrameGetDataFrameTransformStats) WithFilterPath(v ...string) func(*DataFrameGetDataFrameTransformStatsRequest) { + return func(r *DataFrameGetDataFrameTransformStatsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f DataFrameGetDataFrameTransformStats) WithHeader(h map[string]string) func(*DataFrameGetDataFrameTransformStatsRequest) { + return func(r *DataFrameGetDataFrameTransformStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.preview_data_frame_transform.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.preview_data_frame_transform.go new file mode 100644 index 00000000000..4caa371d966 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.preview_data_frame_transform.go @@ -0,0 +1,172 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newDataFramePreviewDataFrameTransformFunc(t Transport) DataFramePreviewDataFrameTransform { + return func(body io.Reader, o ...func(*DataFramePreviewDataFrameTransformRequest)) (*Response, error) { + var r = DataFramePreviewDataFrameTransformRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// DataFramePreviewDataFrameTransform - https://www.elastic.co/guide/en/elasticsearch/reference/current/preview-data-frame-transform.html +// +type DataFramePreviewDataFrameTransform func(body io.Reader, o ...func(*DataFramePreviewDataFrameTransformRequest)) (*Response, error) + +// DataFramePreviewDataFrameTransformRequest configures the Data Frame Preview Data Frame Transform API request. +// +type DataFramePreviewDataFrameTransformRequest struct { + Body io.Reader + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r DataFramePreviewDataFrameTransformRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(len("/_data_frame/transforms/_preview")) + path.WriteString("/_data_frame/transforms/_preview") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, _ := newRequest(method, path.String(), r.Body) + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f DataFramePreviewDataFrameTransform) WithContext(v context.Context) func(*DataFramePreviewDataFrameTransformRequest) { + return func(r *DataFramePreviewDataFrameTransformRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f DataFramePreviewDataFrameTransform) WithPretty() func(*DataFramePreviewDataFrameTransformRequest) { + return func(r *DataFramePreviewDataFrameTransformRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f DataFramePreviewDataFrameTransform) WithHuman() func(*DataFramePreviewDataFrameTransformRequest) { + return func(r *DataFramePreviewDataFrameTransformRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f DataFramePreviewDataFrameTransform) WithErrorTrace() func(*DataFramePreviewDataFrameTransformRequest) { + return func(r *DataFramePreviewDataFrameTransformRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f DataFramePreviewDataFrameTransform) WithFilterPath(v ...string) func(*DataFramePreviewDataFrameTransformRequest) { + return func(r *DataFramePreviewDataFrameTransformRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f DataFramePreviewDataFrameTransform) WithHeader(h map[string]string) func(*DataFramePreviewDataFrameTransformRequest) { + return func(r *DataFramePreviewDataFrameTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.put_data_frame_transform.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.put_data_frame_transform.go new file mode 100644 index 00000000000..b5f8f820c82 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.put_data_frame_transform.go @@ -0,0 +1,194 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newDataFramePutDataFrameTransformFunc(t Transport) DataFramePutDataFrameTransform { + return func(body io.Reader, transform_id string, o ...func(*DataFramePutDataFrameTransformRequest)) (*Response, error) { + var r = DataFramePutDataFrameTransformRequest{Body: body, TransformID: transform_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// DataFramePutDataFrameTransform - https://www.elastic.co/guide/en/elasticsearch/reference/current/put-data-frame-transform.html +// +type DataFramePutDataFrameTransform func(body io.Reader, transform_id string, o ...func(*DataFramePutDataFrameTransformRequest)) (*Response, error) + +// DataFramePutDataFrameTransformRequest configures the Data Frame Put Data Frame Transform API request. +// +type DataFramePutDataFrameTransformRequest struct { + Body io.Reader + + TransformID string + + DeferValidation *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r DataFramePutDataFrameTransformRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_data_frame") + 1 + len("transforms") + 1 + len(r.TransformID)) + path.WriteString("/") + path.WriteString("_data_frame") + path.WriteString("/") + path.WriteString("transforms") + path.WriteString("/") + path.WriteString(r.TransformID) + + params = make(map[string]string) + + if r.DeferValidation != nil { + params["defer_validation"] = strconv.FormatBool(*r.DeferValidation) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, _ := newRequest(method, path.String(), r.Body) + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f DataFramePutDataFrameTransform) WithContext(v context.Context) func(*DataFramePutDataFrameTransformRequest) { + return func(r *DataFramePutDataFrameTransformRequest) { + r.ctx = v + } +} + +// WithDeferValidation - if validations should be deferred until data frame transform starts, defaults to false.. +// +func (f DataFramePutDataFrameTransform) WithDeferValidation(v bool) func(*DataFramePutDataFrameTransformRequest) { + return func(r *DataFramePutDataFrameTransformRequest) { + r.DeferValidation = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f DataFramePutDataFrameTransform) WithPretty() func(*DataFramePutDataFrameTransformRequest) { + return func(r *DataFramePutDataFrameTransformRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f DataFramePutDataFrameTransform) WithHuman() func(*DataFramePutDataFrameTransformRequest) { + return func(r *DataFramePutDataFrameTransformRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f DataFramePutDataFrameTransform) WithErrorTrace() func(*DataFramePutDataFrameTransformRequest) { + return func(r *DataFramePutDataFrameTransformRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f DataFramePutDataFrameTransform) WithFilterPath(v ...string) func(*DataFramePutDataFrameTransformRequest) { + return func(r *DataFramePutDataFrameTransformRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f DataFramePutDataFrameTransform) WithHeader(h map[string]string) func(*DataFramePutDataFrameTransformRequest) { + return func(r *DataFramePutDataFrameTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.start_data_frame_transform.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.start_data_frame_transform.go new file mode 100644 index 00000000000..80c763f7264 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.start_data_frame_transform.go @@ -0,0 +1,189 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package esapi + +import ( + "context" + "net/http" + "strings" + "time" +) + +func newDataFrameStartDataFrameTransformFunc(t Transport) DataFrameStartDataFrameTransform { + return func(transform_id string, o ...func(*DataFrameStartDataFrameTransformRequest)) (*Response, error) { + var r = DataFrameStartDataFrameTransformRequest{TransformID: transform_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// DataFrameStartDataFrameTransform - https://www.elastic.co/guide/en/elasticsearch/reference/current/start-data-frame-transform.html +// +type DataFrameStartDataFrameTransform func(transform_id string, o ...func(*DataFrameStartDataFrameTransformRequest)) (*Response, error) + +// DataFrameStartDataFrameTransformRequest configures the Data Frame Start Data Frame Transform API request. +// +type DataFrameStartDataFrameTransformRequest struct { + TransformID string + + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r DataFrameStartDataFrameTransformRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_data_frame") + 1 + len("transforms") + 1 + len(r.TransformID) + 1 + len("_start")) + path.WriteString("/") + path.WriteString("_data_frame") + path.WriteString("/") + path.WriteString("transforms") + path.WriteString("/") + path.WriteString(r.TransformID) + path.WriteString("/") + path.WriteString("_start") + + params = make(map[string]string) + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, _ := newRequest(method, path.String(), nil) + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f DataFrameStartDataFrameTransform) WithContext(v context.Context) func(*DataFrameStartDataFrameTransformRequest) { + return func(r *DataFrameStartDataFrameTransformRequest) { + r.ctx = v + } +} + +// WithTimeout - controls the time to wait for the transform to start. +// +func (f DataFrameStartDataFrameTransform) WithTimeout(v time.Duration) func(*DataFrameStartDataFrameTransformRequest) { + return func(r *DataFrameStartDataFrameTransformRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f DataFrameStartDataFrameTransform) WithPretty() func(*DataFrameStartDataFrameTransformRequest) { + return func(r *DataFrameStartDataFrameTransformRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f DataFrameStartDataFrameTransform) WithHuman() func(*DataFrameStartDataFrameTransformRequest) { + return func(r *DataFrameStartDataFrameTransformRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f DataFrameStartDataFrameTransform) WithErrorTrace() func(*DataFrameStartDataFrameTransformRequest) { + return func(r *DataFrameStartDataFrameTransformRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f DataFrameStartDataFrameTransform) WithFilterPath(v ...string) func(*DataFrameStartDataFrameTransformRequest) { + return func(r *DataFrameStartDataFrameTransformRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f DataFrameStartDataFrameTransform) WithHeader(h map[string]string) func(*DataFrameStartDataFrameTransformRequest) { + return func(r *DataFrameStartDataFrameTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.stop_data_frame_transform.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.stop_data_frame_transform.go new file mode 100644 index 00000000000..ad70b5046d9 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.stop_data_frame_transform.go @@ -0,0 +1,216 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newDataFrameStopDataFrameTransformFunc(t Transport) DataFrameStopDataFrameTransform { + return func(transform_id string, o ...func(*DataFrameStopDataFrameTransformRequest)) (*Response, error) { + var r = DataFrameStopDataFrameTransformRequest{TransformID: transform_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// DataFrameStopDataFrameTransform - https://www.elastic.co/guide/en/elasticsearch/reference/current/stop-data-frame-transform.html +// +type DataFrameStopDataFrameTransform func(transform_id string, o ...func(*DataFrameStopDataFrameTransformRequest)) (*Response, error) + +// DataFrameStopDataFrameTransformRequest configures the Data Frame Stop Data Frame Transform API request. +// +type DataFrameStopDataFrameTransformRequest struct { + TransformID string + + AllowNoMatch *bool + Timeout time.Duration + WaitForCompletion *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r DataFrameStopDataFrameTransformRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_data_frame") + 1 + len("transforms") + 1 + len(r.TransformID) + 1 + len("_stop")) + path.WriteString("/") + path.WriteString("_data_frame") + path.WriteString("/") + path.WriteString("transforms") + path.WriteString("/") + path.WriteString(r.TransformID) + path.WriteString("/") + path.WriteString("_stop") + + params = make(map[string]string) + + if r.AllowNoMatch != nil { + params["allow_no_match"] = strconv.FormatBool(*r.AllowNoMatch) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.WaitForCompletion != nil { + params["wait_for_completion"] = strconv.FormatBool(*r.WaitForCompletion) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, _ := newRequest(method, path.String(), nil) + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f DataFrameStopDataFrameTransform) WithContext(v context.Context) func(*DataFrameStopDataFrameTransformRequest) { + return func(r *DataFrameStopDataFrameTransformRequest) { + r.ctx = v + } +} + +// WithAllowNoMatch - whether to ignore if a wildcard expression matches no data frame transforms. (this includes `_all` string or when no data frame transforms have been specified). +// +func (f DataFrameStopDataFrameTransform) WithAllowNoMatch(v bool) func(*DataFrameStopDataFrameTransformRequest) { + return func(r *DataFrameStopDataFrameTransformRequest) { + r.AllowNoMatch = &v + } +} + +// WithTimeout - controls the time to wait until the transform has stopped. default to 30 seconds. +// +func (f DataFrameStopDataFrameTransform) WithTimeout(v time.Duration) func(*DataFrameStopDataFrameTransformRequest) { + return func(r *DataFrameStopDataFrameTransformRequest) { + r.Timeout = v + } +} + +// WithWaitForCompletion - whether to wait for the transform to fully stop before returning or not. default to false. +// +func (f DataFrameStopDataFrameTransform) WithWaitForCompletion(v bool) func(*DataFrameStopDataFrameTransformRequest) { + return func(r *DataFrameStopDataFrameTransformRequest) { + r.WaitForCompletion = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f DataFrameStopDataFrameTransform) WithPretty() func(*DataFrameStopDataFrameTransformRequest) { + return func(r *DataFrameStopDataFrameTransformRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f DataFrameStopDataFrameTransform) WithHuman() func(*DataFrameStopDataFrameTransformRequest) { + return func(r *DataFrameStopDataFrameTransformRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f DataFrameStopDataFrameTransform) WithErrorTrace() func(*DataFrameStopDataFrameTransformRequest) { + return func(r *DataFrameStopDataFrameTransformRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f DataFrameStopDataFrameTransform) WithFilterPath(v ...string) func(*DataFrameStopDataFrameTransformRequest) { + return func(r *DataFrameStopDataFrameTransformRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f DataFrameStopDataFrameTransform) WithHeader(h map[string]string) func(*DataFrameStopDataFrameTransformRequest) { + return func(r *DataFrameStopDataFrameTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.update_data_frame_transform.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.update_data_frame_transform.go new file mode 100644 index 00000000000..439e1d43439 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame.update_data_frame_transform.go @@ -0,0 +1,196 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newDataFrameUpdateDataFrameTransformFunc(t Transport) DataFrameUpdateDataFrameTransform { + return func(body io.Reader, transform_id string, o ...func(*DataFrameUpdateDataFrameTransformRequest)) (*Response, error) { + var r = DataFrameUpdateDataFrameTransformRequest{Body: body, TransformID: transform_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// DataFrameUpdateDataFrameTransform - https://www.elastic.co/guide/en/elasticsearch/reference/current/update-data-frame-transform.html +// +type DataFrameUpdateDataFrameTransform func(body io.Reader, transform_id string, o ...func(*DataFrameUpdateDataFrameTransformRequest)) (*Response, error) + +// DataFrameUpdateDataFrameTransformRequest configures the Data Frame Update Data Frame Transform API request. +// +type DataFrameUpdateDataFrameTransformRequest struct { + Body io.Reader + + TransformID string + + DeferValidation *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r DataFrameUpdateDataFrameTransformRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_data_frame") + 1 + len("transforms") + 1 + len(r.TransformID) + 1 + len("_update")) + path.WriteString("/") + path.WriteString("_data_frame") + path.WriteString("/") + path.WriteString("transforms") + path.WriteString("/") + path.WriteString(r.TransformID) + path.WriteString("/") + path.WriteString("_update") + + params = make(map[string]string) + + if r.DeferValidation != nil { + params["defer_validation"] = strconv.FormatBool(*r.DeferValidation) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, _ := newRequest(method, path.String(), r.Body) + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f DataFrameUpdateDataFrameTransform) WithContext(v context.Context) func(*DataFrameUpdateDataFrameTransformRequest) { + return func(r *DataFrameUpdateDataFrameTransformRequest) { + r.ctx = v + } +} + +// WithDeferValidation - if validations should be deferred until data frame transform starts, defaults to false.. +// +func (f DataFrameUpdateDataFrameTransform) WithDeferValidation(v bool) func(*DataFrameUpdateDataFrameTransformRequest) { + return func(r *DataFrameUpdateDataFrameTransformRequest) { + r.DeferValidation = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f DataFrameUpdateDataFrameTransform) WithPretty() func(*DataFrameUpdateDataFrameTransformRequest) { + return func(r *DataFrameUpdateDataFrameTransformRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f DataFrameUpdateDataFrameTransform) WithHuman() func(*DataFrameUpdateDataFrameTransformRequest) { + return func(r *DataFrameUpdateDataFrameTransformRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f DataFrameUpdateDataFrameTransform) WithErrorTrace() func(*DataFrameUpdateDataFrameTransformRequest) { + return func(r *DataFrameUpdateDataFrameTransformRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f DataFrameUpdateDataFrameTransform) WithFilterPath(v ...string) func(*DataFrameUpdateDataFrameTransformRequest) { + return func(r *DataFrameUpdateDataFrameTransformRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f DataFrameUpdateDataFrameTransform) WithHeader(h map[string]string) func(*DataFrameUpdateDataFrameTransformRequest) { + return func(r *DataFrameUpdateDataFrameTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.delete_transform.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.delete_transform.go new file mode 100644 index 00000000000..601b1225293 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.delete_transform.go @@ -0,0 +1,205 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newDataFrameTransformDeprecatedDeleteTransformFunc(t Transport) DataFrameTransformDeprecatedDeleteTransform { + return func(transform_id string, o ...func(*DataFrameTransformDeprecatedDeleteTransformRequest)) (*Response, error) { + var r = DataFrameTransformDeprecatedDeleteTransformRequest{TransformID: transform_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// DataFrameTransformDeprecatedDeleteTransform - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-transform.html. +// +type DataFrameTransformDeprecatedDeleteTransform func(transform_id string, o ...func(*DataFrameTransformDeprecatedDeleteTransformRequest)) (*Response, error) + +// DataFrameTransformDeprecatedDeleteTransformRequest configures the Data Frame Transform Deprecated Delete Transform API request. +// +type DataFrameTransformDeprecatedDeleteTransformRequest struct { + TransformID string + + Force *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r DataFrameTransformDeprecatedDeleteTransformRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_data_frame") + 1 + len("transforms") + 1 + len(r.TransformID)) + path.WriteString("/") + path.WriteString("_data_frame") + path.WriteString("/") + path.WriteString("transforms") + path.WriteString("/") + path.WriteString(r.TransformID) + + params = make(map[string]string) + + if r.Force != nil { + params["force"] = strconv.FormatBool(*r.Force) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f DataFrameTransformDeprecatedDeleteTransform) WithContext(v context.Context) func(*DataFrameTransformDeprecatedDeleteTransformRequest) { + return func(r *DataFrameTransformDeprecatedDeleteTransformRequest) { + r.ctx = v + } +} + +// WithForce - when `true`, the transform is deleted regardless of its current state. the default value is `false`, meaning that the transform must be `stopped` before it can be deleted.. +// +func (f DataFrameTransformDeprecatedDeleteTransform) WithForce(v bool) func(*DataFrameTransformDeprecatedDeleteTransformRequest) { + return func(r *DataFrameTransformDeprecatedDeleteTransformRequest) { + r.Force = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f DataFrameTransformDeprecatedDeleteTransform) WithPretty() func(*DataFrameTransformDeprecatedDeleteTransformRequest) { + return func(r *DataFrameTransformDeprecatedDeleteTransformRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f DataFrameTransformDeprecatedDeleteTransform) WithHuman() func(*DataFrameTransformDeprecatedDeleteTransformRequest) { + return func(r *DataFrameTransformDeprecatedDeleteTransformRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f DataFrameTransformDeprecatedDeleteTransform) WithErrorTrace() func(*DataFrameTransformDeprecatedDeleteTransformRequest) { + return func(r *DataFrameTransformDeprecatedDeleteTransformRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f DataFrameTransformDeprecatedDeleteTransform) WithFilterPath(v ...string) func(*DataFrameTransformDeprecatedDeleteTransformRequest) { + return func(r *DataFrameTransformDeprecatedDeleteTransformRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f DataFrameTransformDeprecatedDeleteTransform) WithHeader(h map[string]string) func(*DataFrameTransformDeprecatedDeleteTransformRequest) { + return func(r *DataFrameTransformDeprecatedDeleteTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f DataFrameTransformDeprecatedDeleteTransform) WithOpaqueID(s string) func(*DataFrameTransformDeprecatedDeleteTransformRequest) { + return func(r *DataFrameTransformDeprecatedDeleteTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.get_transform.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.get_transform.go new file mode 100644 index 00000000000..1afd4e973ed --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.get_transform.go @@ -0,0 +1,241 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newDataFrameTransformDeprecatedGetTransformFunc(t Transport) DataFrameTransformDeprecatedGetTransform { + return func(o ...func(*DataFrameTransformDeprecatedGetTransformRequest)) (*Response, error) { + var r = DataFrameTransformDeprecatedGetTransformRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// DataFrameTransformDeprecatedGetTransform - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/get-transform.html. +// +type DataFrameTransformDeprecatedGetTransform func(o ...func(*DataFrameTransformDeprecatedGetTransformRequest)) (*Response, error) + +// DataFrameTransformDeprecatedGetTransformRequest configures the Data Frame Transform Deprecated Get Transform API request. +// +type DataFrameTransformDeprecatedGetTransformRequest struct { + TransformID string + + AllowNoMatch *bool + From *int + Size *int + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r DataFrameTransformDeprecatedGetTransformRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_data_frame") + 1 + len("transforms") + 1 + len(r.TransformID)) + path.WriteString("/") + path.WriteString("_data_frame") + path.WriteString("/") + path.WriteString("transforms") + if r.TransformID != "" { + path.WriteString("/") + path.WriteString(r.TransformID) + } + + params = make(map[string]string) + + if r.AllowNoMatch != nil { + params["allow_no_match"] = strconv.FormatBool(*r.AllowNoMatch) + } + + if r.From != nil { + params["from"] = strconv.FormatInt(int64(*r.From), 10) + } + + if r.Size != nil { + params["size"] = strconv.FormatInt(int64(*r.Size), 10) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f DataFrameTransformDeprecatedGetTransform) WithContext(v context.Context) func(*DataFrameTransformDeprecatedGetTransformRequest) { + return func(r *DataFrameTransformDeprecatedGetTransformRequest) { + r.ctx = v + } +} + +// WithTransformID - the ID or comma delimited list of ID expressions of the transforms to get, '_all' or '*' implies get all transforms. +// +func (f DataFrameTransformDeprecatedGetTransform) WithTransformID(v string) func(*DataFrameTransformDeprecatedGetTransformRequest) { + return func(r *DataFrameTransformDeprecatedGetTransformRequest) { + r.TransformID = v + } +} + +// WithAllowNoMatch - whether to ignore if a wildcard expression matches no transforms. (this includes `_all` string or when no transforms have been specified). +// +func (f DataFrameTransformDeprecatedGetTransform) WithAllowNoMatch(v bool) func(*DataFrameTransformDeprecatedGetTransformRequest) { + return func(r *DataFrameTransformDeprecatedGetTransformRequest) { + r.AllowNoMatch = &v + } +} + +// WithFrom - skips a number of transform configs, defaults to 0. +// +func (f DataFrameTransformDeprecatedGetTransform) WithFrom(v int) func(*DataFrameTransformDeprecatedGetTransformRequest) { + return func(r *DataFrameTransformDeprecatedGetTransformRequest) { + r.From = &v + } +} + +// WithSize - specifies a max number of transforms to get, defaults to 100. +// +func (f DataFrameTransformDeprecatedGetTransform) WithSize(v int) func(*DataFrameTransformDeprecatedGetTransformRequest) { + return func(r *DataFrameTransformDeprecatedGetTransformRequest) { + r.Size = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f DataFrameTransformDeprecatedGetTransform) WithPretty() func(*DataFrameTransformDeprecatedGetTransformRequest) { + return func(r *DataFrameTransformDeprecatedGetTransformRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f DataFrameTransformDeprecatedGetTransform) WithHuman() func(*DataFrameTransformDeprecatedGetTransformRequest) { + return func(r *DataFrameTransformDeprecatedGetTransformRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f DataFrameTransformDeprecatedGetTransform) WithErrorTrace() func(*DataFrameTransformDeprecatedGetTransformRequest) { + return func(r *DataFrameTransformDeprecatedGetTransformRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f DataFrameTransformDeprecatedGetTransform) WithFilterPath(v ...string) func(*DataFrameTransformDeprecatedGetTransformRequest) { + return func(r *DataFrameTransformDeprecatedGetTransformRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f DataFrameTransformDeprecatedGetTransform) WithHeader(h map[string]string) func(*DataFrameTransformDeprecatedGetTransformRequest) { + return func(r *DataFrameTransformDeprecatedGetTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f DataFrameTransformDeprecatedGetTransform) WithOpaqueID(s string) func(*DataFrameTransformDeprecatedGetTransformRequest) { + return func(r *DataFrameTransformDeprecatedGetTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.get_transform_stats.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.get_transform_stats.go new file mode 100644 index 00000000000..056f88214e9 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.get_transform_stats.go @@ -0,0 +1,233 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newDataFrameTransformDeprecatedGetTransformStatsFunc(t Transport) DataFrameTransformDeprecatedGetTransformStats { + return func(transform_id string, o ...func(*DataFrameTransformDeprecatedGetTransformStatsRequest)) (*Response, error) { + var r = DataFrameTransformDeprecatedGetTransformStatsRequest{TransformID: transform_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// DataFrameTransformDeprecatedGetTransformStats - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/get-transform-stats.html. +// +type DataFrameTransformDeprecatedGetTransformStats func(transform_id string, o ...func(*DataFrameTransformDeprecatedGetTransformStatsRequest)) (*Response, error) + +// DataFrameTransformDeprecatedGetTransformStatsRequest configures the Data Frame Transform Deprecated Get Transform Stats API request. +// +type DataFrameTransformDeprecatedGetTransformStatsRequest struct { + TransformID string + + AllowNoMatch *bool + From *int + Size *int + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r DataFrameTransformDeprecatedGetTransformStatsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_data_frame") + 1 + len("transforms") + 1 + len(r.TransformID) + 1 + len("_stats")) + path.WriteString("/") + path.WriteString("_data_frame") + path.WriteString("/") + path.WriteString("transforms") + path.WriteString("/") + path.WriteString(r.TransformID) + path.WriteString("/") + path.WriteString("_stats") + + params = make(map[string]string) + + if r.AllowNoMatch != nil { + params["allow_no_match"] = strconv.FormatBool(*r.AllowNoMatch) + } + + if r.From != nil { + params["from"] = strconv.FormatInt(int64(*r.From), 10) + } + + if r.Size != nil { + params["size"] = strconv.FormatInt(int64(*r.Size), 10) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f DataFrameTransformDeprecatedGetTransformStats) WithContext(v context.Context) func(*DataFrameTransformDeprecatedGetTransformStatsRequest) { + return func(r *DataFrameTransformDeprecatedGetTransformStatsRequest) { + r.ctx = v + } +} + +// WithAllowNoMatch - whether to ignore if a wildcard expression matches no transforms. (this includes `_all` string or when no transforms have been specified). +// +func (f DataFrameTransformDeprecatedGetTransformStats) WithAllowNoMatch(v bool) func(*DataFrameTransformDeprecatedGetTransformStatsRequest) { + return func(r *DataFrameTransformDeprecatedGetTransformStatsRequest) { + r.AllowNoMatch = &v + } +} + +// WithFrom - skips a number of transform stats, defaults to 0. +// +func (f DataFrameTransformDeprecatedGetTransformStats) WithFrom(v int) func(*DataFrameTransformDeprecatedGetTransformStatsRequest) { + return func(r *DataFrameTransformDeprecatedGetTransformStatsRequest) { + r.From = &v + } +} + +// WithSize - specifies a max number of transform stats to get, defaults to 100. +// +func (f DataFrameTransformDeprecatedGetTransformStats) WithSize(v int) func(*DataFrameTransformDeprecatedGetTransformStatsRequest) { + return func(r *DataFrameTransformDeprecatedGetTransformStatsRequest) { + r.Size = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f DataFrameTransformDeprecatedGetTransformStats) WithPretty() func(*DataFrameTransformDeprecatedGetTransformStatsRequest) { + return func(r *DataFrameTransformDeprecatedGetTransformStatsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f DataFrameTransformDeprecatedGetTransformStats) WithHuman() func(*DataFrameTransformDeprecatedGetTransformStatsRequest) { + return func(r *DataFrameTransformDeprecatedGetTransformStatsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f DataFrameTransformDeprecatedGetTransformStats) WithErrorTrace() func(*DataFrameTransformDeprecatedGetTransformStatsRequest) { + return func(r *DataFrameTransformDeprecatedGetTransformStatsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f DataFrameTransformDeprecatedGetTransformStats) WithFilterPath(v ...string) func(*DataFrameTransformDeprecatedGetTransformStatsRequest) { + return func(r *DataFrameTransformDeprecatedGetTransformStatsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f DataFrameTransformDeprecatedGetTransformStats) WithHeader(h map[string]string) func(*DataFrameTransformDeprecatedGetTransformStatsRequest) { + return func(r *DataFrameTransformDeprecatedGetTransformStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f DataFrameTransformDeprecatedGetTransformStats) WithOpaqueID(s string) func(*DataFrameTransformDeprecatedGetTransformStatsRequest) { + return func(r *DataFrameTransformDeprecatedGetTransformStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.preview_transform.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.preview_transform.go new file mode 100644 index 00000000000..d0251a96b3b --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.preview_transform.go @@ -0,0 +1,190 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newDataFrameTransformDeprecatedPreviewTransformFunc(t Transport) DataFrameTransformDeprecatedPreviewTransform { + return func(body io.Reader, o ...func(*DataFrameTransformDeprecatedPreviewTransformRequest)) (*Response, error) { + var r = DataFrameTransformDeprecatedPreviewTransformRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// DataFrameTransformDeprecatedPreviewTransform - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/preview-transform.html. +// +type DataFrameTransformDeprecatedPreviewTransform func(body io.Reader, o ...func(*DataFrameTransformDeprecatedPreviewTransformRequest)) (*Response, error) + +// DataFrameTransformDeprecatedPreviewTransformRequest configures the Data Frame Transform Deprecated Preview Transform API request. +// +type DataFrameTransformDeprecatedPreviewTransformRequest struct { + Body io.Reader + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r DataFrameTransformDeprecatedPreviewTransformRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(len("/_data_frame/transforms/_preview")) + path.WriteString("/_data_frame/transforms/_preview") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f DataFrameTransformDeprecatedPreviewTransform) WithContext(v context.Context) func(*DataFrameTransformDeprecatedPreviewTransformRequest) { + return func(r *DataFrameTransformDeprecatedPreviewTransformRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f DataFrameTransformDeprecatedPreviewTransform) WithPretty() func(*DataFrameTransformDeprecatedPreviewTransformRequest) { + return func(r *DataFrameTransformDeprecatedPreviewTransformRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f DataFrameTransformDeprecatedPreviewTransform) WithHuman() func(*DataFrameTransformDeprecatedPreviewTransformRequest) { + return func(r *DataFrameTransformDeprecatedPreviewTransformRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f DataFrameTransformDeprecatedPreviewTransform) WithErrorTrace() func(*DataFrameTransformDeprecatedPreviewTransformRequest) { + return func(r *DataFrameTransformDeprecatedPreviewTransformRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f DataFrameTransformDeprecatedPreviewTransform) WithFilterPath(v ...string) func(*DataFrameTransformDeprecatedPreviewTransformRequest) { + return func(r *DataFrameTransformDeprecatedPreviewTransformRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f DataFrameTransformDeprecatedPreviewTransform) WithHeader(h map[string]string) func(*DataFrameTransformDeprecatedPreviewTransformRequest) { + return func(r *DataFrameTransformDeprecatedPreviewTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f DataFrameTransformDeprecatedPreviewTransform) WithOpaqueID(s string) func(*DataFrameTransformDeprecatedPreviewTransformRequest) { + return func(r *DataFrameTransformDeprecatedPreviewTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.put_transform.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.put_transform.go new file mode 100644 index 00000000000..4dff90102ea --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.put_transform.go @@ -0,0 +1,212 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newDataFrameTransformDeprecatedPutTransformFunc(t Transport) DataFrameTransformDeprecatedPutTransform { + return func(body io.Reader, transform_id string, o ...func(*DataFrameTransformDeprecatedPutTransformRequest)) (*Response, error) { + var r = DataFrameTransformDeprecatedPutTransformRequest{Body: body, TransformID: transform_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// DataFrameTransformDeprecatedPutTransform - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/put-transform.html. +// +type DataFrameTransformDeprecatedPutTransform func(body io.Reader, transform_id string, o ...func(*DataFrameTransformDeprecatedPutTransformRequest)) (*Response, error) + +// DataFrameTransformDeprecatedPutTransformRequest configures the Data Frame Transform Deprecated Put Transform API request. +// +type DataFrameTransformDeprecatedPutTransformRequest struct { + Body io.Reader + + TransformID string + + DeferValidation *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r DataFrameTransformDeprecatedPutTransformRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_data_frame") + 1 + len("transforms") + 1 + len(r.TransformID)) + path.WriteString("/") + path.WriteString("_data_frame") + path.WriteString("/") + path.WriteString("transforms") + path.WriteString("/") + path.WriteString(r.TransformID) + + params = make(map[string]string) + + if r.DeferValidation != nil { + params["defer_validation"] = strconv.FormatBool(*r.DeferValidation) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f DataFrameTransformDeprecatedPutTransform) WithContext(v context.Context) func(*DataFrameTransformDeprecatedPutTransformRequest) { + return func(r *DataFrameTransformDeprecatedPutTransformRequest) { + r.ctx = v + } +} + +// WithDeferValidation - if validations should be deferred until transform starts, defaults to false.. +// +func (f DataFrameTransformDeprecatedPutTransform) WithDeferValidation(v bool) func(*DataFrameTransformDeprecatedPutTransformRequest) { + return func(r *DataFrameTransformDeprecatedPutTransformRequest) { + r.DeferValidation = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f DataFrameTransformDeprecatedPutTransform) WithPretty() func(*DataFrameTransformDeprecatedPutTransformRequest) { + return func(r *DataFrameTransformDeprecatedPutTransformRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f DataFrameTransformDeprecatedPutTransform) WithHuman() func(*DataFrameTransformDeprecatedPutTransformRequest) { + return func(r *DataFrameTransformDeprecatedPutTransformRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f DataFrameTransformDeprecatedPutTransform) WithErrorTrace() func(*DataFrameTransformDeprecatedPutTransformRequest) { + return func(r *DataFrameTransformDeprecatedPutTransformRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f DataFrameTransformDeprecatedPutTransform) WithFilterPath(v ...string) func(*DataFrameTransformDeprecatedPutTransformRequest) { + return func(r *DataFrameTransformDeprecatedPutTransformRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f DataFrameTransformDeprecatedPutTransform) WithHeader(h map[string]string) func(*DataFrameTransformDeprecatedPutTransformRequest) { + return func(r *DataFrameTransformDeprecatedPutTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f DataFrameTransformDeprecatedPutTransform) WithOpaqueID(s string) func(*DataFrameTransformDeprecatedPutTransformRequest) { + return func(r *DataFrameTransformDeprecatedPutTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.start_transform.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.start_transform.go new file mode 100644 index 00000000000..6bc226101ea --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.start_transform.go @@ -0,0 +1,207 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" + "time" +) + +func newDataFrameTransformDeprecatedStartTransformFunc(t Transport) DataFrameTransformDeprecatedStartTransform { + return func(transform_id string, o ...func(*DataFrameTransformDeprecatedStartTransformRequest)) (*Response, error) { + var r = DataFrameTransformDeprecatedStartTransformRequest{TransformID: transform_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// DataFrameTransformDeprecatedStartTransform - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/start-transform.html. +// +type DataFrameTransformDeprecatedStartTransform func(transform_id string, o ...func(*DataFrameTransformDeprecatedStartTransformRequest)) (*Response, error) + +// DataFrameTransformDeprecatedStartTransformRequest configures the Data Frame Transform Deprecated Start Transform API request. +// +type DataFrameTransformDeprecatedStartTransformRequest struct { + TransformID string + + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r DataFrameTransformDeprecatedStartTransformRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_data_frame") + 1 + len("transforms") + 1 + len(r.TransformID) + 1 + len("_start")) + path.WriteString("/") + path.WriteString("_data_frame") + path.WriteString("/") + path.WriteString("transforms") + path.WriteString("/") + path.WriteString(r.TransformID) + path.WriteString("/") + path.WriteString("_start") + + params = make(map[string]string) + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f DataFrameTransformDeprecatedStartTransform) WithContext(v context.Context) func(*DataFrameTransformDeprecatedStartTransformRequest) { + return func(r *DataFrameTransformDeprecatedStartTransformRequest) { + r.ctx = v + } +} + +// WithTimeout - controls the time to wait for the transform to start. +// +func (f DataFrameTransformDeprecatedStartTransform) WithTimeout(v time.Duration) func(*DataFrameTransformDeprecatedStartTransformRequest) { + return func(r *DataFrameTransformDeprecatedStartTransformRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f DataFrameTransformDeprecatedStartTransform) WithPretty() func(*DataFrameTransformDeprecatedStartTransformRequest) { + return func(r *DataFrameTransformDeprecatedStartTransformRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f DataFrameTransformDeprecatedStartTransform) WithHuman() func(*DataFrameTransformDeprecatedStartTransformRequest) { + return func(r *DataFrameTransformDeprecatedStartTransformRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f DataFrameTransformDeprecatedStartTransform) WithErrorTrace() func(*DataFrameTransformDeprecatedStartTransformRequest) { + return func(r *DataFrameTransformDeprecatedStartTransformRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f DataFrameTransformDeprecatedStartTransform) WithFilterPath(v ...string) func(*DataFrameTransformDeprecatedStartTransformRequest) { + return func(r *DataFrameTransformDeprecatedStartTransformRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f DataFrameTransformDeprecatedStartTransform) WithHeader(h map[string]string) func(*DataFrameTransformDeprecatedStartTransformRequest) { + return func(r *DataFrameTransformDeprecatedStartTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f DataFrameTransformDeprecatedStartTransform) WithOpaqueID(s string) func(*DataFrameTransformDeprecatedStartTransformRequest) { + return func(r *DataFrameTransformDeprecatedStartTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.stop_transform.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.stop_transform.go new file mode 100644 index 00000000000..e0494cbd5aa --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.stop_transform.go @@ -0,0 +1,234 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newDataFrameTransformDeprecatedStopTransformFunc(t Transport) DataFrameTransformDeprecatedStopTransform { + return func(transform_id string, o ...func(*DataFrameTransformDeprecatedStopTransformRequest)) (*Response, error) { + var r = DataFrameTransformDeprecatedStopTransformRequest{TransformID: transform_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// DataFrameTransformDeprecatedStopTransform - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/stop-transform.html. +// +type DataFrameTransformDeprecatedStopTransform func(transform_id string, o ...func(*DataFrameTransformDeprecatedStopTransformRequest)) (*Response, error) + +// DataFrameTransformDeprecatedStopTransformRequest configures the Data Frame Transform Deprecated Stop Transform API request. +// +type DataFrameTransformDeprecatedStopTransformRequest struct { + TransformID string + + AllowNoMatch *bool + Timeout time.Duration + WaitForCompletion *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r DataFrameTransformDeprecatedStopTransformRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_data_frame") + 1 + len("transforms") + 1 + len(r.TransformID) + 1 + len("_stop")) + path.WriteString("/") + path.WriteString("_data_frame") + path.WriteString("/") + path.WriteString("transforms") + path.WriteString("/") + path.WriteString(r.TransformID) + path.WriteString("/") + path.WriteString("_stop") + + params = make(map[string]string) + + if r.AllowNoMatch != nil { + params["allow_no_match"] = strconv.FormatBool(*r.AllowNoMatch) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.WaitForCompletion != nil { + params["wait_for_completion"] = strconv.FormatBool(*r.WaitForCompletion) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f DataFrameTransformDeprecatedStopTransform) WithContext(v context.Context) func(*DataFrameTransformDeprecatedStopTransformRequest) { + return func(r *DataFrameTransformDeprecatedStopTransformRequest) { + r.ctx = v + } +} + +// WithAllowNoMatch - whether to ignore if a wildcard expression matches no transforms. (this includes `_all` string or when no transforms have been specified). +// +func (f DataFrameTransformDeprecatedStopTransform) WithAllowNoMatch(v bool) func(*DataFrameTransformDeprecatedStopTransformRequest) { + return func(r *DataFrameTransformDeprecatedStopTransformRequest) { + r.AllowNoMatch = &v + } +} + +// WithTimeout - controls the time to wait until the transform has stopped. default to 30 seconds. +// +func (f DataFrameTransformDeprecatedStopTransform) WithTimeout(v time.Duration) func(*DataFrameTransformDeprecatedStopTransformRequest) { + return func(r *DataFrameTransformDeprecatedStopTransformRequest) { + r.Timeout = v + } +} + +// WithWaitForCompletion - whether to wait for the transform to fully stop before returning or not. default to false. +// +func (f DataFrameTransformDeprecatedStopTransform) WithWaitForCompletion(v bool) func(*DataFrameTransformDeprecatedStopTransformRequest) { + return func(r *DataFrameTransformDeprecatedStopTransformRequest) { + r.WaitForCompletion = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f DataFrameTransformDeprecatedStopTransform) WithPretty() func(*DataFrameTransformDeprecatedStopTransformRequest) { + return func(r *DataFrameTransformDeprecatedStopTransformRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f DataFrameTransformDeprecatedStopTransform) WithHuman() func(*DataFrameTransformDeprecatedStopTransformRequest) { + return func(r *DataFrameTransformDeprecatedStopTransformRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f DataFrameTransformDeprecatedStopTransform) WithErrorTrace() func(*DataFrameTransformDeprecatedStopTransformRequest) { + return func(r *DataFrameTransformDeprecatedStopTransformRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f DataFrameTransformDeprecatedStopTransform) WithFilterPath(v ...string) func(*DataFrameTransformDeprecatedStopTransformRequest) { + return func(r *DataFrameTransformDeprecatedStopTransformRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f DataFrameTransformDeprecatedStopTransform) WithHeader(h map[string]string) func(*DataFrameTransformDeprecatedStopTransformRequest) { + return func(r *DataFrameTransformDeprecatedStopTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f DataFrameTransformDeprecatedStopTransform) WithOpaqueID(s string) func(*DataFrameTransformDeprecatedStopTransformRequest) { + return func(r *DataFrameTransformDeprecatedStopTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.update_transform.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.update_transform.go new file mode 100644 index 00000000000..6bb66eb7c53 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.data_frame_transform_deprecated.update_transform.go @@ -0,0 +1,214 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newDataFrameTransformDeprecatedUpdateTransformFunc(t Transport) DataFrameTransformDeprecatedUpdateTransform { + return func(body io.Reader, transform_id string, o ...func(*DataFrameTransformDeprecatedUpdateTransformRequest)) (*Response, error) { + var r = DataFrameTransformDeprecatedUpdateTransformRequest{Body: body, TransformID: transform_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// DataFrameTransformDeprecatedUpdateTransform - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/update-transform.html. +// +type DataFrameTransformDeprecatedUpdateTransform func(body io.Reader, transform_id string, o ...func(*DataFrameTransformDeprecatedUpdateTransformRequest)) (*Response, error) + +// DataFrameTransformDeprecatedUpdateTransformRequest configures the Data Frame Transform Deprecated Update Transform API request. +// +type DataFrameTransformDeprecatedUpdateTransformRequest struct { + Body io.Reader + + TransformID string + + DeferValidation *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r DataFrameTransformDeprecatedUpdateTransformRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_data_frame") + 1 + len("transforms") + 1 + len(r.TransformID) + 1 + len("_update")) + path.WriteString("/") + path.WriteString("_data_frame") + path.WriteString("/") + path.WriteString("transforms") + path.WriteString("/") + path.WriteString(r.TransformID) + path.WriteString("/") + path.WriteString("_update") + + params = make(map[string]string) + + if r.DeferValidation != nil { + params["defer_validation"] = strconv.FormatBool(*r.DeferValidation) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f DataFrameTransformDeprecatedUpdateTransform) WithContext(v context.Context) func(*DataFrameTransformDeprecatedUpdateTransformRequest) { + return func(r *DataFrameTransformDeprecatedUpdateTransformRequest) { + r.ctx = v + } +} + +// WithDeferValidation - if validations should be deferred until transform starts, defaults to false.. +// +func (f DataFrameTransformDeprecatedUpdateTransform) WithDeferValidation(v bool) func(*DataFrameTransformDeprecatedUpdateTransformRequest) { + return func(r *DataFrameTransformDeprecatedUpdateTransformRequest) { + r.DeferValidation = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f DataFrameTransformDeprecatedUpdateTransform) WithPretty() func(*DataFrameTransformDeprecatedUpdateTransformRequest) { + return func(r *DataFrameTransformDeprecatedUpdateTransformRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f DataFrameTransformDeprecatedUpdateTransform) WithHuman() func(*DataFrameTransformDeprecatedUpdateTransformRequest) { + return func(r *DataFrameTransformDeprecatedUpdateTransformRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f DataFrameTransformDeprecatedUpdateTransform) WithErrorTrace() func(*DataFrameTransformDeprecatedUpdateTransformRequest) { + return func(r *DataFrameTransformDeprecatedUpdateTransformRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f DataFrameTransformDeprecatedUpdateTransform) WithFilterPath(v ...string) func(*DataFrameTransformDeprecatedUpdateTransformRequest) { + return func(r *DataFrameTransformDeprecatedUpdateTransformRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f DataFrameTransformDeprecatedUpdateTransform) WithHeader(h map[string]string) func(*DataFrameTransformDeprecatedUpdateTransformRequest) { + return func(r *DataFrameTransformDeprecatedUpdateTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f DataFrameTransformDeprecatedUpdateTransform) WithOpaqueID(s string) func(*DataFrameTransformDeprecatedUpdateTransformRequest) { + return func(r *DataFrameTransformDeprecatedUpdateTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.enrich.delete_policy.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.enrich.delete_policy.go new file mode 100644 index 00000000000..bd63f0e625c --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.enrich.delete_policy.go @@ -0,0 +1,190 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newEnrichDeletePolicyFunc(t Transport) EnrichDeletePolicy { + return func(name string, o ...func(*EnrichDeletePolicyRequest)) (*Response, error) { + var r = EnrichDeletePolicyRequest{Name: name} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// EnrichDeletePolicy - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/enrich-delete-policy.html. +// +type EnrichDeletePolicy func(name string, o ...func(*EnrichDeletePolicyRequest)) (*Response, error) + +// EnrichDeletePolicyRequest configures the Enrich Delete Policy API request. +// +type EnrichDeletePolicyRequest struct { + Name string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r EnrichDeletePolicyRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_enrich") + 1 + len("policy") + 1 + len(r.Name)) + path.WriteString("/") + path.WriteString("_enrich") + path.WriteString("/") + path.WriteString("policy") + path.WriteString("/") + path.WriteString(r.Name) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f EnrichDeletePolicy) WithContext(v context.Context) func(*EnrichDeletePolicyRequest) { + return func(r *EnrichDeletePolicyRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f EnrichDeletePolicy) WithPretty() func(*EnrichDeletePolicyRequest) { + return func(r *EnrichDeletePolicyRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f EnrichDeletePolicy) WithHuman() func(*EnrichDeletePolicyRequest) { + return func(r *EnrichDeletePolicyRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f EnrichDeletePolicy) WithErrorTrace() func(*EnrichDeletePolicyRequest) { + return func(r *EnrichDeletePolicyRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f EnrichDeletePolicy) WithFilterPath(v ...string) func(*EnrichDeletePolicyRequest) { + return func(r *EnrichDeletePolicyRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f EnrichDeletePolicy) WithHeader(h map[string]string) func(*EnrichDeletePolicyRequest) { + return func(r *EnrichDeletePolicyRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f EnrichDeletePolicy) WithOpaqueID(s string) func(*EnrichDeletePolicyRequest) { + return func(r *EnrichDeletePolicyRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.enrich.execute_policy.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.enrich.execute_policy.go new file mode 100644 index 00000000000..3dd048c2198 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.enrich.execute_policy.go @@ -0,0 +1,207 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newEnrichExecutePolicyFunc(t Transport) EnrichExecutePolicy { + return func(name string, o ...func(*EnrichExecutePolicyRequest)) (*Response, error) { + var r = EnrichExecutePolicyRequest{Name: name} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// EnrichExecutePolicy - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/enrich-execute-policy.html. +// +type EnrichExecutePolicy func(name string, o ...func(*EnrichExecutePolicyRequest)) (*Response, error) + +// EnrichExecutePolicyRequest configures the Enrich Execute Policy API request. +// +type EnrichExecutePolicyRequest struct { + Name string + + WaitForCompletion *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r EnrichExecutePolicyRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_enrich") + 1 + len("policy") + 1 + len(r.Name) + 1 + len("_execute")) + path.WriteString("/") + path.WriteString("_enrich") + path.WriteString("/") + path.WriteString("policy") + path.WriteString("/") + path.WriteString(r.Name) + path.WriteString("/") + path.WriteString("_execute") + + params = make(map[string]string) + + if r.WaitForCompletion != nil { + params["wait_for_completion"] = strconv.FormatBool(*r.WaitForCompletion) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f EnrichExecutePolicy) WithContext(v context.Context) func(*EnrichExecutePolicyRequest) { + return func(r *EnrichExecutePolicyRequest) { + r.ctx = v + } +} + +// WithWaitForCompletion - should the request should block until the execution is complete.. +// +func (f EnrichExecutePolicy) WithWaitForCompletion(v bool) func(*EnrichExecutePolicyRequest) { + return func(r *EnrichExecutePolicyRequest) { + r.WaitForCompletion = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f EnrichExecutePolicy) WithPretty() func(*EnrichExecutePolicyRequest) { + return func(r *EnrichExecutePolicyRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f EnrichExecutePolicy) WithHuman() func(*EnrichExecutePolicyRequest) { + return func(r *EnrichExecutePolicyRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f EnrichExecutePolicy) WithErrorTrace() func(*EnrichExecutePolicyRequest) { + return func(r *EnrichExecutePolicyRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f EnrichExecutePolicy) WithFilterPath(v ...string) func(*EnrichExecutePolicyRequest) { + return func(r *EnrichExecutePolicyRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f EnrichExecutePolicy) WithHeader(h map[string]string) func(*EnrichExecutePolicyRequest) { + return func(r *EnrichExecutePolicyRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f EnrichExecutePolicy) WithOpaqueID(s string) func(*EnrichExecutePolicyRequest) { + return func(r *EnrichExecutePolicyRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.enrich.get_policy.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.enrich.get_policy.go new file mode 100644 index 00000000000..e0b7b4db6ee --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.enrich.get_policy.go @@ -0,0 +1,200 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newEnrichGetPolicyFunc(t Transport) EnrichGetPolicy { + return func(o ...func(*EnrichGetPolicyRequest)) (*Response, error) { + var r = EnrichGetPolicyRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// EnrichGetPolicy - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/enrich-get-policy.html. +// +type EnrichGetPolicy func(o ...func(*EnrichGetPolicyRequest)) (*Response, error) + +// EnrichGetPolicyRequest configures the Enrich Get Policy API request. +// +type EnrichGetPolicyRequest struct { + Name string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r EnrichGetPolicyRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_enrich") + 1 + len("policy") + 1 + len(r.Name)) + path.WriteString("/") + path.WriteString("_enrich") + path.WriteString("/") + path.WriteString("policy") + if r.Name != "" { + path.WriteString("/") + path.WriteString(r.Name) + } + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f EnrichGetPolicy) WithContext(v context.Context) func(*EnrichGetPolicyRequest) { + return func(r *EnrichGetPolicyRequest) { + r.ctx = v + } +} + +// WithName - the name of the enrich policy. +// +func (f EnrichGetPolicy) WithName(v string) func(*EnrichGetPolicyRequest) { + return func(r *EnrichGetPolicyRequest) { + r.Name = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f EnrichGetPolicy) WithPretty() func(*EnrichGetPolicyRequest) { + return func(r *EnrichGetPolicyRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f EnrichGetPolicy) WithHuman() func(*EnrichGetPolicyRequest) { + return func(r *EnrichGetPolicyRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f EnrichGetPolicy) WithErrorTrace() func(*EnrichGetPolicyRequest) { + return func(r *EnrichGetPolicyRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f EnrichGetPolicy) WithFilterPath(v ...string) func(*EnrichGetPolicyRequest) { + return func(r *EnrichGetPolicyRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f EnrichGetPolicy) WithHeader(h map[string]string) func(*EnrichGetPolicyRequest) { + return func(r *EnrichGetPolicyRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f EnrichGetPolicy) WithOpaqueID(s string) func(*EnrichGetPolicyRequest) { + return func(r *EnrichGetPolicyRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.enrich.put_policy.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.enrich.put_policy.go new file mode 100644 index 00000000000..fbb7a595dbd --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.enrich.put_policy.go @@ -0,0 +1,197 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newEnrichPutPolicyFunc(t Transport) EnrichPutPolicy { + return func(name string, body io.Reader, o ...func(*EnrichPutPolicyRequest)) (*Response, error) { + var r = EnrichPutPolicyRequest{Name: name, Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// EnrichPutPolicy - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/enrich-put-policy.html. +// +type EnrichPutPolicy func(name string, body io.Reader, o ...func(*EnrichPutPolicyRequest)) (*Response, error) + +// EnrichPutPolicyRequest configures the Enrich Put Policy API request. +// +type EnrichPutPolicyRequest struct { + Body io.Reader + + Name string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r EnrichPutPolicyRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_enrich") + 1 + len("policy") + 1 + len(r.Name)) + path.WriteString("/") + path.WriteString("_enrich") + path.WriteString("/") + path.WriteString("policy") + path.WriteString("/") + path.WriteString(r.Name) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f EnrichPutPolicy) WithContext(v context.Context) func(*EnrichPutPolicyRequest) { + return func(r *EnrichPutPolicyRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f EnrichPutPolicy) WithPretty() func(*EnrichPutPolicyRequest) { + return func(r *EnrichPutPolicyRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f EnrichPutPolicy) WithHuman() func(*EnrichPutPolicyRequest) { + return func(r *EnrichPutPolicyRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f EnrichPutPolicy) WithErrorTrace() func(*EnrichPutPolicyRequest) { + return func(r *EnrichPutPolicyRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f EnrichPutPolicy) WithFilterPath(v ...string) func(*EnrichPutPolicyRequest) { + return func(r *EnrichPutPolicyRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f EnrichPutPolicy) WithHeader(h map[string]string) func(*EnrichPutPolicyRequest) { + return func(r *EnrichPutPolicyRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f EnrichPutPolicy) WithOpaqueID(s string) func(*EnrichPutPolicyRequest) { + return func(r *EnrichPutPolicyRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.enrich.stats.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.enrich.stats.go new file mode 100644 index 00000000000..af1bc267957 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.enrich.stats.go @@ -0,0 +1,183 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newEnrichStatsFunc(t Transport) EnrichStats { + return func(o ...func(*EnrichStatsRequest)) (*Response, error) { + var r = EnrichStatsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// EnrichStats - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/enrich-stats.html. +// +type EnrichStats func(o ...func(*EnrichStatsRequest)) (*Response, error) + +// EnrichStatsRequest configures the Enrich Stats API request. +// +type EnrichStatsRequest struct { + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r EnrichStatsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_enrich/_stats")) + path.WriteString("/_enrich/_stats") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f EnrichStats) WithContext(v context.Context) func(*EnrichStatsRequest) { + return func(r *EnrichStatsRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f EnrichStats) WithPretty() func(*EnrichStatsRequest) { + return func(r *EnrichStatsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f EnrichStats) WithHuman() func(*EnrichStatsRequest) { + return func(r *EnrichStatsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f EnrichStats) WithErrorTrace() func(*EnrichStatsRequest) { + return func(r *EnrichStatsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f EnrichStats) WithFilterPath(v ...string) func(*EnrichStatsRequest) { + return func(r *EnrichStatsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f EnrichStats) WithHeader(h map[string]string) func(*EnrichStatsRequest) { + return func(r *EnrichStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f EnrichStats) WithOpaqueID(s string) func(*EnrichStatsRequest) { + return func(r *EnrichStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.graph.explore.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.graph.explore.go new file mode 100644 index 00000000000..fc9d18a86b1 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.graph.explore.go @@ -0,0 +1,233 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" + "time" +) + +func newGraphExploreFunc(t Transport) GraphExplore { + return func(index []string, o ...func(*GraphExploreRequest)) (*Response, error) { + var r = GraphExploreRequest{Index: index} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// GraphExplore - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/graph-explore-api.html. +// +type GraphExplore func(index []string, o ...func(*GraphExploreRequest)) (*Response, error) + +// GraphExploreRequest configures the Graph Explore API request. +// +type GraphExploreRequest struct { + Index []string + + Body io.Reader + + Routing string + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r GraphExploreRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_graph") + 1 + len("explore")) + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + path.WriteString("/") + path.WriteString("_graph") + path.WriteString("/") + path.WriteString("explore") + + params = make(map[string]string) + + if r.Routing != "" { + params["routing"] = r.Routing + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f GraphExplore) WithContext(v context.Context) func(*GraphExploreRequest) { + return func(r *GraphExploreRequest) { + r.ctx = v + } +} + +// WithBody - Graph Query DSL. +// +func (f GraphExplore) WithBody(v io.Reader) func(*GraphExploreRequest) { + return func(r *GraphExploreRequest) { + r.Body = v + } +} + +// WithRouting - specific routing value. +// +func (f GraphExplore) WithRouting(v string) func(*GraphExploreRequest) { + return func(r *GraphExploreRequest) { + r.Routing = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f GraphExplore) WithTimeout(v time.Duration) func(*GraphExploreRequest) { + return func(r *GraphExploreRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f GraphExplore) WithPretty() func(*GraphExploreRequest) { + return func(r *GraphExploreRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f GraphExplore) WithHuman() func(*GraphExploreRequest) { + return func(r *GraphExploreRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f GraphExplore) WithErrorTrace() func(*GraphExploreRequest) { + return func(r *GraphExploreRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f GraphExplore) WithFilterPath(v ...string) func(*GraphExploreRequest) { + return func(r *GraphExploreRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f GraphExplore) WithHeader(h map[string]string) func(*GraphExploreRequest) { + return func(r *GraphExploreRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f GraphExplore) WithOpaqueID(s string) func(*GraphExploreRequest) { + return func(r *GraphExploreRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.delete_lifecycle.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.delete_lifecycle.go new file mode 100644 index 00000000000..21cb3f3281c --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.delete_lifecycle.go @@ -0,0 +1,190 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newILMDeleteLifecycleFunc(t Transport) ILMDeleteLifecycle { + return func(policy string, o ...func(*ILMDeleteLifecycleRequest)) (*Response, error) { + var r = ILMDeleteLifecycleRequest{Policy: policy} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// ILMDeleteLifecycle - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-delete-lifecycle.html. +// +type ILMDeleteLifecycle func(policy string, o ...func(*ILMDeleteLifecycleRequest)) (*Response, error) + +// ILMDeleteLifecycleRequest configures the ILM Delete Lifecycle API request. +// +type ILMDeleteLifecycleRequest struct { + Policy string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ILMDeleteLifecycleRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_ilm") + 1 + len("policy") + 1 + len(r.Policy)) + path.WriteString("/") + path.WriteString("_ilm") + path.WriteString("/") + path.WriteString("policy") + path.WriteString("/") + path.WriteString(r.Policy) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f ILMDeleteLifecycle) WithContext(v context.Context) func(*ILMDeleteLifecycleRequest) { + return func(r *ILMDeleteLifecycleRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f ILMDeleteLifecycle) WithPretty() func(*ILMDeleteLifecycleRequest) { + return func(r *ILMDeleteLifecycleRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f ILMDeleteLifecycle) WithHuman() func(*ILMDeleteLifecycleRequest) { + return func(r *ILMDeleteLifecycleRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ILMDeleteLifecycle) WithErrorTrace() func(*ILMDeleteLifecycleRequest) { + return func(r *ILMDeleteLifecycleRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f ILMDeleteLifecycle) WithFilterPath(v ...string) func(*ILMDeleteLifecycleRequest) { + return func(r *ILMDeleteLifecycleRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f ILMDeleteLifecycle) WithHeader(h map[string]string) func(*ILMDeleteLifecycleRequest) { + return func(r *ILMDeleteLifecycleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f ILMDeleteLifecycle) WithOpaqueID(s string) func(*ILMDeleteLifecycleRequest) { + return func(r *ILMDeleteLifecycleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.explain_lifecycle.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.explain_lifecycle.go new file mode 100644 index 00000000000..a05e188efd3 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.explain_lifecycle.go @@ -0,0 +1,218 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newILMExplainLifecycleFunc(t Transport) ILMExplainLifecycle { + return func(index string, o ...func(*ILMExplainLifecycleRequest)) (*Response, error) { + var r = ILMExplainLifecycleRequest{Index: index} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// ILMExplainLifecycle - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-explain-lifecycle.html. +// +type ILMExplainLifecycle func(index string, o ...func(*ILMExplainLifecycleRequest)) (*Response, error) + +// ILMExplainLifecycleRequest configures the ILM Explain Lifecycle API request. +// +type ILMExplainLifecycleRequest struct { + Index string + + OnlyErrors *bool + OnlyManaged *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ILMExplainLifecycleRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(r.Index) + 1 + len("_ilm") + 1 + len("explain")) + path.WriteString("/") + path.WriteString(r.Index) + path.WriteString("/") + path.WriteString("_ilm") + path.WriteString("/") + path.WriteString("explain") + + params = make(map[string]string) + + if r.OnlyErrors != nil { + params["only_errors"] = strconv.FormatBool(*r.OnlyErrors) + } + + if r.OnlyManaged != nil { + params["only_managed"] = strconv.FormatBool(*r.OnlyManaged) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f ILMExplainLifecycle) WithContext(v context.Context) func(*ILMExplainLifecycleRequest) { + return func(r *ILMExplainLifecycleRequest) { + r.ctx = v + } +} + +// WithOnlyErrors - filters the indices included in the response to ones in an ilm error state, implies only_managed. +// +func (f ILMExplainLifecycle) WithOnlyErrors(v bool) func(*ILMExplainLifecycleRequest) { + return func(r *ILMExplainLifecycleRequest) { + r.OnlyErrors = &v + } +} + +// WithOnlyManaged - filters the indices included in the response to ones managed by ilm. +// +func (f ILMExplainLifecycle) WithOnlyManaged(v bool) func(*ILMExplainLifecycleRequest) { + return func(r *ILMExplainLifecycleRequest) { + r.OnlyManaged = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f ILMExplainLifecycle) WithPretty() func(*ILMExplainLifecycleRequest) { + return func(r *ILMExplainLifecycleRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f ILMExplainLifecycle) WithHuman() func(*ILMExplainLifecycleRequest) { + return func(r *ILMExplainLifecycleRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ILMExplainLifecycle) WithErrorTrace() func(*ILMExplainLifecycleRequest) { + return func(r *ILMExplainLifecycleRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f ILMExplainLifecycle) WithFilterPath(v ...string) func(*ILMExplainLifecycleRequest) { + return func(r *ILMExplainLifecycleRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f ILMExplainLifecycle) WithHeader(h map[string]string) func(*ILMExplainLifecycleRequest) { + return func(r *ILMExplainLifecycleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f ILMExplainLifecycle) WithOpaqueID(s string) func(*ILMExplainLifecycleRequest) { + return func(r *ILMExplainLifecycleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.get_lifecycle.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.get_lifecycle.go new file mode 100644 index 00000000000..174abb510e5 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.get_lifecycle.go @@ -0,0 +1,200 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newILMGetLifecycleFunc(t Transport) ILMGetLifecycle { + return func(o ...func(*ILMGetLifecycleRequest)) (*Response, error) { + var r = ILMGetLifecycleRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// ILMGetLifecycle - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-get-lifecycle.html. +// +type ILMGetLifecycle func(o ...func(*ILMGetLifecycleRequest)) (*Response, error) + +// ILMGetLifecycleRequest configures the ILM Get Lifecycle API request. +// +type ILMGetLifecycleRequest struct { + Policy string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ILMGetLifecycleRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_ilm") + 1 + len("policy") + 1 + len(r.Policy)) + path.WriteString("/") + path.WriteString("_ilm") + path.WriteString("/") + path.WriteString("policy") + if r.Policy != "" { + path.WriteString("/") + path.WriteString(r.Policy) + } + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f ILMGetLifecycle) WithContext(v context.Context) func(*ILMGetLifecycleRequest) { + return func(r *ILMGetLifecycleRequest) { + r.ctx = v + } +} + +// WithPolicy - the name of the index lifecycle policy. +// +func (f ILMGetLifecycle) WithPolicy(v string) func(*ILMGetLifecycleRequest) { + return func(r *ILMGetLifecycleRequest) { + r.Policy = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f ILMGetLifecycle) WithPretty() func(*ILMGetLifecycleRequest) { + return func(r *ILMGetLifecycleRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f ILMGetLifecycle) WithHuman() func(*ILMGetLifecycleRequest) { + return func(r *ILMGetLifecycleRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ILMGetLifecycle) WithErrorTrace() func(*ILMGetLifecycleRequest) { + return func(r *ILMGetLifecycleRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f ILMGetLifecycle) WithFilterPath(v ...string) func(*ILMGetLifecycleRequest) { + return func(r *ILMGetLifecycleRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f ILMGetLifecycle) WithHeader(h map[string]string) func(*ILMGetLifecycleRequest) { + return func(r *ILMGetLifecycleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f ILMGetLifecycle) WithOpaqueID(s string) func(*ILMGetLifecycleRequest) { + return func(r *ILMGetLifecycleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.get_status.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.get_status.go new file mode 100644 index 00000000000..f7a4dd1cbb4 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.get_status.go @@ -0,0 +1,183 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newILMGetStatusFunc(t Transport) ILMGetStatus { + return func(o ...func(*ILMGetStatusRequest)) (*Response, error) { + var r = ILMGetStatusRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// ILMGetStatus - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-get-status.html. +// +type ILMGetStatus func(o ...func(*ILMGetStatusRequest)) (*Response, error) + +// ILMGetStatusRequest configures the ILM Get Status API request. +// +type ILMGetStatusRequest struct { + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ILMGetStatusRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_ilm/status")) + path.WriteString("/_ilm/status") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f ILMGetStatus) WithContext(v context.Context) func(*ILMGetStatusRequest) { + return func(r *ILMGetStatusRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f ILMGetStatus) WithPretty() func(*ILMGetStatusRequest) { + return func(r *ILMGetStatusRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f ILMGetStatus) WithHuman() func(*ILMGetStatusRequest) { + return func(r *ILMGetStatusRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ILMGetStatus) WithErrorTrace() func(*ILMGetStatusRequest) { + return func(r *ILMGetStatusRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f ILMGetStatus) WithFilterPath(v ...string) func(*ILMGetStatusRequest) { + return func(r *ILMGetStatusRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f ILMGetStatus) WithHeader(h map[string]string) func(*ILMGetStatusRequest) { + return func(r *ILMGetStatusRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f ILMGetStatus) WithOpaqueID(s string) func(*ILMGetStatusRequest) { + return func(r *ILMGetStatusRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.move_to_step.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.move_to_step.go new file mode 100644 index 00000000000..f87aee0e25c --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.move_to_step.go @@ -0,0 +1,205 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newILMMoveToStepFunc(t Transport) ILMMoveToStep { + return func(index string, o ...func(*ILMMoveToStepRequest)) (*Response, error) { + var r = ILMMoveToStepRequest{Index: index} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// ILMMoveToStep - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-move-to-step.html. +// +type ILMMoveToStep func(index string, o ...func(*ILMMoveToStepRequest)) (*Response, error) + +// ILMMoveToStepRequest configures the ILM Move To Step API request. +// +type ILMMoveToStepRequest struct { + Index string + + Body io.Reader + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ILMMoveToStepRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_ilm") + 1 + len("move") + 1 + len(r.Index)) + path.WriteString("/") + path.WriteString("_ilm") + path.WriteString("/") + path.WriteString("move") + path.WriteString("/") + path.WriteString(r.Index) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f ILMMoveToStep) WithContext(v context.Context) func(*ILMMoveToStepRequest) { + return func(r *ILMMoveToStepRequest) { + r.ctx = v + } +} + +// WithBody - The new lifecycle step to move to. +// +func (f ILMMoveToStep) WithBody(v io.Reader) func(*ILMMoveToStepRequest) { + return func(r *ILMMoveToStepRequest) { + r.Body = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f ILMMoveToStep) WithPretty() func(*ILMMoveToStepRequest) { + return func(r *ILMMoveToStepRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f ILMMoveToStep) WithHuman() func(*ILMMoveToStepRequest) { + return func(r *ILMMoveToStepRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ILMMoveToStep) WithErrorTrace() func(*ILMMoveToStepRequest) { + return func(r *ILMMoveToStepRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f ILMMoveToStep) WithFilterPath(v ...string) func(*ILMMoveToStepRequest) { + return func(r *ILMMoveToStepRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f ILMMoveToStep) WithHeader(h map[string]string) func(*ILMMoveToStepRequest) { + return func(r *ILMMoveToStepRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f ILMMoveToStep) WithOpaqueID(s string) func(*ILMMoveToStepRequest) { + return func(r *ILMMoveToStepRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.put_lifecycle.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.put_lifecycle.go new file mode 100644 index 00000000000..bef9a54e6b4 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.put_lifecycle.go @@ -0,0 +1,205 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newILMPutLifecycleFunc(t Transport) ILMPutLifecycle { + return func(policy string, o ...func(*ILMPutLifecycleRequest)) (*Response, error) { + var r = ILMPutLifecycleRequest{Policy: policy} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// ILMPutLifecycle - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-put-lifecycle.html. +// +type ILMPutLifecycle func(policy string, o ...func(*ILMPutLifecycleRequest)) (*Response, error) + +// ILMPutLifecycleRequest configures the ILM Put Lifecycle API request. +// +type ILMPutLifecycleRequest struct { + Body io.Reader + + Policy string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ILMPutLifecycleRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_ilm") + 1 + len("policy") + 1 + len(r.Policy)) + path.WriteString("/") + path.WriteString("_ilm") + path.WriteString("/") + path.WriteString("policy") + path.WriteString("/") + path.WriteString(r.Policy) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f ILMPutLifecycle) WithContext(v context.Context) func(*ILMPutLifecycleRequest) { + return func(r *ILMPutLifecycleRequest) { + r.ctx = v + } +} + +// WithBody - The lifecycle policy definition to register. +// +func (f ILMPutLifecycle) WithBody(v io.Reader) func(*ILMPutLifecycleRequest) { + return func(r *ILMPutLifecycleRequest) { + r.Body = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f ILMPutLifecycle) WithPretty() func(*ILMPutLifecycleRequest) { + return func(r *ILMPutLifecycleRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f ILMPutLifecycle) WithHuman() func(*ILMPutLifecycleRequest) { + return func(r *ILMPutLifecycleRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ILMPutLifecycle) WithErrorTrace() func(*ILMPutLifecycleRequest) { + return func(r *ILMPutLifecycleRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f ILMPutLifecycle) WithFilterPath(v ...string) func(*ILMPutLifecycleRequest) { + return func(r *ILMPutLifecycleRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f ILMPutLifecycle) WithHeader(h map[string]string) func(*ILMPutLifecycleRequest) { + return func(r *ILMPutLifecycleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f ILMPutLifecycle) WithOpaqueID(s string) func(*ILMPutLifecycleRequest) { + return func(r *ILMPutLifecycleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.remove_policy.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.remove_policy.go new file mode 100644 index 00000000000..595e6955c9f --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.remove_policy.go @@ -0,0 +1,190 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newILMRemovePolicyFunc(t Transport) ILMRemovePolicy { + return func(index string, o ...func(*ILMRemovePolicyRequest)) (*Response, error) { + var r = ILMRemovePolicyRequest{Index: index} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// ILMRemovePolicy - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-remove-policy.html. +// +type ILMRemovePolicy func(index string, o ...func(*ILMRemovePolicyRequest)) (*Response, error) + +// ILMRemovePolicyRequest configures the ILM Remove Policy API request. +// +type ILMRemovePolicyRequest struct { + Index string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ILMRemovePolicyRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len(r.Index) + 1 + len("_ilm") + 1 + len("remove")) + path.WriteString("/") + path.WriteString(r.Index) + path.WriteString("/") + path.WriteString("_ilm") + path.WriteString("/") + path.WriteString("remove") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f ILMRemovePolicy) WithContext(v context.Context) func(*ILMRemovePolicyRequest) { + return func(r *ILMRemovePolicyRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f ILMRemovePolicy) WithPretty() func(*ILMRemovePolicyRequest) { + return func(r *ILMRemovePolicyRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f ILMRemovePolicy) WithHuman() func(*ILMRemovePolicyRequest) { + return func(r *ILMRemovePolicyRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ILMRemovePolicy) WithErrorTrace() func(*ILMRemovePolicyRequest) { + return func(r *ILMRemovePolicyRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f ILMRemovePolicy) WithFilterPath(v ...string) func(*ILMRemovePolicyRequest) { + return func(r *ILMRemovePolicyRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f ILMRemovePolicy) WithHeader(h map[string]string) func(*ILMRemovePolicyRequest) { + return func(r *ILMRemovePolicyRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f ILMRemovePolicy) WithOpaqueID(s string) func(*ILMRemovePolicyRequest) { + return func(r *ILMRemovePolicyRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.retry.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.retry.go new file mode 100644 index 00000000000..e972af1616d --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.retry.go @@ -0,0 +1,190 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newILMRetryFunc(t Transport) ILMRetry { + return func(index string, o ...func(*ILMRetryRequest)) (*Response, error) { + var r = ILMRetryRequest{Index: index} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// ILMRetry - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-retry-policy.html. +// +type ILMRetry func(index string, o ...func(*ILMRetryRequest)) (*Response, error) + +// ILMRetryRequest configures the ILM Retry API request. +// +type ILMRetryRequest struct { + Index string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ILMRetryRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len(r.Index) + 1 + len("_ilm") + 1 + len("retry")) + path.WriteString("/") + path.WriteString(r.Index) + path.WriteString("/") + path.WriteString("_ilm") + path.WriteString("/") + path.WriteString("retry") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f ILMRetry) WithContext(v context.Context) func(*ILMRetryRequest) { + return func(r *ILMRetryRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f ILMRetry) WithPretty() func(*ILMRetryRequest) { + return func(r *ILMRetryRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f ILMRetry) WithHuman() func(*ILMRetryRequest) { + return func(r *ILMRetryRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ILMRetry) WithErrorTrace() func(*ILMRetryRequest) { + return func(r *ILMRetryRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f ILMRetry) WithFilterPath(v ...string) func(*ILMRetryRequest) { + return func(r *ILMRetryRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f ILMRetry) WithHeader(h map[string]string) func(*ILMRetryRequest) { + return func(r *ILMRetryRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f ILMRetry) WithOpaqueID(s string) func(*ILMRetryRequest) { + return func(r *ILMRetryRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.start.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.start.go new file mode 100644 index 00000000000..396005d511a --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.start.go @@ -0,0 +1,183 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newILMStartFunc(t Transport) ILMStart { + return func(o ...func(*ILMStartRequest)) (*Response, error) { + var r = ILMStartRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// ILMStart - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-start.html. +// +type ILMStart func(o ...func(*ILMStartRequest)) (*Response, error) + +// ILMStartRequest configures the ILM Start API request. +// +type ILMStartRequest struct { + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ILMStartRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(len("/_ilm/start")) + path.WriteString("/_ilm/start") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f ILMStart) WithContext(v context.Context) func(*ILMStartRequest) { + return func(r *ILMStartRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f ILMStart) WithPretty() func(*ILMStartRequest) { + return func(r *ILMStartRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f ILMStart) WithHuman() func(*ILMStartRequest) { + return func(r *ILMStartRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ILMStart) WithErrorTrace() func(*ILMStartRequest) { + return func(r *ILMStartRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f ILMStart) WithFilterPath(v ...string) func(*ILMStartRequest) { + return func(r *ILMStartRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f ILMStart) WithHeader(h map[string]string) func(*ILMStartRequest) { + return func(r *ILMStartRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f ILMStart) WithOpaqueID(s string) func(*ILMStartRequest) { + return func(r *ILMStartRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.stop.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.stop.go new file mode 100644 index 00000000000..d4abb9e0cc6 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ilm.stop.go @@ -0,0 +1,183 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newILMStopFunc(t Transport) ILMStop { + return func(o ...func(*ILMStopRequest)) (*Response, error) { + var r = ILMStopRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// ILMStop - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-stop.html. +// +type ILMStop func(o ...func(*ILMStopRequest)) (*Response, error) + +// ILMStopRequest configures the ILM Stop API request. +// +type ILMStopRequest struct { + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r ILMStopRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(len("/_ilm/stop")) + path.WriteString("/_ilm/stop") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f ILMStop) WithContext(v context.Context) func(*ILMStopRequest) { + return func(r *ILMStopRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f ILMStop) WithPretty() func(*ILMStopRequest) { + return func(r *ILMStopRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f ILMStop) WithHuman() func(*ILMStopRequest) { + return func(r *ILMStopRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ILMStop) WithErrorTrace() func(*ILMStopRequest) { + return func(r *ILMStopRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f ILMStop) WithFilterPath(v ...string) func(*ILMStopRequest) { + return func(r *ILMStopRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f ILMStop) WithHeader(h map[string]string) func(*ILMStopRequest) { + return func(r *ILMStopRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f ILMStop) WithOpaqueID(s string) func(*ILMStopRequest) { + return func(r *ILMStopRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.indices.freeze.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.indices.freeze.go new file mode 100644 index 00000000000..0079edc8a9d --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.indices.freeze.go @@ -0,0 +1,269 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newIndicesFreezeFunc(t Transport) IndicesFreeze { + return func(index string, o ...func(*IndicesFreezeRequest)) (*Response, error) { + var r = IndicesFreezeRequest{Index: index} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesFreeze - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/frozen.html. +// +type IndicesFreeze func(index string, o ...func(*IndicesFreezeRequest)) (*Response, error) + +// IndicesFreezeRequest configures the Indices Freeze API request. +// +type IndicesFreezeRequest struct { + Index string + + AllowNoIndices *bool + ExpandWildcards string + IgnoreUnavailable *bool + MasterTimeout time.Duration + Timeout time.Duration + WaitForActiveShards string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesFreezeRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len(r.Index) + 1 + len("_freeze")) + path.WriteString("/") + path.WriteString(r.Index) + path.WriteString("/") + path.WriteString("_freeze") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.WaitForActiveShards != "" { + params["wait_for_active_shards"] = r.WaitForActiveShards + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesFreeze) WithContext(v context.Context) func(*IndicesFreezeRequest) { + return func(r *IndicesFreezeRequest) { + r.ctx = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f IndicesFreeze) WithAllowNoIndices(v bool) func(*IndicesFreezeRequest) { + return func(r *IndicesFreezeRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f IndicesFreeze) WithExpandWildcards(v string) func(*IndicesFreezeRequest) { + return func(r *IndicesFreezeRequest) { + r.ExpandWildcards = v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f IndicesFreeze) WithIgnoreUnavailable(v bool) func(*IndicesFreezeRequest) { + return func(r *IndicesFreezeRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f IndicesFreeze) WithMasterTimeout(v time.Duration) func(*IndicesFreezeRequest) { + return func(r *IndicesFreezeRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f IndicesFreeze) WithTimeout(v time.Duration) func(*IndicesFreezeRequest) { + return func(r *IndicesFreezeRequest) { + r.Timeout = v + } +} + +// WithWaitForActiveShards - sets the number of active shards to wait for before the operation returns.. +// +func (f IndicesFreeze) WithWaitForActiveShards(v string) func(*IndicesFreezeRequest) { + return func(r *IndicesFreezeRequest) { + r.WaitForActiveShards = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesFreeze) WithPretty() func(*IndicesFreezeRequest) { + return func(r *IndicesFreezeRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesFreeze) WithHuman() func(*IndicesFreezeRequest) { + return func(r *IndicesFreezeRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesFreeze) WithErrorTrace() func(*IndicesFreezeRequest) { + return func(r *IndicesFreezeRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesFreeze) WithFilterPath(v ...string) func(*IndicesFreezeRequest) { + return func(r *IndicesFreezeRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesFreeze) WithHeader(h map[string]string) func(*IndicesFreezeRequest) { + return func(r *IndicesFreezeRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesFreeze) WithOpaqueID(s string) func(*IndicesFreezeRequest) { + return func(r *IndicesFreezeRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.indices.reload_search_analyzers.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.indices.reload_search_analyzers.go new file mode 100644 index 00000000000..9ed5c3c8f5d --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.indices.reload_search_analyzers.go @@ -0,0 +1,229 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newIndicesReloadSearchAnalyzersFunc(t Transport) IndicesReloadSearchAnalyzers { + return func(index []string, o ...func(*IndicesReloadSearchAnalyzersRequest)) (*Response, error) { + var r = IndicesReloadSearchAnalyzersRequest{Index: index} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesReloadSearchAnalyzers - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-reload-analyzers.html. +// +type IndicesReloadSearchAnalyzers func(index []string, o ...func(*IndicesReloadSearchAnalyzersRequest)) (*Response, error) + +// IndicesReloadSearchAnalyzersRequest configures the Indices Reload Search Analyzers API request. +// +type IndicesReloadSearchAnalyzersRequest struct { + Index []string + + AllowNoIndices *bool + ExpandWildcards string + IgnoreUnavailable *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesReloadSearchAnalyzersRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_reload_search_analyzers")) + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + path.WriteString("/") + path.WriteString("_reload_search_analyzers") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesReloadSearchAnalyzers) WithContext(v context.Context) func(*IndicesReloadSearchAnalyzersRequest) { + return func(r *IndicesReloadSearchAnalyzersRequest) { + r.ctx = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f IndicesReloadSearchAnalyzers) WithAllowNoIndices(v bool) func(*IndicesReloadSearchAnalyzersRequest) { + return func(r *IndicesReloadSearchAnalyzersRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f IndicesReloadSearchAnalyzers) WithExpandWildcards(v string) func(*IndicesReloadSearchAnalyzersRequest) { + return func(r *IndicesReloadSearchAnalyzersRequest) { + r.ExpandWildcards = v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f IndicesReloadSearchAnalyzers) WithIgnoreUnavailable(v bool) func(*IndicesReloadSearchAnalyzersRequest) { + return func(r *IndicesReloadSearchAnalyzersRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesReloadSearchAnalyzers) WithPretty() func(*IndicesReloadSearchAnalyzersRequest) { + return func(r *IndicesReloadSearchAnalyzersRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesReloadSearchAnalyzers) WithHuman() func(*IndicesReloadSearchAnalyzersRequest) { + return func(r *IndicesReloadSearchAnalyzersRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesReloadSearchAnalyzers) WithErrorTrace() func(*IndicesReloadSearchAnalyzersRequest) { + return func(r *IndicesReloadSearchAnalyzersRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesReloadSearchAnalyzers) WithFilterPath(v ...string) func(*IndicesReloadSearchAnalyzersRequest) { + return func(r *IndicesReloadSearchAnalyzersRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesReloadSearchAnalyzers) WithHeader(h map[string]string) func(*IndicesReloadSearchAnalyzersRequest) { + return func(r *IndicesReloadSearchAnalyzersRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesReloadSearchAnalyzers) WithOpaqueID(s string) func(*IndicesReloadSearchAnalyzersRequest) { + return func(r *IndicesReloadSearchAnalyzersRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.indices.unfreeze.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.indices.unfreeze.go new file mode 100644 index 00000000000..dd2f8526e6f --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.indices.unfreeze.go @@ -0,0 +1,269 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newIndicesUnfreezeFunc(t Transport) IndicesUnfreeze { + return func(index string, o ...func(*IndicesUnfreezeRequest)) (*Response, error) { + var r = IndicesUnfreezeRequest{Index: index} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// IndicesUnfreeze - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/frozen.html. +// +type IndicesUnfreeze func(index string, o ...func(*IndicesUnfreezeRequest)) (*Response, error) + +// IndicesUnfreezeRequest configures the Indices Unfreeze API request. +// +type IndicesUnfreezeRequest struct { + Index string + + AllowNoIndices *bool + ExpandWildcards string + IgnoreUnavailable *bool + MasterTimeout time.Duration + Timeout time.Duration + WaitForActiveShards string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r IndicesUnfreezeRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len(r.Index) + 1 + len("_unfreeze")) + path.WriteString("/") + path.WriteString(r.Index) + path.WriteString("/") + path.WriteString("_unfreeze") + + params = make(map[string]string) + + if r.AllowNoIndices != nil { + params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) + } + + if r.ExpandWildcards != "" { + params["expand_wildcards"] = r.ExpandWildcards + } + + if r.IgnoreUnavailable != nil { + params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) + } + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.WaitForActiveShards != "" { + params["wait_for_active_shards"] = r.WaitForActiveShards + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f IndicesUnfreeze) WithContext(v context.Context) func(*IndicesUnfreezeRequest) { + return func(r *IndicesUnfreezeRequest) { + r.ctx = v + } +} + +// WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). +// +func (f IndicesUnfreeze) WithAllowNoIndices(v bool) func(*IndicesUnfreezeRequest) { + return func(r *IndicesUnfreezeRequest) { + r.AllowNoIndices = &v + } +} + +// WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. +// +func (f IndicesUnfreeze) WithExpandWildcards(v string) func(*IndicesUnfreezeRequest) { + return func(r *IndicesUnfreezeRequest) { + r.ExpandWildcards = v + } +} + +// WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). +// +func (f IndicesUnfreeze) WithIgnoreUnavailable(v bool) func(*IndicesUnfreezeRequest) { + return func(r *IndicesUnfreezeRequest) { + r.IgnoreUnavailable = &v + } +} + +// WithMasterTimeout - specify timeout for connection to master. +// +func (f IndicesUnfreeze) WithMasterTimeout(v time.Duration) func(*IndicesUnfreezeRequest) { + return func(r *IndicesUnfreezeRequest) { + r.MasterTimeout = v + } +} + +// WithTimeout - explicit operation timeout. +// +func (f IndicesUnfreeze) WithTimeout(v time.Duration) func(*IndicesUnfreezeRequest) { + return func(r *IndicesUnfreezeRequest) { + r.Timeout = v + } +} + +// WithWaitForActiveShards - sets the number of active shards to wait for before the operation returns.. +// +func (f IndicesUnfreeze) WithWaitForActiveShards(v string) func(*IndicesUnfreezeRequest) { + return func(r *IndicesUnfreezeRequest) { + r.WaitForActiveShards = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f IndicesUnfreeze) WithPretty() func(*IndicesUnfreezeRequest) { + return func(r *IndicesUnfreezeRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f IndicesUnfreeze) WithHuman() func(*IndicesUnfreezeRequest) { + return func(r *IndicesUnfreezeRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f IndicesUnfreeze) WithErrorTrace() func(*IndicesUnfreezeRequest) { + return func(r *IndicesUnfreezeRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f IndicesUnfreeze) WithFilterPath(v ...string) func(*IndicesUnfreezeRequest) { + return func(r *IndicesUnfreezeRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f IndicesUnfreeze) WithHeader(h map[string]string) func(*IndicesUnfreezeRequest) { + return func(r *IndicesUnfreezeRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f IndicesUnfreeze) WithOpaqueID(s string) func(*IndicesUnfreezeRequest) { + return func(r *IndicesUnfreezeRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.delete.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.delete.go new file mode 100644 index 00000000000..4e4bfba80f2 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.delete.go @@ -0,0 +1,183 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newLicenseDeleteFunc(t Transport) LicenseDelete { + return func(o ...func(*LicenseDeleteRequest)) (*Response, error) { + var r = LicenseDeleteRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// LicenseDelete - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/delete-license.html. +// +type LicenseDelete func(o ...func(*LicenseDeleteRequest)) (*Response, error) + +// LicenseDeleteRequest configures the License Delete API request. +// +type LicenseDeleteRequest struct { + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r LicenseDeleteRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(len("/_license")) + path.WriteString("/_license") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f LicenseDelete) WithContext(v context.Context) func(*LicenseDeleteRequest) { + return func(r *LicenseDeleteRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f LicenseDelete) WithPretty() func(*LicenseDeleteRequest) { + return func(r *LicenseDeleteRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f LicenseDelete) WithHuman() func(*LicenseDeleteRequest) { + return func(r *LicenseDeleteRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f LicenseDelete) WithErrorTrace() func(*LicenseDeleteRequest) { + return func(r *LicenseDeleteRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f LicenseDelete) WithFilterPath(v ...string) func(*LicenseDeleteRequest) { + return func(r *LicenseDeleteRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f LicenseDelete) WithHeader(h map[string]string) func(*LicenseDeleteRequest) { + return func(r *LicenseDeleteRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f LicenseDelete) WithOpaqueID(s string) func(*LicenseDeleteRequest) { + return func(r *LicenseDeleteRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.get.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.get.go new file mode 100644 index 00000000000..eea05934581 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.get.go @@ -0,0 +1,198 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newLicenseGetFunc(t Transport) LicenseGet { + return func(o ...func(*LicenseGetRequest)) (*Response, error) { + var r = LicenseGetRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// LicenseGet - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/get-license.html. +// +type LicenseGet func(o ...func(*LicenseGetRequest)) (*Response, error) + +// LicenseGetRequest configures the License Get API request. +// +type LicenseGetRequest struct { + Local *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r LicenseGetRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_license")) + path.WriteString("/_license") + + params = make(map[string]string) + + if r.Local != nil { + params["local"] = strconv.FormatBool(*r.Local) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f LicenseGet) WithContext(v context.Context) func(*LicenseGetRequest) { + return func(r *LicenseGetRequest) { + r.ctx = v + } +} + +// WithLocal - return local information, do not retrieve the state from master node (default: false). +// +func (f LicenseGet) WithLocal(v bool) func(*LicenseGetRequest) { + return func(r *LicenseGetRequest) { + r.Local = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f LicenseGet) WithPretty() func(*LicenseGetRequest) { + return func(r *LicenseGetRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f LicenseGet) WithHuman() func(*LicenseGetRequest) { + return func(r *LicenseGetRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f LicenseGet) WithErrorTrace() func(*LicenseGetRequest) { + return func(r *LicenseGetRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f LicenseGet) WithFilterPath(v ...string) func(*LicenseGetRequest) { + return func(r *LicenseGetRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f LicenseGet) WithHeader(h map[string]string) func(*LicenseGetRequest) { + return func(r *LicenseGetRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f LicenseGet) WithOpaqueID(s string) func(*LicenseGetRequest) { + return func(r *LicenseGetRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.get_basic_status.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.get_basic_status.go new file mode 100644 index 00000000000..3fe4b8aa7b4 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.get_basic_status.go @@ -0,0 +1,183 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newLicenseGetBasicStatusFunc(t Transport) LicenseGetBasicStatus { + return func(o ...func(*LicenseGetBasicStatusRequest)) (*Response, error) { + var r = LicenseGetBasicStatusRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// LicenseGetBasicStatus - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/get-basic-status.html. +// +type LicenseGetBasicStatus func(o ...func(*LicenseGetBasicStatusRequest)) (*Response, error) + +// LicenseGetBasicStatusRequest configures the License Get Basic Status API request. +// +type LicenseGetBasicStatusRequest struct { + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r LicenseGetBasicStatusRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_license/basic_status")) + path.WriteString("/_license/basic_status") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f LicenseGetBasicStatus) WithContext(v context.Context) func(*LicenseGetBasicStatusRequest) { + return func(r *LicenseGetBasicStatusRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f LicenseGetBasicStatus) WithPretty() func(*LicenseGetBasicStatusRequest) { + return func(r *LicenseGetBasicStatusRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f LicenseGetBasicStatus) WithHuman() func(*LicenseGetBasicStatusRequest) { + return func(r *LicenseGetBasicStatusRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f LicenseGetBasicStatus) WithErrorTrace() func(*LicenseGetBasicStatusRequest) { + return func(r *LicenseGetBasicStatusRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f LicenseGetBasicStatus) WithFilterPath(v ...string) func(*LicenseGetBasicStatusRequest) { + return func(r *LicenseGetBasicStatusRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f LicenseGetBasicStatus) WithHeader(h map[string]string) func(*LicenseGetBasicStatusRequest) { + return func(r *LicenseGetBasicStatusRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f LicenseGetBasicStatus) WithOpaqueID(s string) func(*LicenseGetBasicStatusRequest) { + return func(r *LicenseGetBasicStatusRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.get_trial_status.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.get_trial_status.go new file mode 100644 index 00000000000..175e04ab284 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.get_trial_status.go @@ -0,0 +1,183 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newLicenseGetTrialStatusFunc(t Transport) LicenseGetTrialStatus { + return func(o ...func(*LicenseGetTrialStatusRequest)) (*Response, error) { + var r = LicenseGetTrialStatusRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// LicenseGetTrialStatus - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/get-trial-status.html. +// +type LicenseGetTrialStatus func(o ...func(*LicenseGetTrialStatusRequest)) (*Response, error) + +// LicenseGetTrialStatusRequest configures the License Get Trial Status API request. +// +type LicenseGetTrialStatusRequest struct { + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r LicenseGetTrialStatusRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_license/trial_status")) + path.WriteString("/_license/trial_status") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f LicenseGetTrialStatus) WithContext(v context.Context) func(*LicenseGetTrialStatusRequest) { + return func(r *LicenseGetTrialStatusRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f LicenseGetTrialStatus) WithPretty() func(*LicenseGetTrialStatusRequest) { + return func(r *LicenseGetTrialStatusRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f LicenseGetTrialStatus) WithHuman() func(*LicenseGetTrialStatusRequest) { + return func(r *LicenseGetTrialStatusRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f LicenseGetTrialStatus) WithErrorTrace() func(*LicenseGetTrialStatusRequest) { + return func(r *LicenseGetTrialStatusRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f LicenseGetTrialStatus) WithFilterPath(v ...string) func(*LicenseGetTrialStatusRequest) { + return func(r *LicenseGetTrialStatusRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f LicenseGetTrialStatus) WithHeader(h map[string]string) func(*LicenseGetTrialStatusRequest) { + return func(r *LicenseGetTrialStatusRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f LicenseGetTrialStatus) WithOpaqueID(s string) func(*LicenseGetTrialStatusRequest) { + return func(r *LicenseGetTrialStatusRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.post.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.post.go new file mode 100644 index 00000000000..bd44c73492a --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.post.go @@ -0,0 +1,213 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newLicensePostFunc(t Transport) LicensePost { + return func(o ...func(*LicensePostRequest)) (*Response, error) { + var r = LicensePostRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// LicensePost - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/update-license.html. +// +type LicensePost func(o ...func(*LicensePostRequest)) (*Response, error) + +// LicensePostRequest configures the License Post API request. +// +type LicensePostRequest struct { + Body io.Reader + + Acknowledge *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r LicensePostRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(len("/_license")) + path.WriteString("/_license") + + params = make(map[string]string) + + if r.Acknowledge != nil { + params["acknowledge"] = strconv.FormatBool(*r.Acknowledge) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f LicensePost) WithContext(v context.Context) func(*LicensePostRequest) { + return func(r *LicensePostRequest) { + r.ctx = v + } +} + +// WithBody - licenses to be installed. +// +func (f LicensePost) WithBody(v io.Reader) func(*LicensePostRequest) { + return func(r *LicensePostRequest) { + r.Body = v + } +} + +// WithAcknowledge - whether the user has acknowledged acknowledge messages (default: false). +// +func (f LicensePost) WithAcknowledge(v bool) func(*LicensePostRequest) { + return func(r *LicensePostRequest) { + r.Acknowledge = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f LicensePost) WithPretty() func(*LicensePostRequest) { + return func(r *LicensePostRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f LicensePost) WithHuman() func(*LicensePostRequest) { + return func(r *LicensePostRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f LicensePost) WithErrorTrace() func(*LicensePostRequest) { + return func(r *LicensePostRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f LicensePost) WithFilterPath(v ...string) func(*LicensePostRequest) { + return func(r *LicensePostRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f LicensePost) WithHeader(h map[string]string) func(*LicensePostRequest) { + return func(r *LicensePostRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f LicensePost) WithOpaqueID(s string) func(*LicensePostRequest) { + return func(r *LicensePostRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.post_start_basic.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.post_start_basic.go new file mode 100644 index 00000000000..34a6c5c26ca --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.post_start_basic.go @@ -0,0 +1,198 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newLicensePostStartBasicFunc(t Transport) LicensePostStartBasic { + return func(o ...func(*LicensePostStartBasicRequest)) (*Response, error) { + var r = LicensePostStartBasicRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// LicensePostStartBasic - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/start-basic.html. +// +type LicensePostStartBasic func(o ...func(*LicensePostStartBasicRequest)) (*Response, error) + +// LicensePostStartBasicRequest configures the License Post Start Basic API request. +// +type LicensePostStartBasicRequest struct { + Acknowledge *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r LicensePostStartBasicRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(len("/_license/start_basic")) + path.WriteString("/_license/start_basic") + + params = make(map[string]string) + + if r.Acknowledge != nil { + params["acknowledge"] = strconv.FormatBool(*r.Acknowledge) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f LicensePostStartBasic) WithContext(v context.Context) func(*LicensePostStartBasicRequest) { + return func(r *LicensePostStartBasicRequest) { + r.ctx = v + } +} + +// WithAcknowledge - whether the user has acknowledged acknowledge messages (default: false). +// +func (f LicensePostStartBasic) WithAcknowledge(v bool) func(*LicensePostStartBasicRequest) { + return func(r *LicensePostStartBasicRequest) { + r.Acknowledge = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f LicensePostStartBasic) WithPretty() func(*LicensePostStartBasicRequest) { + return func(r *LicensePostStartBasicRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f LicensePostStartBasic) WithHuman() func(*LicensePostStartBasicRequest) { + return func(r *LicensePostStartBasicRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f LicensePostStartBasic) WithErrorTrace() func(*LicensePostStartBasicRequest) { + return func(r *LicensePostStartBasicRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f LicensePostStartBasic) WithFilterPath(v ...string) func(*LicensePostStartBasicRequest) { + return func(r *LicensePostStartBasicRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f LicensePostStartBasic) WithHeader(h map[string]string) func(*LicensePostStartBasicRequest) { + return func(r *LicensePostStartBasicRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f LicensePostStartBasic) WithOpaqueID(s string) func(*LicensePostStartBasicRequest) { + return func(r *LicensePostStartBasicRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.post_start_trial.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.post_start_trial.go new file mode 100644 index 00000000000..2489dda3f83 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.license.post_start_trial.go @@ -0,0 +1,211 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newLicensePostStartTrialFunc(t Transport) LicensePostStartTrial { + return func(o ...func(*LicensePostStartTrialRequest)) (*Response, error) { + var r = LicensePostStartTrialRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// LicensePostStartTrial - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/start-trial.html. +// +type LicensePostStartTrial func(o ...func(*LicensePostStartTrialRequest)) (*Response, error) + +// LicensePostStartTrialRequest configures the License Post Start Trial API request. +// +type LicensePostStartTrialRequest struct { + Acknowledge *bool + DocumentType string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r LicensePostStartTrialRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(len("/_license/start_trial")) + path.WriteString("/_license/start_trial") + + params = make(map[string]string) + + if r.Acknowledge != nil { + params["acknowledge"] = strconv.FormatBool(*r.Acknowledge) + } + + if r.DocumentType != "" { + params["type"] = r.DocumentType + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f LicensePostStartTrial) WithContext(v context.Context) func(*LicensePostStartTrialRequest) { + return func(r *LicensePostStartTrialRequest) { + r.ctx = v + } +} + +// WithAcknowledge - whether the user has acknowledged acknowledge messages (default: false). +// +func (f LicensePostStartTrial) WithAcknowledge(v bool) func(*LicensePostStartTrialRequest) { + return func(r *LicensePostStartTrialRequest) { + r.Acknowledge = &v + } +} + +// WithDocumentType - the type of trial license to generate (default: "trial"). +// +func (f LicensePostStartTrial) WithDocumentType(v string) func(*LicensePostStartTrialRequest) { + return func(r *LicensePostStartTrialRequest) { + r.DocumentType = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f LicensePostStartTrial) WithPretty() func(*LicensePostStartTrialRequest) { + return func(r *LicensePostStartTrialRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f LicensePostStartTrial) WithHuman() func(*LicensePostStartTrialRequest) { + return func(r *LicensePostStartTrialRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f LicensePostStartTrial) WithErrorTrace() func(*LicensePostStartTrialRequest) { + return func(r *LicensePostStartTrialRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f LicensePostStartTrial) WithFilterPath(v ...string) func(*LicensePostStartTrialRequest) { + return func(r *LicensePostStartTrialRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f LicensePostStartTrial) WithHeader(h map[string]string) func(*LicensePostStartTrialRequest) { + return func(r *LicensePostStartTrialRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f LicensePostStartTrial) WithOpaqueID(s string) func(*LicensePostStartTrialRequest) { + return func(r *LicensePostStartTrialRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.migration.deprecations.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.migration.deprecations.go new file mode 100644 index 00000000000..24c44a0cae3 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.migration.deprecations.go @@ -0,0 +1,200 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newMigrationDeprecationsFunc(t Transport) MigrationDeprecations { + return func(o ...func(*MigrationDeprecationsRequest)) (*Response, error) { + var r = MigrationDeprecationsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MigrationDeprecations - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/migration-api-deprecation.html. +// +type MigrationDeprecations func(o ...func(*MigrationDeprecationsRequest)) (*Response, error) + +// MigrationDeprecationsRequest configures the Migration Deprecations API request. +// +type MigrationDeprecationsRequest struct { + Index string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MigrationDeprecationsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(r.Index) + 1 + len("_migration") + 1 + len("deprecations")) + if r.Index != "" { + path.WriteString("/") + path.WriteString(r.Index) + } + path.WriteString("/") + path.WriteString("_migration") + path.WriteString("/") + path.WriteString("deprecations") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MigrationDeprecations) WithContext(v context.Context) func(*MigrationDeprecationsRequest) { + return func(r *MigrationDeprecationsRequest) { + r.ctx = v + } +} + +// WithIndex - index pattern. +// +func (f MigrationDeprecations) WithIndex(v string) func(*MigrationDeprecationsRequest) { + return func(r *MigrationDeprecationsRequest) { + r.Index = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MigrationDeprecations) WithPretty() func(*MigrationDeprecationsRequest) { + return func(r *MigrationDeprecationsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MigrationDeprecations) WithHuman() func(*MigrationDeprecationsRequest) { + return func(r *MigrationDeprecationsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MigrationDeprecations) WithErrorTrace() func(*MigrationDeprecationsRequest) { + return func(r *MigrationDeprecationsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MigrationDeprecations) WithFilterPath(v ...string) func(*MigrationDeprecationsRequest) { + return func(r *MigrationDeprecationsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MigrationDeprecations) WithHeader(h map[string]string) func(*MigrationDeprecationsRequest) { + return func(r *MigrationDeprecationsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MigrationDeprecations) WithOpaqueID(s string) func(*MigrationDeprecationsRequest) { + return func(r *MigrationDeprecationsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.close_job.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.close_job.go new file mode 100644 index 00000000000..bb59fcb7cde --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.close_job.go @@ -0,0 +1,249 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" + "time" +) + +func newMLCloseJobFunc(t Transport) MLCloseJob { + return func(job_id string, o ...func(*MLCloseJobRequest)) (*Response, error) { + var r = MLCloseJobRequest{JobID: job_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLCloseJob - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-close-job.html. +// +type MLCloseJob func(job_id string, o ...func(*MLCloseJobRequest)) (*Response, error) + +// MLCloseJobRequest configures the ML Close Job API request. +// +type MLCloseJobRequest struct { + Body io.Reader + + JobID string + + AllowNoJobs *bool + Force *bool + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLCloseJobRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_ml") + 1 + len("anomaly_detectors") + 1 + len(r.JobID) + 1 + len("_close")) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("anomaly_detectors") + path.WriteString("/") + path.WriteString(r.JobID) + path.WriteString("/") + path.WriteString("_close") + + params = make(map[string]string) + + if r.AllowNoJobs != nil { + params["allow_no_jobs"] = strconv.FormatBool(*r.AllowNoJobs) + } + + if r.Force != nil { + params["force"] = strconv.FormatBool(*r.Force) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLCloseJob) WithContext(v context.Context) func(*MLCloseJobRequest) { + return func(r *MLCloseJobRequest) { + r.ctx = v + } +} + +// WithBody - The URL params optionally sent in the body. +// +func (f MLCloseJob) WithBody(v io.Reader) func(*MLCloseJobRequest) { + return func(r *MLCloseJobRequest) { + r.Body = v + } +} + +// WithAllowNoJobs - whether to ignore if a wildcard expression matches no jobs. (this includes `_all` string or when no jobs have been specified). +// +func (f MLCloseJob) WithAllowNoJobs(v bool) func(*MLCloseJobRequest) { + return func(r *MLCloseJobRequest) { + r.AllowNoJobs = &v + } +} + +// WithForce - true if the job should be forcefully closed. +// +func (f MLCloseJob) WithForce(v bool) func(*MLCloseJobRequest) { + return func(r *MLCloseJobRequest) { + r.Force = &v + } +} + +// WithTimeout - controls the time to wait until a job has closed. default to 30 minutes. +// +func (f MLCloseJob) WithTimeout(v time.Duration) func(*MLCloseJobRequest) { + return func(r *MLCloseJobRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLCloseJob) WithPretty() func(*MLCloseJobRequest) { + return func(r *MLCloseJobRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLCloseJob) WithHuman() func(*MLCloseJobRequest) { + return func(r *MLCloseJobRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLCloseJob) WithErrorTrace() func(*MLCloseJobRequest) { + return func(r *MLCloseJobRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLCloseJob) WithFilterPath(v ...string) func(*MLCloseJobRequest) { + return func(r *MLCloseJobRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLCloseJob) WithHeader(h map[string]string) func(*MLCloseJobRequest) { + return func(r *MLCloseJobRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLCloseJob) WithOpaqueID(s string) func(*MLCloseJobRequest) { + return func(r *MLCloseJobRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_calendar.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_calendar.go new file mode 100644 index 00000000000..f4976d4f7fc --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_calendar.go @@ -0,0 +1,188 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newMLDeleteCalendarFunc(t Transport) MLDeleteCalendar { + return func(calendar_id string, o ...func(*MLDeleteCalendarRequest)) (*Response, error) { + var r = MLDeleteCalendarRequest{CalendarID: calendar_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLDeleteCalendar - +// +type MLDeleteCalendar func(calendar_id string, o ...func(*MLDeleteCalendarRequest)) (*Response, error) + +// MLDeleteCalendarRequest configures the ML Delete Calendar API request. +// +type MLDeleteCalendarRequest struct { + CalendarID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLDeleteCalendarRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_ml") + 1 + len("calendars") + 1 + len(r.CalendarID)) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("calendars") + path.WriteString("/") + path.WriteString(r.CalendarID) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLDeleteCalendar) WithContext(v context.Context) func(*MLDeleteCalendarRequest) { + return func(r *MLDeleteCalendarRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLDeleteCalendar) WithPretty() func(*MLDeleteCalendarRequest) { + return func(r *MLDeleteCalendarRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLDeleteCalendar) WithHuman() func(*MLDeleteCalendarRequest) { + return func(r *MLDeleteCalendarRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLDeleteCalendar) WithErrorTrace() func(*MLDeleteCalendarRequest) { + return func(r *MLDeleteCalendarRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLDeleteCalendar) WithFilterPath(v ...string) func(*MLDeleteCalendarRequest) { + return func(r *MLDeleteCalendarRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLDeleteCalendar) WithHeader(h map[string]string) func(*MLDeleteCalendarRequest) { + return func(r *MLDeleteCalendarRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLDeleteCalendar) WithOpaqueID(s string) func(*MLDeleteCalendarRequest) { + return func(r *MLDeleteCalendarRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_calendar_event.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_calendar_event.go new file mode 100644 index 00000000000..fa9a5818fe6 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_calendar_event.go @@ -0,0 +1,193 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newMLDeleteCalendarEventFunc(t Transport) MLDeleteCalendarEvent { + return func(calendar_id string, event_id string, o ...func(*MLDeleteCalendarEventRequest)) (*Response, error) { + var r = MLDeleteCalendarEventRequest{CalendarID: calendar_id, EventID: event_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLDeleteCalendarEvent - +// +type MLDeleteCalendarEvent func(calendar_id string, event_id string, o ...func(*MLDeleteCalendarEventRequest)) (*Response, error) + +// MLDeleteCalendarEventRequest configures the ML Delete Calendar Event API request. +// +type MLDeleteCalendarEventRequest struct { + CalendarID string + EventID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLDeleteCalendarEventRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_ml") + 1 + len("calendars") + 1 + len(r.CalendarID) + 1 + len("events") + 1 + len(r.EventID)) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("calendars") + path.WriteString("/") + path.WriteString(r.CalendarID) + path.WriteString("/") + path.WriteString("events") + path.WriteString("/") + path.WriteString(r.EventID) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLDeleteCalendarEvent) WithContext(v context.Context) func(*MLDeleteCalendarEventRequest) { + return func(r *MLDeleteCalendarEventRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLDeleteCalendarEvent) WithPretty() func(*MLDeleteCalendarEventRequest) { + return func(r *MLDeleteCalendarEventRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLDeleteCalendarEvent) WithHuman() func(*MLDeleteCalendarEventRequest) { + return func(r *MLDeleteCalendarEventRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLDeleteCalendarEvent) WithErrorTrace() func(*MLDeleteCalendarEventRequest) { + return func(r *MLDeleteCalendarEventRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLDeleteCalendarEvent) WithFilterPath(v ...string) func(*MLDeleteCalendarEventRequest) { + return func(r *MLDeleteCalendarEventRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLDeleteCalendarEvent) WithHeader(h map[string]string) func(*MLDeleteCalendarEventRequest) { + return func(r *MLDeleteCalendarEventRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLDeleteCalendarEvent) WithOpaqueID(s string) func(*MLDeleteCalendarEventRequest) { + return func(r *MLDeleteCalendarEventRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_calendar_job.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_calendar_job.go new file mode 100644 index 00000000000..1af14892774 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_calendar_job.go @@ -0,0 +1,193 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newMLDeleteCalendarJobFunc(t Transport) MLDeleteCalendarJob { + return func(calendar_id string, job_id string, o ...func(*MLDeleteCalendarJobRequest)) (*Response, error) { + var r = MLDeleteCalendarJobRequest{CalendarID: calendar_id, JobID: job_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLDeleteCalendarJob - +// +type MLDeleteCalendarJob func(calendar_id string, job_id string, o ...func(*MLDeleteCalendarJobRequest)) (*Response, error) + +// MLDeleteCalendarJobRequest configures the ML Delete Calendar Job API request. +// +type MLDeleteCalendarJobRequest struct { + CalendarID string + JobID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLDeleteCalendarJobRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_ml") + 1 + len("calendars") + 1 + len(r.CalendarID) + 1 + len("jobs") + 1 + len(r.JobID)) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("calendars") + path.WriteString("/") + path.WriteString(r.CalendarID) + path.WriteString("/") + path.WriteString("jobs") + path.WriteString("/") + path.WriteString(r.JobID) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLDeleteCalendarJob) WithContext(v context.Context) func(*MLDeleteCalendarJobRequest) { + return func(r *MLDeleteCalendarJobRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLDeleteCalendarJob) WithPretty() func(*MLDeleteCalendarJobRequest) { + return func(r *MLDeleteCalendarJobRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLDeleteCalendarJob) WithHuman() func(*MLDeleteCalendarJobRequest) { + return func(r *MLDeleteCalendarJobRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLDeleteCalendarJob) WithErrorTrace() func(*MLDeleteCalendarJobRequest) { + return func(r *MLDeleteCalendarJobRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLDeleteCalendarJob) WithFilterPath(v ...string) func(*MLDeleteCalendarJobRequest) { + return func(r *MLDeleteCalendarJobRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLDeleteCalendarJob) WithHeader(h map[string]string) func(*MLDeleteCalendarJobRequest) { + return func(r *MLDeleteCalendarJobRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLDeleteCalendarJob) WithOpaqueID(s string) func(*MLDeleteCalendarJobRequest) { + return func(r *MLDeleteCalendarJobRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_data_frame_analytics.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_data_frame_analytics.go new file mode 100644 index 00000000000..a8b445d4235 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_data_frame_analytics.go @@ -0,0 +1,192 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newMLDeleteDataFrameAnalyticsFunc(t Transport) MLDeleteDataFrameAnalytics { + return func(id string, o ...func(*MLDeleteDataFrameAnalyticsRequest)) (*Response, error) { + var r = MLDeleteDataFrameAnalyticsRequest{ID: id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLDeleteDataFrameAnalytics - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/delete-dfanalytics.html. +// +type MLDeleteDataFrameAnalytics func(id string, o ...func(*MLDeleteDataFrameAnalyticsRequest)) (*Response, error) + +// MLDeleteDataFrameAnalyticsRequest configures the ML Delete Data Frame Analytics API request. +// +type MLDeleteDataFrameAnalyticsRequest struct { + ID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLDeleteDataFrameAnalyticsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_ml") + 1 + len("data_frame") + 1 + len("analytics") + 1 + len(r.ID)) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("data_frame") + path.WriteString("/") + path.WriteString("analytics") + path.WriteString("/") + path.WriteString(r.ID) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLDeleteDataFrameAnalytics) WithContext(v context.Context) func(*MLDeleteDataFrameAnalyticsRequest) { + return func(r *MLDeleteDataFrameAnalyticsRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLDeleteDataFrameAnalytics) WithPretty() func(*MLDeleteDataFrameAnalyticsRequest) { + return func(r *MLDeleteDataFrameAnalyticsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLDeleteDataFrameAnalytics) WithHuman() func(*MLDeleteDataFrameAnalyticsRequest) { + return func(r *MLDeleteDataFrameAnalyticsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLDeleteDataFrameAnalytics) WithErrorTrace() func(*MLDeleteDataFrameAnalyticsRequest) { + return func(r *MLDeleteDataFrameAnalyticsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLDeleteDataFrameAnalytics) WithFilterPath(v ...string) func(*MLDeleteDataFrameAnalyticsRequest) { + return func(r *MLDeleteDataFrameAnalyticsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLDeleteDataFrameAnalytics) WithHeader(h map[string]string) func(*MLDeleteDataFrameAnalyticsRequest) { + return func(r *MLDeleteDataFrameAnalyticsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLDeleteDataFrameAnalytics) WithOpaqueID(s string) func(*MLDeleteDataFrameAnalyticsRequest) { + return func(r *MLDeleteDataFrameAnalyticsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_datafeed.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_datafeed.go new file mode 100644 index 00000000000..3838931d249 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_datafeed.go @@ -0,0 +1,205 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newMLDeleteDatafeedFunc(t Transport) MLDeleteDatafeed { + return func(datafeed_id string, o ...func(*MLDeleteDatafeedRequest)) (*Response, error) { + var r = MLDeleteDatafeedRequest{DatafeedID: datafeed_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLDeleteDatafeed - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-datafeed.html. +// +type MLDeleteDatafeed func(datafeed_id string, o ...func(*MLDeleteDatafeedRequest)) (*Response, error) + +// MLDeleteDatafeedRequest configures the ML Delete Datafeed API request. +// +type MLDeleteDatafeedRequest struct { + DatafeedID string + + Force *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLDeleteDatafeedRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_ml") + 1 + len("datafeeds") + 1 + len(r.DatafeedID)) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("datafeeds") + path.WriteString("/") + path.WriteString(r.DatafeedID) + + params = make(map[string]string) + + if r.Force != nil { + params["force"] = strconv.FormatBool(*r.Force) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLDeleteDatafeed) WithContext(v context.Context) func(*MLDeleteDatafeedRequest) { + return func(r *MLDeleteDatafeedRequest) { + r.ctx = v + } +} + +// WithForce - true if the datafeed should be forcefully deleted. +// +func (f MLDeleteDatafeed) WithForce(v bool) func(*MLDeleteDatafeedRequest) { + return func(r *MLDeleteDatafeedRequest) { + r.Force = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLDeleteDatafeed) WithPretty() func(*MLDeleteDatafeedRequest) { + return func(r *MLDeleteDatafeedRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLDeleteDatafeed) WithHuman() func(*MLDeleteDatafeedRequest) { + return func(r *MLDeleteDatafeedRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLDeleteDatafeed) WithErrorTrace() func(*MLDeleteDatafeedRequest) { + return func(r *MLDeleteDatafeedRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLDeleteDatafeed) WithFilterPath(v ...string) func(*MLDeleteDatafeedRequest) { + return func(r *MLDeleteDatafeedRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLDeleteDatafeed) WithHeader(h map[string]string) func(*MLDeleteDatafeedRequest) { + return func(r *MLDeleteDatafeedRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLDeleteDatafeed) WithOpaqueID(s string) func(*MLDeleteDatafeedRequest) { + return func(r *MLDeleteDatafeedRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_expired_data.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_expired_data.go new file mode 100644 index 00000000000..688bf774c92 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_expired_data.go @@ -0,0 +1,181 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newMLDeleteExpiredDataFunc(t Transport) MLDeleteExpiredData { + return func(o ...func(*MLDeleteExpiredDataRequest)) (*Response, error) { + var r = MLDeleteExpiredDataRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLDeleteExpiredData - +// +type MLDeleteExpiredData func(o ...func(*MLDeleteExpiredDataRequest)) (*Response, error) + +// MLDeleteExpiredDataRequest configures the ML Delete Expired Data API request. +// +type MLDeleteExpiredDataRequest struct { + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLDeleteExpiredDataRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(len("/_ml/_delete_expired_data")) + path.WriteString("/_ml/_delete_expired_data") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLDeleteExpiredData) WithContext(v context.Context) func(*MLDeleteExpiredDataRequest) { + return func(r *MLDeleteExpiredDataRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLDeleteExpiredData) WithPretty() func(*MLDeleteExpiredDataRequest) { + return func(r *MLDeleteExpiredDataRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLDeleteExpiredData) WithHuman() func(*MLDeleteExpiredDataRequest) { + return func(r *MLDeleteExpiredDataRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLDeleteExpiredData) WithErrorTrace() func(*MLDeleteExpiredDataRequest) { + return func(r *MLDeleteExpiredDataRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLDeleteExpiredData) WithFilterPath(v ...string) func(*MLDeleteExpiredDataRequest) { + return func(r *MLDeleteExpiredDataRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLDeleteExpiredData) WithHeader(h map[string]string) func(*MLDeleteExpiredDataRequest) { + return func(r *MLDeleteExpiredDataRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLDeleteExpiredData) WithOpaqueID(s string) func(*MLDeleteExpiredDataRequest) { + return func(r *MLDeleteExpiredDataRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_filter.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_filter.go new file mode 100644 index 00000000000..cbad83df71e --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_filter.go @@ -0,0 +1,188 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newMLDeleteFilterFunc(t Transport) MLDeleteFilter { + return func(filter_id string, o ...func(*MLDeleteFilterRequest)) (*Response, error) { + var r = MLDeleteFilterRequest{FilterID: filter_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLDeleteFilter - +// +type MLDeleteFilter func(filter_id string, o ...func(*MLDeleteFilterRequest)) (*Response, error) + +// MLDeleteFilterRequest configures the ML Delete Filter API request. +// +type MLDeleteFilterRequest struct { + FilterID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLDeleteFilterRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_ml") + 1 + len("filters") + 1 + len(r.FilterID)) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("filters") + path.WriteString("/") + path.WriteString(r.FilterID) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLDeleteFilter) WithContext(v context.Context) func(*MLDeleteFilterRequest) { + return func(r *MLDeleteFilterRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLDeleteFilter) WithPretty() func(*MLDeleteFilterRequest) { + return func(r *MLDeleteFilterRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLDeleteFilter) WithHuman() func(*MLDeleteFilterRequest) { + return func(r *MLDeleteFilterRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLDeleteFilter) WithErrorTrace() func(*MLDeleteFilterRequest) { + return func(r *MLDeleteFilterRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLDeleteFilter) WithFilterPath(v ...string) func(*MLDeleteFilterRequest) { + return func(r *MLDeleteFilterRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLDeleteFilter) WithHeader(h map[string]string) func(*MLDeleteFilterRequest) { + return func(r *MLDeleteFilterRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLDeleteFilter) WithOpaqueID(s string) func(*MLDeleteFilterRequest) { + return func(r *MLDeleteFilterRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_forecast.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_forecast.go new file mode 100644 index 00000000000..89bef7dcef2 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_forecast.go @@ -0,0 +1,234 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newMLDeleteForecastFunc(t Transport) MLDeleteForecast { + return func(job_id string, o ...func(*MLDeleteForecastRequest)) (*Response, error) { + var r = MLDeleteForecastRequest{JobID: job_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLDeleteForecast - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-forecast.html. +// +type MLDeleteForecast func(job_id string, o ...func(*MLDeleteForecastRequest)) (*Response, error) + +// MLDeleteForecastRequest configures the ML Delete Forecast API request. +// +type MLDeleteForecastRequest struct { + ForecastID string + JobID string + + AllowNoForecasts *bool + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLDeleteForecastRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_ml") + 1 + len("anomaly_detectors") + 1 + len(r.JobID) + 1 + len("_forecast") + 1 + len(r.ForecastID)) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("anomaly_detectors") + path.WriteString("/") + path.WriteString(r.JobID) + path.WriteString("/") + path.WriteString("_forecast") + if r.ForecastID != "" { + path.WriteString("/") + path.WriteString(r.ForecastID) + } + + params = make(map[string]string) + + if r.AllowNoForecasts != nil { + params["allow_no_forecasts"] = strconv.FormatBool(*r.AllowNoForecasts) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLDeleteForecast) WithContext(v context.Context) func(*MLDeleteForecastRequest) { + return func(r *MLDeleteForecastRequest) { + r.ctx = v + } +} + +// WithForecastID - the ID of the forecast to delete, can be comma delimited list. leaving blank implies `_all`. +// +func (f MLDeleteForecast) WithForecastID(v string) func(*MLDeleteForecastRequest) { + return func(r *MLDeleteForecastRequest) { + r.ForecastID = v + } +} + +// WithAllowNoForecasts - whether to ignore if `_all` matches no forecasts. +// +func (f MLDeleteForecast) WithAllowNoForecasts(v bool) func(*MLDeleteForecastRequest) { + return func(r *MLDeleteForecastRequest) { + r.AllowNoForecasts = &v + } +} + +// WithTimeout - controls the time to wait until the forecast(s) are deleted. default to 30 seconds. +// +func (f MLDeleteForecast) WithTimeout(v time.Duration) func(*MLDeleteForecastRequest) { + return func(r *MLDeleteForecastRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLDeleteForecast) WithPretty() func(*MLDeleteForecastRequest) { + return func(r *MLDeleteForecastRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLDeleteForecast) WithHuman() func(*MLDeleteForecastRequest) { + return func(r *MLDeleteForecastRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLDeleteForecast) WithErrorTrace() func(*MLDeleteForecastRequest) { + return func(r *MLDeleteForecastRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLDeleteForecast) WithFilterPath(v ...string) func(*MLDeleteForecastRequest) { + return func(r *MLDeleteForecastRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLDeleteForecast) WithHeader(h map[string]string) func(*MLDeleteForecastRequest) { + return func(r *MLDeleteForecastRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLDeleteForecast) WithOpaqueID(s string) func(*MLDeleteForecastRequest) { + return func(r *MLDeleteForecastRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_job.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_job.go new file mode 100644 index 00000000000..0f77838dc71 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_job.go @@ -0,0 +1,218 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newMLDeleteJobFunc(t Transport) MLDeleteJob { + return func(job_id string, o ...func(*MLDeleteJobRequest)) (*Response, error) { + var r = MLDeleteJobRequest{JobID: job_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLDeleteJob - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-job.html. +// +type MLDeleteJob func(job_id string, o ...func(*MLDeleteJobRequest)) (*Response, error) + +// MLDeleteJobRequest configures the ML Delete Job API request. +// +type MLDeleteJobRequest struct { + JobID string + + Force *bool + WaitForCompletion *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLDeleteJobRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_ml") + 1 + len("anomaly_detectors") + 1 + len(r.JobID)) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("anomaly_detectors") + path.WriteString("/") + path.WriteString(r.JobID) + + params = make(map[string]string) + + if r.Force != nil { + params["force"] = strconv.FormatBool(*r.Force) + } + + if r.WaitForCompletion != nil { + params["wait_for_completion"] = strconv.FormatBool(*r.WaitForCompletion) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLDeleteJob) WithContext(v context.Context) func(*MLDeleteJobRequest) { + return func(r *MLDeleteJobRequest) { + r.ctx = v + } +} + +// WithForce - true if the job should be forcefully deleted. +// +func (f MLDeleteJob) WithForce(v bool) func(*MLDeleteJobRequest) { + return func(r *MLDeleteJobRequest) { + r.Force = &v + } +} + +// WithWaitForCompletion - should this request wait until the operation has completed before returning. +// +func (f MLDeleteJob) WithWaitForCompletion(v bool) func(*MLDeleteJobRequest) { + return func(r *MLDeleteJobRequest) { + r.WaitForCompletion = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLDeleteJob) WithPretty() func(*MLDeleteJobRequest) { + return func(r *MLDeleteJobRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLDeleteJob) WithHuman() func(*MLDeleteJobRequest) { + return func(r *MLDeleteJobRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLDeleteJob) WithErrorTrace() func(*MLDeleteJobRequest) { + return func(r *MLDeleteJobRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLDeleteJob) WithFilterPath(v ...string) func(*MLDeleteJobRequest) { + return func(r *MLDeleteJobRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLDeleteJob) WithHeader(h map[string]string) func(*MLDeleteJobRequest) { + return func(r *MLDeleteJobRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLDeleteJob) WithOpaqueID(s string) func(*MLDeleteJobRequest) { + return func(r *MLDeleteJobRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_model_snapshot.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_model_snapshot.go new file mode 100644 index 00000000000..7fdcb6f0fa9 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.delete_model_snapshot.go @@ -0,0 +1,195 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newMLDeleteModelSnapshotFunc(t Transport) MLDeleteModelSnapshot { + return func(snapshot_id string, job_id string, o ...func(*MLDeleteModelSnapshotRequest)) (*Response, error) { + var r = MLDeleteModelSnapshotRequest{SnapshotID: snapshot_id, JobID: job_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLDeleteModelSnapshot - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-snapshot.html. +// +type MLDeleteModelSnapshot func(snapshot_id string, job_id string, o ...func(*MLDeleteModelSnapshotRequest)) (*Response, error) + +// MLDeleteModelSnapshotRequest configures the ML Delete Model Snapshot API request. +// +type MLDeleteModelSnapshotRequest struct { + JobID string + SnapshotID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLDeleteModelSnapshotRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_ml") + 1 + len("anomaly_detectors") + 1 + len(r.JobID) + 1 + len("model_snapshots") + 1 + len(r.SnapshotID)) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("anomaly_detectors") + path.WriteString("/") + path.WriteString(r.JobID) + path.WriteString("/") + path.WriteString("model_snapshots") + path.WriteString("/") + path.WriteString(r.SnapshotID) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLDeleteModelSnapshot) WithContext(v context.Context) func(*MLDeleteModelSnapshotRequest) { + return func(r *MLDeleteModelSnapshotRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLDeleteModelSnapshot) WithPretty() func(*MLDeleteModelSnapshotRequest) { + return func(r *MLDeleteModelSnapshotRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLDeleteModelSnapshot) WithHuman() func(*MLDeleteModelSnapshotRequest) { + return func(r *MLDeleteModelSnapshotRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLDeleteModelSnapshot) WithErrorTrace() func(*MLDeleteModelSnapshotRequest) { + return func(r *MLDeleteModelSnapshotRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLDeleteModelSnapshot) WithFilterPath(v ...string) func(*MLDeleteModelSnapshotRequest) { + return func(r *MLDeleteModelSnapshotRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLDeleteModelSnapshot) WithHeader(h map[string]string) func(*MLDeleteModelSnapshotRequest) { + return func(r *MLDeleteModelSnapshotRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLDeleteModelSnapshot) WithOpaqueID(s string) func(*MLDeleteModelSnapshotRequest) { + return func(r *MLDeleteModelSnapshotRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.estimate_memory_usage.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.estimate_memory_usage.go new file mode 100644 index 00000000000..b71008b2ed1 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.estimate_memory_usage.go @@ -0,0 +1,190 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newMLEstimateMemoryUsageFunc(t Transport) MLEstimateMemoryUsage { + return func(body io.Reader, o ...func(*MLEstimateMemoryUsageRequest)) (*Response, error) { + var r = MLEstimateMemoryUsageRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLEstimateMemoryUsage - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/estimate-memory-usage-dfanalytics.html. +// +type MLEstimateMemoryUsage func(body io.Reader, o ...func(*MLEstimateMemoryUsageRequest)) (*Response, error) + +// MLEstimateMemoryUsageRequest configures the ML Estimate Memory Usage API request. +// +type MLEstimateMemoryUsageRequest struct { + Body io.Reader + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLEstimateMemoryUsageRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(len("/_ml/data_frame/analytics/_estimate_memory_usage")) + path.WriteString("/_ml/data_frame/analytics/_estimate_memory_usage") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLEstimateMemoryUsage) WithContext(v context.Context) func(*MLEstimateMemoryUsageRequest) { + return func(r *MLEstimateMemoryUsageRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLEstimateMemoryUsage) WithPretty() func(*MLEstimateMemoryUsageRequest) { + return func(r *MLEstimateMemoryUsageRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLEstimateMemoryUsage) WithHuman() func(*MLEstimateMemoryUsageRequest) { + return func(r *MLEstimateMemoryUsageRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLEstimateMemoryUsage) WithErrorTrace() func(*MLEstimateMemoryUsageRequest) { + return func(r *MLEstimateMemoryUsageRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLEstimateMemoryUsage) WithFilterPath(v ...string) func(*MLEstimateMemoryUsageRequest) { + return func(r *MLEstimateMemoryUsageRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLEstimateMemoryUsage) WithHeader(h map[string]string) func(*MLEstimateMemoryUsageRequest) { + return func(r *MLEstimateMemoryUsageRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLEstimateMemoryUsage) WithOpaqueID(s string) func(*MLEstimateMemoryUsageRequest) { + return func(r *MLEstimateMemoryUsageRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.evaluate_data_frame.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.evaluate_data_frame.go new file mode 100644 index 00000000000..1b0350cfe56 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.evaluate_data_frame.go @@ -0,0 +1,190 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newMLEvaluateDataFrameFunc(t Transport) MLEvaluateDataFrame { + return func(body io.Reader, o ...func(*MLEvaluateDataFrameRequest)) (*Response, error) { + var r = MLEvaluateDataFrameRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLEvaluateDataFrame - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/evaluate-dfanalytics.html. +// +type MLEvaluateDataFrame func(body io.Reader, o ...func(*MLEvaluateDataFrameRequest)) (*Response, error) + +// MLEvaluateDataFrameRequest configures the ML Evaluate Data Frame API request. +// +type MLEvaluateDataFrameRequest struct { + Body io.Reader + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLEvaluateDataFrameRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(len("/_ml/data_frame/_evaluate")) + path.WriteString("/_ml/data_frame/_evaluate") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLEvaluateDataFrame) WithContext(v context.Context) func(*MLEvaluateDataFrameRequest) { + return func(r *MLEvaluateDataFrameRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLEvaluateDataFrame) WithPretty() func(*MLEvaluateDataFrameRequest) { + return func(r *MLEvaluateDataFrameRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLEvaluateDataFrame) WithHuman() func(*MLEvaluateDataFrameRequest) { + return func(r *MLEvaluateDataFrameRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLEvaluateDataFrame) WithErrorTrace() func(*MLEvaluateDataFrameRequest) { + return func(r *MLEvaluateDataFrameRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLEvaluateDataFrame) WithFilterPath(v ...string) func(*MLEvaluateDataFrameRequest) { + return func(r *MLEvaluateDataFrameRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLEvaluateDataFrame) WithHeader(h map[string]string) func(*MLEvaluateDataFrameRequest) { + return func(r *MLEvaluateDataFrameRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLEvaluateDataFrame) WithOpaqueID(s string) func(*MLEvaluateDataFrameRequest) { + return func(r *MLEvaluateDataFrameRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.find_file_structure.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.find_file_structure.go new file mode 100644 index 00000000000..d74b3988764 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.find_file_structure.go @@ -0,0 +1,375 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" + "time" +) + +func newMLFindFileStructureFunc(t Transport) MLFindFileStructure { + return func(body io.Reader, o ...func(*MLFindFileStructureRequest)) (*Response, error) { + var r = MLFindFileStructureRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLFindFileStructure - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-find-file-structure.html. +// +type MLFindFileStructure func(body io.Reader, o ...func(*MLFindFileStructureRequest)) (*Response, error) + +// MLFindFileStructureRequest configures the ML Find File Structure API request. +// +type MLFindFileStructureRequest struct { + Body io.Reader + + Charset string + ColumnNames []string + Delimiter string + Explain *bool + Format string + GrokPattern string + HasHeaderRow *bool + LineMergeSizeLimit *int + LinesToSample *int + Quote string + ShouldTrimFields *bool + Timeout time.Duration + TimestampField string + TimestampFormat string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLFindFileStructureRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(len("/_ml/find_file_structure")) + path.WriteString("/_ml/find_file_structure") + + params = make(map[string]string) + + if r.Charset != "" { + params["charset"] = r.Charset + } + + if len(r.ColumnNames) > 0 { + params["column_names"] = strings.Join(r.ColumnNames, ",") + } + + if r.Delimiter != "" { + params["delimiter"] = r.Delimiter + } + + if r.Explain != nil { + params["explain"] = strconv.FormatBool(*r.Explain) + } + + if r.Format != "" { + params["format"] = r.Format + } + + if r.GrokPattern != "" { + params["grok_pattern"] = r.GrokPattern + } + + if r.HasHeaderRow != nil { + params["has_header_row"] = strconv.FormatBool(*r.HasHeaderRow) + } + + if r.LineMergeSizeLimit != nil { + params["line_merge_size_limit"] = strconv.FormatInt(int64(*r.LineMergeSizeLimit), 10) + } + + if r.LinesToSample != nil { + params["lines_to_sample"] = strconv.FormatInt(int64(*r.LinesToSample), 10) + } + + if r.Quote != "" { + params["quote"] = r.Quote + } + + if r.ShouldTrimFields != nil { + params["should_trim_fields"] = strconv.FormatBool(*r.ShouldTrimFields) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.TimestampField != "" { + params["timestamp_field"] = r.TimestampField + } + + if r.TimestampFormat != "" { + params["timestamp_format"] = r.TimestampFormat + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLFindFileStructure) WithContext(v context.Context) func(*MLFindFileStructureRequest) { + return func(r *MLFindFileStructureRequest) { + r.ctx = v + } +} + +// WithCharset - optional parameter to specify the character set of the file. +// +func (f MLFindFileStructure) WithCharset(v string) func(*MLFindFileStructureRequest) { + return func(r *MLFindFileStructureRequest) { + r.Charset = v + } +} + +// WithColumnNames - optional parameter containing a comma separated list of the column names for a delimited file. +// +func (f MLFindFileStructure) WithColumnNames(v ...string) func(*MLFindFileStructureRequest) { + return func(r *MLFindFileStructureRequest) { + r.ColumnNames = v + } +} + +// WithDelimiter - optional parameter to specify the delimiter character for a delimited file - must be a single character. +// +func (f MLFindFileStructure) WithDelimiter(v string) func(*MLFindFileStructureRequest) { + return func(r *MLFindFileStructureRequest) { + r.Delimiter = v + } +} + +// WithExplain - whether to include a commentary on how the structure was derived. +// +func (f MLFindFileStructure) WithExplain(v bool) func(*MLFindFileStructureRequest) { + return func(r *MLFindFileStructureRequest) { + r.Explain = &v + } +} + +// WithFormat - optional parameter to specify the high level file format. +// +func (f MLFindFileStructure) WithFormat(v string) func(*MLFindFileStructureRequest) { + return func(r *MLFindFileStructureRequest) { + r.Format = v + } +} + +// WithGrokPattern - optional parameter to specify the grok pattern that should be used to extract fields from messages in a semi-structured text file. +// +func (f MLFindFileStructure) WithGrokPattern(v string) func(*MLFindFileStructureRequest) { + return func(r *MLFindFileStructureRequest) { + r.GrokPattern = v + } +} + +// WithHasHeaderRow - optional parameter to specify whether a delimited file includes the column names in its first row. +// +func (f MLFindFileStructure) WithHasHeaderRow(v bool) func(*MLFindFileStructureRequest) { + return func(r *MLFindFileStructureRequest) { + r.HasHeaderRow = &v + } +} + +// WithLineMergeSizeLimit - maximum number of characters permitted in a single message when lines are merged to create messages.. +// +func (f MLFindFileStructure) WithLineMergeSizeLimit(v int) func(*MLFindFileStructureRequest) { + return func(r *MLFindFileStructureRequest) { + r.LineMergeSizeLimit = &v + } +} + +// WithLinesToSample - how many lines of the file should be included in the analysis. +// +func (f MLFindFileStructure) WithLinesToSample(v int) func(*MLFindFileStructureRequest) { + return func(r *MLFindFileStructureRequest) { + r.LinesToSample = &v + } +} + +// WithQuote - optional parameter to specify the quote character for a delimited file - must be a single character. +// +func (f MLFindFileStructure) WithQuote(v string) func(*MLFindFileStructureRequest) { + return func(r *MLFindFileStructureRequest) { + r.Quote = v + } +} + +// WithShouldTrimFields - optional parameter to specify whether the values between delimiters in a delimited file should have whitespace trimmed from them. +// +func (f MLFindFileStructure) WithShouldTrimFields(v bool) func(*MLFindFileStructureRequest) { + return func(r *MLFindFileStructureRequest) { + r.ShouldTrimFields = &v + } +} + +// WithTimeout - timeout after which the analysis will be aborted. +// +func (f MLFindFileStructure) WithTimeout(v time.Duration) func(*MLFindFileStructureRequest) { + return func(r *MLFindFileStructureRequest) { + r.Timeout = v + } +} + +// WithTimestampField - optional parameter to specify the timestamp field in the file. +// +func (f MLFindFileStructure) WithTimestampField(v string) func(*MLFindFileStructureRequest) { + return func(r *MLFindFileStructureRequest) { + r.TimestampField = v + } +} + +// WithTimestampFormat - optional parameter to specify the timestamp format in the file - may be either a joda or java time format. +// +func (f MLFindFileStructure) WithTimestampFormat(v string) func(*MLFindFileStructureRequest) { + return func(r *MLFindFileStructureRequest) { + r.TimestampFormat = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLFindFileStructure) WithPretty() func(*MLFindFileStructureRequest) { + return func(r *MLFindFileStructureRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLFindFileStructure) WithHuman() func(*MLFindFileStructureRequest) { + return func(r *MLFindFileStructureRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLFindFileStructure) WithErrorTrace() func(*MLFindFileStructureRequest) { + return func(r *MLFindFileStructureRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLFindFileStructure) WithFilterPath(v ...string) func(*MLFindFileStructureRequest) { + return func(r *MLFindFileStructureRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLFindFileStructure) WithHeader(h map[string]string) func(*MLFindFileStructureRequest) { + return func(r *MLFindFileStructureRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLFindFileStructure) WithOpaqueID(s string) func(*MLFindFileStructureRequest) { + return func(r *MLFindFileStructureRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.flush_job.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.flush_job.go new file mode 100644 index 00000000000..6f3421d6b0c --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.flush_job.go @@ -0,0 +1,274 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newMLFlushJobFunc(t Transport) MLFlushJob { + return func(job_id string, o ...func(*MLFlushJobRequest)) (*Response, error) { + var r = MLFlushJobRequest{JobID: job_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLFlushJob - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-flush-job.html. +// +type MLFlushJob func(job_id string, o ...func(*MLFlushJobRequest)) (*Response, error) + +// MLFlushJobRequest configures the ML Flush Job API request. +// +type MLFlushJobRequest struct { + Body io.Reader + + JobID string + + AdvanceTime string + CalcInterim *bool + End string + SkipTime string + Start string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLFlushJobRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_ml") + 1 + len("anomaly_detectors") + 1 + len(r.JobID) + 1 + len("_flush")) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("anomaly_detectors") + path.WriteString("/") + path.WriteString(r.JobID) + path.WriteString("/") + path.WriteString("_flush") + + params = make(map[string]string) + + if r.AdvanceTime != "" { + params["advance_time"] = r.AdvanceTime + } + + if r.CalcInterim != nil { + params["calc_interim"] = strconv.FormatBool(*r.CalcInterim) + } + + if r.End != "" { + params["end"] = r.End + } + + if r.SkipTime != "" { + params["skip_time"] = r.SkipTime + } + + if r.Start != "" { + params["start"] = r.Start + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLFlushJob) WithContext(v context.Context) func(*MLFlushJobRequest) { + return func(r *MLFlushJobRequest) { + r.ctx = v + } +} + +// WithBody - Flush parameters. +// +func (f MLFlushJob) WithBody(v io.Reader) func(*MLFlushJobRequest) { + return func(r *MLFlushJobRequest) { + r.Body = v + } +} + +// WithAdvanceTime - advances time to the given value generating results and updating the model for the advanced interval. +// +func (f MLFlushJob) WithAdvanceTime(v string) func(*MLFlushJobRequest) { + return func(r *MLFlushJobRequest) { + r.AdvanceTime = v + } +} + +// WithCalcInterim - calculates interim results for the most recent bucket or all buckets within the latency period. +// +func (f MLFlushJob) WithCalcInterim(v bool) func(*MLFlushJobRequest) { + return func(r *MLFlushJobRequest) { + r.CalcInterim = &v + } +} + +// WithEnd - when used in conjunction with calc_interim, specifies the range of buckets on which to calculate interim results. +// +func (f MLFlushJob) WithEnd(v string) func(*MLFlushJobRequest) { + return func(r *MLFlushJobRequest) { + r.End = v + } +} + +// WithSkipTime - skips time to the given value without generating results or updating the model for the skipped interval. +// +func (f MLFlushJob) WithSkipTime(v string) func(*MLFlushJobRequest) { + return func(r *MLFlushJobRequest) { + r.SkipTime = v + } +} + +// WithStart - when used in conjunction with calc_interim, specifies the range of buckets on which to calculate interim results. +// +func (f MLFlushJob) WithStart(v string) func(*MLFlushJobRequest) { + return func(r *MLFlushJobRequest) { + r.Start = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLFlushJob) WithPretty() func(*MLFlushJobRequest) { + return func(r *MLFlushJobRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLFlushJob) WithHuman() func(*MLFlushJobRequest) { + return func(r *MLFlushJobRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLFlushJob) WithErrorTrace() func(*MLFlushJobRequest) { + return func(r *MLFlushJobRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLFlushJob) WithFilterPath(v ...string) func(*MLFlushJobRequest) { + return func(r *MLFlushJobRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLFlushJob) WithHeader(h map[string]string) func(*MLFlushJobRequest) { + return func(r *MLFlushJobRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLFlushJob) WithOpaqueID(s string) func(*MLFlushJobRequest) { + return func(r *MLFlushJobRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.forecast.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.forecast.go new file mode 100644 index 00000000000..99ff8ba3aa5 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.forecast.go @@ -0,0 +1,218 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" + "time" +) + +func newMLForecastFunc(t Transport) MLForecast { + return func(job_id string, o ...func(*MLForecastRequest)) (*Response, error) { + var r = MLForecastRequest{JobID: job_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLForecast - +// +type MLForecast func(job_id string, o ...func(*MLForecastRequest)) (*Response, error) + +// MLForecastRequest configures the ML Forecast API request. +// +type MLForecastRequest struct { + JobID string + + Duration time.Duration + ExpiresIn time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLForecastRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_ml") + 1 + len("anomaly_detectors") + 1 + len(r.JobID) + 1 + len("_forecast")) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("anomaly_detectors") + path.WriteString("/") + path.WriteString(r.JobID) + path.WriteString("/") + path.WriteString("_forecast") + + params = make(map[string]string) + + if r.Duration != 0 { + params["duration"] = formatDuration(r.Duration) + } + + if r.ExpiresIn != 0 { + params["expires_in"] = formatDuration(r.ExpiresIn) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLForecast) WithContext(v context.Context) func(*MLForecastRequest) { + return func(r *MLForecastRequest) { + r.ctx = v + } +} + +// WithDuration - the duration of the forecast. +// +func (f MLForecast) WithDuration(v time.Duration) func(*MLForecastRequest) { + return func(r *MLForecastRequest) { + r.Duration = v + } +} + +// WithExpiresIn - the time interval after which the forecast expires. expired forecasts will be deleted at the first opportunity.. +// +func (f MLForecast) WithExpiresIn(v time.Duration) func(*MLForecastRequest) { + return func(r *MLForecastRequest) { + r.ExpiresIn = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLForecast) WithPretty() func(*MLForecastRequest) { + return func(r *MLForecastRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLForecast) WithHuman() func(*MLForecastRequest) { + return func(r *MLForecastRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLForecast) WithErrorTrace() func(*MLForecastRequest) { + return func(r *MLForecastRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLForecast) WithFilterPath(v ...string) func(*MLForecastRequest) { + return func(r *MLForecastRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLForecast) WithHeader(h map[string]string) func(*MLForecastRequest) { + return func(r *MLForecastRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLForecast) WithOpaqueID(s string) func(*MLForecastRequest) { + return func(r *MLForecastRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_buckets.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_buckets.go new file mode 100644 index 00000000000..3ce3b11b3f3 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_buckets.go @@ -0,0 +1,342 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "fmt" + "io" + "net/http" + "strconv" + "strings" +) + +func newMLGetBucketsFunc(t Transport) MLGetBuckets { + return func(job_id string, o ...func(*MLGetBucketsRequest)) (*Response, error) { + var r = MLGetBucketsRequest{JobID: job_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLGetBuckets - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-bucket.html. +// +type MLGetBuckets func(job_id string, o ...func(*MLGetBucketsRequest)) (*Response, error) + +// MLGetBucketsRequest configures the ML Get Buckets API request. +// +type MLGetBucketsRequest struct { + Body io.Reader + + JobID string + Timestamp string + + AnomalyScore interface{} + Desc *bool + End string + ExcludeInterim *bool + Expand *bool + From *int + Size *int + Sort string + Start string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLGetBucketsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_ml") + 1 + len("anomaly_detectors") + 1 + len(r.JobID) + 1 + len("results") + 1 + len("buckets") + 1 + len(r.Timestamp)) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("anomaly_detectors") + path.WriteString("/") + path.WriteString(r.JobID) + path.WriteString("/") + path.WriteString("results") + path.WriteString("/") + path.WriteString("buckets") + if r.Timestamp != "" { + path.WriteString("/") + path.WriteString(r.Timestamp) + } + + params = make(map[string]string) + + if r.AnomalyScore != nil { + params["anomaly_score"] = fmt.Sprintf("%v", r.AnomalyScore) + } + + if r.Desc != nil { + params["desc"] = strconv.FormatBool(*r.Desc) + } + + if r.End != "" { + params["end"] = r.End + } + + if r.ExcludeInterim != nil { + params["exclude_interim"] = strconv.FormatBool(*r.ExcludeInterim) + } + + if r.Expand != nil { + params["expand"] = strconv.FormatBool(*r.Expand) + } + + if r.From != nil { + params["from"] = strconv.FormatInt(int64(*r.From), 10) + } + + if r.Size != nil { + params["size"] = strconv.FormatInt(int64(*r.Size), 10) + } + + if r.Sort != "" { + params["sort"] = r.Sort + } + + if r.Start != "" { + params["start"] = r.Start + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLGetBuckets) WithContext(v context.Context) func(*MLGetBucketsRequest) { + return func(r *MLGetBucketsRequest) { + r.ctx = v + } +} + +// WithBody - Bucket selection details if not provided in URI. +// +func (f MLGetBuckets) WithBody(v io.Reader) func(*MLGetBucketsRequest) { + return func(r *MLGetBucketsRequest) { + r.Body = v + } +} + +// WithTimestamp - the timestamp of the desired single bucket result. +// +func (f MLGetBuckets) WithTimestamp(v string) func(*MLGetBucketsRequest) { + return func(r *MLGetBucketsRequest) { + r.Timestamp = v + } +} + +// WithAnomalyScore - filter for the most anomalous buckets. +// +func (f MLGetBuckets) WithAnomalyScore(v interface{}) func(*MLGetBucketsRequest) { + return func(r *MLGetBucketsRequest) { + r.AnomalyScore = v + } +} + +// WithDesc - set the sort direction. +// +func (f MLGetBuckets) WithDesc(v bool) func(*MLGetBucketsRequest) { + return func(r *MLGetBucketsRequest) { + r.Desc = &v + } +} + +// WithEnd - end time filter for buckets. +// +func (f MLGetBuckets) WithEnd(v string) func(*MLGetBucketsRequest) { + return func(r *MLGetBucketsRequest) { + r.End = v + } +} + +// WithExcludeInterim - exclude interim results. +// +func (f MLGetBuckets) WithExcludeInterim(v bool) func(*MLGetBucketsRequest) { + return func(r *MLGetBucketsRequest) { + r.ExcludeInterim = &v + } +} + +// WithExpand - include anomaly records. +// +func (f MLGetBuckets) WithExpand(v bool) func(*MLGetBucketsRequest) { + return func(r *MLGetBucketsRequest) { + r.Expand = &v + } +} + +// WithFrom - skips a number of buckets. +// +func (f MLGetBuckets) WithFrom(v int) func(*MLGetBucketsRequest) { + return func(r *MLGetBucketsRequest) { + r.From = &v + } +} + +// WithSize - specifies a max number of buckets to get. +// +func (f MLGetBuckets) WithSize(v int) func(*MLGetBucketsRequest) { + return func(r *MLGetBucketsRequest) { + r.Size = &v + } +} + +// WithSort - sort buckets by a particular field. +// +func (f MLGetBuckets) WithSort(v string) func(*MLGetBucketsRequest) { + return func(r *MLGetBucketsRequest) { + r.Sort = v + } +} + +// WithStart - start time filter for buckets. +// +func (f MLGetBuckets) WithStart(v string) func(*MLGetBucketsRequest) { + return func(r *MLGetBucketsRequest) { + r.Start = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLGetBuckets) WithPretty() func(*MLGetBucketsRequest) { + return func(r *MLGetBucketsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLGetBuckets) WithHuman() func(*MLGetBucketsRequest) { + return func(r *MLGetBucketsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLGetBuckets) WithErrorTrace() func(*MLGetBucketsRequest) { + return func(r *MLGetBucketsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLGetBuckets) WithFilterPath(v ...string) func(*MLGetBucketsRequest) { + return func(r *MLGetBucketsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLGetBuckets) WithHeader(h map[string]string) func(*MLGetBucketsRequest) { + return func(r *MLGetBucketsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLGetBuckets) WithOpaqueID(s string) func(*MLGetBucketsRequest) { + return func(r *MLGetBucketsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_calendar_events.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_calendar_events.go new file mode 100644 index 00000000000..b5c6c7fee3d --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_calendar_events.go @@ -0,0 +1,258 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "fmt" + "net/http" + "strconv" + "strings" +) + +func newMLGetCalendarEventsFunc(t Transport) MLGetCalendarEvents { + return func(calendar_id string, o ...func(*MLGetCalendarEventsRequest)) (*Response, error) { + var r = MLGetCalendarEventsRequest{CalendarID: calendar_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLGetCalendarEvents - +// +type MLGetCalendarEvents func(calendar_id string, o ...func(*MLGetCalendarEventsRequest)) (*Response, error) + +// MLGetCalendarEventsRequest configures the ML Get Calendar Events API request. +// +type MLGetCalendarEventsRequest struct { + CalendarID string + + End interface{} + From *int + JobID string + Size *int + Start string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLGetCalendarEventsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_ml") + 1 + len("calendars") + 1 + len(r.CalendarID) + 1 + len("events")) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("calendars") + path.WriteString("/") + path.WriteString(r.CalendarID) + path.WriteString("/") + path.WriteString("events") + + params = make(map[string]string) + + if r.End != nil { + params["end"] = fmt.Sprintf("%v", r.End) + } + + if r.From != nil { + params["from"] = strconv.FormatInt(int64(*r.From), 10) + } + + if r.JobID != "" { + params["job_id"] = r.JobID + } + + if r.Size != nil { + params["size"] = strconv.FormatInt(int64(*r.Size), 10) + } + + if r.Start != "" { + params["start"] = r.Start + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLGetCalendarEvents) WithContext(v context.Context) func(*MLGetCalendarEventsRequest) { + return func(r *MLGetCalendarEventsRequest) { + r.ctx = v + } +} + +// WithEnd - get events before this time. +// +func (f MLGetCalendarEvents) WithEnd(v interface{}) func(*MLGetCalendarEventsRequest) { + return func(r *MLGetCalendarEventsRequest) { + r.End = v + } +} + +// WithFrom - skips a number of events. +// +func (f MLGetCalendarEvents) WithFrom(v int) func(*MLGetCalendarEventsRequest) { + return func(r *MLGetCalendarEventsRequest) { + r.From = &v + } +} + +// WithJobID - get events for the job. when this option is used calendar_id must be '_all'. +// +func (f MLGetCalendarEvents) WithJobID(v string) func(*MLGetCalendarEventsRequest) { + return func(r *MLGetCalendarEventsRequest) { + r.JobID = v + } +} + +// WithSize - specifies a max number of events to get. +// +func (f MLGetCalendarEvents) WithSize(v int) func(*MLGetCalendarEventsRequest) { + return func(r *MLGetCalendarEventsRequest) { + r.Size = &v + } +} + +// WithStart - get events after this time. +// +func (f MLGetCalendarEvents) WithStart(v string) func(*MLGetCalendarEventsRequest) { + return func(r *MLGetCalendarEventsRequest) { + r.Start = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLGetCalendarEvents) WithPretty() func(*MLGetCalendarEventsRequest) { + return func(r *MLGetCalendarEventsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLGetCalendarEvents) WithHuman() func(*MLGetCalendarEventsRequest) { + return func(r *MLGetCalendarEventsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLGetCalendarEvents) WithErrorTrace() func(*MLGetCalendarEventsRequest) { + return func(r *MLGetCalendarEventsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLGetCalendarEvents) WithFilterPath(v ...string) func(*MLGetCalendarEventsRequest) { + return func(r *MLGetCalendarEventsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLGetCalendarEvents) WithHeader(h map[string]string) func(*MLGetCalendarEventsRequest) { + return func(r *MLGetCalendarEventsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLGetCalendarEvents) WithOpaqueID(s string) func(*MLGetCalendarEventsRequest) { + return func(r *MLGetCalendarEventsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_calendars.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_calendars.go new file mode 100644 index 00000000000..c4a5ddca147 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_calendars.go @@ -0,0 +1,241 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newMLGetCalendarsFunc(t Transport) MLGetCalendars { + return func(o ...func(*MLGetCalendarsRequest)) (*Response, error) { + var r = MLGetCalendarsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLGetCalendars - +// +type MLGetCalendars func(o ...func(*MLGetCalendarsRequest)) (*Response, error) + +// MLGetCalendarsRequest configures the ML Get Calendars API request. +// +type MLGetCalendarsRequest struct { + Body io.Reader + + CalendarID string + + From *int + Size *int + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLGetCalendarsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_ml") + 1 + len("calendars") + 1 + len(r.CalendarID)) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("calendars") + if r.CalendarID != "" { + path.WriteString("/") + path.WriteString(r.CalendarID) + } + + params = make(map[string]string) + + if r.From != nil { + params["from"] = strconv.FormatInt(int64(*r.From), 10) + } + + if r.Size != nil { + params["size"] = strconv.FormatInt(int64(*r.Size), 10) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLGetCalendars) WithContext(v context.Context) func(*MLGetCalendarsRequest) { + return func(r *MLGetCalendarsRequest) { + r.ctx = v + } +} + +// WithBody - The from and size parameters optionally sent in the body. +// +func (f MLGetCalendars) WithBody(v io.Reader) func(*MLGetCalendarsRequest) { + return func(r *MLGetCalendarsRequest) { + r.Body = v + } +} + +// WithCalendarID - the ID of the calendar to fetch. +// +func (f MLGetCalendars) WithCalendarID(v string) func(*MLGetCalendarsRequest) { + return func(r *MLGetCalendarsRequest) { + r.CalendarID = v + } +} + +// WithFrom - skips a number of calendars. +// +func (f MLGetCalendars) WithFrom(v int) func(*MLGetCalendarsRequest) { + return func(r *MLGetCalendarsRequest) { + r.From = &v + } +} + +// WithSize - specifies a max number of calendars to get. +// +func (f MLGetCalendars) WithSize(v int) func(*MLGetCalendarsRequest) { + return func(r *MLGetCalendarsRequest) { + r.Size = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLGetCalendars) WithPretty() func(*MLGetCalendarsRequest) { + return func(r *MLGetCalendarsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLGetCalendars) WithHuman() func(*MLGetCalendarsRequest) { + return func(r *MLGetCalendarsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLGetCalendars) WithErrorTrace() func(*MLGetCalendarsRequest) { + return func(r *MLGetCalendarsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLGetCalendars) WithFilterPath(v ...string) func(*MLGetCalendarsRequest) { + return func(r *MLGetCalendarsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLGetCalendars) WithHeader(h map[string]string) func(*MLGetCalendarsRequest) { + return func(r *MLGetCalendarsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLGetCalendars) WithOpaqueID(s string) func(*MLGetCalendarsRequest) { + return func(r *MLGetCalendarsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_categories.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_categories.go new file mode 100644 index 00000000000..bcf521c28e8 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_categories.go @@ -0,0 +1,252 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newMLGetCategoriesFunc(t Transport) MLGetCategories { + return func(job_id string, o ...func(*MLGetCategoriesRequest)) (*Response, error) { + var r = MLGetCategoriesRequest{JobID: job_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLGetCategories - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-category.html. +// +type MLGetCategories func(job_id string, o ...func(*MLGetCategoriesRequest)) (*Response, error) + +// MLGetCategoriesRequest configures the ML Get Categories API request. +// +type MLGetCategoriesRequest struct { + Body io.Reader + + CategoryID *int + JobID string + + From *int + Size *int + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLGetCategoriesRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_ml") + 1 + len("anomaly_detectors") + 1 + len(r.JobID) + 1 + len("results") + 1 + len("categories")) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("anomaly_detectors") + path.WriteString("/") + path.WriteString(r.JobID) + path.WriteString("/") + path.WriteString("results") + path.WriteString("/") + path.WriteString("categories") + if r.CategoryID != nil { + value := strconv.FormatInt(int64(*r.CategoryID), 10) + path.Grow(1 + len(value)) + path.WriteString("/") + path.WriteString(value) + } + + params = make(map[string]string) + + if r.From != nil { + params["from"] = strconv.FormatInt(int64(*r.From), 10) + } + + if r.Size != nil { + params["size"] = strconv.FormatInt(int64(*r.Size), 10) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLGetCategories) WithContext(v context.Context) func(*MLGetCategoriesRequest) { + return func(r *MLGetCategoriesRequest) { + r.ctx = v + } +} + +// WithBody - Category selection details if not provided in URI. +// +func (f MLGetCategories) WithBody(v io.Reader) func(*MLGetCategoriesRequest) { + return func(r *MLGetCategoriesRequest) { + r.Body = v + } +} + +// WithCategoryID - the identifier of the category definition of interest. +// +func (f MLGetCategories) WithCategoryID(v int) func(*MLGetCategoriesRequest) { + return func(r *MLGetCategoriesRequest) { + r.CategoryID = &v + } +} + +// WithFrom - skips a number of categories. +// +func (f MLGetCategories) WithFrom(v int) func(*MLGetCategoriesRequest) { + return func(r *MLGetCategoriesRequest) { + r.From = &v + } +} + +// WithSize - specifies a max number of categories to get. +// +func (f MLGetCategories) WithSize(v int) func(*MLGetCategoriesRequest) { + return func(r *MLGetCategoriesRequest) { + r.Size = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLGetCategories) WithPretty() func(*MLGetCategoriesRequest) { + return func(r *MLGetCategoriesRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLGetCategories) WithHuman() func(*MLGetCategoriesRequest) { + return func(r *MLGetCategoriesRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLGetCategories) WithErrorTrace() func(*MLGetCategoriesRequest) { + return func(r *MLGetCategoriesRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLGetCategories) WithFilterPath(v ...string) func(*MLGetCategoriesRequest) { + return func(r *MLGetCategoriesRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLGetCategories) WithHeader(h map[string]string) func(*MLGetCategoriesRequest) { + return func(r *MLGetCategoriesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLGetCategories) WithOpaqueID(s string) func(*MLGetCategoriesRequest) { + return func(r *MLGetCategoriesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_data_frame_analytics.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_data_frame_analytics.go new file mode 100644 index 00000000000..387f82e516f --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_data_frame_analytics.go @@ -0,0 +1,243 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newMLGetDataFrameAnalyticsFunc(t Transport) MLGetDataFrameAnalytics { + return func(o ...func(*MLGetDataFrameAnalyticsRequest)) (*Response, error) { + var r = MLGetDataFrameAnalyticsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLGetDataFrameAnalytics - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/get-dfanalytics.html. +// +type MLGetDataFrameAnalytics func(o ...func(*MLGetDataFrameAnalyticsRequest)) (*Response, error) + +// MLGetDataFrameAnalyticsRequest configures the ML Get Data Frame Analytics API request. +// +type MLGetDataFrameAnalyticsRequest struct { + ID string + + AllowNoMatch *bool + From *int + Size *int + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLGetDataFrameAnalyticsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_ml") + 1 + len("data_frame") + 1 + len("analytics") + 1 + len(r.ID)) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("data_frame") + path.WriteString("/") + path.WriteString("analytics") + if r.ID != "" { + path.WriteString("/") + path.WriteString(r.ID) + } + + params = make(map[string]string) + + if r.AllowNoMatch != nil { + params["allow_no_match"] = strconv.FormatBool(*r.AllowNoMatch) + } + + if r.From != nil { + params["from"] = strconv.FormatInt(int64(*r.From), 10) + } + + if r.Size != nil { + params["size"] = strconv.FormatInt(int64(*r.Size), 10) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLGetDataFrameAnalytics) WithContext(v context.Context) func(*MLGetDataFrameAnalyticsRequest) { + return func(r *MLGetDataFrameAnalyticsRequest) { + r.ctx = v + } +} + +// WithID - the ID of the data frame analytics to fetch. +// +func (f MLGetDataFrameAnalytics) WithID(v string) func(*MLGetDataFrameAnalyticsRequest) { + return func(r *MLGetDataFrameAnalyticsRequest) { + r.ID = v + } +} + +// WithAllowNoMatch - whether to ignore if a wildcard expression matches no data frame analytics. (this includes `_all` string or when no data frame analytics have been specified). +// +func (f MLGetDataFrameAnalytics) WithAllowNoMatch(v bool) func(*MLGetDataFrameAnalyticsRequest) { + return func(r *MLGetDataFrameAnalyticsRequest) { + r.AllowNoMatch = &v + } +} + +// WithFrom - skips a number of analytics. +// +func (f MLGetDataFrameAnalytics) WithFrom(v int) func(*MLGetDataFrameAnalyticsRequest) { + return func(r *MLGetDataFrameAnalyticsRequest) { + r.From = &v + } +} + +// WithSize - specifies a max number of analytics to get. +// +func (f MLGetDataFrameAnalytics) WithSize(v int) func(*MLGetDataFrameAnalyticsRequest) { + return func(r *MLGetDataFrameAnalyticsRequest) { + r.Size = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLGetDataFrameAnalytics) WithPretty() func(*MLGetDataFrameAnalyticsRequest) { + return func(r *MLGetDataFrameAnalyticsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLGetDataFrameAnalytics) WithHuman() func(*MLGetDataFrameAnalyticsRequest) { + return func(r *MLGetDataFrameAnalyticsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLGetDataFrameAnalytics) WithErrorTrace() func(*MLGetDataFrameAnalyticsRequest) { + return func(r *MLGetDataFrameAnalyticsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLGetDataFrameAnalytics) WithFilterPath(v ...string) func(*MLGetDataFrameAnalyticsRequest) { + return func(r *MLGetDataFrameAnalyticsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLGetDataFrameAnalytics) WithHeader(h map[string]string) func(*MLGetDataFrameAnalyticsRequest) { + return func(r *MLGetDataFrameAnalyticsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLGetDataFrameAnalytics) WithOpaqueID(s string) func(*MLGetDataFrameAnalyticsRequest) { + return func(r *MLGetDataFrameAnalyticsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_data_frame_analytics_stats.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_data_frame_analytics_stats.go new file mode 100644 index 00000000000..25c1301f0f1 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_data_frame_analytics_stats.go @@ -0,0 +1,245 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newMLGetDataFrameAnalyticsStatsFunc(t Transport) MLGetDataFrameAnalyticsStats { + return func(o ...func(*MLGetDataFrameAnalyticsStatsRequest)) (*Response, error) { + var r = MLGetDataFrameAnalyticsStatsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLGetDataFrameAnalyticsStats - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/get-dfanalytics-stats.html. +// +type MLGetDataFrameAnalyticsStats func(o ...func(*MLGetDataFrameAnalyticsStatsRequest)) (*Response, error) + +// MLGetDataFrameAnalyticsStatsRequest configures the ML Get Data Frame Analytics Stats API request. +// +type MLGetDataFrameAnalyticsStatsRequest struct { + ID string + + AllowNoMatch *bool + From *int + Size *int + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLGetDataFrameAnalyticsStatsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_ml") + 1 + len("data_frame") + 1 + len("analytics") + 1 + len(r.ID) + 1 + len("_stats")) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("data_frame") + path.WriteString("/") + path.WriteString("analytics") + if r.ID != "" { + path.WriteString("/") + path.WriteString(r.ID) + } + path.WriteString("/") + path.WriteString("_stats") + + params = make(map[string]string) + + if r.AllowNoMatch != nil { + params["allow_no_match"] = strconv.FormatBool(*r.AllowNoMatch) + } + + if r.From != nil { + params["from"] = strconv.FormatInt(int64(*r.From), 10) + } + + if r.Size != nil { + params["size"] = strconv.FormatInt(int64(*r.Size), 10) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLGetDataFrameAnalyticsStats) WithContext(v context.Context) func(*MLGetDataFrameAnalyticsStatsRequest) { + return func(r *MLGetDataFrameAnalyticsStatsRequest) { + r.ctx = v + } +} + +// WithID - the ID of the data frame analytics stats to fetch. +// +func (f MLGetDataFrameAnalyticsStats) WithID(v string) func(*MLGetDataFrameAnalyticsStatsRequest) { + return func(r *MLGetDataFrameAnalyticsStatsRequest) { + r.ID = v + } +} + +// WithAllowNoMatch - whether to ignore if a wildcard expression matches no data frame analytics. (this includes `_all` string or when no data frame analytics have been specified). +// +func (f MLGetDataFrameAnalyticsStats) WithAllowNoMatch(v bool) func(*MLGetDataFrameAnalyticsStatsRequest) { + return func(r *MLGetDataFrameAnalyticsStatsRequest) { + r.AllowNoMatch = &v + } +} + +// WithFrom - skips a number of analytics. +// +func (f MLGetDataFrameAnalyticsStats) WithFrom(v int) func(*MLGetDataFrameAnalyticsStatsRequest) { + return func(r *MLGetDataFrameAnalyticsStatsRequest) { + r.From = &v + } +} + +// WithSize - specifies a max number of analytics to get. +// +func (f MLGetDataFrameAnalyticsStats) WithSize(v int) func(*MLGetDataFrameAnalyticsStatsRequest) { + return func(r *MLGetDataFrameAnalyticsStatsRequest) { + r.Size = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLGetDataFrameAnalyticsStats) WithPretty() func(*MLGetDataFrameAnalyticsStatsRequest) { + return func(r *MLGetDataFrameAnalyticsStatsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLGetDataFrameAnalyticsStats) WithHuman() func(*MLGetDataFrameAnalyticsStatsRequest) { + return func(r *MLGetDataFrameAnalyticsStatsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLGetDataFrameAnalyticsStats) WithErrorTrace() func(*MLGetDataFrameAnalyticsStatsRequest) { + return func(r *MLGetDataFrameAnalyticsStatsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLGetDataFrameAnalyticsStats) WithFilterPath(v ...string) func(*MLGetDataFrameAnalyticsStatsRequest) { + return func(r *MLGetDataFrameAnalyticsStatsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLGetDataFrameAnalyticsStats) WithHeader(h map[string]string) func(*MLGetDataFrameAnalyticsStatsRequest) { + return func(r *MLGetDataFrameAnalyticsStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLGetDataFrameAnalyticsStats) WithOpaqueID(s string) func(*MLGetDataFrameAnalyticsStatsRequest) { + return func(r *MLGetDataFrameAnalyticsStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_datafeed_stats.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_datafeed_stats.go new file mode 100644 index 00000000000..de0292d4b62 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_datafeed_stats.go @@ -0,0 +1,217 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newMLGetDatafeedStatsFunc(t Transport) MLGetDatafeedStats { + return func(o ...func(*MLGetDatafeedStatsRequest)) (*Response, error) { + var r = MLGetDatafeedStatsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLGetDatafeedStats - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-datafeed-stats.html. +// +type MLGetDatafeedStats func(o ...func(*MLGetDatafeedStatsRequest)) (*Response, error) + +// MLGetDatafeedStatsRequest configures the ML Get Datafeed Stats API request. +// +type MLGetDatafeedStatsRequest struct { + DatafeedID string + + AllowNoDatafeeds *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLGetDatafeedStatsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_ml") + 1 + len("datafeeds") + 1 + len(r.DatafeedID) + 1 + len("_stats")) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("datafeeds") + if r.DatafeedID != "" { + path.WriteString("/") + path.WriteString(r.DatafeedID) + } + path.WriteString("/") + path.WriteString("_stats") + + params = make(map[string]string) + + if r.AllowNoDatafeeds != nil { + params["allow_no_datafeeds"] = strconv.FormatBool(*r.AllowNoDatafeeds) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLGetDatafeedStats) WithContext(v context.Context) func(*MLGetDatafeedStatsRequest) { + return func(r *MLGetDatafeedStatsRequest) { + r.ctx = v + } +} + +// WithDatafeedID - the ID of the datafeeds stats to fetch. +// +func (f MLGetDatafeedStats) WithDatafeedID(v string) func(*MLGetDatafeedStatsRequest) { + return func(r *MLGetDatafeedStatsRequest) { + r.DatafeedID = v + } +} + +// WithAllowNoDatafeeds - whether to ignore if a wildcard expression matches no datafeeds. (this includes `_all` string or when no datafeeds have been specified). +// +func (f MLGetDatafeedStats) WithAllowNoDatafeeds(v bool) func(*MLGetDatafeedStatsRequest) { + return func(r *MLGetDatafeedStatsRequest) { + r.AllowNoDatafeeds = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLGetDatafeedStats) WithPretty() func(*MLGetDatafeedStatsRequest) { + return func(r *MLGetDatafeedStatsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLGetDatafeedStats) WithHuman() func(*MLGetDatafeedStatsRequest) { + return func(r *MLGetDatafeedStatsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLGetDatafeedStats) WithErrorTrace() func(*MLGetDatafeedStatsRequest) { + return func(r *MLGetDatafeedStatsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLGetDatafeedStats) WithFilterPath(v ...string) func(*MLGetDatafeedStatsRequest) { + return func(r *MLGetDatafeedStatsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLGetDatafeedStats) WithHeader(h map[string]string) func(*MLGetDatafeedStatsRequest) { + return func(r *MLGetDatafeedStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLGetDatafeedStats) WithOpaqueID(s string) func(*MLGetDatafeedStatsRequest) { + return func(r *MLGetDatafeedStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_datafeeds.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_datafeeds.go new file mode 100644 index 00000000000..ba3946d87f9 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_datafeeds.go @@ -0,0 +1,215 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newMLGetDatafeedsFunc(t Transport) MLGetDatafeeds { + return func(o ...func(*MLGetDatafeedsRequest)) (*Response, error) { + var r = MLGetDatafeedsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLGetDatafeeds - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-datafeed.html. +// +type MLGetDatafeeds func(o ...func(*MLGetDatafeedsRequest)) (*Response, error) + +// MLGetDatafeedsRequest configures the ML Get Datafeeds API request. +// +type MLGetDatafeedsRequest struct { + DatafeedID string + + AllowNoDatafeeds *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLGetDatafeedsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_ml") + 1 + len("datafeeds") + 1 + len(r.DatafeedID)) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("datafeeds") + if r.DatafeedID != "" { + path.WriteString("/") + path.WriteString(r.DatafeedID) + } + + params = make(map[string]string) + + if r.AllowNoDatafeeds != nil { + params["allow_no_datafeeds"] = strconv.FormatBool(*r.AllowNoDatafeeds) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLGetDatafeeds) WithContext(v context.Context) func(*MLGetDatafeedsRequest) { + return func(r *MLGetDatafeedsRequest) { + r.ctx = v + } +} + +// WithDatafeedID - the ID of the datafeeds to fetch. +// +func (f MLGetDatafeeds) WithDatafeedID(v string) func(*MLGetDatafeedsRequest) { + return func(r *MLGetDatafeedsRequest) { + r.DatafeedID = v + } +} + +// WithAllowNoDatafeeds - whether to ignore if a wildcard expression matches no datafeeds. (this includes `_all` string or when no datafeeds have been specified). +// +func (f MLGetDatafeeds) WithAllowNoDatafeeds(v bool) func(*MLGetDatafeedsRequest) { + return func(r *MLGetDatafeedsRequest) { + r.AllowNoDatafeeds = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLGetDatafeeds) WithPretty() func(*MLGetDatafeedsRequest) { + return func(r *MLGetDatafeedsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLGetDatafeeds) WithHuman() func(*MLGetDatafeedsRequest) { + return func(r *MLGetDatafeedsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLGetDatafeeds) WithErrorTrace() func(*MLGetDatafeedsRequest) { + return func(r *MLGetDatafeedsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLGetDatafeeds) WithFilterPath(v ...string) func(*MLGetDatafeedsRequest) { + return func(r *MLGetDatafeedsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLGetDatafeeds) WithHeader(h map[string]string) func(*MLGetDatafeedsRequest) { + return func(r *MLGetDatafeedsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLGetDatafeeds) WithOpaqueID(s string) func(*MLGetDatafeedsRequest) { + return func(r *MLGetDatafeedsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_filters.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_filters.go new file mode 100644 index 00000000000..4935f1c80a4 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_filters.go @@ -0,0 +1,226 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newMLGetFiltersFunc(t Transport) MLGetFilters { + return func(o ...func(*MLGetFiltersRequest)) (*Response, error) { + var r = MLGetFiltersRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLGetFilters - +// +type MLGetFilters func(o ...func(*MLGetFiltersRequest)) (*Response, error) + +// MLGetFiltersRequest configures the ML Get Filters API request. +// +type MLGetFiltersRequest struct { + FilterID string + + From *int + Size *int + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLGetFiltersRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_ml") + 1 + len("filters") + 1 + len(r.FilterID)) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("filters") + if r.FilterID != "" { + path.WriteString("/") + path.WriteString(r.FilterID) + } + + params = make(map[string]string) + + if r.From != nil { + params["from"] = strconv.FormatInt(int64(*r.From), 10) + } + + if r.Size != nil { + params["size"] = strconv.FormatInt(int64(*r.Size), 10) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLGetFilters) WithContext(v context.Context) func(*MLGetFiltersRequest) { + return func(r *MLGetFiltersRequest) { + r.ctx = v + } +} + +// WithFilterID - the ID of the filter to fetch. +// +func (f MLGetFilters) WithFilterID(v string) func(*MLGetFiltersRequest) { + return func(r *MLGetFiltersRequest) { + r.FilterID = v + } +} + +// WithFrom - skips a number of filters. +// +func (f MLGetFilters) WithFrom(v int) func(*MLGetFiltersRequest) { + return func(r *MLGetFiltersRequest) { + r.From = &v + } +} + +// WithSize - specifies a max number of filters to get. +// +func (f MLGetFilters) WithSize(v int) func(*MLGetFiltersRequest) { + return func(r *MLGetFiltersRequest) { + r.Size = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLGetFilters) WithPretty() func(*MLGetFiltersRequest) { + return func(r *MLGetFiltersRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLGetFilters) WithHuman() func(*MLGetFiltersRequest) { + return func(r *MLGetFiltersRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLGetFilters) WithErrorTrace() func(*MLGetFiltersRequest) { + return func(r *MLGetFiltersRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLGetFilters) WithFilterPath(v ...string) func(*MLGetFiltersRequest) { + return func(r *MLGetFiltersRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLGetFilters) WithHeader(h map[string]string) func(*MLGetFiltersRequest) { + return func(r *MLGetFiltersRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLGetFilters) WithOpaqueID(s string) func(*MLGetFiltersRequest) { + return func(r *MLGetFiltersRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_influencers.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_influencers.go new file mode 100644 index 00000000000..4c0f2a66eaa --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_influencers.go @@ -0,0 +1,316 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "fmt" + "io" + "net/http" + "strconv" + "strings" +) + +func newMLGetInfluencersFunc(t Transport) MLGetInfluencers { + return func(job_id string, o ...func(*MLGetInfluencersRequest)) (*Response, error) { + var r = MLGetInfluencersRequest{JobID: job_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLGetInfluencers - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-influencer.html. +// +type MLGetInfluencers func(job_id string, o ...func(*MLGetInfluencersRequest)) (*Response, error) + +// MLGetInfluencersRequest configures the ML Get Influencers API request. +// +type MLGetInfluencersRequest struct { + Body io.Reader + + JobID string + + Desc *bool + End string + ExcludeInterim *bool + From *int + InfluencerScore interface{} + Size *int + Sort string + Start string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLGetInfluencersRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_ml") + 1 + len("anomaly_detectors") + 1 + len(r.JobID) + 1 + len("results") + 1 + len("influencers")) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("anomaly_detectors") + path.WriteString("/") + path.WriteString(r.JobID) + path.WriteString("/") + path.WriteString("results") + path.WriteString("/") + path.WriteString("influencers") + + params = make(map[string]string) + + if r.Desc != nil { + params["desc"] = strconv.FormatBool(*r.Desc) + } + + if r.End != "" { + params["end"] = r.End + } + + if r.ExcludeInterim != nil { + params["exclude_interim"] = strconv.FormatBool(*r.ExcludeInterim) + } + + if r.From != nil { + params["from"] = strconv.FormatInt(int64(*r.From), 10) + } + + if r.InfluencerScore != nil { + params["influencer_score"] = fmt.Sprintf("%v", r.InfluencerScore) + } + + if r.Size != nil { + params["size"] = strconv.FormatInt(int64(*r.Size), 10) + } + + if r.Sort != "" { + params["sort"] = r.Sort + } + + if r.Start != "" { + params["start"] = r.Start + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLGetInfluencers) WithContext(v context.Context) func(*MLGetInfluencersRequest) { + return func(r *MLGetInfluencersRequest) { + r.ctx = v + } +} + +// WithBody - Influencer selection criteria. +// +func (f MLGetInfluencers) WithBody(v io.Reader) func(*MLGetInfluencersRequest) { + return func(r *MLGetInfluencersRequest) { + r.Body = v + } +} + +// WithDesc - whether the results should be sorted in decending order. +// +func (f MLGetInfluencers) WithDesc(v bool) func(*MLGetInfluencersRequest) { + return func(r *MLGetInfluencersRequest) { + r.Desc = &v + } +} + +// WithEnd - end timestamp for the requested influencers. +// +func (f MLGetInfluencers) WithEnd(v string) func(*MLGetInfluencersRequest) { + return func(r *MLGetInfluencersRequest) { + r.End = v + } +} + +// WithExcludeInterim - exclude interim results. +// +func (f MLGetInfluencers) WithExcludeInterim(v bool) func(*MLGetInfluencersRequest) { + return func(r *MLGetInfluencersRequest) { + r.ExcludeInterim = &v + } +} + +// WithFrom - skips a number of influencers. +// +func (f MLGetInfluencers) WithFrom(v int) func(*MLGetInfluencersRequest) { + return func(r *MLGetInfluencersRequest) { + r.From = &v + } +} + +// WithInfluencerScore - influencer score threshold for the requested influencers. +// +func (f MLGetInfluencers) WithInfluencerScore(v interface{}) func(*MLGetInfluencersRequest) { + return func(r *MLGetInfluencersRequest) { + r.InfluencerScore = v + } +} + +// WithSize - specifies a max number of influencers to get. +// +func (f MLGetInfluencers) WithSize(v int) func(*MLGetInfluencersRequest) { + return func(r *MLGetInfluencersRequest) { + r.Size = &v + } +} + +// WithSort - sort field for the requested influencers. +// +func (f MLGetInfluencers) WithSort(v string) func(*MLGetInfluencersRequest) { + return func(r *MLGetInfluencersRequest) { + r.Sort = v + } +} + +// WithStart - start timestamp for the requested influencers. +// +func (f MLGetInfluencers) WithStart(v string) func(*MLGetInfluencersRequest) { + return func(r *MLGetInfluencersRequest) { + r.Start = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLGetInfluencers) WithPretty() func(*MLGetInfluencersRequest) { + return func(r *MLGetInfluencersRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLGetInfluencers) WithHuman() func(*MLGetInfluencersRequest) { + return func(r *MLGetInfluencersRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLGetInfluencers) WithErrorTrace() func(*MLGetInfluencersRequest) { + return func(r *MLGetInfluencersRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLGetInfluencers) WithFilterPath(v ...string) func(*MLGetInfluencersRequest) { + return func(r *MLGetInfluencersRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLGetInfluencers) WithHeader(h map[string]string) func(*MLGetInfluencersRequest) { + return func(r *MLGetInfluencersRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLGetInfluencers) WithOpaqueID(s string) func(*MLGetInfluencersRequest) { + return func(r *MLGetInfluencersRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_job_stats.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_job_stats.go new file mode 100644 index 00000000000..469b73261c1 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_job_stats.go @@ -0,0 +1,217 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newMLGetJobStatsFunc(t Transport) MLGetJobStats { + return func(o ...func(*MLGetJobStatsRequest)) (*Response, error) { + var r = MLGetJobStatsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLGetJobStats - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-job-stats.html. +// +type MLGetJobStats func(o ...func(*MLGetJobStatsRequest)) (*Response, error) + +// MLGetJobStatsRequest configures the ML Get Job Stats API request. +// +type MLGetJobStatsRequest struct { + JobID string + + AllowNoJobs *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLGetJobStatsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_ml") + 1 + len("anomaly_detectors") + 1 + len(r.JobID) + 1 + len("_stats")) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("anomaly_detectors") + if r.JobID != "" { + path.WriteString("/") + path.WriteString(r.JobID) + } + path.WriteString("/") + path.WriteString("_stats") + + params = make(map[string]string) + + if r.AllowNoJobs != nil { + params["allow_no_jobs"] = strconv.FormatBool(*r.AllowNoJobs) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLGetJobStats) WithContext(v context.Context) func(*MLGetJobStatsRequest) { + return func(r *MLGetJobStatsRequest) { + r.ctx = v + } +} + +// WithJobID - the ID of the jobs stats to fetch. +// +func (f MLGetJobStats) WithJobID(v string) func(*MLGetJobStatsRequest) { + return func(r *MLGetJobStatsRequest) { + r.JobID = v + } +} + +// WithAllowNoJobs - whether to ignore if a wildcard expression matches no jobs. (this includes `_all` string or when no jobs have been specified). +// +func (f MLGetJobStats) WithAllowNoJobs(v bool) func(*MLGetJobStatsRequest) { + return func(r *MLGetJobStatsRequest) { + r.AllowNoJobs = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLGetJobStats) WithPretty() func(*MLGetJobStatsRequest) { + return func(r *MLGetJobStatsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLGetJobStats) WithHuman() func(*MLGetJobStatsRequest) { + return func(r *MLGetJobStatsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLGetJobStats) WithErrorTrace() func(*MLGetJobStatsRequest) { + return func(r *MLGetJobStatsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLGetJobStats) WithFilterPath(v ...string) func(*MLGetJobStatsRequest) { + return func(r *MLGetJobStatsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLGetJobStats) WithHeader(h map[string]string) func(*MLGetJobStatsRequest) { + return func(r *MLGetJobStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLGetJobStats) WithOpaqueID(s string) func(*MLGetJobStatsRequest) { + return func(r *MLGetJobStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_jobs.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_jobs.go new file mode 100644 index 00000000000..49f1172cb98 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_jobs.go @@ -0,0 +1,215 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newMLGetJobsFunc(t Transport) MLGetJobs { + return func(o ...func(*MLGetJobsRequest)) (*Response, error) { + var r = MLGetJobsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLGetJobs - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-job.html. +// +type MLGetJobs func(o ...func(*MLGetJobsRequest)) (*Response, error) + +// MLGetJobsRequest configures the ML Get Jobs API request. +// +type MLGetJobsRequest struct { + JobID string + + AllowNoJobs *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLGetJobsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_ml") + 1 + len("anomaly_detectors") + 1 + len(r.JobID)) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("anomaly_detectors") + if r.JobID != "" { + path.WriteString("/") + path.WriteString(r.JobID) + } + + params = make(map[string]string) + + if r.AllowNoJobs != nil { + params["allow_no_jobs"] = strconv.FormatBool(*r.AllowNoJobs) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLGetJobs) WithContext(v context.Context) func(*MLGetJobsRequest) { + return func(r *MLGetJobsRequest) { + r.ctx = v + } +} + +// WithJobID - the ID of the jobs to fetch. +// +func (f MLGetJobs) WithJobID(v string) func(*MLGetJobsRequest) { + return func(r *MLGetJobsRequest) { + r.JobID = v + } +} + +// WithAllowNoJobs - whether to ignore if a wildcard expression matches no jobs. (this includes `_all` string or when no jobs have been specified). +// +func (f MLGetJobs) WithAllowNoJobs(v bool) func(*MLGetJobsRequest) { + return func(r *MLGetJobsRequest) { + r.AllowNoJobs = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLGetJobs) WithPretty() func(*MLGetJobsRequest) { + return func(r *MLGetJobsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLGetJobs) WithHuman() func(*MLGetJobsRequest) { + return func(r *MLGetJobsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLGetJobs) WithErrorTrace() func(*MLGetJobsRequest) { + return func(r *MLGetJobsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLGetJobs) WithFilterPath(v ...string) func(*MLGetJobsRequest) { + return func(r *MLGetJobsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLGetJobs) WithHeader(h map[string]string) func(*MLGetJobsRequest) { + return func(r *MLGetJobsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLGetJobs) WithOpaqueID(s string) func(*MLGetJobsRequest) { + return func(r *MLGetJobsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_model_snapshots.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_model_snapshots.go new file mode 100644 index 00000000000..f362efbff9e --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_model_snapshots.go @@ -0,0 +1,301 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "fmt" + "io" + "net/http" + "strconv" + "strings" +) + +func newMLGetModelSnapshotsFunc(t Transport) MLGetModelSnapshots { + return func(job_id string, o ...func(*MLGetModelSnapshotsRequest)) (*Response, error) { + var r = MLGetModelSnapshotsRequest{JobID: job_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLGetModelSnapshots - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-snapshot.html. +// +type MLGetModelSnapshots func(job_id string, o ...func(*MLGetModelSnapshotsRequest)) (*Response, error) + +// MLGetModelSnapshotsRequest configures the ML Get Model Snapshots API request. +// +type MLGetModelSnapshotsRequest struct { + Body io.Reader + + JobID string + SnapshotID string + + Desc *bool + End interface{} + From *int + Size *int + Sort string + Start interface{} + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLGetModelSnapshotsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_ml") + 1 + len("anomaly_detectors") + 1 + len(r.JobID) + 1 + len("model_snapshots") + 1 + len(r.SnapshotID)) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("anomaly_detectors") + path.WriteString("/") + path.WriteString(r.JobID) + path.WriteString("/") + path.WriteString("model_snapshots") + if r.SnapshotID != "" { + path.WriteString("/") + path.WriteString(r.SnapshotID) + } + + params = make(map[string]string) + + if r.Desc != nil { + params["desc"] = strconv.FormatBool(*r.Desc) + } + + if r.End != nil { + params["end"] = fmt.Sprintf("%v", r.End) + } + + if r.From != nil { + params["from"] = strconv.FormatInt(int64(*r.From), 10) + } + + if r.Size != nil { + params["size"] = strconv.FormatInt(int64(*r.Size), 10) + } + + if r.Sort != "" { + params["sort"] = r.Sort + } + + if r.Start != nil { + params["start"] = fmt.Sprintf("%v", r.Start) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLGetModelSnapshots) WithContext(v context.Context) func(*MLGetModelSnapshotsRequest) { + return func(r *MLGetModelSnapshotsRequest) { + r.ctx = v + } +} + +// WithBody - Model snapshot selection criteria. +// +func (f MLGetModelSnapshots) WithBody(v io.Reader) func(*MLGetModelSnapshotsRequest) { + return func(r *MLGetModelSnapshotsRequest) { + r.Body = v + } +} + +// WithSnapshotID - the ID of the snapshot to fetch. +// +func (f MLGetModelSnapshots) WithSnapshotID(v string) func(*MLGetModelSnapshotsRequest) { + return func(r *MLGetModelSnapshotsRequest) { + r.SnapshotID = v + } +} + +// WithDesc - true if the results should be sorted in descending order. +// +func (f MLGetModelSnapshots) WithDesc(v bool) func(*MLGetModelSnapshotsRequest) { + return func(r *MLGetModelSnapshotsRequest) { + r.Desc = &v + } +} + +// WithEnd - the filter 'end' query parameter. +// +func (f MLGetModelSnapshots) WithEnd(v interface{}) func(*MLGetModelSnapshotsRequest) { + return func(r *MLGetModelSnapshotsRequest) { + r.End = v + } +} + +// WithFrom - skips a number of documents. +// +func (f MLGetModelSnapshots) WithFrom(v int) func(*MLGetModelSnapshotsRequest) { + return func(r *MLGetModelSnapshotsRequest) { + r.From = &v + } +} + +// WithSize - the default number of documents returned in queries as a string.. +// +func (f MLGetModelSnapshots) WithSize(v int) func(*MLGetModelSnapshotsRequest) { + return func(r *MLGetModelSnapshotsRequest) { + r.Size = &v + } +} + +// WithSort - name of the field to sort on. +// +func (f MLGetModelSnapshots) WithSort(v string) func(*MLGetModelSnapshotsRequest) { + return func(r *MLGetModelSnapshotsRequest) { + r.Sort = v + } +} + +// WithStart - the filter 'start' query parameter. +// +func (f MLGetModelSnapshots) WithStart(v interface{}) func(*MLGetModelSnapshotsRequest) { + return func(r *MLGetModelSnapshotsRequest) { + r.Start = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLGetModelSnapshots) WithPretty() func(*MLGetModelSnapshotsRequest) { + return func(r *MLGetModelSnapshotsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLGetModelSnapshots) WithHuman() func(*MLGetModelSnapshotsRequest) { + return func(r *MLGetModelSnapshotsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLGetModelSnapshots) WithErrorTrace() func(*MLGetModelSnapshotsRequest) { + return func(r *MLGetModelSnapshotsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLGetModelSnapshots) WithFilterPath(v ...string) func(*MLGetModelSnapshotsRequest) { + return func(r *MLGetModelSnapshotsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLGetModelSnapshots) WithHeader(h map[string]string) func(*MLGetModelSnapshotsRequest) { + return func(r *MLGetModelSnapshotsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLGetModelSnapshots) WithOpaqueID(s string) func(*MLGetModelSnapshotsRequest) { + return func(r *MLGetModelSnapshotsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_overall_buckets.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_overall_buckets.go new file mode 100644 index 00000000000..91a5a7a52ab --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_overall_buckets.go @@ -0,0 +1,303 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "fmt" + "io" + "net/http" + "strconv" + "strings" +) + +func newMLGetOverallBucketsFunc(t Transport) MLGetOverallBuckets { + return func(job_id string, o ...func(*MLGetOverallBucketsRequest)) (*Response, error) { + var r = MLGetOverallBucketsRequest{JobID: job_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLGetOverallBuckets - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-overall-buckets.html. +// +type MLGetOverallBuckets func(job_id string, o ...func(*MLGetOverallBucketsRequest)) (*Response, error) + +// MLGetOverallBucketsRequest configures the ML Get Overall Buckets API request. +// +type MLGetOverallBucketsRequest struct { + Body io.Reader + + JobID string + + AllowNoJobs *bool + BucketSpan string + End string + ExcludeInterim *bool + OverallScore interface{} + Start string + TopN *int + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLGetOverallBucketsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_ml") + 1 + len("anomaly_detectors") + 1 + len(r.JobID) + 1 + len("results") + 1 + len("overall_buckets")) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("anomaly_detectors") + path.WriteString("/") + path.WriteString(r.JobID) + path.WriteString("/") + path.WriteString("results") + path.WriteString("/") + path.WriteString("overall_buckets") + + params = make(map[string]string) + + if r.AllowNoJobs != nil { + params["allow_no_jobs"] = strconv.FormatBool(*r.AllowNoJobs) + } + + if r.BucketSpan != "" { + params["bucket_span"] = r.BucketSpan + } + + if r.End != "" { + params["end"] = r.End + } + + if r.ExcludeInterim != nil { + params["exclude_interim"] = strconv.FormatBool(*r.ExcludeInterim) + } + + if r.OverallScore != nil { + params["overall_score"] = fmt.Sprintf("%v", r.OverallScore) + } + + if r.Start != "" { + params["start"] = r.Start + } + + if r.TopN != nil { + params["top_n"] = strconv.FormatInt(int64(*r.TopN), 10) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLGetOverallBuckets) WithContext(v context.Context) func(*MLGetOverallBucketsRequest) { + return func(r *MLGetOverallBucketsRequest) { + r.ctx = v + } +} + +// WithBody - Overall bucket selection details if not provided in URI. +// +func (f MLGetOverallBuckets) WithBody(v io.Reader) func(*MLGetOverallBucketsRequest) { + return func(r *MLGetOverallBucketsRequest) { + r.Body = v + } +} + +// WithAllowNoJobs - whether to ignore if a wildcard expression matches no jobs. (this includes `_all` string or when no jobs have been specified). +// +func (f MLGetOverallBuckets) WithAllowNoJobs(v bool) func(*MLGetOverallBucketsRequest) { + return func(r *MLGetOverallBucketsRequest) { + r.AllowNoJobs = &v + } +} + +// WithBucketSpan - the span of the overall buckets. defaults to the longest job bucket_span. +// +func (f MLGetOverallBuckets) WithBucketSpan(v string) func(*MLGetOverallBucketsRequest) { + return func(r *MLGetOverallBucketsRequest) { + r.BucketSpan = v + } +} + +// WithEnd - returns overall buckets with timestamps earlier than this time. +// +func (f MLGetOverallBuckets) WithEnd(v string) func(*MLGetOverallBucketsRequest) { + return func(r *MLGetOverallBucketsRequest) { + r.End = v + } +} + +// WithExcludeInterim - if true overall buckets that include interim buckets will be excluded. +// +func (f MLGetOverallBuckets) WithExcludeInterim(v bool) func(*MLGetOverallBucketsRequest) { + return func(r *MLGetOverallBucketsRequest) { + r.ExcludeInterim = &v + } +} + +// WithOverallScore - returns overall buckets with overall scores higher than this value. +// +func (f MLGetOverallBuckets) WithOverallScore(v interface{}) func(*MLGetOverallBucketsRequest) { + return func(r *MLGetOverallBucketsRequest) { + r.OverallScore = v + } +} + +// WithStart - returns overall buckets with timestamps after this time. +// +func (f MLGetOverallBuckets) WithStart(v string) func(*MLGetOverallBucketsRequest) { + return func(r *MLGetOverallBucketsRequest) { + r.Start = v + } +} + +// WithTopN - the number of top job bucket scores to be used in the overall_score calculation. +// +func (f MLGetOverallBuckets) WithTopN(v int) func(*MLGetOverallBucketsRequest) { + return func(r *MLGetOverallBucketsRequest) { + r.TopN = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLGetOverallBuckets) WithPretty() func(*MLGetOverallBucketsRequest) { + return func(r *MLGetOverallBucketsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLGetOverallBuckets) WithHuman() func(*MLGetOverallBucketsRequest) { + return func(r *MLGetOverallBucketsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLGetOverallBuckets) WithErrorTrace() func(*MLGetOverallBucketsRequest) { + return func(r *MLGetOverallBucketsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLGetOverallBuckets) WithFilterPath(v ...string) func(*MLGetOverallBucketsRequest) { + return func(r *MLGetOverallBucketsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLGetOverallBuckets) WithHeader(h map[string]string) func(*MLGetOverallBucketsRequest) { + return func(r *MLGetOverallBucketsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLGetOverallBuckets) WithOpaqueID(s string) func(*MLGetOverallBucketsRequest) { + return func(r *MLGetOverallBucketsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_records.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_records.go new file mode 100644 index 00000000000..73f327445e6 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.get_records.go @@ -0,0 +1,316 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "fmt" + "io" + "net/http" + "strconv" + "strings" +) + +func newMLGetRecordsFunc(t Transport) MLGetRecords { + return func(job_id string, o ...func(*MLGetRecordsRequest)) (*Response, error) { + var r = MLGetRecordsRequest{JobID: job_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLGetRecords - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-record.html. +// +type MLGetRecords func(job_id string, o ...func(*MLGetRecordsRequest)) (*Response, error) + +// MLGetRecordsRequest configures the ML Get Records API request. +// +type MLGetRecordsRequest struct { + Body io.Reader + + JobID string + + Desc *bool + End string + ExcludeInterim *bool + From *int + RecordScore interface{} + Size *int + Sort string + Start string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLGetRecordsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_ml") + 1 + len("anomaly_detectors") + 1 + len(r.JobID) + 1 + len("results") + 1 + len("records")) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("anomaly_detectors") + path.WriteString("/") + path.WriteString(r.JobID) + path.WriteString("/") + path.WriteString("results") + path.WriteString("/") + path.WriteString("records") + + params = make(map[string]string) + + if r.Desc != nil { + params["desc"] = strconv.FormatBool(*r.Desc) + } + + if r.End != "" { + params["end"] = r.End + } + + if r.ExcludeInterim != nil { + params["exclude_interim"] = strconv.FormatBool(*r.ExcludeInterim) + } + + if r.From != nil { + params["from"] = strconv.FormatInt(int64(*r.From), 10) + } + + if r.RecordScore != nil { + params["record_score"] = fmt.Sprintf("%v", r.RecordScore) + } + + if r.Size != nil { + params["size"] = strconv.FormatInt(int64(*r.Size), 10) + } + + if r.Sort != "" { + params["sort"] = r.Sort + } + + if r.Start != "" { + params["start"] = r.Start + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLGetRecords) WithContext(v context.Context) func(*MLGetRecordsRequest) { + return func(r *MLGetRecordsRequest) { + r.ctx = v + } +} + +// WithBody - Record selection criteria. +// +func (f MLGetRecords) WithBody(v io.Reader) func(*MLGetRecordsRequest) { + return func(r *MLGetRecordsRequest) { + r.Body = v + } +} + +// WithDesc - set the sort direction. +// +func (f MLGetRecords) WithDesc(v bool) func(*MLGetRecordsRequest) { + return func(r *MLGetRecordsRequest) { + r.Desc = &v + } +} + +// WithEnd - end time filter for records. +// +func (f MLGetRecords) WithEnd(v string) func(*MLGetRecordsRequest) { + return func(r *MLGetRecordsRequest) { + r.End = v + } +} + +// WithExcludeInterim - exclude interim results. +// +func (f MLGetRecords) WithExcludeInterim(v bool) func(*MLGetRecordsRequest) { + return func(r *MLGetRecordsRequest) { + r.ExcludeInterim = &v + } +} + +// WithFrom - skips a number of records. +// +func (f MLGetRecords) WithFrom(v int) func(*MLGetRecordsRequest) { + return func(r *MLGetRecordsRequest) { + r.From = &v + } +} + +// WithRecordScore - . +// +func (f MLGetRecords) WithRecordScore(v interface{}) func(*MLGetRecordsRequest) { + return func(r *MLGetRecordsRequest) { + r.RecordScore = v + } +} + +// WithSize - specifies a max number of records to get. +// +func (f MLGetRecords) WithSize(v int) func(*MLGetRecordsRequest) { + return func(r *MLGetRecordsRequest) { + r.Size = &v + } +} + +// WithSort - sort records by a particular field. +// +func (f MLGetRecords) WithSort(v string) func(*MLGetRecordsRequest) { + return func(r *MLGetRecordsRequest) { + r.Sort = v + } +} + +// WithStart - start time filter for records. +// +func (f MLGetRecords) WithStart(v string) func(*MLGetRecordsRequest) { + return func(r *MLGetRecordsRequest) { + r.Start = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLGetRecords) WithPretty() func(*MLGetRecordsRequest) { + return func(r *MLGetRecordsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLGetRecords) WithHuman() func(*MLGetRecordsRequest) { + return func(r *MLGetRecordsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLGetRecords) WithErrorTrace() func(*MLGetRecordsRequest) { + return func(r *MLGetRecordsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLGetRecords) WithFilterPath(v ...string) func(*MLGetRecordsRequest) { + return func(r *MLGetRecordsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLGetRecords) WithHeader(h map[string]string) func(*MLGetRecordsRequest) { + return func(r *MLGetRecordsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLGetRecords) WithOpaqueID(s string) func(*MLGetRecordsRequest) { + return func(r *MLGetRecordsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.info.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.info.go new file mode 100644 index 00000000000..0c9de050bea --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.info.go @@ -0,0 +1,181 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newMLInfoFunc(t Transport) MLInfo { + return func(o ...func(*MLInfoRequest)) (*Response, error) { + var r = MLInfoRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLInfo - +// +type MLInfo func(o ...func(*MLInfoRequest)) (*Response, error) + +// MLInfoRequest configures the ML Info API request. +// +type MLInfoRequest struct { + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLInfoRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_ml/info")) + path.WriteString("/_ml/info") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLInfo) WithContext(v context.Context) func(*MLInfoRequest) { + return func(r *MLInfoRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLInfo) WithPretty() func(*MLInfoRequest) { + return func(r *MLInfoRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLInfo) WithHuman() func(*MLInfoRequest) { + return func(r *MLInfoRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLInfo) WithErrorTrace() func(*MLInfoRequest) { + return func(r *MLInfoRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLInfo) WithFilterPath(v ...string) func(*MLInfoRequest) { + return func(r *MLInfoRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLInfo) WithHeader(h map[string]string) func(*MLInfoRequest) { + return func(r *MLInfoRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLInfo) WithOpaqueID(s string) func(*MLInfoRequest) { + return func(r *MLInfoRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.open_job.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.open_job.go new file mode 100644 index 00000000000..37a74928bc8 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.open_job.go @@ -0,0 +1,192 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newMLOpenJobFunc(t Transport) MLOpenJob { + return func(job_id string, o ...func(*MLOpenJobRequest)) (*Response, error) { + var r = MLOpenJobRequest{JobID: job_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLOpenJob - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-open-job.html. +// +type MLOpenJob func(job_id string, o ...func(*MLOpenJobRequest)) (*Response, error) + +// MLOpenJobRequest configures the ML Open Job API request. +// +type MLOpenJobRequest struct { + JobID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLOpenJobRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_ml") + 1 + len("anomaly_detectors") + 1 + len(r.JobID) + 1 + len("_open")) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("anomaly_detectors") + path.WriteString("/") + path.WriteString(r.JobID) + path.WriteString("/") + path.WriteString("_open") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLOpenJob) WithContext(v context.Context) func(*MLOpenJobRequest) { + return func(r *MLOpenJobRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLOpenJob) WithPretty() func(*MLOpenJobRequest) { + return func(r *MLOpenJobRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLOpenJob) WithHuman() func(*MLOpenJobRequest) { + return func(r *MLOpenJobRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLOpenJob) WithErrorTrace() func(*MLOpenJobRequest) { + return func(r *MLOpenJobRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLOpenJob) WithFilterPath(v ...string) func(*MLOpenJobRequest) { + return func(r *MLOpenJobRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLOpenJob) WithHeader(h map[string]string) func(*MLOpenJobRequest) { + return func(r *MLOpenJobRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLOpenJob) WithOpaqueID(s string) func(*MLOpenJobRequest) { + return func(r *MLOpenJobRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.post_calendar_events.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.post_calendar_events.go new file mode 100644 index 00000000000..37ecc8b568c --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.post_calendar_events.go @@ -0,0 +1,197 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newMLPostCalendarEventsFunc(t Transport) MLPostCalendarEvents { + return func(calendar_id string, body io.Reader, o ...func(*MLPostCalendarEventsRequest)) (*Response, error) { + var r = MLPostCalendarEventsRequest{CalendarID: calendar_id, Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLPostCalendarEvents - +// +type MLPostCalendarEvents func(calendar_id string, body io.Reader, o ...func(*MLPostCalendarEventsRequest)) (*Response, error) + +// MLPostCalendarEventsRequest configures the ML Post Calendar Events API request. +// +type MLPostCalendarEventsRequest struct { + Body io.Reader + + CalendarID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLPostCalendarEventsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_ml") + 1 + len("calendars") + 1 + len(r.CalendarID) + 1 + len("events")) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("calendars") + path.WriteString("/") + path.WriteString(r.CalendarID) + path.WriteString("/") + path.WriteString("events") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLPostCalendarEvents) WithContext(v context.Context) func(*MLPostCalendarEventsRequest) { + return func(r *MLPostCalendarEventsRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLPostCalendarEvents) WithPretty() func(*MLPostCalendarEventsRequest) { + return func(r *MLPostCalendarEventsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLPostCalendarEvents) WithHuman() func(*MLPostCalendarEventsRequest) { + return func(r *MLPostCalendarEventsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLPostCalendarEvents) WithErrorTrace() func(*MLPostCalendarEventsRequest) { + return func(r *MLPostCalendarEventsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLPostCalendarEvents) WithFilterPath(v ...string) func(*MLPostCalendarEventsRequest) { + return func(r *MLPostCalendarEventsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLPostCalendarEvents) WithHeader(h map[string]string) func(*MLPostCalendarEventsRequest) { + return func(r *MLPostCalendarEventsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLPostCalendarEvents) WithOpaqueID(s string) func(*MLPostCalendarEventsRequest) { + return func(r *MLPostCalendarEventsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.post_data.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.post_data.go new file mode 100644 index 00000000000..4bebb4c207f --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.post_data.go @@ -0,0 +1,226 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newMLPostDataFunc(t Transport) MLPostData { + return func(job_id string, body io.Reader, o ...func(*MLPostDataRequest)) (*Response, error) { + var r = MLPostDataRequest{JobID: job_id, Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLPostData - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-post-data.html. +// +type MLPostData func(job_id string, body io.Reader, o ...func(*MLPostDataRequest)) (*Response, error) + +// MLPostDataRequest configures the ML Post Data API request. +// +type MLPostDataRequest struct { + Body io.Reader + + JobID string + + ResetEnd string + ResetStart string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLPostDataRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_ml") + 1 + len("anomaly_detectors") + 1 + len(r.JobID) + 1 + len("_data")) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("anomaly_detectors") + path.WriteString("/") + path.WriteString(r.JobID) + path.WriteString("/") + path.WriteString("_data") + + params = make(map[string]string) + + if r.ResetEnd != "" { + params["reset_end"] = r.ResetEnd + } + + if r.ResetStart != "" { + params["reset_start"] = r.ResetStart + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLPostData) WithContext(v context.Context) func(*MLPostDataRequest) { + return func(r *MLPostDataRequest) { + r.ctx = v + } +} + +// WithResetEnd - optional parameter to specify the end of the bucket resetting range. +// +func (f MLPostData) WithResetEnd(v string) func(*MLPostDataRequest) { + return func(r *MLPostDataRequest) { + r.ResetEnd = v + } +} + +// WithResetStart - optional parameter to specify the start of the bucket resetting range. +// +func (f MLPostData) WithResetStart(v string) func(*MLPostDataRequest) { + return func(r *MLPostDataRequest) { + r.ResetStart = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLPostData) WithPretty() func(*MLPostDataRequest) { + return func(r *MLPostDataRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLPostData) WithHuman() func(*MLPostDataRequest) { + return func(r *MLPostDataRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLPostData) WithErrorTrace() func(*MLPostDataRequest) { + return func(r *MLPostDataRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLPostData) WithFilterPath(v ...string) func(*MLPostDataRequest) { + return func(r *MLPostDataRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLPostData) WithHeader(h map[string]string) func(*MLPostDataRequest) { + return func(r *MLPostDataRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLPostData) WithOpaqueID(s string) func(*MLPostDataRequest) { + return func(r *MLPostDataRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.preview_datafeed.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.preview_datafeed.go new file mode 100644 index 00000000000..8866dedf449 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.preview_datafeed.go @@ -0,0 +1,192 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newMLPreviewDatafeedFunc(t Transport) MLPreviewDatafeed { + return func(datafeed_id string, o ...func(*MLPreviewDatafeedRequest)) (*Response, error) { + var r = MLPreviewDatafeedRequest{DatafeedID: datafeed_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLPreviewDatafeed - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-preview-datafeed.html. +// +type MLPreviewDatafeed func(datafeed_id string, o ...func(*MLPreviewDatafeedRequest)) (*Response, error) + +// MLPreviewDatafeedRequest configures the ML Preview Datafeed API request. +// +type MLPreviewDatafeedRequest struct { + DatafeedID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLPreviewDatafeedRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_ml") + 1 + len("datafeeds") + 1 + len(r.DatafeedID) + 1 + len("_preview")) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("datafeeds") + path.WriteString("/") + path.WriteString(r.DatafeedID) + path.WriteString("/") + path.WriteString("_preview") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLPreviewDatafeed) WithContext(v context.Context) func(*MLPreviewDatafeedRequest) { + return func(r *MLPreviewDatafeedRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLPreviewDatafeed) WithPretty() func(*MLPreviewDatafeedRequest) { + return func(r *MLPreviewDatafeedRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLPreviewDatafeed) WithHuman() func(*MLPreviewDatafeedRequest) { + return func(r *MLPreviewDatafeedRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLPreviewDatafeed) WithErrorTrace() func(*MLPreviewDatafeedRequest) { + return func(r *MLPreviewDatafeedRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLPreviewDatafeed) WithFilterPath(v ...string) func(*MLPreviewDatafeedRequest) { + return func(r *MLPreviewDatafeedRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLPreviewDatafeed) WithHeader(h map[string]string) func(*MLPreviewDatafeedRequest) { + return func(r *MLPreviewDatafeedRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLPreviewDatafeed) WithOpaqueID(s string) func(*MLPreviewDatafeedRequest) { + return func(r *MLPreviewDatafeedRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.put_calendar.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.put_calendar.go new file mode 100644 index 00000000000..ba2c0920fc6 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.put_calendar.go @@ -0,0 +1,203 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newMLPutCalendarFunc(t Transport) MLPutCalendar { + return func(calendar_id string, o ...func(*MLPutCalendarRequest)) (*Response, error) { + var r = MLPutCalendarRequest{CalendarID: calendar_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLPutCalendar - +// +type MLPutCalendar func(calendar_id string, o ...func(*MLPutCalendarRequest)) (*Response, error) + +// MLPutCalendarRequest configures the ML Put Calendar API request. +// +type MLPutCalendarRequest struct { + Body io.Reader + + CalendarID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLPutCalendarRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_ml") + 1 + len("calendars") + 1 + len(r.CalendarID)) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("calendars") + path.WriteString("/") + path.WriteString(r.CalendarID) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLPutCalendar) WithContext(v context.Context) func(*MLPutCalendarRequest) { + return func(r *MLPutCalendarRequest) { + r.ctx = v + } +} + +// WithBody - The calendar details. +// +func (f MLPutCalendar) WithBody(v io.Reader) func(*MLPutCalendarRequest) { + return func(r *MLPutCalendarRequest) { + r.Body = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLPutCalendar) WithPretty() func(*MLPutCalendarRequest) { + return func(r *MLPutCalendarRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLPutCalendar) WithHuman() func(*MLPutCalendarRequest) { + return func(r *MLPutCalendarRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLPutCalendar) WithErrorTrace() func(*MLPutCalendarRequest) { + return func(r *MLPutCalendarRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLPutCalendar) WithFilterPath(v ...string) func(*MLPutCalendarRequest) { + return func(r *MLPutCalendarRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLPutCalendar) WithHeader(h map[string]string) func(*MLPutCalendarRequest) { + return func(r *MLPutCalendarRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLPutCalendar) WithOpaqueID(s string) func(*MLPutCalendarRequest) { + return func(r *MLPutCalendarRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.put_calendar_job.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.put_calendar_job.go new file mode 100644 index 00000000000..7cec01376fa --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.put_calendar_job.go @@ -0,0 +1,193 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newMLPutCalendarJobFunc(t Transport) MLPutCalendarJob { + return func(calendar_id string, job_id string, o ...func(*MLPutCalendarJobRequest)) (*Response, error) { + var r = MLPutCalendarJobRequest{CalendarID: calendar_id, JobID: job_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLPutCalendarJob - +// +type MLPutCalendarJob func(calendar_id string, job_id string, o ...func(*MLPutCalendarJobRequest)) (*Response, error) + +// MLPutCalendarJobRequest configures the ML Put Calendar Job API request. +// +type MLPutCalendarJobRequest struct { + CalendarID string + JobID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLPutCalendarJobRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_ml") + 1 + len("calendars") + 1 + len(r.CalendarID) + 1 + len("jobs") + 1 + len(r.JobID)) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("calendars") + path.WriteString("/") + path.WriteString(r.CalendarID) + path.WriteString("/") + path.WriteString("jobs") + path.WriteString("/") + path.WriteString(r.JobID) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLPutCalendarJob) WithContext(v context.Context) func(*MLPutCalendarJobRequest) { + return func(r *MLPutCalendarJobRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLPutCalendarJob) WithPretty() func(*MLPutCalendarJobRequest) { + return func(r *MLPutCalendarJobRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLPutCalendarJob) WithHuman() func(*MLPutCalendarJobRequest) { + return func(r *MLPutCalendarJobRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLPutCalendarJob) WithErrorTrace() func(*MLPutCalendarJobRequest) { + return func(r *MLPutCalendarJobRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLPutCalendarJob) WithFilterPath(v ...string) func(*MLPutCalendarJobRequest) { + return func(r *MLPutCalendarJobRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLPutCalendarJob) WithHeader(h map[string]string) func(*MLPutCalendarJobRequest) { + return func(r *MLPutCalendarJobRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLPutCalendarJob) WithOpaqueID(s string) func(*MLPutCalendarJobRequest) { + return func(r *MLPutCalendarJobRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.put_data_frame_analytics.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.put_data_frame_analytics.go new file mode 100644 index 00000000000..9ed963181fe --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.put_data_frame_analytics.go @@ -0,0 +1,199 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newMLPutDataFrameAnalyticsFunc(t Transport) MLPutDataFrameAnalytics { + return func(id string, body io.Reader, o ...func(*MLPutDataFrameAnalyticsRequest)) (*Response, error) { + var r = MLPutDataFrameAnalyticsRequest{ID: id, Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLPutDataFrameAnalytics - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/put-dfanalytics.html. +// +type MLPutDataFrameAnalytics func(id string, body io.Reader, o ...func(*MLPutDataFrameAnalyticsRequest)) (*Response, error) + +// MLPutDataFrameAnalyticsRequest configures the ML Put Data Frame Analytics API request. +// +type MLPutDataFrameAnalyticsRequest struct { + ID string + + Body io.Reader + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLPutDataFrameAnalyticsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_ml") + 1 + len("data_frame") + 1 + len("analytics") + 1 + len(r.ID)) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("data_frame") + path.WriteString("/") + path.WriteString("analytics") + path.WriteString("/") + path.WriteString(r.ID) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLPutDataFrameAnalytics) WithContext(v context.Context) func(*MLPutDataFrameAnalyticsRequest) { + return func(r *MLPutDataFrameAnalyticsRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLPutDataFrameAnalytics) WithPretty() func(*MLPutDataFrameAnalyticsRequest) { + return func(r *MLPutDataFrameAnalyticsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLPutDataFrameAnalytics) WithHuman() func(*MLPutDataFrameAnalyticsRequest) { + return func(r *MLPutDataFrameAnalyticsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLPutDataFrameAnalytics) WithErrorTrace() func(*MLPutDataFrameAnalyticsRequest) { + return func(r *MLPutDataFrameAnalyticsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLPutDataFrameAnalytics) WithFilterPath(v ...string) func(*MLPutDataFrameAnalyticsRequest) { + return func(r *MLPutDataFrameAnalyticsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLPutDataFrameAnalytics) WithHeader(h map[string]string) func(*MLPutDataFrameAnalyticsRequest) { + return func(r *MLPutDataFrameAnalyticsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLPutDataFrameAnalytics) WithOpaqueID(s string) func(*MLPutDataFrameAnalyticsRequest) { + return func(r *MLPutDataFrameAnalyticsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.put_datafeed.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.put_datafeed.go new file mode 100644 index 00000000000..23f55cad19f --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.put_datafeed.go @@ -0,0 +1,197 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newMLPutDatafeedFunc(t Transport) MLPutDatafeed { + return func(body io.Reader, datafeed_id string, o ...func(*MLPutDatafeedRequest)) (*Response, error) { + var r = MLPutDatafeedRequest{Body: body, DatafeedID: datafeed_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLPutDatafeed - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-put-datafeed.html. +// +type MLPutDatafeed func(body io.Reader, datafeed_id string, o ...func(*MLPutDatafeedRequest)) (*Response, error) + +// MLPutDatafeedRequest configures the ML Put Datafeed API request. +// +type MLPutDatafeedRequest struct { + Body io.Reader + + DatafeedID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLPutDatafeedRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_ml") + 1 + len("datafeeds") + 1 + len(r.DatafeedID)) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("datafeeds") + path.WriteString("/") + path.WriteString(r.DatafeedID) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLPutDatafeed) WithContext(v context.Context) func(*MLPutDatafeedRequest) { + return func(r *MLPutDatafeedRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLPutDatafeed) WithPretty() func(*MLPutDatafeedRequest) { + return func(r *MLPutDatafeedRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLPutDatafeed) WithHuman() func(*MLPutDatafeedRequest) { + return func(r *MLPutDatafeedRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLPutDatafeed) WithErrorTrace() func(*MLPutDatafeedRequest) { + return func(r *MLPutDatafeedRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLPutDatafeed) WithFilterPath(v ...string) func(*MLPutDatafeedRequest) { + return func(r *MLPutDatafeedRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLPutDatafeed) WithHeader(h map[string]string) func(*MLPutDatafeedRequest) { + return func(r *MLPutDatafeedRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLPutDatafeed) WithOpaqueID(s string) func(*MLPutDatafeedRequest) { + return func(r *MLPutDatafeedRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.put_filter.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.put_filter.go new file mode 100644 index 00000000000..3e90b174c3d --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.put_filter.go @@ -0,0 +1,195 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newMLPutFilterFunc(t Transport) MLPutFilter { + return func(body io.Reader, filter_id string, o ...func(*MLPutFilterRequest)) (*Response, error) { + var r = MLPutFilterRequest{Body: body, FilterID: filter_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLPutFilter - +// +type MLPutFilter func(body io.Reader, filter_id string, o ...func(*MLPutFilterRequest)) (*Response, error) + +// MLPutFilterRequest configures the ML Put Filter API request. +// +type MLPutFilterRequest struct { + Body io.Reader + + FilterID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLPutFilterRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_ml") + 1 + len("filters") + 1 + len(r.FilterID)) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("filters") + path.WriteString("/") + path.WriteString(r.FilterID) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLPutFilter) WithContext(v context.Context) func(*MLPutFilterRequest) { + return func(r *MLPutFilterRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLPutFilter) WithPretty() func(*MLPutFilterRequest) { + return func(r *MLPutFilterRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLPutFilter) WithHuman() func(*MLPutFilterRequest) { + return func(r *MLPutFilterRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLPutFilter) WithErrorTrace() func(*MLPutFilterRequest) { + return func(r *MLPutFilterRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLPutFilter) WithFilterPath(v ...string) func(*MLPutFilterRequest) { + return func(r *MLPutFilterRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLPutFilter) WithHeader(h map[string]string) func(*MLPutFilterRequest) { + return func(r *MLPutFilterRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLPutFilter) WithOpaqueID(s string) func(*MLPutFilterRequest) { + return func(r *MLPutFilterRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.put_job.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.put_job.go new file mode 100644 index 00000000000..52057bd895c --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.put_job.go @@ -0,0 +1,197 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newMLPutJobFunc(t Transport) MLPutJob { + return func(job_id string, body io.Reader, o ...func(*MLPutJobRequest)) (*Response, error) { + var r = MLPutJobRequest{JobID: job_id, Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLPutJob - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-put-job.html. +// +type MLPutJob func(job_id string, body io.Reader, o ...func(*MLPutJobRequest)) (*Response, error) + +// MLPutJobRequest configures the ML Put Job API request. +// +type MLPutJobRequest struct { + Body io.Reader + + JobID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLPutJobRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_ml") + 1 + len("anomaly_detectors") + 1 + len(r.JobID)) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("anomaly_detectors") + path.WriteString("/") + path.WriteString(r.JobID) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLPutJob) WithContext(v context.Context) func(*MLPutJobRequest) { + return func(r *MLPutJobRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLPutJob) WithPretty() func(*MLPutJobRequest) { + return func(r *MLPutJobRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLPutJob) WithHuman() func(*MLPutJobRequest) { + return func(r *MLPutJobRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLPutJob) WithErrorTrace() func(*MLPutJobRequest) { + return func(r *MLPutJobRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLPutJob) WithFilterPath(v ...string) func(*MLPutJobRequest) { + return func(r *MLPutJobRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLPutJob) WithHeader(h map[string]string) func(*MLPutJobRequest) { + return func(r *MLPutJobRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLPutJob) WithOpaqueID(s string) func(*MLPutJobRequest) { + return func(r *MLPutJobRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.revert_model_snapshot.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.revert_model_snapshot.go new file mode 100644 index 00000000000..a685610bbe7 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.revert_model_snapshot.go @@ -0,0 +1,227 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newMLRevertModelSnapshotFunc(t Transport) MLRevertModelSnapshot { + return func(snapshot_id string, job_id string, o ...func(*MLRevertModelSnapshotRequest)) (*Response, error) { + var r = MLRevertModelSnapshotRequest{SnapshotID: snapshot_id, JobID: job_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLRevertModelSnapshot - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-revert-snapshot.html. +// +type MLRevertModelSnapshot func(snapshot_id string, job_id string, o ...func(*MLRevertModelSnapshotRequest)) (*Response, error) + +// MLRevertModelSnapshotRequest configures the ML Revert Model Snapshot API request. +// +type MLRevertModelSnapshotRequest struct { + Body io.Reader + + JobID string + SnapshotID string + + DeleteInterveningResults *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLRevertModelSnapshotRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_ml") + 1 + len("anomaly_detectors") + 1 + len(r.JobID) + 1 + len("model_snapshots") + 1 + len(r.SnapshotID) + 1 + len("_revert")) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("anomaly_detectors") + path.WriteString("/") + path.WriteString(r.JobID) + path.WriteString("/") + path.WriteString("model_snapshots") + path.WriteString("/") + path.WriteString(r.SnapshotID) + path.WriteString("/") + path.WriteString("_revert") + + params = make(map[string]string) + + if r.DeleteInterveningResults != nil { + params["delete_intervening_results"] = strconv.FormatBool(*r.DeleteInterveningResults) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLRevertModelSnapshot) WithContext(v context.Context) func(*MLRevertModelSnapshotRequest) { + return func(r *MLRevertModelSnapshotRequest) { + r.ctx = v + } +} + +// WithBody - Reversion options. +// +func (f MLRevertModelSnapshot) WithBody(v io.Reader) func(*MLRevertModelSnapshotRequest) { + return func(r *MLRevertModelSnapshotRequest) { + r.Body = v + } +} + +// WithDeleteInterveningResults - should we reset the results back to the time of the snapshot?. +// +func (f MLRevertModelSnapshot) WithDeleteInterveningResults(v bool) func(*MLRevertModelSnapshotRequest) { + return func(r *MLRevertModelSnapshotRequest) { + r.DeleteInterveningResults = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLRevertModelSnapshot) WithPretty() func(*MLRevertModelSnapshotRequest) { + return func(r *MLRevertModelSnapshotRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLRevertModelSnapshot) WithHuman() func(*MLRevertModelSnapshotRequest) { + return func(r *MLRevertModelSnapshotRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLRevertModelSnapshot) WithErrorTrace() func(*MLRevertModelSnapshotRequest) { + return func(r *MLRevertModelSnapshotRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLRevertModelSnapshot) WithFilterPath(v ...string) func(*MLRevertModelSnapshotRequest) { + return func(r *MLRevertModelSnapshotRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLRevertModelSnapshot) WithHeader(h map[string]string) func(*MLRevertModelSnapshotRequest) { + return func(r *MLRevertModelSnapshotRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLRevertModelSnapshot) WithOpaqueID(s string) func(*MLRevertModelSnapshotRequest) { + return func(r *MLRevertModelSnapshotRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.set_upgrade_mode.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.set_upgrade_mode.go new file mode 100644 index 00000000000..9aa89b6436a --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.set_upgrade_mode.go @@ -0,0 +1,212 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newMLSetUpgradeModeFunc(t Transport) MLSetUpgradeMode { + return func(o ...func(*MLSetUpgradeModeRequest)) (*Response, error) { + var r = MLSetUpgradeModeRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLSetUpgradeMode - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-set-upgrade-mode.html. +// +type MLSetUpgradeMode func(o ...func(*MLSetUpgradeModeRequest)) (*Response, error) + +// MLSetUpgradeModeRequest configures the ML Set Upgrade Mode API request. +// +type MLSetUpgradeModeRequest struct { + Enabled *bool + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLSetUpgradeModeRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(len("/_ml/set_upgrade_mode")) + path.WriteString("/_ml/set_upgrade_mode") + + params = make(map[string]string) + + if r.Enabled != nil { + params["enabled"] = strconv.FormatBool(*r.Enabled) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLSetUpgradeMode) WithContext(v context.Context) func(*MLSetUpgradeModeRequest) { + return func(r *MLSetUpgradeModeRequest) { + r.ctx = v + } +} + +// WithEnabled - whether to enable upgrade_mode ml setting or not. defaults to false.. +// +func (f MLSetUpgradeMode) WithEnabled(v bool) func(*MLSetUpgradeModeRequest) { + return func(r *MLSetUpgradeModeRequest) { + r.Enabled = &v + } +} + +// WithTimeout - controls the time to wait before action times out. defaults to 30 seconds. +// +func (f MLSetUpgradeMode) WithTimeout(v time.Duration) func(*MLSetUpgradeModeRequest) { + return func(r *MLSetUpgradeModeRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLSetUpgradeMode) WithPretty() func(*MLSetUpgradeModeRequest) { + return func(r *MLSetUpgradeModeRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLSetUpgradeMode) WithHuman() func(*MLSetUpgradeModeRequest) { + return func(r *MLSetUpgradeModeRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLSetUpgradeMode) WithErrorTrace() func(*MLSetUpgradeModeRequest) { + return func(r *MLSetUpgradeModeRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLSetUpgradeMode) WithFilterPath(v ...string) func(*MLSetUpgradeModeRequest) { + return func(r *MLSetUpgradeModeRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLSetUpgradeMode) WithHeader(h map[string]string) func(*MLSetUpgradeModeRequest) { + return func(r *MLSetUpgradeModeRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLSetUpgradeMode) WithOpaqueID(s string) func(*MLSetUpgradeModeRequest) { + return func(r *MLSetUpgradeModeRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.start_data_frame_analytics.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.start_data_frame_analytics.go new file mode 100644 index 00000000000..e2ad34c154f --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.start_data_frame_analytics.go @@ -0,0 +1,224 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" + "time" +) + +func newMLStartDataFrameAnalyticsFunc(t Transport) MLStartDataFrameAnalytics { + return func(id string, o ...func(*MLStartDataFrameAnalyticsRequest)) (*Response, error) { + var r = MLStartDataFrameAnalyticsRequest{ID: id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLStartDataFrameAnalytics - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/start-dfanalytics.html. +// +type MLStartDataFrameAnalytics func(id string, o ...func(*MLStartDataFrameAnalyticsRequest)) (*Response, error) + +// MLStartDataFrameAnalyticsRequest configures the ML Start Data Frame Analytics API request. +// +type MLStartDataFrameAnalyticsRequest struct { + ID string + + Body io.Reader + + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLStartDataFrameAnalyticsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_ml") + 1 + len("data_frame") + 1 + len("analytics") + 1 + len(r.ID) + 1 + len("_start")) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("data_frame") + path.WriteString("/") + path.WriteString("analytics") + path.WriteString("/") + path.WriteString(r.ID) + path.WriteString("/") + path.WriteString("_start") + + params = make(map[string]string) + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLStartDataFrameAnalytics) WithContext(v context.Context) func(*MLStartDataFrameAnalyticsRequest) { + return func(r *MLStartDataFrameAnalyticsRequest) { + r.ctx = v + } +} + +// WithBody - The start data frame analytics parameters. +// +func (f MLStartDataFrameAnalytics) WithBody(v io.Reader) func(*MLStartDataFrameAnalyticsRequest) { + return func(r *MLStartDataFrameAnalyticsRequest) { + r.Body = v + } +} + +// WithTimeout - controls the time to wait until the task has started. defaults to 20 seconds. +// +func (f MLStartDataFrameAnalytics) WithTimeout(v time.Duration) func(*MLStartDataFrameAnalyticsRequest) { + return func(r *MLStartDataFrameAnalyticsRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLStartDataFrameAnalytics) WithPretty() func(*MLStartDataFrameAnalyticsRequest) { + return func(r *MLStartDataFrameAnalyticsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLStartDataFrameAnalytics) WithHuman() func(*MLStartDataFrameAnalyticsRequest) { + return func(r *MLStartDataFrameAnalyticsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLStartDataFrameAnalytics) WithErrorTrace() func(*MLStartDataFrameAnalyticsRequest) { + return func(r *MLStartDataFrameAnalyticsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLStartDataFrameAnalytics) WithFilterPath(v ...string) func(*MLStartDataFrameAnalyticsRequest) { + return func(r *MLStartDataFrameAnalyticsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLStartDataFrameAnalytics) WithHeader(h map[string]string) func(*MLStartDataFrameAnalyticsRequest) { + return func(r *MLStartDataFrameAnalyticsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLStartDataFrameAnalytics) WithOpaqueID(s string) func(*MLStartDataFrameAnalyticsRequest) { + return func(r *MLStartDataFrameAnalyticsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.start_datafeed.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.start_datafeed.go new file mode 100644 index 00000000000..0961eccb5ab --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.start_datafeed.go @@ -0,0 +1,248 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" + "time" +) + +func newMLStartDatafeedFunc(t Transport) MLStartDatafeed { + return func(datafeed_id string, o ...func(*MLStartDatafeedRequest)) (*Response, error) { + var r = MLStartDatafeedRequest{DatafeedID: datafeed_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLStartDatafeed - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-start-datafeed.html. +// +type MLStartDatafeed func(datafeed_id string, o ...func(*MLStartDatafeedRequest)) (*Response, error) + +// MLStartDatafeedRequest configures the ML Start Datafeed API request. +// +type MLStartDatafeedRequest struct { + Body io.Reader + + DatafeedID string + + End string + Start string + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLStartDatafeedRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_ml") + 1 + len("datafeeds") + 1 + len(r.DatafeedID) + 1 + len("_start")) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("datafeeds") + path.WriteString("/") + path.WriteString(r.DatafeedID) + path.WriteString("/") + path.WriteString("_start") + + params = make(map[string]string) + + if r.End != "" { + params["end"] = r.End + } + + if r.Start != "" { + params["start"] = r.Start + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLStartDatafeed) WithContext(v context.Context) func(*MLStartDatafeedRequest) { + return func(r *MLStartDatafeedRequest) { + r.ctx = v + } +} + +// WithBody - The start datafeed parameters. +// +func (f MLStartDatafeed) WithBody(v io.Reader) func(*MLStartDatafeedRequest) { + return func(r *MLStartDatafeedRequest) { + r.Body = v + } +} + +// WithEnd - the end time when the datafeed should stop. when not set, the datafeed continues in real time. +// +func (f MLStartDatafeed) WithEnd(v string) func(*MLStartDatafeedRequest) { + return func(r *MLStartDatafeedRequest) { + r.End = v + } +} + +// WithStart - the start time from where the datafeed should begin. +// +func (f MLStartDatafeed) WithStart(v string) func(*MLStartDatafeedRequest) { + return func(r *MLStartDatafeedRequest) { + r.Start = v + } +} + +// WithTimeout - controls the time to wait until a datafeed has started. default to 20 seconds. +// +func (f MLStartDatafeed) WithTimeout(v time.Duration) func(*MLStartDatafeedRequest) { + return func(r *MLStartDatafeedRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLStartDatafeed) WithPretty() func(*MLStartDatafeedRequest) { + return func(r *MLStartDatafeedRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLStartDatafeed) WithHuman() func(*MLStartDatafeedRequest) { + return func(r *MLStartDatafeedRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLStartDatafeed) WithErrorTrace() func(*MLStartDatafeedRequest) { + return func(r *MLStartDatafeedRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLStartDatafeed) WithFilterPath(v ...string) func(*MLStartDatafeedRequest) { + return func(r *MLStartDatafeedRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLStartDatafeed) WithHeader(h map[string]string) func(*MLStartDatafeedRequest) { + return func(r *MLStartDatafeedRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLStartDatafeed) WithOpaqueID(s string) func(*MLStartDatafeedRequest) { + return func(r *MLStartDatafeedRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.stop_data_frame_analytics.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.stop_data_frame_analytics.go new file mode 100644 index 00000000000..732af28f70f --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.stop_data_frame_analytics.go @@ -0,0 +1,251 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" + "time" +) + +func newMLStopDataFrameAnalyticsFunc(t Transport) MLStopDataFrameAnalytics { + return func(id string, o ...func(*MLStopDataFrameAnalyticsRequest)) (*Response, error) { + var r = MLStopDataFrameAnalyticsRequest{ID: id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLStopDataFrameAnalytics - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/stop-dfanalytics.html. +// +type MLStopDataFrameAnalytics func(id string, o ...func(*MLStopDataFrameAnalyticsRequest)) (*Response, error) + +// MLStopDataFrameAnalyticsRequest configures the ML Stop Data Frame Analytics API request. +// +type MLStopDataFrameAnalyticsRequest struct { + ID string + + Body io.Reader + + AllowNoMatch *bool + Force *bool + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLStopDataFrameAnalyticsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_ml") + 1 + len("data_frame") + 1 + len("analytics") + 1 + len(r.ID) + 1 + len("_stop")) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("data_frame") + path.WriteString("/") + path.WriteString("analytics") + path.WriteString("/") + path.WriteString(r.ID) + path.WriteString("/") + path.WriteString("_stop") + + params = make(map[string]string) + + if r.AllowNoMatch != nil { + params["allow_no_match"] = strconv.FormatBool(*r.AllowNoMatch) + } + + if r.Force != nil { + params["force"] = strconv.FormatBool(*r.Force) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLStopDataFrameAnalytics) WithContext(v context.Context) func(*MLStopDataFrameAnalyticsRequest) { + return func(r *MLStopDataFrameAnalyticsRequest) { + r.ctx = v + } +} + +// WithBody - The stop data frame analytics parameters. +// +func (f MLStopDataFrameAnalytics) WithBody(v io.Reader) func(*MLStopDataFrameAnalyticsRequest) { + return func(r *MLStopDataFrameAnalyticsRequest) { + r.Body = v + } +} + +// WithAllowNoMatch - whether to ignore if a wildcard expression matches no data frame analytics. (this includes `_all` string or when no data frame analytics have been specified). +// +func (f MLStopDataFrameAnalytics) WithAllowNoMatch(v bool) func(*MLStopDataFrameAnalyticsRequest) { + return func(r *MLStopDataFrameAnalyticsRequest) { + r.AllowNoMatch = &v + } +} + +// WithForce - true if the data frame analytics should be forcefully stopped. +// +func (f MLStopDataFrameAnalytics) WithForce(v bool) func(*MLStopDataFrameAnalyticsRequest) { + return func(r *MLStopDataFrameAnalyticsRequest) { + r.Force = &v + } +} + +// WithTimeout - controls the time to wait until the task has stopped. defaults to 20 seconds. +// +func (f MLStopDataFrameAnalytics) WithTimeout(v time.Duration) func(*MLStopDataFrameAnalyticsRequest) { + return func(r *MLStopDataFrameAnalyticsRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLStopDataFrameAnalytics) WithPretty() func(*MLStopDataFrameAnalyticsRequest) { + return func(r *MLStopDataFrameAnalyticsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLStopDataFrameAnalytics) WithHuman() func(*MLStopDataFrameAnalyticsRequest) { + return func(r *MLStopDataFrameAnalyticsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLStopDataFrameAnalytics) WithErrorTrace() func(*MLStopDataFrameAnalyticsRequest) { + return func(r *MLStopDataFrameAnalyticsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLStopDataFrameAnalytics) WithFilterPath(v ...string) func(*MLStopDataFrameAnalyticsRequest) { + return func(r *MLStopDataFrameAnalyticsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLStopDataFrameAnalytics) WithHeader(h map[string]string) func(*MLStopDataFrameAnalyticsRequest) { + return func(r *MLStopDataFrameAnalyticsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLStopDataFrameAnalytics) WithOpaqueID(s string) func(*MLStopDataFrameAnalyticsRequest) { + return func(r *MLStopDataFrameAnalyticsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.stop_datafeed.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.stop_datafeed.go new file mode 100644 index 00000000000..2789495b1db --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.stop_datafeed.go @@ -0,0 +1,234 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newMLStopDatafeedFunc(t Transport) MLStopDatafeed { + return func(datafeed_id string, o ...func(*MLStopDatafeedRequest)) (*Response, error) { + var r = MLStopDatafeedRequest{DatafeedID: datafeed_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLStopDatafeed - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-stop-datafeed.html. +// +type MLStopDatafeed func(datafeed_id string, o ...func(*MLStopDatafeedRequest)) (*Response, error) + +// MLStopDatafeedRequest configures the ML Stop Datafeed API request. +// +type MLStopDatafeedRequest struct { + DatafeedID string + + AllowNoDatafeeds *bool + Force *bool + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLStopDatafeedRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_ml") + 1 + len("datafeeds") + 1 + len(r.DatafeedID) + 1 + len("_stop")) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("datafeeds") + path.WriteString("/") + path.WriteString(r.DatafeedID) + path.WriteString("/") + path.WriteString("_stop") + + params = make(map[string]string) + + if r.AllowNoDatafeeds != nil { + params["allow_no_datafeeds"] = strconv.FormatBool(*r.AllowNoDatafeeds) + } + + if r.Force != nil { + params["force"] = strconv.FormatBool(*r.Force) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLStopDatafeed) WithContext(v context.Context) func(*MLStopDatafeedRequest) { + return func(r *MLStopDatafeedRequest) { + r.ctx = v + } +} + +// WithAllowNoDatafeeds - whether to ignore if a wildcard expression matches no datafeeds. (this includes `_all` string or when no datafeeds have been specified). +// +func (f MLStopDatafeed) WithAllowNoDatafeeds(v bool) func(*MLStopDatafeedRequest) { + return func(r *MLStopDatafeedRequest) { + r.AllowNoDatafeeds = &v + } +} + +// WithForce - true if the datafeed should be forcefully stopped.. +// +func (f MLStopDatafeed) WithForce(v bool) func(*MLStopDatafeedRequest) { + return func(r *MLStopDatafeedRequest) { + r.Force = &v + } +} + +// WithTimeout - controls the time to wait until a datafeed has stopped. default to 20 seconds. +// +func (f MLStopDatafeed) WithTimeout(v time.Duration) func(*MLStopDatafeedRequest) { + return func(r *MLStopDatafeedRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLStopDatafeed) WithPretty() func(*MLStopDatafeedRequest) { + return func(r *MLStopDatafeedRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLStopDatafeed) WithHuman() func(*MLStopDatafeedRequest) { + return func(r *MLStopDatafeedRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLStopDatafeed) WithErrorTrace() func(*MLStopDatafeedRequest) { + return func(r *MLStopDatafeedRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLStopDatafeed) WithFilterPath(v ...string) func(*MLStopDatafeedRequest) { + return func(r *MLStopDatafeedRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLStopDatafeed) WithHeader(h map[string]string) func(*MLStopDatafeedRequest) { + return func(r *MLStopDatafeedRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLStopDatafeed) WithOpaqueID(s string) func(*MLStopDatafeedRequest) { + return func(r *MLStopDatafeedRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.update_datafeed.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.update_datafeed.go new file mode 100644 index 00000000000..d5e2af6a535 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.update_datafeed.go @@ -0,0 +1,199 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newMLUpdateDatafeedFunc(t Transport) MLUpdateDatafeed { + return func(body io.Reader, datafeed_id string, o ...func(*MLUpdateDatafeedRequest)) (*Response, error) { + var r = MLUpdateDatafeedRequest{Body: body, DatafeedID: datafeed_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLUpdateDatafeed - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-update-datafeed.html. +// +type MLUpdateDatafeed func(body io.Reader, datafeed_id string, o ...func(*MLUpdateDatafeedRequest)) (*Response, error) + +// MLUpdateDatafeedRequest configures the ML Update Datafeed API request. +// +type MLUpdateDatafeedRequest struct { + Body io.Reader + + DatafeedID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLUpdateDatafeedRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_ml") + 1 + len("datafeeds") + 1 + len(r.DatafeedID) + 1 + len("_update")) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("datafeeds") + path.WriteString("/") + path.WriteString(r.DatafeedID) + path.WriteString("/") + path.WriteString("_update") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLUpdateDatafeed) WithContext(v context.Context) func(*MLUpdateDatafeedRequest) { + return func(r *MLUpdateDatafeedRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLUpdateDatafeed) WithPretty() func(*MLUpdateDatafeedRequest) { + return func(r *MLUpdateDatafeedRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLUpdateDatafeed) WithHuman() func(*MLUpdateDatafeedRequest) { + return func(r *MLUpdateDatafeedRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLUpdateDatafeed) WithErrorTrace() func(*MLUpdateDatafeedRequest) { + return func(r *MLUpdateDatafeedRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLUpdateDatafeed) WithFilterPath(v ...string) func(*MLUpdateDatafeedRequest) { + return func(r *MLUpdateDatafeedRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLUpdateDatafeed) WithHeader(h map[string]string) func(*MLUpdateDatafeedRequest) { + return func(r *MLUpdateDatafeedRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLUpdateDatafeed) WithOpaqueID(s string) func(*MLUpdateDatafeedRequest) { + return func(r *MLUpdateDatafeedRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.update_filter.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.update_filter.go new file mode 100644 index 00000000000..99f2593c0c7 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.update_filter.go @@ -0,0 +1,197 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newMLUpdateFilterFunc(t Transport) MLUpdateFilter { + return func(body io.Reader, filter_id string, o ...func(*MLUpdateFilterRequest)) (*Response, error) { + var r = MLUpdateFilterRequest{Body: body, FilterID: filter_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLUpdateFilter - +// +type MLUpdateFilter func(body io.Reader, filter_id string, o ...func(*MLUpdateFilterRequest)) (*Response, error) + +// MLUpdateFilterRequest configures the ML Update Filter API request. +// +type MLUpdateFilterRequest struct { + Body io.Reader + + FilterID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLUpdateFilterRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_ml") + 1 + len("filters") + 1 + len(r.FilterID) + 1 + len("_update")) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("filters") + path.WriteString("/") + path.WriteString(r.FilterID) + path.WriteString("/") + path.WriteString("_update") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLUpdateFilter) WithContext(v context.Context) func(*MLUpdateFilterRequest) { + return func(r *MLUpdateFilterRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLUpdateFilter) WithPretty() func(*MLUpdateFilterRequest) { + return func(r *MLUpdateFilterRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLUpdateFilter) WithHuman() func(*MLUpdateFilterRequest) { + return func(r *MLUpdateFilterRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLUpdateFilter) WithErrorTrace() func(*MLUpdateFilterRequest) { + return func(r *MLUpdateFilterRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLUpdateFilter) WithFilterPath(v ...string) func(*MLUpdateFilterRequest) { + return func(r *MLUpdateFilterRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLUpdateFilter) WithHeader(h map[string]string) func(*MLUpdateFilterRequest) { + return func(r *MLUpdateFilterRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLUpdateFilter) WithOpaqueID(s string) func(*MLUpdateFilterRequest) { + return func(r *MLUpdateFilterRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.update_job.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.update_job.go new file mode 100644 index 00000000000..55be58412e8 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.update_job.go @@ -0,0 +1,199 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newMLUpdateJobFunc(t Transport) MLUpdateJob { + return func(job_id string, body io.Reader, o ...func(*MLUpdateJobRequest)) (*Response, error) { + var r = MLUpdateJobRequest{JobID: job_id, Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLUpdateJob - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-update-job.html. +// +type MLUpdateJob func(job_id string, body io.Reader, o ...func(*MLUpdateJobRequest)) (*Response, error) + +// MLUpdateJobRequest configures the ML Update Job API request. +// +type MLUpdateJobRequest struct { + Body io.Reader + + JobID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLUpdateJobRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_ml") + 1 + len("anomaly_detectors") + 1 + len(r.JobID) + 1 + len("_update")) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("anomaly_detectors") + path.WriteString("/") + path.WriteString(r.JobID) + path.WriteString("/") + path.WriteString("_update") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLUpdateJob) WithContext(v context.Context) func(*MLUpdateJobRequest) { + return func(r *MLUpdateJobRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLUpdateJob) WithPretty() func(*MLUpdateJobRequest) { + return func(r *MLUpdateJobRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLUpdateJob) WithHuman() func(*MLUpdateJobRequest) { + return func(r *MLUpdateJobRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLUpdateJob) WithErrorTrace() func(*MLUpdateJobRequest) { + return func(r *MLUpdateJobRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLUpdateJob) WithFilterPath(v ...string) func(*MLUpdateJobRequest) { + return func(r *MLUpdateJobRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLUpdateJob) WithHeader(h map[string]string) func(*MLUpdateJobRequest) { + return func(r *MLUpdateJobRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLUpdateJob) WithOpaqueID(s string) func(*MLUpdateJobRequest) { + return func(r *MLUpdateJobRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.update_model_snapshot.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.update_model_snapshot.go new file mode 100644 index 00000000000..245b0e2609a --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.update_model_snapshot.go @@ -0,0 +1,204 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newMLUpdateModelSnapshotFunc(t Transport) MLUpdateModelSnapshot { + return func(snapshot_id string, job_id string, body io.Reader, o ...func(*MLUpdateModelSnapshotRequest)) (*Response, error) { + var r = MLUpdateModelSnapshotRequest{SnapshotID: snapshot_id, JobID: job_id, Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLUpdateModelSnapshot - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-update-snapshot.html. +// +type MLUpdateModelSnapshot func(snapshot_id string, job_id string, body io.Reader, o ...func(*MLUpdateModelSnapshotRequest)) (*Response, error) + +// MLUpdateModelSnapshotRequest configures the ML Update Model Snapshot API request. +// +type MLUpdateModelSnapshotRequest struct { + Body io.Reader + + JobID string + SnapshotID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLUpdateModelSnapshotRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_ml") + 1 + len("anomaly_detectors") + 1 + len(r.JobID) + 1 + len("model_snapshots") + 1 + len(r.SnapshotID) + 1 + len("_update")) + path.WriteString("/") + path.WriteString("_ml") + path.WriteString("/") + path.WriteString("anomaly_detectors") + path.WriteString("/") + path.WriteString(r.JobID) + path.WriteString("/") + path.WriteString("model_snapshots") + path.WriteString("/") + path.WriteString(r.SnapshotID) + path.WriteString("/") + path.WriteString("_update") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLUpdateModelSnapshot) WithContext(v context.Context) func(*MLUpdateModelSnapshotRequest) { + return func(r *MLUpdateModelSnapshotRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLUpdateModelSnapshot) WithPretty() func(*MLUpdateModelSnapshotRequest) { + return func(r *MLUpdateModelSnapshotRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLUpdateModelSnapshot) WithHuman() func(*MLUpdateModelSnapshotRequest) { + return func(r *MLUpdateModelSnapshotRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLUpdateModelSnapshot) WithErrorTrace() func(*MLUpdateModelSnapshotRequest) { + return func(r *MLUpdateModelSnapshotRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLUpdateModelSnapshot) WithFilterPath(v ...string) func(*MLUpdateModelSnapshotRequest) { + return func(r *MLUpdateModelSnapshotRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLUpdateModelSnapshot) WithHeader(h map[string]string) func(*MLUpdateModelSnapshotRequest) { + return func(r *MLUpdateModelSnapshotRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLUpdateModelSnapshot) WithOpaqueID(s string) func(*MLUpdateModelSnapshotRequest) { + return func(r *MLUpdateModelSnapshotRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.validate.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.validate.go new file mode 100644 index 00000000000..5058559c083 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.validate.go @@ -0,0 +1,188 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newMLValidateFunc(t Transport) MLValidate { + return func(body io.Reader, o ...func(*MLValidateRequest)) (*Response, error) { + var r = MLValidateRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLValidate - +// +type MLValidate func(body io.Reader, o ...func(*MLValidateRequest)) (*Response, error) + +// MLValidateRequest configures the ML Validate API request. +// +type MLValidateRequest struct { + Body io.Reader + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLValidateRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(len("/_ml/anomaly_detectors/_validate")) + path.WriteString("/_ml/anomaly_detectors/_validate") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLValidate) WithContext(v context.Context) func(*MLValidateRequest) { + return func(r *MLValidateRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLValidate) WithPretty() func(*MLValidateRequest) { + return func(r *MLValidateRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLValidate) WithHuman() func(*MLValidateRequest) { + return func(r *MLValidateRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLValidate) WithErrorTrace() func(*MLValidateRequest) { + return func(r *MLValidateRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLValidate) WithFilterPath(v ...string) func(*MLValidateRequest) { + return func(r *MLValidateRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLValidate) WithHeader(h map[string]string) func(*MLValidateRequest) { + return func(r *MLValidateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLValidate) WithOpaqueID(s string) func(*MLValidateRequest) { + return func(r *MLValidateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.validate_detector.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.validate_detector.go new file mode 100644 index 00000000000..09bdac187ac --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ml.validate_detector.go @@ -0,0 +1,188 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newMLValidateDetectorFunc(t Transport) MLValidateDetector { + return func(body io.Reader, o ...func(*MLValidateDetectorRequest)) (*Response, error) { + var r = MLValidateDetectorRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MLValidateDetector - +// +type MLValidateDetector func(body io.Reader, o ...func(*MLValidateDetectorRequest)) (*Response, error) + +// MLValidateDetectorRequest configures the ML Validate Detector API request. +// +type MLValidateDetectorRequest struct { + Body io.Reader + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MLValidateDetectorRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(len("/_ml/anomaly_detectors/_validate/detector")) + path.WriteString("/_ml/anomaly_detectors/_validate/detector") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MLValidateDetector) WithContext(v context.Context) func(*MLValidateDetectorRequest) { + return func(r *MLValidateDetectorRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MLValidateDetector) WithPretty() func(*MLValidateDetectorRequest) { + return func(r *MLValidateDetectorRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MLValidateDetector) WithHuman() func(*MLValidateDetectorRequest) { + return func(r *MLValidateDetectorRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MLValidateDetector) WithErrorTrace() func(*MLValidateDetectorRequest) { + return func(r *MLValidateDetectorRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MLValidateDetector) WithFilterPath(v ...string) func(*MLValidateDetectorRequest) { + return func(r *MLValidateDetectorRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MLValidateDetector) WithHeader(h map[string]string) func(*MLValidateDetectorRequest) { + return func(r *MLValidateDetectorRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MLValidateDetector) WithOpaqueID(s string) func(*MLValidateDetectorRequest) { + return func(r *MLValidateDetectorRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.monitoring.bulk.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.monitoring.bulk.go new file mode 100644 index 00000000000..396a3675307 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.monitoring.bulk.go @@ -0,0 +1,247 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newMonitoringBulkFunc(t Transport) MonitoringBulk { + return func(body io.Reader, o ...func(*MonitoringBulkRequest)) (*Response, error) { + var r = MonitoringBulkRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// MonitoringBulk - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/es-monitoring.html. +// +type MonitoringBulk func(body io.Reader, o ...func(*MonitoringBulkRequest)) (*Response, error) + +// MonitoringBulkRequest configures the Monitoring Bulk API request. +// +type MonitoringBulkRequest struct { + DocumentType string + + Body io.Reader + + Interval string + SystemAPIVersion string + SystemID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r MonitoringBulkRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_monitoring") + 1 + len(r.DocumentType) + 1 + len("bulk")) + path.WriteString("/") + path.WriteString("_monitoring") + if r.DocumentType != "" { + path.WriteString("/") + path.WriteString(r.DocumentType) + } + path.WriteString("/") + path.WriteString("bulk") + + params = make(map[string]string) + + if r.Interval != "" { + params["interval"] = r.Interval + } + + if r.SystemAPIVersion != "" { + params["system_api_version"] = r.SystemAPIVersion + } + + if r.SystemID != "" { + params["system_id"] = r.SystemID + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f MonitoringBulk) WithContext(v context.Context) func(*MonitoringBulkRequest) { + return func(r *MonitoringBulkRequest) { + r.ctx = v + } +} + +// WithDocumentType - default document type for items which don't provide one. +// +func (f MonitoringBulk) WithDocumentType(v string) func(*MonitoringBulkRequest) { + return func(r *MonitoringBulkRequest) { + r.DocumentType = v + } +} + +// WithInterval - collection interval (e.g., '10s' or '10000ms') of the payload. +// +func (f MonitoringBulk) WithInterval(v string) func(*MonitoringBulkRequest) { + return func(r *MonitoringBulkRequest) { + r.Interval = v + } +} + +// WithSystemAPIVersion - api version of the monitored system. +// +func (f MonitoringBulk) WithSystemAPIVersion(v string) func(*MonitoringBulkRequest) { + return func(r *MonitoringBulkRequest) { + r.SystemAPIVersion = v + } +} + +// WithSystemID - identifier of the monitored system. +// +func (f MonitoringBulk) WithSystemID(v string) func(*MonitoringBulkRequest) { + return func(r *MonitoringBulkRequest) { + r.SystemID = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f MonitoringBulk) WithPretty() func(*MonitoringBulkRequest) { + return func(r *MonitoringBulkRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f MonitoringBulk) WithHuman() func(*MonitoringBulkRequest) { + return func(r *MonitoringBulkRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f MonitoringBulk) WithErrorTrace() func(*MonitoringBulkRequest) { + return func(r *MonitoringBulkRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f MonitoringBulk) WithFilterPath(v ...string) func(*MonitoringBulkRequest) { + return func(r *MonitoringBulkRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f MonitoringBulk) WithHeader(h map[string]string) func(*MonitoringBulkRequest) { + return func(r *MonitoringBulkRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f MonitoringBulk) WithOpaqueID(s string) func(*MonitoringBulkRequest) { + return func(r *MonitoringBulkRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.delete_job.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.delete_job.go new file mode 100644 index 00000000000..974b75a1464 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.delete_job.go @@ -0,0 +1,188 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newRollupDeleteJobFunc(t Transport) RollupDeleteJob { + return func(id string, o ...func(*RollupDeleteJobRequest)) (*Response, error) { + var r = RollupDeleteJobRequest{JobID: id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// RollupDeleteJob - +// +type RollupDeleteJob func(id string, o ...func(*RollupDeleteJobRequest)) (*Response, error) + +// RollupDeleteJobRequest configures the Rollup Delete Job API request. +// +type RollupDeleteJobRequest struct { + JobID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r RollupDeleteJobRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_rollup") + 1 + len("job") + 1 + len(r.JobID)) + path.WriteString("/") + path.WriteString("_rollup") + path.WriteString("/") + path.WriteString("job") + path.WriteString("/") + path.WriteString(r.JobID) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f RollupDeleteJob) WithContext(v context.Context) func(*RollupDeleteJobRequest) { + return func(r *RollupDeleteJobRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f RollupDeleteJob) WithPretty() func(*RollupDeleteJobRequest) { + return func(r *RollupDeleteJobRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f RollupDeleteJob) WithHuman() func(*RollupDeleteJobRequest) { + return func(r *RollupDeleteJobRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f RollupDeleteJob) WithErrorTrace() func(*RollupDeleteJobRequest) { + return func(r *RollupDeleteJobRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f RollupDeleteJob) WithFilterPath(v ...string) func(*RollupDeleteJobRequest) { + return func(r *RollupDeleteJobRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f RollupDeleteJob) WithHeader(h map[string]string) func(*RollupDeleteJobRequest) { + return func(r *RollupDeleteJobRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f RollupDeleteJob) WithOpaqueID(s string) func(*RollupDeleteJobRequest) { + return func(r *RollupDeleteJobRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.get_jobs.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.get_jobs.go new file mode 100644 index 00000000000..fe2f46f66f6 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.get_jobs.go @@ -0,0 +1,198 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newRollupGetJobsFunc(t Transport) RollupGetJobs { + return func(o ...func(*RollupGetJobsRequest)) (*Response, error) { + var r = RollupGetJobsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// RollupGetJobs - +// +type RollupGetJobs func(o ...func(*RollupGetJobsRequest)) (*Response, error) + +// RollupGetJobsRequest configures the Rollup Get Jobs API request. +// +type RollupGetJobsRequest struct { + JobID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r RollupGetJobsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_rollup") + 1 + len("job") + 1 + len(r.JobID)) + path.WriteString("/") + path.WriteString("_rollup") + path.WriteString("/") + path.WriteString("job") + if r.JobID != "" { + path.WriteString("/") + path.WriteString(r.JobID) + } + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f RollupGetJobs) WithContext(v context.Context) func(*RollupGetJobsRequest) { + return func(r *RollupGetJobsRequest) { + r.ctx = v + } +} + +// WithJobID - the ID of the job(s) to fetch. accepts glob patterns, or left blank for all jobs. +// +func (f RollupGetJobs) WithJobID(v string) func(*RollupGetJobsRequest) { + return func(r *RollupGetJobsRequest) { + r.JobID = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f RollupGetJobs) WithPretty() func(*RollupGetJobsRequest) { + return func(r *RollupGetJobsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f RollupGetJobs) WithHuman() func(*RollupGetJobsRequest) { + return func(r *RollupGetJobsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f RollupGetJobs) WithErrorTrace() func(*RollupGetJobsRequest) { + return func(r *RollupGetJobsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f RollupGetJobs) WithFilterPath(v ...string) func(*RollupGetJobsRequest) { + return func(r *RollupGetJobsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f RollupGetJobs) WithHeader(h map[string]string) func(*RollupGetJobsRequest) { + return func(r *RollupGetJobsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f RollupGetJobs) WithOpaqueID(s string) func(*RollupGetJobsRequest) { + return func(r *RollupGetJobsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.get_rollup_caps.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.get_rollup_caps.go new file mode 100644 index 00000000000..6d8d7889757 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.get_rollup_caps.go @@ -0,0 +1,198 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newRollupGetRollupCapsFunc(t Transport) RollupGetRollupCaps { + return func(o ...func(*RollupGetRollupCapsRequest)) (*Response, error) { + var r = RollupGetRollupCapsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// RollupGetRollupCaps - +// +type RollupGetRollupCaps func(o ...func(*RollupGetRollupCapsRequest)) (*Response, error) + +// RollupGetRollupCapsRequest configures the Rollup Get Rollup Caps API request. +// +type RollupGetRollupCapsRequest struct { + Index string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r RollupGetRollupCapsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_rollup") + 1 + len("data") + 1 + len(r.Index)) + path.WriteString("/") + path.WriteString("_rollup") + path.WriteString("/") + path.WriteString("data") + if r.Index != "" { + path.WriteString("/") + path.WriteString(r.Index) + } + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f RollupGetRollupCaps) WithContext(v context.Context) func(*RollupGetRollupCapsRequest) { + return func(r *RollupGetRollupCapsRequest) { + r.ctx = v + } +} + +// WithIndex - the ID of the index to check rollup capabilities on, or left blank for all jobs. +// +func (f RollupGetRollupCaps) WithIndex(v string) func(*RollupGetRollupCapsRequest) { + return func(r *RollupGetRollupCapsRequest) { + r.Index = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f RollupGetRollupCaps) WithPretty() func(*RollupGetRollupCapsRequest) { + return func(r *RollupGetRollupCapsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f RollupGetRollupCaps) WithHuman() func(*RollupGetRollupCapsRequest) { + return func(r *RollupGetRollupCapsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f RollupGetRollupCaps) WithErrorTrace() func(*RollupGetRollupCapsRequest) { + return func(r *RollupGetRollupCapsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f RollupGetRollupCaps) WithFilterPath(v ...string) func(*RollupGetRollupCapsRequest) { + return func(r *RollupGetRollupCapsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f RollupGetRollupCaps) WithHeader(h map[string]string) func(*RollupGetRollupCapsRequest) { + return func(r *RollupGetRollupCapsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f RollupGetRollupCaps) WithOpaqueID(s string) func(*RollupGetRollupCapsRequest) { + return func(r *RollupGetRollupCapsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.get_rollup_index_caps.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.get_rollup_index_caps.go new file mode 100644 index 00000000000..42052a1a96c --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.get_rollup_index_caps.go @@ -0,0 +1,188 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newRollupGetRollupIndexCapsFunc(t Transport) RollupGetRollupIndexCaps { + return func(index string, o ...func(*RollupGetRollupIndexCapsRequest)) (*Response, error) { + var r = RollupGetRollupIndexCapsRequest{Index: index} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// RollupGetRollupIndexCaps - +// +type RollupGetRollupIndexCaps func(index string, o ...func(*RollupGetRollupIndexCapsRequest)) (*Response, error) + +// RollupGetRollupIndexCapsRequest configures the Rollup Get Rollup Index Caps API request. +// +type RollupGetRollupIndexCapsRequest struct { + Index string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r RollupGetRollupIndexCapsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(r.Index) + 1 + len("_rollup") + 1 + len("data")) + path.WriteString("/") + path.WriteString(r.Index) + path.WriteString("/") + path.WriteString("_rollup") + path.WriteString("/") + path.WriteString("data") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f RollupGetRollupIndexCaps) WithContext(v context.Context) func(*RollupGetRollupIndexCapsRequest) { + return func(r *RollupGetRollupIndexCapsRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f RollupGetRollupIndexCaps) WithPretty() func(*RollupGetRollupIndexCapsRequest) { + return func(r *RollupGetRollupIndexCapsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f RollupGetRollupIndexCaps) WithHuman() func(*RollupGetRollupIndexCapsRequest) { + return func(r *RollupGetRollupIndexCapsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f RollupGetRollupIndexCaps) WithErrorTrace() func(*RollupGetRollupIndexCapsRequest) { + return func(r *RollupGetRollupIndexCapsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f RollupGetRollupIndexCaps) WithFilterPath(v ...string) func(*RollupGetRollupIndexCapsRequest) { + return func(r *RollupGetRollupIndexCapsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f RollupGetRollupIndexCaps) WithHeader(h map[string]string) func(*RollupGetRollupIndexCapsRequest) { + return func(r *RollupGetRollupIndexCapsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f RollupGetRollupIndexCaps) WithOpaqueID(s string) func(*RollupGetRollupIndexCapsRequest) { + return func(r *RollupGetRollupIndexCapsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.put_job.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.put_job.go new file mode 100644 index 00000000000..7a67b3cb588 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.put_job.go @@ -0,0 +1,195 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newRollupPutJobFunc(t Transport) RollupPutJob { + return func(id string, body io.Reader, o ...func(*RollupPutJobRequest)) (*Response, error) { + var r = RollupPutJobRequest{JobID: id, Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// RollupPutJob - +// +type RollupPutJob func(id string, body io.Reader, o ...func(*RollupPutJobRequest)) (*Response, error) + +// RollupPutJobRequest configures the Rollup Put Job API request. +// +type RollupPutJobRequest struct { + JobID string + + Body io.Reader + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r RollupPutJobRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_rollup") + 1 + len("job") + 1 + len(r.JobID)) + path.WriteString("/") + path.WriteString("_rollup") + path.WriteString("/") + path.WriteString("job") + path.WriteString("/") + path.WriteString(r.JobID) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f RollupPutJob) WithContext(v context.Context) func(*RollupPutJobRequest) { + return func(r *RollupPutJobRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f RollupPutJob) WithPretty() func(*RollupPutJobRequest) { + return func(r *RollupPutJobRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f RollupPutJob) WithHuman() func(*RollupPutJobRequest) { + return func(r *RollupPutJobRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f RollupPutJob) WithErrorTrace() func(*RollupPutJobRequest) { + return func(r *RollupPutJobRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f RollupPutJob) WithFilterPath(v ...string) func(*RollupPutJobRequest) { + return func(r *RollupPutJobRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f RollupPutJob) WithHeader(h map[string]string) func(*RollupPutJobRequest) { + return func(r *RollupPutJobRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f RollupPutJob) WithOpaqueID(s string) func(*RollupPutJobRequest) { + return func(r *RollupPutJobRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.rollup_search.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.rollup_search.go new file mode 100644 index 00000000000..60d5ffbe9bf --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.rollup_search.go @@ -0,0 +1,234 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newRollupRollupSearchFunc(t Transport) RollupRollupSearch { + return func(index []string, body io.Reader, o ...func(*RollupRollupSearchRequest)) (*Response, error) { + var r = RollupRollupSearchRequest{Index: index, Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// RollupRollupSearch - +// +type RollupRollupSearch func(index []string, body io.Reader, o ...func(*RollupRollupSearchRequest)) (*Response, error) + +// RollupRollupSearchRequest configures the Rollup Rollup Search API request. +// +type RollupRollupSearchRequest struct { + Index []string + DocumentType string + + Body io.Reader + + RestTotalHitsAsInt *bool + TypedKeys *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r RollupRollupSearchRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len(r.DocumentType) + 1 + len("_rollup_search")) + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + if r.DocumentType != "" { + path.WriteString("/") + path.WriteString(r.DocumentType) + } + path.WriteString("/") + path.WriteString("_rollup_search") + + params = make(map[string]string) + + if r.RestTotalHitsAsInt != nil { + params["rest_total_hits_as_int"] = strconv.FormatBool(*r.RestTotalHitsAsInt) + } + + if r.TypedKeys != nil { + params["typed_keys"] = strconv.FormatBool(*r.TypedKeys) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f RollupRollupSearch) WithContext(v context.Context) func(*RollupRollupSearchRequest) { + return func(r *RollupRollupSearchRequest) { + r.ctx = v + } +} + +// WithDocumentType - the doc type inside the index. +// +func (f RollupRollupSearch) WithDocumentType(v string) func(*RollupRollupSearchRequest) { + return func(r *RollupRollupSearchRequest) { + r.DocumentType = v + } +} + +// WithRestTotalHitsAsInt - indicates whether hits.total should be rendered as an integer or an object in the rest search response. +// +func (f RollupRollupSearch) WithRestTotalHitsAsInt(v bool) func(*RollupRollupSearchRequest) { + return func(r *RollupRollupSearchRequest) { + r.RestTotalHitsAsInt = &v + } +} + +// WithTypedKeys - specify whether aggregation and suggester names should be prefixed by their respective types in the response. +// +func (f RollupRollupSearch) WithTypedKeys(v bool) func(*RollupRollupSearchRequest) { + return func(r *RollupRollupSearchRequest) { + r.TypedKeys = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f RollupRollupSearch) WithPretty() func(*RollupRollupSearchRequest) { + return func(r *RollupRollupSearchRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f RollupRollupSearch) WithHuman() func(*RollupRollupSearchRequest) { + return func(r *RollupRollupSearchRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f RollupRollupSearch) WithErrorTrace() func(*RollupRollupSearchRequest) { + return func(r *RollupRollupSearchRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f RollupRollupSearch) WithFilterPath(v ...string) func(*RollupRollupSearchRequest) { + return func(r *RollupRollupSearchRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f RollupRollupSearch) WithHeader(h map[string]string) func(*RollupRollupSearchRequest) { + return func(r *RollupRollupSearchRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f RollupRollupSearch) WithOpaqueID(s string) func(*RollupRollupSearchRequest) { + return func(r *RollupRollupSearchRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.start_job.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.start_job.go new file mode 100644 index 00000000000..c0befa84135 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.start_job.go @@ -0,0 +1,190 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newRollupStartJobFunc(t Transport) RollupStartJob { + return func(id string, o ...func(*RollupStartJobRequest)) (*Response, error) { + var r = RollupStartJobRequest{JobID: id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// RollupStartJob - +// +type RollupStartJob func(id string, o ...func(*RollupStartJobRequest)) (*Response, error) + +// RollupStartJobRequest configures the Rollup Start Job API request. +// +type RollupStartJobRequest struct { + JobID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r RollupStartJobRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_rollup") + 1 + len("job") + 1 + len(r.JobID) + 1 + len("_start")) + path.WriteString("/") + path.WriteString("_rollup") + path.WriteString("/") + path.WriteString("job") + path.WriteString("/") + path.WriteString(r.JobID) + path.WriteString("/") + path.WriteString("_start") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f RollupStartJob) WithContext(v context.Context) func(*RollupStartJobRequest) { + return func(r *RollupStartJobRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f RollupStartJob) WithPretty() func(*RollupStartJobRequest) { + return func(r *RollupStartJobRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f RollupStartJob) WithHuman() func(*RollupStartJobRequest) { + return func(r *RollupStartJobRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f RollupStartJob) WithErrorTrace() func(*RollupStartJobRequest) { + return func(r *RollupStartJobRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f RollupStartJob) WithFilterPath(v ...string) func(*RollupStartJobRequest) { + return func(r *RollupStartJobRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f RollupStartJob) WithHeader(h map[string]string) func(*RollupStartJobRequest) { + return func(r *RollupStartJobRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f RollupStartJob) WithOpaqueID(s string) func(*RollupStartJobRequest) { + return func(r *RollupStartJobRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.stop_job.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.stop_job.go new file mode 100644 index 00000000000..eb90a50404e --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.rollup.stop_job.go @@ -0,0 +1,219 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newRollupStopJobFunc(t Transport) RollupStopJob { + return func(id string, o ...func(*RollupStopJobRequest)) (*Response, error) { + var r = RollupStopJobRequest{JobID: id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// RollupStopJob - +// +type RollupStopJob func(id string, o ...func(*RollupStopJobRequest)) (*Response, error) + +// RollupStopJobRequest configures the Rollup Stop Job API request. +// +type RollupStopJobRequest struct { + JobID string + + Timeout time.Duration + WaitForCompletion *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r RollupStopJobRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_rollup") + 1 + len("job") + 1 + len(r.JobID) + 1 + len("_stop")) + path.WriteString("/") + path.WriteString("_rollup") + path.WriteString("/") + path.WriteString("job") + path.WriteString("/") + path.WriteString(r.JobID) + path.WriteString("/") + path.WriteString("_stop") + + params = make(map[string]string) + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.WaitForCompletion != nil { + params["wait_for_completion"] = strconv.FormatBool(*r.WaitForCompletion) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f RollupStopJob) WithContext(v context.Context) func(*RollupStopJobRequest) { + return func(r *RollupStopJobRequest) { + r.ctx = v + } +} + +// WithTimeout - block for (at maximum) the specified duration while waiting for the job to stop. defaults to 30s.. +// +func (f RollupStopJob) WithTimeout(v time.Duration) func(*RollupStopJobRequest) { + return func(r *RollupStopJobRequest) { + r.Timeout = v + } +} + +// WithWaitForCompletion - true if the api should block until the job has fully stopped, false if should be executed async. defaults to false.. +// +func (f RollupStopJob) WithWaitForCompletion(v bool) func(*RollupStopJobRequest) { + return func(r *RollupStopJobRequest) { + r.WaitForCompletion = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f RollupStopJob) WithPretty() func(*RollupStopJobRequest) { + return func(r *RollupStopJobRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f RollupStopJob) WithHuman() func(*RollupStopJobRequest) { + return func(r *RollupStopJobRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f RollupStopJob) WithErrorTrace() func(*RollupStopJobRequest) { + return func(r *RollupStopJobRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f RollupStopJob) WithFilterPath(v ...string) func(*RollupStopJobRequest) { + return func(r *RollupStopJobRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f RollupStopJob) WithHeader(h map[string]string) func(*RollupStopJobRequest) { + return func(r *RollupStopJobRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f RollupStopJob) WithOpaqueID(s string) func(*RollupStopJobRequest) { + return func(r *RollupStopJobRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.authenticate.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.authenticate.go new file mode 100644 index 00000000000..0cc29002034 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.authenticate.go @@ -0,0 +1,183 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newSecurityAuthenticateFunc(t Transport) SecurityAuthenticate { + return func(o ...func(*SecurityAuthenticateRequest)) (*Response, error) { + var r = SecurityAuthenticateRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityAuthenticate - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-authenticate.html. +// +type SecurityAuthenticate func(o ...func(*SecurityAuthenticateRequest)) (*Response, error) + +// SecurityAuthenticateRequest configures the Security Authenticate API request. +// +type SecurityAuthenticateRequest struct { + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityAuthenticateRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_security/_authenticate")) + path.WriteString("/_security/_authenticate") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityAuthenticate) WithContext(v context.Context) func(*SecurityAuthenticateRequest) { + return func(r *SecurityAuthenticateRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityAuthenticate) WithPretty() func(*SecurityAuthenticateRequest) { + return func(r *SecurityAuthenticateRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityAuthenticate) WithHuman() func(*SecurityAuthenticateRequest) { + return func(r *SecurityAuthenticateRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityAuthenticate) WithErrorTrace() func(*SecurityAuthenticateRequest) { + return func(r *SecurityAuthenticateRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityAuthenticate) WithFilterPath(v ...string) func(*SecurityAuthenticateRequest) { + return func(r *SecurityAuthenticateRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityAuthenticate) WithHeader(h map[string]string) func(*SecurityAuthenticateRequest) { + return func(r *SecurityAuthenticateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityAuthenticate) WithOpaqueID(s string) func(*SecurityAuthenticateRequest) { + return func(r *SecurityAuthenticateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.change_password.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.change_password.go new file mode 100644 index 00000000000..97ac124d39b --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.change_password.go @@ -0,0 +1,223 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newSecurityChangePasswordFunc(t Transport) SecurityChangePassword { + return func(body io.Reader, o ...func(*SecurityChangePasswordRequest)) (*Response, error) { + var r = SecurityChangePasswordRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityChangePassword - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-change-password.html. +// +type SecurityChangePassword func(body io.Reader, o ...func(*SecurityChangePasswordRequest)) (*Response, error) + +// SecurityChangePasswordRequest configures the Security Change Password API request. +// +type SecurityChangePasswordRequest struct { + Body io.Reader + + Username string + + Refresh string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityChangePasswordRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_security") + 1 + len("user") + 1 + len(r.Username) + 1 + len("_password")) + path.WriteString("/") + path.WriteString("_security") + path.WriteString("/") + path.WriteString("user") + if r.Username != "" { + path.WriteString("/") + path.WriteString(r.Username) + } + path.WriteString("/") + path.WriteString("_password") + + params = make(map[string]string) + + if r.Refresh != "" { + params["refresh"] = r.Refresh + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityChangePassword) WithContext(v context.Context) func(*SecurityChangePasswordRequest) { + return func(r *SecurityChangePasswordRequest) { + r.ctx = v + } +} + +// WithUsername - the username of the user to change the password for. +// +func (f SecurityChangePassword) WithUsername(v string) func(*SecurityChangePasswordRequest) { + return func(r *SecurityChangePasswordRequest) { + r.Username = v + } +} + +// WithRefresh - if `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes.. +// +func (f SecurityChangePassword) WithRefresh(v string) func(*SecurityChangePasswordRequest) { + return func(r *SecurityChangePasswordRequest) { + r.Refresh = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityChangePassword) WithPretty() func(*SecurityChangePasswordRequest) { + return func(r *SecurityChangePasswordRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityChangePassword) WithHuman() func(*SecurityChangePasswordRequest) { + return func(r *SecurityChangePasswordRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityChangePassword) WithErrorTrace() func(*SecurityChangePasswordRequest) { + return func(r *SecurityChangePasswordRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityChangePassword) WithFilterPath(v ...string) func(*SecurityChangePasswordRequest) { + return func(r *SecurityChangePasswordRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityChangePassword) WithHeader(h map[string]string) func(*SecurityChangePasswordRequest) { + return func(r *SecurityChangePasswordRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityChangePassword) WithOpaqueID(s string) func(*SecurityChangePasswordRequest) { + return func(r *SecurityChangePasswordRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.clear_cached_realms.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.clear_cached_realms.go new file mode 100644 index 00000000000..232d62103a8 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.clear_cached_realms.go @@ -0,0 +1,206 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newSecurityClearCachedRealmsFunc(t Transport) SecurityClearCachedRealms { + return func(realms []string, o ...func(*SecurityClearCachedRealmsRequest)) (*Response, error) { + var r = SecurityClearCachedRealmsRequest{Realms: realms} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityClearCachedRealms - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-clear-cache.html. +// +type SecurityClearCachedRealms func(realms []string, o ...func(*SecurityClearCachedRealmsRequest)) (*Response, error) + +// SecurityClearCachedRealmsRequest configures the Security Clear Cached Realms API request. +// +type SecurityClearCachedRealmsRequest struct { + Realms []string + + Usernames []string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityClearCachedRealmsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_security") + 1 + len("realm") + 1 + len(strings.Join(r.Realms, ",")) + 1 + len("_clear_cache")) + path.WriteString("/") + path.WriteString("_security") + path.WriteString("/") + path.WriteString("realm") + path.WriteString("/") + path.WriteString(strings.Join(r.Realms, ",")) + path.WriteString("/") + path.WriteString("_clear_cache") + + params = make(map[string]string) + + if len(r.Usernames) > 0 { + params["usernames"] = strings.Join(r.Usernames, ",") + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityClearCachedRealms) WithContext(v context.Context) func(*SecurityClearCachedRealmsRequest) { + return func(r *SecurityClearCachedRealmsRequest) { + r.ctx = v + } +} + +// WithUsernames - comma-separated list of usernames to clear from the cache. +// +func (f SecurityClearCachedRealms) WithUsernames(v ...string) func(*SecurityClearCachedRealmsRequest) { + return func(r *SecurityClearCachedRealmsRequest) { + r.Usernames = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityClearCachedRealms) WithPretty() func(*SecurityClearCachedRealmsRequest) { + return func(r *SecurityClearCachedRealmsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityClearCachedRealms) WithHuman() func(*SecurityClearCachedRealmsRequest) { + return func(r *SecurityClearCachedRealmsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityClearCachedRealms) WithErrorTrace() func(*SecurityClearCachedRealmsRequest) { + return func(r *SecurityClearCachedRealmsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityClearCachedRealms) WithFilterPath(v ...string) func(*SecurityClearCachedRealmsRequest) { + return func(r *SecurityClearCachedRealmsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityClearCachedRealms) WithHeader(h map[string]string) func(*SecurityClearCachedRealmsRequest) { + return func(r *SecurityClearCachedRealmsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityClearCachedRealms) WithOpaqueID(s string) func(*SecurityClearCachedRealmsRequest) { + return func(r *SecurityClearCachedRealmsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.clear_cached_roles.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.clear_cached_roles.go new file mode 100644 index 00000000000..9cea0c72fea --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.clear_cached_roles.go @@ -0,0 +1,192 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newSecurityClearCachedRolesFunc(t Transport) SecurityClearCachedRoles { + return func(name []string, o ...func(*SecurityClearCachedRolesRequest)) (*Response, error) { + var r = SecurityClearCachedRolesRequest{Name: name} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityClearCachedRoles - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-clear-role-cache.html. +// +type SecurityClearCachedRoles func(name []string, o ...func(*SecurityClearCachedRolesRequest)) (*Response, error) + +// SecurityClearCachedRolesRequest configures the Security Clear Cached Roles API request. +// +type SecurityClearCachedRolesRequest struct { + Name []string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityClearCachedRolesRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_security") + 1 + len("role") + 1 + len(strings.Join(r.Name, ",")) + 1 + len("_clear_cache")) + path.WriteString("/") + path.WriteString("_security") + path.WriteString("/") + path.WriteString("role") + path.WriteString("/") + path.WriteString(strings.Join(r.Name, ",")) + path.WriteString("/") + path.WriteString("_clear_cache") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityClearCachedRoles) WithContext(v context.Context) func(*SecurityClearCachedRolesRequest) { + return func(r *SecurityClearCachedRolesRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityClearCachedRoles) WithPretty() func(*SecurityClearCachedRolesRequest) { + return func(r *SecurityClearCachedRolesRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityClearCachedRoles) WithHuman() func(*SecurityClearCachedRolesRequest) { + return func(r *SecurityClearCachedRolesRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityClearCachedRoles) WithErrorTrace() func(*SecurityClearCachedRolesRequest) { + return func(r *SecurityClearCachedRolesRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityClearCachedRoles) WithFilterPath(v ...string) func(*SecurityClearCachedRolesRequest) { + return func(r *SecurityClearCachedRolesRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityClearCachedRoles) WithHeader(h map[string]string) func(*SecurityClearCachedRolesRequest) { + return func(r *SecurityClearCachedRolesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityClearCachedRoles) WithOpaqueID(s string) func(*SecurityClearCachedRolesRequest) { + return func(r *SecurityClearCachedRolesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.create_api_key.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.create_api_key.go new file mode 100644 index 00000000000..5b20bcf36d7 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.create_api_key.go @@ -0,0 +1,204 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newSecurityCreateAPIKeyFunc(t Transport) SecurityCreateAPIKey { + return func(body io.Reader, o ...func(*SecurityCreateAPIKeyRequest)) (*Response, error) { + var r = SecurityCreateAPIKeyRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityCreateAPIKey - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html. +// +type SecurityCreateAPIKey func(body io.Reader, o ...func(*SecurityCreateAPIKeyRequest)) (*Response, error) + +// SecurityCreateAPIKeyRequest configures the Security CreateAPI Key API request. +// +type SecurityCreateAPIKeyRequest struct { + Body io.Reader + + Refresh string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityCreateAPIKeyRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(len("/_security/api_key")) + path.WriteString("/_security/api_key") + + params = make(map[string]string) + + if r.Refresh != "" { + params["refresh"] = r.Refresh + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityCreateAPIKey) WithContext(v context.Context) func(*SecurityCreateAPIKeyRequest) { + return func(r *SecurityCreateAPIKeyRequest) { + r.ctx = v + } +} + +// WithRefresh - if `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes.. +// +func (f SecurityCreateAPIKey) WithRefresh(v string) func(*SecurityCreateAPIKeyRequest) { + return func(r *SecurityCreateAPIKeyRequest) { + r.Refresh = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityCreateAPIKey) WithPretty() func(*SecurityCreateAPIKeyRequest) { + return func(r *SecurityCreateAPIKeyRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityCreateAPIKey) WithHuman() func(*SecurityCreateAPIKeyRequest) { + return func(r *SecurityCreateAPIKeyRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityCreateAPIKey) WithErrorTrace() func(*SecurityCreateAPIKeyRequest) { + return func(r *SecurityCreateAPIKeyRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityCreateAPIKey) WithFilterPath(v ...string) func(*SecurityCreateAPIKeyRequest) { + return func(r *SecurityCreateAPIKeyRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityCreateAPIKey) WithHeader(h map[string]string) func(*SecurityCreateAPIKeyRequest) { + return func(r *SecurityCreateAPIKeyRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityCreateAPIKey) WithOpaqueID(s string) func(*SecurityCreateAPIKeyRequest) { + return func(r *SecurityCreateAPIKeyRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.delete_privileges.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.delete_privileges.go new file mode 100644 index 00000000000..15bb33a36dd --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.delete_privileges.go @@ -0,0 +1,205 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newSecurityDeletePrivilegesFunc(t Transport) SecurityDeletePrivileges { + return func(name string, application string, o ...func(*SecurityDeletePrivilegesRequest)) (*Response, error) { + var r = SecurityDeletePrivilegesRequest{Name: name, Application: application} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityDeletePrivileges - TODO +// +type SecurityDeletePrivileges func(name string, application string, o ...func(*SecurityDeletePrivilegesRequest)) (*Response, error) + +// SecurityDeletePrivilegesRequest configures the Security Delete Privileges API request. +// +type SecurityDeletePrivilegesRequest struct { + Application string + Name string + + Refresh string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityDeletePrivilegesRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_security") + 1 + len("privilege") + 1 + len(r.Application) + 1 + len(r.Name)) + path.WriteString("/") + path.WriteString("_security") + path.WriteString("/") + path.WriteString("privilege") + path.WriteString("/") + path.WriteString(r.Application) + path.WriteString("/") + path.WriteString(r.Name) + + params = make(map[string]string) + + if r.Refresh != "" { + params["refresh"] = r.Refresh + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityDeletePrivileges) WithContext(v context.Context) func(*SecurityDeletePrivilegesRequest) { + return func(r *SecurityDeletePrivilegesRequest) { + r.ctx = v + } +} + +// WithRefresh - if `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes.. +// +func (f SecurityDeletePrivileges) WithRefresh(v string) func(*SecurityDeletePrivilegesRequest) { + return func(r *SecurityDeletePrivilegesRequest) { + r.Refresh = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityDeletePrivileges) WithPretty() func(*SecurityDeletePrivilegesRequest) { + return func(r *SecurityDeletePrivilegesRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityDeletePrivileges) WithHuman() func(*SecurityDeletePrivilegesRequest) { + return func(r *SecurityDeletePrivilegesRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityDeletePrivileges) WithErrorTrace() func(*SecurityDeletePrivilegesRequest) { + return func(r *SecurityDeletePrivilegesRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityDeletePrivileges) WithFilterPath(v ...string) func(*SecurityDeletePrivilegesRequest) { + return func(r *SecurityDeletePrivilegesRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityDeletePrivileges) WithHeader(h map[string]string) func(*SecurityDeletePrivilegesRequest) { + return func(r *SecurityDeletePrivilegesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityDeletePrivileges) WithOpaqueID(s string) func(*SecurityDeletePrivilegesRequest) { + return func(r *SecurityDeletePrivilegesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.delete_role.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.delete_role.go new file mode 100644 index 00000000000..d83a274eca2 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.delete_role.go @@ -0,0 +1,204 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newSecurityDeleteRoleFunc(t Transport) SecurityDeleteRole { + return func(name string, o ...func(*SecurityDeleteRoleRequest)) (*Response, error) { + var r = SecurityDeleteRoleRequest{Name: name} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityDeleteRole - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-delete-role.html. +// +type SecurityDeleteRole func(name string, o ...func(*SecurityDeleteRoleRequest)) (*Response, error) + +// SecurityDeleteRoleRequest configures the Security Delete Role API request. +// +type SecurityDeleteRoleRequest struct { + Name string + + Refresh string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityDeleteRoleRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_security") + 1 + len("role") + 1 + len(r.Name)) + path.WriteString("/") + path.WriteString("_security") + path.WriteString("/") + path.WriteString("role") + path.WriteString("/") + path.WriteString(r.Name) + + params = make(map[string]string) + + if r.Refresh != "" { + params["refresh"] = r.Refresh + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityDeleteRole) WithContext(v context.Context) func(*SecurityDeleteRoleRequest) { + return func(r *SecurityDeleteRoleRequest) { + r.ctx = v + } +} + +// WithRefresh - if `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes.. +// +func (f SecurityDeleteRole) WithRefresh(v string) func(*SecurityDeleteRoleRequest) { + return func(r *SecurityDeleteRoleRequest) { + r.Refresh = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityDeleteRole) WithPretty() func(*SecurityDeleteRoleRequest) { + return func(r *SecurityDeleteRoleRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityDeleteRole) WithHuman() func(*SecurityDeleteRoleRequest) { + return func(r *SecurityDeleteRoleRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityDeleteRole) WithErrorTrace() func(*SecurityDeleteRoleRequest) { + return func(r *SecurityDeleteRoleRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityDeleteRole) WithFilterPath(v ...string) func(*SecurityDeleteRoleRequest) { + return func(r *SecurityDeleteRoleRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityDeleteRole) WithHeader(h map[string]string) func(*SecurityDeleteRoleRequest) { + return func(r *SecurityDeleteRoleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityDeleteRole) WithOpaqueID(s string) func(*SecurityDeleteRoleRequest) { + return func(r *SecurityDeleteRoleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.delete_role_mapping.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.delete_role_mapping.go new file mode 100644 index 00000000000..26777738963 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.delete_role_mapping.go @@ -0,0 +1,204 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newSecurityDeleteRoleMappingFunc(t Transport) SecurityDeleteRoleMapping { + return func(name string, o ...func(*SecurityDeleteRoleMappingRequest)) (*Response, error) { + var r = SecurityDeleteRoleMappingRequest{Name: name} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityDeleteRoleMapping - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-delete-role-mapping.html. +// +type SecurityDeleteRoleMapping func(name string, o ...func(*SecurityDeleteRoleMappingRequest)) (*Response, error) + +// SecurityDeleteRoleMappingRequest configures the Security Delete Role Mapping API request. +// +type SecurityDeleteRoleMappingRequest struct { + Name string + + Refresh string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityDeleteRoleMappingRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_security") + 1 + len("role_mapping") + 1 + len(r.Name)) + path.WriteString("/") + path.WriteString("_security") + path.WriteString("/") + path.WriteString("role_mapping") + path.WriteString("/") + path.WriteString(r.Name) + + params = make(map[string]string) + + if r.Refresh != "" { + params["refresh"] = r.Refresh + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityDeleteRoleMapping) WithContext(v context.Context) func(*SecurityDeleteRoleMappingRequest) { + return func(r *SecurityDeleteRoleMappingRequest) { + r.ctx = v + } +} + +// WithRefresh - if `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes.. +// +func (f SecurityDeleteRoleMapping) WithRefresh(v string) func(*SecurityDeleteRoleMappingRequest) { + return func(r *SecurityDeleteRoleMappingRequest) { + r.Refresh = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityDeleteRoleMapping) WithPretty() func(*SecurityDeleteRoleMappingRequest) { + return func(r *SecurityDeleteRoleMappingRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityDeleteRoleMapping) WithHuman() func(*SecurityDeleteRoleMappingRequest) { + return func(r *SecurityDeleteRoleMappingRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityDeleteRoleMapping) WithErrorTrace() func(*SecurityDeleteRoleMappingRequest) { + return func(r *SecurityDeleteRoleMappingRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityDeleteRoleMapping) WithFilterPath(v ...string) func(*SecurityDeleteRoleMappingRequest) { + return func(r *SecurityDeleteRoleMappingRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityDeleteRoleMapping) WithHeader(h map[string]string) func(*SecurityDeleteRoleMappingRequest) { + return func(r *SecurityDeleteRoleMappingRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityDeleteRoleMapping) WithOpaqueID(s string) func(*SecurityDeleteRoleMappingRequest) { + return func(r *SecurityDeleteRoleMappingRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.delete_user.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.delete_user.go new file mode 100644 index 00000000000..9dbc8a62e31 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.delete_user.go @@ -0,0 +1,204 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newSecurityDeleteUserFunc(t Transport) SecurityDeleteUser { + return func(username string, o ...func(*SecurityDeleteUserRequest)) (*Response, error) { + var r = SecurityDeleteUserRequest{Username: username} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityDeleteUser - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-delete-user.html. +// +type SecurityDeleteUser func(username string, o ...func(*SecurityDeleteUserRequest)) (*Response, error) + +// SecurityDeleteUserRequest configures the Security Delete User API request. +// +type SecurityDeleteUserRequest struct { + Username string + + Refresh string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityDeleteUserRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_security") + 1 + len("user") + 1 + len(r.Username)) + path.WriteString("/") + path.WriteString("_security") + path.WriteString("/") + path.WriteString("user") + path.WriteString("/") + path.WriteString(r.Username) + + params = make(map[string]string) + + if r.Refresh != "" { + params["refresh"] = r.Refresh + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityDeleteUser) WithContext(v context.Context) func(*SecurityDeleteUserRequest) { + return func(r *SecurityDeleteUserRequest) { + r.ctx = v + } +} + +// WithRefresh - if `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes.. +// +func (f SecurityDeleteUser) WithRefresh(v string) func(*SecurityDeleteUserRequest) { + return func(r *SecurityDeleteUserRequest) { + r.Refresh = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityDeleteUser) WithPretty() func(*SecurityDeleteUserRequest) { + return func(r *SecurityDeleteUserRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityDeleteUser) WithHuman() func(*SecurityDeleteUserRequest) { + return func(r *SecurityDeleteUserRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityDeleteUser) WithErrorTrace() func(*SecurityDeleteUserRequest) { + return func(r *SecurityDeleteUserRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityDeleteUser) WithFilterPath(v ...string) func(*SecurityDeleteUserRequest) { + return func(r *SecurityDeleteUserRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityDeleteUser) WithHeader(h map[string]string) func(*SecurityDeleteUserRequest) { + return func(r *SecurityDeleteUserRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityDeleteUser) WithOpaqueID(s string) func(*SecurityDeleteUserRequest) { + return func(r *SecurityDeleteUserRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.disable_user.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.disable_user.go new file mode 100644 index 00000000000..c3e0a17eb95 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.disable_user.go @@ -0,0 +1,206 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newSecurityDisableUserFunc(t Transport) SecurityDisableUser { + return func(username string, o ...func(*SecurityDisableUserRequest)) (*Response, error) { + var r = SecurityDisableUserRequest{Username: username} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityDisableUser - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-disable-user.html. +// +type SecurityDisableUser func(username string, o ...func(*SecurityDisableUserRequest)) (*Response, error) + +// SecurityDisableUserRequest configures the Security Disable User API request. +// +type SecurityDisableUserRequest struct { + Username string + + Refresh string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityDisableUserRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_security") + 1 + len("user") + 1 + len(r.Username) + 1 + len("_disable")) + path.WriteString("/") + path.WriteString("_security") + path.WriteString("/") + path.WriteString("user") + path.WriteString("/") + path.WriteString(r.Username) + path.WriteString("/") + path.WriteString("_disable") + + params = make(map[string]string) + + if r.Refresh != "" { + params["refresh"] = r.Refresh + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityDisableUser) WithContext(v context.Context) func(*SecurityDisableUserRequest) { + return func(r *SecurityDisableUserRequest) { + r.ctx = v + } +} + +// WithRefresh - if `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes.. +// +func (f SecurityDisableUser) WithRefresh(v string) func(*SecurityDisableUserRequest) { + return func(r *SecurityDisableUserRequest) { + r.Refresh = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityDisableUser) WithPretty() func(*SecurityDisableUserRequest) { + return func(r *SecurityDisableUserRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityDisableUser) WithHuman() func(*SecurityDisableUserRequest) { + return func(r *SecurityDisableUserRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityDisableUser) WithErrorTrace() func(*SecurityDisableUserRequest) { + return func(r *SecurityDisableUserRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityDisableUser) WithFilterPath(v ...string) func(*SecurityDisableUserRequest) { + return func(r *SecurityDisableUserRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityDisableUser) WithHeader(h map[string]string) func(*SecurityDisableUserRequest) { + return func(r *SecurityDisableUserRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityDisableUser) WithOpaqueID(s string) func(*SecurityDisableUserRequest) { + return func(r *SecurityDisableUserRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.enable_user.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.enable_user.go new file mode 100644 index 00000000000..42a83cb89ea --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.enable_user.go @@ -0,0 +1,206 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newSecurityEnableUserFunc(t Transport) SecurityEnableUser { + return func(username string, o ...func(*SecurityEnableUserRequest)) (*Response, error) { + var r = SecurityEnableUserRequest{Username: username} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityEnableUser - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-enable-user.html. +// +type SecurityEnableUser func(username string, o ...func(*SecurityEnableUserRequest)) (*Response, error) + +// SecurityEnableUserRequest configures the Security Enable User API request. +// +type SecurityEnableUserRequest struct { + Username string + + Refresh string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityEnableUserRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_security") + 1 + len("user") + 1 + len(r.Username) + 1 + len("_enable")) + path.WriteString("/") + path.WriteString("_security") + path.WriteString("/") + path.WriteString("user") + path.WriteString("/") + path.WriteString(r.Username) + path.WriteString("/") + path.WriteString("_enable") + + params = make(map[string]string) + + if r.Refresh != "" { + params["refresh"] = r.Refresh + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityEnableUser) WithContext(v context.Context) func(*SecurityEnableUserRequest) { + return func(r *SecurityEnableUserRequest) { + r.ctx = v + } +} + +// WithRefresh - if `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes.. +// +func (f SecurityEnableUser) WithRefresh(v string) func(*SecurityEnableUserRequest) { + return func(r *SecurityEnableUserRequest) { + r.Refresh = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityEnableUser) WithPretty() func(*SecurityEnableUserRequest) { + return func(r *SecurityEnableUserRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityEnableUser) WithHuman() func(*SecurityEnableUserRequest) { + return func(r *SecurityEnableUserRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityEnableUser) WithErrorTrace() func(*SecurityEnableUserRequest) { + return func(r *SecurityEnableUserRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityEnableUser) WithFilterPath(v ...string) func(*SecurityEnableUserRequest) { + return func(r *SecurityEnableUserRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityEnableUser) WithHeader(h map[string]string) func(*SecurityEnableUserRequest) { + return func(r *SecurityEnableUserRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityEnableUser) WithOpaqueID(s string) func(*SecurityEnableUserRequest) { + return func(r *SecurityEnableUserRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_api_key.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_api_key.go new file mode 100644 index 00000000000..8ff563d60de --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_api_key.go @@ -0,0 +1,236 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newSecurityGetAPIKeyFunc(t Transport) SecurityGetAPIKey { + return func(o ...func(*SecurityGetAPIKeyRequest)) (*Response, error) { + var r = SecurityGetAPIKeyRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityGetAPIKey - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-api-key.html. +// +type SecurityGetAPIKey func(o ...func(*SecurityGetAPIKeyRequest)) (*Response, error) + +// SecurityGetAPIKeyRequest configures the Security GetAPI Key API request. +// +type SecurityGetAPIKeyRequest struct { + ID string + Name string + RealmName string + Username string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityGetAPIKeyRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_security/api_key")) + path.WriteString("/_security/api_key") + + params = make(map[string]string) + + if r.ID != "" { + params["id"] = r.ID + } + + if r.Name != "" { + params["name"] = r.Name + } + + if r.RealmName != "" { + params["realm_name"] = r.RealmName + } + + if r.Username != "" { + params["username"] = r.Username + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityGetAPIKey) WithContext(v context.Context) func(*SecurityGetAPIKeyRequest) { + return func(r *SecurityGetAPIKeyRequest) { + r.ctx = v + } +} + +// WithID - api key ID of the api key to be retrieved. +// +func (f SecurityGetAPIKey) WithID(v string) func(*SecurityGetAPIKeyRequest) { + return func(r *SecurityGetAPIKeyRequest) { + r.ID = v + } +} + +// WithName - api key name of the api key to be retrieved. +// +func (f SecurityGetAPIKey) WithName(v string) func(*SecurityGetAPIKeyRequest) { + return func(r *SecurityGetAPIKeyRequest) { + r.Name = v + } +} + +// WithRealmName - realm name of the user who created this api key to be retrieved. +// +func (f SecurityGetAPIKey) WithRealmName(v string) func(*SecurityGetAPIKeyRequest) { + return func(r *SecurityGetAPIKeyRequest) { + r.RealmName = v + } +} + +// WithUsername - user name of the user who created this api key to be retrieved. +// +func (f SecurityGetAPIKey) WithUsername(v string) func(*SecurityGetAPIKeyRequest) { + return func(r *SecurityGetAPIKeyRequest) { + r.Username = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityGetAPIKey) WithPretty() func(*SecurityGetAPIKeyRequest) { + return func(r *SecurityGetAPIKeyRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityGetAPIKey) WithHuman() func(*SecurityGetAPIKeyRequest) { + return func(r *SecurityGetAPIKeyRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityGetAPIKey) WithErrorTrace() func(*SecurityGetAPIKeyRequest) { + return func(r *SecurityGetAPIKeyRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityGetAPIKey) WithFilterPath(v ...string) func(*SecurityGetAPIKeyRequest) { + return func(r *SecurityGetAPIKeyRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityGetAPIKey) WithHeader(h map[string]string) func(*SecurityGetAPIKeyRequest) { + return func(r *SecurityGetAPIKeyRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityGetAPIKey) WithOpaqueID(s string) func(*SecurityGetAPIKeyRequest) { + return func(r *SecurityGetAPIKeyRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_builtin_privileges.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_builtin_privileges.go new file mode 100644 index 00000000000..8c272373bff --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_builtin_privileges.go @@ -0,0 +1,183 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newSecurityGetBuiltinPrivilegesFunc(t Transport) SecurityGetBuiltinPrivileges { + return func(o ...func(*SecurityGetBuiltinPrivilegesRequest)) (*Response, error) { + var r = SecurityGetBuiltinPrivilegesRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityGetBuiltinPrivileges - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-builtin-privileges.html. +// +type SecurityGetBuiltinPrivileges func(o ...func(*SecurityGetBuiltinPrivilegesRequest)) (*Response, error) + +// SecurityGetBuiltinPrivilegesRequest configures the Security Get Builtin Privileges API request. +// +type SecurityGetBuiltinPrivilegesRequest struct { + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityGetBuiltinPrivilegesRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_security/privilege/_builtin")) + path.WriteString("/_security/privilege/_builtin") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityGetBuiltinPrivileges) WithContext(v context.Context) func(*SecurityGetBuiltinPrivilegesRequest) { + return func(r *SecurityGetBuiltinPrivilegesRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityGetBuiltinPrivileges) WithPretty() func(*SecurityGetBuiltinPrivilegesRequest) { + return func(r *SecurityGetBuiltinPrivilegesRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityGetBuiltinPrivileges) WithHuman() func(*SecurityGetBuiltinPrivilegesRequest) { + return func(r *SecurityGetBuiltinPrivilegesRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityGetBuiltinPrivileges) WithErrorTrace() func(*SecurityGetBuiltinPrivilegesRequest) { + return func(r *SecurityGetBuiltinPrivilegesRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityGetBuiltinPrivileges) WithFilterPath(v ...string) func(*SecurityGetBuiltinPrivilegesRequest) { + return func(r *SecurityGetBuiltinPrivilegesRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityGetBuiltinPrivileges) WithHeader(h map[string]string) func(*SecurityGetBuiltinPrivilegesRequest) { + return func(r *SecurityGetBuiltinPrivilegesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityGetBuiltinPrivileges) WithOpaqueID(s string) func(*SecurityGetBuiltinPrivilegesRequest) { + return func(r *SecurityGetBuiltinPrivilegesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_privileges.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_privileges.go new file mode 100644 index 00000000000..f09c42c0123 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_privileges.go @@ -0,0 +1,213 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newSecurityGetPrivilegesFunc(t Transport) SecurityGetPrivileges { + return func(o ...func(*SecurityGetPrivilegesRequest)) (*Response, error) { + var r = SecurityGetPrivilegesRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityGetPrivileges - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-privileges.html. +// +type SecurityGetPrivileges func(o ...func(*SecurityGetPrivilegesRequest)) (*Response, error) + +// SecurityGetPrivilegesRequest configures the Security Get Privileges API request. +// +type SecurityGetPrivilegesRequest struct { + Application string + Name string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityGetPrivilegesRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_security") + 1 + len("privilege") + 1 + len(r.Application) + 1 + len(r.Name)) + path.WriteString("/") + path.WriteString("_security") + path.WriteString("/") + path.WriteString("privilege") + if r.Application != "" { + path.WriteString("/") + path.WriteString(r.Application) + } + if r.Name != "" { + path.WriteString("/") + path.WriteString(r.Name) + } + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityGetPrivileges) WithContext(v context.Context) func(*SecurityGetPrivilegesRequest) { + return func(r *SecurityGetPrivilegesRequest) { + r.ctx = v + } +} + +// WithApplication - application name. +// +func (f SecurityGetPrivileges) WithApplication(v string) func(*SecurityGetPrivilegesRequest) { + return func(r *SecurityGetPrivilegesRequest) { + r.Application = v + } +} + +// WithName - privilege name. +// +func (f SecurityGetPrivileges) WithName(v string) func(*SecurityGetPrivilegesRequest) { + return func(r *SecurityGetPrivilegesRequest) { + r.Name = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityGetPrivileges) WithPretty() func(*SecurityGetPrivilegesRequest) { + return func(r *SecurityGetPrivilegesRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityGetPrivileges) WithHuman() func(*SecurityGetPrivilegesRequest) { + return func(r *SecurityGetPrivilegesRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityGetPrivileges) WithErrorTrace() func(*SecurityGetPrivilegesRequest) { + return func(r *SecurityGetPrivilegesRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityGetPrivileges) WithFilterPath(v ...string) func(*SecurityGetPrivilegesRequest) { + return func(r *SecurityGetPrivilegesRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityGetPrivileges) WithHeader(h map[string]string) func(*SecurityGetPrivilegesRequest) { + return func(r *SecurityGetPrivilegesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityGetPrivileges) WithOpaqueID(s string) func(*SecurityGetPrivilegesRequest) { + return func(r *SecurityGetPrivilegesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_role.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_role.go new file mode 100644 index 00000000000..83685207acc --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_role.go @@ -0,0 +1,200 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newSecurityGetRoleFunc(t Transport) SecurityGetRole { + return func(o ...func(*SecurityGetRoleRequest)) (*Response, error) { + var r = SecurityGetRoleRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityGetRole - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-role.html. +// +type SecurityGetRole func(o ...func(*SecurityGetRoleRequest)) (*Response, error) + +// SecurityGetRoleRequest configures the Security Get Role API request. +// +type SecurityGetRoleRequest struct { + Name string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityGetRoleRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_security") + 1 + len("role") + 1 + len(r.Name)) + path.WriteString("/") + path.WriteString("_security") + path.WriteString("/") + path.WriteString("role") + if r.Name != "" { + path.WriteString("/") + path.WriteString(r.Name) + } + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityGetRole) WithContext(v context.Context) func(*SecurityGetRoleRequest) { + return func(r *SecurityGetRoleRequest) { + r.ctx = v + } +} + +// WithName - role name. +// +func (f SecurityGetRole) WithName(v string) func(*SecurityGetRoleRequest) { + return func(r *SecurityGetRoleRequest) { + r.Name = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityGetRole) WithPretty() func(*SecurityGetRoleRequest) { + return func(r *SecurityGetRoleRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityGetRole) WithHuman() func(*SecurityGetRoleRequest) { + return func(r *SecurityGetRoleRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityGetRole) WithErrorTrace() func(*SecurityGetRoleRequest) { + return func(r *SecurityGetRoleRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityGetRole) WithFilterPath(v ...string) func(*SecurityGetRoleRequest) { + return func(r *SecurityGetRoleRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityGetRole) WithHeader(h map[string]string) func(*SecurityGetRoleRequest) { + return func(r *SecurityGetRoleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityGetRole) WithOpaqueID(s string) func(*SecurityGetRoleRequest) { + return func(r *SecurityGetRoleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_role_mapping.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_role_mapping.go new file mode 100644 index 00000000000..d497feb3923 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_role_mapping.go @@ -0,0 +1,200 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newSecurityGetRoleMappingFunc(t Transport) SecurityGetRoleMapping { + return func(o ...func(*SecurityGetRoleMappingRequest)) (*Response, error) { + var r = SecurityGetRoleMappingRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityGetRoleMapping - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-role-mapping.html. +// +type SecurityGetRoleMapping func(o ...func(*SecurityGetRoleMappingRequest)) (*Response, error) + +// SecurityGetRoleMappingRequest configures the Security Get Role Mapping API request. +// +type SecurityGetRoleMappingRequest struct { + Name string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityGetRoleMappingRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_security") + 1 + len("role_mapping") + 1 + len(r.Name)) + path.WriteString("/") + path.WriteString("_security") + path.WriteString("/") + path.WriteString("role_mapping") + if r.Name != "" { + path.WriteString("/") + path.WriteString(r.Name) + } + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityGetRoleMapping) WithContext(v context.Context) func(*SecurityGetRoleMappingRequest) { + return func(r *SecurityGetRoleMappingRequest) { + r.ctx = v + } +} + +// WithName - role-mapping name. +// +func (f SecurityGetRoleMapping) WithName(v string) func(*SecurityGetRoleMappingRequest) { + return func(r *SecurityGetRoleMappingRequest) { + r.Name = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityGetRoleMapping) WithPretty() func(*SecurityGetRoleMappingRequest) { + return func(r *SecurityGetRoleMappingRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityGetRoleMapping) WithHuman() func(*SecurityGetRoleMappingRequest) { + return func(r *SecurityGetRoleMappingRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityGetRoleMapping) WithErrorTrace() func(*SecurityGetRoleMappingRequest) { + return func(r *SecurityGetRoleMappingRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityGetRoleMapping) WithFilterPath(v ...string) func(*SecurityGetRoleMappingRequest) { + return func(r *SecurityGetRoleMappingRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityGetRoleMapping) WithHeader(h map[string]string) func(*SecurityGetRoleMappingRequest) { + return func(r *SecurityGetRoleMappingRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityGetRoleMapping) WithOpaqueID(s string) func(*SecurityGetRoleMappingRequest) { + return func(r *SecurityGetRoleMappingRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_token.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_token.go new file mode 100644 index 00000000000..388cbdfb5eb --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_token.go @@ -0,0 +1,190 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newSecurityGetTokenFunc(t Transport) SecurityGetToken { + return func(body io.Reader, o ...func(*SecurityGetTokenRequest)) (*Response, error) { + var r = SecurityGetTokenRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityGetToken - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-token.html. +// +type SecurityGetToken func(body io.Reader, o ...func(*SecurityGetTokenRequest)) (*Response, error) + +// SecurityGetTokenRequest configures the Security Get Token API request. +// +type SecurityGetTokenRequest struct { + Body io.Reader + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityGetTokenRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(len("/_security/oauth2/token")) + path.WriteString("/_security/oauth2/token") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityGetToken) WithContext(v context.Context) func(*SecurityGetTokenRequest) { + return func(r *SecurityGetTokenRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityGetToken) WithPretty() func(*SecurityGetTokenRequest) { + return func(r *SecurityGetTokenRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityGetToken) WithHuman() func(*SecurityGetTokenRequest) { + return func(r *SecurityGetTokenRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityGetToken) WithErrorTrace() func(*SecurityGetTokenRequest) { + return func(r *SecurityGetTokenRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityGetToken) WithFilterPath(v ...string) func(*SecurityGetTokenRequest) { + return func(r *SecurityGetTokenRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityGetToken) WithHeader(h map[string]string) func(*SecurityGetTokenRequest) { + return func(r *SecurityGetTokenRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityGetToken) WithOpaqueID(s string) func(*SecurityGetTokenRequest) { + return func(r *SecurityGetTokenRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_user.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_user.go new file mode 100644 index 00000000000..cda13f590a9 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_user.go @@ -0,0 +1,200 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newSecurityGetUserFunc(t Transport) SecurityGetUser { + return func(o ...func(*SecurityGetUserRequest)) (*Response, error) { + var r = SecurityGetUserRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityGetUser - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-user.html. +// +type SecurityGetUser func(o ...func(*SecurityGetUserRequest)) (*Response, error) + +// SecurityGetUserRequest configures the Security Get User API request. +// +type SecurityGetUserRequest struct { + Username []string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityGetUserRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_security") + 1 + len("user") + 1 + len(strings.Join(r.Username, ","))) + path.WriteString("/") + path.WriteString("_security") + path.WriteString("/") + path.WriteString("user") + if len(r.Username) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Username, ",")) + } + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityGetUser) WithContext(v context.Context) func(*SecurityGetUserRequest) { + return func(r *SecurityGetUserRequest) { + r.ctx = v + } +} + +// WithUsername - a list of usernames. +// +func (f SecurityGetUser) WithUsername(v ...string) func(*SecurityGetUserRequest) { + return func(r *SecurityGetUserRequest) { + r.Username = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityGetUser) WithPretty() func(*SecurityGetUserRequest) { + return func(r *SecurityGetUserRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityGetUser) WithHuman() func(*SecurityGetUserRequest) { + return func(r *SecurityGetUserRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityGetUser) WithErrorTrace() func(*SecurityGetUserRequest) { + return func(r *SecurityGetUserRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityGetUser) WithFilterPath(v ...string) func(*SecurityGetUserRequest) { + return func(r *SecurityGetUserRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityGetUser) WithHeader(h map[string]string) func(*SecurityGetUserRequest) { + return func(r *SecurityGetUserRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityGetUser) WithOpaqueID(s string) func(*SecurityGetUserRequest) { + return func(r *SecurityGetUserRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_user_privileges.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_user_privileges.go new file mode 100644 index 00000000000..a9d4c1ae3b3 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_user_privileges.go @@ -0,0 +1,183 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newSecurityGetUserPrivilegesFunc(t Transport) SecurityGetUserPrivileges { + return func(o ...func(*SecurityGetUserPrivilegesRequest)) (*Response, error) { + var r = SecurityGetUserPrivilegesRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityGetUserPrivileges - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-privileges.html. +// +type SecurityGetUserPrivileges func(o ...func(*SecurityGetUserPrivilegesRequest)) (*Response, error) + +// SecurityGetUserPrivilegesRequest configures the Security Get User Privileges API request. +// +type SecurityGetUserPrivilegesRequest struct { + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityGetUserPrivilegesRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_security/user/_privileges")) + path.WriteString("/_security/user/_privileges") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityGetUserPrivileges) WithContext(v context.Context) func(*SecurityGetUserPrivilegesRequest) { + return func(r *SecurityGetUserPrivilegesRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityGetUserPrivileges) WithPretty() func(*SecurityGetUserPrivilegesRequest) { + return func(r *SecurityGetUserPrivilegesRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityGetUserPrivileges) WithHuman() func(*SecurityGetUserPrivilegesRequest) { + return func(r *SecurityGetUserPrivilegesRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityGetUserPrivileges) WithErrorTrace() func(*SecurityGetUserPrivilegesRequest) { + return func(r *SecurityGetUserPrivilegesRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityGetUserPrivileges) WithFilterPath(v ...string) func(*SecurityGetUserPrivilegesRequest) { + return func(r *SecurityGetUserPrivilegesRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityGetUserPrivileges) WithHeader(h map[string]string) func(*SecurityGetUserPrivilegesRequest) { + return func(r *SecurityGetUserPrivilegesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityGetUserPrivileges) WithOpaqueID(s string) func(*SecurityGetUserPrivilegesRequest) { + return func(r *SecurityGetUserPrivilegesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.has_privileges.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.has_privileges.go new file mode 100644 index 00000000000..4112c08affb --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.has_privileges.go @@ -0,0 +1,209 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newSecurityHasPrivilegesFunc(t Transport) SecurityHasPrivileges { + return func(body io.Reader, o ...func(*SecurityHasPrivilegesRequest)) (*Response, error) { + var r = SecurityHasPrivilegesRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityHasPrivileges - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-has-privileges.html. +// +type SecurityHasPrivileges func(body io.Reader, o ...func(*SecurityHasPrivilegesRequest)) (*Response, error) + +// SecurityHasPrivilegesRequest configures the Security Has Privileges API request. +// +type SecurityHasPrivilegesRequest struct { + Body io.Reader + + User string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityHasPrivilegesRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_security") + 1 + len("user") + 1 + len(r.User) + 1 + len("_has_privileges")) + path.WriteString("/") + path.WriteString("_security") + path.WriteString("/") + path.WriteString("user") + if r.User != "" { + path.WriteString("/") + path.WriteString(r.User) + } + path.WriteString("/") + path.WriteString("_has_privileges") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityHasPrivileges) WithContext(v context.Context) func(*SecurityHasPrivilegesRequest) { + return func(r *SecurityHasPrivilegesRequest) { + r.ctx = v + } +} + +// WithUser - username. +// +func (f SecurityHasPrivileges) WithUser(v string) func(*SecurityHasPrivilegesRequest) { + return func(r *SecurityHasPrivilegesRequest) { + r.User = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityHasPrivileges) WithPretty() func(*SecurityHasPrivilegesRequest) { + return func(r *SecurityHasPrivilegesRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityHasPrivileges) WithHuman() func(*SecurityHasPrivilegesRequest) { + return func(r *SecurityHasPrivilegesRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityHasPrivileges) WithErrorTrace() func(*SecurityHasPrivilegesRequest) { + return func(r *SecurityHasPrivilegesRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityHasPrivileges) WithFilterPath(v ...string) func(*SecurityHasPrivilegesRequest) { + return func(r *SecurityHasPrivilegesRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityHasPrivileges) WithHeader(h map[string]string) func(*SecurityHasPrivilegesRequest) { + return func(r *SecurityHasPrivilegesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityHasPrivileges) WithOpaqueID(s string) func(*SecurityHasPrivilegesRequest) { + return func(r *SecurityHasPrivilegesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.invalidate_api_key.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.invalidate_api_key.go new file mode 100644 index 00000000000..085a5143d51 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.invalidate_api_key.go @@ -0,0 +1,190 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newSecurityInvalidateAPIKeyFunc(t Transport) SecurityInvalidateAPIKey { + return func(body io.Reader, o ...func(*SecurityInvalidateAPIKeyRequest)) (*Response, error) { + var r = SecurityInvalidateAPIKeyRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityInvalidateAPIKey - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-invalidate-api-key.html. +// +type SecurityInvalidateAPIKey func(body io.Reader, o ...func(*SecurityInvalidateAPIKeyRequest)) (*Response, error) + +// SecurityInvalidateAPIKeyRequest configures the Security InvalidateAPI Key API request. +// +type SecurityInvalidateAPIKeyRequest struct { + Body io.Reader + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityInvalidateAPIKeyRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(len("/_security/api_key")) + path.WriteString("/_security/api_key") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityInvalidateAPIKey) WithContext(v context.Context) func(*SecurityInvalidateAPIKeyRequest) { + return func(r *SecurityInvalidateAPIKeyRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityInvalidateAPIKey) WithPretty() func(*SecurityInvalidateAPIKeyRequest) { + return func(r *SecurityInvalidateAPIKeyRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityInvalidateAPIKey) WithHuman() func(*SecurityInvalidateAPIKeyRequest) { + return func(r *SecurityInvalidateAPIKeyRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityInvalidateAPIKey) WithErrorTrace() func(*SecurityInvalidateAPIKeyRequest) { + return func(r *SecurityInvalidateAPIKeyRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityInvalidateAPIKey) WithFilterPath(v ...string) func(*SecurityInvalidateAPIKeyRequest) { + return func(r *SecurityInvalidateAPIKeyRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityInvalidateAPIKey) WithHeader(h map[string]string) func(*SecurityInvalidateAPIKeyRequest) { + return func(r *SecurityInvalidateAPIKeyRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityInvalidateAPIKey) WithOpaqueID(s string) func(*SecurityInvalidateAPIKeyRequest) { + return func(r *SecurityInvalidateAPIKeyRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.invalidate_token.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.invalidate_token.go new file mode 100644 index 00000000000..09f059adb8e --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.invalidate_token.go @@ -0,0 +1,190 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newSecurityInvalidateTokenFunc(t Transport) SecurityInvalidateToken { + return func(body io.Reader, o ...func(*SecurityInvalidateTokenRequest)) (*Response, error) { + var r = SecurityInvalidateTokenRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityInvalidateToken - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-invalidate-token.html. +// +type SecurityInvalidateToken func(body io.Reader, o ...func(*SecurityInvalidateTokenRequest)) (*Response, error) + +// SecurityInvalidateTokenRequest configures the Security Invalidate Token API request. +// +type SecurityInvalidateTokenRequest struct { + Body io.Reader + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityInvalidateTokenRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(len("/_security/oauth2/token")) + path.WriteString("/_security/oauth2/token") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityInvalidateToken) WithContext(v context.Context) func(*SecurityInvalidateTokenRequest) { + return func(r *SecurityInvalidateTokenRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityInvalidateToken) WithPretty() func(*SecurityInvalidateTokenRequest) { + return func(r *SecurityInvalidateTokenRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityInvalidateToken) WithHuman() func(*SecurityInvalidateTokenRequest) { + return func(r *SecurityInvalidateTokenRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityInvalidateToken) WithErrorTrace() func(*SecurityInvalidateTokenRequest) { + return func(r *SecurityInvalidateTokenRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityInvalidateToken) WithFilterPath(v ...string) func(*SecurityInvalidateTokenRequest) { + return func(r *SecurityInvalidateTokenRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityInvalidateToken) WithHeader(h map[string]string) func(*SecurityInvalidateTokenRequest) { + return func(r *SecurityInvalidateTokenRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityInvalidateToken) WithOpaqueID(s string) func(*SecurityInvalidateTokenRequest) { + return func(r *SecurityInvalidateTokenRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.put_privileges.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.put_privileges.go new file mode 100644 index 00000000000..48311a5273a --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.put_privileges.go @@ -0,0 +1,202 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newSecurityPutPrivilegesFunc(t Transport) SecurityPutPrivileges { + return func(body io.Reader, o ...func(*SecurityPutPrivilegesRequest)) (*Response, error) { + var r = SecurityPutPrivilegesRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityPutPrivileges - TODO +// +type SecurityPutPrivileges func(body io.Reader, o ...func(*SecurityPutPrivilegesRequest)) (*Response, error) + +// SecurityPutPrivilegesRequest configures the Security Put Privileges API request. +// +type SecurityPutPrivilegesRequest struct { + Body io.Reader + + Refresh string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityPutPrivilegesRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(len("/_security/privilege/")) + path.WriteString("/_security/privilege/") + + params = make(map[string]string) + + if r.Refresh != "" { + params["refresh"] = r.Refresh + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityPutPrivileges) WithContext(v context.Context) func(*SecurityPutPrivilegesRequest) { + return func(r *SecurityPutPrivilegesRequest) { + r.ctx = v + } +} + +// WithRefresh - if `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes.. +// +func (f SecurityPutPrivileges) WithRefresh(v string) func(*SecurityPutPrivilegesRequest) { + return func(r *SecurityPutPrivilegesRequest) { + r.Refresh = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityPutPrivileges) WithPretty() func(*SecurityPutPrivilegesRequest) { + return func(r *SecurityPutPrivilegesRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityPutPrivileges) WithHuman() func(*SecurityPutPrivilegesRequest) { + return func(r *SecurityPutPrivilegesRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityPutPrivileges) WithErrorTrace() func(*SecurityPutPrivilegesRequest) { + return func(r *SecurityPutPrivilegesRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityPutPrivileges) WithFilterPath(v ...string) func(*SecurityPutPrivilegesRequest) { + return func(r *SecurityPutPrivilegesRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityPutPrivileges) WithHeader(h map[string]string) func(*SecurityPutPrivilegesRequest) { + return func(r *SecurityPutPrivilegesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityPutPrivileges) WithOpaqueID(s string) func(*SecurityPutPrivilegesRequest) { + return func(r *SecurityPutPrivilegesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.put_role.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.put_role.go new file mode 100644 index 00000000000..814a2bbdca3 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.put_role.go @@ -0,0 +1,211 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newSecurityPutRoleFunc(t Transport) SecurityPutRole { + return func(name string, body io.Reader, o ...func(*SecurityPutRoleRequest)) (*Response, error) { + var r = SecurityPutRoleRequest{Name: name, Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityPutRole - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-put-role.html. +// +type SecurityPutRole func(name string, body io.Reader, o ...func(*SecurityPutRoleRequest)) (*Response, error) + +// SecurityPutRoleRequest configures the Security Put Role API request. +// +type SecurityPutRoleRequest struct { + Body io.Reader + + Name string + + Refresh string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityPutRoleRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_security") + 1 + len("role") + 1 + len(r.Name)) + path.WriteString("/") + path.WriteString("_security") + path.WriteString("/") + path.WriteString("role") + path.WriteString("/") + path.WriteString(r.Name) + + params = make(map[string]string) + + if r.Refresh != "" { + params["refresh"] = r.Refresh + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityPutRole) WithContext(v context.Context) func(*SecurityPutRoleRequest) { + return func(r *SecurityPutRoleRequest) { + r.ctx = v + } +} + +// WithRefresh - if `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes.. +// +func (f SecurityPutRole) WithRefresh(v string) func(*SecurityPutRoleRequest) { + return func(r *SecurityPutRoleRequest) { + r.Refresh = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityPutRole) WithPretty() func(*SecurityPutRoleRequest) { + return func(r *SecurityPutRoleRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityPutRole) WithHuman() func(*SecurityPutRoleRequest) { + return func(r *SecurityPutRoleRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityPutRole) WithErrorTrace() func(*SecurityPutRoleRequest) { + return func(r *SecurityPutRoleRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityPutRole) WithFilterPath(v ...string) func(*SecurityPutRoleRequest) { + return func(r *SecurityPutRoleRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityPutRole) WithHeader(h map[string]string) func(*SecurityPutRoleRequest) { + return func(r *SecurityPutRoleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityPutRole) WithOpaqueID(s string) func(*SecurityPutRoleRequest) { + return func(r *SecurityPutRoleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.put_role_mapping.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.put_role_mapping.go new file mode 100644 index 00000000000..19f28ffed81 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.put_role_mapping.go @@ -0,0 +1,211 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newSecurityPutRoleMappingFunc(t Transport) SecurityPutRoleMapping { + return func(name string, body io.Reader, o ...func(*SecurityPutRoleMappingRequest)) (*Response, error) { + var r = SecurityPutRoleMappingRequest{Name: name, Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityPutRoleMapping - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-put-role-mapping.html. +// +type SecurityPutRoleMapping func(name string, body io.Reader, o ...func(*SecurityPutRoleMappingRequest)) (*Response, error) + +// SecurityPutRoleMappingRequest configures the Security Put Role Mapping API request. +// +type SecurityPutRoleMappingRequest struct { + Body io.Reader + + Name string + + Refresh string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityPutRoleMappingRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_security") + 1 + len("role_mapping") + 1 + len(r.Name)) + path.WriteString("/") + path.WriteString("_security") + path.WriteString("/") + path.WriteString("role_mapping") + path.WriteString("/") + path.WriteString(r.Name) + + params = make(map[string]string) + + if r.Refresh != "" { + params["refresh"] = r.Refresh + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityPutRoleMapping) WithContext(v context.Context) func(*SecurityPutRoleMappingRequest) { + return func(r *SecurityPutRoleMappingRequest) { + r.ctx = v + } +} + +// WithRefresh - if `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes.. +// +func (f SecurityPutRoleMapping) WithRefresh(v string) func(*SecurityPutRoleMappingRequest) { + return func(r *SecurityPutRoleMappingRequest) { + r.Refresh = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityPutRoleMapping) WithPretty() func(*SecurityPutRoleMappingRequest) { + return func(r *SecurityPutRoleMappingRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityPutRoleMapping) WithHuman() func(*SecurityPutRoleMappingRequest) { + return func(r *SecurityPutRoleMappingRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityPutRoleMapping) WithErrorTrace() func(*SecurityPutRoleMappingRequest) { + return func(r *SecurityPutRoleMappingRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityPutRoleMapping) WithFilterPath(v ...string) func(*SecurityPutRoleMappingRequest) { + return func(r *SecurityPutRoleMappingRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityPutRoleMapping) WithHeader(h map[string]string) func(*SecurityPutRoleMappingRequest) { + return func(r *SecurityPutRoleMappingRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityPutRoleMapping) WithOpaqueID(s string) func(*SecurityPutRoleMappingRequest) { + return func(r *SecurityPutRoleMappingRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.put_user.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.put_user.go new file mode 100644 index 00000000000..64fd5524b26 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.put_user.go @@ -0,0 +1,211 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newSecurityPutUserFunc(t Transport) SecurityPutUser { + return func(username string, body io.Reader, o ...func(*SecurityPutUserRequest)) (*Response, error) { + var r = SecurityPutUserRequest{Username: username, Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SecurityPutUser - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-put-user.html. +// +type SecurityPutUser func(username string, body io.Reader, o ...func(*SecurityPutUserRequest)) (*Response, error) + +// SecurityPutUserRequest configures the Security Put User API request. +// +type SecurityPutUserRequest struct { + Body io.Reader + + Username string + + Refresh string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SecurityPutUserRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_security") + 1 + len("user") + 1 + len(r.Username)) + path.WriteString("/") + path.WriteString("_security") + path.WriteString("/") + path.WriteString("user") + path.WriteString("/") + path.WriteString(r.Username) + + params = make(map[string]string) + + if r.Refresh != "" { + params["refresh"] = r.Refresh + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SecurityPutUser) WithContext(v context.Context) func(*SecurityPutUserRequest) { + return func(r *SecurityPutUserRequest) { + r.ctx = v + } +} + +// WithRefresh - if `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes.. +// +func (f SecurityPutUser) WithRefresh(v string) func(*SecurityPutUserRequest) { + return func(r *SecurityPutUserRequest) { + r.Refresh = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SecurityPutUser) WithPretty() func(*SecurityPutUserRequest) { + return func(r *SecurityPutUserRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SecurityPutUser) WithHuman() func(*SecurityPutUserRequest) { + return func(r *SecurityPutUserRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SecurityPutUser) WithErrorTrace() func(*SecurityPutUserRequest) { + return func(r *SecurityPutUserRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SecurityPutUser) WithFilterPath(v ...string) func(*SecurityPutUserRequest) { + return func(r *SecurityPutUserRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SecurityPutUser) WithHeader(h map[string]string) func(*SecurityPutUserRequest) { + return func(r *SecurityPutUserRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SecurityPutUser) WithOpaqueID(s string) func(*SecurityPutUserRequest) { + return func(r *SecurityPutUserRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.delete_lifecycle.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.delete_lifecycle.go new file mode 100644 index 00000000000..f84b7827894 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.delete_lifecycle.go @@ -0,0 +1,190 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newSlmDeleteLifecycleFunc(t Transport) SlmDeleteLifecycle { + return func(policy_id string, o ...func(*SlmDeleteLifecycleRequest)) (*Response, error) { + var r = SlmDeleteLifecycleRequest{PolicyID: policy_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SlmDeleteLifecycle - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-delete.html. +// +type SlmDeleteLifecycle func(policy_id string, o ...func(*SlmDeleteLifecycleRequest)) (*Response, error) + +// SlmDeleteLifecycleRequest configures the Slm Delete Lifecycle API request. +// +type SlmDeleteLifecycleRequest struct { + PolicyID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SlmDeleteLifecycleRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_slm") + 1 + len("policy") + 1 + len(r.PolicyID)) + path.WriteString("/") + path.WriteString("_slm") + path.WriteString("/") + path.WriteString("policy") + path.WriteString("/") + path.WriteString(r.PolicyID) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SlmDeleteLifecycle) WithContext(v context.Context) func(*SlmDeleteLifecycleRequest) { + return func(r *SlmDeleteLifecycleRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SlmDeleteLifecycle) WithPretty() func(*SlmDeleteLifecycleRequest) { + return func(r *SlmDeleteLifecycleRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SlmDeleteLifecycle) WithHuman() func(*SlmDeleteLifecycleRequest) { + return func(r *SlmDeleteLifecycleRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SlmDeleteLifecycle) WithErrorTrace() func(*SlmDeleteLifecycleRequest) { + return func(r *SlmDeleteLifecycleRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SlmDeleteLifecycle) WithFilterPath(v ...string) func(*SlmDeleteLifecycleRequest) { + return func(r *SlmDeleteLifecycleRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SlmDeleteLifecycle) WithHeader(h map[string]string) func(*SlmDeleteLifecycleRequest) { + return func(r *SlmDeleteLifecycleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SlmDeleteLifecycle) WithOpaqueID(s string) func(*SlmDeleteLifecycleRequest) { + return func(r *SlmDeleteLifecycleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.execute_lifecycle.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.execute_lifecycle.go new file mode 100644 index 00000000000..571dc978aa2 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.execute_lifecycle.go @@ -0,0 +1,192 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newSlmExecuteLifecycleFunc(t Transport) SlmExecuteLifecycle { + return func(policy_id string, o ...func(*SlmExecuteLifecycleRequest)) (*Response, error) { + var r = SlmExecuteLifecycleRequest{PolicyID: policy_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SlmExecuteLifecycle - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-execute.html. +// +type SlmExecuteLifecycle func(policy_id string, o ...func(*SlmExecuteLifecycleRequest)) (*Response, error) + +// SlmExecuteLifecycleRequest configures the Slm Execute Lifecycle API request. +// +type SlmExecuteLifecycleRequest struct { + PolicyID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SlmExecuteLifecycleRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_slm") + 1 + len("policy") + 1 + len(r.PolicyID) + 1 + len("_execute")) + path.WriteString("/") + path.WriteString("_slm") + path.WriteString("/") + path.WriteString("policy") + path.WriteString("/") + path.WriteString(r.PolicyID) + path.WriteString("/") + path.WriteString("_execute") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SlmExecuteLifecycle) WithContext(v context.Context) func(*SlmExecuteLifecycleRequest) { + return func(r *SlmExecuteLifecycleRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SlmExecuteLifecycle) WithPretty() func(*SlmExecuteLifecycleRequest) { + return func(r *SlmExecuteLifecycleRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SlmExecuteLifecycle) WithHuman() func(*SlmExecuteLifecycleRequest) { + return func(r *SlmExecuteLifecycleRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SlmExecuteLifecycle) WithErrorTrace() func(*SlmExecuteLifecycleRequest) { + return func(r *SlmExecuteLifecycleRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SlmExecuteLifecycle) WithFilterPath(v ...string) func(*SlmExecuteLifecycleRequest) { + return func(r *SlmExecuteLifecycleRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SlmExecuteLifecycle) WithHeader(h map[string]string) func(*SlmExecuteLifecycleRequest) { + return func(r *SlmExecuteLifecycleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SlmExecuteLifecycle) WithOpaqueID(s string) func(*SlmExecuteLifecycleRequest) { + return func(r *SlmExecuteLifecycleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.execute_retention.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.execute_retention.go new file mode 100644 index 00000000000..1eee581a673 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.execute_retention.go @@ -0,0 +1,183 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newSlmExecuteRetentionFunc(t Transport) SlmExecuteRetention { + return func(o ...func(*SlmExecuteRetentionRequest)) (*Response, error) { + var r = SlmExecuteRetentionRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SlmExecuteRetention - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-execute-retention.html. +// +type SlmExecuteRetention func(o ...func(*SlmExecuteRetentionRequest)) (*Response, error) + +// SlmExecuteRetentionRequest configures the Slm Execute Retention API request. +// +type SlmExecuteRetentionRequest struct { + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SlmExecuteRetentionRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(len("/_slm/_execute_retention")) + path.WriteString("/_slm/_execute_retention") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SlmExecuteRetention) WithContext(v context.Context) func(*SlmExecuteRetentionRequest) { + return func(r *SlmExecuteRetentionRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SlmExecuteRetention) WithPretty() func(*SlmExecuteRetentionRequest) { + return func(r *SlmExecuteRetentionRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SlmExecuteRetention) WithHuman() func(*SlmExecuteRetentionRequest) { + return func(r *SlmExecuteRetentionRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SlmExecuteRetention) WithErrorTrace() func(*SlmExecuteRetentionRequest) { + return func(r *SlmExecuteRetentionRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SlmExecuteRetention) WithFilterPath(v ...string) func(*SlmExecuteRetentionRequest) { + return func(r *SlmExecuteRetentionRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SlmExecuteRetention) WithHeader(h map[string]string) func(*SlmExecuteRetentionRequest) { + return func(r *SlmExecuteRetentionRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SlmExecuteRetention) WithOpaqueID(s string) func(*SlmExecuteRetentionRequest) { + return func(r *SlmExecuteRetentionRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.get_lifecycle.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.get_lifecycle.go new file mode 100644 index 00000000000..5e20aab76b1 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.get_lifecycle.go @@ -0,0 +1,200 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newSlmGetLifecycleFunc(t Transport) SlmGetLifecycle { + return func(o ...func(*SlmGetLifecycleRequest)) (*Response, error) { + var r = SlmGetLifecycleRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SlmGetLifecycle - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-get.html. +// +type SlmGetLifecycle func(o ...func(*SlmGetLifecycleRequest)) (*Response, error) + +// SlmGetLifecycleRequest configures the Slm Get Lifecycle API request. +// +type SlmGetLifecycleRequest struct { + PolicyID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SlmGetLifecycleRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_slm") + 1 + len("policy") + 1 + len(r.PolicyID)) + path.WriteString("/") + path.WriteString("_slm") + path.WriteString("/") + path.WriteString("policy") + if r.PolicyID != "" { + path.WriteString("/") + path.WriteString(r.PolicyID) + } + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SlmGetLifecycle) WithContext(v context.Context) func(*SlmGetLifecycleRequest) { + return func(r *SlmGetLifecycleRequest) { + r.ctx = v + } +} + +// WithPolicyID - comma-separated list of snapshot lifecycle policies to retrieve. +// +func (f SlmGetLifecycle) WithPolicyID(v string) func(*SlmGetLifecycleRequest) { + return func(r *SlmGetLifecycleRequest) { + r.PolicyID = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SlmGetLifecycle) WithPretty() func(*SlmGetLifecycleRequest) { + return func(r *SlmGetLifecycleRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SlmGetLifecycle) WithHuman() func(*SlmGetLifecycleRequest) { + return func(r *SlmGetLifecycleRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SlmGetLifecycle) WithErrorTrace() func(*SlmGetLifecycleRequest) { + return func(r *SlmGetLifecycleRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SlmGetLifecycle) WithFilterPath(v ...string) func(*SlmGetLifecycleRequest) { + return func(r *SlmGetLifecycleRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SlmGetLifecycle) WithHeader(h map[string]string) func(*SlmGetLifecycleRequest) { + return func(r *SlmGetLifecycleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SlmGetLifecycle) WithOpaqueID(s string) func(*SlmGetLifecycleRequest) { + return func(r *SlmGetLifecycleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.get_stats.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.get_stats.go new file mode 100644 index 00000000000..e748f622ba2 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.get_stats.go @@ -0,0 +1,183 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newSlmGetStatsFunc(t Transport) SlmGetStats { + return func(o ...func(*SlmGetStatsRequest)) (*Response, error) { + var r = SlmGetStatsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SlmGetStats - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/slm-get-stats.html. +// +type SlmGetStats func(o ...func(*SlmGetStatsRequest)) (*Response, error) + +// SlmGetStatsRequest configures the Slm Get Stats API request. +// +type SlmGetStatsRequest struct { + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SlmGetStatsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_slm/stats")) + path.WriteString("/_slm/stats") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SlmGetStats) WithContext(v context.Context) func(*SlmGetStatsRequest) { + return func(r *SlmGetStatsRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SlmGetStats) WithPretty() func(*SlmGetStatsRequest) { + return func(r *SlmGetStatsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SlmGetStats) WithHuman() func(*SlmGetStatsRequest) { + return func(r *SlmGetStatsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SlmGetStats) WithErrorTrace() func(*SlmGetStatsRequest) { + return func(r *SlmGetStatsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SlmGetStats) WithFilterPath(v ...string) func(*SlmGetStatsRequest) { + return func(r *SlmGetStatsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SlmGetStats) WithHeader(h map[string]string) func(*SlmGetStatsRequest) { + return func(r *SlmGetStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SlmGetStats) WithOpaqueID(s string) func(*SlmGetStatsRequest) { + return func(r *SlmGetStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.put_lifecycle.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.put_lifecycle.go new file mode 100644 index 00000000000..2a74de2d872 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.put_lifecycle.go @@ -0,0 +1,205 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newSlmPutLifecycleFunc(t Transport) SlmPutLifecycle { + return func(policy_id string, o ...func(*SlmPutLifecycleRequest)) (*Response, error) { + var r = SlmPutLifecycleRequest{PolicyID: policy_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SlmPutLifecycle - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/slm-api-put.html. +// +type SlmPutLifecycle func(policy_id string, o ...func(*SlmPutLifecycleRequest)) (*Response, error) + +// SlmPutLifecycleRequest configures the Slm Put Lifecycle API request. +// +type SlmPutLifecycleRequest struct { + Body io.Reader + + PolicyID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SlmPutLifecycleRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_slm") + 1 + len("policy") + 1 + len(r.PolicyID)) + path.WriteString("/") + path.WriteString("_slm") + path.WriteString("/") + path.WriteString("policy") + path.WriteString("/") + path.WriteString(r.PolicyID) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SlmPutLifecycle) WithContext(v context.Context) func(*SlmPutLifecycleRequest) { + return func(r *SlmPutLifecycleRequest) { + r.ctx = v + } +} + +// WithBody - The snapshot lifecycle policy definition to register. +// +func (f SlmPutLifecycle) WithBody(v io.Reader) func(*SlmPutLifecycleRequest) { + return func(r *SlmPutLifecycleRequest) { + r.Body = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SlmPutLifecycle) WithPretty() func(*SlmPutLifecycleRequest) { + return func(r *SlmPutLifecycleRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SlmPutLifecycle) WithHuman() func(*SlmPutLifecycleRequest) { + return func(r *SlmPutLifecycleRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SlmPutLifecycle) WithErrorTrace() func(*SlmPutLifecycleRequest) { + return func(r *SlmPutLifecycleRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SlmPutLifecycle) WithFilterPath(v ...string) func(*SlmPutLifecycleRequest) { + return func(r *SlmPutLifecycleRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SlmPutLifecycle) WithHeader(h map[string]string) func(*SlmPutLifecycleRequest) { + return func(r *SlmPutLifecycleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SlmPutLifecycle) WithOpaqueID(s string) func(*SlmPutLifecycleRequest) { + return func(r *SlmPutLifecycleRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.sql.clear_cursor.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.sql.clear_cursor.go new file mode 100644 index 00000000000..845644b1ece --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.sql.clear_cursor.go @@ -0,0 +1,188 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newSQLClearCursorFunc(t Transport) SQLClearCursor { + return func(body io.Reader, o ...func(*SQLClearCursorRequest)) (*Response, error) { + var r = SQLClearCursorRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SQLClearCursor - Clear SQL cursor +// +type SQLClearCursor func(body io.Reader, o ...func(*SQLClearCursorRequest)) (*Response, error) + +// SQLClearCursorRequest configures the SQL Clear Cursor API request. +// +type SQLClearCursorRequest struct { + Body io.Reader + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SQLClearCursorRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(len("/_sql/close")) + path.WriteString("/_sql/close") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SQLClearCursor) WithContext(v context.Context) func(*SQLClearCursorRequest) { + return func(r *SQLClearCursorRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SQLClearCursor) WithPretty() func(*SQLClearCursorRequest) { + return func(r *SQLClearCursorRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SQLClearCursor) WithHuman() func(*SQLClearCursorRequest) { + return func(r *SQLClearCursorRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SQLClearCursor) WithErrorTrace() func(*SQLClearCursorRequest) { + return func(r *SQLClearCursorRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SQLClearCursor) WithFilterPath(v ...string) func(*SQLClearCursorRequest) { + return func(r *SQLClearCursorRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SQLClearCursor) WithHeader(h map[string]string) func(*SQLClearCursorRequest) { + return func(r *SQLClearCursorRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SQLClearCursor) WithOpaqueID(s string) func(*SQLClearCursorRequest) { + return func(r *SQLClearCursorRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.sql.query.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.sql.query.go new file mode 100644 index 00000000000..9ab5da2c552 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.sql.query.go @@ -0,0 +1,202 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newSQLQueryFunc(t Transport) SQLQuery { + return func(body io.Reader, o ...func(*SQLQueryRequest)) (*Response, error) { + var r = SQLQueryRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SQLQuery - Execute SQL +// +type SQLQuery func(body io.Reader, o ...func(*SQLQueryRequest)) (*Response, error) + +// SQLQueryRequest configures the SQL Query API request. +// +type SQLQueryRequest struct { + Body io.Reader + + Format string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SQLQueryRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(len("/_sql")) + path.WriteString("/_sql") + + params = make(map[string]string) + + if r.Format != "" { + params["format"] = r.Format + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SQLQuery) WithContext(v context.Context) func(*SQLQueryRequest) { + return func(r *SQLQueryRequest) { + r.ctx = v + } +} + +// WithFormat - a short version of the accept header, e.g. json, yaml. +// +func (f SQLQuery) WithFormat(v string) func(*SQLQueryRequest) { + return func(r *SQLQueryRequest) { + r.Format = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SQLQuery) WithPretty() func(*SQLQueryRequest) { + return func(r *SQLQueryRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SQLQuery) WithHuman() func(*SQLQueryRequest) { + return func(r *SQLQueryRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SQLQuery) WithErrorTrace() func(*SQLQueryRequest) { + return func(r *SQLQueryRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SQLQuery) WithFilterPath(v ...string) func(*SQLQueryRequest) { + return func(r *SQLQueryRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SQLQuery) WithHeader(h map[string]string) func(*SQLQueryRequest) { + return func(r *SQLQueryRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SQLQuery) WithOpaqueID(s string) func(*SQLQueryRequest) { + return func(r *SQLQueryRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.sql.translate.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.sql.translate.go new file mode 100644 index 00000000000..398e9c294d0 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.sql.translate.go @@ -0,0 +1,188 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newSQLTranslateFunc(t Transport) SQLTranslate { + return func(body io.Reader, o ...func(*SQLTranslateRequest)) (*Response, error) { + var r = SQLTranslateRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SQLTranslate - Translate SQL into Elasticsearch queries +// +type SQLTranslate func(body io.Reader, o ...func(*SQLTranslateRequest)) (*Response, error) + +// SQLTranslateRequest configures the SQL Translate API request. +// +type SQLTranslateRequest struct { + Body io.Reader + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SQLTranslateRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(len("/_sql/translate")) + path.WriteString("/_sql/translate") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SQLTranslate) WithContext(v context.Context) func(*SQLTranslateRequest) { + return func(r *SQLTranslateRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SQLTranslate) WithPretty() func(*SQLTranslateRequest) { + return func(r *SQLTranslateRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SQLTranslate) WithHuman() func(*SQLTranslateRequest) { + return func(r *SQLTranslateRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SQLTranslate) WithErrorTrace() func(*SQLTranslateRequest) { + return func(r *SQLTranslateRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SQLTranslate) WithFilterPath(v ...string) func(*SQLTranslateRequest) { + return func(r *SQLTranslateRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SQLTranslate) WithHeader(h map[string]string) func(*SQLTranslateRequest) { + return func(r *SQLTranslateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SQLTranslate) WithOpaqueID(s string) func(*SQLTranslateRequest) { + return func(r *SQLTranslateRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ssl.certificates.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ssl.certificates.go new file mode 100644 index 00000000000..c18a6e48f65 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.ssl.certificates.go @@ -0,0 +1,183 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newSSLCertificatesFunc(t Transport) SSLCertificates { + return func(o ...func(*SSLCertificatesRequest)) (*Response, error) { + var r = SSLCertificatesRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// SSLCertificates - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-ssl.html. +// +type SSLCertificates func(o ...func(*SSLCertificatesRequest)) (*Response, error) + +// SSLCertificatesRequest configures the SSL Certificates API request. +// +type SSLCertificatesRequest struct { + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r SSLCertificatesRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_ssl/certificates")) + path.WriteString("/_ssl/certificates") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f SSLCertificates) WithContext(v context.Context) func(*SSLCertificatesRequest) { + return func(r *SSLCertificatesRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f SSLCertificates) WithPretty() func(*SSLCertificatesRequest) { + return func(r *SSLCertificatesRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f SSLCertificates) WithHuman() func(*SSLCertificatesRequest) { + return func(r *SSLCertificatesRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f SSLCertificates) WithErrorTrace() func(*SSLCertificatesRequest) { + return func(r *SSLCertificatesRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f SSLCertificates) WithFilterPath(v ...string) func(*SSLCertificatesRequest) { + return func(r *SSLCertificatesRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f SSLCertificates) WithHeader(h map[string]string) func(*SSLCertificatesRequest) { + return func(r *SSLCertificatesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f SSLCertificates) WithOpaqueID(s string) func(*SSLCertificatesRequest) { + return func(r *SSLCertificatesRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.delete_transform.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.delete_transform.go new file mode 100644 index 00000000000..eb444c3eae7 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.delete_transform.go @@ -0,0 +1,203 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newTransformDeleteTransformFunc(t Transport) TransformDeleteTransform { + return func(transform_id string, o ...func(*TransformDeleteTransformRequest)) (*Response, error) { + var r = TransformDeleteTransformRequest{TransformID: transform_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// TransformDeleteTransform - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-transform.html. +// +type TransformDeleteTransform func(transform_id string, o ...func(*TransformDeleteTransformRequest)) (*Response, error) + +// TransformDeleteTransformRequest configures the Transform Delete Transform API request. +// +type TransformDeleteTransformRequest struct { + TransformID string + + Force *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r TransformDeleteTransformRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_transform") + 1 + len(r.TransformID)) + path.WriteString("/") + path.WriteString("_transform") + path.WriteString("/") + path.WriteString(r.TransformID) + + params = make(map[string]string) + + if r.Force != nil { + params["force"] = strconv.FormatBool(*r.Force) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f TransformDeleteTransform) WithContext(v context.Context) func(*TransformDeleteTransformRequest) { + return func(r *TransformDeleteTransformRequest) { + r.ctx = v + } +} + +// WithForce - when `true`, the transform is deleted regardless of its current state. the default value is `false`, meaning that the transform must be `stopped` before it can be deleted.. +// +func (f TransformDeleteTransform) WithForce(v bool) func(*TransformDeleteTransformRequest) { + return func(r *TransformDeleteTransformRequest) { + r.Force = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f TransformDeleteTransform) WithPretty() func(*TransformDeleteTransformRequest) { + return func(r *TransformDeleteTransformRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f TransformDeleteTransform) WithHuman() func(*TransformDeleteTransformRequest) { + return func(r *TransformDeleteTransformRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f TransformDeleteTransform) WithErrorTrace() func(*TransformDeleteTransformRequest) { + return func(r *TransformDeleteTransformRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f TransformDeleteTransform) WithFilterPath(v ...string) func(*TransformDeleteTransformRequest) { + return func(r *TransformDeleteTransformRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f TransformDeleteTransform) WithHeader(h map[string]string) func(*TransformDeleteTransformRequest) { + return func(r *TransformDeleteTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f TransformDeleteTransform) WithOpaqueID(s string) func(*TransformDeleteTransformRequest) { + return func(r *TransformDeleteTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.get_transform.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.get_transform.go new file mode 100644 index 00000000000..40b11b71648 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.get_transform.go @@ -0,0 +1,239 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newTransformGetTransformFunc(t Transport) TransformGetTransform { + return func(o ...func(*TransformGetTransformRequest)) (*Response, error) { + var r = TransformGetTransformRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// TransformGetTransform - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/get-transform.html. +// +type TransformGetTransform func(o ...func(*TransformGetTransformRequest)) (*Response, error) + +// TransformGetTransformRequest configures the Transform Get Transform API request. +// +type TransformGetTransformRequest struct { + TransformID string + + AllowNoMatch *bool + From *int + Size *int + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r TransformGetTransformRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_transform") + 1 + len(r.TransformID)) + path.WriteString("/") + path.WriteString("_transform") + if r.TransformID != "" { + path.WriteString("/") + path.WriteString(r.TransformID) + } + + params = make(map[string]string) + + if r.AllowNoMatch != nil { + params["allow_no_match"] = strconv.FormatBool(*r.AllowNoMatch) + } + + if r.From != nil { + params["from"] = strconv.FormatInt(int64(*r.From), 10) + } + + if r.Size != nil { + params["size"] = strconv.FormatInt(int64(*r.Size), 10) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f TransformGetTransform) WithContext(v context.Context) func(*TransformGetTransformRequest) { + return func(r *TransformGetTransformRequest) { + r.ctx = v + } +} + +// WithTransformID - the ID or comma delimited list of ID expressions of the transforms to get, '_all' or '*' implies get all transforms. +// +func (f TransformGetTransform) WithTransformID(v string) func(*TransformGetTransformRequest) { + return func(r *TransformGetTransformRequest) { + r.TransformID = v + } +} + +// WithAllowNoMatch - whether to ignore if a wildcard expression matches no transforms. (this includes `_all` string or when no transforms have been specified). +// +func (f TransformGetTransform) WithAllowNoMatch(v bool) func(*TransformGetTransformRequest) { + return func(r *TransformGetTransformRequest) { + r.AllowNoMatch = &v + } +} + +// WithFrom - skips a number of transform configs, defaults to 0. +// +func (f TransformGetTransform) WithFrom(v int) func(*TransformGetTransformRequest) { + return func(r *TransformGetTransformRequest) { + r.From = &v + } +} + +// WithSize - specifies a max number of transforms to get, defaults to 100. +// +func (f TransformGetTransform) WithSize(v int) func(*TransformGetTransformRequest) { + return func(r *TransformGetTransformRequest) { + r.Size = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f TransformGetTransform) WithPretty() func(*TransformGetTransformRequest) { + return func(r *TransformGetTransformRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f TransformGetTransform) WithHuman() func(*TransformGetTransformRequest) { + return func(r *TransformGetTransformRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f TransformGetTransform) WithErrorTrace() func(*TransformGetTransformRequest) { + return func(r *TransformGetTransformRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f TransformGetTransform) WithFilterPath(v ...string) func(*TransformGetTransformRequest) { + return func(r *TransformGetTransformRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f TransformGetTransform) WithHeader(h map[string]string) func(*TransformGetTransformRequest) { + return func(r *TransformGetTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f TransformGetTransform) WithOpaqueID(s string) func(*TransformGetTransformRequest) { + return func(r *TransformGetTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.get_transform_stats.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.get_transform_stats.go new file mode 100644 index 00000000000..3bde103019d --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.get_transform_stats.go @@ -0,0 +1,231 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newTransformGetTransformStatsFunc(t Transport) TransformGetTransformStats { + return func(transform_id string, o ...func(*TransformGetTransformStatsRequest)) (*Response, error) { + var r = TransformGetTransformStatsRequest{TransformID: transform_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// TransformGetTransformStats - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/get-transform-stats.html. +// +type TransformGetTransformStats func(transform_id string, o ...func(*TransformGetTransformStatsRequest)) (*Response, error) + +// TransformGetTransformStatsRequest configures the Transform Get Transform Stats API request. +// +type TransformGetTransformStatsRequest struct { + TransformID string + + AllowNoMatch *bool + From *int + Size *int + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r TransformGetTransformStatsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_transform") + 1 + len(r.TransformID) + 1 + len("_stats")) + path.WriteString("/") + path.WriteString("_transform") + path.WriteString("/") + path.WriteString(r.TransformID) + path.WriteString("/") + path.WriteString("_stats") + + params = make(map[string]string) + + if r.AllowNoMatch != nil { + params["allow_no_match"] = strconv.FormatBool(*r.AllowNoMatch) + } + + if r.From != nil { + params["from"] = strconv.FormatInt(int64(*r.From), 10) + } + + if r.Size != nil { + params["size"] = strconv.FormatInt(int64(*r.Size), 10) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f TransformGetTransformStats) WithContext(v context.Context) func(*TransformGetTransformStatsRequest) { + return func(r *TransformGetTransformStatsRequest) { + r.ctx = v + } +} + +// WithAllowNoMatch - whether to ignore if a wildcard expression matches no transforms. (this includes `_all` string or when no transforms have been specified). +// +func (f TransformGetTransformStats) WithAllowNoMatch(v bool) func(*TransformGetTransformStatsRequest) { + return func(r *TransformGetTransformStatsRequest) { + r.AllowNoMatch = &v + } +} + +// WithFrom - skips a number of transform stats, defaults to 0. +// +func (f TransformGetTransformStats) WithFrom(v int) func(*TransformGetTransformStatsRequest) { + return func(r *TransformGetTransformStatsRequest) { + r.From = &v + } +} + +// WithSize - specifies a max number of transform stats to get, defaults to 100. +// +func (f TransformGetTransformStats) WithSize(v int) func(*TransformGetTransformStatsRequest) { + return func(r *TransformGetTransformStatsRequest) { + r.Size = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f TransformGetTransformStats) WithPretty() func(*TransformGetTransformStatsRequest) { + return func(r *TransformGetTransformStatsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f TransformGetTransformStats) WithHuman() func(*TransformGetTransformStatsRequest) { + return func(r *TransformGetTransformStatsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f TransformGetTransformStats) WithErrorTrace() func(*TransformGetTransformStatsRequest) { + return func(r *TransformGetTransformStatsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f TransformGetTransformStats) WithFilterPath(v ...string) func(*TransformGetTransformStatsRequest) { + return func(r *TransformGetTransformStatsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f TransformGetTransformStats) WithHeader(h map[string]string) func(*TransformGetTransformStatsRequest) { + return func(r *TransformGetTransformStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f TransformGetTransformStats) WithOpaqueID(s string) func(*TransformGetTransformStatsRequest) { + return func(r *TransformGetTransformStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.preview_transform.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.preview_transform.go new file mode 100644 index 00000000000..f13c49b2317 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.preview_transform.go @@ -0,0 +1,190 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strings" +) + +func newTransformPreviewTransformFunc(t Transport) TransformPreviewTransform { + return func(body io.Reader, o ...func(*TransformPreviewTransformRequest)) (*Response, error) { + var r = TransformPreviewTransformRequest{Body: body} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// TransformPreviewTransform - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/preview-transform.html. +// +type TransformPreviewTransform func(body io.Reader, o ...func(*TransformPreviewTransformRequest)) (*Response, error) + +// TransformPreviewTransformRequest configures the Transform Preview Transform API request. +// +type TransformPreviewTransformRequest struct { + Body io.Reader + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r TransformPreviewTransformRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(len("/_transform/_preview")) + path.WriteString("/_transform/_preview") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f TransformPreviewTransform) WithContext(v context.Context) func(*TransformPreviewTransformRequest) { + return func(r *TransformPreviewTransformRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f TransformPreviewTransform) WithPretty() func(*TransformPreviewTransformRequest) { + return func(r *TransformPreviewTransformRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f TransformPreviewTransform) WithHuman() func(*TransformPreviewTransformRequest) { + return func(r *TransformPreviewTransformRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f TransformPreviewTransform) WithErrorTrace() func(*TransformPreviewTransformRequest) { + return func(r *TransformPreviewTransformRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f TransformPreviewTransform) WithFilterPath(v ...string) func(*TransformPreviewTransformRequest) { + return func(r *TransformPreviewTransformRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f TransformPreviewTransform) WithHeader(h map[string]string) func(*TransformPreviewTransformRequest) { + return func(r *TransformPreviewTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f TransformPreviewTransform) WithOpaqueID(s string) func(*TransformPreviewTransformRequest) { + return func(r *TransformPreviewTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.put_transform.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.put_transform.go new file mode 100644 index 00000000000..4ad218366d7 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.put_transform.go @@ -0,0 +1,210 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newTransformPutTransformFunc(t Transport) TransformPutTransform { + return func(body io.Reader, transform_id string, o ...func(*TransformPutTransformRequest)) (*Response, error) { + var r = TransformPutTransformRequest{Body: body, TransformID: transform_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// TransformPutTransform - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/put-transform.html. +// +type TransformPutTransform func(body io.Reader, transform_id string, o ...func(*TransformPutTransformRequest)) (*Response, error) + +// TransformPutTransformRequest configures the Transform Put Transform API request. +// +type TransformPutTransformRequest struct { + Body io.Reader + + TransformID string + + DeferValidation *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r TransformPutTransformRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_transform") + 1 + len(r.TransformID)) + path.WriteString("/") + path.WriteString("_transform") + path.WriteString("/") + path.WriteString(r.TransformID) + + params = make(map[string]string) + + if r.DeferValidation != nil { + params["defer_validation"] = strconv.FormatBool(*r.DeferValidation) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f TransformPutTransform) WithContext(v context.Context) func(*TransformPutTransformRequest) { + return func(r *TransformPutTransformRequest) { + r.ctx = v + } +} + +// WithDeferValidation - if validations should be deferred until transform starts, defaults to false.. +// +func (f TransformPutTransform) WithDeferValidation(v bool) func(*TransformPutTransformRequest) { + return func(r *TransformPutTransformRequest) { + r.DeferValidation = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f TransformPutTransform) WithPretty() func(*TransformPutTransformRequest) { + return func(r *TransformPutTransformRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f TransformPutTransform) WithHuman() func(*TransformPutTransformRequest) { + return func(r *TransformPutTransformRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f TransformPutTransform) WithErrorTrace() func(*TransformPutTransformRequest) { + return func(r *TransformPutTransformRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f TransformPutTransform) WithFilterPath(v ...string) func(*TransformPutTransformRequest) { + return func(r *TransformPutTransformRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f TransformPutTransform) WithHeader(h map[string]string) func(*TransformPutTransformRequest) { + return func(r *TransformPutTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f TransformPutTransform) WithOpaqueID(s string) func(*TransformPutTransformRequest) { + return func(r *TransformPutTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.start_transform.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.start_transform.go new file mode 100644 index 00000000000..7df44644632 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.start_transform.go @@ -0,0 +1,205 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" + "time" +) + +func newTransformStartTransformFunc(t Transport) TransformStartTransform { + return func(transform_id string, o ...func(*TransformStartTransformRequest)) (*Response, error) { + var r = TransformStartTransformRequest{TransformID: transform_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// TransformStartTransform - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/start-transform.html. +// +type TransformStartTransform func(transform_id string, o ...func(*TransformStartTransformRequest)) (*Response, error) + +// TransformStartTransformRequest configures the Transform Start Transform API request. +// +type TransformStartTransformRequest struct { + TransformID string + + Timeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r TransformStartTransformRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_transform") + 1 + len(r.TransformID) + 1 + len("_start")) + path.WriteString("/") + path.WriteString("_transform") + path.WriteString("/") + path.WriteString(r.TransformID) + path.WriteString("/") + path.WriteString("_start") + + params = make(map[string]string) + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f TransformStartTransform) WithContext(v context.Context) func(*TransformStartTransformRequest) { + return func(r *TransformStartTransformRequest) { + r.ctx = v + } +} + +// WithTimeout - controls the time to wait for the transform to start. +// +func (f TransformStartTransform) WithTimeout(v time.Duration) func(*TransformStartTransformRequest) { + return func(r *TransformStartTransformRequest) { + r.Timeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f TransformStartTransform) WithPretty() func(*TransformStartTransformRequest) { + return func(r *TransformStartTransformRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f TransformStartTransform) WithHuman() func(*TransformStartTransformRequest) { + return func(r *TransformStartTransformRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f TransformStartTransform) WithErrorTrace() func(*TransformStartTransformRequest) { + return func(r *TransformStartTransformRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f TransformStartTransform) WithFilterPath(v ...string) func(*TransformStartTransformRequest) { + return func(r *TransformStartTransformRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f TransformStartTransform) WithHeader(h map[string]string) func(*TransformStartTransformRequest) { + return func(r *TransformStartTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f TransformStartTransform) WithOpaqueID(s string) func(*TransformStartTransformRequest) { + return func(r *TransformStartTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.stop_transform.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.stop_transform.go new file mode 100644 index 00000000000..efcdc8604ff --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.stop_transform.go @@ -0,0 +1,232 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" + "time" +) + +func newTransformStopTransformFunc(t Transport) TransformStopTransform { + return func(transform_id string, o ...func(*TransformStopTransformRequest)) (*Response, error) { + var r = TransformStopTransformRequest{TransformID: transform_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// TransformStopTransform - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/stop-transform.html. +// +type TransformStopTransform func(transform_id string, o ...func(*TransformStopTransformRequest)) (*Response, error) + +// TransformStopTransformRequest configures the Transform Stop Transform API request. +// +type TransformStopTransformRequest struct { + TransformID string + + AllowNoMatch *bool + Timeout time.Duration + WaitForCompletion *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r TransformStopTransformRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_transform") + 1 + len(r.TransformID) + 1 + len("_stop")) + path.WriteString("/") + path.WriteString("_transform") + path.WriteString("/") + path.WriteString(r.TransformID) + path.WriteString("/") + path.WriteString("_stop") + + params = make(map[string]string) + + if r.AllowNoMatch != nil { + params["allow_no_match"] = strconv.FormatBool(*r.AllowNoMatch) + } + + if r.Timeout != 0 { + params["timeout"] = formatDuration(r.Timeout) + } + + if r.WaitForCompletion != nil { + params["wait_for_completion"] = strconv.FormatBool(*r.WaitForCompletion) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f TransformStopTransform) WithContext(v context.Context) func(*TransformStopTransformRequest) { + return func(r *TransformStopTransformRequest) { + r.ctx = v + } +} + +// WithAllowNoMatch - whether to ignore if a wildcard expression matches no transforms. (this includes `_all` string or when no transforms have been specified). +// +func (f TransformStopTransform) WithAllowNoMatch(v bool) func(*TransformStopTransformRequest) { + return func(r *TransformStopTransformRequest) { + r.AllowNoMatch = &v + } +} + +// WithTimeout - controls the time to wait until the transform has stopped. default to 30 seconds. +// +func (f TransformStopTransform) WithTimeout(v time.Duration) func(*TransformStopTransformRequest) { + return func(r *TransformStopTransformRequest) { + r.Timeout = v + } +} + +// WithWaitForCompletion - whether to wait for the transform to fully stop before returning or not. default to false. +// +func (f TransformStopTransform) WithWaitForCompletion(v bool) func(*TransformStopTransformRequest) { + return func(r *TransformStopTransformRequest) { + r.WaitForCompletion = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f TransformStopTransform) WithPretty() func(*TransformStopTransformRequest) { + return func(r *TransformStopTransformRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f TransformStopTransform) WithHuman() func(*TransformStopTransformRequest) { + return func(r *TransformStopTransformRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f TransformStopTransform) WithErrorTrace() func(*TransformStopTransformRequest) { + return func(r *TransformStopTransformRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f TransformStopTransform) WithFilterPath(v ...string) func(*TransformStopTransformRequest) { + return func(r *TransformStopTransformRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f TransformStopTransform) WithHeader(h map[string]string) func(*TransformStopTransformRequest) { + return func(r *TransformStopTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f TransformStopTransform) WithOpaqueID(s string) func(*TransformStopTransformRequest) { + return func(r *TransformStopTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.update_transform.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.update_transform.go new file mode 100644 index 00000000000..8f0581c7b28 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.update_transform.go @@ -0,0 +1,212 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newTransformUpdateTransformFunc(t Transport) TransformUpdateTransform { + return func(body io.Reader, transform_id string, o ...func(*TransformUpdateTransformRequest)) (*Response, error) { + var r = TransformUpdateTransformRequest{Body: body, TransformID: transform_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// TransformUpdateTransform - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/update-transform.html. +// +type TransformUpdateTransform func(body io.Reader, transform_id string, o ...func(*TransformUpdateTransformRequest)) (*Response, error) + +// TransformUpdateTransformRequest configures the Transform Update Transform API request. +// +type TransformUpdateTransformRequest struct { + Body io.Reader + + TransformID string + + DeferValidation *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r TransformUpdateTransformRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(1 + len("_transform") + 1 + len(r.TransformID) + 1 + len("_update")) + path.WriteString("/") + path.WriteString("_transform") + path.WriteString("/") + path.WriteString(r.TransformID) + path.WriteString("/") + path.WriteString("_update") + + params = make(map[string]string) + + if r.DeferValidation != nil { + params["defer_validation"] = strconv.FormatBool(*r.DeferValidation) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f TransformUpdateTransform) WithContext(v context.Context) func(*TransformUpdateTransformRequest) { + return func(r *TransformUpdateTransformRequest) { + r.ctx = v + } +} + +// WithDeferValidation - if validations should be deferred until transform starts, defaults to false.. +// +func (f TransformUpdateTransform) WithDeferValidation(v bool) func(*TransformUpdateTransformRequest) { + return func(r *TransformUpdateTransformRequest) { + r.DeferValidation = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f TransformUpdateTransform) WithPretty() func(*TransformUpdateTransformRequest) { + return func(r *TransformUpdateTransformRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f TransformUpdateTransform) WithHuman() func(*TransformUpdateTransformRequest) { + return func(r *TransformUpdateTransformRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f TransformUpdateTransform) WithErrorTrace() func(*TransformUpdateTransformRequest) { + return func(r *TransformUpdateTransformRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f TransformUpdateTransform) WithFilterPath(v ...string) func(*TransformUpdateTransformRequest) { + return func(r *TransformUpdateTransformRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f TransformUpdateTransform) WithHeader(h map[string]string) func(*TransformUpdateTransformRequest) { + return func(r *TransformUpdateTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f TransformUpdateTransform) WithOpaqueID(s string) func(*TransformUpdateTransformRequest) { + return func(r *TransformUpdateTransformRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.ack_watch.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.ack_watch.go new file mode 100644 index 00000000000..02a12edc232 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.ack_watch.go @@ -0,0 +1,205 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newWatcherAckWatchFunc(t Transport) WatcherAckWatch { + return func(watch_id string, o ...func(*WatcherAckWatchRequest)) (*Response, error) { + var r = WatcherAckWatchRequest{WatchID: watch_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// WatcherAckWatch - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-ack-watch.html. +// +type WatcherAckWatch func(watch_id string, o ...func(*WatcherAckWatchRequest)) (*Response, error) + +// WatcherAckWatchRequest configures the Watcher Ack Watch API request. +// +type WatcherAckWatchRequest struct { + ActionID []string + WatchID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r WatcherAckWatchRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_watcher") + 1 + len("watch") + 1 + len(r.WatchID) + 1 + len("_ack") + 1 + len(strings.Join(r.ActionID, ","))) + path.WriteString("/") + path.WriteString("_watcher") + path.WriteString("/") + path.WriteString("watch") + path.WriteString("/") + path.WriteString(r.WatchID) + path.WriteString("/") + path.WriteString("_ack") + if len(r.ActionID) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.ActionID, ",")) + } + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f WatcherAckWatch) WithContext(v context.Context) func(*WatcherAckWatchRequest) { + return func(r *WatcherAckWatchRequest) { + r.ctx = v + } +} + +// WithActionID - a list of the action ids to be acked. +// +func (f WatcherAckWatch) WithActionID(v ...string) func(*WatcherAckWatchRequest) { + return func(r *WatcherAckWatchRequest) { + r.ActionID = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f WatcherAckWatch) WithPretty() func(*WatcherAckWatchRequest) { + return func(r *WatcherAckWatchRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f WatcherAckWatch) WithHuman() func(*WatcherAckWatchRequest) { + return func(r *WatcherAckWatchRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f WatcherAckWatch) WithErrorTrace() func(*WatcherAckWatchRequest) { + return func(r *WatcherAckWatchRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f WatcherAckWatch) WithFilterPath(v ...string) func(*WatcherAckWatchRequest) { + return func(r *WatcherAckWatchRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f WatcherAckWatch) WithHeader(h map[string]string) func(*WatcherAckWatchRequest) { + return func(r *WatcherAckWatchRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f WatcherAckWatch) WithOpaqueID(s string) func(*WatcherAckWatchRequest) { + return func(r *WatcherAckWatchRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.activate_watch.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.activate_watch.go new file mode 100644 index 00000000000..1f0d5dd03a2 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.activate_watch.go @@ -0,0 +1,192 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newWatcherActivateWatchFunc(t Transport) WatcherActivateWatch { + return func(watch_id string, o ...func(*WatcherActivateWatchRequest)) (*Response, error) { + var r = WatcherActivateWatchRequest{WatchID: watch_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// WatcherActivateWatch - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-activate-watch.html. +// +type WatcherActivateWatch func(watch_id string, o ...func(*WatcherActivateWatchRequest)) (*Response, error) + +// WatcherActivateWatchRequest configures the Watcher Activate Watch API request. +// +type WatcherActivateWatchRequest struct { + WatchID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r WatcherActivateWatchRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_watcher") + 1 + len("watch") + 1 + len(r.WatchID) + 1 + len("_activate")) + path.WriteString("/") + path.WriteString("_watcher") + path.WriteString("/") + path.WriteString("watch") + path.WriteString("/") + path.WriteString(r.WatchID) + path.WriteString("/") + path.WriteString("_activate") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f WatcherActivateWatch) WithContext(v context.Context) func(*WatcherActivateWatchRequest) { + return func(r *WatcherActivateWatchRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f WatcherActivateWatch) WithPretty() func(*WatcherActivateWatchRequest) { + return func(r *WatcherActivateWatchRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f WatcherActivateWatch) WithHuman() func(*WatcherActivateWatchRequest) { + return func(r *WatcherActivateWatchRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f WatcherActivateWatch) WithErrorTrace() func(*WatcherActivateWatchRequest) { + return func(r *WatcherActivateWatchRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f WatcherActivateWatch) WithFilterPath(v ...string) func(*WatcherActivateWatchRequest) { + return func(r *WatcherActivateWatchRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f WatcherActivateWatch) WithHeader(h map[string]string) func(*WatcherActivateWatchRequest) { + return func(r *WatcherActivateWatchRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f WatcherActivateWatch) WithOpaqueID(s string) func(*WatcherActivateWatchRequest) { + return func(r *WatcherActivateWatchRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.deactivate_watch.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.deactivate_watch.go new file mode 100644 index 00000000000..9b39ff40cce --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.deactivate_watch.go @@ -0,0 +1,192 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newWatcherDeactivateWatchFunc(t Transport) WatcherDeactivateWatch { + return func(watch_id string, o ...func(*WatcherDeactivateWatchRequest)) (*Response, error) { + var r = WatcherDeactivateWatchRequest{WatchID: watch_id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// WatcherDeactivateWatch - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-deactivate-watch.html. +// +type WatcherDeactivateWatch func(watch_id string, o ...func(*WatcherDeactivateWatchRequest)) (*Response, error) + +// WatcherDeactivateWatchRequest configures the Watcher Deactivate Watch API request. +// +type WatcherDeactivateWatchRequest struct { + WatchID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r WatcherDeactivateWatchRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_watcher") + 1 + len("watch") + 1 + len(r.WatchID) + 1 + len("_deactivate")) + path.WriteString("/") + path.WriteString("_watcher") + path.WriteString("/") + path.WriteString("watch") + path.WriteString("/") + path.WriteString(r.WatchID) + path.WriteString("/") + path.WriteString("_deactivate") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f WatcherDeactivateWatch) WithContext(v context.Context) func(*WatcherDeactivateWatchRequest) { + return func(r *WatcherDeactivateWatchRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f WatcherDeactivateWatch) WithPretty() func(*WatcherDeactivateWatchRequest) { + return func(r *WatcherDeactivateWatchRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f WatcherDeactivateWatch) WithHuman() func(*WatcherDeactivateWatchRequest) { + return func(r *WatcherDeactivateWatchRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f WatcherDeactivateWatch) WithErrorTrace() func(*WatcherDeactivateWatchRequest) { + return func(r *WatcherDeactivateWatchRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f WatcherDeactivateWatch) WithFilterPath(v ...string) func(*WatcherDeactivateWatchRequest) { + return func(r *WatcherDeactivateWatchRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f WatcherDeactivateWatch) WithHeader(h map[string]string) func(*WatcherDeactivateWatchRequest) { + return func(r *WatcherDeactivateWatchRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f WatcherDeactivateWatch) WithOpaqueID(s string) func(*WatcherDeactivateWatchRequest) { + return func(r *WatcherDeactivateWatchRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.delete_watch.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.delete_watch.go new file mode 100644 index 00000000000..60b6e3d2109 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.delete_watch.go @@ -0,0 +1,190 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newWatcherDeleteWatchFunc(t Transport) WatcherDeleteWatch { + return func(id string, o ...func(*WatcherDeleteWatchRequest)) (*Response, error) { + var r = WatcherDeleteWatchRequest{WatchID: id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// WatcherDeleteWatch - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-delete-watch.html. +// +type WatcherDeleteWatch func(id string, o ...func(*WatcherDeleteWatchRequest)) (*Response, error) + +// WatcherDeleteWatchRequest configures the Watcher Delete Watch API request. +// +type WatcherDeleteWatchRequest struct { + WatchID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r WatcherDeleteWatchRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "DELETE" + + path.Grow(1 + len("_watcher") + 1 + len("watch") + 1 + len(r.WatchID)) + path.WriteString("/") + path.WriteString("_watcher") + path.WriteString("/") + path.WriteString("watch") + path.WriteString("/") + path.WriteString(r.WatchID) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f WatcherDeleteWatch) WithContext(v context.Context) func(*WatcherDeleteWatchRequest) { + return func(r *WatcherDeleteWatchRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f WatcherDeleteWatch) WithPretty() func(*WatcherDeleteWatchRequest) { + return func(r *WatcherDeleteWatchRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f WatcherDeleteWatch) WithHuman() func(*WatcherDeleteWatchRequest) { + return func(r *WatcherDeleteWatchRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f WatcherDeleteWatch) WithErrorTrace() func(*WatcherDeleteWatchRequest) { + return func(r *WatcherDeleteWatchRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f WatcherDeleteWatch) WithFilterPath(v ...string) func(*WatcherDeleteWatchRequest) { + return func(r *WatcherDeleteWatchRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f WatcherDeleteWatch) WithHeader(h map[string]string) func(*WatcherDeleteWatchRequest) { + return func(r *WatcherDeleteWatchRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f WatcherDeleteWatch) WithOpaqueID(s string) func(*WatcherDeleteWatchRequest) { + return func(r *WatcherDeleteWatchRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.execute_watch.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.execute_watch.go new file mode 100644 index 00000000000..0d93c6c6cae --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.execute_watch.go @@ -0,0 +1,232 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newWatcherExecuteWatchFunc(t Transport) WatcherExecuteWatch { + return func(o ...func(*WatcherExecuteWatchRequest)) (*Response, error) { + var r = WatcherExecuteWatchRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// WatcherExecuteWatch - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-execute-watch.html. +// +type WatcherExecuteWatch func(o ...func(*WatcherExecuteWatchRequest)) (*Response, error) + +// WatcherExecuteWatchRequest configures the Watcher Execute Watch API request. +// +type WatcherExecuteWatchRequest struct { + WatchID string + + Body io.Reader + + Debug *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r WatcherExecuteWatchRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_watcher") + 1 + len("watch") + 1 + len(r.WatchID) + 1 + len("_execute")) + path.WriteString("/") + path.WriteString("_watcher") + path.WriteString("/") + path.WriteString("watch") + if r.WatchID != "" { + path.WriteString("/") + path.WriteString(r.WatchID) + } + path.WriteString("/") + path.WriteString("_execute") + + params = make(map[string]string) + + if r.Debug != nil { + params["debug"] = strconv.FormatBool(*r.Debug) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f WatcherExecuteWatch) WithContext(v context.Context) func(*WatcherExecuteWatchRequest) { + return func(r *WatcherExecuteWatchRequest) { + r.ctx = v + } +} + +// WithBody - Execution control. +// +func (f WatcherExecuteWatch) WithBody(v io.Reader) func(*WatcherExecuteWatchRequest) { + return func(r *WatcherExecuteWatchRequest) { + r.Body = v + } +} + +// WithWatchID - watch ID. +// +func (f WatcherExecuteWatch) WithWatchID(v string) func(*WatcherExecuteWatchRequest) { + return func(r *WatcherExecuteWatchRequest) { + r.WatchID = v + } +} + +// WithDebug - indicates whether the watch should execute in debug mode. +// +func (f WatcherExecuteWatch) WithDebug(v bool) func(*WatcherExecuteWatchRequest) { + return func(r *WatcherExecuteWatchRequest) { + r.Debug = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f WatcherExecuteWatch) WithPretty() func(*WatcherExecuteWatchRequest) { + return func(r *WatcherExecuteWatchRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f WatcherExecuteWatch) WithHuman() func(*WatcherExecuteWatchRequest) { + return func(r *WatcherExecuteWatchRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f WatcherExecuteWatch) WithErrorTrace() func(*WatcherExecuteWatchRequest) { + return func(r *WatcherExecuteWatchRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f WatcherExecuteWatch) WithFilterPath(v ...string) func(*WatcherExecuteWatchRequest) { + return func(r *WatcherExecuteWatchRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f WatcherExecuteWatch) WithHeader(h map[string]string) func(*WatcherExecuteWatchRequest) { + return func(r *WatcherExecuteWatchRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f WatcherExecuteWatch) WithOpaqueID(s string) func(*WatcherExecuteWatchRequest) { + return func(r *WatcherExecuteWatchRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.get_watch.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.get_watch.go new file mode 100644 index 00000000000..b065e50fcd5 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.get_watch.go @@ -0,0 +1,190 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newWatcherGetWatchFunc(t Transport) WatcherGetWatch { + return func(id string, o ...func(*WatcherGetWatchRequest)) (*Response, error) { + var r = WatcherGetWatchRequest{WatchID: id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// WatcherGetWatch - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-get-watch.html. +// +type WatcherGetWatch func(id string, o ...func(*WatcherGetWatchRequest)) (*Response, error) + +// WatcherGetWatchRequest configures the Watcher Get Watch API request. +// +type WatcherGetWatchRequest struct { + WatchID string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r WatcherGetWatchRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_watcher") + 1 + len("watch") + 1 + len(r.WatchID)) + path.WriteString("/") + path.WriteString("_watcher") + path.WriteString("/") + path.WriteString("watch") + path.WriteString("/") + path.WriteString(r.WatchID) + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f WatcherGetWatch) WithContext(v context.Context) func(*WatcherGetWatchRequest) { + return func(r *WatcherGetWatchRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f WatcherGetWatch) WithPretty() func(*WatcherGetWatchRequest) { + return func(r *WatcherGetWatchRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f WatcherGetWatch) WithHuman() func(*WatcherGetWatchRequest) { + return func(r *WatcherGetWatchRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f WatcherGetWatch) WithErrorTrace() func(*WatcherGetWatchRequest) { + return func(r *WatcherGetWatchRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f WatcherGetWatch) WithFilterPath(v ...string) func(*WatcherGetWatchRequest) { + return func(r *WatcherGetWatchRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f WatcherGetWatch) WithHeader(h map[string]string) func(*WatcherGetWatchRequest) { + return func(r *WatcherGetWatchRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f WatcherGetWatch) WithOpaqueID(s string) func(*WatcherGetWatchRequest) { + return func(r *WatcherGetWatchRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.put_watch.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.put_watch.go new file mode 100644 index 00000000000..8321a85e39e --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.put_watch.go @@ -0,0 +1,259 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "io" + "net/http" + "strconv" + "strings" +) + +func newWatcherPutWatchFunc(t Transport) WatcherPutWatch { + return func(id string, o ...func(*WatcherPutWatchRequest)) (*Response, error) { + var r = WatcherPutWatchRequest{WatchID: id} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// WatcherPutWatch - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-put-watch.html. +// +type WatcherPutWatch func(id string, o ...func(*WatcherPutWatchRequest)) (*Response, error) + +// WatcherPutWatchRequest configures the Watcher Put Watch API request. +// +type WatcherPutWatchRequest struct { + WatchID string + + Body io.Reader + + Active *bool + IfPrimaryTerm *int + IfSeqNo *int + Version *int + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r WatcherPutWatchRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "PUT" + + path.Grow(1 + len("_watcher") + 1 + len("watch") + 1 + len(r.WatchID)) + path.WriteString("/") + path.WriteString("_watcher") + path.WriteString("/") + path.WriteString("watch") + path.WriteString("/") + path.WriteString(r.WatchID) + + params = make(map[string]string) + + if r.Active != nil { + params["active"] = strconv.FormatBool(*r.Active) + } + + if r.IfPrimaryTerm != nil { + params["if_primary_term"] = strconv.FormatInt(int64(*r.IfPrimaryTerm), 10) + } + + if r.IfSeqNo != nil { + params["if_seq_no"] = strconv.FormatInt(int64(*r.IfSeqNo), 10) + } + + if r.Version != nil { + params["version"] = strconv.FormatInt(int64(*r.Version), 10) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), r.Body) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f WatcherPutWatch) WithContext(v context.Context) func(*WatcherPutWatchRequest) { + return func(r *WatcherPutWatchRequest) { + r.ctx = v + } +} + +// WithBody - The watch. +// +func (f WatcherPutWatch) WithBody(v io.Reader) func(*WatcherPutWatchRequest) { + return func(r *WatcherPutWatchRequest) { + r.Body = v + } +} + +// WithActive - specify whether the watch is in/active by default. +// +func (f WatcherPutWatch) WithActive(v bool) func(*WatcherPutWatchRequest) { + return func(r *WatcherPutWatchRequest) { + r.Active = &v + } +} + +// WithIfPrimaryTerm - only update the watch if the last operation that has changed the watch has the specified primary term. +// +func (f WatcherPutWatch) WithIfPrimaryTerm(v int) func(*WatcherPutWatchRequest) { + return func(r *WatcherPutWatchRequest) { + r.IfPrimaryTerm = &v + } +} + +// WithIfSeqNo - only update the watch if the last operation that has changed the watch has the specified sequence number. +// +func (f WatcherPutWatch) WithIfSeqNo(v int) func(*WatcherPutWatchRequest) { + return func(r *WatcherPutWatchRequest) { + r.IfSeqNo = &v + } +} + +// WithVersion - explicit version number for concurrency control. +// +func (f WatcherPutWatch) WithVersion(v int) func(*WatcherPutWatchRequest) { + return func(r *WatcherPutWatchRequest) { + r.Version = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f WatcherPutWatch) WithPretty() func(*WatcherPutWatchRequest) { + return func(r *WatcherPutWatchRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f WatcherPutWatch) WithHuman() func(*WatcherPutWatchRequest) { + return func(r *WatcherPutWatchRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f WatcherPutWatch) WithErrorTrace() func(*WatcherPutWatchRequest) { + return func(r *WatcherPutWatchRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f WatcherPutWatch) WithFilterPath(v ...string) func(*WatcherPutWatchRequest) { + return func(r *WatcherPutWatchRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f WatcherPutWatch) WithHeader(h map[string]string) func(*WatcherPutWatchRequest) { + return func(r *WatcherPutWatchRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f WatcherPutWatch) WithOpaqueID(s string) func(*WatcherPutWatchRequest) { + return func(r *WatcherPutWatchRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.start.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.start.go new file mode 100644 index 00000000000..1de394f12e1 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.start.go @@ -0,0 +1,183 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newWatcherStartFunc(t Transport) WatcherStart { + return func(o ...func(*WatcherStartRequest)) (*Response, error) { + var r = WatcherStartRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// WatcherStart - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-start.html. +// +type WatcherStart func(o ...func(*WatcherStartRequest)) (*Response, error) + +// WatcherStartRequest configures the Watcher Start API request. +// +type WatcherStartRequest struct { + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r WatcherStartRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(len("/_watcher/_start")) + path.WriteString("/_watcher/_start") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f WatcherStart) WithContext(v context.Context) func(*WatcherStartRequest) { + return func(r *WatcherStartRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f WatcherStart) WithPretty() func(*WatcherStartRequest) { + return func(r *WatcherStartRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f WatcherStart) WithHuman() func(*WatcherStartRequest) { + return func(r *WatcherStartRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f WatcherStart) WithErrorTrace() func(*WatcherStartRequest) { + return func(r *WatcherStartRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f WatcherStart) WithFilterPath(v ...string) func(*WatcherStartRequest) { + return func(r *WatcherStartRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f WatcherStart) WithHeader(h map[string]string) func(*WatcherStartRequest) { + return func(r *WatcherStartRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f WatcherStart) WithOpaqueID(s string) func(*WatcherStartRequest) { + return func(r *WatcherStartRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.stats.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.stats.go new file mode 100644 index 00000000000..a74e602af12 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.stats.go @@ -0,0 +1,219 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strconv" + "strings" +) + +func newWatcherStatsFunc(t Transport) WatcherStats { + return func(o ...func(*WatcherStatsRequest)) (*Response, error) { + var r = WatcherStatsRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// WatcherStats - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-stats.html. +// +type WatcherStats func(o ...func(*WatcherStatsRequest)) (*Response, error) + +// WatcherStatsRequest configures the Watcher Stats API request. +// +type WatcherStatsRequest struct { + Metric []string + + EmitStacktraces *bool + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r WatcherStatsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(1 + len("_watcher") + 1 + len("stats") + 1 + len(strings.Join(r.Metric, ","))) + path.WriteString("/") + path.WriteString("_watcher") + path.WriteString("/") + path.WriteString("stats") + if len(r.Metric) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Metric, ",")) + } + + params = make(map[string]string) + + if r.EmitStacktraces != nil { + params["emit_stacktraces"] = strconv.FormatBool(*r.EmitStacktraces) + } + + if len(r.Metric) > 0 { + params["metric"] = strings.Join(r.Metric, ",") + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f WatcherStats) WithContext(v context.Context) func(*WatcherStatsRequest) { + return func(r *WatcherStatsRequest) { + r.ctx = v + } +} + +// WithMetric - controls what additional stat metrics should be include in the response. +// +func (f WatcherStats) WithMetric(v ...string) func(*WatcherStatsRequest) { + return func(r *WatcherStatsRequest) { + r.Metric = v + } +} + +// WithEmitStacktraces - emits stack traces of currently running watches. +// +func (f WatcherStats) WithEmitStacktraces(v bool) func(*WatcherStatsRequest) { + return func(r *WatcherStatsRequest) { + r.EmitStacktraces = &v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f WatcherStats) WithPretty() func(*WatcherStatsRequest) { + return func(r *WatcherStatsRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f WatcherStats) WithHuman() func(*WatcherStatsRequest) { + return func(r *WatcherStatsRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f WatcherStats) WithErrorTrace() func(*WatcherStatsRequest) { + return func(r *WatcherStatsRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f WatcherStats) WithFilterPath(v ...string) func(*WatcherStatsRequest) { + return func(r *WatcherStatsRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f WatcherStats) WithHeader(h map[string]string) func(*WatcherStatsRequest) { + return func(r *WatcherStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f WatcherStats) WithOpaqueID(s string) func(*WatcherStatsRequest) { + return func(r *WatcherStatsRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.stop.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.stop.go new file mode 100644 index 00000000000..4f36a49bf19 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.watcher.stop.go @@ -0,0 +1,183 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newWatcherStopFunc(t Transport) WatcherStop { + return func(o ...func(*WatcherStopRequest)) (*Response, error) { + var r = WatcherStopRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// WatcherStop - +// +// See full documentation at http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-stop.html. +// +type WatcherStop func(o ...func(*WatcherStopRequest)) (*Response, error) + +// WatcherStopRequest configures the Watcher Stop API request. +// +type WatcherStopRequest struct { + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r WatcherStopRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "POST" + + path.Grow(len("/_watcher/_stop")) + path.WriteString("/_watcher/_stop") + + params = make(map[string]string) + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f WatcherStop) WithContext(v context.Context) func(*WatcherStopRequest) { + return func(r *WatcherStopRequest) { + r.ctx = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f WatcherStop) WithPretty() func(*WatcherStopRequest) { + return func(r *WatcherStopRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f WatcherStop) WithHuman() func(*WatcherStopRequest) { + return func(r *WatcherStopRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f WatcherStop) WithErrorTrace() func(*WatcherStopRequest) { + return func(r *WatcherStopRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f WatcherStop) WithFilterPath(v ...string) func(*WatcherStopRequest) { + return func(r *WatcherStopRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f WatcherStop) WithHeader(h map[string]string) func(*WatcherStopRequest) { + return func(r *WatcherStopRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f WatcherStop) WithOpaqueID(s string) func(*WatcherStopRequest) { + return func(r *WatcherStopRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.xpack.info.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.xpack.info.go new file mode 100644 index 00000000000..e4e7ffe5034 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.xpack.info.go @@ -0,0 +1,197 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" +) + +func newXPackInfoFunc(t Transport) XPackInfo { + return func(o ...func(*XPackInfoRequest)) (*Response, error) { + var r = XPackInfoRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// XPackInfo - +// +// See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/info-api.html. +// +type XPackInfo func(o ...func(*XPackInfoRequest)) (*Response, error) + +// XPackInfoRequest configures the X Pack Info API request. +// +type XPackInfoRequest struct { + Categories []string + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r XPackInfoRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_xpack")) + path.WriteString("/_xpack") + + params = make(map[string]string) + + if len(r.Categories) > 0 { + params["categories"] = strings.Join(r.Categories, ",") + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f XPackInfo) WithContext(v context.Context) func(*XPackInfoRequest) { + return func(r *XPackInfoRequest) { + r.ctx = v + } +} + +// WithCategories - comma-separated list of info categories. can be any of: build, license, features. +// +func (f XPackInfo) WithCategories(v ...string) func(*XPackInfoRequest) { + return func(r *XPackInfoRequest) { + r.Categories = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f XPackInfo) WithPretty() func(*XPackInfoRequest) { + return func(r *XPackInfoRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f XPackInfo) WithHuman() func(*XPackInfoRequest) { + return func(r *XPackInfoRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f XPackInfo) WithErrorTrace() func(*XPackInfoRequest) { + return func(r *XPackInfoRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f XPackInfo) WithFilterPath(v ...string) func(*XPackInfoRequest) { + return func(r *XPackInfoRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f XPackInfo) WithHeader(h map[string]string) func(*XPackInfoRequest) { + return func(r *XPackInfoRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f XPackInfo) WithOpaqueID(s string) func(*XPackInfoRequest) { + return func(r *XPackInfoRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.xpack.usage.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.xpack.usage.go new file mode 100644 index 00000000000..0ebcd04633b --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.xpack.usage.go @@ -0,0 +1,196 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// Code generated from specification version 8.0.0: DO NOT EDIT + +package esapi + +import ( + "context" + "net/http" + "strings" + "time" +) + +func newXPackUsageFunc(t Transport) XPackUsage { + return func(o ...func(*XPackUsageRequest)) (*Response, error) { + var r = XPackUsageRequest{} + for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} + +// ----- API Definition ------------------------------------------------------- + +// XPackUsage - Retrieve information about xpack features usage +// +type XPackUsage func(o ...func(*XPackUsageRequest)) (*Response, error) + +// XPackUsageRequest configures the X Pack Usage API request. +// +type XPackUsageRequest struct { + MasterTimeout time.Duration + + Pretty bool + Human bool + ErrorTrace bool + FilterPath []string + + Header http.Header + + ctx context.Context +} + +// Do executes the request and returns response or error. +// +func (r XPackUsageRequest) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + ) + + method = "GET" + + path.Grow(len("/_xpack/usage")) + path.WriteString("/_xpack/usage") + + params = make(map[string]string) + + if r.MasterTimeout != 0 { + params["master_timeout"] = formatDuration(r.MasterTimeout) + } + + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + + req, err := newRequest(method, path.String(), nil) + if err != nil { + return nil, err + } + + if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + } + + if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + } + + if ctx != nil { + req = req.WithContext(ctx) + } + + res, err := transport.Perform(req) + if err != nil { + return nil, err + } + + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + } + + return &response, nil +} + +// WithContext sets the request context. +// +func (f XPackUsage) WithContext(v context.Context) func(*XPackUsageRequest) { + return func(r *XPackUsageRequest) { + r.ctx = v + } +} + +// WithMasterTimeout - specify timeout for watch write operation. +// +func (f XPackUsage) WithMasterTimeout(v time.Duration) func(*XPackUsageRequest) { + return func(r *XPackUsageRequest) { + r.MasterTimeout = v + } +} + +// WithPretty makes the response body pretty-printed. +// +func (f XPackUsage) WithPretty() func(*XPackUsageRequest) { + return func(r *XPackUsageRequest) { + r.Pretty = true + } +} + +// WithHuman makes statistical values human-readable. +// +func (f XPackUsage) WithHuman() func(*XPackUsageRequest) { + return func(r *XPackUsageRequest) { + r.Human = true + } +} + +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f XPackUsage) WithErrorTrace() func(*XPackUsageRequest) { + return func(r *XPackUsageRequest) { + r.ErrorTrace = true + } +} + +// WithFilterPath filters the properties of the response body. +// +func (f XPackUsage) WithFilterPath(v ...string) func(*XPackUsageRequest) { + return func(r *XPackUsageRequest) { + r.FilterPath = v + } +} + +// WithHeader adds the headers to the HTTP request. +// +func (f XPackUsage) WithHeader(h map[string]string) func(*XPackUsageRequest) { + return func(r *XPackUsageRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} + +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f XPackUsage) WithOpaqueID(s string) func(*XPackUsageRequest) { + return func(r *XPackUsageRequest) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/doc.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/doc.go new file mode 100644 index 00000000000..9ec80847771 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/doc.go @@ -0,0 +1,95 @@ +/* +Package esapi provides the Go API for Elasticsearch. + +It is automatically included in the client provided by the +github.com/elastic/go-elasticsearch package: + + es, _ := elasticsearch.NewDefaultClient() + res, _ := es.Info() + log.Println(res) + +For each Elasticsearch API, such as "Index", the package exports two corresponding types: +a function and a struct. + +The function type allows you to call the Elasticsearch API as a method on the client, +passing the parameters as arguments: + + res, err := es.Index( + "test", // Index name + strings.NewReader(`{"title" : "Test"}`), // Document body + es.Index.WithDocumentID("1"), // Document ID + es.Index.WithRefresh("true"), // Refresh + ) + if err != nil { + log.Fatalf("ERROR: %s", err) + } + defer res.Body.Close() + + log.Println(res) + + // => [201 Created] {"_index":"test","_type":"_doc","_id":"1" ... + +The struct type allows for a more hands-on approach, where you create a new struct, with the +request configuration as fields, and call the Do() method +with a context and the client as arguments: + + req := esapi.IndexRequest{ + Index: "test", // Index name + Body: strings.NewReader(`{"title" : "Test"}`), // Document body + DocumentID: "1", // Document ID + Refresh: "true", // Refresh + } + + res, err := req.Do(context.Background(), es) + if err != nil { + log.Fatalf("Error getting response: %s", err) + } + defer res.Body.Close() + + log.Println(res) + + // => [200 OK] {"_index":"test","_type":"_doc","_id":"1","_version":2 ... + +The function type is a wrapper around the struct, and allows +to configure and perform the request in a more expressive way. +It has a minor overhead compared to using a struct directly; +refer to the esapi_benchmark_test.go suite for concrete numbers. + +See the documentation for each API function or struct at +https://godoc.org/github.com/elastic/go-elasticsearch, +or locally by: + + go doc github.com/elastic/go-elasticsearch/v8/esapi Index + go doc github.com/elastic/go-elasticsearch/v8/esapi IndexRequest + +Response + +The esapi.Response type is a lightweight wrapper around http.Response. + +The res.Body field is an io.ReadCloser, leaving the JSON parsing to the +calling code, in the interest of performance and flexibility +(eg. to allow using a custom JSON parser). + +It is imperative to close the response body for a non-nil response. + +The Response type implements a couple of convenience methods for accessing +the status, checking an error status code or printing +the response body for debugging purposes. + +Additional Information + +See the Elasticsearch documentation at +https://www.elastic.co/guide/en/elasticsearch/reference/master/api-conventions.html for detailed information +about the API endpoints and parameters. + +The Go API is generated from the Elasticsearch JSON specification at +https://github.com/elastic/elasticsearch/tree/master/rest-api-spec/src/main/resources/rest-api-spec/api +by the internal package available at +https://github.com/elastic/go-elasticsearch/tree/master/internal/cmd/generate/commands/gensource. + +The API is tested by integration tests common to all Elasticsearch official clients, generated from the +source at https://github.com/elastic/elasticsearch/tree/master/rest-api-spec/src/main/resources/rest-api-spec/test. +The generator is provided by the internal package available at internal/cmd/generate/commands/gentests. + +*/ +package esapi diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/esapi.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/esapi.go new file mode 100644 index 00000000000..cc792858869 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/esapi.go @@ -0,0 +1,49 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package esapi + +import ( + "net/http" + "strconv" + "time" + + "github.com/elastic/go-elasticsearch/v8/internal/version" +) + +// Version returns the package version as a string. +// +const Version = version.Client + +// Transport defines the interface for an API client. +// +type Transport interface { + Perform(*http.Request) (*http.Response, error) +} + +// BoolPtr returns a pointer to v. +// +// It is used as a convenience function for converting a bool value +// into a pointer when passing the value to a function or struct field +// which expects a pointer. +// +func BoolPtr(v bool) *bool { return &v } + +// IntPtr returns a pointer to v. +// +// It is used as a convenience function for converting an int value +// into a pointer when passing the value to a function or struct field +// which expects a pointer. +// +func IntPtr(v int) *int { return &v } + +// formatDuration converts duration to a string in the format +// accepted by Elasticsearch. +// +func formatDuration(d time.Duration) string { + if d < time.Millisecond { + return strconv.FormatInt(int64(d), 10) + "nanos" + } + return strconv.FormatInt(int64(d)/int64(time.Millisecond), 10) + "ms" +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/esapi.request.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/esapi.request.go new file mode 100644 index 00000000000..d967fc61f5c --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/esapi.request.go @@ -0,0 +1,31 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package esapi + +import ( + "context" + "io" + "net/http" +) + +const ( + headerContentType = "Content-Type" +) + +var ( + headerContentTypeJSON = []string{"application/json"} +) + +// Request defines the API request. +// +type Request interface { + Do(ctx context.Context, transport Transport) (*Response, error) +} + +// newRequest creates an HTTP request. +// +func newRequest(method, path string, body io.Reader) (*http.Request, error) { + return http.NewRequest(method, path, body) +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/esapi.response.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/esapi.response.go new file mode 100644 index 00000000000..d1f8442152f --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/esapi.response.go @@ -0,0 +1,80 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package esapi + +import ( + "bytes" + "fmt" + "io" + "io/ioutil" + "net/http" + "strconv" + "strings" +) + +// Response represents the API response. +// +type Response struct { + StatusCode int + Header http.Header + Body io.ReadCloser +} + +// String returns the response as a string. +// +// The intended usage is for testing or debugging only. +// +func (r *Response) String() string { + var ( + out = new(bytes.Buffer) + b1 = bytes.NewBuffer([]byte{}) + b2 = bytes.NewBuffer([]byte{}) + tr io.Reader + ) + + if r != nil && r.Body != nil { + tr = io.TeeReader(r.Body, b1) + defer r.Body.Close() + + if _, err := io.Copy(b2, tr); err != nil { + out.WriteString(fmt.Sprintf("", err)) + return out.String() + } + defer func() { r.Body = ioutil.NopCloser(b1) }() + } + + if r != nil { + out.WriteString(fmt.Sprintf("[%d %s]", r.StatusCode, http.StatusText(r.StatusCode))) + if r.StatusCode > 0 { + out.WriteRune(' ') + } + } else { + out.WriteString("[0 ]") + } + + if r != nil && r.Body != nil { + out.ReadFrom(b2) // errcheck exclude (*bytes.Buffer).ReadFrom + } + + return out.String() +} + +// Status returns the response status as a string. +// +func (r *Response) Status() string { + var b strings.Builder + if r != nil { + b.WriteString(strconv.Itoa(r.StatusCode)) + b.WriteString(" ") + b.WriteString(http.StatusText(r.StatusCode)) + } + return b.String() +} + +// IsError returns true when the response status indicates failure. +// +func (r *Response) IsError() bool { + return r.StatusCode > 299 +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/test/go.mod b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/test/go.mod new file mode 100644 index 00000000000..6f0b667e058 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/test/go.mod @@ -0,0 +1,11 @@ +module github.com/elastic/go-elasticsearch/v8/esapi/test + +go 1.11 + +replace github.com/elastic/go-elasticsearch/v8 => ../../ + +require ( + github.com/elastic/go-elasticsearch/v8 master + + gopkg.in/yaml.v2 v2.2.2 +) diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/estransport/doc.go b/vendor/github.com/elastic/go-elasticsearch/v8/estransport/doc.go new file mode 100644 index 00000000000..e65e34284f6 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/estransport/doc.go @@ -0,0 +1,28 @@ +/* +Package estransport provides the transport layer for the Elasticsearch client. + +It is automatically included in the client provided by the github.com/elastic/go-elasticsearch package +and is not intended for direct use: to configure the client, use the elasticsearch.Config struct. + +The default HTTP transport of the client is http.Transport; use the Transport option to customize it; +see the _examples/customization.go file in this repository for information. + +The package defines the "Selector" interface for getting a URL from the list. At the moment, +the implementation is rather minimal: the client takes a slice of url.URL pointers, +and round-robins across them when performing the request. + +The package will automatically retry requests on network-related errors, and on specific +response status codes (by default 502, 503, 504). Use the RetryOnStatus option to customize the list. +The transport will not retry a timeout network error, unless enabled by setting EnableRetryOnTimeout to true. + +Use the MaxRetries option to configure the number of retries, and set DisableRetry to true +to disable the retry behaviour altogether. + +By default, the retry will be performed without any delay; to configure a backoff interval, +implement the RetryBackoff option function; see an example in the package unit tests for information. + +The package defines the "Logger" interface for logging information about request and response. +It comes with several bundled loggers for logging in text and JSON. + +*/ +package estransport diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/estransport/estransport.go b/vendor/github.com/elastic/go-elasticsearch/v8/estransport/estransport.go new file mode 100644 index 00000000000..da8315a1478 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/estransport/estransport.go @@ -0,0 +1,320 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package estransport + +import ( + "bytes" + "fmt" + "io" + "io/ioutil" + "net" + "net/http" + "net/url" + "regexp" + "runtime" + "strings" + "time" + + "github.com/elastic/go-elasticsearch/v8/internal/version" +) + +// Version returns the package version as a string. +// +const Version = version.Client + +var ( + userAgent string + reGoVersion = regexp.MustCompile(`go(\d+\.\d+\..+)`) + + defaultMaxRetries = 3 + defaultRetryOnStatus = [...]int{502, 503, 504} +) + +func init() { + userAgent = initUserAgent() +} + +// Interface defines the interface for HTTP client. +// +type Interface interface { + Perform(*http.Request) (*http.Response, error) +} + +// Config represents the configuration of HTTP client. +// +type Config struct { + URLs []*url.URL + Username string + Password string + APIKey string + + RetryOnStatus []int + DisableRetry bool + EnableRetryOnTimeout bool + MaxRetries int + RetryBackoff func(attempt int) time.Duration + + Transport http.RoundTripper + Logger Logger +} + +// Client represents the HTTP client. +// +type Client struct { + urls []*url.URL + username string + password string + apikey string + + retryOnStatus []int + disableRetry bool + enableRetryOnTimeout bool + maxRetries int + retryBackoff func(attempt int) time.Duration + + transport http.RoundTripper + selector Selector + logger Logger +} + +// New creates new HTTP client. +// +// http.DefaultTransport will be used if no transport is passed in the configuration. +// +func New(cfg Config) *Client { + if cfg.Transport == nil { + cfg.Transport = http.DefaultTransport + } + + if len(cfg.RetryOnStatus) == 0 { + cfg.RetryOnStatus = defaultRetryOnStatus[:] + } + + if cfg.MaxRetries == 0 { + cfg.MaxRetries = defaultMaxRetries + } + + return &Client{ + urls: cfg.URLs, + username: cfg.Username, + password: cfg.Password, + apikey: cfg.APIKey, + + retryOnStatus: cfg.RetryOnStatus, + disableRetry: cfg.DisableRetry, + enableRetryOnTimeout: cfg.EnableRetryOnTimeout, + maxRetries: cfg.MaxRetries, + retryBackoff: cfg.RetryBackoff, + + transport: cfg.Transport, + selector: NewRoundRobinSelector(cfg.URLs...), + logger: cfg.Logger, + } +} + +// Perform executes the request and returns a response or error. +// +func (c *Client) Perform(req *http.Request) (*http.Response, error) { + var ( + res *http.Response + err error + ) + + // Update request + // + c.setReqUserAgent(req) + + if req.Body != nil && req.Body != http.NoBody && req.GetBody == nil { + if !c.disableRetry || (c.logger != nil && c.logger.RequestBodyEnabled()) { + var buf bytes.Buffer + buf.ReadFrom(req.Body) + req.GetBody = func() (io.ReadCloser, error) { + r := buf + return ioutil.NopCloser(&r), nil + } + if req.Body, err = req.GetBody(); err != nil { + return nil, fmt.Errorf("cannot get request body: %s", err) + } + } + } + + for i := 1; i <= c.maxRetries; i++ { + var ( + nodeURL *url.URL + shouldRetry bool + ) + + // Get URL from the Selector + // + nodeURL, err = c.getURL() + if err != nil { + // TODO(karmi): Log error + return nil, fmt.Errorf("cannot get URL: %s", err) + } + + // Update request + // + c.setReqURL(nodeURL, req) + c.setReqAuth(nodeURL, req) + + if !c.disableRetry && i > 1 && req.Body != nil && req.Body != http.NoBody { + body, err := req.GetBody() + if err != nil { + return nil, fmt.Errorf("cannot get request body: %s", err) + } + req.Body = body + } + + // Set up time measures and execute the request + // + start := time.Now().UTC() + res, err = c.transport.RoundTrip(req) + dur := time.Since(start) + + // Log request and response + // + if c.logger != nil { + if c.logger.RequestBodyEnabled() && req.Body != nil && req.Body != http.NoBody { + req.Body, _ = req.GetBody() + } + c.logRoundTrip(req, res, err, start, dur) + } + + // Retry only on network errors, but don't retry on timeout errors, unless configured + // + if err != nil { + if err, ok := err.(net.Error); ok { + if (!err.Timeout() || c.enableRetryOnTimeout) && !c.disableRetry { + shouldRetry = true + } + } + } + + // Retry on configured response statuses + // + if res != nil && !c.disableRetry { + for _, code := range c.retryOnStatus { + if res.StatusCode == code { + shouldRetry = true + } + } + } + + // Break if retry should not be performed + // + if !shouldRetry { + break + } + + // Delay the retry if a backoff function is configured + // + if c.retryBackoff != nil { + time.Sleep(c.retryBackoff(i)) + } + } + + // TODO(karmi): Wrap error + return res, err +} + +// URLs returns a list of transport URLs. +// +func (c *Client) URLs() []*url.URL { + return c.urls +} + +func (c *Client) getURL() (*url.URL, error) { + return c.selector.Select() +} + +func (c *Client) setReqURL(u *url.URL, req *http.Request) *http.Request { + req.URL.Scheme = u.Scheme + req.URL.Host = u.Host + + if u.Path != "" { + var b strings.Builder + b.Grow(len(u.Path) + len(req.URL.Path)) + b.WriteString(u.Path) + b.WriteString(req.URL.Path) + req.URL.Path = b.String() + } + + return req +} + +func (c *Client) setReqAuth(u *url.URL, req *http.Request) *http.Request { + if _, ok := req.Header["Authorization"]; !ok { + if u.User != nil { + password, _ := u.User.Password() + req.SetBasicAuth(u.User.Username(), password) + return req + } + + if c.apikey != "" { + var b bytes.Buffer + b.Grow(len("APIKey ") + len(c.apikey)) + b.WriteString("APIKey ") + b.WriteString(c.apikey) + req.Header.Set("Authorization", b.String()) + return req + } + + if c.username != "" && c.password != "" { + req.SetBasicAuth(c.username, c.password) + return req + } + } + + return req +} + +func (c *Client) setReqUserAgent(req *http.Request) *http.Request { + req.Header.Set("User-Agent", userAgent) + return req +} + +func (c *Client) logRoundTrip( + req *http.Request, + res *http.Response, + err error, + start time.Time, + dur time.Duration, +) { + var dupRes http.Response + if res != nil { + dupRes = *res + } + if c.logger.ResponseBodyEnabled() { + if res != nil && res.Body != nil && res.Body != http.NoBody { + b1, b2, _ := duplicateBody(res.Body) + dupRes.Body = b1 + res.Body = b2 + } + } + c.logger.LogRoundTrip(req, &dupRes, err, start, dur) // errcheck exclude +} + +func initUserAgent() string { + var b strings.Builder + + b.WriteString("go-elasticsearch") + b.WriteRune('/') + b.WriteString(Version) + b.WriteRune(' ') + b.WriteRune('(') + b.WriteString(runtime.GOOS) + b.WriteRune(' ') + b.WriteString(runtime.GOARCH) + b.WriteString("; ") + b.WriteString("Go ") + if v := reGoVersion.ReplaceAllString(runtime.Version(), "$1"); v != "" { + b.WriteString(v) + } else { + b.WriteString(runtime.Version()) + } + b.WriteRune(')') + + return b.String() +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/estransport/logger.go b/vendor/github.com/elastic/go-elasticsearch/v8/estransport/logger.go new file mode 100644 index 00000000000..263c80c5a51 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/estransport/logger.go @@ -0,0 +1,412 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package estransport + +import ( + "bufio" + "bytes" + "encoding/json" + "fmt" + "io" + "io/ioutil" + "net/http" + "net/url" + "strconv" + "strings" + "time" +) + +// Logger defines an interface for logging request and response. +// +type Logger interface { + // LogRoundTrip should not modify the request or response, except for consuming and closing the body. + // Implementations have to check for nil values in request and response. + LogRoundTrip(*http.Request, *http.Response, error, time.Time, time.Duration) error + // RequestBodyEnabled makes the client pass a copy of request body to the logger. + RequestBodyEnabled() bool + // ResponseBodyEnabled makes the client pass a copy of response body to the logger. + ResponseBodyEnabled() bool +} + +// TextLogger prints the log message in plain text. +// +type TextLogger struct { + Output io.Writer + EnableRequestBody bool + EnableResponseBody bool +} + +// ColorLogger prints the log message in a terminal-optimized plain text. +// +type ColorLogger struct { + Output io.Writer + EnableRequestBody bool + EnableResponseBody bool +} + +// CurlLogger prints the log message as a runnable curl command. +// +type CurlLogger struct { + Output io.Writer + EnableRequestBody bool + EnableResponseBody bool +} + +// JSONLogger prints the log message as JSON. +// +type JSONLogger struct { + Output io.Writer + EnableRequestBody bool + EnableResponseBody bool +} + +// LogRoundTrip prints the information about request and response. +// +func (l *TextLogger) LogRoundTrip(req *http.Request, res *http.Response, err error, start time.Time, dur time.Duration) error { + fmt.Fprintf(l.Output, "%s %s %s [status:%d request:%s]\n", + start.Format(time.RFC3339), + req.Method, + req.URL.String(), + resStatusCode(res), + dur.Truncate(time.Millisecond), + ) + if l.RequestBodyEnabled() && req != nil && req.Body != nil && req.Body != http.NoBody { + var buf bytes.Buffer + if req.GetBody != nil { + b, _ := req.GetBody() + buf.ReadFrom(b) + } else { + buf.ReadFrom(req.Body) + } + logBodyAsText(l.Output, &buf, ">") + } + if l.ResponseBodyEnabled() && res != nil && res.Body != nil && res.Body != http.NoBody { + defer res.Body.Close() + var buf bytes.Buffer + buf.ReadFrom(res.Body) + logBodyAsText(l.Output, &buf, "<") + } + if err != nil { + fmt.Fprintf(l.Output, "! ERROR: %v\n", err) + } + return nil +} + +// RequestBodyEnabled returns true when the request body should be logged. +func (l *TextLogger) RequestBodyEnabled() bool { return l.EnableRequestBody } + +// ResponseBodyEnabled returns true when the response body should be logged. +func (l *TextLogger) ResponseBodyEnabled() bool { return l.EnableResponseBody } + +// LogRoundTrip prints the information about request and response. +// +func (l *ColorLogger) LogRoundTrip(req *http.Request, res *http.Response, err error, start time.Time, dur time.Duration) error { + query, _ := url.QueryUnescape(req.URL.RawQuery) + if query != "" { + query = "?" + query + } + + var ( + status string + color string + ) + + status = res.Status + switch { + case res.StatusCode > 0 && res.StatusCode < 300: + color = "\x1b[32m" + case res.StatusCode > 299 && res.StatusCode < 500: + color = "\x1b[33m" + case res.StatusCode > 499: + color = "\x1b[31m" + default: + status = "ERROR" + color = "\x1b[31;4m" + } + + fmt.Fprintf(l.Output, "%6s \x1b[1;4m%s://%s%s\x1b[0m%s %s%s\x1b[0m \x1b[2m%s\x1b[0m\n", + req.Method, + req.URL.Scheme, + req.URL.Host, + req.URL.Path, + query, + color, + status, + dur.Truncate(time.Millisecond), + ) + + if l.RequestBodyEnabled() && req != nil && req.Body != nil && req.Body != http.NoBody { + var buf bytes.Buffer + if req.GetBody != nil { + b, _ := req.GetBody() + buf.ReadFrom(b) + } else { + buf.ReadFrom(req.Body) + } + fmt.Fprint(l.Output, "\x1b[2m") + logBodyAsText(l.Output, &buf, " »") + fmt.Fprint(l.Output, "\x1b[0m") + } + + if l.ResponseBodyEnabled() && res != nil && res.Body != nil && res.Body != http.NoBody { + defer res.Body.Close() + var buf bytes.Buffer + buf.ReadFrom(res.Body) + fmt.Fprint(l.Output, "\x1b[2m") + logBodyAsText(l.Output, &buf, " «") + fmt.Fprint(l.Output, "\x1b[0m") + } + + if err != nil { + fmt.Fprintf(l.Output, "\x1b[31;1m» ERROR \x1b[31m%v\x1b[0m\n", err) + } + + if l.RequestBodyEnabled() || l.ResponseBodyEnabled() { + fmt.Fprintf(l.Output, "\x1b[2m%s\x1b[0m\n", strings.Repeat("─", 80)) + } + return nil +} + +// RequestBodyEnabled returns true when the request body should be logged. +func (l *ColorLogger) RequestBodyEnabled() bool { return l.EnableRequestBody } + +// ResponseBodyEnabled returns true when the response body should be logged. +func (l *ColorLogger) ResponseBodyEnabled() bool { return l.EnableResponseBody } + +// LogRoundTrip prints the information about request and response. +// +func (l *CurlLogger) LogRoundTrip(req *http.Request, res *http.Response, err error, start time.Time, dur time.Duration) error { + var b bytes.Buffer + + var query string + qvalues := url.Values{} + for k, v := range req.URL.Query() { + if k == "pretty" { + continue + } + for _, qv := range v { + qvalues.Add(k, qv) + } + } + if len(qvalues) > 0 { + query = qvalues.Encode() + } + + b.WriteString(`curl`) + if req.Method == "HEAD" { + b.WriteString(" --head") + } else { + fmt.Fprintf(&b, " -X %s", req.Method) + } + + if len(req.Header) > 0 { + for k, vv := range req.Header { + if k == "Authorization" || k == "User-Agent" { + continue + } + v := strings.Join(vv, ",") + b.WriteString(fmt.Sprintf(" -H '%s: %s'", k, v)) + } + } + + b.WriteString(" 'http://localhost:9200") + b.WriteString(req.URL.Path) + b.WriteString("?pretty") + if query != "" { + fmt.Fprintf(&b, "&%s", query) + } + b.WriteString("'") + + if req != nil && req.Body != nil && req.Body != http.NoBody { + var buf bytes.Buffer + if req.GetBody != nil { + b, _ := req.GetBody() + buf.ReadFrom(b) + } else { + buf.ReadFrom(req.Body) + } + + b.Grow(buf.Len()) + b.WriteString(" -d \\\n'") + json.Indent(&b, buf.Bytes(), "", " ") + b.WriteString("'") + } + + b.WriteRune('\n') + + var status string + status = res.Status + + fmt.Fprintf(&b, "# => %s [%s] %s\n", start.UTC().Format(time.RFC3339), status, dur.Truncate(time.Millisecond)) + if l.ResponseBodyEnabled() && res != nil && res.Body != nil && res.Body != http.NoBody { + var buf bytes.Buffer + buf.ReadFrom(res.Body) + + b.Grow(buf.Len()) + b.WriteString("# ") + json.Indent(&b, buf.Bytes(), "# ", " ") + } + + b.WriteString("\n") + if l.ResponseBodyEnabled() && res != nil && res.Body != nil && res.Body != http.NoBody { + b.WriteString("\n") + } + + b.WriteTo(l.Output) + + return nil +} + +// RequestBodyEnabled returns true when the request body should be logged. +func (l *CurlLogger) RequestBodyEnabled() bool { return l.EnableRequestBody } + +// ResponseBodyEnabled returns true when the response body should be logged. +func (l *CurlLogger) ResponseBodyEnabled() bool { return l.EnableResponseBody } + +// LogRoundTrip prints the information about request and response. +// +func (l *JSONLogger) LogRoundTrip(req *http.Request, res *http.Response, err error, start time.Time, dur time.Duration) error { + // https://github.com/elastic/ecs/blob/master/schemas/http.yml + // + // TODO(karmi): Research performance optimization of using sync.Pool + + bsize := 200 + var b = bytes.NewBuffer(make([]byte, 0, bsize)) + var v = make([]byte, 0, bsize) + + appendTime := func(t time.Time) { + v = v[:0] + v = t.AppendFormat(v, time.RFC3339) + b.Write(v) + } + + appendQuote := func(s string) { + v = v[:0] + v = strconv.AppendQuote(v, s) + b.Write(v) + } + + appendInt := func(i int64) { + v = v[:0] + v = strconv.AppendInt(v, i, 10) + b.Write(v) + } + + port := req.URL.Port() + + b.WriteRune('{') + // -- Timestamp + b.WriteString(`"@timestamp":"`) + appendTime(start.UTC()) + b.WriteRune('"') + // -- Event + b.WriteString(`,"event":{`) + b.WriteString(`"duration":`) + appendInt(dur.Nanoseconds()) + b.WriteRune('}') + // -- URL + b.WriteString(`,"url":{`) + b.WriteString(`"scheme":`) + appendQuote(req.URL.Scheme) + b.WriteString(`,"domain":`) + appendQuote(req.URL.Hostname()) + if port != "" { + b.WriteString(`,"port":`) + b.WriteString(port) + } + b.WriteString(`,"path":`) + appendQuote(req.URL.Path) + b.WriteString(`,"query":`) + appendQuote(req.URL.RawQuery) + b.WriteRune('}') // Close "url" + // -- HTTP + b.WriteString(`,"http":`) + // ---- Request + b.WriteString(`{"request":{`) + b.WriteString(`"method":`) + appendQuote(req.Method) + if l.RequestBodyEnabled() && req != nil && req.Body != nil && req.Body != http.NoBody { + var buf bytes.Buffer + if req.GetBody != nil { + b, _ := req.GetBody() + buf.ReadFrom(b) + } else { + buf.ReadFrom(req.Body) + } + + b.Grow(buf.Len() + 8) + b.WriteString(`,"body":`) + appendQuote(buf.String()) + } + b.WriteRune('}') // Close "http.request" + // ---- Response + b.WriteString(`,"response":{`) + b.WriteString(`"status_code":`) + appendInt(int64(resStatusCode(res))) + if l.ResponseBodyEnabled() && res != nil && res.Body != nil && res.Body != http.NoBody { + defer res.Body.Close() + var buf bytes.Buffer + buf.ReadFrom(res.Body) + + b.Grow(buf.Len() + 8) + b.WriteString(`,"body":`) + appendQuote(buf.String()) + } + b.WriteRune('}') // Close "http.response" + b.WriteRune('}') // Close "http" + // -- Error + if err != nil { + b.WriteString(`,"error":{"message":`) + appendQuote(err.Error()) + b.WriteRune('}') // Close "error" + } + b.WriteRune('}') + b.WriteRune('\n') + b.WriteTo(l.Output) + + return nil +} + +// RequestBodyEnabled returns true when the request body should be logged. +func (l *JSONLogger) RequestBodyEnabled() bool { return l.EnableRequestBody } + +// ResponseBodyEnabled returns true when the response body should be logged. +func (l *JSONLogger) ResponseBodyEnabled() bool { return l.EnableResponseBody } + +func logBodyAsText(dst io.Writer, body io.Reader, prefix string) { + scanner := bufio.NewScanner(body) + for scanner.Scan() { + s := scanner.Text() + if s != "" { + fmt.Fprintf(dst, "%s %s\n", prefix, s) + } + } +} + +func duplicateBody(body io.ReadCloser) (io.ReadCloser, io.ReadCloser, error) { + var ( + b1 bytes.Buffer + b2 bytes.Buffer + tr = io.TeeReader(body, &b2) + ) + _, err := b1.ReadFrom(tr) + if err != nil { + return ioutil.NopCloser(io.MultiReader(&b1, errorReader{err: err})), ioutil.NopCloser(io.MultiReader(&b2, errorReader{err: err})), err + } + defer func() { body.Close() }() + + return ioutil.NopCloser(&b1), ioutil.NopCloser(&b2), nil +} + +func resStatusCode(res *http.Response) int { + if res == nil { + return -1 + } + return res.StatusCode +} + +type errorReader struct{ err error } + +func (r errorReader) Read(p []byte) (int, error) { return 0, r.err } diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/estransport/selector.go b/vendor/github.com/elastic/go-elasticsearch/v8/estransport/selector.go new file mode 100644 index 00000000000..f4a8d3d530f --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/estransport/selector.go @@ -0,0 +1,58 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package estransport + +import ( + "container/ring" + "errors" + "net/url" + "sync" +) + +// Selector defines the interface for selecting URLs for performing request. +// +type Selector interface { + Select() (*url.URL, error) +} + +// RoundRobinSelector implements a round-robin selection strategy. +// +type RoundRobinSelector struct { + sync.Mutex + ring *ring.Ring +} + +// Select returns a URL or error from the list of URLs in a round-robin fashion. +// +func (r *RoundRobinSelector) Select() (*url.URL, error) { + r.Lock() + defer r.Unlock() + + if r.ring.Len() < 1 { + return nil, errors.New("No URL available") + } + + v := r.ring.Value + if ov, ok := v.(*url.URL); !ok || ov == nil { + return nil, errors.New("No URL available") + } + + r.ring = r.ring.Next() + return v.(*url.URL), nil +} + +// NewRoundRobinSelector creates a new RoundRobinSelector. +// +func NewRoundRobinSelector(urls ...*url.URL) *RoundRobinSelector { + r := RoundRobinSelector{} + + r.ring = ring.New(len(urls)) + for _, u := range urls { + r.ring.Value = u + r.ring = r.ring.Next() + } + + return &r +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esutil/doc.go b/vendor/github.com/elastic/go-elasticsearch/v8/esutil/doc.go new file mode 100644 index 00000000000..b37e7ffcea6 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esutil/doc.go @@ -0,0 +1,5 @@ +/* +Package esutil provides helper utilities to the Go client for Elasticsearch. + +*/ +package esutil diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esutil/json_reader.go b/vendor/github.com/elastic/go-elasticsearch/v8/esutil/json_reader.go new file mode 100644 index 00000000000..5d5495aca21 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esutil/json_reader.go @@ -0,0 +1,82 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package esutil + +import ( + "bytes" + "encoding/json" + "io" +) + +// NewJSONReader encodes v into JSON and returns it as an io.Reader. +// +func NewJSONReader(v interface{}) io.Reader { + return &JSONReader{val: v, buf: nil} +} + +// JSONEncoder defines the interface for custom JSON encoders. +// +type JSONEncoder interface { + EncodeJSON(io.Writer) error +} + +// JSONReader represents a reader which takes an interface value, +// encodes it into JSON, and wraps it in an io.Reader. +// +type JSONReader struct { + val interface{} + buf interface { + io.ReadWriter + io.WriterTo + } +} + +// Read implements the io.Reader interface. +// +func (r *JSONReader) Read(p []byte) (int, error) { + if r.buf == nil { + r.buf = new(bytes.Buffer) + if err := r.encode(r.buf); err != nil { + return 0, err + } + } + + return r.buf.Read(p) +} + +// WriteTo implements the io.WriterTo interface. +// +func (r *JSONReader) WriteTo(w io.Writer) (int64, error) { + cw := countingWriter{Writer: w} + err := r.encode(&cw) + return int64(cw.n), err +} + +func (r *JSONReader) encode(w io.Writer) error { + var err error + + if e, ok := r.val.(JSONEncoder); ok { + err = e.EncodeJSON(w) + if err != nil { + return err + } + return nil + } + + return json.NewEncoder(w).Encode(r.val) +} + +type countingWriter struct { + io.Writer + n int +} + +func (cw *countingWriter) Write(p []byte) (int, error) { + n, err := cw.Writer.Write(p) + if n > 0 { + cw.n += n + } + return n, err +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/go.mod b/vendor/github.com/elastic/go-elasticsearch/v8/go.mod new file mode 100644 index 00000000000..6527669f168 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/go.mod @@ -0,0 +1,3 @@ +module github.com/elastic/go-elasticsearch/v8 + +go 1.11 diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/go.sum b/vendor/github.com/elastic/go-elasticsearch/v8/go.sum new file mode 100644 index 00000000000..e69de29bb2d diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/commands.go b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/commands.go new file mode 100644 index 00000000000..27195f739d6 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/commands.go @@ -0,0 +1,34 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package commands + +import ( + "os" + + "github.com/spf13/cobra" + + "github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils" +) + +var rootCmd = &cobra.Command{ + Use: "generate", + Short: "generate allows you to generate APIs and tests", + // Long: "TODO", +} + +// Execute launches the CLI application. +// +func Execute() { + if err := rootCmd.Execute(); err != nil { + utils.PrintErr(err) + os.Exit(1) + } +} + +// RegisterCmd adds a command to rootCmd. +// +func RegisterCmd(cmd *cobra.Command) { + rootCmd.AddCommand(cmd) +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource/command.go b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource/command.go new file mode 100644 index 00000000000..441c0c19c2f --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource/command.go @@ -0,0 +1,280 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package gensource + +import ( + "bytes" + "fmt" + "io" + "os" + "path/filepath" + "strings" + "time" + + "github.com/spf13/cobra" + + "github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands" + "github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils" +) + +var ( + input *string + output *string + gofmt *bool + color *bool + debug *bool + info *bool +) + +var ( + GitCommit string + GitTag string + EsVersion string +) + +func init() { + input = gensourceCmd.Flags().StringP("input", "i", "", "Path to a folder or files with Elasticsearch REST API specification") + output = gensourceCmd.Flags().StringP("output", "o", "", "Path to a folder for generated output") + gofmt = gensourceCmd.Flags().BoolP("gofmt", "f", true, "Format generated output with 'gofmt'") + color = gensourceCmd.Flags().BoolP("color", "c", true, "Syntax highlight the debug output") + debug = gensourceCmd.Flags().BoolP("debug", "d", false, "Print the generated source to terminal") + info = gensourceCmd.Flags().Bool("info", false, "Print the API details to terminal") + + gensourceCmd.MarkFlagRequired("input") + gensourceCmd.MarkFlagRequired("output") + gensourceCmd.Flags().SortFlags = false + + commands.RegisterCmd(gensourceCmd) +} + +var gensourceCmd = &cobra.Command{ + Use: "apisource", + Short: "Generate the Go APIs from the Elasticsearch REST API specification", + Run: func(cmd *cobra.Command, args []string) { + command := &Command{ + Input: *input, + Output: *output, + Gofmt: *gofmt, + DebugInfo: *info, + DebugSource: *debug, + ColorizeSource: *color, + } + err := command.Execute() + if err != nil { + utils.PrintErr(err) + os.Exit(1) + } + }, +} + +// Command represents the "gensource" command. +// +type Command struct { + Input string + Output string + Gofmt bool + DebugInfo bool + DebugSource bool + ColorizeSource bool +} + +// Execute runs the command. +// +func (cmd *Command) Execute() (err error) { + var inputFiles []string + + if strings.Contains(cmd.Input, ",") { + inputFiles = strings.Split(cmd.Input, ",") + } else { + inputFiles, err = filepath.Glob(cmd.Input) + if err != nil { + return fmt.Errorf("Failed to glob input %q: %s", cmd.Input, err) + } + } + + if len(inputFiles) < 1 { + return fmt.Errorf("No files matching input %q", cmd.Input) + } + + EsVersion, err = utils.EsVersion(filepath.Dir(inputFiles[0])) + if err != nil { + return err + } + GitCommit, err = utils.GitCommit(filepath.Dir(inputFiles[0])) + if err != nil { + return err + } + GitTag, err = utils.GitTag(filepath.Dir(inputFiles[0])) + if err != nil { + return err + } + + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[2m") + } + fmt.Fprintln(os.Stderr, strings.Repeat("━", utils.TerminalWidth())) + fmt.Fprintf(os.Stderr, "Specification: %s", EsVersion) + fmt.Fprintf(os.Stderr, " (%s", GitCommit) + if GitTag != "" { + fmt.Fprintf(os.Stderr, ", %s", GitTag) + } + fmt.Fprintf(os.Stderr, ")\n") + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[0m") + } + + var endpoints []*Endpoint + + stats := struct { + n int + start time.Time + }{start: time.Now()} + + for _, fpath := range inputFiles { + fname := filepath.Base(fpath) + if fname == "_common.json" { + continue + } + + f, err := os.Open(fpath) + if err != nil { + return err + } + defer f.Close() + + if err := cmd.processFile(f); err != nil { + return fmt.Errorf("Processing file %q: %s", fname, err) + } + + f.Seek(0, 0) + e, err := NewEndpoint(f) + if err != nil { + return fmt.Errorf("error creating endpoint for %q: %s", fname, err) + } + endpoints = append(endpoints, e) + stats.n++ + } + + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[2m") + } + fmt.Fprintln(os.Stderr, strings.Repeat("━", utils.TerminalWidth())) + fmt.Fprintf(os.Stderr, "Processed %d files in %s\n", stats.n, time.Since(stats.start).Truncate(time.Millisecond)) + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[0m") + } + + return nil +} + +func (cmd *Command) processFile(f *os.File) (err error) { + var out io.Reader + + fname := filepath.Base(f.Name()) + + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[2m") + } + fmt.Fprintln(os.Stderr, strings.Repeat("━", utils.TerminalWidth())) + fmt.Fprintf(os.Stderr, "Processing file %q\n", fname) + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[0m") + } + + endpoint, err := NewEndpoint(f) + if err != nil { + return fmt.Errorf("error creating endpoint for %q: %s", fname, err) + } + + gen := Generator{Endpoint: endpoint} + + if cmd.Gofmt { + out, err = gen.OutputFormatted() + } else { + out, err = gen.Output() + } + if err != nil { + if cmd.DebugSource { + utils.PrintSourceWithErr(out, err) + } + return fmt.Errorf("error generating output for %q: %s", fname, err) + } + + if cmd.DebugInfo { + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[2m") + } + fmt.Fprintf(os.Stderr, gen.Endpoint.DebugInfo()) + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[0m") + } + } + + if cmd.DebugSource { + var src io.Reader + var buf bytes.Buffer + tee := io.TeeReader(out, &buf) + + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[2m") + } + fmt.Fprintln(os.Stderr, strings.Repeat("━", utils.TerminalWidth())) + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[0m") + } + if cmd.ColorizeSource { + src, err = utils.Chromatize(tee) + if err != nil { + return fmt.Errorf("error syntax highligting the output: %s", err) + } + + _, err = io.Copy(os.Stderr, src) + if err != nil { + return fmt.Errorf("error copying output: %s", err) + } + } + + _, err = io.Copy(os.Stderr, out) + if err != nil { + return fmt.Errorf("error copying output: %s", err) + } + + fmt.Fprintf(os.Stderr, "\n\n") + + out = &buf + } + + if cmd.Output == "-" { + _, err = io.Copy(os.Stdout, out) + if err != nil { + return fmt.Errorf("error copying output: %s", err) + } + } else { + if err := os.MkdirAll(cmd.Output, 0775); err != nil { + return fmt.Errorf("error creating directory: %s", err) + } + + var fName string + if gen.Endpoint.Type == "core" { + fName = filepath.Join(cmd.Output, "api."+gen.Endpoint.Name+".go") + } else { + fName = filepath.Join(cmd.Output, "api."+gen.Endpoint.Type+"."+gen.Endpoint.Name+".go") + } + + f, err := os.OpenFile(fName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) + if err != nil { + return fmt.Errorf("error creating file: %s", err) + } + _, err = io.Copy(f, out) + if err != nil { + return fmt.Errorf("error copying output: %s", err) + } + if err := f.Close(); err != nil { + return fmt.Errorf("error closing file: %s", err) + } + } + + return nil +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource/debug.go b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource/debug.go new file mode 100644 index 00000000000..4741212d27e --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource/debug.go @@ -0,0 +1,95 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package gensource + +import ( + "fmt" + "math" + "strings" + "text/tabwriter" + + "github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils" +) + +// DebugInfo returns information about the endpoint as a string. +// +func (e *Endpoint) DebugInfo() string { + var out strings.Builder + w := tabwriter.NewWriter(&out, 0, 0, 1, ' ', 0) + + fmt.Fprintln(&out, strings.Repeat("─", utils.TerminalWidth())) + fmt.Fprintf(&out, "API: %s (%s:%s)\n", e.MethodWithNamespace(), e.Type, e.Name) + fmt.Fprintf(&out, "%s\n", e.Documentation.Description[0:int(math.Min(float64(80), float64(len(e.Documentation.Description))))]) + fmt.Fprintln(&out, strings.Repeat("─", utils.TerminalWidth())) + + fmt.Fprintln(&out, "Paths:") + for _, path := range e.URL.Paths { + fmt.Fprintf(w, "%6s\t%s", path.Methods[0], path.Path) + if path.Deprecated.Version != "" { + fmt.Fprintf(w, "\t*deprecated*") + } + fmt.Fprintf(w, "\n") + } + w.Flush() + + longestPath := e.URL.Paths[0] + for _, v := range e.URL.Paths { + if len(v.Path) > len(longestPath.Path) { + longestPath = v + } + } + + if len(longestPath.Parts) > 0 { + fmt.Fprintln(&out, "Parts:") + for _, part := range longestPath.Parts { + fmt.Fprintf(w, " • %s\t", part.Name) + fmt.Fprintf(w, " %s", part.Type) + if part.Required { + fmt.Fprint(w, ", required") + } + if part.Default != nil { + fmt.Fprintf(w, ", default: %s", part.Default) + } + fmt.Fprint(w, "\n") + } + w.Flush() + } + + if len(e.URL.Params) > 0 { + fmt.Fprintln(&out, "Params:") + for _, param := range e.URL.Params { + fmt.Fprintf(w, " • %s\t %s", param.Name, param.Type) + if param.Required { + fmt.Fprint(w, ", required") + } + if param.Type == "enum" { + fmt.Fprintf(w, ": %s", strings.Join(param.Options, ", ")) + } + if param.Default != nil { + fmt.Fprintf(w, ", default: %s", param.Default) + } + fmt.Fprint(w, "\n") + } + w.Flush() + } + + if e.Body != nil { + fmt.Fprintln(&out, "Body:") + if e.Body.Description != "" { + fmt.Fprintf(&out, " %s.", e.Body.Description) + } + if e.Body.Required { + fmt.Fprintf(&out, " *Required*") + } else { + fmt.Fprintf(&out, " Optional") + } + if e.Body.ContentType != "" { + fmt.Fprintf(&out, ", format: %s", e.Body.ContentType) + } + fmt.Fprintf(&out, "\n") + } + + return out.String() +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource/descriptions.go b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource/descriptions.go new file mode 100644 index 00000000000..e24b1fc8c9e --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource/descriptions.go @@ -0,0 +1,646 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package gensource + +var apiDescriptionsYAML = ` +--- +bulk: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html + description: |- + Allows to perform multiple index/update/delete operations in a single request. + +cat.aliases: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-alias.html + description: |- + Shows information about currently configured aliases to indices including filter and routing infos. + +cat.allocation: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-allocation.html + description: |- + Provides a snapshot of how many shards are allocated to each data node and how much disk space they are using. + +cat.count: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-count.html + description: |- + Provides quick access to the document count of the entire cluster, or individual indices. + +cat.fielddata: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-fielddata.html + description: |- + Shows how much heap memory is currently being used by fielddata on every data node in the cluster. + +cat.health: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-health.html + description: |- + Returns a concise representation of the cluster health. + +cat.help: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cat.html + description: + Returns help for the Cat APIs. + +cat.indices: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-indices.html + description: |- + Returns information about indices: number of primaries and replicas, document counts, disk size, ... + +cat.master: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-master.html + description: |- + Returns information about the master node. + +cat.nodeattrs: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-nodeattrs.html + description: |- + Returns information about custom node attributes. + +cat.nodes: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-nodes.html + description: |- + Returns basic statistics about performance of cluster nodes. + +cat.pending_tasks: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-pending-tasks.html + description: |- + Returns a concise representation of the cluster pending tasks. + +cat.plugins: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-plugins.html + description: |- + Returns information about installed plugins across nodes node. + +cat.recovery: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-recovery.html + description: |- + Returns information about index shard recoveries, both on-going completed. + +cat.repositories: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-repositories.html + description: |- + Returns information about snapshot repositories registered in the cluster. + +cat.segments: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-segments.html + description: |- + Provides low-level information about the segments in the shards of an index. + +cat.shards: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-shards.html + description: |- + Provides a detailed view of shard allocation on nodes. + +cat.snapshots: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-snapshots.html + description: |- + Returns all snapshots in a specific repository. + +cat.tasks: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html + description: |- + Returns information about the tasks currently executing on one or more nodes in the cluster. + +cat.templates: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-templates.html + description: |- + Returns information about existing templates. + +cat.thread_pool: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-thread-pool.html + description: |- + Returns cluster-wide thread pool statistics per node. + By default the active, queue and rejected statistics are returned for all thread pools. + +clear_scroll: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html + description: |- + Explicitly clears the search context for a scroll. + +cluster.allocation_explain: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-allocation-explain.html + description: |- + Provides explanations for shard allocations in the cluster. + +cluster.get_settings: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-update-settings.html + description: |- + Returns cluster settings. + +cluster.health: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-health.html + description: |- + Returns basic information about the health of the cluster. + +cluster.pending_tasks: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-pending.html + description: |- + Returns a list of any cluster-level changes (e.g. create index, update mapping, + allocate or fail shard) which have not yet been executed. + +cluster.put_settings: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-update-settings.html + description: |- + Updates the cluster settings. + +cluster.remote_info: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-remote-info.html + description: |- + Returns the information about configured remote clusters. + +cluster.reroute: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-reroute.html + description: |- + Allows to manually change the allocation of individual shards in the cluster. + +cluster.state: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-state.html + description: |- + Returns a comprehensive information about the state of the cluster. + +cluster.stats: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-stats.html + description: |- + Returns high-level overview of cluster statistics. + +count: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/search-count.html + description: |- + Returns number of documents matching a query. + +create: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html + description: |- + Creates a new document in the index. + + Returns a 409 response when a document with a same ID already exists in the index. + +delete: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete.html + description: |- + Removes a document from the index. + +delete_by_query: + # https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete-by-query.html + description: |- + Deletes documents matching the provided query. + +delete_by_query_rethrottle: + # https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html + description: |- + Changes the number of requests per second for a particular Delete By Query operation. + +delete_script: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html + description: |- + Deletes a script. + +exists: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html + description: |- + Returns information about whether a document exists in an index. + +exists_source: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html + description: |- + Returns information about whether a document source exists in an index. + +explain: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/search-explain.html + description: |- + Returns information about why a specific matches (or doesn't match) a query. + +field_caps: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/search-field-caps.html + description: |- + Returns the information about the capabilities of fields among multiple indices. + +get: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html + description: |- + Returns a document. + +get_script: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html + description: |- + Returns a script. + +get_source: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html + description: |- + Returns the source of a document. + +index: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html + description: |- + Creates or updates a document in an index. + +indices.analyze: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-analyze.html + description: |- + Performs the analysis process on a text and return the tokens breakdown of the text. + +indices.clear_cache: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clearcache.html + description: |- + Clears all or specific caches for one or more indices. + +indices.clone: + # https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clone-index.html + description: |- + Clones an existing index into a new index. + +indices.close: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html + description: |- + Closes an index. + +indices.create: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-create-index.html + description: |- + Creates an index with optional settings and mappings. + +indices.delete: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-delete-index.html + description: |- + Deletes an index. + +indices.delete_alias: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html + description: |- + Deletes an alias. + +indices.delete_template: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html + description: |- + Deletes an index template. + +indices.exists: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-exists.html + description: |- + Returns information about whether a particular index exists. + +indices.exists_alias: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html + description: |- + Returns information about whether a particular alias exists. + +indices.exists_template: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html + description: |- + Returns information about whether a particular index template exists. + +indices.exists_type: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-types-exists.html + description: |- + Returns information about whether a particular document type exists. (DEPRECATED) + +indices.flush: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-flush.html + description: |- + Performs the flush operation on one or more indices. + +indices.flush_synced: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-synced-flush.html + description: |- + Performs a synced flush operation on one or more indices. + +indices.forcemerge: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-forcemerge.html + description: |- + Performs the force merge operation on one or more indices. + +indices.get: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-index.html + description: |- + Returns information about one or more indices. + +indices.get_alias: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html + description: |- + Returns an alias. + +indices.get_field_mapping: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-field-mapping.html + description: |- + Returns mapping for one or more fields. + +indices.get_mapping: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-mapping.html + description: |- + Returns mappings for one or more indices. + +indices.get_settings: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-settings.html + description: |- + Returns settings for one or more indices. + +indices.get_template: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html + description: |- + Returns an index template. + +indices.get_upgrade: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-upgrade.html + description: |- + The _upgrade API is no longer useful and will be removed. + +indices.open: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html + description: |- + Opens an index. + +indices.put_alias: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html + description: |- + Creates or updates an alias. + +indices.put_mapping: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-put-mapping.html + description: |- + Updates the index mappings. + +indices.put_settings: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-update-settings.html + description: |- + Updates the index settings. + +indices.put_template: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html + description: |- + Creates or updates an index template. + +indices.recovery: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-recovery.html + description: |- + Returns information about ongoing index shard recoveries. + +indices.refresh: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-refresh.html + description: |- + Performs the refresh operation in one or more indices. + +indices.rollover: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-rollover-index.html + description: |- + Updates an alias to point to a new index when the existing index + is considered to be too large or too old. + +indices.segments: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-segments.html + description: |- + Provides low-level information about segments in a Lucene index. + +indices.shard_stores: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-shards-stores.html + description: |- + Provides store information for shard copies of indices. + +indices.shrink: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-shrink-index.html + description: |- + Allow to shrink an existing index into a new index with fewer primary shards. + +indices.split: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-split-index.html + description: |- + Allows you to split an existing index into a new index with more primary shards. + +indices.stats: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-stats.html + description: |- + Provides statistics on operations happening in an index. + +indices.update_aliases: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html + description: |- + Updates index aliases. + +indices.upgrade: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-upgrade.html + description: |- + The _upgrade API is no longer useful and will be removed. + +indices.validate_query: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/search-validate.html + description: |- + Allows a user to validate a potentially expensive query without executing it. + +info: + # http://www.elastic.co/guide/ + description: |- + Returns basic information about the cluster. + +ingest.delete_pipeline: + url: https://www.elastic.co/guide/en/elasticsearch/reference/master/delete-pipeline-api.html + description: |- + Deletes a pipeline. + +ingest.get_pipeline: + url: https://www.elastic.co/guide/en/elasticsearch/reference/master/get-pipeline-api.html + description: |- + Returns a pipeline. + +ingest.processor_grok: + # https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html + description: |- + Returns a list of the built-in patterns. + +ingest.put_pipeline: + url: https://www.elastic.co/guide/en/elasticsearch/reference/master/put-pipeline-api.html + description: |- + Creates or updates a pipeline. + +ingest.simulate: + url: https://www.elastic.co/guide/en/elasticsearch/reference/master/simulate-pipeline-api.html + description: |- + Allows to simulate a pipeline with example documents. + +mget: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-get.html + description: |- + Allows to get multiple documents in one request. + +msearch: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/search-multi-search.html + description: |- + Allows to execute several search operations in one request. + +msearch_template: + # http://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html + description: |- + Allows to execute several search template operations in one request. + +mtermvectors: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-termvectors.html + description: |- + Returns multiple termvectors in one request. + +nodes.hot_threads: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-hot-threads.html + description: |- + Returns information about hot threads on each node in the cluster. + +nodes.info: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-info.html + description: |- + Returns information about nodes in the cluster. + +nodes.reload_secure_settings: + # https://www.elastic.co/guide/en/elasticsearch/reference/master/secure-settings.html#reloadable-secure-settings + description: |- + Reloads secure settings. + +nodes.stats: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-stats.html + description: |- + Returns statistical information about nodes in the cluster. + +nodes.usage: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-usage.html + description: |- + Returns low-level information about REST actions usage on nodes. + +ping: + # http://www.elastic.co/guide/ + description: + Returns whether the cluster is running. + +put_script: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html + description: |- + Creates or updates a script. + +rank_eval: + # https://www.elastic.co/guide/en/elasticsearch/reference/master/search-rank-eval.html + description: |- + Allows to evaluate the quality of ranked search results over a set of typical search queries + +reindex: + # https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-reindex.html + description: |- + Allows to copy documents from one index to another, optionally filtering the source + documents by a query, changing the destination index settings, or fetching the + documents from a remote cluster. + +reindex_rethrottle: + # https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-reindex.html + description: |- + Changes the number of requests per second for a particular Reindex operation. + +render_search_template: + # http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-template.html + description: |- + Allows to use the Mustache language to pre-render a search definition. + +scripts_painless_execute: + # https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-execute-api.html + description: |- + Allows an arbitrary script to be executed and a result to be returned + +scripts_painless_context: + # https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-execute-api.html + description: |- + Allows to query context information. + +scroll: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html + description: |- + Allows to retrieve a large numbers of results from a single search request. + +search: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/search-search.html + description: |- + Returns results matching a query. + +search_shards: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/search-shards.html + description: |- + Returns information about the indices and shards that a search request would be executed against. + +search_template: + # http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html + description: |- + Allows to use the Mustache language to pre-render a search definition. + +snapshot.create: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + description: |- + Creates a snapshot in a repository. + +snapshot.create_repository: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + description: |- + Creates a repository. + +snapshot.delete: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + description: |- + Deletes a snapshot. + +snapshot.delete_repository: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + description: |- + Deletes a repository. + +snapshot.get: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + description: |- + Returns information about a snapshot. + +snapshot.get_repository: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + description: |- + Returns information about a repository. + +snapshot.restore: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + description: |- + Restores a snapshot. + +snapshot.status: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + description: |- + Returns information about the status of a snapshot. + +snapshot.verify_repository: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html + description: |- + Verifies a repository. + +tasks.cancel: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html + description: |- + Cancels a task, if it can be cancelled through an API. + +tasks.get: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html + description: |- + Returns information about a task. + +tasks.list: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html + description: |- + Returns a list of tasks. + +termvectors: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-termvectors.html + description: |- + Returns information and statistics about terms in the fields of a particular document. + +update: + # http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-update.html + description: |- + Updates a document with a script or partial document. + +update_by_query: + # https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-update-by-query.html + description: |- + Performs an update on every document in the index without changing the source, + for example to pick up a mapping change. + +update_by_query_rethrottle: + # https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html + description: |- + Changes the number of requests per second for a particular Update By Query operation. +` diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource/generator.go b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource/generator.go new file mode 100644 index 00000000000..bbd24055178 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource/generator.go @@ -0,0 +1,786 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package gensource + +import ( + "bytes" + "fmt" + "io" + "reflect" + "strings" + + "golang.org/x/tools/imports" + + "github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils" +) + +// Generator represents the "gensource" generator. +// +type Generator struct { + b bytes.Buffer + + Endpoint *Endpoint +} + +// Output returns the generator output. +// +func (g *Generator) Output() (io.Reader, error) { + g.genHeader() + g.genConstructor() + g.genMethodDefinition() + g.genRequestStruct() + g.w("\n") + g.genDoMethod() + g.genWithOptions() + + return bytes.NewReader(g.b.Bytes()), nil +} + +// OutputFormatted returns a formatted generator output. +// +func (g *Generator) OutputFormatted() (io.Reader, error) { + out, err := g.Output() + if err != nil { + return bytes.NewReader(g.b.Bytes()), err + } + + var b bytes.Buffer + if _, err := io.Copy(&b, out); err != nil { + return bytes.NewReader(g.b.Bytes()), err + } + + fout, err := imports.Process( + "esapi/api."+g.Endpoint.Name+".go", + g.b.Bytes(), + &imports.Options{ + AllErrors: true, + Comments: true, + FormatOnly: false, + TabIndent: true, + TabWidth: 1, + }) + if err != nil { + return bytes.NewReader(b.Bytes()), err + } + + g.b.Reset() + g.b.Write(fout) + + return bytes.NewReader(fout), nil +} + +func (g *Generator) w(s string) { + g.b.WriteString(s) +} + +func (g *Generator) genHeader() { + g.w(`// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information.` + "\n") + g.w("//\n// Code generated") + if EsVersion != "" { + g.w(fmt.Sprintf(" from specification version %s", EsVersion)) + } + g.w(": DO NOT EDIT\n") + g.w("\n") + g.w("package esapi\n") +} + +func (g *Generator) genConstructor() { + g.w(` +func new` + g.Endpoint.MethodWithNamespace() + `Func(t Transport) ` + g.Endpoint.MethodWithNamespace() + ` { + return func(`) + g.genMethodArguments() + g.w(`o ...func(*` + g.Endpoint.MethodWithNamespace() + `Request)) (*Response, error) {`) + if len(g.Endpoint.RequiredArguments()) > 0 { + g.w("\n\t\t" + `var r = ` + g.Endpoint.MethodWithNamespace() + `Request{`) + for i, arg := range g.Endpoint.RequiredArguments() { + if arg.Name == "type" { + continue // Skip the type parameter, "_doc" is used by default + } + g.w(arg.GoName() + ": " + arg.Name) + if i != len(g.Endpoint.RequiredArguments())-1 { + g.w(", ") + } + } + g.w("}\n") + } else { + g.w("\n\t\t" + `var r = ` + g.Endpoint.MethodWithNamespace() + `Request{}` + "\n") + } + g.w(` for _, f := range o { + f(&r) + } + return r.Do(r.ctx, t) + } +} +`) +} + +func (g *Generator) genMethodDefinition() { + g.w("\n// ----- API Definition -------------------------------------------------------\n\n") + + if g.Endpoint.Type == "xpack" { + g.w(`// ` + g.Endpoint.MethodWithNamespace() + " - " + g.Endpoint.Documentation.Description) + } else { + if g.Endpoint.Documentation.Description != "" { + words := strings.Split(g.Endpoint.Documentation.Description, " ") + initial := strings.ToLower(words[0:1][0]) + description := initial + " " + strings.Join(words[1:], " ") + lines := strings.Split(description, "\n") + + g.w(`// ` + g.Endpoint.MethodWithNamespace() + " " + lines[0:1][0]) + for _, line := range lines[1:] { + g.w("\n// " + line) + } + } + } + + if g.Endpoint.Documentation.URL != "" { + g.w("\n//\n" + `// See full documentation at ` + g.Endpoint.Documentation.URL + ".") + } + + g.w(` +// +type ` + g.Endpoint.MethodWithNamespace() + ` func(`) + g.genMethodArguments() + g.w(`o ...func(*` + g.Endpoint.MethodWithNamespace() + `Request)) (*Response, error) +`) +} + +func (g *Generator) genMethodArguments() { + if len(g.Endpoint.RequiredArguments()) > 0 { + for _, arg := range g.Endpoint.RequiredArguments() { + if arg.Name == "type" { + continue // Skip the type parameter, "_doc" is used by default + } + var argType string + if arg.Name == "body" { + argType = "io.Reader" + } else { + argType = arg.GoType() + } + var argName string + if arg.Name == "type" { + argName = "typ" + } else { + argName = arg.Name + } + g.w(argName + " " + argType) + g.w(", ") + } + } +} + +func (g *Generator) genRequestStruct() { + g.w(` +// ` + g.Endpoint.MethodWithNamespace() + `Request configures the ` + g.Endpoint.HumanMethodWithNamespace() + ` API request. +// +type ` + g.Endpoint.MethodWithNamespace() + `Request struct {`) + specialFields := []string{"index", "type", "id"} + for _, n := range specialFields { + if param, ok := g.Endpoint.URL.AllParts[n]; ok { + g.w("\n\t" + param.GoName()) + g.w("\t" + param.GoType(true)) + } + } + + if len(g.Endpoint.URL.AllParts) > 0 { + g.w("\n") + } + + if g.Endpoint.Body != nil { + g.w("\n\tBody io.Reader") + } + + if len(g.Endpoint.URL.AllParts) > 0 || g.Endpoint.Body != nil { + g.w("\n") + } + + for _, name := range g.Endpoint.URL.PartNamesSorted { + p, ok := g.Endpoint.URL.AllParts[name] + if !ok { + panic(fmt.Sprintf("Part %q not found", name)) + } + + skip := false + for _, v := range specialFields { + if p.Name == v { + skip = true + } + } + if skip { + continue + } + g.w("\n\t" + p.GoName()) + g.w("\t" + p.GoType(true)) + + } + + if len(g.Endpoint.URL.AllParts) > 0 { + g.w("\n") + } + + for _, name := range g.Endpoint.URL.ParamNamesSorted { + p, ok := g.Endpoint.URL.Params[name] + if !ok { + panic(fmt.Sprintf("Parameter %q not found", name)) + } + + if _, ok := g.Endpoint.URL.AllParts[name]; ok { + continue // skip params which are also parts + } + + g.w("\n\t" + p.GoName()) + g.w("\t" + p.GoType(true)) + } + + g.w("\n\n\tPretty\tbool") + g.w("\n\tHuman\tbool") + g.w("\n\tErrorTrace\tbool") + g.w("\n\tFilterPath\t[]string\n") + + g.w("\n\n\tHeader\thttp.Header\n") + + g.w("\n\tctx context.Context\n}\n") +} + +func (g *Generator) genWithOptions() { + // Generate WithContext first + g.w(` +// WithContext sets the request context. +// +func (f ` + g.Endpoint.MethodWithNamespace() + `) WithContext(v context.Context) func(*` + g.Endpoint.MethodWithNamespace() + `Request) { + return func(r *` + g.Endpoint.MethodWithNamespace() + `Request) { + r.ctx = v + } +} +`) + + // Skip adding With... options for arguments which are part of the method signature + skipRequiredArgs := make(map[string]bool) + for _, p := range g.Endpoint.RequiredArguments() { + skipRequiredArgs[p.Name] = true + } + + var methodBody = func(e *Endpoint, a interface{}) string { + var b strings.Builder + + switch a.(type) { + case *Part, *Param: // pass + default: + panic(fmt.Sprintf("FAIL: %q: Unexpected type [%[1]T] for argument: %#[1]v", g.Endpoint.Name, a)) + } + + var ( + methodWithNamespace = e.MethodWithNamespace() + + typ = reflect.TypeOf(a).String() + pFieldName = reflect.ValueOf(a).MethodByName("GoName").Call([]reflect.Value{})[0].String() + pGoType = reflect.ValueOf(a).MethodByName("GoType").Call([]reflect.Value{reflect.ValueOf(false)})[0].String() + // pType = reflect.Indirect(reflect.ValueOf(a)).FieldByName("Type").String() + // pName = reflect.Indirect(reflect.ValueOf(a)).FieldByName("Name").String() + // pGoName = reflect.ValueOf(a).MethodByName("GoName").Call([]reflect.Value{})[0].String() + + pDesc = utils.IDToUpper(strings.ToLower(reflect.Indirect(reflect.ValueOf(a)).FieldByName("Description").String())) + ) + + // Adjust descriptions + if strings.Contains(pDesc, "a comma-separated list") { + pDesc = strings.Replace(pDesc, "a comma-separated list", "a list", -1) + } + if strings.Contains(pDesc, "use `_all` or empty string") { + pDesc = strings.Replace(pDesc, "use `_all` or empty string", "use _all", -1) + } + + // Generate annotation + b.WriteString("\n// With" + pFieldName) + if typ == "*gensource.Part" { + b.WriteString(` - ` + pDesc) + } else { + b.WriteString(` - ` + pDesc) + } + b.WriteString(`.`) + + // Generate function + b.WriteString("\n//\nfunc (f " + methodWithNamespace + `) With` + pFieldName + `(`) + + switch pGoType { + case "bool": + // empty function argument + case "*bool": + b.WriteString(`v bool`) + case "*int": + b.WriteString(`v int`) + case "[]string": + b.WriteString(`v ...string`) + default: + b.WriteString(`v ` + pGoType) + } + + b.WriteString(`) func(*` + methodWithNamespace + `Request) { + return func(r *` + methodWithNamespace + `Request) {` + "\n") + + switch pGoType { + case "bool": + b.WriteString("\t\t" + `r.` + pFieldName + ` = true`) + case "*bool", "*int": + b.WriteString("\t\t" + `r.` + pFieldName + ` = &v`) + default: + b.WriteString("\t\t" + `r.` + pFieldName + ` = v`) + } + + b.WriteString("\n\t}\n}\n") + + return b.String() + } + + // Generate WithBody method + if b := g.Endpoint.Body; b != nil { + // Do not add the option when body is part of the method signature + if !skipRequiredArgs["body"] { + g.w(` +// WithBody` + ` - ` + b.Description + `. +// +func (f ` + g.Endpoint.MethodWithNamespace() + `) WithBody(v io.Reader) func(*` + g.Endpoint.MethodWithNamespace() + `Request) { + return func(r *` + g.Endpoint.MethodWithNamespace() + `Request) { + r.Body = v + } +} +`) + } + } + + // Generate With... methods for parts + for _, pName := range g.Endpoint.URL.PartNamesSorted { + if p, ok := g.Endpoint.URL.AllParts[pName]; ok { + if skipRequiredArgs[p.Name] && p.Name != "type" { + continue + } + + g.w(methodBody(g.Endpoint, p)) + } else { + g.w(`// TODO: ` + p.Name) + } + } + + // Generate With... methods for params + for _, pName := range g.Endpoint.URL.ParamNamesSorted { + if _, ok := g.Endpoint.URL.AllParts[pName]; ok { + continue // skip params which are also parts + } + if p, ok := g.Endpoint.URL.Params[pName]; ok { + g.w(methodBody(g.Endpoint, p)) + } else { + g.w(`// TODO: ` + p.Name) + } + } + + // Generate methods for common parameters + if g.Endpoint.Name != "info" { + g.w(` +// WithPretty makes the response body pretty-printed. +// +func (f ` + g.Endpoint.MethodWithNamespace() + `) WithPretty() func(*` + g.Endpoint.MethodWithNamespace() + `Request) { + return func(r *` + g.Endpoint.MethodWithNamespace() + `Request) { + r.Pretty = true + } +} +`) + } + + g.w(` +// WithHuman makes statistical values human-readable. +// +func (f ` + g.Endpoint.MethodWithNamespace() + `) WithHuman() func(*` + g.Endpoint.MethodWithNamespace() + `Request) { + return func(r *` + g.Endpoint.MethodWithNamespace() + `Request) { + r.Human = true + } +} +`) + + g.w(` +// WithErrorTrace includes the stack trace for errors in the response body. +// +func (f ` + g.Endpoint.MethodWithNamespace() + `) WithErrorTrace() func(*` + g.Endpoint.MethodWithNamespace() + `Request) { + return func(r *` + g.Endpoint.MethodWithNamespace() + `Request) { + r.ErrorTrace = true + } +} +`) + + g.w(` +// WithFilterPath filters the properties of the response body. +// +func (f ` + g.Endpoint.MethodWithNamespace() + `) WithFilterPath(v ...string) func(*` + g.Endpoint.MethodWithNamespace() + `Request) { + return func(r *` + g.Endpoint.MethodWithNamespace() + `Request) { + r.FilterPath = v + } +} +`) + + // Generate methods for HTTP headers + g.w(` +// WithHeader adds the headers to the HTTP request. +// +func (f ` + g.Endpoint.MethodWithNamespace() + `) WithHeader(h map[string]string) func(*` + g.Endpoint.MethodWithNamespace() + `Request) { + return func(r *` + g.Endpoint.MethodWithNamespace() + `Request) { + if r.Header == nil { + r.Header = make(http.Header) + } + for k, v := range h { + r.Header.Add(k, v) + } + } +} +`) + + // Generate methods for the X-Opaque-ID header + g.w(` +// WithOpaqueID adds the X-Opaque-Id header to the HTTP request. +// +func (f ` + g.Endpoint.MethodWithNamespace() + `) WithOpaqueID(s string) func(*` + g.Endpoint.MethodWithNamespace() + `Request) { + return func(r *` + g.Endpoint.MethodWithNamespace() + `Request) { + if r.Header == nil { + r.Header = make(http.Header) + } + r.Header.Set("X-Opaque-Id", s) + } +} +`) +} + +func (g *Generator) genDoMethod() { + g.w(`// Do executes the request and returns response or error. +// +func (r ` + g.Endpoint.MethodWithNamespace() + `Request) Do(ctx context.Context, transport Transport) (*Response, error) { + var ( + method string + path strings.Builder + params map[string]string + )` + "\n\n") + + // Generate the HTTP method + switch g.Endpoint.Name { + case "index": + g.w("\t") + g.w(`if r.DocumentID != "" { + method = "PUT" + } else { + method = "POST" + }`) + g.w("\n\n") + default: + g.w("\t" + `method = "` + g.Endpoint.URL.Paths[0].Methods[0] + `"` + "\n\n") + } + + // Get default part values for specific APIs + // TODO: Move to overrides + var defparts bool + switch g.Endpoint.Name { + case "index", "create", "delete", "explain", "exists", "get", "get_source", "update", "termvectors": + for _, p := range g.Endpoint.URL.AllParts { + if p.Default != nil { + var fieldName string + var fieldValue string + var fieldCondition string + + fieldName = p.GoName() + switch p.Type { + case "string", "enum": + fieldCondition = `r.` + fieldName + ` == ""` + fieldValue = `"` + p.Default.(string) + `"` + case "number": + fieldCondition = `r.` + fieldName + ` == 0` + fieldValue = p.Default.(string) + case "list": + fieldCondition = ` len(r.` + fieldName + `) < 1` + fieldValue = `[]string{"` + p.Default.(string) + `"}` + default: + panic(fmt.Sprintf("FAIL: %q: unexpected parameter type %q for URL part %q", g.Endpoint.Name, p.Type, p.Name)) + } + g.w("\t") + g.w(`if ` + fieldCondition + ` { + r.` + fieldName + ` = ` + fieldValue + ` + }` + "\n") + defparts = true + } + } + } + if defparts { + g.w("\n") + } + + // Generate the URL path + // + if f := g.GetOverride("url", g.Endpoint.Name); f != nil { + g.w(f(g.Endpoint)) + } else { + var ( + pathGrow strings.Builder + pathContent strings.Builder + ) + + pathGrow.WriteString(` path.Grow(`) + + // FIXME: Select longest path based on number of template entries, not string length + longestPath := g.Endpoint.URL.Paths[0] + for _, v := range g.Endpoint.URL.Paths { + if len(v.Path) > len(longestPath.Path) { + longestPath = v + } + } + + if len(longestPath.Parts) < 1 { + if len(g.Endpoint.URL.Paths) < 1 { + panic(fmt.Sprintf("FAIL: %q: empty endpoint\n", g.Endpoint.Name)) + } + pathGrow.WriteString(`len("` + longestPath.Path + `")`) + pathContent.WriteString(` path.WriteString("` + longestPath.Path + `")` + "\n") + + } else { + pathParts := make([]string, 0) + apiArgs := g.Endpoint.RequiredArguments() + for _, v := range strings.Split(longestPath.Path, "/") { + if v != "" { + pathParts = append(pathParts, v) + } + } + + r := strings.NewReplacer("{", "", "}", "") + + for _, v := range pathParts { + var p string + + // Required arguments + for _, a := range apiArgs { + if strings.HasPrefix(v, "{") && a.Name == r.Replace(v) { + p = a.GoName() + pathGrow.WriteString(`1 + `) + pathContent.WriteString(` path.WriteString("/")` + "\n") + switch a.Type { + case "string": + pathGrow.WriteString(`len(r.` + p + `) + `) + pathContent.WriteString(` path.WriteString(r.` + p + `)` + "\n") + case "list": + pathGrow.WriteString(`len(strings.Join(r.` + p + `, ",")) + `) + pathContent.WriteString(` path.WriteString(strings.Join(r.` + p + `, ","))` + "\n") + default: + panic(fmt.Sprintf("FAIL: %q: unexpected type %q for URL part %q\n", g.Endpoint.Name, a.Type, a.Name)) + } + break + } + } + + // Optional arguments + if p == "" { + for _, a := range longestPath.Parts { + // fmt.Printf("a: %+v\n", a) + if strings.HasPrefix(v, "{") && a.Name == r.Replace(v) { + p = a.GoName() + + switch a.Type { + case "string": + pathGrow.WriteString(`1 + len(r.` + p + `) + `) + pathContent.WriteString(` if r.` + p + ` != "" {` + "\n") + pathContent.WriteString(` path.WriteString("/")` + "\n") + pathContent.WriteString(` path.WriteString(r.` + p + `)` + "\n") + pathContent.WriteString(` }` + "\n") + case "list": + pathGrow.WriteString(`1 + len(strings.Join(r.` + p + `, ",")) + `) + pathContent.WriteString(` if len(r.` + p + `) > 0 {` + "\n") + pathContent.WriteString(` path.WriteString("/")` + "\n") + pathContent.WriteString(` path.WriteString(strings.Join(r.` + p + `, ","))` + "\n") + pathContent.WriteString(` }` + "\n") + case "int", "long": + pathContent.WriteString(` if r.` + p + ` != nil {` + "\n") + pathContent.WriteString(` value := strconv.FormatInt(int64(*r.` + p + `), 10)` + "\n") + pathContent.WriteString(` path.Grow(1 + len(value))` + "\n") + pathContent.WriteString(` path.WriteString("/")` + "\n") + pathContent.WriteString(` path.WriteString(value)` + "\n") + pathContent.WriteString(` }` + "\n") + default: + panic(fmt.Sprintf("FAIL: %q: unexpected type %q for URL part %q\n", g.Endpoint.Name, a.Type, a.Name)) + } + + break + } + } + } + + // Optional arguments + if p == "" { + for _, a := range g.Endpoint.URL.Params { + if strings.HasPrefix(v, "{") && a.Name == r.Replace(v) { + p = a.GoName() + pathGrow.WriteString("1 +") + pathContent.WriteString(` path.WriteString("/")` + "\n") + switch a.Type { + case "string": + pathGrow.WriteString(`len(r.` + p + `)`) + pathContent.WriteString(` path.WriteString(r.` + p + `)` + "\n") + case "list": + pathGrow.WriteString(`len(strings.Join(r.` + p + `, ","))`) + pathContent.WriteString(` path.WriteString(strings.Join(r.` + p + `, ","))` + "\n") + default: + panic(fmt.Sprintf("FAIL: %q: unexpected type %q for URL param %q\n", g.Endpoint.Name, a.Type, a.Name)) + } + break + } + } + } + + // Static parts + if p == "" { + pathGrow.WriteString(`1 + len("` + v + `") + `) + pathContent.WriteString(` path.WriteString("/")` + "\n") + pathContent.WriteString(` path.WriteString("` + v + `")` + "\n") + } + } + } + + // Write out the content + pathGrow.WriteString(`)`) + g.w(strings.Replace(pathGrow.String(), " + )", ")", 1) + "\n") + g.w(pathContent.String() + "\n") + } + + // Generate the URL params + g.w(` + params = make(map[string]string)` + "\n") + for _, n := range g.Endpoint.URL.ParamNamesSorted { + if p, ok := g.Endpoint.URL.Params[n]; ok { + var ( + fieldName string + fieldType string + fieldValue string + fieldCondition string + ) + + fieldName = p.GoName() + fieldType = p.GoType() + switch fieldType { + case "bool": + fieldCondition = `r.` + fieldName + fieldValue = `strconv.FormatBool(r.` + fieldName + `)` + case "*bool": + fieldCondition = `r.` + fieldName + ` != nil` + fieldValue = `strconv.FormatBool(*r.` + fieldName + `)` + case "string": + fieldCondition = `r.` + fieldName + ` != ""` + fieldValue = `r.` + fieldName + case "int": + fieldCondition = `r.` + fieldName + ` != 0` + fieldValue = `strconv.FormatInt(int64(r.` + fieldName + `), 10)` + case "*int": + fieldCondition = `r.` + fieldName + ` != nil` + fieldValue = `strconv.FormatInt(int64(*r.` + fieldName + `), 10)` + case "uint": + fieldCondition = `r.` + fieldName + ` != 0` + fieldValue = `strconv.FormatUint(uint64(r.` + fieldName + `), 10)` + case "*uint": + fieldCondition = `r.` + fieldName + ` != 0` + fieldValue = `strconv.FormatUint(uint64(*r.` + fieldName + `), 10)` + case "[]string": + fieldCondition = ` len(r.` + fieldName + `) > 0` + fieldValue = `strings.Join(r.` + fieldName + `, ",")` + case "time.Duration": + fieldCondition = `r.` + fieldName + ` != 0` + fieldValue = `formatDuration(r.` + fieldName + `)` + default: // interface{} + fieldCondition = `r.` + fieldName + ` != nil` + // TODO: Use type switching instead? + fieldValue = `fmt.Sprintf("%v", r.` + fieldName + `)` + } + + g.w(` + if ` + fieldCondition + ` { + params["` + p.Name + `"] = ` + fieldValue + ` + }` + "\n") + + } else { + panic(fmt.Sprintf("FAIL: %q: Unknown parameter %q in URL parameters", g.Endpoint.Name, n)) + } + } + + // Common parameters + g.w(` + if r.Pretty { + params["pretty"] = "true" + } + + if r.Human { + params["human"] = "true" + } + + if r.ErrorTrace { + params["error_trace"] = "true" + } + + if len(r.FilterPath) > 0 { + params["filter_path"] = strings.Join(r.FilterPath, ",") + } + `) + g.w("\n\n") + + // Generate the HTTP request options + var httpBody string + if g.Endpoint.Body != nil { + httpBody = "r.Body" + } else { + httpBody = "nil" + } + + g.w(`req, err := newRequest(method, path.String(), ` + httpBody + `)` + "\n") + g.w(`if err != nil { + return nil, err + }` + "\n\n") + + g.w(`if len(params) > 0 { + q := req.URL.Query() + for k, v := range params { + q.Set(k, v) + } + req.URL.RawQuery = q.Encode() + }` + "\n\n") + + if g.Endpoint.Body != nil { + g.w(`if r.Body != nil { + req.Header[headerContentType] = headerContentTypeJSON + }` + "\n\n") + } + + g.w(`if len(r.Header) > 0 { + if len(req.Header) == 0 { + req.Header = r.Header + } else { + for k, vv := range r.Header { + for _, v := range vv { + req.Header.Add(k, v) + } + } + } + }` + "\n\n") + + g.w(`if ctx != nil { + req = req.WithContext(ctx) + }` + "\n\n") + + g.w(` + res, err := transport.Perform(req) + if err != nil { + return nil, err + }` + "\n\n") + + // Generate the return value + g.w(` + response := Response{ + StatusCode: res.StatusCode, + Body: res.Body, + Header: res.Header, + }` + "\n") + g.w("\n\treturn &response, nil\n") + + g.w("}\n") +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource/model.go b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource/model.go new file mode 100644 index 00000000000..143a647e30d --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource/model.go @@ -0,0 +1,441 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package gensource + +import ( + "encoding/json" + "fmt" + "io" + "os" + "sort" + "strings" + "unicode" + + "gopkg.in/yaml.v2" + + "github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils" +) + +var ( + apiDescriptions map[interface{}]interface{} +) + +func init() { + err := yaml.NewDecoder(strings.NewReader(apiDescriptionsYAML)).Decode(&apiDescriptions) + if err != nil { + panic(fmt.Sprintf("ERROR: %v", err)) + } +} + +// NewEndpoint creates a new API endpoint. +// +func NewEndpoint(f io.Reader) (*Endpoint, error) { + var endpoint Endpoint + var spec map[string]Endpoint + + if err := json.NewDecoder(f).Decode(&spec); err != nil { + return nil, err + } + + for name, e := range spec { + endpoint = e + endpoint.Name = name + endpoint.URL.Params = endpoint.Params + } + + if fpath, ok := f.(*os.File); ok { + if strings.Contains(fpath.Name(), "x-pack") { + endpoint.Type = "xpack" + } + } + if endpoint.Type == "" { + endpoint.Type = "core" + } + + endpoint.URL.AllParts = make(map[string]*Part) + + for _, path := range endpoint.URL.Paths { + for partName, part := range path.Parts { + part.Endpoint = &endpoint + part.Name = partName + } + } + + var params [][]string + for _, path := range endpoint.URL.Paths { + var parts []string + for partName := range path.Parts { + parts = append(parts, partName) + } + params = append(params, parts) + } + + var paramsCounter = make(map[string]int) + for _, pp := range params { + for _, p := range pp { + paramsCounter[p] += 1 + } + } + + // Update the required field of path parts + for _, path := range endpoint.URL.Paths { + for partName, part := range path.Parts { + if p, ok := paramsCounter[partName]; ok { + if p == len(params) { + part.Required = true + } + } + } + } + + for paramName, p := range endpoint.URL.Params { + p.Endpoint = &endpoint + p.Name = paramName + } + + // Update the AllParts field + var partSeen = make(map[string]bool) + for _, path := range endpoint.URL.Paths { + for partName, part := range path.Parts { + if !partSeen[partName] { + endpoint.URL.AllParts[partName] = part + } + partSeen[partName] = true + } + } + + // Fix up the documentation property (X-Pack spec related); TODO: PR + if !strings.HasPrefix(endpoint.Documentation.URL, "http") { + if endpoint.Type == "xpack" && endpoint.Documentation.Description == "" && endpoint.Documentation.URL != "" { + endpoint.Documentation.Description = endpoint.Documentation.URL + } + endpoint.Documentation.URL = "" + } + + var partNames []string + for param := range paramsCounter { + partNames = append(partNames, param) + } + sort.Slice(partNames, func(i, j int) bool { + return strings.Replace(partNames[i], "_", "", 1) < strings.Replace(partNames[j], "_", "", 1) + }) + endpoint.URL.PartNamesSorted = partNames + + var paramNames []string + for _, param := range endpoint.URL.Params { + paramNames = append(paramNames, param.Name) + } + sort.Slice(paramNames, func(i, j int) bool { + return strings.Replace(paramNames[i], "_", "", 1) < strings.Replace(paramNames[j], "_", "", 1) + }) + endpoint.URL.ParamNamesSorted = paramNames + + // if info, ok := apiDescriptions[endpoint.Name]; ok { + // if desc, ok := info.(map[interface{}]interface{})["description"].(string); ok { + // endpoint.Documentation.Description = desc + // } + // } + + return &endpoint, nil +} + +// Endpoint represents an API endpoint. +// +type Endpoint struct { + Name string `json:"-"` + Type string `json:"-"` + + Documentation struct { + URL string `json:"url"` + Description string `json:"description"` + } `json:"documentation"` + + URL *URL `json:"url"` + Params map[string]*Param `json:"params"` + Body *Body `json:"body"` +} + +// URL represents API endpoint URL. +// +type URL struct { + Endpoint *Endpoint `json:"-"` + + Paths []Path `json:"paths"` + DeprecatedPaths []struct { + Path string `json:"path"` + Version string `json:"version"` + Description string `json:"description"` + } `json:"deprecated_paths"` + Params map[string]*Param `json:"params"` + + AllParts map[string]*Part + PartNamesSorted []string + ParamNamesSorted []string +} + +// Path represents URL path +type Path struct { + Path string `json:"path"` + Methods []string `json:"methods"` + Parts map[string]*Part `json:"parts"` + Deprecated struct { + Version string `json:"version"` + Description string `json:"description"` + } +} + +// Part represents part of the API endpoint URL. +// +type Part struct { + Endpoint *Endpoint `json:"-"` + + Name string `json:"-"` + Default interface{} `json:"-"` + + Type string `json:"type"` + Description string `json:"description"` + Required bool `json:"required"` +} + +// Param represents API endpoint parameter. +// +type Param struct { + Endpoint *Endpoint `json:"-"` + + Name string `json:"-"` + + Type string `json:"type"` + Description string `json:"description"` + Options []string `json:"options"` + Default interface{} `json:"default"` + Required bool `json:"required"` +} + +// Body represents API endpoint body. +// +type Body struct { + Endpoint *Endpoint `json:"-"` + + Description string `json:"description"` + Required bool `json:"required"` + ContentType string `json:"serialize"` +} + +// MethodArgument represents a method argument for API endpoint. +// +type MethodArgument struct { + Endpoint *Endpoint + + Name string + Type string + Description string + Options []string + Default interface{} + Required bool +} + +// Namespace returns the API endpoint namespace. +// +func (e *Endpoint) Namespace() string { + ep := strings.Split(e.Name, ".") + return utils.NameToGo(ep[0]) +} + +// MethodName returns the API endpoint method name. +// +func (e *Endpoint) MethodName() string { + ep := strings.Split(e.Name, ".") + ep = append(ep[:0], ep[1:]...) + ns := make([]string, len(ep)) + for _, v := range ep { + m := strings.Split(v, "_") + mn := make([]string, len(m)) + for _, vv := range m { + mn = append(mn, strings.Title(vv)) + } + ns = append(ns, strings.Join(mn, "")) + } + return strings.Join(ns, "") +} + +// MethodWithNamespace returns the API endpoint method name with namespace. +// +func (e *Endpoint) MethodWithNamespace() string { + return utils.APIToGo(e.Name) +} + +// HumanMethodWithNamespace returns the API endpoint method name in humanized form. +// +func (e *Endpoint) HumanMethodWithNamespace() string { + var ( + src = e.MethodWithNamespace() + out string + ) + for i, l := range src { + if unicode.IsUpper(l) && i > 0 { + if i+2 <= len(src) && unicode.IsUpper([]rune(src[i+1 : i+2])[0]) { + out += string(l) + } else { + out += " " + string(l) + } + } else { + out += string(l) + } + } + return out +} + +// RequiredArguments return the list of required method arguments. +// +func (e *Endpoint) RequiredArguments() []MethodArgument { + var args = make([]MethodArgument, 0) + var prominentArgs = []string{ + "index", + "type", + "id", + "repository", + "snapshot", + "snapshot_id", + "calendar_id", + "job_id", + "username", + "name", + } + + var contains = func(s string) bool { + for _, v := range args { + if v.Name == s { + return true + } + } + return false + } + + // Return the prominent arguments first + for _, d := range prominentArgs { + for _, p := range e.URL.Paths[0].Parts { + if p.Name != d { + continue + } + if p.Required { + args = append(args, MethodArgument{ + Endpoint: e, + Name: p.Name, + Type: p.Type, + Description: p.Description, + Required: true, + }) + } + // Make the 'type' required for selected APIs + if p.Name == "type" && (e.Name == "index" || e.Name == "create") { + args = append(args, MethodArgument{ + Endpoint: e, + Name: p.Name, + Type: p.Type, + Description: p.Description, + Required: true, + }) + } + } + } + + // Return the body after prominent arguments + if e.Body != nil && e.Body.Required { + args = append(args, MethodArgument{ + Endpoint: e, + Name: "body", + Description: e.Body.Description, + }) + } + + // Return rest of the URL parts + for _, p := range e.URL.Paths[0].Parts { + if contains(p.Name) { + continue + } + if p.Required { + args = append(args, MethodArgument{ + Endpoint: e, + Name: p.Name, + Type: p.Type, + Description: p.Description, + Required: true, + }) + } + } + + // Return URL params + for _, p := range e.URL.Params { + if contains(p.Name) { + continue + } + if p.Required { + args = append(args, MethodArgument{ + Endpoint: e, + Name: p.Name, + Type: p.Type, + Description: p.Description, + Options: p.Options, + Default: p.Default, + Required: p.Required, + }) + } + } + + return args +} + +// GoName returns a Go name for part. +// +func (p *Part) GoName() string { + switch { + case p.Name == "context": + return "ScriptContext" + default: + return utils.NameToGo(p.Name, p.Endpoint.MethodWithNamespace()) + } +} + +// GoType returns a Go type for part. +// +func (p *Part) GoType(comment ...bool) string { + return utils.TypeToGo(p.Type) +} + +// GoName returns a Go name for parameter. +// +func (p *Param) GoName() string { + switch { + case p.Name == "context": + return "ScriptContext" + case p.Name == "q": + return "Query" + default: + return utils.NameToGo(p.Name, p.Endpoint.MethodWithNamespace()) + } +} + +// GoType returns a Go type for parameter. +// +func (p *Param) GoType(comment ...bool) string { + if f := (&Generator{Endpoint: p.Endpoint}).GetOverride("polymorphic-param", p.Endpoint.Name); f != nil { + if out := f(p.Endpoint, p.Name); out != "" { + return out + } + } + return utils.TypeToGo(p.Type) +} + +// GoName returns a Go name for method argument. +// +func (p *MethodArgument) GoName() string { + return utils.NameToGo(p.Name, p.Endpoint.MethodWithNamespace()) +} + +// GoType returns a Go type for method argument. +// +func (p *MethodArgument) GoType(comment ...bool) string { + return utils.TypeToGo(p.Type) +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource/overrides.go b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource/overrides.go new file mode 100644 index 00000000000..8dade186fb7 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource/overrides.go @@ -0,0 +1,109 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package gensource + +var ( + overrideRules map[string][]OverrideRule +) + +// OverrideFunc defines a function to override generated code for endpoint. +// +type OverrideFunc func(*Endpoint, ...interface{}) string + +// OverrideRule represents an override rule. +// +type OverrideRule struct { + Func OverrideFunc + Matching []string +} + +// GetOverride returns an override function for id and API name. +// +func (g *Generator) GetOverride(id, apiName string) OverrideFunc { + if rr, ok := overrideRules[id]; ok { + for _, r := range rr { + if r.Match(apiName) { + return r.Func + } + } + } + return nil +} + +// Match returns true when API name matches a rule. +// +func (r OverrideRule) Match(apiName string) bool { + for _, v := range r.Matching { + if v == "*" { + return true + } + if v == apiName { + return true + } + } + return false +} + +func init() { + overrideRules = map[string][]OverrideRule{ + + "polymorphic-param": {{ + Matching: []string{"search"}, + Func: func(e *Endpoint, i ...interface{}) string { + if len(i) > 0 { + switch i[0] { + case "track_total_hits": + return "interface{}" + } + } + return "" + }, + }}, + + "url": { + { + Matching: []string{"cluster.stats"}, + Func: func(*Endpoint, ...interface{}) string { + return ` + path.Grow(len("/nodes/_cluster/stats/nodes/") + len(strings.Join(r.NodeID, ","))) + path.WriteString("/") + path.WriteString("_cluster") + path.WriteString("/") + path.WriteString("stats") + if len(r.NodeID) > 0 { + path.WriteString("/") + path.WriteString("nodes") + path.WriteString("/") + path.WriteString(strings.Join(r.NodeID, ",")) + } +` + }, + }, + { + Matching: []string{"indices.put_mapping"}, + Func: func(*Endpoint, ...interface{}) string { + return ` + path.Grow(len(strings.Join(r.Index, ",")) + len("/_mapping") + 1) + if len(r.Index) > 0 { + path.WriteString("/") + path.WriteString(strings.Join(r.Index, ",")) + } + path.WriteString("/") + path.WriteString("_mapping") +` + }, + }, + { + Matching: []string{"scroll"}, + Func: func(*Endpoint, ...interface{}) string { + return ` + path.Grow(len("/_search/scroll")) + path.WriteString("/_search/scroll") +` + }, + }, + }, + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/genstruct/command.go b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/genstruct/command.go new file mode 100644 index 00000000000..2002c8b720a --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/genstruct/command.go @@ -0,0 +1,342 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package genstruct + +import ( + "bytes" + "fmt" + "go/types" + "io" + "os" + "path/filepath" + "strings" + + "golang.org/x/tools/go/packages" + "golang.org/x/tools/imports" + + "github.com/spf13/cobra" + + "github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands" + "github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils" +) + +var ( + GitCommit string + GitTag string + EsVersion string +) + +var ( + output *string + gofmt *bool + color *bool + debug *bool + info *bool + + pkgNames []string +) + +func init() { + if pkgNamesEnv := os.Getenv("PACKAGE_NAMES"); pkgNamesEnv != "" { + pkgNames = strings.Split(pkgNamesEnv, ",") + } else { + pkgNames = []string{ + "github.com/elastic/go-elasticsearch/v8/esapi", + } + } + + output = genapiCmd.Flags().StringP("output", "o", "", "Path to a folder for generated output") + gofmt = genapiCmd.Flags().BoolP("gofmt", "f", true, "Format generated output with 'gofmt'") + color = genapiCmd.Flags().BoolP("color", "c", true, "Syntax highlight the debug output") + debug = genapiCmd.Flags().BoolP("debug", "d", false, "Print the generated source to terminal") + info = genapiCmd.Flags().Bool("info", false, "Print the API details to terminal") + genapiCmd.Flags().SortFlags = false + + commands.RegisterCmd(genapiCmd) +} + +var genapiCmd = &cobra.Command{ + Use: "apistruct", + Short: "Generate the main Go API struct and constructor", + Run: func(cmd *cobra.Command, args []string) { + command := &Command{ + Output: *output, + Gofmt: *gofmt, + DebugSource: *debug, + ColorizeSource: *color, + } + err := command.Execute() + if err != nil { + utils.PrintErr(err) + os.Exit(1) + } + }, +} + +// Command represents the "genapi" command. +// +type Command struct { + Output string + Gofmt bool + DebugSource bool + ColorizeSource bool +} + +// Execute runs the command. +// +func (cmd *Command) Execute() (err error) { + EsVersion, err = utils.EsVersion("") + if err != nil { + return err + } + GitCommit, err = utils.GitCommit("") + if err != nil { + return err + } + GitTag, err = utils.GitTag("") + if err != nil { + return err + } + return cmd.processAPIConstructor() +} + +func (cmd *Command) processAPIConstructor() (err error) { + var ( + namespaces []string + endpoints []*types.TypeName + + b bytes.Buffer + i int + n int + m int + ) + + namespaces = []string{ + // Core APIs + // + "Cat", + "Cluster", + "Indices", + "Ingest", + "Nodes", + "Remote", + "Snapshot", + "Tasks", + + // XPack APIs + // + "CCR", + "ILM", + "License", + "Migration", + "ML", + "Monitoring", + "Rollup", + "Security", + "SQL", + "SSL", + "Watcher", + "XPack", + } + + lpkgs, err := packages.Load(&packages.Config{Mode: packages.LoadTypes}, pkgNames...) + if err != nil { + fmt.Printf("Error loading packages: %s\n", err) + return err + } + + for _, lpkg := range lpkgs { + n++ + + if cmd.DebugSource { + fmt.Println(lpkg.Types) + } + + scope := lpkg.Types.Scope() + for _, name := range scope.Names() { + m++ + obj := scope.Lookup(name) + // Skip unexported objects + if !obj.Exported() { + continue + } + + // Skip non-structs + structObj, ok := obj.Type().Underlying().(*types.Struct) + if !ok { + continue + } + + // Skip non-request objects + if !strings.HasSuffix(obj.Name(), "Request") { + continue + } + + // Append API struct to endpoints + endpoints = append(endpoints, obj.(*types.TypeName)) + + i++ + fmt.Printf("%-3d | %s{}\n", i, obj.Name()) + for j := 0; j < structObj.NumFields(); j++ { + field := structObj.Field(j) + if cmd.DebugSource { + fmt.Printf(" %s %s\n", field.Name(), field.Type()) + } + } + } + } + + b.WriteString("// Code generated") + if EsVersion != "" || GitCommit != "" || GitTag != "" { + b.WriteString(fmt.Sprintf(" from specification version %s", EsVersion)) + if GitCommit != "" { + b.WriteString(fmt.Sprintf(" (%s", GitCommit)) + if GitTag != "" { + b.WriteString(fmt.Sprintf("|%s", GitTag)) + } + b.WriteString(")") + } + } + b.WriteString(": DO NOT EDIT\n") + b.WriteString("\n") + + b.WriteString(`package esapi + +// API contains the Elasticsearch APIs +// +type API struct { +`) + for _, n := range namespaces { + b.WriteString(fmt.Sprintf("\t%[1]s *%[1]s\n", n)) + } + + b.WriteString("\n") + + for _, e := range endpoints { + skip := false + name := strings.ReplaceAll(e.Name(), "Request", "") + + // Skip APIs in namespace + for _, n := range namespaces { + if strings.HasPrefix(strings.ToLower(name), strings.ToLower(n)) { + skip = true + } + } + if !skip { + b.WriteString(fmt.Sprintf("\t%[1]s %[1]s\n", name)) + } + } + + b.WriteString(`}` + "\n\n") + + for _, n := range namespaces { + b.WriteString(`// ` + n + ` contains the ` + n + ` APIs` + "\n") + b.WriteString(`type ` + n + ` struct {` + "\n") + for _, e := range endpoints { + name := strings.ReplaceAll(e.Name(), "Request", "") + if strings.HasPrefix(strings.ToLower(name), strings.ToLower(n)) { + methodName := strings.ReplaceAll(name, n, "") + b.WriteString(fmt.Sprintf("\t%s %s\n", methodName, name)) + } + } + b.WriteString("}\n\n") + } + + b.WriteString(`// New creates new API +// +func New(t Transport) *API { + return &API{ +`) + + for _, e := range endpoints { + skip := false + name := strings.ReplaceAll(e.Name(), "Request", "") + + for _, n := range namespaces { + if strings.HasPrefix(strings.ToLower(name), strings.ToLower(n)) { + skip = true + } + } + if !skip { + b.WriteString(fmt.Sprintf("\t\t%[1]s: new%[1]sFunc(t),\n", name)) + } + } + + for _, n := range namespaces { + b.WriteString(fmt.Sprintf("\t\t%[1]s: &%[1]s{\n", n)) + for _, e := range endpoints { + name := strings.ReplaceAll(e.Name(), "Request", "") + if strings.HasPrefix(strings.ToLower(name), strings.ToLower(n)) { + methodName := strings.ReplaceAll(name, n, "") + b.WriteString(fmt.Sprintf("\t\t\t%s: new%sFunc(t),\n", methodName, name)) + } + } + b.WriteString("\t\t},\n") + } + + b.WriteString(` } +} +`) + + if cmd.Gofmt { + out, err := imports.Process( + "esapi/api._.go", + b.Bytes(), + &imports.Options{ + AllErrors: true, + Comments: true, + FormatOnly: false, + TabIndent: true, + TabWidth: 1, + }) + if err != nil { + return err + } + b = *bytes.NewBuffer(out) + } + + if cmd.DebugSource { + var src io.Reader + var buf bytes.Buffer + tee := io.TeeReader(bytes.NewReader(b.Bytes()), &buf) + + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[2m") + } + fmt.Fprintln(os.Stderr, strings.Repeat("━", utils.TerminalWidth())) + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[0m") + } + if cmd.ColorizeSource { + src, err = utils.Chromatize(tee) + if err != nil { + return fmt.Errorf("error syntax highligting the output: %s", err) + } + } else { + src = bytes.NewReader(b.Bytes()) + } + + _, err = io.Copy(os.Stderr, src) + if err != nil { + return fmt.Errorf("error copying output: %s", err) + } + + fmt.Fprintf(os.Stderr, "\n\n") + } + + fname := filepath.Join(cmd.Output, "api._.go") + f, err := os.OpenFile(fname, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0755) + if err != nil { + return fmt.Errorf("error creating file: %s", err) + } + _, err = io.Copy(f, &b) + if err != nil { + return fmt.Errorf("error copying output: %s", err) + } + if err := f.Close(); err != nil { + return fmt.Errorf("error closing file: %s", err) + } + return nil +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/command.go b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/command.go new file mode 100644 index 00000000000..4f34d854ffa --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/command.go @@ -0,0 +1,296 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package gentests + +//go:generate go run gen_api_registry.go + +import ( + "bytes" + "errors" + "fmt" + "io" + "os" + "path/filepath" + "strings" + "time" + + "github.com/spf13/cobra" + yaml "gopkg.in/yaml.v2" + + "github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands" + "github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils" +) + +var ( + input *string + output *string + gofmt *bool + color *bool + debug *bool + info *bool + + // Populated by 'go generate' + apiRegistry map[string]map[string]string +) + +var ( + GitCommit string + GitTag string + EsVersion string +) + +func init() { + input = gentestsCmd.Flags().StringP("input", "i", "", "Path to a folder or files with Elasticsearch REST API specification") + output = gentestsCmd.Flags().StringP("output", "o", "", "Path to a folder for generated output") + gofmt = gentestsCmd.Flags().BoolP("gofmt", "f", true, "Format generated output with 'gofmt'") + color = gentestsCmd.Flags().BoolP("color", "c", true, "Syntax highlight the debug output") + debug = gentestsCmd.Flags().BoolP("debug", "d", false, "Print the generated source to terminal") + info = gentestsCmd.Flags().Bool("info", false, "Print the API details to terminal") + + gentestsCmd.MarkFlagRequired("input") + gentestsCmd.MarkFlagRequired("output") + + commands.RegisterCmd(gentestsCmd) +} + +var gentestsCmd = &cobra.Command{ + Use: "apitests", + Short: "Generate the Go integration tests from the Elasticsearch common test suite", + Run: func(cmd *cobra.Command, args []string) { + command := &Command{ + Input: *input, + Output: *output, + Gofmt: *gofmt, + DebugInfo: *info, + DebugSource: *debug, + ColorizeSource: *color, + } + err := command.Execute() + if err != nil { + utils.PrintErr(err) + os.Exit(1) + } + }, +} + +// Command represents the "gentests" command. +// +type Command struct { + Input string + Output string + Gofmt bool + DebugInfo bool + DebugSource bool + ColorizeSource bool +} + +// Execute runs the command. +// +func (cmd *Command) Execute() error { + if len(apiRegistry) < 1 { + return fmt.Errorf("API registry in 'api_registry.gen.go' is empty: Did you run go generate?") + } + + inputFiles, err := filepath.Glob(cmd.Input) + if err != nil { + return fmt.Errorf("Failed to glob input %q: %s", cmd.Input, err) + } + + if len(inputFiles) < 1 { + return fmt.Errorf("No files matching input %q", cmd.Input) + } + + EsVersion, err = utils.EsVersion(filepath.Dir(inputFiles[0])) + if err != nil { + return err + } + if EsVersion == "" { + return errors.New("Elasticsearch version is empty") + } + + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[2;1m") + } + fmt.Fprintf(os.Stderr, "Elasticsearch %s\n", EsVersion) + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[0m") + } + + GitCommit, err = utils.GitCommit(filepath.Dir(inputFiles[0])) + if err != nil { + return fmt.Errorf("Failed to get Git commit: %s", err) + } + GitTag, _ = utils.GitTag(filepath.Dir(inputFiles[0])) + + stats := struct { + n int + start time.Time + }{start: time.Now()} + + for _, fpath := range inputFiles { + var skip bool + + if filepath.Ext(fpath) != ".yml" && filepath.Ext(fpath) != ".yaml" { + skip = true + } + + for _, skipFile := range skipFiles { + if strings.HasSuffix(fpath, skipFile) { + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[2m") + } + fmt.Fprintln(os.Stderr, strings.Repeat("━", utils.TerminalWidth())) + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[0;33m") + } + fmt.Fprintf(os.Stderr, "Skipping %q\n", fpath) + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[0m") + } + skip = true + } + } + + if skip { + continue + } + + if err := cmd.processFile(fpath); err != nil { + return fmt.Errorf("Processing file %q: %s", fpath, err) + } + stats.n++ + } + + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[2m") + } + fmt.Fprintln(os.Stderr, strings.Repeat("━", utils.TerminalWidth())) + fmt.Fprintf(os.Stderr, "Processed %d files in %s\n", stats.n, time.Since(stats.start).Truncate(time.Millisecond)) + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[0m") + } + + return nil +} + +func (cmd *Command) processFile(fpath string) (err error) { + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[2m") + } + fmt.Fprintln(os.Stderr, strings.Repeat("━", utils.TerminalWidth())) + fmt.Fprintf(os.Stderr, "Processing %q\n", fpath) + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[0m") + } + + var out io.Reader + var payloads []TestPayload + + f, err := os.Open(fpath) + if err != nil { + return err + } + defer f.Close() + + patched, err := PatchTestSource(fpath, f) + if err != nil { + return fmt.Errorf("cannot patch source: %s", err) + } + + dec := yaml.NewDecoder(patched) + + for { + var payload interface{} + err := dec.Decode(&payload) + if err == io.EOF { + break + } + if err != nil { + return fmt.Errorf("parse error: %s", err) + } + payloads = append(payloads, TestPayload{fpath, payload}) + } + + ts := NewTestSuite(fpath, payloads) + + if cmd.DebugInfo { + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[2m") + } + fmt.Fprint(os.Stderr, ts.DebugInfo()) + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\n\x1b[0m") + } + } + + if ts.Skip { + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[2m") + } + fmt.Fprintf(os.Stderr, "Skipping test suite %q", ts.Name()) + if utils.IsTTY() { + fmt.Fprint(os.Stderr, "\n\x1b[0m") + } + return nil + } + + gen := Generator{TestSuite: ts} + + if cmd.Gofmt { + out, err = gen.OutputFormatted() + } else { + out, err = gen.Output() + } + if err != nil { + if cmd.DebugSource { + utils.PrintSourceWithErr(out, err) + } + return fmt.Errorf("error generating output: %s", err) + } + + if cmd.DebugSource { + var src io.Reader + var buf bytes.Buffer + tee := io.TeeReader(out, &buf) + + src, err = utils.Chromatize(tee) + if err != nil { + return fmt.Errorf("error syntax highligting the output: %s", err) + } + + _, err = io.Copy(os.Stderr, src) + if err != nil { + return fmt.Errorf("error copying output: %s", err) + } + + out = &buf + } + + if cmd.Output == "-" { + _, err = io.Copy(os.Stdout, out) + if err != nil { + return fmt.Errorf("error copying output: %s", err) + } + } else { + if err := os.MkdirAll(cmd.Output, 0775); err != nil { + return fmt.Errorf("error creating directory: %s", err) + } + + fName := filepath.Join(cmd.Output, gen.TestSuite.Filename()+"_test.go") + f, err := os.OpenFile(fName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0755) + if err != nil { + return fmt.Errorf("error creating file: %s", err) + } + _, err = io.Copy(f, out) + if err != nil { + return fmt.Errorf("error copying output: %s", err) + } + if err := f.Close(); err != nil { + return fmt.Errorf("error closing file: %s", err) + } + } + + return nil +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/debug.go b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/debug.go new file mode 100644 index 00000000000..af3c88e1166 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/debug.go @@ -0,0 +1,100 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package gentests + +import ( + "fmt" + "strings" + + "github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils" +) + +// DebugInfo returns information about the endpoint as a string. +// +func (tg TestSuite) DebugInfo() string { + var out strings.Builder + + fmt.Fprintln(&out, strings.Repeat("─", utils.TerminalWidth())) + fmt.Fprint(&out, "["+tg.Name()+"]\n") + fmt.Fprintln(&out, strings.Repeat("─", utils.TerminalWidth())) + + if len(tg.Setup) > 0 { + for _, a := range tg.Setup { + fmt.Fprint(&out, "[setup] ") + fmt.Fprint(&out, a.Method()+"(") + var i int + for k, v := range a.Params() { + i++ + fmt.Fprint(&out, ""+k+": "+fmt.Sprintf("%v", v)) + if i < len(a.Params()) { + fmt.Fprint(&out, ", ") + } + } + fmt.Fprint(&out, ")") + fmt.Fprint(&out, "\n") + } + } + + if len(tg.Teardown) > 0 { + for _, a := range tg.Teardown { + fmt.Fprint(&out, "[tdown] ") + fmt.Fprint(&out, a.Method()+"(") + var i int + for k, v := range a.Params() { + i++ + fmt.Fprint(&out, ""+k+": "+fmt.Sprintf("%v", v)) + if i < len(a.Params()) { + fmt.Fprint(&out, ", ") + } + } + fmt.Fprint(&out, ")\n") + } + } + + for _, t := range tg.Tests { + if utils.IsTTY() { + fmt.Fprint(&out, "\x1b[1;2m") + } + fmt.Fprintln(&out, t.Name+":") + if utils.IsTTY() { + fmt.Fprint(&out, "\x1b[0;2m") + } + for _, a := range t.Setup { + fmt.Fprintf(&out, " [setup] ") + fmt.Fprint(&out, a.Method()+"()\n") + } + for _, a := range t.Teardown { + fmt.Fprintf(&out, " [tdown] ") + fmt.Fprint(&out, a.Method()+"()\n") + } + for _, a := range t.Steps { + switch a.(type) { + case Action: + aa := a.(Action) + fmt.Fprintf(&out, " ==> ") + fmt.Fprint(&out, aa.Method()+"(") + var i int + for k, v := range aa.Params() { + i++ + fmt.Fprint(&out, ""+k+": "+fmt.Sprintf("%v", v)) + if i < len(aa.Params()) { + fmt.Fprint(&out, ", ") + } + } + fmt.Fprint(&out, ")\n") + case Assertion: + aa := a.(Assertion) + fmt.Fprintf(&out, " ~~> ") + fmt.Fprintf(&out, "%q: %s", aa.operation, aa.payload) + fmt.Fprint(&out, "\n") + default: + panic(fmt.Sprintf("Unknown step %T", a)) + } + } + } + + fmt.Fprintln(&out, strings.Repeat("─", utils.TerminalWidth())) + return out.String() +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/generator.go b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/generator.go new file mode 100644 index 00000000000..6920b3230d6 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/generator.go @@ -0,0 +1,1189 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package gentests + +import ( + "bufio" + "bytes" + "encoding/json" + "fmt" + "io" + "io/ioutil" + "os" + "os/exec" + "path/filepath" + "regexp" + "strconv" + "strings" + "time" + + "golang.org/x/tools/imports" +) + +var ( + goruncache map[string]string +) + +func init() { + goruncache = make(map[string]string) +} + +// Generator represents the "gentests" generator. +// +type Generator struct { + b bytes.Buffer + + TestSuite TestSuite +} + +// Output returns the generator output. +// +func (g *Generator) Output() (io.Reader, error) { + name := g.TestSuite.Name() + if g.TestSuite.Type == "xpack" { + name = "XPack_" + name + } + + g.genFileHeader() + g.w("func Test" + name + "(t *testing.T) {\n") + g.genInitializeClient() + g.genHelpers() + g.genCommonSetup() + if g.TestSuite.Type == "xpack" { + g.genXPackSetup() + } + if len(g.TestSuite.Setup) > 0 { + g.w("// ----- Test Suite Setup --------------------------------------------------------\n") + g.w("testSuiteSetup := func() {\n") + g.genSetupTeardown(g.TestSuite.Setup) + g.w("}\n") + g.w("_ = testSuiteSetup\n") + g.w("// --------------------------------------------------------------------------------\n") + g.w("\n") + } + if len(g.TestSuite.Teardown) > 0 { + g.w("\t// Teardown\n") + g.w("\tdefer func(t *testing.T) {\n") + g.genSetupTeardown(g.TestSuite.Teardown) + g.w("\t}(t)\n") + } + for i, t := range g.TestSuite.Tests { + g.w("\n") + g.genLocationYAML(t) + g.w("\t" + `t.Run("` + strings.Title(t.Name) + `", ` + "func(t *testing.T) {\n") + if !g.genSkip(t) { + g.w("\tdefer recoverPanic(t)\n") + g.w("\tcommonSetup()\n") + if g.TestSuite.Type == "xpack" { + g.w("\txpackSetup()\n") + } + if len(g.TestSuite.Setup) > 0 { + g.w("\ttestSuiteSetup()\n") + } + g.w("\n") + if len(t.Setup) > 0 { + g.w("\t// Test setup\n") + g.genSetupTeardown(t.Setup) + } + if len(t.Teardown) > 0 { + g.w("\t// Test teardown\n") + g.w("\tdefer func(t) {\n") + g.genSetupTeardown(t.Teardown) + g.w("\t}(t *testing.T)\n") + } + if len(t.Setup) > 0 || len(t.Teardown) > 0 { + g.w("\n") + } + g.genSteps(t) + } + g.w("\t})\n") + if i < len(g.TestSuite.Tests)-1 { + g.w("\n") + } + } + g.w("}\n") + return bytes.NewReader(g.b.Bytes()), nil +} + +// OutputFormatted returns a formatted generator output. +// +func (g *Generator) OutputFormatted() (io.Reader, error) { + out, err := g.Output() + if err != nil { + return bytes.NewReader(g.b.Bytes()), err + } + + var b bytes.Buffer + if _, err := io.Copy(&b, out); err != nil { + return bytes.NewReader(g.b.Bytes()), err + } + + fout, err := imports.Process( + "", + g.b.Bytes(), + &imports.Options{ + AllErrors: true, + Comments: true, + FormatOnly: false, + TabIndent: true, + TabWidth: 1, + }) + if err != nil { + return bytes.NewReader(b.Bytes()), err + } + + g.b.Reset() + g.b.Write(fout) + + return bytes.NewReader(fout), nil +} + +func (g *Generator) w(s string) { + g.b.WriteString(s) +} + +func (g *Generator) gorun(code string) (string, error) { + if goruncache[code] != "" { + return goruncache[code], nil + } + + dir, err := ioutil.TempDir("tmp", "gorun") + if err != nil { + return "", fmt.Errorf("gorun: %s", err) + } + f, err := os.Create(filepath.Join(dir, "type_for_struct_field.go")) + if err != nil { + return "", fmt.Errorf("gorun: %s", err) + } + defer func() { + f.Close() + os.RemoveAll(dir) + }() + + // fmt.Println(code) + if err := ioutil.WriteFile(f.Name(), []byte(code), 0644); err != nil { + return "", fmt.Errorf("gorun: %s", err) + } + + cmd := exec.Command("go", "run", f.Name()) + out, err := cmd.Output() + if err != nil { + if e, ok := err.(*exec.ExitError); ok { + return "", fmt.Errorf("gorun: %s", e.Stderr) + } + return "", fmt.Errorf("gorun: %s", err) + } + + goruncache[code] = string(out) + + return string(out), nil +} + +func (g *Generator) genFileHeader() { + g.w("// Code generated") + if EsVersion != "" || GitCommit != "" || GitTag != "" { + g.w(" from YAML test suite version") + if GitCommit != "" { + g.w(fmt.Sprintf(" %s", GitCommit)) + if GitTag != "" { + g.w(fmt.Sprintf("|%s", GitTag)) + } + } + } + g.w(" -- DO NOT EDIT\n") + g.w("\n") + g.w("package esapi_test\n") + g.w(` +import ( + encjson "encoding/json" + encyaml "gopkg.in/yaml.v2" + "fmt" + "context" + "crypto/tls" + "os" + "net/url" + "testing" + "time" + + "github.com/elastic/go-elasticsearch/v8" + "github.com/elastic/go-elasticsearch/v8/esapi" + "github.com/elastic/go-elasticsearch/v8/estransport" +) + +var ( + // Prevent compilation errors for unused packages + _ = fmt.Printf + _ = encjson.NewDecoder + _ = encyaml.NewDecoder + _ = tls.Certificate{} + _ = url.QueryEscape +)` + "\n") +} + +func (g *Generator) genInitializeClient() { + if g.TestSuite.Type == "xpack" { + g.w(` + cfg := elasticsearch.Config{ + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: true, + }, + }, + } + if os.Getenv("DEBUG") != "" { + cfg.Logger = &estransport.ColorLogger{ + Output: os.Stdout, + // EnableRequestBody: true, + EnableResponseBody: true, + } + } + es, eserr := elasticsearch.NewClient(cfg) + if eserr != nil { + t.Fatalf("Error creating the client: %s\n", eserr) + } + +`) + } else { + g.w(` es, eserr := elasticsearch.NewDefaultClient() + if eserr != nil { + t.Fatalf("Error creating the client: %s\n", eserr) + } + +`) + } +} + +func (g *Generator) genHelpers() { + g.w(`recoverPanic := func(t *testing.T) { + reLocation := regexp.MustCompile("(.*_test.go:\\d+).*") + if rec := recover(); rec != nil { + var loc string + s := strings.Split(string(debug.Stack()), "\n") + for i := len(s) - 1; i >= 0; i-- { + if reLocation.MatchString(s[i]) { + loc = strings.TrimSpace(s[i]) + break + } + } + t.Fatalf("Panic: %s in %s", rec, reLocation.ReplaceAllString(loc, "$1")) + } +} +_ = recoverPanic +` + "\n") + + g.w(` + handleResponseError := func(t *testing.T, res *esapi.Response) { + if res.IsError() { + reLocation := regexp.MustCompile("(.*_test.go:\\d+).*") + var loc string + s := strings.Split(string(debug.Stack()), "\n") + for i := len(s) - 1; i >= 0; i-- { + if reLocation.MatchString(s[i]) { + loc = strings.TrimSpace(s[i]) + break + } + } + t.Logf("Response error: %s in %s", res, reLocation.ReplaceAllString(loc, "$1")) + } + } + _ = handleResponseError +`) + g.w("\n\n") +} + +// Reference: https://github.com/elastic/elasticsearch/blob/master/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java +// +func (g *Generator) genCommonSetup() { + g.w(` + // ----- Common Setup ------------------------------------------------------------- + commonSetup := func() { + var res *esapi.Response + + { + res, _ = es.Cluster.Health(es.Cluster.Health.WithWaitForNoInitializingShards(true)) + if res != nil && res.Body != nil { + defer res.Body.Close() + } + } + + { + res, _ = es.Indices.Delete([]string{"_all"}) + if res != nil && res.Body != nil { defer res.Body.Close() } + } + + { + var r map[string]interface{} + res, _ = es.Indices.GetTemplate() + if res != nil && res.Body != nil { + defer res.Body.Close() + json.NewDecoder(res.Body).Decode(&r) + for templateName, _ := range r { + if strings.HasPrefix(templateName, ".") { + continue + } + if templateName == "security_audit_log" { + continue + } + if templateName == "logstash-index-template" { + continue + } + es.Indices.DeleteTemplate(templateName) + } + } + } + + { + res, _ = es.Indices.DeleteAlias([]string{"_all"}, []string{"_all"}) + if res != nil && res.Body != nil { defer res.Body.Close() } + } + + { + var r map[string]interface{} + res, _ = es.Snapshot.GetRepository() + if res != nil && res.Body != nil { + defer res.Body.Close() + json.NewDecoder(res.Body).Decode(&r) + for repositoryID, _ := range r { + var r map[string]interface{} + res, _ = es.Snapshot.Get(repositoryID, []string{"_all"}) + json.NewDecoder(res.Body).Decode(&r) + if r["responses"] != nil { + for _, vv := range r["responses"].([]interface{}) { + for _, v := range vv.(map[string]interface{})["snapshots"].([]interface{}) { + snapshotID, ok := v.(map[string]interface{})["snapshot"] + if !ok { + continue + } + es.Snapshot.Delete(repositoryID, fmt.Sprintf("%s", snapshotID)) + } + } + } + es.Snapshot.DeleteRepository([]string{fmt.Sprintf("%s", repositoryID)}) + } + } + } + + { + res, _ = es.Cluster.Health(es.Cluster.Health.WithWaitForStatus("yellow")) + if res != nil && res.Body != nil { + defer res.Body.Close() + } + } + } + _ = commonSetup + + `) +} + +// Reference: https://github.com/elastic/elasticsearch/blob/master/x-pack/plugin/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestIT.java +// Reference: https://github.com/elastic/elasticsearch/blob/master/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/integration/MlRestTestStateCleaner.java +// +func (g *Generator) genXPackSetup() { + g.w(` + // ----- XPack Setup ------------------------------------------------------------- + xpackSetup := func() { + var res *esapi.Response + + { + var r map[string]interface{} + res, _ = es.Indices.GetTemplate() + if res != nil && res.Body != nil { + defer res.Body.Close() + json.NewDecoder(res.Body).Decode(&r) + for templateName, _ := range r { + if strings.HasPrefix(templateName, ".") { + continue + } + es.Indices.DeleteTemplate(templateName) + } + } + } + + { + res, _ = es.Watcher.DeleteWatch("my_watch") + if res != nil && res.Body != nil { + defer res.Body.Close() + } + } + + { + var r map[string]interface{} + res, _ = es.Security.GetRole(es.Security.GetRole.WithPretty()) + if res != nil && res.Body != nil { + defer res.Body.Close() + json.NewDecoder(res.Body).Decode(&r) + for k, v := range r { + reserved, ok := v.(map[string]interface{})["metadata"].(map[string]interface{})["_reserved"].(bool) + if ok && reserved { + continue + } + es.Security.DeleteRole(k) + } + } + } + + { + var r map[string]interface{} + res, _ = es.Security.GetUser(es.Security.GetUser.WithPretty()) + if res != nil && res.Body != nil { + defer res.Body.Close() + json.NewDecoder(res.Body).Decode(&r) + for k, v := range r { + reserved, ok := v.(map[string]interface{})["metadata"].(map[string]interface{})["_reserved"].(bool) + if ok && reserved { + continue + } + es.Security.DeleteUser(k) + } + } + } + + { + var r map[string]interface{} + res, _ = es.Security.GetPrivileges(es.Security.GetPrivileges.WithPretty()) + if res != nil && res.Body != nil { + defer res.Body.Close() + json.NewDecoder(res.Body).Decode(&r) + for k, v := range r { + reserved, ok := v.(map[string]interface{})["metadata"].(map[string]interface{})["_reserved"].(bool) + if ok && reserved { + continue + } + es.Security.DeletePrivileges(k, "_all") + } + } + } + + { + var r map[string]interface{} + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + es.ML.StopDatafeed("_all", es.ML.StopDatafeed.WithContext(ctx)) + res, _ = es.ML.GetDatafeeds() + if res != nil && res.Body != nil { + defer res.Body.Close() + json.NewDecoder(res.Body).Decode(&r) + for _, v := range r["datafeeds"].([]interface{}) { + datafeedID, ok := v.(map[string]interface{})["datafeed_id"] + if !ok { + continue + } + es.ML.DeleteDatafeed(datafeedID.(string)) + } + } + } + + { + var r map[string]interface{} + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + es.ML.CloseJob("_all", es.ML.CloseJob.WithContext(ctx)) + res, _ = es.ML.GetJobs() + if res != nil && res.Body != nil { + defer res.Body.Close() + json.NewDecoder(res.Body).Decode(&r) + for _, v := range r["jobs"].([]interface{}) { + jobID, ok := v.(map[string]interface{})["job_id"] + if !ok { + continue + } + es.ML.DeleteJob(jobID.(string)) + } + } + } + + { + var r map[string]interface{} + res, _ = es.Rollup.GetJobs(es.Rollup.GetJobs.WithJobID("_all")) + if res != nil && res.Body != nil { + defer res.Body.Close() + json.NewDecoder(res.Body).Decode(&r) + for _, v := range r["jobs"].([]interface{}) { + jobID, ok := v.(map[string]interface{})["config"].(map[string]interface{})["id"] + if !ok { + continue + } + es.Rollup.StopJob(jobID.(string), es.Rollup.StopJob.WithWaitForCompletion(true)) + es.Rollup.DeleteJob(jobID.(string)) + } + } + } + + { + var r map[string]interface{} + res, _ = es.Tasks.List() + if res != nil && res.Body != nil { + defer res.Body.Close() + json.NewDecoder(res.Body).Decode(&r) + for _, vv := range r["nodes"].(map[string]interface{}) { + for _, v := range vv.(map[string]interface{})["tasks"].(map[string]interface{}) { + cancellable, ok := v.(map[string]interface{})["cancellable"] + if !ok || !cancellable.(bool) { + continue + } + taskID := fmt.Sprintf("%v:%v", v.(map[string]interface{})["node"], v.(map[string]interface{})["id"]) + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + es.Tasks.Cancel(es.Tasks.Cancel.WithTaskID(taskID), es.Tasks.Cancel.WithContext(ctx)) + } + } + } + } + + { + var r map[string]interface{} + res, _ = es.Snapshot.GetRepository() + if res != nil && res.Body != nil { + defer res.Body.Close() + json.NewDecoder(res.Body).Decode(&r) + for repositoryID, _ := range r { + var r map[string]interface{} + res, _ = es.Snapshot.Get(repositoryID, []string{"_all"}) + json.NewDecoder(res.Body).Decode(&r) + for _, vv := range r["responses"].([]interface{}) { + for _, v := range vv.(map[string]interface{})["snapshots"].([]interface{}) { + snapshotID, ok := v.(map[string]interface{})["snapshot"] + if !ok { + continue + } + es.Snapshot.Delete(repositoryID, fmt.Sprintf("%s", snapshotID)) + } + } + es.Snapshot.DeleteRepository([]string{fmt.Sprintf("%s", repositoryID)}) + } + } + } + + { + res, _ = es.ILM.RemovePolicy("_all") + if res != nil && res.Body != nil { + defer res.Body.Close() + } + } + + { + res, _ = es.Cluster.Health(es.Cluster.Health.WithWaitForStatus("yellow")) + if res != nil && res.Body != nil { + defer res.Body.Close() + } + } + + { + res, _ = es.Security.PutUser("x_pack_rest_user", strings.NewReader(` + "`" + `{"password":"x-pack-test-password", "roles":["superuser"]}` + "`" + `), es.Security.PutUser.WithPretty()) + if res != nil && res.Body != nil { + defer res.Body.Close() + } + } + + { + res, _ = es.Indices.Refresh(es.Indices.Refresh.WithIndex("_all")) + if res != nil && res.Body != nil { + defer res.Body.Close() + } + } + + { + res, _ = es.Cluster.Health(es.Cluster.Health.WithWaitForStatus("yellow")) + if res != nil && res.Body != nil { + defer res.Body.Close() + } + } + + { + var i int + for { + i++ + var r map[string]interface{} + res, _ = es.Cluster.PendingTasks() + if res != nil && res.Body != nil { + defer res.Body.Close() + json.NewDecoder(res.Body).Decode(&r) + if len(r["tasks"].([]interface{})) < 1 { + break + } + } + if i > 30 { + break + } + time.Sleep(time.Second) + } + } + } + _ = xpackSetup + + `) +} + +func (g *Generator) genLocationYAML(t Test) { + f, err := os.Open(t.Filepath) + if err != nil { + g.w(fmt.Sprintf("// Error opening file: %s\n", err)) + } + + scanner := bufio.NewScanner(f) + var i int + for scanner.Scan() { + i++ + tname := scanner.Text() + tname = strings.TrimRight(tname, `:`) + tname = strings.NewReplacer(`\"`, `"`).Replace(tname) + tname = strings.TrimPrefix(tname, `"`) + tname = strings.TrimSuffix(tname, `"`) + + if tname == t.OrigName { + // TODO: Github URL (with proper branch/commit/etc) + g.w("\t// Source: " + t.Filepath + fmt.Sprintf(":%d", i) + "\n\t//\n") + } + } + if err := scanner.Err(); err != nil { + g.w(fmt.Sprintf("// Error reading file: %s\n", err)) + } +} + +func (g *Generator) genSkip(t Test) (skipped bool) { + // Check the custom skip list + if skips, ok := skipTests[t.BaseFilename()]; ok { + if len(skips) < 1 { + g.w("\t// Skipping all tests in '" + t.BaseFilename() + "'\n") + g.w("\tt.SkipNow()\n\n") + return true + } + + for _, skip := range skips { + if skip == t.OrigName { + g.w("\tt.SkipNow()\n\n") + return true + } + } + } + + // Check the skip property coming from YAML + if t.Skip { + if t.SkipInfo != "" { + g.w("\tt.Skip(" + strconv.Quote(t.SkipInfo) + ")\n\n") + return true + } else { + g.w("\tt.SkipNow()\n\n") + return true + } + } + + return false +} + +func (g *Generator) genSetupTeardown(actions []Action) { + g.genVarSection(Test{}) + + for _, a := range actions { + g.genAction(a, false) + g.w("\n") + } +} + +func (g *Generator) genSteps(t Test) { + var skipBody bool + if !t.Steps.ContainsAssertion() && !t.Steps.ContainsCatch() && !t.Steps.ContainsStash() { + skipBody = true + } + g.genVarSection(t, skipBody) + + for _, step := range t.Steps { + switch step.(type) { + case Action: + // Generate debug info + var dbg strings.Builder + dbg.WriteString("\t\t// => " + step.(Action).Method() + "(") + var j int + for k, v := range step.(Action).Params() { + j++ + dbg.WriteString(k + ": " + strings.Replace(fmt.Sprintf("%v", v), "\n", "|", -1)) + if j < len(step.(Action).Params()) { + dbg.WriteString(", ") + } + } + dbg.WriteString(") ") + pad := 101 - dbg.Len() + if pad < 0 { + pad = 0 + } + g.w(dbg.String() + strings.Repeat("-", pad) + "\n\t\t//\n") + + // Generate the action + g.genAction(step.(Action), skipBody) + g.w("\t\t// " + strings.Repeat("-", 96) + "\n\n") + case Assertion: + // Generate debug info + g.w("\t\t// ~> ") + g.w(fmt.Sprintf("%q: ", step.(Assertion).operation)) + g.w(strings.Replace(fmt.Sprintf("%s", step.(Assertion).payload), "\n", "|", -1)) + g.w("\n") + // Generate the assertion + g.genAssertion(step.(Assertion)) + g.w("\n") + case Stash: + // Generate setting the stash + g.genStashSet(step.(Stash)) + g.w("\n") + default: + panic(fmt.Sprintf("Unknown step %T", step)) + } + } +} + +func (g *Generator) genVarSection(t Test, skipBody ...bool) { + g.w("\t\tvar (\n") + g.w("\t\t\treq esapi.Request\n") + g.w("\t\t\tres *esapi.Response\n") + g.w("\t\t\terr error\n\n") + + g.w("\t\t\tstash = make(map[string]interface{}, 0)\n\n") + + if (len(skipBody) < 1 || (len(skipBody) > 0 && skipBody[0] == false)) && + (t.Steps.ContainsAssertion() || t.Steps.ContainsCatch() || true) { + g.w("\t\t\tbody []byte\n") + g.w("\t\t\tmapi map[string]interface{}\n") + g.w("\t\t\tslic []interface{}\n") + } + + if t.Steps.ContainsAssertion("is_false", "is_true") { + g.w("\n\t\t\tvalue reflect.Value\n") + } + + g.w("\n") + g.w("\t\t\tassertion bool\n") + + g.w("\t\t\tactual interface{}\n") + g.w("\t\t\texpected interface{}\n") + g.w("\n") + + if t.Steps.ContainsAssertion("match", "match-regexp") { + g.w("\n\t\t\tre *regexp.Regexp\n") + g.w("\t\t\tmatch bool\n") + } + + g.w("\t\t)\n\n") + + if (len(skipBody) < 1 || (len(skipBody) > 0 && skipBody[0] == false)) && + (t.Steps.ContainsAssertion() || t.Steps.ContainsCatch() || true) { + g.w("\t\t_ = mapi\n") + g.w("\t\t_ = slic\n") + g.w("\n") + g.w(`handleResponseBody := func(t *testing.T, res *esapi.Response) { + // Reset deserialized structures + mapi = make(map[string]interface{}) + slic = make([]interface{}, 0) + + var err error + body, err = ioutil.ReadAll(res.Body) + if err != nil { + t.Fatalf("Error reading body: %s", err) + } + res.Body.Close() + res.Body = ioutil.NopCloser(bytes.NewBuffer(body)) + + if len(body) < 1 { + // FIXME: Hack to prevent EOF errors + return + } + + if len(res.Header) > 0 { + if strings.Contains(res.Header["Content-Type"][0], "text/plain") { + return + } + + if strings.Contains(res.Header["Content-Type"][0], "yaml") { + if strings.HasPrefix(string(body), "---\n-") { + if err := encyaml.NewDecoder(res.Body).Decode(&slic); err != nil { + t.Fatalf("Error parsing the response body: %s", err) + } + } else { + if err := encyaml.NewDecoder(res.Body).Decode(&mapi); err != nil { + t.Fatalf("Error parsing the response body: %s", err) + } + } + return + } + } + + d := encjson.NewDecoder(res.Body) + d.UseNumber() + + if strings.HasPrefix(string(body), "[") { + if err := d.Decode(&slic); err != nil { + t.Fatalf("Error parsing the response body: %s", err) + } + } else { + if err := d.Decode(&mapi); err != nil { + t.Fatalf("Error parsing the response body: %s", err) + } + } + }` + "\n") + } + + g.w("\n") + + g.w("\t\t_ = stash\n") + + if t.Steps.ContainsAssertion("is_false", "is_true") { + g.w("\t\t_ = value\n") + } + + g.w("\t\t_ = assertion\n") + + g.w("\t\t_ = actual\n") + g.w("\t\t_ = expected\n") + + if t.Steps.ContainsAssertion("match", "match-regexp") { + g.w("\n") + g.w("\t\t_ = re\n") + g.w("\t\t_ = match\n") + } + + g.w("\n") +} + +func (g *Generator) genAction(a Action, skipBody ...bool) { + // Initialize the request + g.w("\t\treq = esapi." + a.Request() + "{\n") + + // Pass the parameters + for k, v := range a.Params() { + // fmt.Printf("%s.%s: <%T> %v\n", a.Request(), k, v, v) + + if strings.HasPrefix(fmt.Sprintf("%s", v), "$") { + v = `stash[` + strconv.Quote(fmt.Sprintf("%s", v)) + `]` + } + + switch v.(type) { + case bool: + g.w("\t\t\t" + k + ": ") + + typ, ok := apiRegistry[a.Request()][k] + if !ok { + panic(fmt.Sprintf("%s.%s: field not found", a.Request(), k)) + } + + switch typ { + case "bool": + g.w(strconv.FormatBool(v.(bool))) + case "*bool": + g.w(`esapi.BoolPtr(` + strconv.FormatBool(v.(bool)) + `)`) + case "string": + g.w(`"` + strconv.FormatBool(v.(bool)) + `"`) + case "[]string": + // TODO: Listify + g.w(`[]string{"` + strconv.FormatBool(v.(bool)) + `"}`) + default: + g.w(strconv.FormatBool(v.(bool))) + } + g.w(",\n") + + case string: + if k == "Body" { + g.w("\t\t\t" + k + ": ") + body := v.(string) + if !strings.HasSuffix(body, "\n") { + body = body + "\n" + } + g.w("strings.NewReader(`" + body + "`)") + } else { + g.w("\t\t\t" + k + ": ") + // TODO: Handle comma separated strings as lists + + // fmt.Printf("%s: %#v\n", a.Request(), apiRegistry[a.Request()]) + // fmt.Printf("%s: %#v\n", k, apiRegistry[a.Request()][k]) + typ, ok := apiRegistry[a.Request()][k] + if !ok { + panic(fmt.Sprintf("%s.%s: field not found", a.Request(), k)) + } + + var value string + if strings.HasPrefix(v.(string), "stash[") { + switch typ { + case "bool": + value = `fmt.Sprintf("%v", ` + v.(string) + `)` + case "string": + value = fmt.Sprintf("%s.(string)", v) + case "[]string": + // TODO: Comma-separated list => Quoted list + value = fmt.Sprintf(`[]string{%s.(string)}`, v) + case "int": + value = `func() int { + switch ` + v.(string) + `.(type) { + case int: + return ` + v.(string) + `.(int) + case float64: + return int(` + v.(string) + `.(float64)) + } + case json.Number: + v, _ := ` + v.(string) + `.(encjson.Number).Int64() + vv := int(v) + return vv + panic(fmt.Sprintf(` + "`" + `Unexpected type %T for ` + v.(string) + "`" + `, ` + v.(string) + `)) + }()` + case "*int": + value = `func() *int { + switch ` + v.(string) + `.(type) { + case int: + v := ` + v.(string) + `.(int) + return &v + case float64: + v := int(` + v.(string) + `.(float64)) + return &v + case json.Number: + v, _ := ` + v.(string) + `.(encjson.Number).Int64() + vv := int(v) + return &vv + } + panic(fmt.Sprintf(` + "`" + `Unexpected type %T for ` + v.(string) + "`" + `, ` + v.(string) + `)) + }()` + case "time.Duration": + value = `fmt.Sprintf("%d", ` + v.(string) + `)` + default: + panic(fmt.Sprintf("Unexpected type %q for value %v", typ, v)) + } + } else { + switch typ { + case "[]string": + value = `[]string{` + fmt.Sprintf("%q", v) + `}` + case "time.Duration": + // re := regexp.MustCompile("^(\\d+).*") + // value = re.ReplaceAllString(fmt.Sprintf("%s", v), "$1") + inputValue := v.(string) + if strings.HasSuffix(inputValue, "d") { + inputValue = inputValue[:len(inputValue)-1] + numericValue, err := strconv.Atoi(inputValue) + if err != nil { + panic(fmt.Sprintf("Cannot convert duration [%s]: %s", inputValue, err)) + } + // Convert to hours + inputValue = fmt.Sprintf("%dh", numericValue*24) + } + + dur, err := time.ParseDuration(inputValue) + if err != nil { + panic(fmt.Sprintf("Cannot parse duration [%s]: %s", v, err)) + } + value = fmt.Sprintf("%d", dur.Nanoseconds()) + default: + if strings.HasSuffix(k, "ID") { + value = fmt.Sprintf("url.QueryEscape(%q)", v) + } else { + value = fmt.Sprintf("%q", v) + } + + } + } + g.w(value) + } + g.w(",\n") + + case int, *int, float64: + g.w("\t\t\t" + k + ": ") + + typ, ok := apiRegistry[a.Request()][k] + if !ok { + panic(fmt.Sprintf("%s.%s: field not found", a.Request(), k)) + } + + var value string + switch typ { + case "string": + value = `"` + fmt.Sprintf("%d", v) + `"` + case "[]string": + value = `[]string{"` + fmt.Sprintf("%d", v) + `"}` + case "time.Duration": + re := regexp.MustCompile("^(\\d+).*") + value = re.ReplaceAllString(fmt.Sprintf("%d", v), "$1") + case "*int": + g.w(`esapi.IntPtr(` + fmt.Sprintf("%d", v) + `)`) + default: + value = fmt.Sprintf("%v", v) + } + g.w(value) + g.w(",\n") + + case []interface{}: + g.w("\t\t\t" + k + ": ") + + typ, ok := apiRegistry[a.Request()][k] + if !ok { + panic(fmt.Sprintf("%s.%s: field not found", a.Request(), k)) + } + + switch typ { + case "string": + switch v.(type) { + case string: + g.w("`" + v.(string) + "`") + case []interface{}: + vvv := make([]string, 0) + for _, vv := range v.([]interface{}) { + vvv = append(vvv, fmt.Sprintf("%s", vv)) + } + g.w("`" + strings.Join(vvv, ",") + "`") + default: + panic(fmt.Sprintf("<%s> %s{}.%s: unexpected value <%T> %#v", typ, a.Request(), k, v, v)) + } + case "[]string": + qv := make([]string, 0) + for _, vv := range v.([]interface{}) { + // TODO: Check type + qv = append(qv, fmt.Sprintf("%q", vv.(string))) + } + g.w(`[]string{` + strings.Join(qv, ",") + `}`) + case "io.Reader": + // Serialize Bulk payloads ... + if k == "Body" { + var b strings.Builder + for _, vv := range v.([]interface{}) { + switch vv.(type) { + case string: + b.WriteString(vv.(string)) + default: + j, err := json.Marshal(convert(vv)) + if err != nil { + panic(fmt.Sprintf("%s{}.%s: %s (%s)", a.Request(), k, err, v)) + } + b.WriteString(string(j)) + } + b.WriteString("\n") + } + b.WriteString("\n") + g.w("\t\tstrings.NewReader(`" + b.String() + "`)") + // ... or just convert the value to JSON + } else { + j, err := json.Marshal(convert(v)) + if err != nil { + panic(fmt.Sprintf("%s{}.%s: %s (%s)", a.Request(), k, err, v)) + } + g.w("\t\tstrings.NewReader(`" + fmt.Sprintf("%s", j) + "`)") + } + } + g.w(",\n") + + case map[interface{}]interface{}: + g.w("\t\t\t" + k + ": ") + // vv := unstash(convert(v).(map[string]interface{})) + // fmt.Println(vv) + j, err := json.Marshal(convert(v)) + if err != nil { + panic(fmt.Sprintf("JSON parse error: %s; %s", err, v)) + } else { + // Unstash values + reStash := regexp.MustCompile(`("\$[^"]+")`) + j = reStash.ReplaceAll(j, []byte("` + strconv.Quote(fmt.Sprintf(\"%v\", stash[$1])) + `")) + + g.w("\t\tstrings.NewReader(`" + fmt.Sprintf("%s", j) + "`)") + g.w(",\n") + } + + default: + g.w(fmt.Sprintf("\t\t// TODO: %s (%v)\n", k, v)) + } + } + + if len(a.headers) > 0 { + if strings.Contains(a.headers["Accept"], "yaml") && strings.HasPrefix(a.Request(), "Cat") { + g.w("\t\t" + `Format: "yaml",` + "\n") + } + if auth_header, ok := a.headers["Authorization"]; ok { + auth_fields := strings.Split(auth_header, " ") + auth_name := auth_fields[0] + auth_value := auth_fields[1] + if strings.HasPrefix(auth_value, "$") { + auth_value = `fmt.Sprintf("%s", stash["` + strings.ReplaceAll(strings.ReplaceAll(auth_value, "{", ""), "}", "") + `"])` + } else { + auth_value = `"` + auth_value + `"` + } + g.w("\t\t" + `Header: http.Header{` + "\n") + g.w("\t\t\t" + `"Authorization": []string{"` + auth_name + ` " + ` + auth_value + `},` + "\n") + g.w("\t\t" + `},` + "\n") + } + } + + g.w("\t\t}\n\n") + + // Get response + g.w("\t\tres, err = req.Do(context.Background(), es)\n") + + g.w(` if err != nil { + t.Fatalf("ERROR: %s", err) + } + defer res.Body.Close() + `) + + g.w("\n\n") + + if len(a.catch) < 1 { + // Handle error responses + g.w(` handleResponseError(t, res)` + "\n") + } else { + // TODO: Test catch + } + + if len(skipBody) < 1 || (len(skipBody) > 0 && skipBody[0] == false) { + // Read and parse the body + g.w(` handleResponseBody(t, res)` + "\n") + } +} + +func (g *Generator) genAssertion(a Assertion) { + g.w(a.Condition()) + g.w(a.Error() + "\n") + g.w("}\n") // Close the condition +} + +func (g *Generator) genStashSet(s Stash) { + g.w(fmt.Sprintf("// Set %q\n", s.Key())) + + value := s.Value() + if strings.HasPrefix(value, `mapi["#`) { + switch { + case strings.HasPrefix(value, `mapi["#base64EncodeCredentials`): + i, j := strings.Index(value, "("), strings.Index(value, ")") + values := strings.Split(value[i+1:j], ",") + value = `base64.StdEncoding.EncodeToString([]byte(` + value += `strings.Join([]string{` + for n, v := range values { + value += `mapi["` + v + `"].(string)` + if n < len(values)-1 { + value += "," + } + } + value += `}, ":")` + value += `))` + default: + panic(fmt.Sprintf("Unknown transformation: %s", value)) + } + } + + g.w(fmt.Sprintf("stash[%q] = %s\n", s.Key(), value)) +} + +func convert(i interface{}) interface{} { + switch x := i.(type) { + case map[interface{}]interface{}: + m2 := map[string]interface{}{} + for k, v := range x { + var ks string + switch k.(type) { + case string: + ks = k.(string) + case int: + ks = fmt.Sprintf("%d", k) + default: + ks = fmt.Sprintf("%v", k) + } + m2[ks] = convert(v) + } + return m2 + case []interface{}: + for i, v := range x { + x[i] = convert(v) + } + } + return i +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/model.go b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/model.go new file mode 100644 index 00000000000..b76779f435c --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/model.go @@ -0,0 +1,897 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package gentests + +import ( + "bytes" + "fmt" + "os" + "path/filepath" + "regexp" + "strconv" + "strings" + + "github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils" +) + +var reFilename = regexp.MustCompile(`\d*_?(.+)\.ya?ml`) +var reNumber = regexp.MustCompile(`^\d+$`) + +// TestPayload represents a single raw section (`---`) from the YAML file. +// +type TestPayload struct { + Filepath string + Payload interface{} +} + +// TestSuite represents a group of tests (a "section") in one file. +// +type TestSuite struct { + Dir string + Filepath string + Skip bool + SkipInfo string + Type string + + Setup []Action + Teardown []Action + + Tests []Test +} + +// Test represents a single named test. +// +type Test struct { + Name string + Filepath string + OrigName string + + Skip bool + SkipInfo string + + Setup []Action + Teardown []Action + + Steps Steps +} + +// Steps represents the test steps. +type Steps []Step + +// Step represents an Action or an Assertion. +// +type Step interface{} + +// Action represents an API action (`do`). +// +type Action struct { + payload interface{} + + method string + params map[interface{}]interface{} + catch string + headers map[string]string +} + +// Assertion represents a test assertion (`is_true`, `match`, etc). +// +type Assertion struct { + payload interface{} + + operation string +} + +// Stash represents the registry for `set` operations. +// +type Stash struct { + payload interface{} +} + +// NewTestSuite returns a test group from the payloads. +// +func NewTestSuite(fpath string, payloads []TestPayload) TestSuite { + ts := TestSuite{ + Dir: strings.Title(filepath.Base(filepath.Dir(fpath))), + Filepath: fpath, + } + + if strings.Contains(fpath, "x-pack") { + ts.Type = "xpack" + } + if ts.Type == "" { + ts.Type = "core" + } + + for _, payload := range payloads { + sec_keys := utils.MapKeys(payload.Payload) + switch { + case len(sec_keys) == 1 && sec_keys[0] == "setup": + for _, v := range payload.Payload.(map[interface{}]interface{}) { + for _, vv := range v.([]interface{}) { + for k, vvv := range vv.(map[interface{}]interface{}) { + if k == "do" { + ts.Setup = append(ts.Setup, NewAction(vvv)) + } + // TODO: Handle skip in setup, eg. indices.get_mapping/10_basic.yml + } + } + } + case len(sec_keys) == 1 && sec_keys[0] == "teardown": + for _, v := range payload.Payload.(map[interface{}]interface{}) { + for _, vv := range v.([]interface{}) { + for _, vvv := range vv.(map[interface{}]interface{}) { + ts.Teardown = append(ts.Teardown, NewAction(vvv)) + } + } + } + default: + for k, v := range payload.Payload.(map[interface{}]interface{}) { + var t Test + var steps []Step + + for _, vv := range v.([]interface{}) { + switch utils.MapKeys(vv)[0] { + case "skip": + var ( + ok bool + skip_v string + skip_r string + ) + + skip := vv.(map[interface{}]interface{})["skip"] + + if skip_v, ok = skip.(map[interface{}]interface{})["version"].(string); ok { + if skip_rr, ok := skip.(map[interface{}]interface{})["reason"].(string); ok { + skip_r = skip_rr + } + if skip_v == "all" { + t.Skip = true + t.SkipInfo = "Skipping all versions" + break + } + if ts.SkipEsVersion(skip_v) { + // fmt.Printf("Skip: %q, EsVersion: %s, Skip: %v, Reason: %s\n", skip_v, EsVersion, ts.SkipEsVersion(skip_v), skip_r) + t.Skip = true + t.SkipInfo = skip_r + } + } + case "setup": + for _, vvv := range vv.(map[interface{}]interface{}) { + for _, vvvv := range vvv.([]interface{}) { + t.Setup = append(t.Setup, NewAction(vvvv.(map[interface{}]interface{})["do"])) + } + } + case "teardown": + for _, vvv := range vv.(map[interface{}]interface{}) { + for _, vvvv := range vvv.([]interface{}) { + t.Teardown = append(t.Teardown, NewAction(vvvv.(map[interface{}]interface{})["do"])) + } + } + case "set": + for _, vvv := range vv.(map[interface{}]interface{}) { + steps = append(steps, NewStash(vvv)) + } + case "transform_and_set": + for _, vvv := range vv.(map[interface{}]interface{}) { + // NOTE: `set_and_transform` has flipped ordering of key and value, compared to `set` + key := utils.MapValues(vvv)[0] + val := utils.MapKeys(vvv)[0] + payload := make(map[interface{}]interface{}) + payload[key] = val + // fmt.Println(payload) + steps = append(steps, NewStash(payload)) + } + case "do": + for _, vvv := range vv.(map[interface{}]interface{}) { + steps = append(steps, NewAction(vvv)) + } + case "is_true", "is_false", "match", "lt", "gt", "lte", "gte": + for kkk, vvv := range vv.(map[interface{}]interface{}) { + steps = append(steps, NewAssertion(kkk.(string), vvv)) + } + // TODO: "length" operator + } + } + + if !ts.Skip { + t.Name = strings.ReplaceAll(k.(string), `"`, `'`) + t.Filepath = payload.Filepath + t.OrigName = k.(string) + t.Steps = steps + + ts.Tests = append(ts.Tests, t) + } + } + } + } + + return ts +} + +// NewAction returns a new action from the payload. +// +func NewAction(payload interface{}) Action { + defer func() { + if r := recover(); r != nil { + fmt.Fprintf(os.Stderr, "Error: %v\n", r) + fmt.Fprintf(os.Stderr, "Payload: %v\n", payload) + } + }() + + var a Action + a.payload = payload + a.headers = make(map[string]string) + + for k, v := range payload.(map[interface{}]interface{}) { + switch k { + case "catch": + a.catch = v.(string) + case "warnings": + // TODO + case "headers": + for kk, vv := range v.(map[interface{}]interface{}) { + a.headers[kk.(string)] = vv.(string) + } + default: + a.method = k.(string) + a.params = v.(map[interface{}]interface{}) + } + } + + return a +} + +// NewAssertion returns a new assertion from the payload. +// +func NewAssertion(operation string, payload interface{}) Assertion { + return Assertion{operation: operation, payload: payload} +} + +// NewStash returns a new stash from the payload. +// +func NewStash(payload interface{}) Stash { + return Stash{payload: payload} +} + +// Name returns a human name for the test suite. +// +func (ts TestSuite) Name() string { + var b strings.Builder + for _, v := range strings.Split(ts.Dir, ".") { + b.WriteString(strings.Title(v)) + } + + bname := reFilename.ReplaceAllString(filepath.Base(ts.Filepath), "$1") + for _, v := range strings.Split(bname, "_") { + b.WriteString(strings.Title(v)) + } + return strings.ReplaceAll(b.String(), "-", "") +} + +// Filename returns a suitable filename for the test suite. +// +func (ts TestSuite) Filename() string { + var b strings.Builder + + if ts.Type == "xpack" { + b.WriteString("xpack_") + } + + b.WriteString(strings.ToLower(strings.Replace(ts.Dir, ".", "_", -1))) + b.WriteString("__") + + bname := reFilename.ReplaceAllString(filepath.Base(ts.Filepath), "$1") + b.WriteString(strings.ToLower(bname)) + + return b.String() +} + +// SkipEsVersion returns true if the test suite should be skipped. +// +func (ts TestSuite) SkipEsVersion(minmax string) bool { + return skipVersion(minmax) +} + +// BaseFilename extracts and returns the test filename in form of `foo/bar/10_qux.yml`. +// +func (t Test) BaseFilename() string { + parts := strings.Split(t.Filepath, "rest-api-spec/test") + if len(parts) < 1 { + panic(fmt.Sprintf("Unexpected parts for path [%s]: %s", t.Filepath, parts)) + } + return strings.TrimPrefix(parts[1], string(filepath.Separator)) +} + +// SkipEsVersion returns true if the test should be skipped. +// +func (t Test) SkipEsVersion(minmax string) bool { + return skipVersion(minmax) +} + +// ContainsAssertion returns true when the set of steps +// contain an assertion, or a specific assertion. +// +func (s Steps) ContainsAssertion(keys ...string) bool { + for _, step := range s { + if a, ok := step.(Assertion); ok { + // No keys, any assertion matches + if len(keys) < 1 { + return true + } + for _, key := range keys { + // Operation matches the key + if a.operation == key { + return true + } + if a.operation == "match" && key == "match-regexp" { + // Does any value look like a regexp? + val := utils.MapValues(a.payload)[0] + if val, ok := val.(string); ok { + if strings.HasPrefix(val, "/") { + return true + } + } + } + } + } + } + return false +} + +// ContainsCatch returns true when the set of steps contains the "catch" clause. +// +func (s Steps) ContainsCatch(keys ...string) bool { + for _, step := range s { + if a, ok := step.(Action); ok { + if a.catch != "" { + return true + } + } + } + return false +} + +// ContainsStash returns true when the set of steps contains the "set" clause. +// +func (s Steps) ContainsStash(keys ...string) bool { + for _, step := range s { + if _, ok := step.(Stash); ok { + return true + } + } + return false +} + +// Method returns the API method name for the action. +// +func (a Action) Method() string { + return utils.NameToGo(a.method) +} + +// Request returns the API request name for the action. +// +func (a Action) Request() string { + var rParts []string + parts := strings.Split(a.method, ".") + for _, p := range parts { + rParts = append(rParts, utils.NameToGo(p)) + } + return strings.Join(rParts, "") + "Request" +} + +// Params returns a map of parameters for the action. +// +func (a Action) Params() map[string]interface{} { + var kk string + out := make(map[string]interface{}) + for k, v := range a.params { + switch k.(string) { + case "context": + kk = "ScriptContext" + case "q": + kk = "Query" + case "ignore": + // TODO: Properly handle ignoring status codes + continue + default: + kk = utils.NameToGo(k.(string), utils.APIToGo(a.method)) + } + switch v.(type) { + case bool: + out[kk] = v.(bool) + case string: + out[kk] = v.(string) + case int: + out[kk] = v.(int) + case float64: + out[kk] = v.(float64) + default: + out[kk] = v + } + } + + return out +} + +// Condition returns the condition for the assertion. +// +// TODO: Evaulate https://godoc.org/github.com/google/go-cmp/cmp +// +func (a Assertion) Condition() string { + var ( + output string + + subject string + expected string + operator string + ) + + switch a.operation { + + // ================================================================================ + case "is_true": + subject = expand(a.payload.(string)) + nilGuard := catchnil(subject) + + if subject != "mapi" && subject != "slic" { + output = `if !(` + nilGuard + ") {\n" + output += `switch ` + escape(subject) + `.(type) { +case bool: + assertion = (` + escape(subject) + ` == true) +case string: + assertion = (` + escape(subject) + `.(string) != ` + `""` + `) +case int: + assertion = (` + escape(subject) + `.(int) != 0) +case float64: + assertion = (` + escape(subject) + `.(float64) != 0) +case encjson.Number: + assertion = (` + escape(subject) + `.(encjson.Number).String() != "0") +default: + assertion = (` + escape(subject) + ` != nil) +}` + "\n" + output += "} else {\n" + output += "assertion = true}\n" + output += `if !assertion` + " {\n" + } else { + // if subject == "slic" { + // output = `if fmt.Sprintf("%v", ` + subject + `) == fmt.Sprintf("%v", []interface{}{}) {` + "\n" + // } else { + // output = `if fmt.Sprintf("%v", ` + subject + `) == fmt.Sprintf("%v", map[string]interface{}{}) {` + "\n" + // } + output = `if ` + subject + ` == nil {` + "\n" + } + return output + + // ================================================================================ + case "is_false": + subject = expand(a.payload.(string)) + nilGuard := catchnil(subject) + + if subject != "mapi" && subject != "slic" { + output = `if !(` + nilGuard + ") {\n" + output += `switch ` + escape(subject) + `.(type) { +case bool: + assertion = (` + escape(subject) + ` == false) +case string: + assertion = (` + escape(subject) + `.(string) == ` + `""` + `) +case int: + assertion = (` + escape(subject) + `.(int) == 0) +case float64: + assertion = (` + escape(subject) + `.(float64) == 0) +case encjson.Number: + assertion = (` + escape(subject) + `.(encjson.Number).String() == "0") +default: + assertion = (` + escape(subject) + ` == nil) +}` + "\n" + output += "} else {\n" + output += "assertion = true}\n" + output += `if !assertion` + " {\n" + } else { + if subject == "slic" { + output = `if fmt.Sprintf("%v", ` + subject + `) != fmt.Sprintf("%v", []interface{}{}) {` + "\n" + } else { + output = `if fmt.Sprintf("%v", ` + subject + `) != fmt.Sprintf("%v", map[string]interface{}{}) {` + "\n" + } + } + return output + + // ================================================================================ + case "lt", "gt", "lte", "gte": + key := utils.MapKeys(a.payload)[0] + + subject = expand(key) + expected = fmt.Sprintf("%v", utils.MapValues(a.payload)[0]) + + nilGuard := catchnil(subject) + + // Is the value a stash value? + if strings.HasPrefix(fmt.Sprintf("%v", utils.MapValues(a.payload)[0]), "$") { + expected = `stash[` + strconv.Quote(expected) + `].(encjson.Number).Float64()` + } else { + expected = `float64(` + expected + `), struct{}{}` + } + + switch a.operation { + case "lt": + operator = "<" + case "gt": + operator = ">" + case "lte": + operator = "<=" + case "gte": + operator = ">=" + } + + r := strings.NewReplacer(`"`, "", `\`, "") + rkey := r.Replace(key) + output += ` if ` + nilGuard + ` { t.Error("Expected [` + rkey + `] to not be nil") } + actual, _ = ` + escape(subject) + `.(encjson.Number).Float64() + expected, _ = ` + expected + ` + assertion = actual.(float64) ` + operator + ` expected.(float64) + if !assertion { + t.Logf("%v != %v", actual, expected)` + "\n" + + return output + + // ================================================================================ + case "match": + var b strings.Builder + + key := utils.MapKeys(a.payload)[0] + val := utils.MapValues(a.payload)[0] + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // 1. Match on body + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + if key == "$body" { + expected = strings.TrimSpace(fmt.Sprintf("%v", val)) + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // 1a. Is the expected value a regex pattern? + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + if strings.HasPrefix(expected, "/") { + // TODO: Refactor + var pattern string + pattern = expected + + // Remove all comments + reComment := regexp.MustCompile(`#\s*[^\n]+`) + pattern = reComment.ReplaceAllString(pattern, "") + + // Remove the prefix and suffix slashes + pattern = strings.TrimPrefix(pattern, "/") + pattern = strings.TrimSuffix(pattern, "/") + + // Remove the new lines + pattern = strings.Replace(pattern, "\n", "", -1) + + // Remove whitespace (can be preceded by slash, eg. cat.templates/10_basic.yml:255) + reWhitespace := regexp.MustCompile(`\\*\s+`) + pattern = reWhitespace.ReplaceAllString(pattern, `\s*`) + + b.WriteString(`re, err = regexp.Compile("(?m)" + ` + "`" + pattern + "`" + `) + if err != nil { + t.Fatalf("Regex compile error: %s", err) + } + + match = re.Match(body)` + "\n") + b.WriteString(` if !match` + " {\n") + return b.String() + } else { + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // 1b. Is the expected value a literal value + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // TODO: Match on literal value + // output = fmt.Sprintf("if true { // TODO, MatchBodyLiteral: %s => %v\n", a.operation, a.payload) + output = `if strings.HasPrefix(string(body), "[") { + match = !reflect.DeepEqual(fmt.Sprintf("%#v", slic), ` + fmt.Sprintf("%#v", val) + `) + } else { + match = !reflect.DeepEqual(fmt.Sprintf("%#v", mapi), ` + fmt.Sprintf("%#v", val) + `) + } + if !match {` + "\n" + return output + } + + // panic(fmt.Sprintf("MatchUnknown: %q => %v\n", a.operation, a.payload)) + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // 2. Match on JSON/YAML field or numbered item + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + } else { + subject = expand(key) + expected = strings.TrimSpace(fmt.Sprintf("%v", val)) + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // 2a. Is the expected value a regex pattern? + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + if strings.HasPrefix(expected, "/") { + var pattern string + pattern = expected + pattern = strings.Replace(pattern, "/", "", -1) + pattern = strings.Replace(pattern, "\n", "", -1) + pattern = strings.Replace(pattern, " ", `\s*`, -1) + + b.WriteString(`re, err = regexp.Compile("(?m)" + ` + "`" + pattern + "`" + `) + if err != nil { + t.Fatalf("Regex compile error: %s", err) + } + + match = re.MatchString(fmt.Sprintf("%v", ` + escape(subject) + `))` + "\n") + b.WriteString(` if !match` + " {\n") + return b.String() + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // 2b. Is the value a regular value? + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + } else { + // fmt.Printf("subject: %s, val: %T, %v \n", subject, val, val) + + nilGuard := catchnil(subject) + switch val.(type) { + + // -------------------------------------------------------------------------------- + case nil: + output += ` if ` + escape(subject) + ` != nil` + " {\n" + + // -------------------------------------------------------------------------------- + case bool: + output += ` if ` + + nilGuard + + " || \n" + + `fmt.Sprintf("%v", ` + escape(subject) + `) != ` + + `fmt.Sprintf("%v", ` + expected + `)` + + " {\n" + case int, float64: + r := strings.NewReplacer(`"`, "", `\`, "") + rkey := r.Replace(key) + output += ` if ` + nilGuard + ` { t.Error("Expected [` + rkey + `] to not be nil") } + actual = ` + escape(subject) + `.(encjson.Number).String() + // TEMP: Hack to prevent 1.0 != 1 errors + actual = strings.TrimSuffix(actual.(string), ".0") + expected = ` + expected + ` + assertion = fmt.Sprintf("%v", actual) == fmt.Sprintf("%v", expected) + if !assertion { + t.Logf("%v != %v", actual, expected)` + "\n" + + // -------------------------------------------------------------------------------- + case string: + output += ` if ` + + nilGuard + + " || \n" + + `fmt.Sprintf("%s", ` + escape(subject) + `) != ` + if strings.HasPrefix(expected, "$") { + output += `fmt.Sprintf("%s", ` + `stash["` + expected + `"]` + `)` + } else { + output += `fmt.Sprintf("%s", ` + strconv.Quote(expected) + `)` + } + output += " {\n" + + // -------------------------------------------------------------------------------- + case map[interface{}]interface{}, map[string]interface{}: + expectedPayload := fmt.Sprintf("%#v", val) + expectedPayload = strings.ReplaceAll(expectedPayload, "map[interface {}]interface {}", "map[string]interface {}") + output = ` actual, _ = encjson.Marshal(` + escape(subject) + `) + expected, _ = encjson.Marshal(` + expectedPayload + `) + if fmt.Sprintf("%s", actual) != fmt.Sprintf("%s", expected) {` + "\n" + + // -------------------------------------------------------------------------------- + case []interface{}: + expectedPayload := fmt.Sprintf("%#v", val) + expectedPayload = strings.ReplaceAll(expectedPayload, "map[interface {}]interface {}", "map[string]interface {}") + output = ` actual, _ = encjson.Marshal(` + escape(subject) + `) + expected, _ = encjson.Marshal(` + expectedPayload + `) + if fmt.Sprintf("%s", actual) != fmt.Sprintf("%s", expected) {` + "\n" + + // -------------------------------------------------------------------------------- + default: + output += ` if true { // TODO, MatchMissingType: ` + fmt.Sprintf("<%[1]T>%[1]v", val) + "\n" + output += ` // Subject: ` + subject + "\n" + output += ` // Value: ` + fmt.Sprintf("%#v", val) + "\n" + } + + return output + } + } + + // ================================================================================ + default: + return fmt.Sprintf("if true { // TODO, Unimplemented: %q => %v\n", a.operation, a.payload) + } + + // panic(fmt.Sprintf("Unreachable: %q => %v", a.operation, a.payload)) +} + +// Error returns an error handling for the failed assertion. +// +func (a Assertion) Error() string { + var ( + output string + + subject string + expected string + ) + + output = `Unexpected value; <` + a.operation + `> : ` + fmt.Sprintf("%s", escape(a.payload)) + + switch a.operation { + case "is_true": + subject = expand(a.payload.(string)) + output = `Expected ` + escape(subject) + ` to be truthy` + + case "is_false": + subject = expand(a.payload.(string)) + output = `Expected ` + escape(subject) + ` to be falsey` + + case "lt", "gt", "lte", "gte": + subject = expand(utils.MapKeys(a.payload)[0]) + expected = fmt.Sprintf("%v", utils.MapValues(a.payload)[0]) + output = `Expected ` + escape(utils.MapKeys(a.payload)[0]) + ` ` + a.operation + ` ` + escape(expected) + + case "length": + panic(fmt.Sprintf("TODO: length: %s", a.payload)) + + case "match": + key := utils.MapKeys(a.payload)[0] + val := utils.MapValues(a.payload)[0] + + expected := strings.TrimSpace(fmt.Sprintf("%v", val)) + + if key == "$body" { // 1. Match on body + + if strings.HasPrefix(expected, "/") { + return `t.Errorf("Expected [$body] to match pattern: %s", re)` + } else { + output = `Expected [$body] to match value: ` + escape(expected) + } + + } else { // 2. Match on JSON/YAML field or numbered item + if key == "" { + key = "response" + } + + if strings.HasPrefix(expected, "/") { // 2a. Is the value to match a regex? + expected = strings.Replace(expected, "\n", "
", -1) + expected = strings.Replace(expected, `/`, `|`, -1) + + return `t.Errorf("Expected [` + strings.Trim(strconv.Quote(escape(key)), `"`) + `] to match pattern: %s", re)` + } else { // 2b. Is the value to match a regular value? + output = `Expected [` + strings.Trim(strconv.Quote(escape(key)), `"`) + `] to match '` + escape(expected) + `'` + } + } + } + + return `t.Error(` + strconv.Quote(output) + `)` +} + +// Key returns the stash key as a string. +// +func (s Stash) Key() string { + vals := utils.MapValues(s.payload) + if len(vals) < 1 { + return "" + } + + return fmt.Sprintf("$%s", vals[0]) +} + +// Value returns the stash value as a string. +// +func (s Stash) Value() string { + vals := utils.MapKeys(s.payload) + if len(vals) < 1 { + return "" + } + + return expand(fmt.Sprintf("%v", vals[0])) +} + +// expand "unwraps" a field name like `foo.bar.0.baz` into a proper Go structure +// +// See https://github.com/elastic/elasticsearch/tree/master/rest-api-spec/src/main/resources/rest-api-spec/test#dot-notation +// +func expand(s string, format ...string) string { + var ( + b bytes.Buffer + + container string + ) + + // Handle the "literal dot" in a fieldname + s = strings.Replace(s, `\.`, `_~_|_~_`, -1) + + parts := strings.Split(s, ".") + + if len(parts) > 0 { + if reNumber.MatchString(parts[0]) { + container = "slic" + } else { + container = "mapi" + } + } else { + container = "mapi" + } + + b.WriteString(container) + + if len(parts) > 0 && parts[0] == "" { + return b.String() + } + + for i, v := range parts { + if reNumber.MatchString(v) { + if i > 0 { + b.WriteString(`.([]interface{})`) + } + b.WriteString(`[`) + b.WriteString(v) + b.WriteString(`]`) + } else { + if i > 0 { + if len(format) > 0 && format[0] == "yaml" { + b.WriteString(`.(map[interface{}]interface{})`) + } else { + b.WriteString(`.(map[string]interface{})`) + } + } + b.WriteString(`["`) + b.WriteString(strings.Trim(v, `"`)) // Remove the quotes from keys + b.WriteString(`"]`) + } + + } + return strings.Replace(b.String(), `_~_|_~_`, `\.`, -1) +} + +// catchnil returns a condition which expands the input and checks if any part is not nil. +// +func catchnil(input string) string { + var output string + + parts := strings.Split(strings.Replace(input, `\.`, `_~_|_~_`, -1), ".") + for i := range parts { + output += strings.Join(parts[:i+1], ".") + " == nil" + if i+1 < len(parts) { + output += " ||\n\t\t" + } + } + output = strings.Replace(output, `_~_|_~_`, `.`, -1) + + return output +} + +// escape replaces unsafe characters in strings +// +func escape(s interface{}) string { + if s, ok := s.(string); ok { + // s = strings.Replace(s, `"`, `'`, -1) + // s = strings.Replace(s, `\`, `\\`, -1) + s = strings.Replace(s, `\.`, `.`, -1) + return s + } + return fmt.Sprintf("%s", s) +} + +// skipVersion parses minmax string and returns +// true when EsVersion is in the range. +// +func skipVersion(minmax string) bool { + versions := strings.Split(minmax, "-") + if len(versions) < 2 { + panic(fmt.Sprintf("skipVersion: Unexpected input: %q", minmax)) + } + + min, max := strings.TrimSpace(versions[0]), strings.TrimSpace(versions[1]) + + if max == "" { // Skip when max version is not set + return true + } + + if EsVersion >= min && EsVersion <= max { + return true + } + + return false +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/patches.go b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/patches.go new file mode 100644 index 00000000000..2ab61cc8288 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/patches.go @@ -0,0 +1,54 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package gentests + +import ( + "bytes" + "io" + "io/ioutil" + "regexp" + "strings" +) + +var ( + rePatchShardKeys = regexp.MustCompile(`shards\.(\d+)\.(\d+)`) + rePatchShardStoresKeys = regexp.MustCompile(`shards\.(\d+)\.stores\.(\d+)`) + rePatchBucketKeys = regexp.MustCompile(`aggregations.(\d+).(\d+).buckets`) +) + +// PatchTestSource performs a regex based patching of the input. +// +func PatchTestSource(fpath string, r io.Reader) (io.Reader, error) { + c, err := ioutil.ReadAll(r) + if err != nil { + return nil, err + } + + // Patch the path to a shard by adding quotes around the shard number, + // which is a map key, not an array index. + for _, p := range []string{ + "indices.flush/10_basic.yml", + "indices.put_template/10_basic.yml", + "indices.recovery/10_basic.yml", + "indices.segments/10_basic.yml", + "indices.shard_stores/10_basic.yml", + "indices.stats/12_level.yml", + } { + if strings.Contains(fpath, p) { + c = rePatchShardKeys.ReplaceAll(c, []byte(`shards."$1".$2`)) + c = rePatchShardStoresKeys.ReplaceAll(c, []byte(`shards."$1".stores.$2`)) + } + } + + for _, p := range []string{ + "search.aggregation/230_composite.yml", + } { + if strings.Contains(fpath, p) { + c = rePatchBucketKeys.ReplaceAll(c, []byte(`aggregations."$1"."$2".buckets`)) + } + } + + return bytes.NewReader(c), nil +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/skips.go b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/skips.go new file mode 100644 index 00000000000..7b6535b214a --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/skips.go @@ -0,0 +1,218 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package gentests + +import ( + "fmt" + "strings" + + "gopkg.in/yaml.v2" +) + +var skipTests map[string][]string + +func init() { + err := yaml.NewDecoder(strings.NewReader(skipTestsYAML)).Decode(&skipTests) + if err != nil { + panic(fmt.Sprintf("ERROR: %v", err)) + } +} + +var skipFiles = []string{ + "update/85_fields_meta.yml", // Uses non-existing API property + "update/86_fields_meta_with_types.yml", // --||-- + + "ml/jobs_get_result_buckets.yml", // Passes string value to int variable + "ml/jobs_get_result_categories.yml", // --||-- + "ml/set_upgrade_mode.yml", // --||-- + + "ml/evaluate_data_frame.yml", // Floats as map keys + + "watcher/stats/10_basic.yml", // Sets "emit_stacktraces" as string ("true"), not bool +} + +// TODO: Comments into descriptions for `Skip()` +// +var skipTestsYAML = ` +--- +# Cannot distinguish between missing value for refresh and an empty string +bulk/50_refresh.yml: + - refresh=empty string immediately makes changes are visible in search +bulk/51_refresh_with_types.yml: + - refresh=empty string immediately makes changes are visible in search +create/60_refresh.yml: + - When refresh url parameter is an empty string that means "refresh immediately" +create/61_refresh_with_types.yml: + - When refresh url parameter is an empty string that means "refresh immediately" +delete/50_refresh.yml: + - When refresh url parameter is an empty string that means "refresh immediately" +delete/51_refresh_with_types.yml: + - When refresh url parameter is an empty string that means "refresh immediately" +index/60_refresh.yml: + - When refresh url parameter is an empty string that means "refresh immediately" +index/61_refresh_with_types.yml: + - When refresh url parameter is an empty string that means "refresh immediately" +update/60_refresh.yml: + - When refresh url parameter is an empty string that means "refresh immediately" +update/61_refresh_with_types.yml: + - When refresh url parameter is an empty string that means "refresh immediately" + +# Stash in value +cluster.reroute/11_explain.yml: +nodes.info/30_settings.yml: +nodes.stats/20_response_filtering.yml: +nodes.stats/30_discovery.yml: + - Discovery stats +nodes.discovery/30_discovery.yml: + - Discovery stats + +# Arbitrary key +indices.shrink/10_basic.yml: +indices.shrink/20_source_mapping.yml: +indices.shrink/30_copy_settings.yml: +indices.split/30_copy_settings.yml: + +# Parsed response is YAML: value is map[interface {}]interface {}, not map[string]interface {} +cat.aliases/20_headers.yml: + - Simple alias with yaml body through Accept header + +# Incorrect int instead of float in match (aggregations.date_range.buckets.0.from: 1000000); TODO: PR +search.aggregation/40_range.yml: + - Date range + +# No support for headers per request yet +tasks.list/10_basic.yml: + - tasks_list headers + +# Node Selector feature not implemented +cat.aliases/10_basic.yml: + - "Help (pre 7.4.0)" + - "Simple alias (pre 7.4.0)" + - "Complex alias (pre 7.4.0)" + - "Column headers (pre 7.4.0)" + - "Alias against closed index (pre 7.4.0)" + +indices.put_mapping/10_basic.yml: + - "Put mappings with explicit _doc type bwc" + +# Not relevant +search/issue4895.yml: +search/issue9606.yml: + +# FIXME +bulk/80_cas.yml: +bulk/81_cas_with_types.yml: + +# ----- X-Pack ---------------------------------------------------------------- + +# Stash in body +api_key/10_basic.yml: + - Test invalidate api key +rollup/put_job.yml: + - Test put job with templates + +# Changing password locks out tests +change_password/10_basic.yml: + - Test user changing their own password + +# Missing refreshes in the test +data_frame/transforms_start_stop.yml: +ml/index_layout.yml: +transform/transforms_start_stop.yml: + - Verify start transform reuses destination index +transform/transforms_start_stop.yml: + - Test get multiple transform stats +transform/transforms_stats.yml: + - Test get multiple transform stats + - Test get multiple transform stats where one does not have a task + +# More QA tests than API tests +data_frame/transforms_stats.yml: + - Test get multiple transform stats + - Test get transform stats on missing transform + - Test get multiple transform stats where one does not have a task +ml/jobs_crud.yml: + - Test reopen job resets the finished time + +# Invalid license makes subsequent tests fail +license/20_put_license.yml: + +# Test tries to match on map from body, but Go keys are not sorted +ml/jobs_crud.yml: + - Test job with rules + - Test put job with model_memory_limit as number + - Test put job with model_memory_limit as string and lazy open + +# Test gets stuck every time +ml/jobs_get_stats.yml: + +# status_exception, Cannot process data because job [post-data-job] does not have a corresponding autodetect process +# resource_already_exists_exception, task with id {job-post-data-job} already exist +# status_exception, Cannot open job [start-stop-datafeed-job-foo-1] because it has already been opened +ml/post_data.yml: + - Test flush with skip_time + - Test POST data job api, flush, close and verify DataCounts doc + - Test flush and close job WITHOUT sending any data +ml/start_stop_datafeed.yml: + - Test stop given expression +transform/transforms_start_stop.yml: + - Test start transform + - Verify start transform reuses destination index + +# Possible bad test setup, Cannot open job [start-stop-datafeed-job] because it has already been opened +# resource_already_exists_exception, task with id {job-start-stop-datafeed-job-foo-2} already exist +ml/start_stop_datafeed.yml: + - Test start datafeed when persistent task allocation disabled + +# Indexing step doesn't appear to work (getting total.hits=0) +monitoring/bulk/10_basic.yml: + - Bulk indexing of monitoring data on closed indices should throw an export exception +# Indexing step doesn't appear to work (getting total.hits=0) +monitoring/bulk/20_privileges.yml: + - Monitoring Bulk API + +# Test tries to match on whole body, but map keys are unstable in Go +rollup/security_tests.yml: + +# Test tries to match on map key, but map keys are unstable in Go +ml/data_frame_analytics_crud.yml: + - Test put with description + - Test put valid config with custom outlier detection + +# TEMPORARY: Missing 'body: { indices: "test_index" }' payload, TODO: PR +snapshot/10_basic.yml: + - Create a source only snapshot and then restore it + +# illegal_argument_exception: Provided password hash uses [NOOP] but the configured hashing algorithm is [BCRYPT] +users/10_basic.yml: + - Test put user with password hash + +# Slash in index name is not escaped (BUG) +security/authz/13_index_datemath.yml: + - Test indexing documents with datemath, when permitted + +# Possibly a cluster health color mismatch... +security/authz/14_cat_indices.yml: + +# Test looks for "testnode.crt", but "ca.crt" is returned first +ssl/10_basic.yml: + - Test get SSL certificates + +# class org.elasticsearch.xpack.vectors.query.VectorScriptDocValues$DenseVectorScriptDocValues cannot be cast to class org.elasticsearch.xpack.vectors.query.VectorScriptDocValues$SparseVectorScriptDocValues ... +vectors/30_sparse_vector_basic.yml: + - Dot Product +# java.lang.IllegalArgumentException: No field found for [my_dense_vector] in mapping +vectors/40_sparse_vector_special_cases.yml: + - Vectors of different dimensions and data types + - Dimensions can be sorted differently + - Distance functions for documents missing vector field should return 0 + +# Cannot connect to Docker IP +watcher/execute_watch/60_http_input.yml: + +# Test tries to match on "tagline", which requires "human=false", which doesn't work in the Go API. +# Also test does too much within a single test, so has to be disabled as whole, unfortunately. +xpack/15_basic.yml: +` diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/go.mod b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/go.mod new file mode 100644 index 00000000000..b7355c60db2 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/go.mod @@ -0,0 +1,16 @@ +module github.com/elastic/go-elasticsearch/v8/internal/cmd/generate + +go 1.11 + +replace github.com/elastic/go-elasticsearch/v8 => ../../../ + +require ( + github.com/alecthomas/chroma v0.6.3 + github.com/elastic/go-elasticsearch/v8 master + github.com/inconshreveable/mousetrap v1.0.0 // indirect + github.com/spf13/cobra v0.0.3 + github.com/spf13/pflag v1.0.3 // indirect + golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c + golang.org/x/tools v0.0.0-20190330180304-aef51cc3777c + gopkg.in/yaml.v2 v2.2.2 +) diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/go.sum b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/go.sum new file mode 100644 index 00000000000..5ed45fba839 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/go.sum @@ -0,0 +1,34 @@ +github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38/go.mod h1:r7bzyVFMNntcxPZXK3/+KdruV1H5KSlyVY0gc+NgInI= +github.com/alecthomas/chroma v0.6.3 h1:8H1D0yddf0mvgvO4JDBKnzLd9ERmzzAijBxnZXGV/FA= +github.com/alecthomas/chroma v0.6.3/go.mod h1:quT2EpvJNqkuPi6DmBHB+E33FXBgBBPzyH5++Dn1LPc= +github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721/go.mod h1:QO9JBoKquHd+jz9nshCh40fOfO+JzsoXy8qTHF68zU0= +github.com/alecthomas/kong v0.1.15/go.mod h1:0m2VYms8rH0qbCqVB2gvGHk74bqLIq0HXjCs5bNbNQU= +github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ= +github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 h1:y5HC9v93H5EPKqaS1UYVg1uYah5Xf51mBfIoWehClUQ= +github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964/go.mod h1:Xd9hchkHSWYkEqJwUGisez3G1QY8Ryz0sdWrLPMGjLk= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dlclark/regexp2 v1.1.6 h1:CqB4MjHw0MFCDj+PHHjiESmHX+N7t0tJzKvC6M97BRg= +github.com/dlclark/regexp2 v1.1.6/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= +github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8= +github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= +github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c h1:Vj5n4GlwjmQteupaxJ9+0FNOmBrHfq7vN4btdGoDZgI= +golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sys v0.0.0-20181128092732-4ed8d59d0b35/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190330180304-aef51cc3777c h1:hbqcUGBwEHdDbhy8EluQIkbwTIbOvaYedVBif4f2mFQ= +golang.org/x/tools v0.0.0-20190330180304-aef51cc3777c/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/main.go b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/main.go new file mode 100644 index 00000000000..465853ed36e --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/main.go @@ -0,0 +1,16 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package main + +import ( + "github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands" + _ "github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gensource" + _ "github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/genstruct" + _ "github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests" +) + +func main() { + commands.Execute() +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/chromatize.go b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/chromatize.go new file mode 100644 index 00000000000..7aba661bb87 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/chromatize.go @@ -0,0 +1,41 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package utils + +import ( + "bytes" + "io" + "io/ioutil" + + "github.com/alecthomas/chroma/formatters" + "github.com/alecthomas/chroma/lexers" + "github.com/alecthomas/chroma/styles" +) + +// Chromatize returns a syntax highlighted Go code. +// +func Chromatize(r io.Reader) (io.Reader, error) { + var b bytes.Buffer + lexer := lexers.Get("go") + + contents, err := ioutil.ReadAll(r) + if err != nil { + return nil, err + } + + it, err := lexer.Tokenise(nil, string(contents)) + if err != nil { + return nil, err + } + + style, _ := styles.Get("pygments").Builder().Build() + formatter := formatters.Get("terminal256") + err = formatter.Format(&b, style, it) + if err != nil { + return nil, err + } + + return &b, nil +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/debug.go b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/debug.go new file mode 100644 index 00000000000..1d862462497 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/debug.go @@ -0,0 +1,82 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package utils + +import ( + "bufio" + "fmt" + "go/scanner" + "go/token" + "io" + "os" + "strings" +) + +// PrintSourceWithErr returns source code annotated with location of an error. +// +func PrintSourceWithErr(out io.Reader, err error) { + if IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[2m") + } + if e, ok := err.(scanner.ErrorList); ok { + fmt.Fprintf(os.Stderr, "\x1b[2m✖ %s\n", e.Error()) + } + fmt.Fprintln(os.Stderr, strings.Repeat("━", TerminalWidth())) + if IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[0m") + } + if _, ok := err.(scanner.ErrorList); ok { + cur := 0 + ferr := err.(scanner.ErrorList) + type ParseError struct { + Pos token.Position + Msg string + } + errlines := make(map[int]ParseError) + for _, e := range ferr { + errlines[e.Pos.Line] = ParseError{Pos: e.Pos, Msg: e.Msg} + } + scanner := bufio.NewScanner(out) + for scanner.Scan() { + cur++ + + if _, ok := errlines[cur]; ok { + if IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[1;31m") + } + fmt.Fprintf(os.Stderr, "%3d| ", cur) + fmt.Fprintln(os.Stderr, scanner.Text()) + } else { + if IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[2m") + } + fmt.Fprintf(os.Stderr, "%3d| ", cur) + if IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[0m") + } + fmt.Fprintln(os.Stderr, scanner.Text()) + } + if IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[0m") + } + if e, ok := errlines[cur]; ok { + if IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[31m") + } + fmt.Fprintf(os.Stderr, strings.Repeat(" ", 4)) + for i := 0; i < e.Pos.Column; i++ { + fmt.Fprintf(os.Stderr, "-") + } + fmt.Fprintf(os.Stderr, "^ ") + fmt.Fprintf(os.Stderr, e.Msg) + fmt.Fprintf(os.Stderr, "\n") + if IsTTY() { + fmt.Fprint(os.Stderr, "\x1b[0m") + } + } + } + fmt.Fprintln(os.Stderr, "") + } +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/map.go b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/map.go new file mode 100644 index 00000000000..09a82a6b7e3 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/map.go @@ -0,0 +1,29 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package utils + +// MapKeys returns the map keys as a slice of strings. +// +func MapKeys(s interface{}) (keys []string) { + if s, ok := s.(map[interface{}]interface{}); ok { + for k := range s { + if k, ok := k.(string); ok { + keys = append(keys, k) + } + } + } + return keys +} + +// MapValues returns the map values as a slice of interfaces. +// +func MapValues(s interface{}) (values []interface{}) { + if s, ok := s.(map[interface{}]interface{}); ok { + for _, v := range s { + values = append(values, v) + } + } + return values +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/metadata.go b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/metadata.go new file mode 100644 index 00000000000..985dd6fbcca --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/metadata.go @@ -0,0 +1,110 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package utils + +import ( + "fmt" + "io/ioutil" + "os" + "os/exec" + "path/filepath" + "regexp" + "strings" +) + +var ( + reEsVersion = regexp.MustCompile(`elasticsearch\s+=\s+(\d+\.\d+\.\d+)`) +) + +// EsVersion returns the Elasticsearch from environment variable, Java property file, or an error. +// +func EsVersion(fpath string) (string, error) { + if envEsVersion := os.Getenv("ELASTICSEARCH_VERSION"); envEsVersion != "" { + return envEsVersion, nil + } + + basePath, err := basePathFromFilepath(fpath) + if err != nil { + return "", fmt.Errorf("EsVersion: %s", err) + } + + c, err := ioutil.ReadFile(filepath.Join(basePath, "buildSrc", "version.properties")) + if err != nil { + return "", fmt.Errorf("EsVersion: %s", err) + } + + m := reEsVersion.FindSubmatch(c) + if len(m) < 2 { + return "", nil + } + return string(m[1]), nil +} + +// GitCommit returns the Git commit from environment variable or parsing information from fpath, or an error. +// +func GitCommit(fpath string) (string, error) { + if gitCommitEnv := os.Getenv("ELASTICSEARCH_BUILD_HASH"); gitCommitEnv != "" { + return gitCommitEnv, nil + } + + basePath, err := basePathFromFilepath(fpath) + if err != nil { + return "", fmt.Errorf("GitCommit: %s", err) + } + + args := strings.Split("git --git-dir="+basePath+".git rev-parse --short HEAD", " ") + cmd := exec.Command(args[0:1][0], args[1:]...) + // fmt.Printf("> %s\n", strings.Join(cmd.Args, " ")) + + out, err := cmd.Output() + if err != nil { + return "", fmt.Errorf("GitCommit: %s", err) + } + return strings.TrimSpace(string(out)), nil +} + +// GitTag returns the Git tag for fpath if available, or an error. +// +func GitTag(fpath string) (string, error) { + basePath, err := basePathFromFilepath(fpath) + if err != nil { + return "", fmt.Errorf("GitCommit: %s", err) + } + + commit, err := GitCommit(fpath) + if err != nil { + return "", fmt.Errorf("GitTag: %s", err) + } + + args := strings.Split("git --git-dir="+basePath+".git tag --points-at "+commit, " ") + cmd := exec.Command(args[0:1][0], args[1:]...) + // fmt.Printf("> %s\n", strings.Join(cmd.Args, " ")) + + out, err := cmd.Output() + if err != nil { + return "", nil + } + + return strings.TrimSpace(string(out)), nil +} + +func basePathFromFilepath(fpath string) (string, error) { + var bpath strings.Builder + + fpath, err := filepath.Abs(fpath) + if err != nil { + return "", err + } + + for _, p := range strings.Split(fpath, string(filepath.Separator)) { + if p == "rest-api-spec" { + break + } + bpath.WriteString(p) + bpath.WriteRune(filepath.Separator) + } + + return bpath.String(), nil +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/naming.go b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/naming.go new file mode 100644 index 00000000000..63729603918 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/naming.go @@ -0,0 +1,126 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package utils + +import "strings" + +var ( + // Options: boolean, enum, list, number, string, time + typesToGo = map[string]string{ + "boolean": "*bool", + "enum": "string", // TODO: Custom "enum" type + "list": "[]string", + "number": "*int", + "int": "*int", + "long": "*int", + "string": "string", + "time": "time.Duration", + } +) + +// APIToGo returns the Go version of API call, eg. cluster.health => ClusterHealth +// +func APIToGo(s string) string { + ep := strings.Split(s, ".") + ns := make([]string, len(ep)) + for _, v := range ep { + m := strings.Split(v, "_") + mn := make([]string, len(m)) + for _, vv := range m { + mn = append(mn, NameToGo(vv)) + } + ns = append(ns, strings.Join(mn, "")) + } + return strings.Join(ns, "") +} + +// NameToGo returns a Go version of name, eg. node_id => NodeID. +// +func NameToGo(s string, api ...string) string { + exceptions := map[string]string{ + "index": "Index", + "id": "DocumentID", + "type": "DocumentType", + } + + acronyms := map[string]string{ + "id": "ID", + "ttl": "TTL", + + "api": "API", + "ccr": "CCR", + "ilm": "ILM", + "ml": "ML", + "sql": "SQL", + "ssl": "SSL", + "xpack": "XPack", + } + + specialMappingsForID := map[string]string{ + "DeleteScript": "ScriptID", + "GetScript": "ScriptID", + "PutScript": "ScriptID", + "IngestDeletePipeline": "PipelineID", + "IngestGetPipeline": "PipelineID", + "IngestPutPipeline": "PipelineID", + "IngestSimulate": "PipelineID", + "RenderSearchTemplate": "TemplateID", + + "MLDeleteDataFrameAnalytics": "ID", + "MLGetDataFrameAnalytics": "ID", + "MLGetDataFrameAnalyticsStats": "ID", + "MLPutDataFrameAnalytics": "ID", + "MLStartDataFrameAnalytics": "ID", + "MLStopDataFrameAnalytics": "ID", + + "RollupDeleteJob": "JobID", + "RollupGetJobs": "JobID", + "RollupGetRollupCaps": "Index", + "RollupPutJob": "JobID", + "RollupStartJob": "JobID", + "RollupStopJob": "JobID", + + "SecurityGetAPIKey": "ID", + + "WatcherDeleteWatch": "WatchID", + "WatcherExecuteWatch": "WatchID", + "WatcherGetWatch": "WatchID", + "WatcherPutWatch": "WatchID", + } + + if s == "id" && api != nil && len(api) > 0 && api[0] != "" && specialMappingsForID[api[0]] != "" { + return specialMappingsForID[api[0]] + } + + if value, ok := exceptions[s]; ok { + return value + } + + ep := strings.Split(s, "_") + ns := make([]string, len(ep)) + for _, v := range ep { + if value, ok := acronyms[v]; ok { + v = value + } + ns = append(ns, strings.Title(v)) + } + return strings.Join(ns, "") +} + +// TypeToGo returns a Go version of type, eg. boolean => *bool. +// +func TypeToGo(s string, comment ...bool) string { + // If the string contains a pipe character, it's a polymorphic parameter, + // ie. it takes heterogeous values, such as "boolean" and "number" + if strings.Contains(s, "|") { + return "interface{}" + } + + if v, ok := typesToGo[s]; ok { + return v + } + + return "interface{}" +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/strings.go b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/strings.go new file mode 100644 index 00000000000..4b2399891dd --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/strings.go @@ -0,0 +1,19 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package utils + +import ( + "regexp" +) + +var ( + reIDString = regexp.MustCompile(`\bid\b`) +) + +// IDToUpper returns a string with all occurrences of "id" capitalized. +// +func IDToUpper(s string) string { + return reIDString.ReplaceAllLiteralString(s, "ID") +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/terminal.go b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/terminal.go new file mode 100644 index 00000000000..81bb2be0202 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/utils/terminal.go @@ -0,0 +1,51 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package utils + +import ( + "fmt" + "os" + + "golang.org/x/crypto/ssh/terminal" +) + +var ( + isTTY bool + tWidth int +) + +func init() { + isTTY = terminal.IsTerminal(int(os.Stderr.Fd())) + tWidth, _, _ = terminal.GetSize(int(os.Stdout.Fd())) +} + +// PrintErr prints an error to STDERR. +// +func PrintErr(err error) { + if isTTY { + fmt.Fprint(os.Stderr, "\x1b[1;37;41m") + } + fmt.Fprintf(os.Stderr, "ERROR: %s", err) + if isTTY { + fmt.Fprint(os.Stderr, "\x1b[0m") + } + fmt.Fprint(os.Stderr, "\n") +} + +// IsTTY returns true when os.Stderr is a terminal. +// +func IsTTY() bool { + return isTTY +} + +// TerminalWidth returns the width of terminal, or zero. +// +func TerminalWidth() int { + if tWidth < 0 { + return 0 + } + + return tWidth +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/version/version.go b/vendor/github.com/elastic/go-elasticsearch/v8/internal/version/version.go new file mode 100644 index 00000000000..c4d25436827 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/version/version.go @@ -0,0 +1,9 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package version + +// Client returns the client version as a string. +// +const Client = "8.0.0-SNAPSHOT" diff --git a/vendor/vendor.json b/vendor/vendor.json index 9bb49003f47..66a397ee2eb 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -1496,6 +1496,13 @@ "revision": "363e3494bdafc50c3447e7a73d94e4caf9fc3c8c", "revisionTime": "2019-10-18T23:19:20Z" }, + { + "checksumSHA1": "wgane+Jx/akhNYEAqL/TlxwvkYg=", + "path": "github.com/elastic/go-elasticsearch/v8", + "revision": "8efb73c32e7fa9d1e2e905d9ec112d51382cabf4", + "revisionTime": "2019-10-22T14:22:00Z", + "tree": true + }, { "checksumSHA1": "3jizmlZPCyo6FAZY8Trk9jA8NH4=", "origin": "github.com/elastic/beats/vendor/github.com/elastic/go-lumber/client/v2", From ff29c22a1108a20024305149a12a4cafccb4ddec Mon Sep 17 00:00:00 2001 From: simitt Date: Fri, 25 Oct 2019 10:03:46 +0200 Subject: [PATCH 2/8] Refactor sourcemap logic Make use of newly integrated go-elasticsearch client for fetching sourcemaps from Elasticsearch. While on it, refactor logic in sourcemap package and tests to get rid of some technical dept. closes #2868 --- beater/api/mux.go | 7 +- beater/beater.go | 23 +- beater/beater_test.go | 24 +- beater/config/config.go | 185 ++------- beater/config/config_test.go | 351 ++++++++--------- beater/config/{config_helper.go => helper.go} | 0 .../{config_helper_test.go => helper_test.go} | 0 sourcemap/id.go => beater/config/mode.go | 49 +-- beater/config/register.go | 35 ++ beater/config/rum.go | 155 ++++++++ beater/config/rum_test.go | 89 +++++ beater/server_test.go | 55 ++- elasticsearch/client.go | 4 +- elasticsearch/test/client.go | 70 ++++ log/selectors.go | 1 + model/error/event.go | 2 +- model/error/event_test.go | 192 ++++------ model/sourcemap/payload.go | 9 +- model/sourcemap/payload_test.go | 92 +++-- model/span/event_test.go | 10 +- model/stacktrace.go | 60 +-- model/stacktrace_frame.go | 109 +++--- model/stacktrace_frame_test.go | 356 +++++++----------- model/stacktrace_test.go | 157 ++++---- sourcemap/accessor.go | 87 ----- sourcemap/accessor_test.go | 184 --------- sourcemap/cache.go | 84 ----- sourcemap/cache_test.go | 121 ------ sourcemap/elasticsearch.go | 168 --------- sourcemap/elasticsearch_test.go | 130 ------- sourcemap/error.go | 31 +- sourcemap/error_test.go | 48 --- sourcemap/es_store.go | 188 +++++++++ sourcemap/es_store_test.go | 100 +++++ sourcemap/id_test.go | 53 --- sourcemap/mapper.go | 90 +---- sourcemap/mapper_test.go | 83 ++-- sourcemap/store.go | 138 +++++++ sourcemap/store_test.go | 194 ++++++++++ sourcemap/test/es_client.go | 151 ++++++++ tests/system/test_integration.py | 2 +- transform/transform.go | 5 +- 42 files changed, 1916 insertions(+), 1976 deletions(-) rename beater/config/{config_helper.go => helper.go} (100%) rename beater/config/{config_helper_test.go => helper_test.go} (100%) rename sourcemap/id.go => beater/config/mode.go (55%) create mode 100644 beater/config/register.go create mode 100644 beater/config/rum.go create mode 100644 beater/config/rum_test.go create mode 100644 elasticsearch/test/client.go delete mode 100644 sourcemap/accessor.go delete mode 100644 sourcemap/accessor_test.go delete mode 100644 sourcemap/cache.go delete mode 100644 sourcemap/cache_test.go delete mode 100644 sourcemap/elasticsearch.go delete mode 100644 sourcemap/elasticsearch_test.go delete mode 100644 sourcemap/error_test.go create mode 100644 sourcemap/es_store.go create mode 100644 sourcemap/es_store_test.go delete mode 100644 sourcemap/id_test.go create mode 100644 sourcemap/store.go create mode 100644 sourcemap/store_test.go create mode 100644 sourcemap/test/es_client.go diff --git a/beater/api/mux.go b/beater/api/mux.go index e10cf41de10..1515b58c588 100644 --- a/beater/api/mux.go +++ b/beater/api/mux.go @@ -24,6 +24,8 @@ import ( "github.com/elastic/beats/libbeat/monitoring" + "github.com/elastic/beats/libbeat/logp" + "github.com/elastic/apm-server/beater/api/asset/sourcemap" "github.com/elastic/apm-server/beater/api/config/agent" "github.com/elastic/apm-server/beater/api/intake" @@ -39,7 +41,6 @@ import ( "github.com/elastic/apm-server/processor/stream" "github.com/elastic/apm-server/publish" "github.com/elastic/apm-server/transform" - "github.com/elastic/beats/libbeat/logp" ) const ( @@ -213,12 +214,12 @@ func userMetaDataDecoder(beaterConfig *config.Config, d decoder.ReqDecoder) deco } func rumTransformConfig(beaterConfig *config.Config) (*transform.Config, error) { - mapper, err := beaterConfig.RumConfig.MemoizedSourcemapMapper() + store, err := beaterConfig.RumConfig.MemoizedSourcemapStore() if err != nil { return nil, err } return &transform.Config{ - SourcemapMapper: mapper, + SourcemapStore: store, LibraryPattern: regexp.MustCompile(beaterConfig.RumConfig.LibraryPattern), ExcludeFromGrouping: regexp.MustCompile(beaterConfig.RumConfig.ExcludeFromGrouping), }, nil diff --git a/beater/beater.go b/beater/beater.go index 716235455ae..6f73600b331 100644 --- a/beater/beater.go +++ b/beater/beater.go @@ -85,31 +85,20 @@ func checkConfig(logger *logp.Logger) error { return nil } -// Creates beater +// New creates a beater instance using the provided configuration func New(b *beat.Beat, ucfg *common.Config) (beat.Beater, error) { logger := logp.NewLogger(logs.Beater) if err := checkConfig(logger); err != nil { return nil, err } - beaterConfig, err := config.NewConfig(b.Info.Version, ucfg) + var esOutputCfg *common.Config + if isElasticsearchOutput(b) { + esOutputCfg = b.Config.Output.Config() + } + beaterConfig, err := config.NewConfig(b.Info.Version, ucfg, esOutputCfg) if err != nil { return nil, err } - if beaterConfig.RumConfig.IsEnabled() { - if b.Config != nil && beaterConfig.RumConfig.SourceMapping.EsConfig == nil { - // fall back to elasticsearch output configuration for sourcemap storage if possible - if isElasticsearchOutput(b) { - logger.Info("Falling back to elasticsearch output for sourcemap storage") - beaterConfig.SetSourcemapElasticsearch(b.Config.Output.Config()) - } else { - logger.Info("Unable to determine sourcemap storage, sourcemaps will not be applied") - } - } - } - if isElasticsearchOutput(b) && - (b.Config.Output.Config().HasField("pipeline") || b.Config.Output.Config().HasField("pipelines")) { - beaterConfig.Pipeline = "" - } bt := &beater{ config: beaterConfig, diff --git a/beater/beater_test.go b/beater/beater_test.go index b8abdfc4dca..bf04b505bb6 100644 --- a/beater/beater_test.go +++ b/beater/beater_test.go @@ -28,9 +28,10 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" - "github.com/elastic/apm-server/beater/config" "github.com/elastic/beats/libbeat/beat" "github.com/elastic/beats/libbeat/common" "github.com/elastic/beats/libbeat/common/transport/tlscommon" @@ -41,6 +42,8 @@ import ( "github.com/elastic/beats/libbeat/publisher/processing" "github.com/elastic/beats/libbeat/publisher/queue" "github.com/elastic/beats/libbeat/publisher/queue/memqueue" + + "github.com/elastic/apm-server/beater/config" ) func TestBeatConfig(t *testing.T) { @@ -392,24 +395,13 @@ func (bt *beater) wait() error { } } -func (bt *beater) sourcemapElasticsearchHosts() []string { - var content map[string]interface{} - if err := bt.config.RumConfig.SourceMapping.EsConfig.Unpack(&content); err != nil { - return nil - } - hostsContent := content["hosts"].([]interface{}) - hosts := make([]string, len(hostsContent)) - for i := range hostsContent { - hosts[i] = hostsContent[i].(string) - } - return hosts -} - func setupBeater(t *testing.T, apmBeat *beat.Beat, ucfg *common.Config, beatConfig *beat.BeatConfig) (*beater, func(), error) { // create our beater beatBeater, err := New(apmBeat, ucfg) - assert.NoError(t, err) - assert.NotNil(t, beatBeater) + if err != nil { + return nil, nil, err + } + require.NotNil(t, beatBeater) c := make(chan error) // start it diff --git a/beater/config/config.go b/beater/config/config.go index ce45edfe3ad..aa5d20337fa 100644 --- a/beater/config/config.go +++ b/beater/config/config.go @@ -18,20 +18,19 @@ package config import ( - "fmt" "net" "path/filepath" "regexp" - "strings" "time" "github.com/pkg/errors" "github.com/elastic/beats/libbeat/common" "github.com/elastic/beats/libbeat/common/transport/tlscommon" + "github.com/elastic/beats/libbeat/logp" "github.com/elastic/beats/libbeat/paths" - "github.com/elastic/apm-server/sourcemap" + logs "github.com/elastic/apm-server/log" ) const ( @@ -43,6 +42,10 @@ const ( msgInvalidConfigAgentCfg = "invalid value for `apm-server.agent.config.cache.expiration`, only accepting full seconds" ) +var ( + regexObserverVersion = regexp.MustCompile("%.*{.*observer.version.?}") +) + // Config holds configuration information nested under the key `apm-server` type Config struct { Host string `config:"host"` @@ -52,7 +55,6 @@ type Config struct { WriteTimeout time.Duration `config:"write_timeout"` MaxEventSize int `config:"max_event_size"` ShutdownTimeout time.Duration `config:"shutdown_timeout"` - SecretToken string `config:"secret_token"` TLS *tlscommon.ServerConfig `config:"ssl"` MaxConnections int `config:"max_connections"` Expvar *ExpvarConfig `config:"expvar"` @@ -63,6 +65,7 @@ type Config struct { Mode Mode `config:"mode"` Kibana *common.Config `config:"kibana"` AgentConfig *AgentConfig `config:"agent.config"` + SecretToken string `config:"secret_token"` Pipeline string } @@ -73,61 +76,22 @@ type ExpvarConfig struct { URL string `config:"url"` } -// RumConfig holds config information related to the RUM endpoint -type RumConfig struct { - Enabled *bool `config:"enabled"` - EventRate *EventRate `config:"event_rate"` - AllowOrigins []string `config:"allow_origins"` - LibraryPattern string `config:"library_pattern"` - ExcludeFromGrouping string `config:"exclude_from_grouping"` - SourceMapping *SourceMapping `config:"source_mapping"` - - BeatVersion string -} - -// EventRate holds config information about event rate limiting -type EventRate struct { - Limit int `config:"limit"` - LruSize int `config:"lru_size"` -} - -// RegisterConfig holds ingest config information -type RegisterConfig struct { - Ingest *IngestConfig `config:"ingest"` -} - -// IngestConfig holds config pipeline ingest information -type IngestConfig struct { - Pipeline *PipelineConfig `config:"pipeline"` -} - -// PipelineConfig holds config information about registering ingest pipelines -type PipelineConfig struct { - Enabled *bool `config:"enabled"` - Overwrite *bool `config:"overwrite"` - Path string -} - // AgentConfig holds remote agent config information type AgentConfig struct { Cache *Cache `config:"cache"` } -// SourceMapping holds sourecemap config information -type SourceMapping struct { - Cache *Cache `config:"cache"` - Enabled *bool `config:"enabled"` - IndexPattern string `config:"index_pattern"` - - EsConfig *common.Config `config:"elasticsearch"` - mapper sourcemap.Mapper -} - // Cache holds config information about cache expiration type Cache struct { Expiration time.Duration `config:"expiration"` } +// LimitedCache holds config information about cache expiration +type LimitedCache struct { + Expiration time.Duration `config:"expiration"` + Size int `config:"size"` +} + // InstrumentationConfig holds config information about self instrumenting the APM Server type InstrumentationConfig struct { Enabled *bool `config:"enabled"` @@ -136,30 +100,9 @@ type InstrumentationConfig struct { SecretToken string `config:"secret_token"` } -//Mode enumerates the APM Server env -type Mode uint8 - -const ( - // ModeProduction is the default mode - ModeProduction Mode = iota - - // ModeExperimental should only be used in development environments. It allows to circumvent some restrictions - // on the Intake API for faster development. - ModeExperimental -) - -// Unpack parses the given string into a Mode value -func (m *Mode) Unpack(s string) error { - if strings.ToLower(s) == "experimental" { - *m = ModeExperimental - return nil - } - *m = ModeProduction - return nil -} - // NewConfig creates a Config struct based on the default config and the given input params -func NewConfig(version string, ucfg *common.Config) (*Config, error) { +func NewConfig(version string, ucfg *common.Config, outputESCfg *common.Config) (*Config, error) { + logger := logp.NewLogger(logs.Config) c := DefaultConfig(version) if ucfg.HasField("ssl") { @@ -181,23 +124,16 @@ func NewConfig(version string, ucfg *common.Config) (*Config, error) { if float64(int(c.AgentConfig.Cache.Expiration.Seconds())) != c.AgentConfig.Cache.Expiration.Seconds() { return nil, errors.New(msgInvalidConfigAgentCfg) } - if c.RumConfig.IsEnabled() { - if _, err := regexp.Compile(c.RumConfig.LibraryPattern); err != nil { - return nil, errors.New(fmt.Sprintf("Invalid regex for `library_pattern`: %v", err.Error())) - } - if _, err := regexp.Compile(c.RumConfig.ExcludeFromGrouping); err != nil { - return nil, errors.New(fmt.Sprintf("Invalid regex for `exclude_from_grouping`: %v", err.Error())) - } - } - return c, nil -} + if outputESCfg != nil && (outputESCfg.HasField("pipeline") || outputESCfg.HasField("pipelines")) { + c.Pipeline = "" + } -// SetSourcemapElasticsearch sets the Elasticsearch configuration for uploading sourcemaps -func (c *Config) SetSourcemapElasticsearch(esConfig *common.Config) { - if c != nil && c.RumConfig.IsEnabled() && c.RumConfig.SourceMapping != nil { - c.RumConfig.SourceMapping.EsConfig = esConfig + if err := c.RumConfig.setup(logger, outputESCfg); err != nil { + return nil, err } + + return c, nil } // IsEnabled indicates whether expvar is enabled or not @@ -205,21 +141,6 @@ func (c *ExpvarConfig) IsEnabled() bool { return c != nil && (c.Enabled == nil || *c.Enabled) } -// IsEnabled indicates whether RUM endpoint is enabled or not -func (c *RumConfig) IsEnabled() bool { - return c != nil && (c.Enabled != nil && *c.Enabled) -} - -// IsEnabled indicates whether sourcemap handling is enabled or not -func (s *SourceMapping) IsEnabled() bool { - return s == nil || s.Enabled == nil || *s.Enabled -} - -// IsSetup indicates whether there is an Elasticsearch configured for sourcemap handling -func (s *SourceMapping) IsSetup() bool { - return s != nil && (s.EsConfig != nil) -} - // IsEnabled indicates whether pipeline registration is enabled or not func (c *PipelineConfig) IsEnabled() bool { return c != nil && (c.Enabled == nil || *c.Enabled) @@ -230,28 +151,6 @@ func (c *PipelineConfig) ShouldOverwrite() bool { return c != nil && (c.Overwrite != nil && *c.Overwrite) } -// MemoizedSourcemapMapper creates the sourcemap mapper once and then caches it -func (c *RumConfig) MemoizedSourcemapMapper() (sourcemap.Mapper, error) { - if !c.IsEnabled() || !c.SourceMapping.IsEnabled() || !c.SourceMapping.IsSetup() { - return nil, nil - } - if c.SourceMapping.mapper != nil { - return c.SourceMapping.mapper, nil - } - - sourcemapConfig := sourcemap.Config{ - CacheExpiration: c.SourceMapping.Cache.Expiration, - ElasticsearchConfig: c.SourceMapping.EsConfig, - Index: replaceVersion(c.SourceMapping.IndexPattern, c.BeatVersion), - } - mapper, err := sourcemap.NewSmapMapper(sourcemapConfig) - if err != nil { - return nil, err - } - c.SourceMapping.mapper = mapper - return c.SourceMapping.mapper, nil -} - // IsEnabled indicates whether self instrumentation is enabled func (c *InstrumentationConfig) IsEnabled() bool { // self instrumentation is disabled by default. @@ -259,27 +158,7 @@ func (c *InstrumentationConfig) IsEnabled() bool { } func replaceVersion(pattern, version string) string { - re := regexp.MustCompile("%.*{.*observer.version.?}") - return re.ReplaceAllLiteralString(pattern, version) -} - -func defaultRum(beatVersion string) *RumConfig { - return &RumConfig{ - EventRate: &EventRate{ - Limit: 300, - LruSize: 1000, - }, - AllowOrigins: []string{"*"}, - SourceMapping: &SourceMapping{ - Cache: &Cache{ - Expiration: 5 * time.Minute, - }, - IndexPattern: "apm-*-sourcemap*", - }, - LibraryPattern: "node_modules|bower_components|~", - ExcludeFromGrouping: "^/webpack", - BeatVersion: beatVersion, - } + return regexObserverVersion.ReplaceAllLiteralString(pattern, version) } // DefaultConfig returns a config with default settings for `apm-server` config options. @@ -294,28 +173,12 @@ func DefaultConfig(beatVersion string) *Config { WriteTimeout: 30 * time.Second, MaxEventSize: 300 * 1024, // 300 kb ShutdownTimeout: 5 * time.Second, - SecretToken: "", AugmentEnabled: true, Expvar: &ExpvarConfig{ Enabled: new(bool), URL: "/debug/vars", }, - RumConfig: &RumConfig{ - EventRate: &EventRate{ - Limit: 300, - LruSize: 1000, - }, - AllowOrigins: []string{"*"}, - SourceMapping: &SourceMapping{ - Cache: &Cache{ - Expiration: 5 * time.Minute, - }, - IndexPattern: "apm-*-sourcemap*", - }, - LibraryPattern: "node_modules|bower_components|~", - ExcludeFromGrouping: "^/webpack", - BeatVersion: beatVersion, - }, + RumConfig: defaultRum(beatVersion), Register: &RegisterConfig{ Ingest: &IngestConfig{ Pipeline: &PipelineConfig{ diff --git a/beater/config/config_test.go b/beater/config/config_test.go index 23aef6ad80e..5469ec98bd3 100644 --- a/beater/config/config_test.go +++ b/beater/config/config_test.go @@ -19,6 +19,7 @@ package config import ( "fmt" + "path/filepath" "testing" "time" @@ -29,151 +30,208 @@ import ( "github.com/elastic/beats/libbeat/common" "github.com/elastic/beats/libbeat/outputs" - "github.com/elastic/go-ucfg/yaml" ) -func TestConfig(t *testing.T) { - truthy := true - cases := []struct { - config []byte - expectedConfig Config +func Test_UnpackConfig(t *testing.T) { + falsy, truthy := false, true + version := "8.0.0" + + tests := map[string]struct { + inpCfg map[string]interface{} + outCfg *Config + outCfgWithES *Config }{ - { - config: []byte(`{ - "host": "localhost:3000", - "max_header_size": 8, - "idle_timeout": 4s, - "read_timeout": 3s, - "write_timeout": 4s, - "shutdown_timeout": 9s, - "secret_token": "1234random", - "ssl": { - "enabled": true, - "key": "1234key", - "certificate": "1234cert", - "certificate_authorities": ["./ca.cert.pem"] + "default config": { + inpCfg: map[string]interface{}{}, + outCfg: DefaultConfig(version), + outCfgWithES: DefaultConfig(version), }, - "rum": { - "enabled": true, - "event_rate": { - "limit": 8000, - "lru_size": 2000, - }, - "allow_origins": ["rum*"], - "source_mapping": { - "cache": { - "expiration": 1m, + "overwrite default": { + inpCfg: map[string]interface{}{ + "host": "localhost:3000", + "max_header_size": 8, + "max_event_size": 100, + "idle_timeout": 5 * time.Second, + "read_timeout": 3 * time.Second, + "write_timeout": 4 * time.Second, + "shutdown_timeout": 9 * time.Second, + "capture_personal_data": true, + "secret_token": "1234random", + "ssl": map[string]interface{}{ + "enabled": true, + "key": "1234key", + "certificate": "1234cert", + "certificate_authorities": []string{"./ca.cert.pem"}, + "client_authentication": "none", + }, + "expvar": map[string]interface{}{ + "enabled": true, + "url": "/debug/vars", + }, + "rum": map[string]interface{}{ + "enabled": true, + "event_rate": map[string]interface{}{ + "limit": 7200, + "lru_size": 2000, + }, + "allow_origins": []string{"example*"}, + "source_mapping": map[string]interface{}{ + "cache": map[string]interface{}{ + "expiration": 8 * time.Minute, + }, + "index_pattern": "apm-test*", + }, + "library_pattern": "^custom", + "exclude_from_grouping": "^grouping", }, - "index_pattern": "apm-rum-test*" + "register": map[string]interface{}{ + "ingest": map[string]interface{}{ + "pipeline": map[string]interface{}{ + "overwrite": false, + "path": filepath.Join("tmp", "definition.json"), + }, + }, + }, + "kibana": map[string]interface{}{"enabled": "true"}, + "agent.config.cache.expiration": "2m", }, - "library_pattern": "pattern-rum", - "exclude_from_grouping": "group_pattern-rum", - }, - "register": { - "ingest": { - "pipeline": { - enabled: true, - overwrite: true, - path: "tmp", - } - } - } - }`), - expectedConfig: Config{ + outCfg: &Config{ Host: "localhost:3000", MaxHeaderSize: 8, - IdleTimeout: 4000000000, + MaxEventSize: 100, + IdleTimeout: 5000000000, ReadTimeout: 3000000000, WriteTimeout: 4000000000, ShutdownTimeout: 9000000000, SecretToken: "1234random", TLS: &tlscommon.ServerConfig{ Enabled: &truthy, - CAs: []string{"./ca.cert.pem"}, Certificate: outputs.CertificateConfig{Certificate: "1234cert", Key: "1234key"}, - ClientAuth: 4}, //4=RequireAndVerifyClientCert + ClientAuth: 0, + CAs: []string{"./ca.cert.pem"}, + }, + AugmentEnabled: true, + Expvar: &ExpvarConfig{ + Enabled: &truthy, + URL: "/debug/vars", + }, RumConfig: &RumConfig{ Enabled: &truthy, EventRate: &EventRate{ - Limit: 8000, + Limit: 7200, LruSize: 2000, }, - AllowOrigins: []string{"rum*"}, + AllowOrigins: []string{"example*"}, SourceMapping: &SourceMapping{ - Cache: &Cache{Expiration: 1 * time.Minute}, - IndexPattern: "apm-rum-test*", + Cache: &Cache{Expiration: 8 * time.Minute}, + IndexPattern: "apm-test*", }, - LibraryPattern: "pattern-rum", - ExcludeFromGrouping: "group_pattern-rum", + LibraryPattern: "^custom", + ExcludeFromGrouping: "^grouping", + BeatVersion: version, }, Register: &RegisterConfig{ Ingest: &IngestConfig{ Pipeline: &PipelineConfig{ Enabled: &truthy, - Overwrite: &truthy, - Path: "tmp", + Overwrite: &falsy, + Path: filepath.Join("tmp", "definition.json"), }, }, }, + Kibana: common.MustNewConfigFrom(map[string]interface{}{"enabled": "true"}), + AgentConfig: &AgentConfig{Cache: &Cache{Expiration: 2 * time.Minute}}, + Pipeline: DefaultAPMPipeline, }, }, - { - config: []byte(`{ - "host": "localhost:8200", - "max_header_size": 8, - "read_timeout": 3s, - "write_timeout": 2s, - "shutdown_timeout": 5s, - "secret_token": "1234random", - "rum": { - "source_mapping": {} - }, - "register": {} - }`), - expectedConfig: Config{ - Host: "localhost:8200", - MaxHeaderSize: 8, - ReadTimeout: 3000000000, - WriteTimeout: 2000000000, + "merge config with default": { + inpCfg: map[string]interface{}{ + "host": "localhost:3000", + "secret_token": "1234random", + "ssl": map[string]interface{}{ + "enabled": true, + }, + "expvar": map[string]interface{}{ + "enabled": true, + "url": "/debug/vars", + }, + "rum": map[string]interface{}{ + "enabled": true, + "source_mapping": map[string]interface{}{ + "cache": map[string]interface{}{ + "expiration": 7, + }, + }, + "library_pattern": "rum", + }, + "register": map[string]interface{}{ + "ingest": map[string]interface{}{ + "pipeline": map[string]interface{}{ + "enabled": false, + }, + }, + }, + }, + outCfg: &Config{ + Host: "localhost:3000", + MaxHeaderSize: 1048576, + MaxEventSize: 307200, + IdleTimeout: 45000000000, + ReadTimeout: 30000000000, + WriteTimeout: 30000000000, ShutdownTimeout: 5000000000, SecretToken: "1234random", + TLS: &tlscommon.ServerConfig{ + Enabled: &truthy, + Certificate: outputs.CertificateConfig{Certificate: "", Key: ""}, + ClientAuth: 3}, + AugmentEnabled: true, + Expvar: &ExpvarConfig{ + Enabled: &truthy, + URL: "/debug/vars", + }, RumConfig: &RumConfig{ - Enabled: nil, - EventRate: nil, - AllowOrigins: nil, + Enabled: &truthy, + EventRate: &EventRate{ + Limit: 300, + LruSize: 1000, + }, + AllowOrigins: []string{"*"}, SourceMapping: &SourceMapping{ - IndexPattern: "", + Cache: &Cache{ + Expiration: 7 * time.Second, + }, + IndexPattern: "apm-*-sourcemap*", }, + LibraryPattern: "rum", + ExcludeFromGrouping: "^/webpack", + BeatVersion: "8.0.0", }, Register: &RegisterConfig{ - Ingest: nil, + Ingest: &IngestConfig{ + Pipeline: &PipelineConfig{ + Enabled: &falsy, + Path: filepath.Join("ingest", "pipeline", "definition.json"), + }, + }, }, - }, - }, - { - config: []byte(`{ }`), - expectedConfig: Config{ - Host: "", - MaxHeaderSize: 0, - IdleTimeout: 0, - ReadTimeout: 0, - WriteTimeout: 0, - ShutdownTimeout: 0, - SecretToken: "", - TLS: nil, - RumConfig: nil, + Kibana: common.MustNewConfigFrom(map[string]interface{}{"enabled": "false"}), + AgentConfig: &AgentConfig{Cache: &Cache{Expiration: 30 * time.Second}}, + Pipeline: DefaultAPMPipeline, }, }, } - for idx, test := range cases { - cfg, err := yaml.NewConfig(test.config) - require.NoError(t, err) - var beaterConfig Config - err = cfg.Unpack(&beaterConfig) - require.NoError(t, err) - msg := fmt.Sprintf("Test number %v failed. Config: %v, ExpectedConfig: %v", idx, beaterConfig, test.expectedConfig) - assert.Equal(t, test.expectedConfig, beaterConfig, msg) + for name, test := range tests { + t.Run(name+"no outputESCfg", func(t *testing.T) { + inpCfg, err := common.NewConfigFrom(test.inpCfg) + assert.NoError(t, err) + + cfg, err := NewConfig(version, inpCfg, nil) + require.NoError(t, err) + require.NotNil(t, cfg) + assert.Equal(t, test.outCfg, cfg) + }) } } @@ -193,70 +251,6 @@ func TestReplaceBeatVersion(t *testing.T) { } } -func TestIsRumEnabled(t *testing.T) { - truthy := true - for _, td := range []struct { - c *Config - enabled bool - }{ - {c: &Config{RumConfig: &RumConfig{Enabled: new(bool)}}, enabled: false}, - {c: &Config{RumConfig: &RumConfig{Enabled: &truthy}}, enabled: true}, - } { - assert.Equal(t, td.enabled, td.c.RumConfig.IsEnabled()) - - } -} - -func TestDefaultRum(t *testing.T) { - c := DefaultConfig("7.0.0") - assert.Equal(t, c.RumConfig, defaultRum("7.0.0")) -} - -func TestMemoizedSourcemapMapper(t *testing.T) { - truthy := true - esConfig, err := common.NewConfigFrom(map[string]interface{}{ - "hosts": []string{"localhost:0"}, - }) - require.NoError(t, err) - mapping := SourceMapping{ - Cache: &Cache{Expiration: 1 * time.Minute}, - IndexPattern: "apm-rum-test*", - EsConfig: esConfig, - } - - for idx, td := range []struct { - c *Config - mapper bool - e error - }{ - {c: &Config{RumConfig: &RumConfig{}}, mapper: false, e: nil}, - {c: &Config{RumConfig: &RumConfig{Enabled: new(bool)}}, mapper: false, e: nil}, - {c: &Config{RumConfig: &RumConfig{Enabled: &truthy}}, mapper: false, e: nil}, - {c: &Config{RumConfig: &RumConfig{SourceMapping: &mapping}}, mapper: false, e: nil}, - {c: &Config{ - RumConfig: &RumConfig{ - Enabled: &truthy, - SourceMapping: &SourceMapping{ - Cache: &Cache{Expiration: 1 * time.Minute}, - IndexPattern: "apm-rum-test*", - }, - }}, - mapper: false, - e: nil}, - {c: &Config{RumConfig: &RumConfig{Enabled: &truthy, SourceMapping: &mapping}}, - mapper: true, - e: nil}, - } { - mapper, e := td.c.RumConfig.MemoizedSourcemapMapper() - if td.mapper { - assert.NotNil(t, mapper, fmt.Sprintf("Test number <%v> failed", idx)) - } else { - assert.Nil(t, mapper, fmt.Sprintf("Test number <%v> failed", idx)) - } - assert.Equal(t, td.e, e) - } -} - func TestPipeline(t *testing.T) { truthy, falsy := true, false cases := []struct { @@ -314,7 +308,7 @@ func TestTLSSettings(t *testing.T) { ucfgCfg, err := common.NewConfigFrom(tc.config) require.NoError(t, err) - cfg, err := NewConfig("9.9.9", ucfgCfg) + cfg, err := NewConfig("9.9.9", ucfgCfg, nil) require.NoError(t, err) assert.Equal(t, tc.tls.ClientAuth, cfg.TLS.ClientAuth) }) @@ -340,7 +334,7 @@ func TestTLSSettings(t *testing.T) { ucfgCfg, err := common.NewConfigFrom(tc.config) require.NoError(t, err) - cfg, err := NewConfig("9.9.9", ucfgCfg) + cfg, err := NewConfig("9.9.9", ucfgCfg, nil) require.NoError(t, err) assert.Equal(t, tc.tls.VerificationMode, cfg.TLS.VerificationMode) }) @@ -373,22 +367,39 @@ func TestTLSSettings(t *testing.T) { func TestAgentConfig(t *testing.T) { t.Run("InvalidValueTooSmall", func(t *testing.T) { cfg, err := NewConfig("9.9.9", - common.MustNewConfigFrom(map[string]string{"agent.config.cache.expiration": "123ms"})) + common.MustNewConfigFrom(map[string]string{"agent.config.cache.expiration": "123ms"}), nil) require.Error(t, err) assert.Nil(t, cfg) }) t.Run("InvalidUnit", func(t *testing.T) { cfg, err := NewConfig("9.9.9", - common.MustNewConfigFrom(map[string]string{"agent.config.cache.expiration": "1230ms"})) + common.MustNewConfigFrom(map[string]string{"agent.config.cache.expiration": "1230ms"}), nil) require.Error(t, err) assert.Nil(t, cfg) }) t.Run("Valid", func(t *testing.T) { cfg, err := NewConfig("9.9.9", - common.MustNewConfigFrom(map[string]string{"agent.config.cache.expiration": "123000ms"})) + common.MustNewConfigFrom(map[string]string{"agent.config.cache.expiration": "123000ms"}), nil) require.NoError(t, err) assert.Equal(t, time.Second*123, cfg.AgentConfig.Cache.Expiration) }) } + +func TestSourcemapESConfig(t *testing.T) { + version := "8.0.0" + ucfg, err := common.NewConfigFrom(`{"rum":{"enabled":true}}`) + require.NoError(t, err) + + // no es config given + cfg, err := NewConfig(version, ucfg, nil) + require.NoError(t, err) + assert.Nil(t, cfg.RumConfig.SourceMapping.ESConfig) + + // with es config + outputESCfg := common.MustNewConfigFrom(`{"hosts":["192.0.0.168:9200"]}`) + cfg, err = NewConfig(version, ucfg, outputESCfg) + require.NoError(t, err) + assert.NotNil(t, cfg.RumConfig.SourceMapping.ESConfig) +} diff --git a/beater/config/config_helper.go b/beater/config/helper.go similarity index 100% rename from beater/config/config_helper.go rename to beater/config/helper.go diff --git a/beater/config/config_helper_test.go b/beater/config/helper_test.go similarity index 100% rename from beater/config/config_helper_test.go rename to beater/config/helper_test.go diff --git a/sourcemap/id.go b/beater/config/mode.go similarity index 55% rename from sourcemap/id.go rename to beater/config/mode.go index b5730fb2505..ff2a2f58a90 100644 --- a/sourcemap/id.go +++ b/beater/config/mode.go @@ -15,41 +15,28 @@ // specific language governing permissions and limitations // under the License. -package sourcemap +package config -import ( - "fmt" - "strings" -) +import "strings" -type Id struct { - ServiceName string - ServiceVersion string - Path string -} +//Mode enumerates the APM Server env +type Mode uint8 -func (i *Id) Key() string { - info := []string{} - info = add(info, i.ServiceName) - info = add(info, i.ServiceVersion) - info = add(info, i.Path) - return strings.Join(info, "_") -} +const ( + // ModeProduction is the default mode + ModeProduction Mode = iota -func (i *Id) String() string { - return fmt.Sprintf("Service Name: '%s', Service Version: '%s' and Path: '%s'", - i.ServiceName, - i.ServiceVersion, - i.Path) -} - -func (i *Id) Valid() bool { - return i.ServiceName != "" && i.ServiceVersion != "" && i.Path != "" -} + // ModeExperimental should only be used in development environments. It allows to circumvent some restrictions + // on the Intake API for faster development. + ModeExperimental +) -func add(a []string, s string) []string { - if s != "" { - a = append(a, s) +// Unpack parses the given string into a Mode value +func (m *Mode) Unpack(s string) error { + if strings.ToLower(s) == "experimental" { + *m = ModeExperimental + return nil } - return a + *m = ModeProduction + return nil } diff --git a/beater/config/register.go b/beater/config/register.go new file mode 100644 index 00000000000..cab44410985 --- /dev/null +++ b/beater/config/register.go @@ -0,0 +1,35 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package config + +// RegisterConfig holds ingest config information +type RegisterConfig struct { + Ingest *IngestConfig `config:"ingest"` +} + +// IngestConfig holds config pipeline ingest information +type IngestConfig struct { + Pipeline *PipelineConfig `config:"pipeline"` +} + +// PipelineConfig holds config information about registering ingest pipelines +type PipelineConfig struct { + Enabled *bool `config:"enabled"` + Overwrite *bool `config:"overwrite"` + Path string +} diff --git a/beater/config/rum.go b/beater/config/rum.go new file mode 100644 index 00000000000..b83ecb08e68 --- /dev/null +++ b/beater/config/rum.go @@ -0,0 +1,155 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package config + +import ( + "regexp" + "time" + + "github.com/pkg/errors" + + "github.com/elastic/beats/libbeat/common" + "github.com/elastic/beats/libbeat/logp" + + "github.com/elastic/apm-server/elasticsearch" + "github.com/elastic/apm-server/sourcemap" +) + +const ( + allowAllOrigins = "*" + defaultEventRateLimit = 300 + defaultEventRateLRUSize = 1000 + defaultExcludeFromGrouping = "^/webpack" + defaultLibraryPattern = "node_modules|bower_components|~" + defaultSourcemapCacheExpiration = 5 * time.Minute + defaultSourcemapIndexPattern = "apm-*-sourcemap*" + + esConnectionTimeout = 5 * time.Second +) + +// RumConfig holds config information related to the RUM endpoint +type RumConfig struct { + Enabled *bool `config:"enabled"` + EventRate *EventRate `config:"event_rate"` + AllowOrigins []string `config:"allow_origins"` + LibraryPattern string `config:"library_pattern"` + ExcludeFromGrouping string `config:"exclude_from_grouping"` + SourceMapping *SourceMapping `config:"source_mapping"` + + BeatVersion string +} + +// EventRate holds config information about event rate limiting +type EventRate struct { + Limit int `config:"limit"` + LruSize int `config:"lru_size"` +} + +// SourceMapping holds sourecemap config information +type SourceMapping struct { + Cache *Cache `config:"cache"` + Enabled *bool `config:"enabled"` + IndexPattern string `config:"index_pattern"` + ESConfig *elasticsearch.Config `config:"elasticsearch"` + store *sourcemap.Store +} + +// IsEnabled indicates whether RUM endpoint is enabled or not +func (c *RumConfig) IsEnabled() bool { + return c != nil && (c.Enabled != nil && *c.Enabled) +} + +// IsEnabled indicates whether sourcemap handling is enabled or not +func (s *SourceMapping) IsEnabled() bool { + return s == nil || s.Enabled == nil || *s.Enabled +} + +// MemoizedSourcemapStore creates the sourcemap store once and then caches it +func (c *RumConfig) MemoizedSourcemapStore() (*sourcemap.Store, error) { + if !c.IsEnabled() || !c.SourceMapping.IsEnabled() || !c.SourceMapping.isSetup() { + return nil, nil + } + if c.SourceMapping.store != nil { + return c.SourceMapping.store, nil + } + + esClient, err := elasticsearch.NewClient(c.SourceMapping.ESConfig) + if err != nil { + return nil, err + } + index := replaceVersion(c.SourceMapping.IndexPattern, c.BeatVersion) + store, err := sourcemap.NewStore(esClient, index, c.SourceMapping.Cache.Expiration) + if err != nil { + return nil, err + } + c.SourceMapping.store = store + return store, nil +} + +func (c *RumConfig) setup(log *logp.Logger, outputESCfg *common.Config) error { + if !c.IsEnabled() { + return nil + } + + if _, err := regexp.Compile(c.LibraryPattern); err != nil { + return errors.Wrapf(err, "Invalid regex for `library_pattern`: ") + } + if _, err := regexp.Compile(c.ExcludeFromGrouping); err != nil { + return errors.Wrapf(err, "Invalid regex for `exclude_from_grouping`: ") + } + + if c.SourceMapping == nil || c.SourceMapping.ESConfig != nil { + return nil + } + + // fall back to elasticsearch output configuration for sourcemap storage if possible + if outputESCfg == nil { + log.Info("Unable to determine sourcemap storage, sourcemaps will not be applied") + return nil + } + log.Info("Falling back to elasticsearch output for sourcemap storage") + esCfg := &elasticsearch.Config{Hosts: []string{"localhost:9200"}, Protocol: "http", Timeout: esConnectionTimeout} + if err := outputESCfg.Unpack(esCfg); err != nil { + return errors.Wrap(err, "unpacking Elasticsearch config into Sourcemap config") + } + c.SourceMapping.ESConfig = esCfg + return nil +} + +func (s *SourceMapping) isSetup() bool { + return s != nil && (s.ESConfig != nil) +} + +func defaultRum(beatVersion string) *RumConfig { + return &RumConfig{ + EventRate: &EventRate{ + Limit: defaultEventRateLimit, + LruSize: defaultEventRateLRUSize, + }, + AllowOrigins: []string{allowAllOrigins}, + SourceMapping: &SourceMapping{ + Cache: &Cache{ + Expiration: defaultSourcemapCacheExpiration, + }, + IndexPattern: defaultSourcemapIndexPattern, + }, + LibraryPattern: defaultLibraryPattern, + ExcludeFromGrouping: defaultExcludeFromGrouping, + BeatVersion: beatVersion, + } +} diff --git a/beater/config/rum_test.go b/beater/config/rum_test.go new file mode 100644 index 00000000000..4e5d7b3304c --- /dev/null +++ b/beater/config/rum_test.go @@ -0,0 +1,89 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package config + +import ( + "fmt" + "testing" + "time" + + "github.com/stretchr/testify/assert" + + "github.com/elastic/apm-server/elasticsearch" +) + +func TestIsRumEnabled(t *testing.T) { + truthy := true + for _, td := range []struct { + c *Config + enabled bool + }{ + {c: &Config{RumConfig: &RumConfig{Enabled: new(bool)}}, enabled: false}, + {c: &Config{RumConfig: &RumConfig{Enabled: &truthy}}, enabled: true}, + } { + assert.Equal(t, td.enabled, td.c.RumConfig.IsEnabled()) + + } +} + +func TestDefaultRum(t *testing.T) { + c := DefaultConfig("7.0.0") + assert.Equal(t, defaultRum("7.0.0"), c.RumConfig) +} + +func TestMemoizedSourcemapMapper(t *testing.T) { + truthy := true + esConfig := elasticsearch.Config{Hosts: []string{"localhost:0"}} + mapping := SourceMapping{ + Cache: &Cache{Expiration: 1 * time.Minute}, + IndexPattern: "apm-rum-test*", + ESConfig: &esConfig, + } + + for idx, td := range []struct { + c *Config + mapper bool + e error + }{ + {c: &Config{RumConfig: &RumConfig{}}, mapper: false, e: nil}, + {c: &Config{RumConfig: &RumConfig{Enabled: new(bool)}}, mapper: false, e: nil}, + {c: &Config{RumConfig: &RumConfig{Enabled: &truthy}}, mapper: false, e: nil}, + {c: &Config{RumConfig: &RumConfig{SourceMapping: &mapping}}, mapper: false, e: nil}, + {c: &Config{ + RumConfig: &RumConfig{ + Enabled: &truthy, + SourceMapping: &SourceMapping{ + Cache: &Cache{Expiration: 1 * time.Minute}, + IndexPattern: "apm-rum-test*", + }, + }}, + mapper: false, + e: nil}, + {c: &Config{RumConfig: &RumConfig{Enabled: &truthy, SourceMapping: &mapping}}, + mapper: true, + e: nil}, + } { + mapper, e := td.c.RumConfig.MemoizedSourcemapStore() + if td.mapper { + assert.NotNil(t, mapper, fmt.Sprintf("Test number <%v> failed", idx)) + } else { + assert.Nil(t, mapper, fmt.Sprintf("Test number <%v> failed", idx)) + } + assert.Equal(t, td.e, e) + } +} diff --git a/beater/server_test.go b/beater/server_test.go index bece4753b41..328ef6b022d 100644 --- a/beater/server_test.go +++ b/beater/server_test.go @@ -40,6 +40,7 @@ import ( "github.com/elastic/apm-server/beater/api" "github.com/elastic/apm-server/beater/config" + "github.com/elastic/apm-server/elasticsearch" "github.com/elastic/apm-server/tests/loader" ) @@ -234,7 +235,8 @@ func TestServerRumSwitch(t *testing.T) { func TestServerSourcemapBadConfig(t *testing.T) { ucfg, err := common.NewConfigFrom(m{"rum": m{"enabled": true, "source_mapping": m{"elasticsearch": m{"hosts": []string{}}}}}) require.NoError(t, err) - _, teardown, err := setupServer(t, ucfg, nil, nil) + s, teardown, err := setupServer(t, ucfg, nil, nil) + require.Nil(t, s) if err == nil { defer teardown() } @@ -318,18 +320,17 @@ func TestServerNoContentType(t *testing.T) { } func TestServerSourcemapElasticsearch(t *testing.T) { - cases := []struct { - expected []string + for name, tc := range map[string]struct { + expected elasticsearch.Hosts config m outputConfig m }{ - { + "nil": { expected: nil, config: m{}, }, - { - // source_mapping.elasticsearch.hosts set - expected: []string{"localhost:5200"}, + "esConfigured": { + expected: elasticsearch.Hosts{"localhost:5200"}, config: m{ "rum": m{ "enabled": "true", @@ -337,9 +338,8 @@ func TestServerSourcemapElasticsearch(t *testing.T) { }, }, }, - { - // source_mapping.elasticsearch.hosts not set, elasticsearch.enabled = true - expected: []string{"localhost:5201"}, + "esFromOutput": { + expected: elasticsearch.Hosts{"localhost:5201"}, config: m{ "rum": m{ "enabled": "true", @@ -352,8 +352,7 @@ func TestServerSourcemapElasticsearch(t *testing.T) { }, }, }, - { - // source_mapping.elasticsearch.hosts not set, elasticsearch.enabled = false + "esOutputDisabled": { expected: nil, config: m{ "rum": m{ @@ -367,24 +366,22 @@ func TestServerSourcemapElasticsearch(t *testing.T) { }, }, }, - } - for _, testCase := range cases { - ucfg, err := common.NewConfigFrom(testCase.config) - if !assert.NoError(t, err) { - continue - } + } { + t.Run(name, func(t *testing.T) { + ucfg, err := common.NewConfigFrom(tc.config) + require.NoError(t, err) - var beatConfig beat.BeatConfig - ocfg, err := common.NewConfigFrom(testCase.outputConfig) - if !assert.NoError(t, err) { - continue - } - beatConfig.Output.Unpack(ocfg) - apm, teardown, err := setupServer(t, ucfg, &beatConfig, nil) - if assert.NoError(t, err) { - assert.Equal(t, testCase.expected, apm.sourcemapElasticsearchHosts()) - } - teardown() + var beatConfig beat.BeatConfig + ocfg, err := common.NewConfigFrom(tc.outputConfig) + require.NoError(t, err) + require.NoError(t, beatConfig.Output.Unpack(ocfg)) + apm, teardown, err := setupServer(t, ucfg, &beatConfig, nil) + require.NoError(t, err) + if tc.expected != nil { + assert.Equal(t, tc.expected, apm.config.RumConfig.SourceMapping.ESConfig.Hosts) + } + teardown() + }) } } diff --git a/elasticsearch/client.go b/elasticsearch/client.go index ed6a381acf0..f99b669ddb6 100644 --- a/elasticsearch/client.go +++ b/elasticsearch/client.go @@ -35,7 +35,7 @@ import ( const ( prefixHTTP = "http" prefixHTTPSchema = prefixHTTP + "://" - esDefaultPort = 9200 + defaultESPort = 9200 ) var ( @@ -122,7 +122,7 @@ func httpProxyURL(cfg *Config) (func(*http.Request) (*url.URL, error), error) { func addresses(cfg *Config) ([]string, error) { var addresses []string for _, host := range cfg.Hosts { - address, err := common.MakeURL(cfg.Protocol, cfg.Path, host, esDefaultPort) + address, err := common.MakeURL(cfg.Protocol, cfg.Path, host, defaultESPort) if err != nil { return nil, err } diff --git a/elasticsearch/test/client.go b/elasticsearch/test/client.go new file mode 100644 index 00000000000..c2443a48d03 --- /dev/null +++ b/elasticsearch/test/client.go @@ -0,0 +1,70 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package test + +import ( + "bytes" + "encoding/json" + "io" + "io/ioutil" + "net/http" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/pkg/errors" + + "github.com/elastic/go-elasticsearch/v8" +) + +// Transport can be used to pass to test Elasticsearch Client for more control over client behavior +type Transport struct { + roundTripFn func(req *http.Request) (*http.Response, error) + executed int +} + +// RoundTrip implements http.RoundTripper interface +func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) { + t.executed++ + return t.roundTripFn(req) +} + +// NewTransport creates test transport instance returning status code and body according to input parameters when called. +func NewTransport(t *testing.T, statusCode int, esBody map[string]interface{}) *Transport { + var body io.ReadCloser + if esBody == nil { + body = ioutil.NopCloser(bytes.NewReader([]byte{})) + } else { + resp, err := json.Marshal(esBody) + require.NoError(t, err) + body = ioutil.NopCloser(bytes.NewReader(resp)) + } + return &Transport{ + roundTripFn: func(_ *http.Request) (*http.Response, error) { + if statusCode == http.StatusInternalServerError { + return &http.Response{}, errors.New("Internal server error") + } + return &http.Response{StatusCode: statusCode, Body: body}, nil + }, + } +} + +// NewElasticsearchClient creates ES client using the given transport instance +func NewElasticsearchClient(transport *Transport) (*elasticsearch.Client, error) { + return elasticsearch.NewClient(elasticsearch.Config{Addresses: []string{}, Transport: transport}) +} diff --git a/log/selectors.go b/log/selectors.go index 538d542ab91..d7d3097cbbb 100644 --- a/log/selectors.go +++ b/log/selectors.go @@ -20,6 +20,7 @@ package logs // logging selectors const ( Beater = "beater" + Config = "config" Handler = "handler" Ilm = "ilm" IndexManagement = "index-management" diff --git a/model/error/event.go b/model/error/event.go index 0391f505b33..5db6debc35e 100644 --- a/model/error/event.go +++ b/model/error/event.go @@ -254,7 +254,7 @@ func (e *Event) fields(tctx *transform.Context) common.MapStr { } func (e *Event) updateCulprit(tctx *transform.Context) { - if tctx.Config.SourcemapMapper == nil { + if tctx.Config.SourcemapStore == nil { return } var fr *m.StacktraceFrame diff --git a/model/error/event_test.go b/model/error/event_test.go index fd754ab93c7..e7381638bd6 100644 --- a/model/error/event_test.go +++ b/model/error/event_test.go @@ -24,20 +24,17 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" - "os" - "path/filepath" "testing" "time" - s "github.com/go-sourcemap/sourcemap" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" m "github.com/elastic/apm-server/model" "github.com/elastic/apm-server/model/metadata" "github.com/elastic/apm-server/sourcemap" + "github.com/elastic/apm-server/sourcemap/test" "github.com/elastic/apm-server/transform" "github.com/elastic/apm-server/utility" @@ -136,7 +133,7 @@ func TestErrorEventDecode(t *testing.T) { "stacktrace": "123", }, }, - err: m.ErrInvalidStacktraceType, + err: errors.New("invalid type for stacktrace"), }, "invalid type for log stacktrace": { input: map[string]interface{}{ @@ -146,7 +143,7 @@ func TestErrorEventDecode(t *testing.T) { "stacktrace": "123", }, }, - err: m.ErrInvalidStacktraceType, + err: errors.New("invalid type for stacktrace"), }, "minimal valid error": { input: map[string]interface{}{ @@ -440,68 +437,60 @@ func TestEventFields(t *testing.T) { baseLogGroupingKey := hex.EncodeToString(baseLogHash.Sum(nil)) trId := "945254c5-67a5-417e-8a4e-aa29efcbfb79" - tests := []struct { + tests := map[string]struct { Event Event Output common.MapStr - Msg string }{ - { + "minimal": { Event: Event{}, Output: common.MapStr{ "grouping_key": hex.EncodeToString(md5.New().Sum(nil)), }, - Msg: "Minimal Event", }, - { + "withLog": { Event: Event{Log: baseLog()}, Output: common.MapStr{ "log": common.MapStr{"message": "error log message"}, "grouping_key": baseLogGroupingKey, }, - Msg: "Minimal Event wth log", }, - { + "withLogAndException": { Event: Event{Exception: baseException(), Log: baseLog()}, Output: common.MapStr{ "exception": []common.MapStr{{"message": "exception message"}}, "log": common.MapStr{"message": "error log message"}, "grouping_key": baseExceptionGroupingKey, }, - Msg: "Minimal Event wth log and exception", }, - { + "withException": { Event: Event{Exception: baseException()}, Output: common.MapStr{ "exception": []common.MapStr{{"message": "exception message"}}, "grouping_key": baseExceptionGroupingKey, }, - Msg: "Minimal Event with exception", }, - { + "stringCode": { Event: Event{Exception: baseException().withCode("13")}, Output: common.MapStr{ "exception": []common.MapStr{{"message": "exception message", "code": "13"}}, "grouping_key": baseExceptionGroupingKey, }, - Msg: "Minimal Event with exception and string code", }, - { + "intCode": { Event: Event{Exception: baseException().withCode(13)}, Output: common.MapStr{ "exception": []common.MapStr{{"message": "exception message", "code": "13"}}, "grouping_key": baseExceptionGroupingKey, }, - Msg: "Minimal Event wth exception and int code", }, - { + "floatCode": { Event: Event{Exception: baseException().withCode(13.0)}, Output: common.MapStr{ "exception": []common.MapStr{{"message": "exception message", "code": "13"}}, "grouping_key": baseExceptionGroupingKey, }, - Msg: "Minimal Event wth exception and float code", }, - { + "withFrames": { Event: Event{ Id: &id, Timestamp: time.Now(), @@ -537,23 +526,24 @@ func TestEventFields(t *testing.T) { }, "grouping_key": "2725d2590215a6e975f393bf438f90ef", }, - Msg: "Event with frames", }, } - s := "myservice" - tctx := &transform.Context{ - Config: transform.Config{SourcemapMapper: &sourcemap.SmapMapper{}}, - Metadata: metadata.Metadata{ - Service: &metadata.Service{Name: &s}, - }, - } + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + s := "myservice" + tctx := &transform.Context{ + Config: transform.Config{SourcemapStore: &sourcemap.Store{}}, + Metadata: metadata.Metadata{ + Service: &metadata.Service{Name: &s, Version: &s}, + }, + } - for idx, test := range tests { - output := test.Event.Transform(tctx) - require.Len(t, output, 1) - fields := output[0].Fields["error"] - assert.Equal(t, test.Output, fields, fmt.Sprintf("Failed at idx %v; %s", idx, test.Msg)) + output := tc.Event.Transform(tctx) + require.Len(t, output, 1) + fields := output[0].Fields["error"] + assert.Equal(t, tc.Output, fields) + }) } } @@ -561,9 +551,9 @@ func TestEvents(t *testing.T) { timestamp := time.Date(2019, 1, 3, 15, 17, 4, 908.596*1e6, time.FixedZone("+0100", 3600)) timestampUs := timestamp.UnixNano() / 1000 - serviceName, agentName, agentVersion := "myservice", "go", "1.0" + serviceName, agentName, version := "myservice", "go", "1.0" service := metadata.Service{ - Name: &serviceName, Agent: metadata.Agent{Name: &agentName, Version: &agentVersion}, + Name: &serviceName, Version: &version, Agent: metadata.Agent{Name: &agentName, Version: &version}, } serviceVersion := "1.2.3" exMsg := "exception message" @@ -577,16 +567,16 @@ func TestEvents(t *testing.T) { labels := m.Labels(common.MapStr{"key": true}) custom := m.Custom(common.MapStr{"foo": "bar"}) metadataLabels := common.MapStr{"label": 101} - tests := []struct { + for name, tc := range map[string]struct { Transformable transform.Transformable Output common.MapStr Msg string }{ - { + "valid": { Transformable: &Event{Timestamp: timestamp}, Output: common.MapStr{ "agent": common.MapStr{"name": "go", "version": "1.0"}, - "service": common.MapStr{"name": "myservice"}, + "service": common.MapStr{"name": "myservice", "version": "1.0"}, "error": common.MapStr{ "grouping_key": "d41d8cd98f00b204e9800998ecf8427e", }, @@ -595,14 +585,13 @@ func TestEvents(t *testing.T) { "timestamp": common.MapStr{"us": timestampUs}, "labels": common.MapStr{"label": 101}, }, - Msg: "Payload with valid Event.", }, - { + "notSampled": { Transformable: &Event{Timestamp: timestamp, TransactionSampled: &sampledFalse}, Output: common.MapStr{ "transaction": common.MapStr{"sampled": false}, "agent": common.MapStr{"name": "go", "version": "1.0"}, - "service": common.MapStr{"name": "myservice"}, + "service": common.MapStr{"name": "myservice", "version": "1.0"}, "error": common.MapStr{ "grouping_key": "d41d8cd98f00b204e9800998ecf8427e", }, @@ -611,9 +600,8 @@ func TestEvents(t *testing.T) { "timestamp": common.MapStr{"us": timestampUs}, "labels": common.MapStr{"label": 101}, }, - Msg: "Payload with valid Event.", }, - { + "withMeta": { Transformable: &Event{Timestamp: timestamp, TransactionType: &transactionType}, Output: common.MapStr{ "transaction": common.MapStr{"type": "request"}, @@ -621,15 +609,14 @@ func TestEvents(t *testing.T) { "grouping_key": "d41d8cd98f00b204e9800998ecf8427e", }, "processor": common.MapStr{"event": "error", "name": "error"}, - "service": common.MapStr{"name": "myservice"}, + "service": common.MapStr{"name": "myservice", "version": "1.0"}, "user": common.MapStr{"id": uid}, "timestamp": common.MapStr{"us": timestampUs}, "agent": common.MapStr{"name": "go", "version": "1.0"}, "labels": common.MapStr{"label": 101}, }, - Msg: "Payload with valid Event.", }, - { + "withContext": { Transformable: &Event{ Timestamp: timestamp, Log: baseLog(), @@ -647,7 +634,7 @@ func TestEvents(t *testing.T) { Output: common.MapStr{ "labels": common.MapStr{"key": true, "label": 101}, - "service": common.MapStr{"name": "myservice"}, + "service": common.MapStr{"name": "myservice", "version": "1.0"}, "agent": common.MapStr{"name": "go", "version": "1.0"}, "user": common.MapStr{"email": email}, "client": common.MapStr{"ip": userIp}, @@ -676,9 +663,8 @@ func TestEvents(t *testing.T) { "transaction": common.MapStr{"id": "945254c5-67a5-417e-8a4e-aa29efcbfb79", "sampled": true}, "timestamp": common.MapStr{"us": timestampUs}, }, - Msg: "Payload with Event with Context.", }, - { + "deepUpdateService": { Transformable: &Event{Timestamp: timestamp, Service: &metadata.Service{Version: &serviceVersion}}, Output: common.MapStr{ "service": common.MapStr{"name": serviceName, "version": serviceVersion}, @@ -689,23 +675,23 @@ func TestEvents(t *testing.T) { "processor": common.MapStr{"event": "error", "name": "error"}, "timestamp": common.MapStr{"us": timestampUs}, }, - Msg: "Deep update service fields", }, - } + } { + t.Run(name, func(t *testing.T) { + me := metadata.NewMetadata(&service, nil, nil, &metadata.User{Id: &uid}, metadataLabels) + tctx := &transform.Context{ + Metadata: *me, + Config: transform.Config{SourcemapStore: &sourcemap.Store{}}, + RequestTime: timestamp, + } - me := metadata.NewMetadata(&service, nil, nil, &metadata.User{Id: &uid}, metadataLabels) - tctx := &transform.Context{ - Metadata: *me, - Config: transform.Config{SourcemapMapper: &sourcemap.SmapMapper{}}, - RequestTime: timestamp, - } + outputEvents := tc.Transformable.Transform(tctx) + require.Len(t, outputEvents, 1) + outputEvent := outputEvents[0] + assert.Equal(t, tc.Output, outputEvent.Fields) + assert.Equal(t, timestamp, outputEvent.Timestamp) - for idx, test := range tests { - outputEvents := test.Transformable.Transform(tctx) - require.Len(t, outputEvents, 1) - outputEvent := outputEvents[0] - assert.Equal(t, test.Output, outputEvent.Fields, fmt.Sprintf("Failed at idx %v; %s", idx, test.Msg)) - assert.Equal(t, timestamp, outputEvent.Timestamp, fmt.Sprintf("Bad timestamp at idx %v; %s", idx, test.Msg)) + }) } } @@ -722,7 +708,7 @@ func TestCulprit(t *testing.T) { &m.StacktraceFrame{Filename: "f", Function: &fct, Sourcemap: m.Sourcemap{Updated: &truthy}}, &m.StacktraceFrame{Filename: "bar", Function: &fct, Sourcemap: m.Sourcemap{Updated: &truthy}}, } - mapper := sourcemap.SmapMapper{} + store := &sourcemap.Store{} tests := []struct { event Event config transform.Config @@ -737,13 +723,13 @@ func TestCulprit(t *testing.T) { }, { event: Event{Culprit: &c}, - config: transform.Config{SourcemapMapper: &mapper}, + config: transform.Config{SourcemapStore: store}, culprit: "foo", msg: "No Stacktrace Frame given.", }, { event: Event{Culprit: &c, Log: &Log{Stacktrace: st}}, - config: transform.Config{SourcemapMapper: &mapper}, + config: transform.Config{SourcemapStore: store}, culprit: "foo", msg: "Log.StacktraceFrame has no updated frame", }, @@ -759,7 +745,7 @@ func TestCulprit(t *testing.T) { }, }, }, - config: transform.Config{SourcemapMapper: &mapper}, + config: transform.Config{SourcemapStore: store}, culprit: "f", msg: "Adapt culprit to first valid Log.StacktraceFrame information.", }, @@ -768,7 +754,7 @@ func TestCulprit(t *testing.T) { Culprit: &c, Exception: &Exception{Stacktrace: stUpdate}, }, - config: transform.Config{SourcemapMapper: &mapper}, + config: transform.Config{SourcemapStore: store}, culprit: "f in fct", msg: "Adapt culprit to first valid Exception.StacktraceFrame information.", }, @@ -778,7 +764,7 @@ func TestCulprit(t *testing.T) { Log: &Log{Stacktrace: st}, Exception: &Exception{Stacktrace: stUpdate}, }, - config: transform.Config{SourcemapMapper: &mapper}, + config: transform.Config{SourcemapStore: store}, culprit: "f in fct", msg: "Log and Exception StacktraceFrame given, only one changes culprit.", }, @@ -796,7 +782,7 @@ func TestCulprit(t *testing.T) { }, Exception: &Exception{Stacktrace: stUpdate}, }, - config: transform.Config{SourcemapMapper: &mapper}, + config: transform.Config{SourcemapStore: store}, culprit: "a in fct", msg: "Log Stacktrace is prioritized over Exception StacktraceFrame", }, @@ -1011,51 +997,31 @@ func md5With(args ...string) []byte { } func TestSourcemapping(t *testing.T) { - c1 := 18 - lineno := 1 - empty := "" + col, line, path := 23, 1, "../a/b" exMsg := "exception message" - event := Event{Exception: &Exception{ - Message: &exMsg, - Stacktrace: m.Stacktrace{ - &m.StacktraceFrame{Filename: "/a/b/c", Lineno: &lineno, Colno: &c1}, - }, + event1 := Event{Exception: &Exception{Message: &exMsg, + Stacktrace: m.Stacktrace{&m.StacktraceFrame{Filename: "/a/b/c", Lineno: &line, Colno: &col, AbsPath: &path}}, + }} + event2 := Event{Exception: &Exception{Message: &exMsg, + Stacktrace: m.Stacktrace{&m.StacktraceFrame{Filename: "/a/b/c", Lineno: &line, Colno: &col, AbsPath: &path}}, }} + + // transform without sourcemap store + str := "foo" tctx := &transform.Context{ - Config: transform.Config{SourcemapMapper: nil}, - Metadata: metadata.Metadata{ - Service: &metadata.Service{Name: &empty}, - }, + Config: transform.Config{SourcemapStore: nil}, + Metadata: metadata.Metadata{Service: &metadata.Service{Name: &str, Version: &str}}, } - trNoSmap := event.fields(tctx) - - event2 := Event{Exception: &Exception{ - Message: &exMsg, - Stacktrace: m.Stacktrace{ - &m.StacktraceFrame{Filename: "/a/b/c", Lineno: &lineno, Colno: &c1}, - }, - }} - mapper := sourcemap.SmapMapper{Accessor: &fakeAcc{}} + transformedNoSourcemap := event1.fields(tctx) - tctx.Config = transform.Config{SourcemapMapper: &mapper} - trWithSmap := event2.fields(tctx) + // transform with sourcemap store + store, err := sourcemap.NewStore(test.ESClientWithValidSourcemap(t), "apm-*sourcemap*", time.Minute) + require.NoError(t, err) + tctx.Config = transform.Config{SourcemapStore: store} + transformedWithSourcemap := event2.fields(tctx) - assert.Equal(t, 1, *event.Exception.Stacktrace[0].Lineno) + // ensure events have different line number and grouping keys + assert.Equal(t, 1, *event1.Exception.Stacktrace[0].Lineno) assert.Equal(t, 5, *event2.Exception.Stacktrace[0].Lineno) - - assert.NotEqual(t, trNoSmap["grouping_key"], trWithSmap["grouping_key"]) -} - -type fakeAcc struct{} - -func (ac *fakeAcc) Fetch(smapId sourcemap.Id) (*s.Consumer, error) { - file := "bundle.js.map" - current, _ := os.Getwd() - path := filepath.Join(current, "../../testdata/sourcemap/", file) - fileBytes, err := ioutil.ReadFile(path) - if err != nil { - return nil, err - } - return s.Parse("", fileBytes) + assert.NotEqual(t, transformedNoSourcemap["grouping_key"], transformedWithSourcemap["grouping_key"]) } -func (a *fakeAcc) Remove(smapId sourcemap.Id) {} diff --git a/model/sourcemap/payload.go b/model/sourcemap/payload.go index 02673a8155b..b76d02d73af 100644 --- a/model/sourcemap/payload.go +++ b/model/sourcemap/payload.go @@ -29,7 +29,6 @@ import ( logs "github.com/elastic/apm-server/log" "github.com/elastic/apm-server/model/sourcemap/generated/schema" - smap "github.com/elastic/apm-server/sourcemap" "github.com/elastic/apm-server/transform" "github.com/elastic/apm-server/utility" "github.com/elastic/apm-server/validation" @@ -66,14 +65,10 @@ func (pa *Sourcemap) Transform(tctx *transform.Context) []beat.Event { return nil } - if tctx.Config.SourcemapMapper == nil { + if tctx.Config.SourcemapStore == nil { logp.NewLogger(logs.Sourcemap).Error("Sourcemap Accessor is nil, cache cannot be invalidated.") } else { - tctx.Config.SourcemapMapper.NewSourcemapAdded(smap.Id{ - ServiceName: pa.ServiceName, - ServiceVersion: pa.ServiceVersion, - Path: pa.BundleFilepath, - }) + tctx.Config.SourcemapStore.Added(pa.ServiceName, pa.ServiceVersion, pa.BundleFilepath) } ev := beat.Event{ diff --git a/model/sourcemap/payload_test.go b/model/sourcemap/payload_test.go index aaeef1d5972..8904eda70c0 100644 --- a/model/sourcemap/payload_test.go +++ b/model/sourcemap/payload_test.go @@ -18,13 +18,20 @@ package sourcemap import ( + "net/http" "testing" "time" + "go.uber.org/zap/zapcore" + + "github.com/elastic/beats/libbeat/logp" + s "github.com/go-sourcemap/sourcemap" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + estest "github.com/elastic/apm-server/elasticsearch/test" + logs "github.com/elastic/apm-server/log" "github.com/elastic/apm-server/sourcemap" "github.com/elastic/apm-server/tests/loader" "github.com/elastic/apm-server/transform" @@ -95,43 +102,56 @@ func TestParseSourcemaps(t *testing.T) { } func TestInvalidateCache(t *testing.T) { + // load sourcemap from file and decode data, err := loader.LoadData("../testdata/sourcemap/payload.json") assert.NoError(t, err) - - smapId := sourcemap.Id{Path: "/tmp"} - smapMapper := smapMapperFake{ - c: map[string]*sourcemap.Mapping{ - "/tmp": &(sourcemap.Mapping{}), - }, - } - mapping, err := smapMapper.Apply(smapId, 0, 0) - require.NoError(t, err) - assert.NotNil(t, mapping) - - conf := transform.Config{SourcemapMapper: &smapMapper} - tctx := &transform.Context{Config: conf} - - sourcemap, err := DecodeSourcemap(data) - require.NoError(t, err) - sourcemap.Transform(tctx) - - sourcemap, err = DecodeSourcemap(data) - require.NoError(t, err) - sourcemap.Transform(tctx) - - mapping, err = smapMapper.Apply(smapId, 0, 0) + decoded, err := DecodeSourcemap(data) require.NoError(t, err) - assert.Nil(t, mapping) -} - -type smapMapperFake struct { - c map[string]*sourcemap.Mapping -} - -func (a *smapMapperFake) Apply(id sourcemap.Id, lineno, colno int) (*sourcemap.Mapping, error) { - return a.c[id.Path], nil -} - -func (sm *smapMapperFake) NewSourcemapAdded(id sourcemap.Id) { - sm.c = map[string]*sourcemap.Mapping{} + event := decoded.(*Sourcemap) + + t.Run("withSourcemapStore", func(t *testing.T) { + // collect logs + require.NoError(t, logp.DevelopmentSetup(logp.ToObserverOutput())) + + // create sourcemap store + client, err := estest.NewElasticsearchClient(estest.NewTransport(t, http.StatusOK, nil)) + require.NoError(t, err) + store, err := sourcemap.NewStore(client, "foo", time.Minute) + require.NoError(t, err) + + // transform with sourcemap store + event.Transform(&transform.Context{Config: transform.Config{SourcemapStore: store}}) + + logCollection := logp.ObserverLogs().TakeAll() + assert.Equal(t, 2, len(logCollection)) + + // first sourcemap was added + for i, entry := range logCollection { + assert.Equal(t, logs.Sourcemap, entry.LoggerName) + assert.Equal(t, zapcore.DebugLevel, entry.Level) + if i == 0 { + assert.Contains(t, entry.Message, "Added id service_1_js/bundle.js. Cache now has 1 entries.") + } else { + assert.Contains(t, entry.Message, "Removed id service_1_js/bundle.js. Cache now has 0 entries.") + } + } + + }) + + t.Run("noSourcemapStore", func(t *testing.T) { + // collect logs + require.NoError(t, logp.DevelopmentSetup(logp.ToObserverOutput())) + + // transform with sourcemap store + event.Transform(&transform.Context{Config: transform.Config{SourcemapStore: nil}}) + + logCollection := logp.ObserverLogs().TakeAll() + assert.Equal(t, 1, len(logCollection)) + for _, entry := range logCollection { + assert.Equal(t, logs.Sourcemap, entry.LoggerName) + assert.Equal(t, zapcore.ErrorLevel, entry.Level) + assert.Contains(t, entry.Message, "cache cannot be invalidated") + } + + }) } diff --git a/model/span/event_test.go b/model/span/event_test.go index 7af3a98cf99..9d1120005c0 100644 --- a/model/span/event_test.go +++ b/model/span/event_test.go @@ -24,6 +24,7 @@ import ( "testing" "time" + "github.com/elastic/apm-server/sourcemap" "github.com/elastic/apm-server/utility" "github.com/stretchr/testify/assert" @@ -33,7 +34,6 @@ import ( m "github.com/elastic/apm-server/model" "github.com/elastic/apm-server/model/metadata" - "github.com/elastic/apm-server/sourcemap" "github.com/elastic/apm-server/transform" ) @@ -104,7 +104,7 @@ func TestDecodeSpan(t *testing.T) { "name": name, "type": "db.postgresql.query.custom", "start": start, "duration": duration, "parent_id": parentId, "timestamp": timestampEpoch, "id": id, "trace_id": traceId, "stacktrace": []interface{}{"foo"}, }, - err: m.ErrInvalidStacktraceFrameType.Error(), + err: "invalid type for stacktrace frame", }, "minimal payload": { input: map[string]interface{}{ @@ -230,8 +230,8 @@ func TestDecodeSpan(t *testing.T) { func TestSpanTransform(t *testing.T) { path := "test/path" start := 0.65 - serviceName, env := "myService", "staging" - service := metadata.Service{Name: &serviceName, Environment: &env} + serviceName, serviceVersion, env := "myService", "1.2", "staging" + service := metadata.Service{Name: &serviceName, Version: &serviceVersion, Environment: &env} hexId, parentId, traceId := "0147258369012345", "abcdef0123456789", "01234567890123456789abcdefa" subtype := "myspansubtype" action := "myspanquery" @@ -319,7 +319,7 @@ func TestSpanTransform(t *testing.T) { } tctx := &transform.Context{ - Config: transform.Config{SourcemapMapper: &sourcemap.SmapMapper{}}, + Config: transform.Config{SourcemapStore: &sourcemap.Store{}}, Metadata: metadata.Metadata{Service: &service, Labels: metadataLabels}, RequestTime: timestamp, } diff --git a/model/stacktrace.go b/model/stacktrace.go index 763cf5ff306..d2f335b2c3f 100644 --- a/model/stacktrace.go +++ b/model/stacktrace.go @@ -20,15 +20,18 @@ package model import ( "errors" - logs "github.com/elastic/apm-server/log" - "github.com/elastic/beats/libbeat/common" "github.com/elastic/beats/libbeat/logp" + logs "github.com/elastic/apm-server/log" + "github.com/elastic/apm-server/transform" ) -var ErrInvalidStacktraceType = errors.New("invalid type for stacktrace") +var ( + errInvalidStacktraceType = errors.New("invalid type for stacktrace") + msgServiceInvalidForSourcemapping = "Cannot apply sourcemap without a service name or service version" +) type Stacktrace []*StacktraceFrame @@ -38,7 +41,7 @@ func DecodeStacktrace(input interface{}, err error) (*Stacktrace, error) { } raw, ok := input.([]interface{}) if !ok { - return nil, ErrInvalidStacktraceType + return nil, errInvalidStacktraceType } st := make(Stacktrace, len(raw)) for idx, fr := range raw { @@ -67,33 +70,44 @@ func (st *Stacktrace) Transform(tctx *transform.Context) []common.MapStr { // - lineno // - abs_path is set to the cleaned abs_path // - sourcmeap.updated is set to true + + if tctx.Config.SourcemapStore == nil { + return st.transform(tctx, noSourcemapping) + } + if tctx.Metadata.Service == nil || tctx.Metadata.Service.Name == nil || tctx.Metadata.Service.Version == nil { + logp.NewLogger(logs.Stacktrace).Warn(msgServiceInvalidForSourcemapping) + return st.transform(tctx, noSourcemapping) + } + + var errMsg string + var sourcemapErrorSet = map[string]interface{}{} + logger := logp.NewLogger(logs.Stacktrace) + fct := "" + return st.transform(tctx, func(frame *StacktraceFrame) { + fct, errMsg = frame.applySourcemap(tctx.Config.SourcemapStore, tctx.Metadata.Service, fct) + if errMsg != "" { + if _, ok := sourcemapErrorSet[errMsg]; !ok { + logger.Warn(errMsg) + sourcemapErrorSet[errMsg] = nil + } + } + }) +} + +func (st *Stacktrace) transform(ctx *transform.Context, apply func(*StacktraceFrame)) []common.MapStr { frameCount := len(*st) if frameCount == 0 { return nil } + var fr *StacktraceFrame frames := make([]common.MapStr, frameCount) - - fct := "" - var sourcemapErrorSet = make(map[string]struct{}) - for idx := frameCount - 1; idx >= 0; idx-- { fr = (*st)[idx] - if tctx.Config.SourcemapMapper != nil && tctx.Metadata.Service != nil { - var errMsg string - fct, errMsg = fr.applySourcemap(tctx.Config.SourcemapMapper, tctx.Metadata.Service, fct) - sourcemapErrorSet[errMsg] = struct{}{} - } - frames[idx] = fr.Transform(tctx) + apply(fr) + frames[idx] = fr.Transform(ctx) } - if len(sourcemapErrorSet) > 0 { - logger := logp.NewLogger(logs.Stacktrace) - for errMsg := range sourcemapErrorSet { - if errMsg != "" { - logger.Warn(errMsg) - } - } - } - return frames } + +func noSourcemapping(_ *StacktraceFrame) {} diff --git a/model/stacktrace_frame.go b/model/stacktrace_frame.go index 637abc34b87..a3aea97e3de 100644 --- a/model/stacktrace_frame.go +++ b/model/stacktrace_frame.go @@ -18,14 +18,27 @@ package model import ( - "errors" + "fmt" "regexp" + "github.com/pkg/errors" + + "github.com/elastic/beats/libbeat/common" + "github.com/elastic/apm-server/model/metadata" "github.com/elastic/apm-server/sourcemap" "github.com/elastic/apm-server/transform" "github.com/elastic/apm-server/utility" - "github.com/elastic/beats/libbeat/common" +) + +const ( + errMsgSourcemapColumnMandatory = "Colno mandatory for sourcemapping." + errMsgSourcemapLineMandatory = "Lineno mandatory for sourcemapping." + errMsgSourcemapPathMandatory = "AbsPath mandatory for sourcemapping." +) + +var ( + errInvalidStacktraceFrameType = errors.New("invalid type for stacktrace frame") ) type StacktraceFrame struct { @@ -63,15 +76,13 @@ type Original struct { sourcemapCopied bool } -var ErrInvalidStacktraceFrameType = errors.New("invalid type for stacktrace frame") - func DecodeStacktraceFrame(input interface{}, err error) (*StacktraceFrame, error) { if input == nil || err != nil { return nil, err } raw, ok := input.(map[string]interface{}) if !ok { - return nil, ErrInvalidStacktraceFrameType + return nil, errInvalidStacktraceFrameType } decoder := utility.ManualDecoder{} frame := StacktraceFrame{ @@ -156,50 +167,66 @@ func (s *StacktraceFrame) setLibraryFrame(pattern *regexp.Regexp) { s.LibraryFrame = &libraryFrame } -func (s *StacktraceFrame) applySourcemap(mapper sourcemap.Mapper, service *metadata.Service, prevFunction string) (string, string) { - s.setOriginalSourcemapData() +func (s *StacktraceFrame) applySourcemap(store *sourcemap.Store, service *metadata.Service, prevFunction string) (function string, errMsg string) { + function = prevFunction - if s.Original.Colno == nil { - errMsg := "Colno mandatory for sourcemapping." - s.updateError(errMsg) - return prevFunction, errMsg - } - if s.Original.Lineno == nil { - errMsg := "Lineno mandatory for sourcemapping." + var valid bool + if valid, errMsg = s.validForSourcemapping(); !valid { s.updateError(errMsg) - return prevFunction, errMsg + return } - sourcemapId, errMsg := s.buildSourcemapId(service) - if errMsg != "" { - return prevFunction, errMsg - } - mapping, err := mapper.Apply(sourcemapId, *s.Original.Lineno, *s.Original.Colno) + s.setOriginalSourcemapData() + + path := utility.CleanUrlPath(*s.Original.AbsPath) + mapper, err := store.Fetch(*service.Name, *service.Version, path) if err != nil { - e, isSourcemapError := err.(sourcemap.Error) - if !isSourcemapError || e.Kind == sourcemap.MapError || e.Kind == sourcemap.KeyError { + if errors.Cause(err) == sourcemap.ErrNoSourcemapFound { s.updateError(err.Error()) } - return prevFunction, err.Error() + errMsg = err.Error() + return } - if mapping.Filename != "" { - s.Filename = mapping.Filename + file, fct, line, col, ctxLine, preCtx, postCtx, ok := mapper.Apply(*s.Original.Lineno, *s.Original.Colno) + if !ok { + errMsg = fmt.Sprintf("No Sourcemap found for Lineno %v, Colno %v", *s.Original.Lineno, *s.Original.Colno) + s.updateError(errMsg) + return + } + + if file != "" { + s.Filename = file } - s.Colno = &mapping.Colno - s.Lineno = &mapping.Lineno - s.AbsPath = &mapping.Path + s.Colno = &col + s.Lineno = &line + s.AbsPath = &path s.updateSmap(true) s.Function = &prevFunction - s.ContextLine = &mapping.ContextLine - s.PreContext = mapping.PreContext - s.PostContext = mapping.PostContext + s.ContextLine = &ctxLine + s.PreContext = preCtx + s.PostContext = postCtx + + if fct != "" { + function = fct + return + } + function = "" + return +} - if mapping.Function != "" { - return mapping.Function, "" +func (s *StacktraceFrame) validForSourcemapping() (bool, string) { + if s.Colno == nil { + return false, errMsgSourcemapColumnMandatory + } + if s.Lineno == nil { + return false, errMsgSourcemapLineMandatory } - return "", "" + if s.AbsPath == nil { + return false, errMsgSourcemapPathMandatory + } + return true, "" } func (s *StacktraceFrame) setOriginalSourcemapData() { @@ -215,20 +242,6 @@ func (s *StacktraceFrame) setOriginalSourcemapData() { s.Original.sourcemapCopied = true } -func (s *StacktraceFrame) buildSourcemapId(service *metadata.Service) (sourcemap.Id, string) { - if service.Name == nil { - return sourcemap.Id{}, "Cannot apply sourcemap without a service name." - } - id := sourcemap.Id{ServiceName: *service.Name} - if service.Version != nil { - id.ServiceVersion = *service.Version - } - if s.AbsPath != nil { - id.Path = utility.CleanUrlPath(*s.AbsPath) - } - return id, "" -} - func (s *StacktraceFrame) updateError(errMsg string) { s.Sourcemap.Error = &errMsg s.updateSmap(false) diff --git a/model/stacktrace_frame_test.go b/model/stacktrace_frame_test.go index 8c2b0591388..859fdc28fc4 100644 --- a/model/stacktrace_frame_test.go +++ b/model/stacktrace_frame_test.go @@ -22,13 +22,16 @@ import ( "fmt" "regexp" "testing" + "time" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/stretchr/testify/assert" + "github.com/elastic/go-elasticsearch/v8" "github.com/elastic/apm-server/model/metadata" "github.com/elastic/apm-server/sourcemap" + "github.com/elastic/apm-server/sourcemap/test" "github.com/elastic/apm-server/transform" "github.com/elastic/apm-server/utility" @@ -48,7 +51,7 @@ func TestStacktraceFrameDecode(t *testing.T) { }{ {input: nil, err: nil, s: nil}, {input: nil, inpErr: errors.New("a"), err: errors.New("a"), s: nil}, - {input: "", err: ErrInvalidStacktraceFrameType, s: nil}, + {input: "", err: errInvalidStacktraceFrameType, s: nil}, { input: map[string]interface{}{}, err: utility.ErrFetch, @@ -159,177 +162,139 @@ func TestStacktraceFrameTransform(t *testing.T) { } } -func TestApplySourcemap(t *testing.T) { - colno := 1 - l0, l5, l6, l7, l8, l9 := 0, 5, 6, 7, 8, 9 - fct := "original function" - absPath := "original path" - tests := []struct { - fr StacktraceFrame - lineno, colno int - filename, function, absPath string - smapUpdated bool - smapError string - fct string - outFct string - msg string - }{ - { - fr: StacktraceFrame{Lineno: &l0, Function: &fct, AbsPath: &absPath}, - lineno: l0, - filename: "", - function: "original function", - absPath: "original path", - smapUpdated: false, - smapError: "Colno mandatory for sourcemapping.", - fct: "", - outFct: "", - msg: "No colno", - }, - { - fr: StacktraceFrame{ - Colno: &colno, - Lineno: &l9, - Filename: "filename", - Function: &fct, - AbsPath: &absPath, - }, - colno: 1, - lineno: l9, - filename: "filename", - function: "original function", - absPath: "original path", - smapUpdated: false, - smapError: "Some untyped error", - fct: "", - outFct: "", - msg: "Some error occured in mapper.", - }, - { - fr: StacktraceFrame{Colno: &colno, Lineno: &l8, Function: &fct, AbsPath: &absPath}, - colno: 1, - lineno: l8, - filename: "", - function: "original function", - absPath: "original path", - fct: "", - outFct: "", - msg: "Some access error occured in mapper.", - }, - { - fr: StacktraceFrame{Colno: &colno, Lineno: &l7, Function: &fct, AbsPath: &absPath}, - colno: 1, - lineno: l7, - filename: "", - function: "original function", - absPath: "original path", - smapUpdated: false, - smapError: "Some mapping error", - fct: "", - outFct: "", - msg: "Some mapping error occured in mapper.", - }, - { - fr: StacktraceFrame{Colno: &colno, Lineno: &l6, Function: &fct, AbsPath: &absPath}, - colno: 1, - lineno: l6, - filename: "", - function: "original function", - absPath: "original path", - smapUpdated: false, - smapError: "Some key error", - fct: "", - outFct: "", - msg: "Some key error occured in mapper.", - }, - { - fr: StacktraceFrame{ - Colno: &colno, - Lineno: &l5, - Filename: "original filename", - Function: &fct, - AbsPath: &absPath, - }, - colno: 100, - lineno: 500, - filename: "original filename", - function: "other function", - absPath: "changed path", - smapUpdated: true, - - fct: "other function", - outFct: "", - msg: "Sourcemap with empty filename and function mapping applied.", - }, - { - fr: StacktraceFrame{ - Colno: &colno, - Lineno: &l0, - Filename: "original filename", - Function: &fct, - AbsPath: &absPath, - }, - colno: 100, - lineno: 400, - filename: "changed filename", - function: "prev function", - absPath: "changed path", - smapUpdated: true, +func TestSourcemap_Apply(t *testing.T) { - fct: "prev function", - outFct: "changed function", - msg: "Full sourcemap mapping applied.", - }, + name, version, col, line, path := "myservice", "2.1.4", 10, 15, "/../a/path" + validService := func() *metadata.Service { + return &metadata.Service{Name: &name, Version: &version} + } + validFrame := func() *StacktraceFrame { + return &StacktraceFrame{Colno: &col, Lineno: &line, AbsPath: &path} } - ver, name := "1", "foo" - service := &metadata.Service{Name: &name, Version: &ver} - for idx, test := range tests { - // check that original data are preserved, - // even when Transform function is applied twice. - if test.smapUpdated { - origAbsPath := *test.fr.AbsPath - origFilename := test.fr.Filename - origLineno := test.fr.Lineno - origColno := test.fr.Colno - origFunction := test.fr.Function - - (&test.fr).applySourcemap(&FakeMapper{}, service, test.fct) - (&test.fr).applySourcemap(&FakeMapper{}, service, test.fct) + t.Run("frame", func(t *testing.T) { + for name, tc := range map[string]struct { + frame *StacktraceFrame - assert.Equal(t, origAbsPath, *test.fr.Original.AbsPath) - assert.Equal(t, origFilename, test.fr.Original.Filename) - assert.Equal(t, origLineno, test.fr.Original.Lineno) - if origColno == nil { - assert.Nil(t, test.fr.Original.Colno) - } else { - assert.Equal(t, *origColno, *test.fr.Original.Colno) - } - if origFunction == nil { - assert.Nil(t, test.fr.Original.Function) - } else { - assert.Equal(t, *origFunction, *test.fr.Original.Function) - } + expectedErrorMsg string + }{ + "noColumn": { + frame: &StacktraceFrame{}, + expectedErrorMsg: "Colno mandatory"}, + "noLine": { + frame: &StacktraceFrame{Colno: &col}, + expectedErrorMsg: "Lineno mandatory"}, + "noPath": { + frame: &StacktraceFrame{Colno: &col, Lineno: &line}, + expectedErrorMsg: "AbsPath mandatory", + }, + } { + t.Run(name, func(t *testing.T) { + function, msg := tc.frame.applySourcemap(&sourcemap.Store{}, validService(), "foo") + assert.Equal(t, "foo", function) + assert.Contains(t, msg, tc.expectedErrorMsg) + assert.Equal(t, new(bool), tc.frame.Sourcemap.Updated) + require.NotNil(t, tc.frame.Sourcemap.Error) + assert.Contains(t, *tc.frame.Sourcemap.Error, msg) + assert.Zero(t, tc.frame.Original) + }) } + }) - // check that source mapping is applied as expected - output, errMsg := (&test.fr).applySourcemap(&FakeMapper{}, service, test.fct) - assert.Equal(t, test.smapError, errMsg) - assert.Equal(t, test.outFct, output) - assert.Equal(t, test.lineno, *test.fr.Lineno, fmt.Sprintf("Failed at idx %v; %s", idx, test.msg)) - assert.Equal(t, test.filename, test.fr.Filename, fmt.Sprintf("Failed at idx %v; %s", idx, test.msg)) - assert.Equal(t, test.function, *test.fr.Function, fmt.Sprintf("Failed at idx %v; %s", idx, test.msg)) - assert.Equal(t, test.absPath, *test.fr.AbsPath, fmt.Sprintf("Failed at idx %v; %s", idx, test.msg)) - if test.colno != 0 { - assert.Equal(t, test.colno, *test.fr.Colno, fmt.Sprintf("Failed at idx %v; %s", idx, test.msg)) + t.Run("errorPerFrame", func(t *testing.T) { + for name, tc := range map[string]struct { + store *sourcemap.Store + expectedErrorMsg string + }{ + "noSourcemap": {store: testSourcemapStore(t, test.ESClientWithSourcemapNotFound(t)), + expectedErrorMsg: "No Sourcemap available"}, + "noMapping": {store: testSourcemapStore(t, test.ESClientWithValidSourcemap(t)), + expectedErrorMsg: "No Sourcemap found for Lineno", + }, + } { + t.Run(name, func(t *testing.T) { + frame := validFrame() + function, msg := frame.applySourcemap(tc.store, validService(), "xyz") + assert.Equal(t, "xyz", function) + require.Contains(t, msg, tc.expectedErrorMsg) + assert.NotZero(t, frame.Sourcemap.Error) + assert.Equal(t, new(bool), frame.Sourcemap.Updated) + }) } - if test.smapError != "" || test.smapUpdated { - assert.Equal(t, test.smapUpdated, *test.fr.Sourcemap.Updated, fmt.Sprintf("Failed at idx %v; %s", idx, test.msg)) + }) + + t.Run("mappingError", func(t *testing.T) { + for name, tc := range map[string]struct { + store *sourcemap.Store + expectedErrorMsg string + }{ + "ESUnavailable": {store: testSourcemapStore(t, test.ESClientUnavailable(t)), + expectedErrorMsg: "Internal server error"}, + "invalidSourcemap": {store: testSourcemapStore(t, test.ESClientWithInvalidSourcemap(t)), + expectedErrorMsg: "Could not parse Sourcemap."}, + "unsupportedSourcemap": {store: testSourcemapStore(t, test.ESClientWithUnsupportedSourcemap(t)), + expectedErrorMsg: "only 3rd version is supported"}, + } { + t.Run(name, func(t *testing.T) { + frame := validFrame() + function, msg := frame.applySourcemap(tc.store, validService(), "xyz") + assert.Equal(t, "xyz", function) + require.Contains(t, msg, tc.expectedErrorMsg) + assert.NotZero(t, msg) + assert.Zero(t, frame.Sourcemap) + }) } - if test.smapError != "" { - assert.Equal(t, test.smapError, *test.fr.Sourcemap.Error, fmt.Sprintf("Failed at idx %v; %s", idx, test.msg)) + }) + + t.Run("mapping", func(t *testing.T) { + + for name, tc := range map[string]struct { + origCol, origLine int + origPath string + + function, file, path, ctxLine string + preCtx, postCtx []string + col, line int + }{ + "withFunction": {origCol: 67, origLine: 1, origPath: "/../a/path", + function: "exports", file: "", path: "/a/path", ctxLine: " \t\t\texports: {},", col: 0, line: 13, + preCtx: []string{" \t\tif(installedModules[moduleId])", " \t\t\treturn installedModules[moduleId].exports;", "", " \t\t// Create a new module (and put it into the cache)", " \t\tvar module = installedModules[moduleId] = {"}, + postCtx: []string{" \t\t\tid: moduleId,", " \t\t\tloaded: false", " \t\t};", "", " \t\t// Execute the module function"}}, + "withFilename": {origCol: 7, origLine: 1, origPath: "/../a/path", + function: "", file: "webpack:///bundle.js", path: "/a/path", + ctxLine: "/******/ (function(modules) { // webpackBootstrap", preCtx: []string{}, + postCtx: []string{"/******/ \t// The module cache", "/******/ \tvar installedModules = {};", "/******/", "/******/ \t// The require function", "/******/ \tfunction __webpack_require__(moduleId) {"}, + col: 9, line: 1}, + "withoutFilename": {origCol: 23, origLine: 1, origPath: "/../a/path", + function: "__webpack_require__", file: "", path: "/a/path", ctxLine: " \tfunction __webpack_require__(moduleId) {", + preCtx: []string{" \t// The module cache", " \tvar installedModules = {};", "", " \t// The require function"}, + postCtx: []string{"", " \t\t// Check if module is in cache", " \t\tif(installedModules[moduleId])", " \t\t\treturn installedModules[moduleId].exports;", ""}, + col: 0, line: 5}, + } { + t.Run(name, func(t *testing.T) { + frame := &StacktraceFrame{Colno: &tc.origCol, Lineno: &tc.origLine, AbsPath: &tc.origPath} + + prevFunction := "xyz" + function, msg := frame.applySourcemap(testSourcemapStore(t, test.ESClientWithValidSourcemap(t)), validService(), prevFunction) + require.Empty(t, msg) + assert.Zero(t, frame.Sourcemap.Error) + updated := true + assert.Equal(t, &updated, frame.Sourcemap.Updated) + + assert.Equal(t, tc.function, function) + assert.Equal(t, tc.file, frame.Filename) + assert.Equal(t, prevFunction, *frame.Function) + assert.Equal(t, tc.col, *frame.Colno) + assert.Equal(t, tc.line, *frame.Lineno) + assert.Equal(t, tc.path, *frame.AbsPath) + assert.Equal(t, tc.ctxLine, *frame.ContextLine) + assert.Equal(t, tc.preCtx, frame.PreContext) + assert.Equal(t, tc.postCtx, frame.PostContext) + + assert.NotZero(t, frame.Original) + }) } - } + }) } func TestIsLibraryFrame(t *testing.T) { @@ -514,63 +479,8 @@ func TestLibraryFrame(t *testing.T) { } } -func TestBuildSourcemap(t *testing.T) { - version := "1.0" - path := "././a/b/../c" - serviceName, empty := "foo", "" - tests := []struct { - service metadata.Service - fr StacktraceFrame - out string - err string - }{ - {service: metadata.Service{}, fr: StacktraceFrame{}, out: "", err: "Cannot apply sourcemap without a service name."}, - {service: metadata.Service{Version: &version, Name: &empty}, fr: StacktraceFrame{}, out: "1.0"}, - {service: metadata.Service{Name: &serviceName}, fr: StacktraceFrame{}, out: "foo"}, - {service: metadata.Service{Name: &empty}, fr: StacktraceFrame{AbsPath: &path}, out: "a/c"}, - { - service: metadata.Service{Name: &serviceName, Version: &version}, - fr: StacktraceFrame{AbsPath: &path}, - out: "foo_1.0_a/c", - }, - } - for _, test := range tests { - id, errStr := test.fr.buildSourcemapId(&test.service) - require.Equal(t, test.err, errStr) - assert.Equal(t, test.out, (&id).Key()) - } -} - -// Fake implemenations for Mapper - -type FakeMapper struct{} - -func (m *FakeMapper) Apply(smapId sourcemap.Id, lineno, colno int) (*sourcemap.Mapping, error) { - switch lineno { - case 9: - return nil, errors.New("Some untyped error") - case 8: - return nil, sourcemap.Error{Kind: sourcemap.AccessError} - case 7: - return nil, sourcemap.Error{Kind: sourcemap.MapError, Msg: "Some mapping error"} - case 6: - return nil, sourcemap.Error{Kind: sourcemap.KeyError, Msg: "Some key error"} - case 5: - return &sourcemap.Mapping{ - Filename: "", - Function: "", - Colno: 100, - Lineno: 500, - Path: "changed path", - }, nil - default: - return &sourcemap.Mapping{ - Filename: "changed filename", - Function: "changed function", - Colno: 100, - Lineno: 400, - Path: "changed path", - }, nil - } +func testSourcemapStore(t *testing.T, client *elasticsearch.Client) *sourcemap.Store { + store, err := sourcemap.NewStore(client, "apm-*sourcemap*", time.Minute) + require.NoError(t, err) + return store } -func (m *FakeMapper) NewSourcemapAdded(smapId sourcemap.Id) {} diff --git a/model/stacktrace_test.go b/model/stacktrace_test.go index 9695c274a7d..8f7aae38c57 100644 --- a/model/stacktrace_test.go +++ b/model/stacktrace_test.go @@ -24,9 +24,11 @@ import ( "github.com/stretchr/testify/assert" + "github.com/elastic/beats/libbeat/common" + "github.com/elastic/apm-server/model/metadata" + "github.com/elastic/apm-server/sourcemap/test" "github.com/elastic/apm-server/transform" - "github.com/elastic/beats/libbeat/common" ) func TestStacktraceDecode(t *testing.T) { @@ -41,7 +43,7 @@ func TestStacktraceDecode(t *testing.T) { {input: "", err: errors.New("invalid type for stacktrace"), s: nil}, { input: []interface{}{"foo"}, - err: ErrInvalidStacktraceFrameType, + err: errInvalidStacktraceFrameType, s: &Stacktrace{nil}, }, { @@ -155,23 +157,21 @@ func TestStacktraceTransform(t *testing.T) { } func TestStacktraceTransformWithSourcemapping(t *testing.T) { - colno := 1 - l4, l5, l6, l8 := 4, 5, 6, 8 - fct := "original function" - absPath, serviceName := "original path", "service1" - service := metadata.Service{Name: &serviceName} + int1, int6, int7, int67 := 1, 6, 7, 67 + fct1, fct2 := "function foo", "function bar" + absPath, serviceName, serviceVersion := "/../a/c", "service1", "2.4.1" + service := metadata.Service{Name: &serviceName, Version: &serviceVersion} - tests := []struct { + for name, tc := range map[string]struct { Stacktrace Stacktrace Output []common.MapStr Msg string }{ - { + "emptyStacktrace": { Stacktrace: Stacktrace{}, Output: nil, - Msg: "Empty Stacktrace", }, - { + "emptyFrame": { Stacktrace: Stacktrace{&StacktraceFrame{}}, Output: []common.MapStr{ {"filename": "", @@ -182,10 +182,9 @@ func TestStacktraceTransformWithSourcemapping(t *testing.T) { }, }, }, - Msg: "Stacktrace with empty Frame", }, - { - Stacktrace: Stacktrace{&StacktraceFrame{Colno: &colno}}, + "noLineno": { + Stacktrace: Stacktrace{&StacktraceFrame{Colno: &int1}}, Output: []common.MapStr{ {"filename": "", "line": common.MapStr{"column": 1}, @@ -196,97 +195,115 @@ func TestStacktraceTransformWithSourcemapping(t *testing.T) { }, }, }, - Msg: "Stacktrace with no lineno", }, - { + "sourcemapApplied": { Stacktrace: Stacktrace{ &StacktraceFrame{ - Colno: &colno, - Lineno: &l4, + Colno: &int7, + Lineno: &int1, Filename: "original filename", - Function: &fct, + Function: &fct1, AbsPath: &absPath, }, - &StacktraceFrame{Colno: &colno, Lineno: &l6, Function: &fct, AbsPath: &absPath}, - &StacktraceFrame{Colno: &colno, Lineno: &l8, Function: &fct, AbsPath: &absPath}, &StacktraceFrame{ - Colno: &colno, - Lineno: &l5, - Filename: "original filename", - Function: &fct, + Colno: &int67, + Lineno: &int1, + Filename: "myfilename", + Function: &fct2, AbsPath: &absPath, }, &StacktraceFrame{ - Colno: &colno, - Lineno: &l4, - Filename: "/webpack", + Colno: &int7, + Lineno: &int1, + Filename: "myfilename", + Function: &fct2, AbsPath: &absPath, }, + &StacktraceFrame{Colno: &int1, Lineno: &int6, Function: &fct2, AbsPath: &absPath}, }, Output: []common.MapStr{ { - "abs_path": "changed path", "filename": "changed filename", "function": "", - "line": common.MapStr{"column": 100, "number": 400, "context": ""}, + "abs_path": "/a/c", + "filename": "webpack:///bundle.js", + "function": "exports", + "context": common.MapStr{ + "post": []string{"/******/ \t// The module cache", "/******/ \tvar installedModules = {};", "/******/", "/******/ \t// The require function", "/******/ \tfunction __webpack_require__(moduleId) {"}}, + "line": common.MapStr{ + "column": 9, + "number": 1, + "context": "/******/ (function(modules) { // webpackBootstrap"}, "exclude_from_grouping": false, "sourcemap": common.MapStr{"updated": true}, "original": common.MapStr{ - "abs_path": "original path", - "colno": 1, + "abs_path": "/../a/c", + "colno": 7, "filename": "original filename", - "function": "original function", - "lineno": 4, + "function": "function foo", + "lineno": 1, }, }, { - "abs_path": "original path", "filename": "", "function": "original function", - "line": common.MapStr{"column": 1, "number": 6}, - "exclude_from_grouping": false, - "sourcemap": common.MapStr{"updated": false, "error": "Some key error"}, - }, - { - "abs_path": "original path", "filename": "", "function": "original function", - "line": common.MapStr{"column": 1, "number": 8}, - "exclude_from_grouping": false, - }, - { - "abs_path": "changed path", "filename": "original filename", "function": "changed function", - "line": common.MapStr{"column": 100, "number": 500, "context": ""}, + "abs_path": "/a/c", + "filename": "myfilename", + "function": "", //prev function + "context": common.MapStr{ + "post": []string{" \t\t\tid: moduleId,", " \t\t\tloaded: false", " \t\t};", "", " \t\t// Execute the module function"}, + "pre": []string{" \t\tif(installedModules[moduleId])", " \t\t\treturn installedModules[moduleId].exports;", "", " \t\t// Create a new module (and put it into the cache)", " \t\tvar module = installedModules[moduleId] = {"}}, + "line": common.MapStr{ + "column": 0, + "number": 13, + "context": " \t\t\texports: {},"}, "exclude_from_grouping": false, "sourcemap": common.MapStr{"updated": true}, "original": common.MapStr{ - "abs_path": "original path", - "colno": 1, - "filename": "original filename", - "function": "original function", - "lineno": 5, + "abs_path": "/../a/c", + "colno": 67, + "filename": "myfilename", + "function": "function bar", + "lineno": 1, }, }, { - "abs_path": "changed path", "filename": "changed filename", "function": "", - "line": common.MapStr{"column": 100, "number": 400, "context": ""}, + "abs_path": "/a/c", + "filename": "webpack:///bundle.js", + "function": "", //prev function + "context": common.MapStr{ + "post": []string{"/******/ \t// The module cache", "/******/ \tvar installedModules = {};", "/******/", "/******/ \t// The require function", "/******/ \tfunction __webpack_require__(moduleId) {"}}, + "line": common.MapStr{ + "column": 9, + "number": 1, + "context": "/******/ (function(modules) { // webpackBootstrap"}, "exclude_from_grouping": false, "sourcemap": common.MapStr{"updated": true}, "original": common.MapStr{ - "abs_path": "original path", - "colno": 1, - "filename": "/webpack", - "lineno": 4, + "abs_path": "/../a/c", + "colno": 7, + "filename": "myfilename", + "function": "function bar", + "lineno": 1, }, }, + { + "abs_path": "/../a/c", + "filename": "", + "function": fct2, + "line": common.MapStr{"column": 1, "number": 6}, + "exclude_from_grouping": false, + "sourcemap": common.MapStr{"updated": false, "error": "No Sourcemap found for Lineno 6, Colno 1"}, + }, }, - Msg: "Stacktrace with sourcemapping", }, - } - - for idx, test := range tests { - tctx := &transform.Context{ - Config: transform.Config{SourcemapMapper: &FakeMapper{}}, - Metadata: metadata.Metadata{Service: &service}, - } + } { + t.Run(name, func(t *testing.T) { + tctx := &transform.Context{ + Config: transform.Config{SourcemapStore: testSourcemapStore(t, test.ESClientWithValidSourcemap(t))}, + Metadata: metadata.Metadata{Service: &service}, + } - // run `Stacktrace.Transform` twice to ensure method is idempotent - test.Stacktrace.Transform(tctx) - output := test.Stacktrace.Transform(tctx) - assert.Equal(t, test.Output, output, fmt.Sprintf("Failed at idx %v; %s", idx, test.Msg)) + // run `Stacktrace.Transform` twice to ensure method is idempotent + tc.Stacktrace.Transform(tctx) + output := tc.Stacktrace.Transform(tctx) + assert.Equal(t, tc.Output, output) + }) } } diff --git a/sourcemap/accessor.go b/sourcemap/accessor.go deleted file mode 100644 index b956e29b80f..00000000000 --- a/sourcemap/accessor.go +++ /dev/null @@ -1,87 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package sourcemap - -import ( - "fmt" - - "github.com/go-sourcemap/sourcemap" -) - -type Accessor interface { - Fetch(id Id) (*sourcemap.Consumer, error) - Remove(id Id) -} - -type SmapAccessor struct { - es elasticsearch - cache *cache -} - -func NewSmapAccessor(config Config) (*SmapAccessor, error) { - es, err := NewElasticsearch(config.ElasticsearchConfig, config.Index) - if err != nil { - return nil, err - } - cache, err := newCache(config.CacheExpiration) - if err != nil { - return nil, err - } - return &SmapAccessor{ - es: es, - cache: cache, - }, nil -} - -func (s *SmapAccessor) Fetch(id Id) (*sourcemap.Consumer, error) { - if !id.Valid() { - return nil, Error{ - Msg: fmt.Sprintf("Sourcemap Key Error for %v", id.String()), - Kind: KeyError, - } - } - consumer, found := s.cache.fetch(id) - if consumer != nil { - // avoid fetching ES again when key was already queried - // but no Sourcemap was found for it. - return consumer, nil - } - if found { - return nil, errSmapNotAvailable(id) - } - consumer, err := s.es.fetch(id) - if err != nil { - return nil, err - } - s.cache.add(id, consumer) - if consumer == nil { - return nil, errSmapNotAvailable(id) - } - return consumer, nil -} - -func (s *SmapAccessor) Remove(id Id) { - s.cache.remove(id) -} - -func errSmapNotAvailable(id Id) Error { - return Error{ - Msg: fmt.Sprintf("No Sourcemap available for %v.", id.String()), - Kind: MapError, - } -} diff --git a/sourcemap/accessor_test.go b/sourcemap/accessor_test.go deleted file mode 100644 index ad3c69abb83..00000000000 --- a/sourcemap/accessor_test.go +++ /dev/null @@ -1,184 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package sourcemap - -import ( - "io/ioutil" - "os" - "path/filepath" - "testing" - "time" - - "github.com/go-sourcemap/sourcemap" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestNewSmapAccessor(t *testing.T) { - // Init problem with Elasticsearch - smapAcc, err := NewSmapAccessor(Config{}) - assert.Nil(t, smapAcc) - require.Error(t, err) - assert.Equal(t, (err.(Error)).Kind, InitError) - assert.Contains(t, err.Error(), "ES Client cannot be initialized") - - // Init problem with cache - config := Config{ElasticsearchConfig: getFakeESConfig(nil), CacheExpiration: -1} - smapAcc, err = NewSmapAccessor(config) - assert.Nil(t, smapAcc) - require.Error(t, err) - assert.Equal(t, (err.(Error)).Kind, InitError) - assert.Contains(t, err.Error(), "Cache cannot be initialized") - - // Init ok - minimalConfig := Config{ElasticsearchConfig: getFakeESConfig(nil)} - smapAcc, err = NewSmapAccessor(minimalConfig) - require.NoError(t, err) - assert.NotNil(t, smapAcc.es) - assert.NotNil(t, smapAcc.cache) - - smapAcc, err = NewSmapAccessor(getFakeConfig()) - require.NoError(t, err) - assert.NotNil(t, smapAcc.es) - assert.NotNil(t, smapAcc.cache) -} - -func TestFetchKeyError(t *testing.T) { - id := Id{Path: "/tmp"} - smapAcc, err := NewSmapAccessor(getFakeConfig()) - require.NoError(t, err) - c, err := smapAcc.Fetch(id) - require.Error(t, err) - assert.Equal(t, (err.(Error)).Kind, KeyError) - assert.Nil(t, c) -} - -func TestFetchAccessError(t *testing.T) { - smapAcc, err := NewSmapAccessor(getFakeConfig()) - require.NoError(t, err) - c, err := smapAcc.Fetch(getFakeId()) - require.Error(t, err) - assert.Equal(t, (err.(Error)).Kind, AccessError) - assert.Nil(t, c) -} - -func TestFetchAndCaching(t *testing.T) { - id := getFakeId() - smapAcc, err := NewSmapAccessor(getFakeConfig()) - require.NoError(t, err) - smapAcc.es = &FakeESAccessor{} - - // at the beginning cache is empty - cached, found := smapAcc.cache.fetch(id) - assert.Nil(t, cached) - assert.False(t, found) - - // smap fetched from ES - c, err := smapAcc.Fetch(id) - require.NoError(t, err) - assert.NotNil(t, c) - - // ensure that smap is cached - cached, found = smapAcc.cache.fetch(id) - assert.NotNil(t, cached) - assert.True(t, found) - assert.Equal(t, c, cached) -} - -func TestFetchCacheEmptyValueWhenSmapNotFound(t *testing.T) { - smapAcc, err := NewSmapAccessor(getFakeConfig()) - require.NoError(t, err) - smapAcc.es = &FakeESAccessor{} - id := Id{Path: "/tmp/123", ServiceName: "foo", ServiceVersion: "bar"} - - // at the beginning cache is empty - cached, found := smapAcc.cache.fetch(id) - assert.Nil(t, cached) - assert.False(t, found) - - // no smap found for given id when fetching from ES - c, err := smapAcc.Fetch(id) - assert.Nil(t, c) - require.Error(t, err) - assert.Contains(t, err.Error(), "No Sourcemap available") - assert.Equal(t, (err.(Error)).Kind, MapError) - - // check that cache value is now set with null value - cached, found = smapAcc.cache.fetch(id) - assert.Nil(t, cached) - assert.True(t, found) - - // check that error is returned also when empty value is fetched from cache - c, err = smapAcc.Fetch(id) - require.Error(t, err) - assert.Nil(t, c) - assert.Contains(t, err.Error(), "No Sourcemap available") - assert.Equal(t, (err.(Error)).Kind, MapError) -} - -func TestSourcemapRemovedFromCache(t *testing.T) { - id := getFakeId() - smap := getFakeSmap() - - smapAcc, err := NewSmapAccessor(getFakeConfig()) - require.NoError(t, err) - smapAcc.cache.add(id, smap) - cached, found := smapAcc.cache.fetch(id) - assert.True(t, found) - assert.Equal(t, smap, cached) - - smapAcc.Remove(id) - cached, found = smapAcc.cache.fetch(id) - assert.Nil(t, cached) - assert.False(t, found) -} - -type FakeESAccessor struct{} - -func (es *FakeESAccessor) fetch(id Id) (*sourcemap.Consumer, error) { - if id.Path == "/tmp" { - return getFakeSmap(), nil - } else { - return nil, nil - } -} - -func getFakeId() Id { - return Id{Path: "/tmp", ServiceName: "foo", ServiceVersion: "1.0"} -} - -func getFakeSmap() *sourcemap.Consumer { - cwd, _ := os.Getwd() - data, err := ioutil.ReadFile(filepath.Join(cwd, "..", "testdata/sourcemap/bundle.js.map")) - if err != nil { - panic(err) - } - smap, err := sourcemap.Parse("", data) - if err != nil { - panic(err) - } - return smap -} - -func getFakeConfig() Config { - return Config{ - ElasticsearchConfig: getFakeESConfig(nil), - CacheExpiration: 1 * time.Second, - Index: "test-index", - } -} diff --git a/sourcemap/cache.go b/sourcemap/cache.go deleted file mode 100644 index 7fec0c845b7..00000000000 --- a/sourcemap/cache.go +++ /dev/null @@ -1,84 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package sourcemap - -import ( - "math" - "time" - - "github.com/go-sourcemap/sourcemap" - gocache "github.com/patrickmn/go-cache" - - "github.com/elastic/beats/libbeat/logp" - - logs "github.com/elastic/apm-server/log" -) - -const ( - minCleanupIntervalSeconds float64 = 60 -) - -type cache struct { - goca *gocache.Cache - logger *logp.Logger -} - -func newCache(expiration time.Duration) (*cache, error) { - if expiration < 0 { - return nil, Error{ - Msg: "Cache cannot be initialized. Expiration and CleanupInterval need to be >= 0", - Kind: InitError, - } - } - return &cache{ - goca: gocache.New(expiration, cleanupInterval(expiration)), - logger: logp.NewLogger(logs.Sourcemap), - }, nil -} - -func (c *cache) add(id Id, consumer *sourcemap.Consumer) { - c.goca.Set(id.Key(), consumer, gocache.DefaultExpiration) - if !c.logger.IsDebug() { - return - } - c.logger.Debugf("Added id %v. Cache now has %v entries.", id.Key(), c.goca.ItemCount()) -} - -func (c *cache) remove(id Id) { - c.goca.Delete(id.Key()) - if !c.logger.IsDebug() { - return - } - c.logger.Debugf("Removed id %v. Cache now has %v entries.", id.Key(), c.goca.ItemCount()) -} - -func (c *cache) fetch(id Id) (*sourcemap.Consumer, bool) { - if cached, found := c.goca.Get(id.Key()); found { - if cached == nil { - // in case empty value was cached - // return found=true - return nil, true - } - return cached.(*sourcemap.Consumer), true - } - return nil, false -} - -func cleanupInterval(ttl time.Duration) time.Duration { - return time.Duration(math.Max(ttl.Seconds(), minCleanupIntervalSeconds)) * time.Second -} diff --git a/sourcemap/cache_test.go b/sourcemap/cache_test.go deleted file mode 100644 index 58c992a1237..00000000000 --- a/sourcemap/cache_test.go +++ /dev/null @@ -1,121 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package sourcemap - -import ( - "fmt" - "testing" - "time" - - "github.com/stretchr/testify/assert" -) - -func TestCache(t *testing.T) { - _, err := newCache(-1 * time.Second) - assert.Error(t, err) - assert.Equal(t, (err.(Error)).Kind, InitError) - assert.Contains(t, err.Error(), "Cache cannot be initialized") - - _, err = newCache(1 * time.Second) - assert.NoError(t, err) -} - -func TestAddAndFetch(t *testing.T) { - c, err := newCache(60 * time.Second) - assert.NoError(t, err) - testSmap := getFakeSmap() - id := fakeSmapId() - - //check that cache is nil - smap, found := c.fetch(id) - assert.Nil(t, smap) - assert.False(t, found) - - //add to cache and check that value is cached - c.add(id, testSmap) - smap, found = c.fetch(id) - assert.Equal(t, smap, testSmap) - assert.True(t, found) - - //add nil value to cache and check that value is cached - c.add(id, nil) - smap, found = c.fetch(id) - assert.Nil(t, smap) - assert.True(t, found) -} - -func TestRemove(t *testing.T) { - c, err := newCache(60 * time.Second) - assert.NoError(t, err) - id := fakeSmapId() - testSmap := getFakeSmap() - - c.add(id, testSmap) - smap, _ := c.fetch(id) - assert.Equal(t, smap, testSmap) - - c.remove(id) - smap, found := c.fetch(id) - assert.Nil(t, smap) - assert.False(t, found) -} - -func TestExpiration(t *testing.T) { - expiration := 25 * time.Millisecond - c, err := newCache(expiration) - assert.NoError(t, err) - id := fakeSmapId() - testSmap := getFakeSmap() - - c.add(id, testSmap) - smap, found := c.fetch(id) - assert.Equal(t, smap, testSmap) - assert.True(t, found) - - //let the cache expire - time.Sleep(expiration + 1*time.Millisecond) - smap, found = c.fetch(id) - assert.Nil(t, smap) - assert.False(t, found) -} - -func TestCleanupInterval(t *testing.T) { - tests := []struct { - ttl time.Duration - expected float64 - }{ - {expected: 1}, - {ttl: 30 * time.Second, expected: 1}, - {ttl: 30 * time.Second, expected: 1}, - {ttl: 60 * time.Second, expected: 1}, - {ttl: 61 * time.Second, expected: 61.0 / 60}, - {ttl: 5 * time.Minute, expected: 5}, - } - for idx, test := range tests { - out := cleanupInterval(test.ttl) - assert.Equal(t, test.expected, out.Minutes(), - fmt.Sprintf("(%v) expected %v minutes, received %v minutes", idx, test.expected, out.Minutes())) - } -} - -func fakeSmapId() Id { - serviceName := "foo" - serviceVersion := "bar" - path := "bundle.js.map" - return Id{serviceName, serviceVersion, path} -} diff --git a/sourcemap/elasticsearch.go b/sourcemap/elasticsearch.go deleted file mode 100644 index 2de607c5013..00000000000 --- a/sourcemap/elasticsearch.go +++ /dev/null @@ -1,168 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package sourcemap - -import ( - "encoding/json" - "fmt" - "sync" - - logs "github.com/elastic/apm-server/log" - - "github.com/elastic/apm-server/utility" - - "github.com/go-sourcemap/sourcemap" - - "github.com/elastic/beats/libbeat/common" - "github.com/elastic/beats/libbeat/logp" - es "github.com/elastic/beats/libbeat/outputs/elasticsearch" -) - -type elasticsearch interface { - fetch(id Id) (*sourcemap.Consumer, error) -} - -type smapElasticsearch struct { - mu sync.Mutex // guards clients - clients []es.Client - - index string - logger *logp.Logger -} - -func NewElasticsearch(config *common.Config, index string) (*smapElasticsearch, error) { - esClients, err := es.NewElasticsearchClients(config) - if err != nil || esClients == nil || len(esClients) == 0 { - return nil, Error{ - Msg: fmt.Sprintf("Sourcemap ES Client cannot be initialized. %v", err.Error()), - Kind: InitError, - } - } - if index == "" { - index = "*" - } - return &smapElasticsearch{ - clients: esClients, - index: index, - logger: logp.NewLogger(logs.Sourcemap), - }, nil -} - -func (e *smapElasticsearch) fetch(id Id) (*sourcemap.Consumer, error) { - result, err := e.runESQuery(query(id)) - if err != nil { - return nil, err - } - return e.parseResult(result, id) -} - -func (e *smapElasticsearch) runESQuery(body map[string]interface{}) (*es.SearchResults, error) { - var err error - var result *es.SearchResults - e.mu.Lock() - defer e.mu.Unlock() - for _, client := range e.clients { - _, result, err = client.Connection.SearchURIWithBody(e.index, "", nil, body) - if err == nil { - return result, nil - } - } - if err != nil { - return nil, Error{Msg: err.Error(), Kind: AccessError} - } - return result, nil -} - -func (e *smapElasticsearch) parseResult(result *es.SearchResults, id Id) (*sourcemap.Consumer, error) { - if result.Hits.Total.Value == 0 { - return nil, nil - } - if result.Hits.Total.Value > 1 { - e.logger.Warnf("%d sourcemaps found for service %s version %s and file %s, using the most recent one", - result.Hits.Total.Value, id.ServiceName, id.ServiceVersion, id.Path) - } - smap, err := parseSmap(result.Hits.Hits[0]) - if err != nil { - return nil, err - } - cons, err := sourcemap.Parse("", []byte(smap)) - if err != nil { - return nil, Error{ - Msg: fmt.Sprintf("Could not parse Sourcemap. %v", err.Error()), - Kind: ParseError, - } - } - return cons, nil -} - -func query(id Id) map[string]interface{} { - return map[string]interface{}{ - "query": map[string]interface{}{ - "bool": map[string]interface{}{ - "must": []map[string]interface{}{ - {"term": map[string]interface{}{"processor.name": "sourcemap"}}, - {"term": map[string]interface{}{"sourcemap.service.name": id.ServiceName}}, - {"term": map[string]interface{}{"sourcemap.service.version": id.ServiceVersion}}, - {"bool": map[string]interface{}{ - "should": []map[string]interface{}{ - {"term": map[string]interface{}{"sourcemap.bundle_filepath": map[string]interface{}{ - "value": id.Path, - // prefer full url match - "boost": 2.0, - }}}, - {"term": map[string]interface{}{"sourcemap.bundle_filepath": utility.UrlPath(id.Path)}}, - }, - }}, - }, - }, - }, - "size": 1, - "sort": []map[string]interface{}{ - { - "_score": map[string]interface{}{ - "order": "desc", - }, - }, - { - "@timestamp": map[string]interface{}{ - "order": "desc", - }, - }, - }, - "_source": "sourcemap.sourcemap", - } -} - -func parseSmap(result []byte) (string, error) { - var smap struct { - Source struct { - Sourcemap struct { - Sourcemap string - } - } `json:"_source"` - } - err := json.Unmarshal(result, &smap) - if err != nil { - return "", Error{Msg: err.Error(), Kind: ParseError} - } - // until https://github.com/golang/go/issues/19858 is resolved - if smap.Source.Sourcemap.Sourcemap == "" { - return "", Error{Msg: "Sourcemapping ES Result not in expected format", Kind: ParseError} - } - return smap.Source.Sourcemap.Sourcemap, nil -} diff --git a/sourcemap/elasticsearch_test.go b/sourcemap/elasticsearch_test.go deleted file mode 100644 index bc993f09535..00000000000 --- a/sourcemap/elasticsearch_test.go +++ /dev/null @@ -1,130 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package sourcemap - -import ( - "encoding/json" - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/elastic/beats/libbeat/common" - es "github.com/elastic/beats/libbeat/outputs/elasticsearch" -) - -func TestNewElasticsearch(t *testing.T) { - _, err := NewElasticsearch(getFakeESConfig(map[string]interface{}{}), "apm") - assert.Error(t, err) - assert.Equal(t, (err.(Error)).Kind, InitError) - assert.Contains(t, err.Error(), "ES Client cannot be initialized") - - es, err := NewElasticsearch(getFakeESConfig(nil), "") - assert.NoError(t, err) - assert.Equal(t, "*", es.index) -} - -func TestNoElasticsearchConnection(t *testing.T) { - es, err := NewElasticsearch(getFakeESConfig(nil), "") - assert.NoError(t, err) - c, err := es.fetch(Id{ServiceName: "testService"}) - assert.Nil(t, c) - assert.Error(t, err) - assert.Equal(t, (err.(Error)).Kind, AccessError) - assert.Contains(t, err.Error(), "connection") -} - -func TestParseResultNoSourcemap(t *testing.T) { - id := Id{Path: "/tmp"} - result := &es.SearchResults{} - c, err := (&smapElasticsearch{}).parseResult(result, id) - assert.Nil(t, c) - assert.NoError(t, err) -} - -func TestParseResultParseError(t *testing.T) { - id := Id{Path: "/tmp"} - result := &es.SearchResults{ - Hits: es.Hits{ - Hits: []json.RawMessage{ - {}, - }, - Total: es.Total{Value: 1}, - }, - } - c, err := (&smapElasticsearch{}).parseResult(result, id) - assert.Nil(t, c) - assert.Error(t, err) - assert.Equal(t, (err.(Error)).Kind, ParseError) - - result = &es.SearchResults{ - Hits: es.Hits{ - Hits: []json.RawMessage{ - []byte(`{"_id": "1","_source": {"sourcemap": {"sourcemap": "map"}}}`), - }, - Total: es.Total{Value: 1}, - }, - } - c, err = (&smapElasticsearch{}).parseResult(result, id) - assert.Nil(t, c) - assert.Error(t, err) - assert.Contains(t, err.Error(), "Could not parse Sourcemap") - assert.Equal(t, (err.(Error)).Kind, ParseError) -} - -func TestParseSourcemapResult(t *testing.T) { - smap, err := parseSmap([]byte(`{ -"_id": "1", -"_source": { -"sourcemap": { -"sourcemap": "map" -} -} -} -`)) - assert.NoError(t, err) - assert.Equal(t, "map", smap) -} - -func TestParseSourcemapResultError(t *testing.T) { - // valid json, missing sourcemap - _, err := parseSmap([]byte(`{ -"_id": "1", -"_source": { -"foo": "bar" -} -} -`)) - assert.Error(t, err) - - // invalid json - _, err = parseSmap([]byte(`{`)) - assert.Error(t, err) -} - -func getFakeESConfig(cfg map[string]interface{}) *common.Config { - if cfg == nil { - cfg = map[string]interface{}{ - "hosts": []string{ - "http://localhost:9288", - "http://localhost:9898", - }, - } - } - c, _ := common.NewConfigFrom(cfg) - return c -} diff --git a/sourcemap/error.go b/sourcemap/error.go index ff4eb803249..3e07623622e 100644 --- a/sourcemap/error.go +++ b/sourcemap/error.go @@ -17,21 +17,16 @@ package sourcemap -type Enum string - -const ( - InitError Enum = "InitError" - AccessError Enum = "AccessError" - ParseError Enum = "ParseError" - MapError Enum = "MapError" - KeyError Enum = "KeyError" -) - -type Error struct { - Msg string - Kind Enum -} - -func (e Error) Error() string { - return e.Msg -} +//type internalErr struct { +// err error +// noSourcemap bool +// temporary bool +//} +// +//func (e *internalErr) Error() string { +// return e.err.Error() +//} +// +//func (e *internalErr) NoSourcemapFound() bool { +// return e.noSourcemap +//} diff --git a/sourcemap/error_test.go b/sourcemap/error_test.go deleted file mode 100644 index 43969603f87..00000000000 --- a/sourcemap/error_test.go +++ /dev/null @@ -1,48 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package sourcemap - -import ( - "fmt" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestError(t *testing.T) { - tests := []struct { - Msg string - Kind Enum - OutMsg string - OutKind string - }{ - {OutMsg: "", OutKind: ""}, - {Msg: "Init failed", Kind: InitError, OutMsg: "Init failed", OutKind: "InitError"}, - {Msg: "Access failed", Kind: AccessError, OutMsg: "Access failed", OutKind: "AccessError"}, - {Msg: "Map failed", Kind: MapError, OutMsg: "Map failed", OutKind: "MapError"}, - {Msg: "Parse failed", Kind: ParseError, OutMsg: "Parse failed", OutKind: "ParseError"}, - {Msg: "Key error", Kind: KeyError, OutMsg: "Key error", OutKind: "KeyError"}, - } - for idx, test := range tests { - err := Error{Msg: test.Msg, Kind: test.Kind} - assert.Equal(t, test.OutMsg, err.Msg, - fmt.Sprintf("(%v): Expected <%v>, Received <%v> ", idx, test.OutMsg, err.Msg)) - assert.Equal(t, test.OutKind, string(err.Kind), - fmt.Sprintf("(%v): Expected <%v>, Received <%v> ", idx, test.OutKind, err.Kind)) - } -} diff --git a/sourcemap/es_store.go b/sourcemap/es_store.go new file mode 100644 index 00000000000..58a261ac8ba --- /dev/null +++ b/sourcemap/es_store.go @@ -0,0 +1,188 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package sourcemap + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + + "github.com/pkg/errors" + + "github.com/elastic/beats/libbeat/logp" + "github.com/elastic/go-elasticsearch/v8" + "github.com/elastic/go-elasticsearch/v8/esapi" + + "github.com/elastic/apm-server/utility" +) + +const ( + boolStr = "bool" + boostStr = "boost" + descStr = "desc" + mustStr = "must" + orderStr = "order" + processorNameStr = "processor.name" + queryStr = "query" + scoreStr = "_score" + shouldStr = "should" + sizeStr = "size" + sortStr = "sort" + sourcemapStr = "sourcemap" + sourcemapBundleFilepathStr = "sourcemap.bundle_filepath" + sourcemapServiceNameStr = "sourcemap.service.name" + sourcemapServiceVersionStr = "sourcemap.service.version" + sourcemapSourcemapStr = "sourcemap.sourcemap" + sourceStr = "_source" + termStr = "term" + timestampStr = "@timestamp" + valueStr = "value" + + emptyResult = "" + + errMsgParseSourcemap = "Could not parse Sourcemap." +) + +var ( + errMsgESFailure = "failure querying ES" + errSourcemapWrongFormat = errors.New("Sourcemapping ES Result not in expected format") +) + +type esStore struct { + client *elasticsearch.Client + index string + logger *logp.Logger +} + +type esSourcemapResponse struct { + Hits struct { + Total struct { + Value int + } + Hits []struct { + Source struct { + Sourcemap struct { + Sourcemap string + } + } `json:"_source"` + } + } `json:"hits"` +} + +func (s *esStore) fetch(name, version, path string) (string, error) { + response, err := s.runSearchQuery(name, version, path) + if err != nil { + return "", errors.Wrap(err, errMsgESFailure) + } + defer response.Body.Close() + // handle error response + if response.IsError() { + if response.StatusCode == http.StatusNotFound { + return "", nil + } + b, err := ioutil.ReadAll(response.Body) + if err != nil { + return "", errors.Wrap(err, errMsgParseSourcemap) + } + return "", errors.New(fmt.Sprintf("%s %s", errMsgParseSourcemap, b)) + } + + // parse response + return parse(response, name, version, path, s.logger) +} + +func (s *esStore) runSearchQuery(name, version, path string) (*esapi.Response, error) { + // build and encode the query + var buf bytes.Buffer + if err := json.NewEncoder(&buf).Encode(query(name, version, path)); err != nil { + return nil, err + } + + // Perform the runSearchQuery request. + return s.client.Search( + s.client.Search.WithContext(context.Background()), + s.client.Search.WithIndex(s.index), + s.client.Search.WithBody(&buf), + s.client.Search.WithTrackTotalHits(true), + s.client.Search.WithPretty(), + ) +} + +func parse(response *esapi.Response, name, version, path string, logger *logp.Logger) (string, error) { + var esSourcemapResponse esSourcemapResponse + if err := json.NewDecoder(response.Body).Decode(&esSourcemapResponse); err != nil { + return "", err + } + hits := esSourcemapResponse.Hits.Total.Value + if hits == 0 { + return emptyResult, nil + } + + var esSourcemap string + if hits > 1 { + logger.Warnf("%d sourcemaps found for service %s version %s and file %s, using the most recent one", + hits, name, version, path) + } + esSourcemap = esSourcemapResponse.Hits.Hits[0].Source.Sourcemap.Sourcemap + // until https://github.com/golang/go/issues/19858 is resolved + if esSourcemap == emptyResult { + return emptyResult, errSourcemapWrongFormat + } + return esSourcemap, nil +} + +func query(name, version, path string) map[string]interface{} { + return map[string]interface{}{ + queryStr: map[string]interface{}{ + boolStr: map[string]interface{}{ + mustStr: []map[string]interface{}{ + {termStr: map[string]interface{}{processorNameStr: sourcemapStr}}, + {termStr: map[string]interface{}{sourcemapServiceNameStr: name}}, + {termStr: map[string]interface{}{sourcemapServiceVersionStr: version}}, + {boolStr: map[string]interface{}{ + shouldStr: []map[string]interface{}{ + {termStr: map[string]interface{}{sourcemapBundleFilepathStr: map[string]interface{}{ + valueStr: path, + // prefer full url match + boostStr: 2.0, + }}}, + {termStr: map[string]interface{}{sourcemapBundleFilepathStr: utility.UrlPath(path)}}, + }, + }}, + }, + }, + }, + sizeStr: 1, + sortStr: []map[string]interface{}{ + { + scoreStr: map[string]interface{}{ + orderStr: descStr, + }, + }, + { + timestampStr: map[string]interface{}{ + orderStr: descStr, + }, + }, + }, + sourceStr: sourcemapSourcemapStr, + } +} diff --git a/sourcemap/es_store_test.go b/sourcemap/es_store_test.go new file mode 100644 index 00000000000..396c4468612 --- /dev/null +++ b/sourcemap/es_store_test.go @@ -0,0 +1,100 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package sourcemap + +import ( + "net/http" + "strings" + "testing" + + "github.com/go-sourcemap/sourcemap" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/elastic/beats/libbeat/logp" + "github.com/elastic/go-elasticsearch/v8" + + estest "github.com/elastic/apm-server/elasticsearch/test" + logs "github.com/elastic/apm-server/log" + "github.com/elastic/apm-server/sourcemap/test" +) + +func Test_esFetcher_fetchError(t *testing.T) { + for name, tc := range map[string]struct { + statusCode int + esBody map[string]interface{} + temporary bool + }{ + "es not reachable": { + statusCode: http.StatusInternalServerError, temporary: true, + }, + "es bad request": { + statusCode: http.StatusBadRequest, + }, + "empty sourcemap string": { + esBody: map[string]interface{}{ + "hits": map[string]interface{}{ + "total": map[string]interface{}{"value": 1}, + "hits": []map[string]interface{}{ + {"_source": map[string]interface{}{ + "sourcemap": map[string]interface{}{ + "sourcemap": ""}}}}}}, + }, + } { + t.Run(name, func(t *testing.T) { + statusCode := tc.statusCode + if statusCode == 0 { + statusCode = http.StatusOK + } + client, err := estest.NewElasticsearchClient(estest.NewTransport(t, statusCode, tc.esBody)) + require.NoError(t, err) + consumer, err := testESStore(client).fetch("abc", "1.0", "/tmp") + require.Error(t, err) + assert.Equal(t, tc.temporary, strings.Contains(err.Error(), errMsgESFailure)) + assert.Empty(t, consumer) + }) + } +} + +func Test_esFetcher_fetch(t *testing.T) { + for name, tc := range map[string]struct { + client *elasticsearch.Client + filePath string + }{ + "no sourcemap found": {client: test.ESClientWithSourcemapNotFound(t)}, + "valid sourcemap found": {client: test.ESClientWithValidSourcemap(t), filePath: "bundle.js"}, + } { + t.Run(name, func(t *testing.T) { + sourcemapStr, err := testESStore(tc.client).fetch("abc", "1.0", "/tmp") + require.NoError(t, err) + + if tc.filePath == "" { + assert.Empty(t, sourcemapStr) + } else { + sourcemapConsumer, err := sourcemap.Parse("", []byte(sourcemapStr)) + require.NoError(t, err) + assert.Equal(t, tc.filePath, sourcemapConsumer.File()) + } + }) + } +} + +func testESStore(client *elasticsearch.Client) *esStore { + return &esStore{client: client, index: "apm-sourcemap", logger: logp.NewLogger(logs.Sourcemap)} +} diff --git a/sourcemap/id_test.go b/sourcemap/id_test.go deleted file mode 100644 index 18f71b2aab2..00000000000 --- a/sourcemap/id_test.go +++ /dev/null @@ -1,53 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package sourcemap - -import ( - "fmt" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestSmapIdKey(t *testing.T) { - tests := []struct { - id Id - key string - valid bool - }{ - { - id: Id{ServiceName: "foo", ServiceVersion: "1.0", Path: "a/b"}, - key: "foo_1.0_a/b", - valid: true, - }, - { - id: Id{ServiceName: "foo", ServiceVersion: "bar"}, - key: "foo_bar", - valid: false, - }, - {id: Id{ServiceName: "foo"}, key: "foo", valid: false}, - {id: Id{ServiceVersion: "1"}, key: "1", valid: false}, - {id: Id{Path: "/tmp/a"}, key: "/tmp/a", valid: false}, - } - for idx, test := range tests { - assert.Equal(t, test.key, test.id.Key(), - fmt.Sprintf("(%v) Expected Key() to return <%v> but received<%v>", idx, test.key, test.id.Key())) - assert.Equal(t, test.valid, test.id.Valid(), - fmt.Sprintf("(%v) Expected Valid() to be <%v>", idx, test.valid)) - } -} diff --git a/sourcemap/mapper.go b/sourcemap/mapper.go index 1eca3f058a5..e4216b35da9 100644 --- a/sourcemap/mapper.go +++ b/sourcemap/mapper.go @@ -18,91 +18,33 @@ package sourcemap import ( - "fmt" "strings" - "time" - logs "github.com/elastic/apm-server/log" - - "github.com/elastic/beats/libbeat/common" - "github.com/elastic/beats/libbeat/logp" + "github.com/go-sourcemap/sourcemap" ) const sourcemapContentSnippetSize = 5 -type Mapper interface { - Apply(Id, int, int) (*Mapping, error) - NewSourcemapAdded(id Id) -} - -type SmapMapper struct { - Accessor Accessor - logger *logp.Logger +// Mapper holds a sourcemapper instance to be able to apply sourcemapping +type Mapper struct { + sourcemapConsumer *sourcemap.Consumer } -type Config struct { - CacheExpiration time.Duration - ElasticsearchConfig *common.Config - Index string -} +// Apply sourcemapping for given line and column and return values after sourcemapping +func (m *Mapper) Apply(lineno, colno int) ( + file string, function string, line int, col int, + contextLine string, preContext []string, postContext []string, ok bool) { -type Mapping struct { - Filename string - Function string - Colno int - Lineno int - Path string - ContextLine string - PreContext []string - PostContext []string -} - -func NewSmapMapper(config Config) (*SmapMapper, error) { - accessor, err := NewSmapAccessor(config) - if err != nil { - return nil, err + if m.sourcemapConsumer == nil { + return } - return &SmapMapper{ - Accessor: accessor, - logger: logp.NewLogger(logs.Sourcemap), - }, nil -} -func (m *SmapMapper) Apply(id Id, lineno, colno int) (*Mapping, error) { - smapCons, err := m.Accessor.Fetch(id) - if err != nil { - return nil, err - } - - file, funct, line, col, ok := smapCons.Source(lineno, colno) - if !ok { - return nil, Error{ - Msg: fmt.Sprintf("No Sourcemap found for id %v, Lineno %v, Colno %v", - id.String(), lineno, colno), - Kind: KeyError, - } - } - src := strings.Split(smapCons.SourceContent(file), "\n") - return &Mapping{ - Filename: file, - Function: funct, - Lineno: line, - Colno: col, - Path: id.Path, - // line is 1-based - ContextLine: strings.Join(subSlice(line-1, line, src), ""), - PreContext: subSlice(line-1-sourcemapContentSnippetSize, line-1, src), - PostContext: subSlice(line, line+sourcemapContentSnippetSize, src), - }, nil -} - -func (m *SmapMapper) NewSourcemapAdded(id Id) { - _, err := m.Accessor.Fetch(id) - if err == nil { - m.logger.Warnf("Overriding sourcemap for service %s version %s and file %s", - id.ServiceName, id.ServiceVersion, id.Path) - } - m.Accessor.Remove(id) + file, function, line, col, ok = m.sourcemapConsumer.Source(lineno, colno) + src := strings.Split(m.sourcemapConsumer.SourceContent(file), "\n") + contextLine = strings.Join(subSlice(line-1, line, src), "") + preContext = subSlice(line-1-sourcemapContentSnippetSize, line-1, src) + postContext = subSlice(line, line+sourcemapContentSnippetSize, src) + return } func subSlice(from, to int, content []string) []string { diff --git a/sourcemap/mapper_test.go b/sourcemap/mapper_test.go index d69a2f5e367..8886f53b98d 100644 --- a/sourcemap/mapper_test.go +++ b/sourcemap/mapper_test.go @@ -18,54 +18,48 @@ package sourcemap import ( - "io/ioutil" - "os" - "path/filepath" "testing" + "github.com/stretchr/testify/require" + + "github.com/elastic/apm-server/sourcemap/test" + "github.com/go-sourcemap/sourcemap" "github.com/stretchr/testify/assert" ) -func TestNewSmapMapper(t *testing.T) { - mapper, err := NewSmapMapper(Config{}) - assert.Nil(t, mapper) - assert.Error(t, err) - assert.Equal(t, (err.(Error)).Kind, InitError) - - mapper, err = NewSmapMapper(getFakeConfig()) - assert.NoError(t, err) - assert.NotNil(t, mapper) -} - func TestApply(t *testing.T) { - mapper, err := NewSmapMapper(getFakeConfig()) - assert.NoError(t, err) - assert.NotNil(t, mapper) + // no sourcemapConsumer + _, _, _, _, _, _, _, ok := (&Mapper{}).Apply(0, 0) + assert.False(t, ok) - // error occurs - mapping, err := mapper.Apply(Id{}, 0, 0) - assert.Nil(t, mapping) - assert.Error(t, err) - assert.Equal(t, (err.(Error)).Kind, KeyError) + sourcemapConsumer, err := sourcemap.Parse("", []byte(test.ValidSourcemap)) + require.NoError(t, err) + m := &Mapper{sourcemapConsumer: sourcemapConsumer} - // no mapping found in sourcemap - mapper.Accessor = &fakeAccessor{} - mapping, err = mapper.Apply(Id{Path: "bundle.js.map"}, 0, 0) - assert.Nil(t, mapping) - assert.Error(t, err) - assert.Contains(t, err.Error(), "No Sourcemap found") - assert.Equal(t, (err.(Error)).Kind, KeyError) + t.Run("notOK", func(t *testing.T) { + // nothing found for lineno and colno + file, fc, line, col, ctxLine, _, _, ok := m.Apply(0, 0) + require.False(t, ok) + assert.Zero(t, file) + assert.Zero(t, fc) + assert.Zero(t, line) + assert.Zero(t, col) + assert.Zero(t, ctxLine) + }) - // mapping found in minified sourcemap - mapping, err = mapper.Apply(Id{Path: "bundle.js.map"}, 1, 7) - assert.NoError(t, err) - assert.NotNil(t, mapping) - assert.Equal(t, "webpack:///bundle.js", mapping.Filename) - assert.Equal(t, "", mapping.Function) - assert.Equal(t, 1, mapping.Lineno) - assert.Equal(t, 9, mapping.Colno) - assert.Equal(t, "bundle.js.map", mapping.Path) + t.Run("OK", func(t *testing.T) { + // mapping found in minified sourcemap + file, fc, line, col, ctxLine, preCtx, postCtx, ok := m.Apply(1, 7) + require.True(t, ok) + assert.Equal(t, "webpack:///bundle.js", file) + assert.Equal(t, "", fc) + assert.Equal(t, 1, line) + assert.Equal(t, 9, col) + assert.Equal(t, "/******/ (function(modules) { // webpackBootstrap", ctxLine) + assert.Equal(t, []string{}, preCtx) + assert.NotZero(t, postCtx) + }) } func TestSubSlice(t *testing.T) { @@ -94,16 +88,3 @@ func TestSubSlice(t *testing.T) { assert.Equal(t, []string{}, subSlice(test.start, test.end, []string{})) } } - -type fakeAccessor struct{} - -func (ac *fakeAccessor) Fetch(smapId Id) (*sourcemap.Consumer, error) { - current, _ := os.Getwd() - path := filepath.Join(current, "../testdata/sourcemap/", smapId.Path) - fileBytes, err := ioutil.ReadFile(path) - if err != nil { - return nil, err - } - return sourcemap.Parse("", fileBytes) -} -func (ac *fakeAccessor) Remove(smapId Id) {} diff --git a/sourcemap/store.go b/sourcemap/store.go new file mode 100644 index 00000000000..bdfe8383a29 --- /dev/null +++ b/sourcemap/store.go @@ -0,0 +1,138 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package sourcemap + +import ( + "math" + "strings" + "time" + + "github.com/go-sourcemap/sourcemap" + gocache "github.com/patrickmn/go-cache" + "github.com/pkg/errors" + + "github.com/elastic/go-elasticsearch/v8" + + "github.com/elastic/beats/libbeat/logp" + + logs "github.com/elastic/apm-server/log" +) + +var ( + //ErrNoSourcemapFound indicates that no sourcemap exists for provided criteria + ErrNoSourcemapFound = errors.New("No Sourcemap available") +) + +const ( + minCleanupIntervalSeconds float64 = 60 +) + +var ( + errInit = errors.New("Cache cannot be initialized. Expiration and CleanupInterval need to be >= 0") +) + +// Store holds information necessary to fetch a sourcemap, either from an Elasticsearch instance or an internal cache. +type Store struct { + cache *gocache.Cache + esStore *esStore + logger *logp.Logger +} + +// NewStore creates a new instance for fetching sourcemaps. The client and index parameters are needed to be able to +// fetch sourcemaps from Elasticsearch. The expiration time is used for the internal cache. +func NewStore(client *elasticsearch.Client, index string, expiration time.Duration) (*Store, error) { + if expiration < 0 { + return nil, errInit + } + logger := logp.NewLogger(logs.Sourcemap) + return &Store{ + cache: gocache.New(expiration, cleanupInterval(expiration)), + esStore: &esStore{client: client, index: index, logger: logger}, + logger: logger, + }, nil +} + +// Fetch a sourcemap from the store. +func (s *Store) Fetch(name string, version string, path string) (*Mapper, error) { + key := key([]string{name, version, path}) + + // fetch from cache + if val, found := s.cache.Get(key); found { + sourcemapConsumer, ok := val.(*sourcemap.Consumer) + if ok && sourcemapConsumer != nil { + return &Mapper{sourcemapConsumer: sourcemapConsumer}, nil + } + return nil, errNoSourcemap(name, version, path) + } + + // fetch from Elasticsearch and ensure caching for all non-temporary results + sourcemapStr, err := s.esStore.fetch(name, version, path) + if err != nil { + if !strings.Contains(err.Error(), errMsgESFailure) { + s.add(key, nil) + } + return nil, err + } + + if sourcemapStr == emptyResult { + s.add(key, nil) + return nil, errNoSourcemap(name, version, path) + } + + consumer, err := sourcemap.Parse("", []byte(sourcemapStr)) + if err != nil { + s.add(key, nil) + return nil, errors.Wrap(err, errMsgParseSourcemap) + } + s.add(key, consumer) + return &Mapper{sourcemapConsumer: consumer}, nil +} + +// Added ensures the internal cache is cleared for the given parameters. This should be called when a sourcemap is uploaded. +func (s *Store) Added(name string, version string, path string) { + if _, err := s.Fetch(name, version, path); err == nil { + s.logger.Warnf("Overriding sourcemap for service %s version %s and file %s", + name, version, path) + } + key := key([]string{name, version, path}) + s.cache.Delete(key) + if !s.logger.IsDebug() { + return + } + s.logger.Debugf("Removed id %v. Cache now has %v entries.", key, s.cache.ItemCount()) +} + +func (s *Store) add(key string, consumer *sourcemap.Consumer) { + s.cache.SetDefault(key, consumer) + if !s.logger.IsDebug() { + return + } + s.logger.Debugf("Added id %v. Cache now has %v entries.", key, s.cache.ItemCount()) +} + +func key(s []string) string { + return strings.Join(s, "_") +} + +func cleanupInterval(ttl time.Duration) time.Duration { + return time.Duration(math.Max(ttl.Seconds(), minCleanupIntervalSeconds)) * time.Second +} + +func errNoSourcemap(name, version, path string) error { + return errors.Wrapf(ErrNoSourcemapFound, "ServiceName %s, ServiceVersion %s, Path %s.", name, version, path) +} diff --git a/sourcemap/store_test.go b/sourcemap/store_test.go new file mode 100644 index 00000000000..1ff4d6b5d8e --- /dev/null +++ b/sourcemap/store_test.go @@ -0,0 +1,194 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package sourcemap + +import ( + "fmt" + "testing" + "time" + + "github.com/go-sourcemap/sourcemap" + gocache "github.com/patrickmn/go-cache" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/elastic/go-elasticsearch/v8" + + "github.com/elastic/apm-server/sourcemap/test" +) + +func Test_NewStore(t *testing.T) { + _, err := NewStore(nil, "", -1) + require.Error(t, err) + + f, err := NewStore(nil, "", 100) + require.NoError(t, err) + assert.NotNil(t, f.cache) +} + +func TestStore_Fetch(t *testing.T) { + serviceName, serviceVersion, path := "foo", "1.0.1", "/tmp" + key := "foo_1.0.1_/tmp" + + t.Run("cache", func(t *testing.T) { + t.Run("nil", func(t *testing.T) { + var nilConsumer *sourcemap.Consumer + store := testStore(t, test.ESClientWithValidSourcemap(t)) //if ES was queried, it would return a valid sourcemap + store.add(key, nilConsumer) + + mapper, err := store.Fetch(serviceName, serviceVersion, path) + require.Error(t, err) + assert.Contains(t, err.Error(), "No Sourcemap available") + require.Nil(t, mapper) + }) + + t.Run("sourcemapConsumer", func(t *testing.T) { + consumer := &sourcemap.Consumer{} + store := testStore(t, test.ESClientUnavailable(t)) //if ES was queried, it would return a server error + store.add(key, consumer) + + mapper, err := store.Fetch(serviceName, serviceVersion, path) + require.NoError(t, err) + require.NotNil(t, mapper) + assert.Equal(t, consumer, mapper.sourcemapConsumer) + + }) + }) + + t.Run("validFromES", func(t *testing.T) { + store := testStore(t, test.ESClientWithValidSourcemap(t)) + mapper, err := store.Fetch(serviceName, serviceVersion, path) + require.NoError(t, err) + require.NotNil(t, mapper) + assert.NotNil(t, mapper.sourcemapConsumer) + + // ensure sourcemap is added to cache + cached, found := store.cache.Get(key) + require.True(t, found) + assert.Equal(t, mapper.sourcemapConsumer, cached) + }) + + t.Run("invalidFromES", func(t *testing.T) { + for name, client := range map[string]*elasticsearch.Client{ + "notFound": test.ESClientWithSourcemapNotFound(t), + "invalid": test.ESClientWithInvalidSourcemap(t), + "unsupportedVersion": test.ESClientWithUnsupportedSourcemap(t), + } { + t.Run(name, func(t *testing.T) { + store := testStore(t, client) + //not cached + cached, found := store.cache.Get(key) + require.False(t, found) + assert.Nil(t, cached) + + //fetch nil value, leading to error + mapper, err := store.Fetch(serviceName, serviceVersion, path) + require.Error(t, err) + require.Nil(t, mapper) + + // ensure nil value is added to cache + cached, found = store.cache.Get(key) + assert.True(t, found) + assert.Nil(t, cached) + }) + } + }) + + t.Run("noConnectionToES", func(t *testing.T) { + store := testStore(t, test.ESClientUnavailable(t)) + //not cached + _, found := store.cache.Get(key) + require.False(t, found) + + //fetch nil value, leading to error + mapper, err := store.Fetch(serviceName, serviceVersion, path) + require.Error(t, err) + require.Nil(t, mapper) + + // ensure not cached + _, found = store.cache.Get(key) + assert.False(t, found) + }) +} + +func TestStore_Added(t *testing.T) { + name, version, path := "foo", "1.0.1", "/tmp" + key := "foo_1.0.1_/tmp" + + // setup + // remove empty sourcemap from cache, and valid one with File() == "bundle.js" from Elasticsearch + store := testStore(t, test.ESClientWithValidSourcemap(t)) + store.add(key, &sourcemap.Consumer{}) + + mapper, err := store.Fetch(name, version, path) + require.NoError(t, err) + require.NotNil(t, mapper) + assert.Equal(t, &sourcemap.Consumer{}, mapper.sourcemapConsumer) + assert.Equal(t, "", mapper.sourcemapConsumer.File()) + + // remove from cache, afterwards sourcemap should be fetched from ES + store.Added(name, version, path) + mapper, err = store.Fetch(name, version, path) + require.NoError(t, err) + require.NotNil(t, mapper) + assert.NotNil(t, &sourcemap.Consumer{}, mapper.sourcemapConsumer) + assert.Equal(t, "bundle.js", mapper.sourcemapConsumer.File()) +} + +func TestExpiration(t *testing.T) { + store := testStore(t, test.ESClientUnavailable(t)) //if ES was queried it would return an error + store.cache = gocache.New(25*time.Millisecond, 100) + store.add("foo_1.0.1_/tmp", &sourcemap.Consumer{}) + name, version, path := "foo", "1.0.1", "/tmp" + + // sourcemap is cached + mapper, err := store.Fetch(name, version, path) + require.NoError(t, err) + assert.Equal(t, &sourcemap.Consumer{}, mapper.sourcemapConsumer) + + time.Sleep(25 * time.Millisecond) + // cache is cleared, sourcemap is fetched from ES leading to an error + mapper, err = store.Fetch(name, version, path) + require.Error(t, err) + assert.Nil(t, mapper) +} + +func TestCleanupInterval(t *testing.T) { + tests := []struct { + ttl time.Duration + expected float64 + }{ + {expected: 1}, + {ttl: 30 * time.Second, expected: 1}, + {ttl: 30 * time.Second, expected: 1}, + {ttl: 60 * time.Second, expected: 1}, + {ttl: 61 * time.Second, expected: 61.0 / 60}, + {ttl: 5 * time.Minute, expected: 5}, + } + for idx, test := range tests { + out := cleanupInterval(test.ttl) + assert.Equal(t, test.expected, out.Minutes(), + fmt.Sprintf("(%v) expected %v minutes, received %v minutes", idx, test.expected, out.Minutes())) + } +} + +func testStore(t *testing.T, client *elasticsearch.Client) *Store { + store, err := NewStore(client, "apm-*sourcemap*", time.Minute) + require.NoError(t, err) + return store +} diff --git a/sourcemap/test/es_client.go b/sourcemap/test/es_client.go new file mode 100644 index 00000000000..da69ecf8d91 --- /dev/null +++ b/sourcemap/test/es_client.go @@ -0,0 +1,151 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package test + +import ( + "net/http" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/elastic/go-elasticsearch/v8" + + "github.com/elastic/apm-server/elasticsearch/test" +) + +//ValidSourcemap represents an example for a valid sourcemap string +var ValidSourcemap = `{ + "version": 3, + "sources": [ + "webpack:///bundle.js", + "", + "webpack:///./scripts/index.js", + "webpack:///./index.html", + "webpack:///./scripts/app.js" + ], + "names": [ + "modules", + "__webpack_require__", + "moduleId", + "installedModules", + "exports", + "module", + "id", + "loaded", + "call", + "m", + "c", + "p", + "foo", + "console", + "log", + "foobar" + ], + "mappings": "CAAS,SAAUA,GCInB,QAAAC,GAAAC,GAGA,GAAAC,EAAAD,GACA,MAAAC,GAAAD,GAAAE,OAGA,IAAAC,GAAAF,EAAAD,IACAE,WACAE,GAAAJ,EACAK,QAAA,EAUA,OANAP,GAAAE,GAAAM,KAAAH,EAAAD,QAAAC,IAAAD,QAAAH,GAGAI,EAAAE,QAAA,EAGAF,EAAAD,QAvBA,GAAAD,KAqCA,OATAF,GAAAQ,EAAAT,EAGAC,EAAAS,EAAAP,EAGAF,EAAAU,EAAA,GAGAV,EAAA,KDMM,SAASI,EAAQD,EAASH,GE3ChCA,EAAA,GAEAA,EAAA,GAEAW,OFmDM,SAASP,EAAQD,EAASH,GGxDhCI,EAAAD,QAAAH,EAAAU,EAAA,cH8DM,SAASN,EAAQD,GI9DvB,QAAAQ,KACAC,QAAAC,IAAAC,QAGAH", + "file": "bundle.js", + "sourcesContent": [ + "/******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n/******/\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n/******/\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\n/******/ \t\t};\n/******/\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.loaded = true;\n/******/\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/\n/******/\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n/******/\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n/******/\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t// Webpack\n\t__webpack_require__(1)\n\t\n\t__webpack_require__(2)\n\t\n\tfoo()\n\n\n/***/ },\n/* 1 */\n/***/ function(module, exports, __webpack_require__) {\n\n\tmodule.exports = __webpack_require__.p + \"index.html\"\n\n/***/ },\n/* 2 */\n/***/ function(module, exports) {\n\n\tfunction foo() {\n\t console.log(foobar)\n\t}\n\t\n\tfoo()\n\n\n/***/ }\n/******/ ]);\n\n\n/** WEBPACK FOOTER **\n ** bundle.js\n **/", + " \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 6002740481c9666b0d38\n **/", + "// Webpack\nrequire('../index.html')\n\nrequire('./app')\n\nfoo()\n\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./scripts/index.js\n ** module id = 0\n ** module chunks = 0\n **/", + "module.exports = __webpack_public_path__ + \"index.html\"\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./index.html\n ** module id = 1\n ** module chunks = 0\n **/", + "function foo() {\n console.log(foobar)\n}\n\nfoo()\n\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./scripts/app.js\n ** module id = 2\n ** module chunks = 0\n **/" + ], + "sourceRoot": "" +}` + +// ESClientWithValidSourcemap returns an elasticsearch client that will always return a document containing +// a valid sourcemap. +func ESClientWithValidSourcemap(t *testing.T) *elasticsearch.Client { + client, err := test.NewElasticsearchClient(test.NewTransport(t, http.StatusOK, validSourcemapFromES())) + require.NoError(t, err) + return client +} + +// ESClientUnavailable returns an elasticsearch client that will always return an internal server error +func ESClientUnavailable(t *testing.T) *elasticsearch.Client { + client, err := test.NewElasticsearchClient(test.NewTransport(t, http.StatusInternalServerError, nil)) + require.NoError(t, err) + return client +} + +// ESClientWithInvalidSourcemap returns an elasticsearch client that will always return a document containing +// an invalid sourcemap. +func ESClientWithInvalidSourcemap(t *testing.T) *elasticsearch.Client { + client, err := test.NewElasticsearchClient(test.NewTransport(t, http.StatusOK, invalidSourcemapFromES())) + require.NoError(t, err) + return client +} + +// ESClientWithUnsupportedSourcemap returns an elasticsearch client that will always return a document containing +// a sourcemap with an unsupported version. +func ESClientWithUnsupportedSourcemap(t *testing.T) *elasticsearch.Client { + client, err := test.NewElasticsearchClient(test.NewTransport(t, http.StatusOK, sourcemapUnsupportedVersionFromES())) + require.NoError(t, err) + return client +} + +// ESClientWithSourcemapNotFound returns an elasticsearch client that will always return a not found error +func ESClientWithSourcemapNotFound(t *testing.T) *elasticsearch.Client { + client, err := test.NewElasticsearchClient(test.NewTransport(t, http.StatusNotFound, sourcemapNotFoundFromES())) + require.NoError(t, err) + return client +} + +func validSourcemapFromES() map[string]interface{} { + return map[string]interface{}{ + "hits": map[string]interface{}{ + "total": map[string]interface{}{"value": 1}, + "hits": []map[string]interface{}{ + {"_source": map[string]interface{}{ + "sourcemap": map[string]interface{}{ + "sourcemap": ValidSourcemap}}}}}} +} + +func sourcemapNotFoundFromES() map[string]interface{} { + return map[string]interface{}{ + "hits": map[string]interface{}{ + "total": map[string]interface{}{"value": 0}}} +} + +func invalidSourcemapFromES() map[string]interface{} { + return map[string]interface{}{ + "hits": map[string]interface{}{ + "total": map[string]interface{}{"value": 1}, + "hits": []map[string]interface{}{ + {"_source": map[string]interface{}{ + "sourcemap": map[string]interface{}{ + "sourcemap": "foo"}}}}}} +} + +func sourcemapUnsupportedVersionFromES() map[string]interface{} { + return map[string]interface{}{ + "hits": map[string]interface{}{ + "total": map[string]interface{}{"value": 1}, + "hits": []map[string]interface{}{ + {"_source": map[string]interface{}{ + "sourcemap": map[string]interface{}{ + "sourcemap": `{ + "version": 1, + "sources": ["webpack:///bundle.js"], + "names": [], + "mappings": "CAAS", + "file": "bundle.js", + "sourcesContent": [], + "sourceRoot": "" + }`}}}}}} +} diff --git a/tests/system/test_integration.py b/tests/system/test_integration.py index 6007324209b..ea68ebf19f8 100644 --- a/tests/system/test_integration.py +++ b/tests/system/test_integration.py @@ -433,7 +433,7 @@ def test_no_sourcemap(self): 'error', 1) self.check_rum_error_sourcemap( - False, expected_err="No Sourcemap available for") + False, expected_err="No Sourcemap available") @unittest.skipUnless(INTEGRATION_TESTS, "integration test") def test_no_matching_sourcemap(self): diff --git a/transform/transform.go b/transform/transform.go index 59e6982653e..a571cca9732 100644 --- a/transform/transform.go +++ b/transform/transform.go @@ -21,9 +21,10 @@ import ( "regexp" "time" + "github.com/elastic/beats/libbeat/beat" + "github.com/elastic/apm-server/model/metadata" "github.com/elastic/apm-server/sourcemap" - "github.com/elastic/beats/libbeat/beat" ) type Transformable interface { @@ -39,5 +40,5 @@ type Context struct { type Config struct { LibraryPattern *regexp.Regexp ExcludeFromGrouping *regexp.Regexp - SourcemapMapper sourcemap.Mapper + SourcemapStore *sourcemap.Store } From 47c51367d38fe175797947d8941906d7a2e758b0 Mon Sep 17 00:00:00 2001 From: simitt Date: Wed, 13 Nov 2019 12:58:52 +0100 Subject: [PATCH 3/8] Fix failing test --- tests/system/test_integration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/test_integration.py b/tests/system/test_integration.py index ea68ebf19f8..86bc094e200 100644 --- a/tests/system/test_integration.py +++ b/tests/system/test_integration.py @@ -554,7 +554,7 @@ def test_sourcemap_cache_expiration(self): self.intake_url, 'error', 1) - self.check_rum_error_sourcemap(False, expected_err="No Sourcemap available for") + self.check_rum_error_sourcemap(False, expected_err="No Sourcemap available") class SourcemappingDisabledIntegrationTest(ClientSideElasticTest): From 18ea3090714a8088183d89c319dbb7d5796a860f Mon Sep 17 00:00:00 2001 From: simitt Date: Mon, 18 Nov 2019 10:45:29 +0100 Subject: [PATCH 4/8] Update go-elasticsearch dependency and licensing file handling. --- NOTICE.txt | 11 +- .../elastic/go-elasticsearch/v8/LICENSE | 201 ----------- .../elastic/go-elasticsearch/v8/Makefile | 2 + .../go-elasticsearch/v8/elasticsearch.go | 74 +++- .../go-elasticsearch/v8/esapi/api._.go | 2 +- .../v8/esapi/api.rank_eval.go | 13 + .../esapi/api.xpack.security.get_api_key.go | 14 + .../v8/esapi/api.xpack.slm.get_lifecycle.go | 10 +- .../api.xpack.transform.stop_transform.go | 26 ++ .../v8/estransport/connection.go | 316 ++++++++++++++++++ .../v8/estransport/discovery.go | 199 +++++++++++ .../go-elasticsearch/v8/estransport/doc.go | 18 +- .../v8/estransport/estransport.go | 147 ++++++-- .../go-elasticsearch/v8/estransport/logger.go | 29 ++ .../v8/estransport/metrics.go | 181 ++++++++++ .../v8/estransport/selector.go | 58 ---- .../cmd/generate/commands/gentests/skips.go | 2 + vendor/vendor.json | 6 +- 18 files changed, 974 insertions(+), 335 deletions(-) delete mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/LICENSE create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/estransport/connection.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/estransport/discovery.go create mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/estransport/metrics.go delete mode 100644 vendor/github.com/elastic/go-elasticsearch/v8/estransport/selector.go diff --git a/NOTICE.txt b/NOTICE.txt index ea69ba1920e..1de999ee39f 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -513,22 +513,13 @@ limitations under the License. -------------------------------------------------------------------- Dependency: github.com/elastic/go-elasticsearch -Revision: 8efb73c32e7fa9d1e2e905d9ec112d51382cabf4 +Revision: 413583419151bfec42078b5754120bb4d04bd537 License type (autodetected): Apache-2.0 ./vendor/github.com/elastic/go-elasticsearch/LICENSE: -------------------------------------------------------------------- Apache License 2.0 --------------------------------------------------------------------- -Dependency: github.com/elastic/go-elasticsearch/v8 -Revision: 8efb73c32e7fa9d1e2e905d9ec112d51382cabf4 -License type (autodetected): Apache-2.0 -./vendor/github.com/elastic/go-elasticsearch/v8/LICENSE: --------------------------------------------------------------------- -Apache License 2.0 - - -------------------------------------------------------------------- Dependency: github.com/elastic/go-lumber Revision: 616041e345fc33c97bc0eb0fa6b388aa07bca3e1 diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/LICENSE b/vendor/github.com/elastic/go-elasticsearch/v8/LICENSE deleted file mode 100644 index b1a731fb5a3..00000000000 --- a/vendor/github.com/elastic/go-elasticsearch/v8/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2018 Elasticsearch BV - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/Makefile b/vendor/github.com/elastic/go-elasticsearch/v8/Makefile index 6d09e6bfe47..2e1c36a5fe5 100644 --- a/vendor/github.com/elastic/go-elasticsearch/v8/Makefile +++ b/vendor/github.com/elastic/go-elasticsearch/v8/Makefile @@ -254,10 +254,12 @@ else $(eval xpack_env += --env "xpack.security.http.ssl.key=certs/testnode.key") $(eval xpack_env += --env "xpack.security.http.ssl.certificate=certs/testnode.crt") $(eval xpack_env += --env "xpack.security.http.ssl.certificate_authorities=certs/ca.crt") + $(eval xpack_env += --env "xpack.security.http.ssl.verification_mode=none") $(eval xpack_env += --env "xpack.security.transport.ssl.enabled=true") $(eval xpack_env += --env "xpack.security.transport.ssl.key=certs/testnode.key") $(eval xpack_env += --env "xpack.security.transport.ssl.certificate=certs/testnode.crt") $(eval xpack_env += --env "xpack.security.transport.ssl.certificate_authorities=certs/ca.crt") + $(eval xpack_env += --env "xpack.security.transport.ssl.verification_mode=none") $(eval xpack_volumes += --volume "$(PWD)/.jenkins/certs/testnode.crt:/usr/share/elasticsearch/config/certs/testnode.crt") $(eval xpack_volumes += --volume "$(PWD)/.jenkins/certs/testnode.key:/usr/share/elasticsearch/config/certs/testnode.key") $(eval xpack_volumes += --volume "$(PWD)/.jenkins/certs/ca.crt:/usr/share/elasticsearch/config/certs/ca.crt") diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/elasticsearch.go b/vendor/github.com/elastic/go-elasticsearch/v8/elasticsearch.go index d7a8b8cebff..5a5446afc34 100644 --- a/vendor/github.com/elastic/go-elasticsearch/v8/elasticsearch.go +++ b/vendor/github.com/elastic/go-elasticsearch/v8/elasticsearch.go @@ -42,10 +42,20 @@ type Config struct { EnableRetryOnTimeout bool // Default: false. MaxRetries int // Default: 3. + DiscoverNodesOnStart bool // Discover nodes when initializing the client. Default: false. + DiscoverNodesInterval time.Duration // Discover nodes periodically. Default: disabled. + + EnableMetrics bool // Enable the metrics collection. + EnableDebugLogger bool // Enable the debug logging. + RetryBackoff func(attempt int) time.Duration // Optional backoff duration. Default: nil. - Transport http.RoundTripper // The HTTP transport object. - Logger estransport.Logger // The logger object. + Transport http.RoundTripper // The HTTP transport object. + Logger estransport.Logger // The logger object. + Selector estransport.Selector // The selector object. + + // Optional constructor function for a custom ConnectionPool. Default: nil. + ConnectionPoolFunc func([]*estransport.Connection, estransport.Selector) estransport.ConnectionPool } // Client represents the Elasticsearch client. @@ -90,7 +100,7 @@ func NewClient(cfg Config) (*Client, error) { } if len(cfg.Addresses) > 0 && cfg.CloudID != "" { - return nil, errors.New("cannot create client: both Adresses and CloudID are set") + return nil, errors.New("cannot create client: both Addresses and CloudID are set") } if cfg.CloudID != "" { @@ -101,10 +111,9 @@ func NewClient(cfg Config) (*Client, error) { addrs = append(addrs, cloudAddrs) } else { if len(envAddrs) > 0 { - addrs = append(envAddrs, envAddrs...) - } - if len(cfg.Addresses) > 0 { - addrs = append(envAddrs, cfg.Addresses...) + addrs = append(addrs, envAddrs...) + } else if len(cfg.Addresses) > 0 { + addrs = append(addrs, cfg.Addresses...) } } @@ -118,6 +127,13 @@ func NewClient(cfg Config) (*Client, error) { urls = append(urls, u) } + // TODO(karmi): Refactor + if urls[0].User != nil { + cfg.Username = urls[0].User.Username() + pw, _ := urls[0].User.Password() + cfg.Password = pw + } + tp := estransport.New(estransport.Config{ URLs: urls, Username: cfg.Username, @@ -130,11 +146,24 @@ func NewClient(cfg Config) (*Client, error) { MaxRetries: cfg.MaxRetries, RetryBackoff: cfg.RetryBackoff, - Transport: cfg.Transport, - Logger: cfg.Logger, + EnableMetrics: cfg.EnableMetrics, + EnableDebugLogger: cfg.EnableDebugLogger, + + DiscoverNodesInterval: cfg.DiscoverNodesInterval, + + Transport: cfg.Transport, + Logger: cfg.Logger, + Selector: cfg.Selector, + ConnectionPoolFunc: cfg.ConnectionPoolFunc, }) - return &Client{Transport: tp, API: esapi.New(tp)}, nil + client := &Client{Transport: tp, API: esapi.New(tp)} + + if cfg.DiscoverNodesOnStart { + go client.DiscoverNodes() + } + + return client, nil } // Perform delegates to Transport to execute a request and return a response. @@ -143,6 +172,24 @@ func (c *Client) Perform(req *http.Request) (*http.Response, error) { return c.Transport.Perform(req) } +// Metrics returns the client metrics. +// +func (c *Client) Metrics() (estransport.Metrics, error) { + if mt, ok := c.Transport.(estransport.Measurable); ok { + return mt.Metrics() + } + return estransport.Metrics{}, errors.New("transport is missing method Metrics()") +} + +// DiscoverNodes reloads the client connections by fetching information from the cluster. +// +func (c *Client) DiscoverNodes() error { + if dt, ok := c.Transport.(estransport.Discoverable); ok { + return dt.DiscoverNodes() + } + return errors.New("transport is missing method DiscoverNodes()") +} + // addrsFromEnvironment returns a list of addresses by splitting // the ELASTICSEARCH_URL environment variable with comma, or an empty list. // @@ -178,10 +225,7 @@ func addrsToURLs(addrs []string) ([]*url.URL, error) { // See: https://www.elastic.co/guide/en/cloud/current/ec-cloud-id.html // func addrFromCloudID(input string) (string, error) { - var ( - port = 9243 - scheme = "https://" - ) + var scheme = "https://" values := strings.Split(input, ":") if len(values) != 2 { @@ -192,5 +236,5 @@ func addrFromCloudID(input string) (string, error) { return "", err } parts := strings.Split(string(data), "$") - return fmt.Sprintf("%s%s.%s:%d", scheme, parts[1], parts[0], port), nil + return fmt.Sprintf("%s%s.%s", scheme, parts[1], parts[0]), nil } diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api._.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api._.go index 51d9da6eba1..602b5d387c5 100644 --- a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api._.go +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api._.go @@ -1,4 +1,4 @@ -// Code generated from specification version 8.0.0 (c60139a345a): DO NOT EDIT +// Code generated from specification version 8.0.0 (beb60d2cddb): DO NOT EDIT package esapi diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.rank_eval.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.rank_eval.go index ae852e726fc..34481473e73 100644 --- a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.rank_eval.go +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.rank_eval.go @@ -42,6 +42,7 @@ type RankEvalRequest struct { AllowNoIndices *bool ExpandWildcards string IgnoreUnavailable *bool + SearchType string Pretty bool Human bool @@ -86,6 +87,10 @@ func (r RankEvalRequest) Do(ctx context.Context, transport Transport) (*Response params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) } + if r.SearchType != "" { + params["search_type"] = r.SearchType + } + if r.Pretty { params["pretty"] = "true" } @@ -189,6 +194,14 @@ func (f RankEval) WithIgnoreUnavailable(v bool) func(*RankEvalRequest) { } } +// WithSearchType - search operation type. +// +func (f RankEval) WithSearchType(v string) func(*RankEvalRequest) { + return func(r *RankEvalRequest) { + r.SearchType = v + } +} + // WithPretty makes the response body pretty-printed. // func (f RankEval) WithPretty() func(*RankEvalRequest) { diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_api_key.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_api_key.go index 8ff563d60de..ca85b3db028 100644 --- a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_api_key.go +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.security.get_api_key.go @@ -9,6 +9,7 @@ package esapi import ( "context" "net/http" + "strconv" "strings" ) @@ -35,6 +36,7 @@ type SecurityGetAPIKey func(o ...func(*SecurityGetAPIKeyRequest)) (*Response, er type SecurityGetAPIKeyRequest struct { ID string Name string + Owner *bool RealmName string Username string @@ -72,6 +74,10 @@ func (r SecurityGetAPIKeyRequest) Do(ctx context.Context, transport Transport) ( params["name"] = r.Name } + if r.Owner != nil { + params["owner"] = strconv.FormatBool(*r.Owner) + } + if r.RealmName != "" { params["realm_name"] = r.RealmName } @@ -163,6 +169,14 @@ func (f SecurityGetAPIKey) WithName(v string) func(*SecurityGetAPIKeyRequest) { } } +// WithOwner - flag to query api keys owned by the currently authenticated user. +// +func (f SecurityGetAPIKey) WithOwner(v bool) func(*SecurityGetAPIKeyRequest) { + return func(r *SecurityGetAPIKeyRequest) { + r.Owner = &v + } +} + // WithRealmName - realm name of the user who created this api key to be retrieved. // func (f SecurityGetAPIKey) WithRealmName(v string) func(*SecurityGetAPIKeyRequest) { diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.get_lifecycle.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.get_lifecycle.go index 5e20aab76b1..f6cd60b353e 100644 --- a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.get_lifecycle.go +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.slm.get_lifecycle.go @@ -33,7 +33,7 @@ type SlmGetLifecycle func(o ...func(*SlmGetLifecycleRequest)) (*Response, error) // SlmGetLifecycleRequest configures the Slm Get Lifecycle API request. // type SlmGetLifecycleRequest struct { - PolicyID string + PolicyID []string Pretty bool Human bool @@ -56,14 +56,14 @@ func (r SlmGetLifecycleRequest) Do(ctx context.Context, transport Transport) (*R method = "GET" - path.Grow(1 + len("_slm") + 1 + len("policy") + 1 + len(r.PolicyID)) + path.Grow(1 + len("_slm") + 1 + len("policy") + 1 + len(strings.Join(r.PolicyID, ","))) path.WriteString("/") path.WriteString("_slm") path.WriteString("/") path.WriteString("policy") - if r.PolicyID != "" { + if len(r.PolicyID) > 0 { path.WriteString("/") - path.WriteString(r.PolicyID) + path.WriteString(strings.Join(r.PolicyID, ",")) } params = make(map[string]string) @@ -137,7 +137,7 @@ func (f SlmGetLifecycle) WithContext(v context.Context) func(*SlmGetLifecycleReq // WithPolicyID - comma-separated list of snapshot lifecycle policies to retrieve. // -func (f SlmGetLifecycle) WithPolicyID(v string) func(*SlmGetLifecycleRequest) { +func (f SlmGetLifecycle) WithPolicyID(v ...string) func(*SlmGetLifecycleRequest) { return func(r *SlmGetLifecycleRequest) { r.PolicyID = v } diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.stop_transform.go b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.stop_transform.go index efcdc8604ff..feefaa16d3e 100644 --- a/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.stop_transform.go +++ b/vendor/github.com/elastic/go-elasticsearch/v8/esapi/api.xpack.transform.stop_transform.go @@ -38,7 +38,9 @@ type TransformStopTransformRequest struct { TransformID string AllowNoMatch *bool + Force *bool Timeout time.Duration + WaitForCheckpoint *bool WaitForCompletion *bool Pretty bool @@ -76,10 +78,18 @@ func (r TransformStopTransformRequest) Do(ctx context.Context, transport Transpo params["allow_no_match"] = strconv.FormatBool(*r.AllowNoMatch) } + if r.Force != nil { + params["force"] = strconv.FormatBool(*r.Force) + } + if r.Timeout != 0 { params["timeout"] = formatDuration(r.Timeout) } + if r.WaitForCheckpoint != nil { + params["wait_for_checkpoint"] = strconv.FormatBool(*r.WaitForCheckpoint) + } + if r.WaitForCompletion != nil { params["wait_for_completion"] = strconv.FormatBool(*r.WaitForCompletion) } @@ -159,6 +169,14 @@ func (f TransformStopTransform) WithAllowNoMatch(v bool) func(*TransformStopTran } } +// WithForce - whether to force stop a failed transform or not. default to false. +// +func (f TransformStopTransform) WithForce(v bool) func(*TransformStopTransformRequest) { + return func(r *TransformStopTransformRequest) { + r.Force = &v + } +} + // WithTimeout - controls the time to wait until the transform has stopped. default to 30 seconds. // func (f TransformStopTransform) WithTimeout(v time.Duration) func(*TransformStopTransformRequest) { @@ -167,6 +185,14 @@ func (f TransformStopTransform) WithTimeout(v time.Duration) func(*TransformStop } } +// WithWaitForCheckpoint - whether to wait for the transform to reach a checkpoint before stopping. default to false. +// +func (f TransformStopTransform) WithWaitForCheckpoint(v bool) func(*TransformStopTransformRequest) { + return func(r *TransformStopTransformRequest) { + r.WaitForCheckpoint = &v + } +} + // WithWaitForCompletion - whether to wait for the transform to fully stop before returning or not. default to false. // func (f TransformStopTransform) WithWaitForCompletion(v bool) func(*TransformStopTransformRequest) { diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/estransport/connection.go b/vendor/github.com/elastic/go-elasticsearch/v8/estransport/connection.go new file mode 100644 index 00000000000..7764a503bb4 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/estransport/connection.go @@ -0,0 +1,316 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package estransport + +import ( + "errors" + "fmt" + "math" + "net/url" + "sort" + "sync" + "time" +) + +var ( + defaultResurrectTimeoutInitial = 60 * time.Second + defaultResurrectTimeoutFactorCutoff = 5 +) + +// Selector defines the interface for selecting connections from the pool. +// +type Selector interface { + Select([]*Connection) (*Connection, error) +} + +// ConnectionPool defines the interface for the connection pool. +// +type ConnectionPool interface { + Next() (*Connection, error) // Next returns the next available connection. + OnSuccess(*Connection) error // OnSuccess reports that the connection was successful. + OnFailure(*Connection) error // OnFailure reports that the connection failed. + URLs() []*url.URL // URLs returns the list of URLs of available connections. +} + +// Connection represents a connection to a node. +// +type Connection struct { + sync.Mutex + + URL *url.URL + IsDead bool + DeadSince time.Time + Failures int + + ID string + Name string + Roles []string + Attributes map[string]interface{} +} + +type singleConnectionPool struct { + connection *Connection + + metrics *metrics +} + +type statusConnectionPool struct { + sync.Mutex + + live []*Connection // List of live connections + dead []*Connection // List of dead connections + selector Selector + + metrics *metrics +} + +type roundRobinSelector struct { + sync.Mutex + + curr int // Index of the current connection +} + +// NewConnectionPool creates and returns a default connection pool. +// +func NewConnectionPool(conns []*Connection, selector Selector) (ConnectionPool, error) { + if len(conns) == 1 { + return &singleConnectionPool{connection: conns[0]}, nil + } + if selector == nil { + selector = &roundRobinSelector{curr: -1} + } + return &statusConnectionPool{live: conns, selector: selector}, nil +} + +// Next returns the connection from pool. +// +func (cp *singleConnectionPool) Next() (*Connection, error) { + return cp.connection, nil +} + +// OnSuccess is a no-op for single connection pool. +func (cp *singleConnectionPool) OnSuccess(c *Connection) error { return nil } + +// OnFailure is a no-op for single connection pool. +func (cp *singleConnectionPool) OnFailure(c *Connection) error { return nil } + +// URLs returns the list of URLs of available connections. +func (cp *singleConnectionPool) URLs() []*url.URL { return []*url.URL{cp.connection.URL} } + +func (cp *singleConnectionPool) connections() []*Connection { return []*Connection{cp.connection} } + +// Next returns a connection from pool, or an error. +// +func (cp *statusConnectionPool) Next() (*Connection, error) { + cp.Lock() + defer cp.Unlock() + + // Return next live connection + if len(cp.live) > 0 { + return cp.selector.Select(cp.live) + } else if len(cp.dead) > 0 { + // No live connection is available, resurrect one of the dead ones. + c := cp.dead[len(cp.dead)-1] + cp.dead = cp.dead[:len(cp.dead)-1] + c.Lock() + defer c.Unlock() + cp.resurrect(c, false) + return c, nil + } + return nil, errors.New("no connection available") +} + +// OnSuccess marks the connection as successful. +// +func (cp *statusConnectionPool) OnSuccess(c *Connection) error { + c.Lock() + defer c.Unlock() + + // Short-circuit for live connection + if !c.IsDead { + return nil + } + + c.markAsHealthy() + + cp.Lock() + defer cp.Unlock() + return cp.resurrect(c, true) +} + +// OnFailure marks the connection as failed. +// +func (cp *statusConnectionPool) OnFailure(c *Connection) error { + cp.Lock() + defer cp.Unlock() + + c.Lock() + + if c.IsDead { + if debugLogger != nil { + debugLogger.Logf("Already removed %s\n", c.URL) + } + c.Unlock() + return nil + } + + if debugLogger != nil { + debugLogger.Logf("Removing %s...\n", c.URL) + } + c.markAsDead() + cp.scheduleResurrect(c) + c.Unlock() + + // Push item to dead list and sort slice by number of failures + cp.dead = append(cp.dead, c) + sort.Slice(cp.dead, func(i, j int) bool { + c1 := cp.dead[i] + c2 := cp.dead[j] + c1.Lock() + c2.Lock() + defer c1.Unlock() + defer c2.Unlock() + + res := c1.Failures > c2.Failures + return res + }) + + // Check if connection exists in the list, return error if not. + index := -1 + for i, conn := range cp.live { + if conn == c { + index = i + } + } + if index < 0 { + return errors.New("connection not in live list") + } + + // Remove item; https://github.com/golang/go/wiki/SliceTricks + copy(cp.live[index:], cp.live[index+1:]) + cp.live = cp.live[:len(cp.live)-1] + + return nil +} + +// URLs returns the list of URLs of available connections. +// +func (cp *statusConnectionPool) URLs() []*url.URL { + var urls []*url.URL + + cp.Lock() + defer cp.Unlock() + + for _, c := range cp.live { + urls = append(urls, c.URL) + } + + return urls +} + +func (cp *statusConnectionPool) connections() []*Connection { + var conns []*Connection + conns = append(conns, cp.live...) + conns = append(conns, cp.dead...) + return conns +} + +// resurrect adds the connection to the list of available connections. +// When removeDead is true, it also removes it from the dead list. +// The calling code is responsible for locking. +// +func (cp *statusConnectionPool) resurrect(c *Connection, removeDead bool) error { + if debugLogger != nil { + debugLogger.Logf("Resurrecting %s\n", c.URL) + } + + c.markAsLive() + cp.live = append(cp.live, c) + + if removeDead { + index := -1 + for i, conn := range cp.dead { + if conn == c { + index = i + } + } + if index >= 0 { + // Remove item; https://github.com/golang/go/wiki/SliceTricks + copy(cp.dead[index:], cp.dead[index+1:]) + cp.dead = cp.dead[:len(cp.dead)-1] + } + } + + return nil +} + +// scheduleResurrect schedules the connection to be resurrected. +// +func (cp *statusConnectionPool) scheduleResurrect(c *Connection) { + factor := math.Min(float64(c.Failures-1), float64(defaultResurrectTimeoutFactorCutoff)) + timeout := time.Duration(defaultResurrectTimeoutInitial.Seconds() * math.Exp2(factor) * float64(time.Second)) + if debugLogger != nil { + debugLogger.Logf("Resurrect %s (failures=%d, factor=%1.1f, timeout=%s) in %s\n", c.URL, c.Failures, factor, timeout, c.DeadSince.Add(timeout).Sub(time.Now().UTC()).Truncate(time.Second)) + } + + time.AfterFunc(timeout, func() { + cp.Lock() + defer cp.Unlock() + + c.Lock() + defer c.Unlock() + + if !c.IsDead { + if debugLogger != nil { + debugLogger.Logf("Already resurrected %s\n", c.URL) + } + return + } + + cp.resurrect(c, true) + }) +} + +// Select returns the connection in a round-robin fashion. +// +func (s *roundRobinSelector) Select(conns []*Connection) (*Connection, error) { + s.Lock() + defer s.Unlock() + + s.curr = (s.curr + 1) % len(conns) + return conns[s.curr], nil +} + +// markAsDead marks the connection as dead. +// +func (c *Connection) markAsDead() { + c.IsDead = true + if c.DeadSince.IsZero() { + c.DeadSince = time.Now().UTC() + } + c.Failures++ +} + +// markAsLive marks the connection as alive. +// +func (c *Connection) markAsLive() { + c.IsDead = false +} + +// markAsHealthy marks the connection as healthy. +// +func (c *Connection) markAsHealthy() { + c.IsDead = false + c.DeadSince = time.Time{} + c.Failures = 0 +} + +// String returns a readable connection representation. +// +func (c *Connection) String() string { + c.Lock() + defer c.Unlock() + return fmt.Sprintf("<%s> dead=%v failures=%d", c.URL, c.IsDead, c.Failures) +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/estransport/discovery.go b/vendor/github.com/elastic/go-elasticsearch/v8/estransport/discovery.go new file mode 100644 index 00000000000..b82291cda81 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/estransport/discovery.go @@ -0,0 +1,199 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package estransport + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + "net/url" + "sort" + "strings" + "sync" + "time" +) + +// Discoverable defines the interface for transports supporting node discovery. +// +type Discoverable interface { + DiscoverNodes() error +} + +// nodeInfo represents the information about node in a cluster. +// +// See: https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-nodes-info.html +// +type nodeInfo struct { + ID string + Name string + URL *url.URL + Roles []string + Attributes map[string]interface{} + HTTP struct { + PublishAddress string `json:"publish_address"` + } +} + +// DiscoverNodes reloads the client connections by fetching information from the cluster. +// +func (c *Client) DiscoverNodes() error { + var conns []*Connection + + nodes, err := c.getNodesInfo() + if err != nil { + if debugLogger != nil { + debugLogger.Logf("Error getting nodes info: %s\n", err) + } + return fmt.Errorf("discovery: get nodes: %s", err) + } + + for _, node := range nodes { + var ( + isDataNode bool + isIngestNode bool + ) + + roles := append(node.Roles[:0:0], node.Roles...) + sort.Strings(roles) + + if i := sort.SearchStrings(roles, "data"); i < len(roles) && roles[i] == "data" { + isDataNode = true + } + if i := sort.SearchStrings(roles, "ingest"); i < len(roles) && roles[i] == "ingest" { + isIngestNode = true + } + + if debugLogger != nil { + var skip string + if !isDataNode || !isIngestNode { + skip = "; [SKIP]" + } + debugLogger.Logf("Discovered node [%s]; %s; roles=%s%s\n", node.Name, node.URL, node.Roles, skip) + } + + // Skip master only nodes + // TODO(karmi): Move logic to Selector? + if !isDataNode || !isIngestNode { + continue + } + + conns = append(conns, &Connection{ + URL: node.URL, + ID: node.ID, + Name: node.Name, + Roles: node.Roles, + Attributes: node.Attributes, + }) + } + + c.Lock() + defer c.Unlock() + + if lockable, ok := c.pool.(sync.Locker); ok { + lockable.Lock() + defer lockable.Unlock() + } + + if c.poolFunc != nil { + c.pool = c.poolFunc(conns, c.selector) + } else { + // TODO(karmi): Replace only live connections, leave dead scheduled for resurrect? + c.pool, err = NewConnectionPool(conns, c.selector) + if err != nil { + return err + } + } + + return nil +} + +func (c *Client) getNodesInfo() ([]nodeInfo, error) { + var ( + out []nodeInfo + scheme = c.urls[0].Scheme + ) + + req, err := http.NewRequest("GET", "/_nodes/http", nil) + if err != nil { + return out, err + } + + c.Lock() + conn, err := c.pool.Next() + c.Unlock() + // TODO(karmi): If no connection is returned, fallback to original URLs + if err != nil { + return out, err + } + + c.setReqURL(conn.URL, req) + c.setReqAuth(conn.URL, req) + c.setReqUserAgent(req) + + res, err := c.transport.RoundTrip(req) + if err != nil { + return out, err + } + defer res.Body.Close() + + if res.StatusCode > 200 { + body, _ := ioutil.ReadAll(res.Body) + return out, fmt.Errorf("server error: %s: %s", res.Status, body) + } + + var env map[string]json.RawMessage + if err := json.NewDecoder(res.Body).Decode(&env); err != nil { + return out, err + } + + var nodes map[string]nodeInfo + if err := json.Unmarshal(env["nodes"], &nodes); err != nil { + return out, err + } + + for id, node := range nodes { + node.ID = id + u, err := c.getNodeURL(node, scheme) + if err != nil { + return out, err + } + node.URL = u + out = append(out, node) + } + + return out, nil +} + +func (c *Client) getNodeURL(node nodeInfo, scheme string) (*url.URL, error) { + var ( + host string + port string + + addrs = strings.Split(node.HTTP.PublishAddress, "/") + ports = strings.Split(node.HTTP.PublishAddress, ":") + ) + + if len(addrs) > 1 { + host = addrs[0] + } else { + host = strings.Split(addrs[0], ":")[0] + } + port = ports[len(ports)-1] + + u := &url.URL{ + Scheme: scheme, + Host: host + ":" + port, + } + + return u, nil +} + +func (c *Client) scheduleDiscoverNodes(d time.Duration) { + go c.DiscoverNodes() + time.AfterFunc(c.discoverNodesInterval, func() { + c.scheduleDiscoverNodes(c.discoverNodesInterval) + }) +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/estransport/doc.go b/vendor/github.com/elastic/go-elasticsearch/v8/estransport/doc.go index e65e34284f6..096b730707f 100644 --- a/vendor/github.com/elastic/go-elasticsearch/v8/estransport/doc.go +++ b/vendor/github.com/elastic/go-elasticsearch/v8/estransport/doc.go @@ -5,11 +5,7 @@ It is automatically included in the client provided by the github.com/elastic/go and is not intended for direct use: to configure the client, use the elasticsearch.Config struct. The default HTTP transport of the client is http.Transport; use the Transport option to customize it; -see the _examples/customization.go file in this repository for information. - -The package defines the "Selector" interface for getting a URL from the list. At the moment, -the implementation is rather minimal: the client takes a slice of url.URL pointers, -and round-robins across them when performing the request. +see the _examples/coniguration.go and _examples/customization.go files in this repository for information. The package will automatically retry requests on network-related errors, and on specific response status codes (by default 502, 503, 504). Use the RetryOnStatus option to customize the list. @@ -21,8 +17,18 @@ to disable the retry behaviour altogether. By default, the retry will be performed without any delay; to configure a backoff interval, implement the RetryBackoff option function; see an example in the package unit tests for information. -The package defines the "Logger" interface for logging information about request and response. +When multiple addresses are passed in configuration, the package will use them in a round-robin fashion, +and will keep track of live and dead nodes. The status of dead nodes is checked periodically. + +To customize the node selection behaviour, provide a Selector implementation in the configuration. +To replace the connection pool entirely, provide a custom ConnectionPool implementation via +the ConnectionPoolFunc option. + +The package defines the Logger interface for logging information about request and response. It comes with several bundled loggers for logging in text and JSON. +Use the EnableDebugLogger option to enable the debugging logger for connection management. + +Use the EnableMetrics option to enable metric collection and export. */ package estransport diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/estransport/estransport.go b/vendor/github.com/elastic/go-elasticsearch/v8/estransport/estransport.go index da8315a1478..8e89c09f464 100644 --- a/vendor/github.com/elastic/go-elasticsearch/v8/estransport/estransport.go +++ b/vendor/github.com/elastic/go-elasticsearch/v8/estransport/estransport.go @@ -12,9 +12,11 @@ import ( "net" "net/http" "net/url" + "os" "regexp" "runtime" "strings" + "sync" "time" "github.com/elastic/go-elasticsearch/v8/internal/version" @@ -56,30 +58,45 @@ type Config struct { MaxRetries int RetryBackoff func(attempt int) time.Duration + EnableMetrics bool + EnableDebugLogger bool + + DiscoverNodesInterval time.Duration + Transport http.RoundTripper Logger Logger + Selector Selector + + ConnectionPoolFunc func([]*Connection, Selector) ConnectionPool } // Client represents the HTTP client. // type Client struct { + sync.Mutex + urls []*url.URL username string password string apikey string - retryOnStatus []int - disableRetry bool - enableRetryOnTimeout bool - maxRetries int - retryBackoff func(attempt int) time.Duration + retryOnStatus []int + disableRetry bool + enableRetryOnTimeout bool + maxRetries int + retryBackoff func(attempt int) time.Duration + discoverNodesInterval time.Duration + + metrics *metrics transport http.RoundTripper - selector Selector logger Logger + selector Selector + pool ConnectionPool + poolFunc func([]*Connection, Selector) ConnectionPool } -// New creates new HTTP client. +// New creates new transport client. // // http.DefaultTransport will be used if no transport is passed in the configuration. // @@ -96,22 +113,58 @@ func New(cfg Config) *Client { cfg.MaxRetries = defaultMaxRetries } - return &Client{ + var conns []*Connection + for _, u := range cfg.URLs { + conns = append(conns, &Connection{URL: u}) + } + + client := Client{ urls: cfg.URLs, username: cfg.Username, password: cfg.Password, apikey: cfg.APIKey, - retryOnStatus: cfg.RetryOnStatus, - disableRetry: cfg.DisableRetry, - enableRetryOnTimeout: cfg.EnableRetryOnTimeout, - maxRetries: cfg.MaxRetries, - retryBackoff: cfg.RetryBackoff, + retryOnStatus: cfg.RetryOnStatus, + disableRetry: cfg.DisableRetry, + enableRetryOnTimeout: cfg.EnableRetryOnTimeout, + maxRetries: cfg.MaxRetries, + retryBackoff: cfg.RetryBackoff, + discoverNodesInterval: cfg.DiscoverNodesInterval, transport: cfg.Transport, - selector: NewRoundRobinSelector(cfg.URLs...), logger: cfg.Logger, + selector: cfg.Selector, + poolFunc: cfg.ConnectionPoolFunc, + } + + if client.poolFunc != nil { + client.pool = client.poolFunc(conns, client.selector) + } else { + client.pool, _ = NewConnectionPool(conns, client.selector) + } + + if cfg.EnableDebugLogger { + debugLogger = &debuggingLogger{Output: os.Stdout} + } + + if cfg.EnableMetrics { + client.metrics = &metrics{responses: make(map[int]int)} + // TODO(karmi): Type assertion to interface + if pool, ok := client.pool.(*singleConnectionPool); ok { + pool.metrics = client.metrics + } + if pool, ok := client.pool.(*statusConnectionPool); ok { + pool.metrics = client.metrics + } + } + + if client.discoverNodesInterval > 0 { + time.AfterFunc(client.discoverNodesInterval, func() { + client.scheduleDiscoverNodes(client.discoverNodesInterval) + }) } + + return &client } // Perform executes the request and returns a response or error. @@ -122,8 +175,14 @@ func (c *Client) Perform(req *http.Request) (*http.Response, error) { err error ) + // Record metrics, when enabled + if c.metrics != nil { + c.metrics.Lock() + c.metrics.requests++ + c.metrics.Unlock() + } + // Update request - // c.setReqUserAgent(req) if req.Body != nil && req.Body != http.NoBody && req.GetBody == nil { @@ -142,22 +201,24 @@ func (c *Client) Perform(req *http.Request) (*http.Response, error) { for i := 1; i <= c.maxRetries; i++ { var ( - nodeURL *url.URL + conn *Connection shouldRetry bool ) - // Get URL from the Selector - // - nodeURL, err = c.getURL() + // Get connection from the pool + c.Lock() + conn, err = c.pool.Next() + c.Unlock() if err != nil { - // TODO(karmi): Log error - return nil, fmt.Errorf("cannot get URL: %s", err) + if c.logger != nil { + c.logRoundTrip(req, nil, err, time.Time{}, time.Duration(0)) + } + return nil, fmt.Errorf("cannot get connection: %s", err) } // Update request - // - c.setReqURL(nodeURL, req) - c.setReqAuth(nodeURL, req) + c.setReqURL(conn.URL, req) + c.setReqAuth(conn.URL, req) if !c.disableRetry && i > 1 && req.Body != nil && req.Body != http.NoBody { body, err := req.GetBody() @@ -168,13 +229,11 @@ func (c *Client) Perform(req *http.Request) (*http.Response, error) { } // Set up time measures and execute the request - // start := time.Now().UTC() res, err = c.transport.RoundTrip(req) dur := time.Since(start) // Log request and response - // if c.logger != nil { if c.logger.RequestBodyEnabled() && req.Body != nil && req.Body != http.NoBody { req.Body, _ = req.GetBody() @@ -182,18 +241,39 @@ func (c *Client) Perform(req *http.Request) (*http.Response, error) { c.logRoundTrip(req, res, err, start, dur) } - // Retry only on network errors, but don't retry on timeout errors, unless configured - // if err != nil { + // Record metrics, when enabled + if c.metrics != nil { + c.metrics.Lock() + c.metrics.failures++ + c.metrics.Unlock() + } + + // Report the connection as unsuccessful + c.Lock() + c.pool.OnFailure(conn) + c.Unlock() + + // Retry only on network errors, but don't retry on timeout errors, unless configured if err, ok := err.(net.Error); ok { if (!err.Timeout() || c.enableRetryOnTimeout) && !c.disableRetry { shouldRetry = true } } + } else { + // Report the connection as succesfull + c.Lock() + c.pool.OnSuccess(conn) + c.Unlock() + } + + if res != nil && c.metrics != nil { + c.metrics.Lock() + c.metrics.responses[res.StatusCode]++ + c.metrics.Unlock() } // Retry on configured response statuses - // if res != nil && !c.disableRetry { for _, code := range c.retryOnStatus { if res.StatusCode == code { @@ -203,13 +283,11 @@ func (c *Client) Perform(req *http.Request) (*http.Response, error) { } // Break if retry should not be performed - // if !shouldRetry { break } // Delay the retry if a backoff function is configured - // if c.retryBackoff != nil { time.Sleep(c.retryBackoff(i)) } @@ -221,12 +299,9 @@ func (c *Client) Perform(req *http.Request) (*http.Response, error) { // URLs returns a list of transport URLs. // +// func (c *Client) URLs() []*url.URL { - return c.urls -} - -func (c *Client) getURL() (*url.URL, error) { - return c.selector.Select() + return c.pool.URLs() } func (c *Client) setReqURL(u *url.URL, req *http.Request) *http.Request { diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/estransport/logger.go b/vendor/github.com/elastic/go-elasticsearch/v8/estransport/logger.go index 263c80c5a51..4f0af98a3a6 100644 --- a/vendor/github.com/elastic/go-elasticsearch/v8/estransport/logger.go +++ b/vendor/github.com/elastic/go-elasticsearch/v8/estransport/logger.go @@ -18,6 +18,8 @@ import ( "time" ) +var debugLogger DebuggingLogger + // Logger defines an interface for logging request and response. // type Logger interface { @@ -30,6 +32,13 @@ type Logger interface { ResponseBodyEnabled() bool } +// DebuggingLogger defines the interface for a debugging logger. +// +type DebuggingLogger interface { + Log(a ...interface{}) error + Logf(format string, a ...interface{}) error +} + // TextLogger prints the log message in plain text. // type TextLogger struct { @@ -62,6 +71,12 @@ type JSONLogger struct { EnableResponseBody bool } +// debuggingLogger prints debug messages as plain text. +// +type debuggingLogger struct { + Output io.Writer +} + // LogRoundTrip prints the information about request and response. // func (l *TextLogger) LogRoundTrip(req *http.Request, res *http.Response, err error, start time.Time, dur time.Duration) error { @@ -375,6 +390,20 @@ func (l *JSONLogger) RequestBodyEnabled() bool { return l.EnableRequestBody } // ResponseBodyEnabled returns true when the response body should be logged. func (l *JSONLogger) ResponseBodyEnabled() bool { return l.EnableResponseBody } +// Log prints the arguments to output in default format. +// +func (l *debuggingLogger) Log(a ...interface{}) error { + _, err := fmt.Fprint(l.Output, a...) + return err +} + +// Logf prints formats the arguments and prints them to output. +// +func (l *debuggingLogger) Logf(format string, a ...interface{}) error { + _, err := fmt.Fprintf(l.Output, format, a...) + return err +} + func logBodyAsText(dst io.Writer, body io.Reader, prefix string) { scanner := bufio.NewScanner(body) for scanner.Scan() { diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/estransport/metrics.go b/vendor/github.com/elastic/go-elasticsearch/v8/estransport/metrics.go new file mode 100644 index 00000000000..c01df0a2c35 --- /dev/null +++ b/vendor/github.com/elastic/go-elasticsearch/v8/estransport/metrics.go @@ -0,0 +1,181 @@ +// Licensed to Elasticsearch B.V. under one or more agreements. +// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +package estransport + +import ( + "errors" + "fmt" + "strconv" + "strings" + "sync" + "time" +) + +// Measurable defines the interface for transports supporting metrics. +// +type Measurable interface { + Metrics() (Metrics, error) +} + +// connectionable defines the interface for transports returning a list of connections. +// +type connectionable interface { + connections() []*Connection +} + +// Metrics represents the transport metrics. +// +type Metrics struct { + Requests int `json:"requests"` + Failures int `json:"failures"` + Responses map[int]int `json:"responses"` + + Connections []fmt.Stringer `json:"connections"` +} + +// ConnectionMetric represents metric information for a connection. +// +type ConnectionMetric struct { + URL string `json:"url"` + Failures int `json:"failures,omitempty"` + IsDead bool `json:"dead,omitempty"` + DeadSince *time.Time `json:"dead_since,omitempty"` + + Meta struct { + ID string `json:"id"` + Name string `json:"name"` + Roles []string `json:"roles"` + } `json:"meta"` +} + +// metrics represents the inner state of metrics. +// +type metrics struct { + sync.RWMutex + + requests int + failures int + responses map[int]int + + connections []*Connection +} + +// Metrics returns the transport metrics. +// +func (c *Client) Metrics() (Metrics, error) { + if c.metrics == nil { + return Metrics{}, errors.New("transport metrics not enabled") + } + c.metrics.RLock() + defer c.metrics.RUnlock() + + if lockable, ok := c.pool.(sync.Locker); ok { + lockable.Lock() + defer lockable.Unlock() + } + + m := Metrics{ + Requests: c.metrics.requests, + Failures: c.metrics.failures, + Responses: c.metrics.responses, + } + + if pool, ok := c.pool.(connectionable); ok { + for _, c := range pool.connections() { + c.Lock() + + cm := ConnectionMetric{ + URL: c.URL.String(), + IsDead: c.IsDead, + Failures: c.Failures, + } + + if !c.DeadSince.IsZero() { + cm.DeadSince = &c.DeadSince + } + + if c.ID != "" { + cm.Meta.ID = c.ID + } + + if c.Name != "" { + cm.Meta.Name = c.Name + } + + if len(c.Roles) > 0 { + cm.Meta.Roles = c.Roles + } + + m.Connections = append(m.Connections, cm) + c.Unlock() + } + } + + return m, nil +} + +// String returns the metrics as a string. +// +func (m Metrics) String() string { + var ( + i int + b strings.Builder + ) + b.WriteString("{") + + b.WriteString("Requests:") + b.WriteString(strconv.Itoa(m.Requests)) + + b.WriteString(" Failures:") + b.WriteString(strconv.Itoa(m.Failures)) + + if len(m.Responses) > 0 { + b.WriteString(" Responses: ") + b.WriteString("[") + + for code, num := range m.Responses { + b.WriteString(strconv.Itoa(code)) + b.WriteString(":") + b.WriteString(strconv.Itoa(num)) + if i+1 < len(m.Responses) { + b.WriteString(", ") + } + i++ + } + b.WriteString("]") + } + + b.WriteString(" Connections: [") + for i, c := range m.Connections { + b.WriteString(c.String()) + if i+1 < len(m.Connections) { + b.WriteString(", ") + } + i++ + } + b.WriteString("]") + + b.WriteString("}") + return b.String() +} + +// String returns the connection information as a string. +// +func (cm ConnectionMetric) String() string { + var b strings.Builder + b.WriteString("{") + b.WriteString(cm.URL) + if cm.IsDead { + fmt.Fprintf(&b, " dead=%v", cm.IsDead) + } + if cm.Failures > 0 { + fmt.Fprintf(&b, " failures=%d", cm.Failures) + } + if cm.DeadSince != nil { + fmt.Fprintf(&b, " dead_since=%s", cm.DeadSince.Local().Format(time.Stamp)) + } + b.WriteString("}") + return b.String() +} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/estransport/selector.go b/vendor/github.com/elastic/go-elasticsearch/v8/estransport/selector.go deleted file mode 100644 index f4a8d3d530f..00000000000 --- a/vendor/github.com/elastic/go-elasticsearch/v8/estransport/selector.go +++ /dev/null @@ -1,58 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more agreements. -// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License. -// See the LICENSE file in the project root for more information. - -package estransport - -import ( - "container/ring" - "errors" - "net/url" - "sync" -) - -// Selector defines the interface for selecting URLs for performing request. -// -type Selector interface { - Select() (*url.URL, error) -} - -// RoundRobinSelector implements a round-robin selection strategy. -// -type RoundRobinSelector struct { - sync.Mutex - ring *ring.Ring -} - -// Select returns a URL or error from the list of URLs in a round-robin fashion. -// -func (r *RoundRobinSelector) Select() (*url.URL, error) { - r.Lock() - defer r.Unlock() - - if r.ring.Len() < 1 { - return nil, errors.New("No URL available") - } - - v := r.ring.Value - if ov, ok := v.(*url.URL); !ok || ov == nil { - return nil, errors.New("No URL available") - } - - r.ring = r.ring.Next() - return v.(*url.URL), nil -} - -// NewRoundRobinSelector creates a new RoundRobinSelector. -// -func NewRoundRobinSelector(urls ...*url.URL) *RoundRobinSelector { - r := RoundRobinSelector{} - - r.ring = ring.New(len(urls)) - for _, u := range urls { - r.ring.Value = u - r.ring = r.ring.Next() - } - - return &r -} diff --git a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/skips.go b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/skips.go index 7b6535b214a..c16c1154cb2 100644 --- a/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/skips.go +++ b/vendor/github.com/elastic/go-elasticsearch/v8/internal/cmd/generate/commands/gentests/skips.go @@ -110,6 +110,8 @@ bulk/81_cas_with_types.yml: # Stash in body api_key/10_basic.yml: - Test invalidate api key +api_key/11_invalidation.yml: + - Test invalidate api key by username rollup/put_job.yml: - Test put job with templates diff --git a/vendor/vendor.json b/vendor/vendor.json index 66a397ee2eb..a98c64c039d 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -1497,10 +1497,10 @@ "revisionTime": "2019-10-18T23:19:20Z" }, { - "checksumSHA1": "wgane+Jx/akhNYEAqL/TlxwvkYg=", + "checksumSHA1": "cSNhWI3euRSQv1BsIKpx/M59B4o=", "path": "github.com/elastic/go-elasticsearch/v8", - "revision": "8efb73c32e7fa9d1e2e905d9ec112d51382cabf4", - "revisionTime": "2019-10-22T14:22:00Z", + "revision": "413583419151bfec42078b5754120bb4d04bd537", + "revisionTime": "2019-11-16T09:03:43Z", "tree": true }, { From 85cdfe5d8d4e5a4472b098d7af0ef77a9b8e4596 Mon Sep 17 00:00:00 2001 From: simitt Date: Mon, 18 Nov 2019 11:48:05 +0100 Subject: [PATCH 5/8] Adapt to PR comments --- beater/beater_test.go | 295 ----------------------------------- beater/config/config.go | 38 +---- beater/config/config_test.go | 4 +- beater/config/register.go | 31 ++++ beater/config/rum.go | 6 + beater/server_test.go | 98 +++++++++++- model/stacktrace_frame.go | 9 +- sourcemap/error.go | 32 ---- sourcemap/es_store.go | 62 +++----- sourcemap/store.go | 13 +- sourcemap/store_test.go | 29 +++- 11 files changed, 188 insertions(+), 429 deletions(-) delete mode 100644 sourcemap/error.go diff --git a/beater/beater_test.go b/beater/beater_test.go index bf04b505bb6..aac026d75ff 100644 --- a/beater/beater_test.go +++ b/beater/beater_test.go @@ -24,225 +24,15 @@ import ( "net" "net/http" "net/url" - "path/filepath" "testing" "time" "github.com/stretchr/testify/require" - "github.com/stretchr/testify/assert" - "github.com/elastic/beats/libbeat/beat" "github.com/elastic/beats/libbeat/common" - "github.com/elastic/beats/libbeat/common/transport/tlscommon" - "github.com/elastic/beats/libbeat/logp" - "github.com/elastic/beats/libbeat/outputs" - pubs "github.com/elastic/beats/libbeat/publisher" - "github.com/elastic/beats/libbeat/publisher/pipeline" - "github.com/elastic/beats/libbeat/publisher/processing" - "github.com/elastic/beats/libbeat/publisher/queue" - "github.com/elastic/beats/libbeat/publisher/queue/memqueue" - - "github.com/elastic/apm-server/beater/config" ) -func TestBeatConfig(t *testing.T) { - falsy, truthy := false, true - - tests := map[string]struct { - conf map[string]interface{} - beaterConf *config.Config - }{ - "default config": { - conf: map[string]interface{}{}, - beaterConf: config.DefaultConfig("6.2.0"), - }, - "overwrite default config": { - conf: map[string]interface{}{ - "host": "localhost:3000", - "max_header_size": 8, - "max_event_size": 100, - "idle_timeout": 5 * time.Second, - "read_timeout": 3 * time.Second, - "write_timeout": 4 * time.Second, - "shutdown_timeout": 9 * time.Second, - "capture_personal_data": true, - "secret_token": "1234random", - "ssl": map[string]interface{}{ - "enabled": true, - "key": "1234key", - "certificate": "1234cert", - "client_authentication": "none", - }, - "expvar": map[string]interface{}{ - "enabled": true, - "url": "/debug/vars", - }, - "rum": map[string]interface{}{ - "enabled": true, - "event_rate": map[string]interface{}{ - "limit": 7200, - "lru_size": 2000, - }, - "allow_origins": []string{"example*"}, - "source_mapping": map[string]interface{}{ - "cache": map[string]interface{}{ - "expiration": 8 * time.Minute, - }, - "index_pattern": "apm-test*", - }, - "library_pattern": "^custom", - "exclude_from_grouping": "^grouping", - }, - "register": map[string]interface{}{ - "ingest": map[string]interface{}{ - "pipeline": map[string]interface{}{ - "overwrite": false, - "path": filepath.Join("tmp", "definition.json"), - }, - }, - }, - "kibana": map[string]interface{}{"enabled": "true"}, - "agent.config.cache.expiration": "2m", - }, - beaterConf: &config.Config{ - Host: "localhost:3000", - MaxHeaderSize: 8, - MaxEventSize: 100, - IdleTimeout: 5000000000, - ReadTimeout: 3000000000, - WriteTimeout: 4000000000, - ShutdownTimeout: 9000000000, - SecretToken: "1234random", - TLS: &tlscommon.ServerConfig{ - Enabled: &truthy, - Certificate: outputs.CertificateConfig{Certificate: "1234cert", Key: "1234key"}, - ClientAuth: 0}, - AugmentEnabled: true, - Expvar: &config.ExpvarConfig{ - Enabled: &truthy, - URL: "/debug/vars", - }, - RumConfig: &config.RumConfig{ - Enabled: &truthy, - EventRate: &config.EventRate{ - Limit: 7200, - LruSize: 2000, - }, - AllowOrigins: []string{"example*"}, - SourceMapping: &config.SourceMapping{ - Cache: &config.Cache{Expiration: 8 * time.Minute}, - IndexPattern: "apm-test*", - }, - LibraryPattern: "^custom", - ExcludeFromGrouping: "^grouping", - BeatVersion: "6.2.0", - }, - Register: &config.RegisterConfig{ - Ingest: &config.IngestConfig{ - Pipeline: &config.PipelineConfig{ - Enabled: &truthy, - Overwrite: &falsy, - Path: filepath.Join("tmp", "definition.json"), - }, - }, - }, - Kibana: common.MustNewConfigFrom(map[string]interface{}{"enabled": "true"}), - AgentConfig: &config.AgentConfig{Cache: &config.Cache{Expiration: 2 * time.Minute}}, - Pipeline: config.DefaultAPMPipeline, - }, - }, - "merge config with default": { - conf: map[string]interface{}{ - "host": "localhost:3000", - "secret_token": "1234random", - "ssl": map[string]interface{}{ - "enabled": true, - }, - "expvar": map[string]interface{}{ - "enabled": true, - "url": "/debug/vars", - }, - "rum": map[string]interface{}{ - "enabled": true, - "source_mapping": map[string]interface{}{ - "cache": map[string]interface{}{ - "expiration": 7, - }, - }, - "library_pattern": "rum", - }, - "register": map[string]interface{}{ - "ingest": map[string]interface{}{ - "pipeline": map[string]interface{}{ - "enabled": false, - }, - }, - }, - }, - beaterConf: &config.Config{ - Host: "localhost:3000", - MaxHeaderSize: 1048576, - MaxEventSize: 307200, - IdleTimeout: 45000000000, - ReadTimeout: 30000000000, - WriteTimeout: 30000000000, - ShutdownTimeout: 5000000000, - SecretToken: "1234random", - TLS: &tlscommon.ServerConfig{ - Enabled: &truthy, - Certificate: outputs.CertificateConfig{Certificate: "", Key: ""}, - ClientAuth: 3}, - AugmentEnabled: true, - Expvar: &config.ExpvarConfig{ - Enabled: &truthy, - URL: "/debug/vars", - }, - RumConfig: &config.RumConfig{ - Enabled: &truthy, - EventRate: &config.EventRate{ - Limit: 300, - LruSize: 1000, - }, - AllowOrigins: []string{"*"}, - SourceMapping: &config.SourceMapping{ - Cache: &config.Cache{ - Expiration: 7 * time.Second, - }, - IndexPattern: "apm-*-sourcemap*", - }, - LibraryPattern: "rum", - ExcludeFromGrouping: "^/webpack", - BeatVersion: "6.2.0", - }, - Register: &config.RegisterConfig{ - Ingest: &config.IngestConfig{ - Pipeline: &config.PipelineConfig{ - Enabled: &falsy, - Path: filepath.Join("ingest", "pipeline", "definition.json"), - }, - }, - }, - Kibana: common.MustNewConfigFrom(map[string]interface{}{"enabled": "false"}), - AgentConfig: &config.AgentConfig{Cache: &config.Cache{Expiration: 30 * time.Second}}, - Pipeline: config.DefaultAPMPipeline, - }, - }, - } - - for name, test := range tests { - t.Run(name, func(t *testing.T) { - ucfgConfig, err := common.NewConfigFrom(test.conf) - assert.NoError(t, err) - btr, err := New(&beat.Beat{Info: beat.Info{Version: "6.2.0"}}, ucfgConfig) - assert.NoError(t, err) - assert.NotNil(t, btr) - bt := btr.(*beater) - assert.Equal(t, test.beaterConf, bt.config) - }) - } -} - /* Run the benchmarks as follows: @@ -262,91 +52,6 @@ To get a memory profile, use this: */ -type ChanClient struct { - done chan struct{} - Channel chan beat.Event -} - -func NewChanClientWith(ch chan beat.Event) *ChanClient { - if ch == nil { - ch = make(chan beat.Event, 1) - } - c := &ChanClient{ - done: make(chan struct{}), - Channel: ch, - } - return c -} - -func (c *ChanClient) Close() error { - close(c.done) - return nil -} - -// Publish will publish every event in the batch on the channel. Options will be ignored. -// Always returns without error. -func (c *ChanClient) Publish(batch pubs.Batch) error { - for _, event := range batch.Events() { - select { - case <-c.done: - case c.Channel <- event.Content: - } - } - batch.ACK() - return nil -} - -func (c *ChanClient) String() string { - return "event capturing test client" -} - -type DummyOutputClient struct { -} - -func (d *DummyOutputClient) Publish(batch pubs.Batch) error { - batch.ACK() - return nil -} -func (d *DummyOutputClient) Close() error { return nil } -func (d *DummyOutputClient) String() string { return "" } - -func DummyPipeline(cfg *common.Config, info beat.Info, clients ...outputs.Client) *pipeline.Pipeline { - if len(clients) == 0 { - clients = []outputs.Client{&DummyOutputClient{}} - } - if cfg == nil { - cfg = common.NewConfig() - } - processors, err := processing.MakeDefaultObserverSupport(false)(info, logp.NewLogger("testbeat"), cfg) - if err != nil { - panic(err) - } - p, err := pipeline.New( - info, - pipeline.Monitors{}, - func(e queue.Eventer) (queue.Queue, error) { - return memqueue.NewBroker(nil, memqueue.Settings{ - Eventer: e, - Events: 20, - }), nil - }, - outputs.Group{ - Clients: clients, - BatchSize: 5, - Retry: 0, // no retry. on error drop events - }, - pipeline.Settings{ - WaitClose: 0, - WaitCloseMode: pipeline.NoWaitOnClose, - Processors: processors, - }, - ) - if err != nil { - panic(err) - } - return p -} - func (bt *beater) client(insecure bool) (string, *http.Client) { transport := &http.Transport{} if insecure { diff --git a/beater/config/config.go b/beater/config/config.go index aa5d20337fa..2d06cc16655 100644 --- a/beater/config/config.go +++ b/beater/config/config.go @@ -19,7 +19,6 @@ package config import ( "net" - "path/filepath" "regexp" "time" @@ -28,7 +27,6 @@ import ( "github.com/elastic/beats/libbeat/common" "github.com/elastic/beats/libbeat/common/transport/tlscommon" "github.com/elastic/beats/libbeat/logp" - "github.com/elastic/beats/libbeat/paths" logs "github.com/elastic/apm-server/log" ) @@ -36,8 +34,6 @@ import ( const ( // DefaultPort of APM Server DefaultPort = "8200" - // DefaultAPMPipeline is set to apm but can be user overwritten - DefaultAPMPipeline = "apm" msgInvalidConfigAgentCfg = "invalid value for `apm-server.agent.config.cache.expiration`, only accepting full seconds" ) @@ -86,12 +82,6 @@ type Cache struct { Expiration time.Duration `config:"expiration"` } -// LimitedCache holds config information about cache expiration -type LimitedCache struct { - Expiration time.Duration `config:"expiration"` - Size int `config:"size"` -} - // InstrumentationConfig holds config information about self instrumenting the APM Server type InstrumentationConfig struct { Enabled *bool `config:"enabled"` @@ -141,29 +131,14 @@ func (c *ExpvarConfig) IsEnabled() bool { return c != nil && (c.Enabled == nil || *c.Enabled) } -// IsEnabled indicates whether pipeline registration is enabled or not -func (c *PipelineConfig) IsEnabled() bool { - return c != nil && (c.Enabled == nil || *c.Enabled) -} - -// ShouldOverwrite indicates whether existing pipelines should be overwritten during registration process -func (c *PipelineConfig) ShouldOverwrite() bool { - return c != nil && (c.Overwrite != nil && *c.Overwrite) -} - // IsEnabled indicates whether self instrumentation is enabled func (c *InstrumentationConfig) IsEnabled() bool { // self instrumentation is disabled by default. return c != nil && c.Enabled != nil && *c.Enabled } -func replaceVersion(pattern, version string) string { - return regexObserverVersion.ReplaceAllLiteralString(pattern, version) -} - // DefaultConfig returns a config with default settings for `apm-server` config options. func DefaultConfig(beatVersion string) *Config { - pipeline := true return &Config{ Host: net.JoinHostPort("localhost", DefaultPort), MaxHeaderSize: 1 * 1024 * 1024, // 1mb @@ -178,18 +153,11 @@ func DefaultConfig(beatVersion string) *Config { Enabled: new(bool), URL: "/debug/vars", }, - RumConfig: defaultRum(beatVersion), - Register: &RegisterConfig{ - Ingest: &IngestConfig{ - Pipeline: &PipelineConfig{ - Enabled: &pipeline, - Path: paths.Resolve(paths.Home, - filepath.Join("ingest", "pipeline", "definition.json")), - }}, - }, + RumConfig: defaultRum(beatVersion), + Register: defaultRegisterConfig(true), Mode: ModeProduction, Kibana: common.MustNewConfigFrom(map[string]interface{}{"enabled": "false"}), AgentConfig: &AgentConfig{Cache: &Cache{Expiration: 30 * time.Second}}, - Pipeline: DefaultAPMPipeline, + Pipeline: defaultAPMPipeline, } } diff --git a/beater/config/config_test.go b/beater/config/config_test.go index 5469ec98bd3..118bf2dc310 100644 --- a/beater/config/config_test.go +++ b/beater/config/config_test.go @@ -141,7 +141,7 @@ func Test_UnpackConfig(t *testing.T) { }, Kibana: common.MustNewConfigFrom(map[string]interface{}{"enabled": "true"}), AgentConfig: &AgentConfig{Cache: &Cache{Expiration: 2 * time.Minute}}, - Pipeline: DefaultAPMPipeline, + Pipeline: defaultAPMPipeline, }, }, "merge config with default": { @@ -217,7 +217,7 @@ func Test_UnpackConfig(t *testing.T) { }, Kibana: common.MustNewConfigFrom(map[string]interface{}{"enabled": "false"}), AgentConfig: &AgentConfig{Cache: &Cache{Expiration: 30 * time.Second}}, - Pipeline: DefaultAPMPipeline, + Pipeline: defaultAPMPipeline, }, }, } diff --git a/beater/config/register.go b/beater/config/register.go index cab44410985..0f4cb9b44ae 100644 --- a/beater/config/register.go +++ b/beater/config/register.go @@ -17,6 +17,16 @@ package config +import ( + "path/filepath" + + "github.com/elastic/beats/libbeat/paths" +) + +const ( + defaultAPMPipeline = "apm" +) + // RegisterConfig holds ingest config information type RegisterConfig struct { Ingest *IngestConfig `config:"ingest"` @@ -33,3 +43,24 @@ type PipelineConfig struct { Overwrite *bool `config:"overwrite"` Path string } + +// IsEnabled indicates whether pipeline registration is enabled or not +func (c *PipelineConfig) IsEnabled() bool { + return c != nil && (c.Enabled == nil || *c.Enabled) +} + +// ShouldOverwrite indicates whether existing pipelines should be overwritten during registration process +func (c *PipelineConfig) ShouldOverwrite() bool { + return c != nil && (c.Overwrite != nil && *c.Overwrite) +} + +func defaultRegisterConfig(pipelineEnabled bool) *RegisterConfig { + return &RegisterConfig{ + Ingest: &IngestConfig{ + Pipeline: &PipelineConfig{ + Enabled: &pipelineEnabled, + Path: paths.Resolve(paths.Home, + filepath.Join("ingest", "pipeline", "definition.json")), + }}, + } +} diff --git a/beater/config/rum.go b/beater/config/rum.go index b83ecb08e68..f492753dd84 100644 --- a/beater/config/rum.go +++ b/beater/config/rum.go @@ -92,6 +92,8 @@ func (c *RumConfig) MemoizedSourcemapStore() (*sourcemap.Store, error) { if err != nil { return nil, err } + // the index pattern by default contains a variable `observer.version` that needs to be replaced with the + // concrete apm-server version. index := replaceVersion(c.SourceMapping.IndexPattern, c.BeatVersion) store, err := sourcemap.NewStore(esClient, index, c.SourceMapping.Cache.Expiration) if err != nil { @@ -135,6 +137,10 @@ func (s *SourceMapping) isSetup() bool { return s != nil && (s.ESConfig != nil) } +func replaceVersion(pattern, version string) string { + return regexObserverVersion.ReplaceAllLiteralString(pattern, version) +} + func defaultRum(beatVersion string) *RumConfig { return &RumConfig{ EventRate: &EventRate{ diff --git a/beater/server_test.go b/beater/server_test.go index 328ef6b022d..5b1b33e01db 100644 --- a/beater/server_test.go +++ b/beater/server_test.go @@ -30,6 +30,13 @@ import ( "github.com/gofrs/uuid" + "github.com/elastic/beats/libbeat/logp" + "github.com/elastic/beats/libbeat/outputs" + pubs "github.com/elastic/beats/libbeat/publisher" + "github.com/elastic/beats/libbeat/publisher/pipeline" + "github.com/elastic/beats/libbeat/publisher/processing" + "github.com/elastic/beats/libbeat/publisher/queue" + "github.com/elastic/beats/libbeat/publisher/queue/memqueue" "github.com/elastic/beats/libbeat/version" "github.com/stretchr/testify/assert" @@ -385,6 +392,91 @@ func TestServerSourcemapElasticsearch(t *testing.T) { } } +type chanClient struct { + done chan struct{} + Channel chan beat.Event +} + +func newChanClientWith(ch chan beat.Event) *chanClient { + if ch == nil { + ch = make(chan beat.Event, 1) + } + c := &chanClient{ + done: make(chan struct{}), + Channel: ch, + } + return c +} + +func (c *chanClient) Close() error { + close(c.done) + return nil +} + +// Publish will publish every event in the batch on the channel. Options will be ignored. +// Always returns without error. +func (c *chanClient) Publish(batch pubs.Batch) error { + for _, event := range batch.Events() { + select { + case <-c.done: + case c.Channel <- event.Content: + } + } + batch.ACK() + return nil +} + +func (c *chanClient) String() string { + return "event capturing test client" +} + +type dummyOutputClient struct { +} + +func (d *dummyOutputClient) Publish(batch pubs.Batch) error { + batch.ACK() + return nil +} +func (d *dummyOutputClient) Close() error { return nil } +func (d *dummyOutputClient) String() string { return "" } + +func dummyPipeline(cfg *common.Config, info beat.Info, clients ...outputs.Client) *pipeline.Pipeline { + if len(clients) == 0 { + clients = []outputs.Client{&dummyOutputClient{}} + } + if cfg == nil { + cfg = common.NewConfig() + } + processors, err := processing.MakeDefaultObserverSupport(false)(info, logp.NewLogger("testbeat"), cfg) + if err != nil { + panic(err) + } + p, err := pipeline.New( + info, + pipeline.Monitors{}, + func(e queue.Eventer) (queue.Queue, error) { + return memqueue.NewBroker(nil, memqueue.Settings{ + Eventer: e, + Events: 20, + }), nil + }, + outputs.Group{ + Clients: clients, + BatchSize: 5, + Retry: 0, // no retry. on error drop events + }, + pipeline.Settings{ + WaitClose: 0, + WaitCloseMode: pipeline.NoWaitOnClose, + Processors: processors, + }, + ) + if err != nil { + panic(err) + } + return p +} + func setupServer(t *testing.T, cfg *common.Config, beatConfig *beat.BeatConfig, events chan beat.Event) (*beater, func(), error) { if testing.Short() { @@ -411,11 +503,11 @@ func setupServer(t *testing.T, cfg *common.Config, beatConfig *beat.BeatConfig, var pub beat.Pipeline if events != nil { // capture events - pubClient := NewChanClientWith(events) - pub = DummyPipeline(cfg, info, pubClient) + pubClient := newChanClientWith(events) + pub = dummyPipeline(cfg, info, pubClient) } else { // don't capture events - pub = DummyPipeline(cfg, info) + pub = dummyPipeline(cfg, info) } // create a beat diff --git a/model/stacktrace_frame.go b/model/stacktrace_frame.go index a3aea97e3de..f13bfb72c88 100644 --- a/model/stacktrace_frame.go +++ b/model/stacktrace_frame.go @@ -181,12 +181,15 @@ func (s *StacktraceFrame) applySourcemap(store *sourcemap.Store, service *metada path := utility.CleanUrlPath(*s.Original.AbsPath) mapper, err := store.Fetch(*service.Name, *service.Version, path) if err != nil { - if errors.Cause(err) == sourcemap.ErrNoSourcemapFound { - s.updateError(err.Error()) - } errMsg = err.Error() return } + if mapper == nil { + errMsg = fmt.Sprintf("No Sourcemap available for ServiceName %s, ServiceVersion %s, Path %s.", + *service.Name, *service.Version, path) + s.updateError(errMsg) + return + } file, fct, line, col, ctxLine, preCtx, postCtx, ok := mapper.Apply(*s.Original.Lineno, *s.Original.Colno) if !ok { diff --git a/sourcemap/error.go b/sourcemap/error.go deleted file mode 100644 index 3e07623622e..00000000000 --- a/sourcemap/error.go +++ /dev/null @@ -1,32 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package sourcemap - -//type internalErr struct { -// err error -// noSourcemap bool -// temporary bool -//} -// -//func (e *internalErr) Error() string { -// return e.err.Error() -//} -// -//func (e *internalErr) NoSourcemapFound() bool { -// return e.noSourcemap -//} diff --git a/sourcemap/es_store.go b/sourcemap/es_store.go index 58a261ac8ba..f8184c7ba8d 100644 --- a/sourcemap/es_store.go +++ b/sourcemap/es_store.go @@ -35,29 +35,7 @@ import ( ) const ( - boolStr = "bool" - boostStr = "boost" - descStr = "desc" - mustStr = "must" - orderStr = "order" - processorNameStr = "processor.name" - queryStr = "query" - scoreStr = "_score" - shouldStr = "should" - sizeStr = "size" - sortStr = "sort" - sourcemapStr = "sourcemap" - sourcemapBundleFilepathStr = "sourcemap.bundle_filepath" - sourcemapServiceNameStr = "sourcemap.service.name" - sourcemapServiceVersionStr = "sourcemap.service.version" - sourcemapSourcemapStr = "sourcemap.sourcemap" - sourceStr = "_source" - termStr = "term" - timestampStr = "@timestamp" - valueStr = "value" - - emptyResult = "" - + emptyResult = "" errMsgParseSourcemap = "Could not parse Sourcemap." ) @@ -151,38 +129,38 @@ func parse(response *esapi.Response, name, version, path string, logger *logp.Lo func query(name, version, path string) map[string]interface{} { return map[string]interface{}{ - queryStr: map[string]interface{}{ - boolStr: map[string]interface{}{ - mustStr: []map[string]interface{}{ - {termStr: map[string]interface{}{processorNameStr: sourcemapStr}}, - {termStr: map[string]interface{}{sourcemapServiceNameStr: name}}, - {termStr: map[string]interface{}{sourcemapServiceVersionStr: version}}, - {boolStr: map[string]interface{}{ - shouldStr: []map[string]interface{}{ - {termStr: map[string]interface{}{sourcemapBundleFilepathStr: map[string]interface{}{ - valueStr: path, + "query": map[string]interface{}{ + "bool": map[string]interface{}{ + "must": []map[string]interface{}{ + {"term": map[string]interface{}{"processor.name": "sourcemap"}}, + {"term": map[string]interface{}{"sourcemap.service.name": name}}, + {"term": map[string]interface{}{"sourcemap.service.version": version}}, + {"bool": map[string]interface{}{ + "should": []map[string]interface{}{ + {"term": map[string]interface{}{"sourcemap.bundle_filepath": map[string]interface{}{ + "value": path, // prefer full url match - boostStr: 2.0, + "boost": 2.0, }}}, - {termStr: map[string]interface{}{sourcemapBundleFilepathStr: utility.UrlPath(path)}}, + {"term": map[string]interface{}{"sourcemap.bundle_filepath": utility.UrlPath(path)}}, }, }}, }, }, }, - sizeStr: 1, - sortStr: []map[string]interface{}{ + "size": 1, + "sort": []map[string]interface{}{ { - scoreStr: map[string]interface{}{ - orderStr: descStr, + "_score": map[string]interface{}{ + "order": "desc", }, }, { - timestampStr: map[string]interface{}{ - orderStr: descStr, + "@timestamp": map[string]interface{}{ + "order": "desc", }, }, }, - sourceStr: sourcemapSourcemapStr, + "_source": "sourcemap.sourcemap", } } diff --git a/sourcemap/store.go b/sourcemap/store.go index bdfe8383a29..dccae88aab2 100644 --- a/sourcemap/store.go +++ b/sourcemap/store.go @@ -33,11 +33,6 @@ import ( logs "github.com/elastic/apm-server/log" ) -var ( - //ErrNoSourcemapFound indicates that no sourcemap exists for provided criteria - ErrNoSourcemapFound = errors.New("No Sourcemap available") -) - const ( minCleanupIntervalSeconds float64 = 60 ) @@ -77,7 +72,7 @@ func (s *Store) Fetch(name string, version string, path string) (*Mapper, error) if ok && sourcemapConsumer != nil { return &Mapper{sourcemapConsumer: sourcemapConsumer}, nil } - return nil, errNoSourcemap(name, version, path) + return nil, nil } // fetch from Elasticsearch and ensure caching for all non-temporary results @@ -91,7 +86,7 @@ func (s *Store) Fetch(name string, version string, path string) (*Mapper, error) if sourcemapStr == emptyResult { s.add(key, nil) - return nil, errNoSourcemap(name, version, path) + return nil, nil } consumer, err := sourcemap.Parse("", []byte(sourcemapStr)) @@ -132,7 +127,3 @@ func key(s []string) string { func cleanupInterval(ttl time.Duration) time.Duration { return time.Duration(math.Max(ttl.Seconds(), minCleanupIntervalSeconds)) * time.Second } - -func errNoSourcemap(name, version, path string) error { - return errors.Wrapf(ErrNoSourcemapFound, "ServiceName %s, ServiceVersion %s, Path %s.", name, version, path) -} diff --git a/sourcemap/store_test.go b/sourcemap/store_test.go index 1ff4d6b5d8e..2633d12fa5f 100644 --- a/sourcemap/store_test.go +++ b/sourcemap/store_test.go @@ -52,9 +52,8 @@ func TestStore_Fetch(t *testing.T) { store.add(key, nilConsumer) mapper, err := store.Fetch(serviceName, serviceVersion, path) - require.Error(t, err) - assert.Contains(t, err.Error(), "No Sourcemap available") - require.Nil(t, mapper) + assert.Nil(t, mapper) + assert.Nil(t, err) }) t.Run("sourcemapConsumer", func(t *testing.T) { @@ -75,7 +74,7 @@ func TestStore_Fetch(t *testing.T) { mapper, err := store.Fetch(serviceName, serviceVersion, path) require.NoError(t, err) require.NotNil(t, mapper) - assert.NotNil(t, mapper.sourcemapConsumer) + require.NotNil(t, mapper.sourcemapConsumer) // ensure sourcemap is added to cache cached, found := store.cache.Get(key) @@ -83,9 +82,27 @@ func TestStore_Fetch(t *testing.T) { assert.Equal(t, mapper.sourcemapConsumer, cached) }) + t.Run("notFoundInES", func(t *testing.T) { + + store := testStore(t, test.ESClientWithSourcemapNotFound(t)) + //not cached + cached, found := store.cache.Get(key) + require.False(t, found) + require.Nil(t, cached) + + //fetch nil value, leading to error + mapper, err := store.Fetch(serviceName, serviceVersion, path) + require.Nil(t, err) + require.Nil(t, mapper) + + // ensure nil value is added to cache + cached, found = store.cache.Get(key) + assert.True(t, found) + assert.Nil(t, cached) + }) + t.Run("invalidFromES", func(t *testing.T) { for name, client := range map[string]*elasticsearch.Client{ - "notFound": test.ESClientWithSourcemapNotFound(t), "invalid": test.ESClientWithInvalidSourcemap(t), "unsupportedVersion": test.ESClientWithUnsupportedSourcemap(t), } { @@ -94,7 +111,7 @@ func TestStore_Fetch(t *testing.T) { //not cached cached, found := store.cache.Get(key) require.False(t, found) - assert.Nil(t, cached) + require.Nil(t, cached) //fetch nil value, leading to error mapper, err := store.Fetch(serviceName, serviceVersion, path) From da72899f8963d216c0286898d6514ebd8aced5cd Mon Sep 17 00:00:00 2001 From: simitt Date: Mon, 18 Nov 2019 13:23:03 +0100 Subject: [PATCH 6/8] fix system tests --- sourcemap/store.go | 2 +- tests/system/apmserver.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/sourcemap/store.go b/sourcemap/store.go index dccae88aab2..aabdef177fa 100644 --- a/sourcemap/store.go +++ b/sourcemap/store.go @@ -100,7 +100,7 @@ func (s *Store) Fetch(name string, version string, path string) (*Mapper, error) // Added ensures the internal cache is cleared for the given parameters. This should be called when a sourcemap is uploaded. func (s *Store) Added(name string, version string, path string) { - if _, err := s.Fetch(name, version, path); err == nil { + if sourcemap, err := s.Fetch(name, version, path); err == nil && sourcemap != nil { s.logger.Warnf("Overriding sourcemap for service %s version %s and file %s", name, version, path) } diff --git a/tests/system/apmserver.py b/tests/system/apmserver.py index 3ff14bd55d0..1f82387bb78 100644 --- a/tests/system/apmserver.py +++ b/tests/system/apmserver.py @@ -286,8 +286,7 @@ def get_transaction_payload_path(self, name="transactions_spans_rum_2.ndjson"): def upload_sourcemap(self, file_name='bundle_no_mapping.js.map', service_name='apm-agent-js', service_version='1.0.1', - bundle_filepath='bundle_no_mapping.js.map', - expected_ct=1): + bundle_filepath='bundle_no_mapping.js.map'): path = self._beat_path_join( 'testdata', 'sourcemap', From 6e08ef39705a152b20ecbd3efef63fa795946345 Mon Sep 17 00:00:00 2001 From: simitt Date: Tue, 19 Nov 2019 10:39:06 +0100 Subject: [PATCH 7/8] Address PR comments --- README.md | 10 +++++ model/stacktrace_frame.go | 2 +- sourcemap/es_store.go | 93 +++++++++++++++++++++++++-------------- sourcemap/mapper.go | 16 +++---- sourcemap/mapper_test.go | 9 ++-- sourcemap/store.go | 11 ++--- sourcemap/store_test.go | 18 +++----- 7 files changed, 91 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index 6afb9fd2441..610d32c9bc4 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,16 @@ To update the dependency to a specific commit or branch run command as following ``` BEATS_VERSION=f240148065af94d55c5149e444482b9635801f27 make update-beats ``` +### Go-elasticsearch client Update + +It is important to keep the used [go-elasticsearch client](https://github.com/elastic/go-elasticsearch) in sync with the according major version. +We also recommend to use the latest available client for minor versions. +Since APM Server does not yet support go modules, you can update the dependency using govendor, e.g. by running: +``` +git clone --branch v7.4.1 https://github.com/elastic/go-elasticsearch.git $GOPATH/src/github.com/elastic/go-elasticsearch/v7 +govendor add github.com/elastic/go-elasticsearch/v7/^ +mv ./vendor/github.com/elastic/go-elasticsearch/v7/LICENSE ./vendor/github.com/elastic/go-elasticsearch/ +``` ## Packaging diff --git a/model/stacktrace_frame.go b/model/stacktrace_frame.go index f13bfb72c88..3a046773f70 100644 --- a/model/stacktrace_frame.go +++ b/model/stacktrace_frame.go @@ -191,7 +191,7 @@ func (s *StacktraceFrame) applySourcemap(store *sourcemap.Store, service *metada return } - file, fct, line, col, ctxLine, preCtx, postCtx, ok := mapper.Apply(*s.Original.Lineno, *s.Original.Colno) + file, fct, line, col, ctxLine, preCtx, postCtx, ok := sourcemap.Map(mapper, *s.Original.Lineno, *s.Original.Colno) if !ok { errMsg = fmt.Sprintf("No Sourcemap found for Lineno %v, Colno %v", *s.Original.Lineno, *s.Original.Colno) s.updateError(errMsg) diff --git a/sourcemap/es_store.go b/sourcemap/es_store.go index f8184c7ba8d..a28cdc3accc 100644 --- a/sourcemap/es_store.go +++ b/sourcemap/es_store.go @@ -128,39 +128,66 @@ func parse(response *esapi.Response, name, version, path string, logger *logp.Lo } func query(name, version, path string) map[string]interface{} { + return searchFirst( + boolean( + must( + term("processor.name", "sourcemap"), + term("sourcemap.service.name", name), + term("sourcemap.service.version", version), + term("processor.name", "sourcemap"), + boolean( + should( + // prefer full URL match + boostedTerm("sourcemap.bundle_filepath", path, 2.0), + term("sourcemap.bundle_filepath", utility.UrlPath(path)), + ), + ), + ), + ), + "sourcemap.sourcemap", + desc("_score"), + desc("@timestamp"), + ) +} + +func wrap(k string, v map[string]interface{}) map[string]interface{} { + return map[string]interface{}{k: v} +} + +func boolean(clause map[string]interface{}) map[string]interface{} { + return wrap("bool", clause) +} + +func should(clauses ...map[string]interface{}) map[string]interface{} { + return map[string]interface{}{"should": clauses} +} + +func must(clauses ...map[string]interface{}) map[string]interface{} { + return map[string]interface{}{"must": clauses} +} + +func term(k, v string) map[string]interface{} { + return map[string]interface{}{"term": map[string]interface{}{k: v}} +} + +func boostedTerm(k, v string, boost float32) map[string]interface{} { + return wrap("term", + wrap(k, map[string]interface{}{ + "value": v, + "boost": boost, + }), + ) +} + +func desc(by string) map[string]interface{} { + return wrap(by, map[string]interface{}{"order": "desc"}) +} + +func searchFirst(query map[string]interface{}, source string, sort ...map[string]interface{}) map[string]interface{} { return map[string]interface{}{ - "query": map[string]interface{}{ - "bool": map[string]interface{}{ - "must": []map[string]interface{}{ - {"term": map[string]interface{}{"processor.name": "sourcemap"}}, - {"term": map[string]interface{}{"sourcemap.service.name": name}}, - {"term": map[string]interface{}{"sourcemap.service.version": version}}, - {"bool": map[string]interface{}{ - "should": []map[string]interface{}{ - {"term": map[string]interface{}{"sourcemap.bundle_filepath": map[string]interface{}{ - "value": path, - // prefer full url match - "boost": 2.0, - }}}, - {"term": map[string]interface{}{"sourcemap.bundle_filepath": utility.UrlPath(path)}}, - }, - }}, - }, - }, - }, - "size": 1, - "sort": []map[string]interface{}{ - { - "_score": map[string]interface{}{ - "order": "desc", - }, - }, - { - "@timestamp": map[string]interface{}{ - "order": "desc", - }, - }, - }, - "_source": "sourcemap.sourcemap", + "query": query, + "size": 1, + "sort": sort, + "_source": source, } } diff --git a/sourcemap/mapper.go b/sourcemap/mapper.go index e4216b35da9..8c3ed655974 100644 --- a/sourcemap/mapper.go +++ b/sourcemap/mapper.go @@ -25,22 +25,16 @@ import ( const sourcemapContentSnippetSize = 5 -// Mapper holds a sourcemapper instance to be able to apply sourcemapping -type Mapper struct { - sourcemapConsumer *sourcemap.Consumer -} - -// Apply sourcemapping for given line and column and return values after sourcemapping -func (m *Mapper) Apply(lineno, colno int) ( +// Map sourcemapping for given line and column and return values after sourcemapping +func Map(mapper *sourcemap.Consumer, lineno, colno int) ( file string, function string, line int, col int, contextLine string, preContext []string, postContext []string, ok bool) { - if m.sourcemapConsumer == nil { + if mapper == nil { return } - - file, function, line, col, ok = m.sourcemapConsumer.Source(lineno, colno) - src := strings.Split(m.sourcemapConsumer.SourceContent(file), "\n") + file, function, line, col, ok = mapper.Source(lineno, colno) + src := strings.Split(mapper.SourceContent(file), "\n") contextLine = strings.Join(subSlice(line-1, line, src), "") preContext = subSlice(line-1-sourcemapContentSnippetSize, line-1, src) postContext = subSlice(line, line+sourcemapContentSnippetSize, src) diff --git a/sourcemap/mapper_test.go b/sourcemap/mapper_test.go index 8886f53b98d..20785728e8b 100644 --- a/sourcemap/mapper_test.go +++ b/sourcemap/mapper_test.go @@ -30,16 +30,15 @@ import ( func TestApply(t *testing.T) { // no sourcemapConsumer - _, _, _, _, _, _, _, ok := (&Mapper{}).Apply(0, 0) + _, _, _, _, _, _, _, ok := Map(nil, 0, 0) assert.False(t, ok) - sourcemapConsumer, err := sourcemap.Parse("", []byte(test.ValidSourcemap)) + m, err := sourcemap.Parse("", []byte(test.ValidSourcemap)) require.NoError(t, err) - m := &Mapper{sourcemapConsumer: sourcemapConsumer} t.Run("notOK", func(t *testing.T) { // nothing found for lineno and colno - file, fc, line, col, ctxLine, _, _, ok := m.Apply(0, 0) + file, fc, line, col, ctxLine, _, _, ok := Map(m, 0, 0) require.False(t, ok) assert.Zero(t, file) assert.Zero(t, fc) @@ -50,7 +49,7 @@ func TestApply(t *testing.T) { t.Run("OK", func(t *testing.T) { // mapping found in minified sourcemap - file, fc, line, col, ctxLine, preCtx, postCtx, ok := m.Apply(1, 7) + file, fc, line, col, ctxLine, preCtx, postCtx, ok := Map(m, 1, 7) require.True(t, ok) assert.Equal(t, "webpack:///bundle.js", file) assert.Equal(t, "", fc) diff --git a/sourcemap/store.go b/sourcemap/store.go index aabdef177fa..891ea50ea66 100644 --- a/sourcemap/store.go +++ b/sourcemap/store.go @@ -63,16 +63,13 @@ func NewStore(client *elasticsearch.Client, index string, expiration time.Durati } // Fetch a sourcemap from the store. -func (s *Store) Fetch(name string, version string, path string) (*Mapper, error) { +func (s *Store) Fetch(name string, version string, path string) (*sourcemap.Consumer, error) { key := key([]string{name, version, path}) // fetch from cache if val, found := s.cache.Get(key); found { - sourcemapConsumer, ok := val.(*sourcemap.Consumer) - if ok && sourcemapConsumer != nil { - return &Mapper{sourcemapConsumer: sourcemapConsumer}, nil - } - return nil, nil + consumer, _ := val.(*sourcemap.Consumer) + return consumer, nil } // fetch from Elasticsearch and ensure caching for all non-temporary results @@ -95,7 +92,7 @@ func (s *Store) Fetch(name string, version string, path string) (*Mapper, error) return nil, errors.Wrap(err, errMsgParseSourcemap) } s.add(key, consumer) - return &Mapper{sourcemapConsumer: consumer}, nil + return consumer, nil } // Added ensures the internal cache is cleared for the given parameters. This should be called when a sourcemap is uploaded. diff --git a/sourcemap/store_test.go b/sourcemap/store_test.go index 2633d12fa5f..3bec3a0c050 100644 --- a/sourcemap/store_test.go +++ b/sourcemap/store_test.go @@ -63,8 +63,7 @@ func TestStore_Fetch(t *testing.T) { mapper, err := store.Fetch(serviceName, serviceVersion, path) require.NoError(t, err) - require.NotNil(t, mapper) - assert.Equal(t, consumer, mapper.sourcemapConsumer) + assert.Equal(t, consumer, mapper) }) }) @@ -74,12 +73,11 @@ func TestStore_Fetch(t *testing.T) { mapper, err := store.Fetch(serviceName, serviceVersion, path) require.NoError(t, err) require.NotNil(t, mapper) - require.NotNil(t, mapper.sourcemapConsumer) // ensure sourcemap is added to cache cached, found := store.cache.Get(key) require.True(t, found) - assert.Equal(t, mapper.sourcemapConsumer, cached) + assert.Equal(t, mapper, cached) }) t.Run("notFoundInES", func(t *testing.T) { @@ -154,17 +152,15 @@ func TestStore_Added(t *testing.T) { mapper, err := store.Fetch(name, version, path) require.NoError(t, err) - require.NotNil(t, mapper) - assert.Equal(t, &sourcemap.Consumer{}, mapper.sourcemapConsumer) - assert.Equal(t, "", mapper.sourcemapConsumer.File()) + assert.Equal(t, &sourcemap.Consumer{}, mapper) + assert.Equal(t, "", mapper.File()) // remove from cache, afterwards sourcemap should be fetched from ES store.Added(name, version, path) mapper, err = store.Fetch(name, version, path) require.NoError(t, err) - require.NotNil(t, mapper) - assert.NotNil(t, &sourcemap.Consumer{}, mapper.sourcemapConsumer) - assert.Equal(t, "bundle.js", mapper.sourcemapConsumer.File()) + assert.NotNil(t, &sourcemap.Consumer{}, mapper) + assert.Equal(t, "bundle.js", mapper.File()) } func TestExpiration(t *testing.T) { @@ -176,7 +172,7 @@ func TestExpiration(t *testing.T) { // sourcemap is cached mapper, err := store.Fetch(name, version, path) require.NoError(t, err) - assert.Equal(t, &sourcemap.Consumer{}, mapper.sourcemapConsumer) + assert.Equal(t, &sourcemap.Consumer{}, mapper) time.Sleep(25 * time.Millisecond) // cache is cleared, sourcemap is fetched from ES leading to an error From 3dd5984273eb92a70fbfb5a5c7c82f2b4030ea19 Mon Sep 17 00:00:00 2001 From: simitt Date: Wed, 20 Nov 2019 08:39:47 +0100 Subject: [PATCH 8/8] Add username and password Integration test with username and password will be automatically applied when security is enabled in system tests. --- elasticsearch/client.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/elasticsearch/client.go b/elasticsearch/client.go index f99b669ddb6..ab6c5310e7e 100644 --- a/elasticsearch/client.go +++ b/elasticsearch/client.go @@ -52,6 +52,8 @@ type Config struct { ProxyDisable bool `config:"proxy_disable"` Timeout time.Duration `config:"timeout"` TLS *tlscommon.Config `config:"ssl"` + Username string `config:"username"` + Password string `config:"password"` } // Hosts is an array of host strings and needs to have at least one entry @@ -82,6 +84,8 @@ func NewClient(config *Config) (*goelasticsearch.Client, error) { } return goelasticsearch.NewClient(goelasticsearch.Config{ + Username: config.Username, + Password: config.Password, Addresses: addresses, Transport: &http.Transport{ Proxy: proxy,