Skip to content

Commit

Permalink
opensearchapi: add ingestClient
Browse files Browse the repository at this point in the history
Signed-off-by: Jakob Hahn <[email protected]>
  • Loading branch information
Jakob3xD committed Sep 22, 2023
1 parent 30a6587 commit 9a4235a
Show file tree
Hide file tree
Showing 12 changed files with 910 additions and 0 deletions.
65 changes: 65 additions & 0 deletions opensearchapi/api_ingest-create-params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.

// 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.

package opensearchapi

import "time"

// IngestCreateParams represents possible parameters for the IngestCreateReq
type IngestCreateParams struct {
MasterTimeout time.Duration
ClusterManagerTimeout time.Duration
Timeout time.Duration

Pretty bool
Human bool
ErrorTrace bool
}

func (r IngestCreateParams) get() map[string]string {
params := make(map[string]string)

if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}

if r.ClusterManagerTimeout != 0 {
params["cluster_manager_timeout"] = formatDuration(r.ClusterManagerTimeout)
}

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"
}

return params
}
62 changes: 62 additions & 0 deletions opensearchapi/api_ingest-create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.

// 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.

package opensearchapi

import (
"fmt"
"io"
"net/http"

"github.com/opensearch-project/opensearch-go/v2"
)

// IngestCreateReq represents possible options for the index create request
type IngestCreateReq struct {
PipelineID string

Body io.Reader

Header http.Header
Params IngestCreateParams
}

// GetRequest returns the *http.Request that gets executed by the client
func (r IngestCreateReq) GetRequest() (*http.Request, error) {
return opensearch.BuildRequest(
"PUT",
fmt.Sprintf("/_ingest/pipeline/%s", r.PipelineID),
r.Body,
r.Params.get(),
r.Header,
)
}

// IngestCreateResp represents the returned struct of the index create response
type IngestCreateResp struct {
Acknowledged bool `json:"acknowledged"`
response *opensearch.Response
}

// Inspect returns the Inspect type containing the raw *opensearch.Reponse
func (r IngestCreateResp) Inspect() Inspect {
return Inspect{Response: r.response}
}
65 changes: 65 additions & 0 deletions opensearchapi/api_ingest-delete-params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.

// 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.

package opensearchapi

import "time"

// IngestDeleteParams represents possible parameters for the IngestDeleteReq
type IngestDeleteParams struct {
MasterTimeout time.Duration
ClusterManagerTimeout time.Duration
Timeout time.Duration

Pretty bool
Human bool
ErrorTrace bool
}

func (r IngestDeleteParams) get() map[string]string {
params := make(map[string]string)

if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}

if r.ClusterManagerTimeout != 0 {
params["cluster_manager_timeout"] = formatDuration(r.ClusterManagerTimeout)
}

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"
}

return params
}
59 changes: 59 additions & 0 deletions opensearchapi/api_ingest-delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.

// 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.

package opensearchapi

import (
"fmt"
"net/http"

"github.com/opensearch-project/opensearch-go/v2"
)

// IngestDeleteReq represents possible options for the index create request
type IngestDeleteReq struct {
PipelineID string

Header http.Header
Params IngestDeleteParams
}

// GetRequest returns the *http.Request that gets executed by the client
func (r IngestDeleteReq) GetRequest() (*http.Request, error) {
return opensearch.BuildRequest(
"DELETE",
fmt.Sprintf("/_ingest/pipeline/%s", r.PipelineID),
nil,
r.Params.get(),
r.Header,
)
}

// IngestDeleteResp represents the returned struct of the index create response
type IngestDeleteResp struct {
Acknowledged bool `json:"acknowledged"`
response *opensearch.Response
}

// Inspect returns the Inspect type containing the raw *opensearch.Reponse
func (r IngestDeleteResp) Inspect() Inspect {
return Inspect{Response: r.response}
}
68 changes: 68 additions & 0 deletions opensearchapi/api_ingest-get-params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.

// 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.

package opensearchapi

import (
"strconv"
"time"
)

// IngestGetParams represents possible parameters for the IngestGetReq
type IngestGetParams struct {
MasterTimeout time.Duration
ClusterManagerTimeout time.Duration
Summary *bool

Pretty bool
Human bool
ErrorTrace bool
}

func (r IngestGetParams) get() map[string]string {
params := make(map[string]string)

if r.MasterTimeout != 0 {
params["master_timeout"] = formatDuration(r.MasterTimeout)
}

if r.ClusterManagerTimeout != 0 {
params["cluster_manager_timeout"] = formatDuration(r.ClusterManagerTimeout)
}

if r.Summary != nil {
params["summary"] = strconv.FormatBool(*r.Summary)
}

if r.Pretty {
params["pretty"] = "true"
}

if r.Human {
params["human"] = "true"
}

if r.ErrorTrace {
params["error_trace"] = "true"
}

return params
}
64 changes: 64 additions & 0 deletions opensearchapi/api_ingest-get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.
//
// Modifications Copyright OpenSearch Contributors. See
// GitHub history for details.

// 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.

package opensearchapi

import (
"encoding/json"
"fmt"
"net/http"
"strings"

"github.com/opensearch-project/opensearch-go/v2"
)

// IngestGetReq represents possible options for the index create request
type IngestGetReq struct {
PipelineIDs []string

Header http.Header
Params IngestGetParams
}

// GetRequest returns the *http.Request that gets executed by the client
func (r IngestGetReq) GetRequest() (*http.Request, error) {
return opensearch.BuildRequest(
"GET",
fmt.Sprintf("/_ingest/pipeline/%s", strings.Join(r.PipelineIDs, ",")),
nil,
r.Params.get(),
r.Header,
)
}

// IngestGetResp represents the returned struct of the index create response
type IngestGetResp struct {
Pipelines map[string]struct {
Description string `json:"description"`
Processors []map[string]json.RawMessage `json:"processors"`
}
response *opensearch.Response
}

// Inspect returns the Inspect type containing the raw *opensearch.Reponse
func (r IngestGetResp) Inspect() Inspect {
return Inspect{Response: r.response}
}
Loading

0 comments on commit 9a4235a

Please sign in to comment.