Repository: opensearch-project/opensearch-go
Pull request #347 (2023-07-18 21:18:57)

Bump github.com/aws/aws-sdk-go from 1.44.298 to 1.44.302
[//]: # (dependabot-start)
⚠️  **Dependabot is rebasing this PR** ⚠️ 

Rebasing might not happen immediately, so don't worry if this takes some time.

Note: if you make any changes to this PR yourself, they will take precedence over the rebase.

---

[//]: # (dependabot-end)

Bumps [github.com/aws/aws-sdk-go](https://github.com/aws/aws-sdk-go) from 1.44.298 to 1.44.302.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/aws/aws-sdk-go/releases">github.com/aws/aws-sdk-go's releases</a>.</em></p>
<blockquote>
<h1>Release v1.44.302 (2023-07-18)</h1>
<h3>Service Client Updates</h3>
<ul>
<li><code>service/codeguru-security</code>: Updates service documentation</li>
<li><code>service/connect</code>: Updates service documentation</li>
<li><code>service/es</code>: Updates service API
<ul>
<li>Regex Validation on the ElasticSearch Engine Version attribute</li>
</ul>
</li>
<li><code>service/m2</code>: Updates service API and documentation</li>
<li><code>service/models.lex.v2</code>: Updates service API, documentation, and paginators</li>
<li><code>service/snowball</code>: Updates service API, documentation, paginators, and examples
<ul>
<li>Adds support for RACK_5U_C. This is the first AWS Snow Family device designed to meet U.S. Military Ruggedization Standards (MIL-STD-810H) with 208 vCPU device in a portable, compact 5U, half-rack width form-factor.</li>
</ul>
</li>
<li><code>service/translate</code>: Updates service documentation</li>
</ul>
<h1>Release v1.44.301 (2023-07-17)</h1>
<h3>Service Client Updates</h3>
<ul>
<li><code>service/codeartifact</code>: Updates service documentation</li>
<li><code>service/docdb</code>: Updates service API and documentation
<ul>
<li>Added major version upgrade option in ModifyDBCluster API</li>
</ul>
</li>
<li><code>service/ec2</code>: Updates service API and documentation
<ul>
<li>Add Nitro TPM support on DescribeInstanceTypes</li>
</ul>
</li>
<li><code>service/glue</code>: Updates service API
<ul>
<li>Adding new supported permission type flags to get-unfiltered endpoints that callers may pass to indicate support for enforcing Lake Formation fine-grained access control on nested column attributes.</li>
</ul>
</li>
<li><code>service/ivs</code>: Updates service API and documentation</li>
<li><code>service/lakeformation</code>: Updates service API and documentation</li>
</ul>
<h1>Release v1.44.300 (2023-07-13)</h1>
<h3>Service Client Updates</h3>
<ul>
<li><code>service/cognito-idp</code>: Updates service API</li>
<li><code>service/connect</code>: Updates service API and documentation</li>
<li><code>service/datasync</code>: Updates service API and documentation</li>
<li><code>service/dms</code>: Updates service API and documentation
<ul>
<li>Enhanced PostgreSQL target endpoint settings for providing Babelfish support.</li>
</ul>
</li>
<li><code>service/ec2</code>: Updates service API
<ul>
<li>This release adds support for the C7gn and Hpc7g instances. C7gn instances are powered by AWS Graviton3 processors and the fifth-generation AWS Nitro Cards. Hpc7g instances are powered by AWS Graviton 3E processors and provide up to 200 Gbps network bandwidth.</li>
</ul>
</li>
<li><code>service/fsx</code>: Updates service API and documentation</li>
<li><code>service/iam</code>: Updates service documentation
<ul>
<li>Documentation updates for AWS Identity and Access Management (IAM).</li>
</ul>
</li>
<li><code>service/mediatailor</code>: Updates service API and documentation</li>
<li><code>service/personalize</code>: Updates service API and documentation</li>
<li><code>service/proton</code>: Updates service API, documentation, and paginators</li>
<li><code>service/s3</code>: Updates service API, documentation, and examples
<ul>
<li>S3 Inventory now supports Object Access Control List and Object Owner as available object metadata fields in inventory reports.</li>
</ul>
</li>
<li><code>service/sagemaker</code>: Updates service API and documentation
<ul>
<li>Amazon SageMaker Canvas adds WorkspeceSettings support for CanvasAppSettings</li>
</ul>
</li>
<li><code>service/secretsmanager</code>: Updates service documentation and examples</li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/aws/aws-sdk-go/commit/e7bdeb8a795c2c9e610daedbff2e7af39f10aff3"><code>e7bdeb8</code></a> Release v1.44.302 (2023-07-18) (<a href="https://redirect.github.com/aws/aws-sdk-go/issues/4915">#4915</a>)</li>
<li><a href="https://github.com/aws/aws-sdk-go/commit/e078cf77411fa8f31faf86d0abbee28d05fb1771"><code>e078cf7</code></a> Release v1.44.301 (2023-07-17) (<a href="https://redirect.github.com/aws/aws-sdk-go/issues/4914">#4914</a>)</li>
<li><a href="https://github.com/aws/aws-sdk-go/commit/f219aebae13c8bddba19549e83d8c066b4ae6417"><code>f219aeb</code></a> Release v1.44.300 (2023-07-13) (<a href="https://redirect.github.com/aws/aws-sdk-go/issues/4909">#4909</a>)</li>
<li><a href="https://github.com/aws/aws-sdk-go/commit/633dbc1aad9e11574c96f3123de67b19fabfdf86"><code>633dbc1</code></a> Release v1.44.299 (2023-07-11) (<a href="https://redirect.github.com/aws/aws-sdk-go/issues/4906">#4906</a>)</li>
<li>See full diff in <a href="https://github.com/aws/aws-sdk-go/compare/v1.44.298...v1.44.302">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=github.com/aws/aws-sdk-go&package-manager=go_modules&previous-version=1.44.298&new-version=1.44.302)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

dblock: @dependabot recreate

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c574d2e..b29ec67 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,7 +6,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
 
 ### Dependencies
 
-- Bumps `github.com/aws/aws-sdk-go` from 1.44.180 to 1.44.298
+- Bumps `github.com/aws/aws-sdk-go` from 1.44.180 to 1.44.302
 - Bumps `github.com/aws/aws-sdk-go-v2` from 1.17.4 to 1.18.1
 - Bumps `github.com/aws/aws-sdk-go-v2/config` from 1.18.8 to 1.18.28
 - Bumps `github.com/stretchr/testify` from 1.8.1 to 1.8.4
@@ -51,7 +51,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
 
 - Corrects curl logging to emit the correct URL destination ([#101](https://github.com/opensearch-project/opensearch-go/pull/101))
 - Corrects handling of errors without an error response body ([#286](https://github.com/opensearch-project/opensearch-go/pull/286))
+- Corrects AWSv4 signature on DataStream Stats with no index name specified ([#338](https://github.com/opensearch-project/opensearch-go/pull/338))
 
 ### Security
 
-[Unreleased]: https://github.com/opensearch-project/opensearch-go/compare/v2.2.0...HEAD
\ No newline at end of file
+[Unreleased]: https://github.com/opensearch-project/opensearch-go/compare/v2.2.0...HEAD
diff --git a/go.mod b/go.mod
index 8fdf09c..01275e8 100644
--- a/go.mod
+++ b/go.mod
@@ -3,9 +3,10 @@ module github.com/opensearch-project/opensearch-go/v2
 go 1.15
 
 require (
-	github.com/aws/aws-sdk-go v1.44.298
+	github.com/aws/aws-sdk-go v1.44.302
 	github.com/aws/aws-sdk-go-v2 v1.19.0
 	github.com/aws/aws-sdk-go-v2/config v1.18.28
+	github.com/kinbiko/jsonassert v1.1.1
 	github.com/stretchr/testify v1.8.4
 	golang.org/x/net v0.7.0 // indirect
 )
diff --git a/go.sum b/go.sum
index cc74045..2e232a6 100644
--- a/go.sum
+++ b/go.sum
@@ -1,5 +1,5 @@
-github.com/aws/aws-sdk-go v1.44.298 h1:5qTxdubgV7PptZJmp/2qDwD2JL187ePL7VOxsSh1i3g=
-github.com/aws/aws-sdk-go v1.44.298/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
+github.com/aws/aws-sdk-go v1.44.302 h1:ST3ko6GrJKn3Xi+nAvxjG3uk/V1pW8KC52WLeIxqqNk=
+github.com/aws/aws-sdk-go v1.44.302/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
 github.com/aws/aws-sdk-go-v2 v1.19.0 h1:klAT+y3pGFBU/qVf1uzwttpBbiuozJYWzNLHioyDJ+k=
 github.com/aws/aws-sdk-go-v2 v1.19.0/go.mod h1:uzbQtefpm44goOPmdKyAlXSNcwlRgF3ePWVW6EtJvvw=
 github.com/aws/aws-sdk-go-v2/config v1.18.28 h1:TINEaKyh1Td64tqFvn09iYpKiWjmHYrG1fa91q2gnqw=
@@ -33,6 +33,8 @@ github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9Y
 github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
 github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
 github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
+github.com/kinbiko/jsonassert v1.1.1 h1:DB12divY+YB+cVpHULLuKePSi6+ui4M/shHSzJISkSE=
+github.com/kinbiko/jsonassert v1.1.1/go.mod h1:NO4lzrogohtIdNUNzx8sdzB55M4R4Q1bsrWVdqQ7C+A=
 github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
diff --git a/opensearchapi/api.indices.get_datastream_stats.go b/opensearchapi/api.indices.get_datastream_stats.go
index 4bc2e93..fe7dc31 100644
--- a/opensearchapi/api.indices.get_datastream_stats.go
+++ b/opensearchapi/api.indices.get_datastream_stats.go
@@ -58,8 +58,11 @@ func (r IndicesGetDataStreamStatsRequest) Do(ctx context.Context, transport Tran
 	method = "GET"
 
 	path.Grow(1 + len("_data_stream") + 1 + len(r.Name) + 1 + len("_stats"))
-	path.WriteString("/_data_stream/")
-	path.WriteString(r.Name)
+	path.WriteString("/_data_stream")
+	if r.Name != "" {
+		path.WriteString("/")
+		path.WriteString(r.Name)
+	}
 	path.WriteString("/_stats")
 
 	params = make(map[string]string)


Test patch:
diff --git a/opensearchapi/api.indices.datastream_test.go b/opensearchapi/api.indices.datastream_test.go
index 39f98e3..a6aeb12 100644
--- a/opensearchapi/api.indices.datastream_test.go
+++ b/opensearchapi/api.indices.datastream_test.go
@@ -13,18 +13,18 @@
 package opensearchapi_test
 
 import (
-	"bytes"
 	"context"
-	"encoding/json"
 	"fmt"
-	"github.com/opensearch-project/opensearch-go/v2"
-	"github.com/opensearch-project/opensearch-go/v2/opensearchapi"
-	"github.com/stretchr/testify/require"
 	"io/ioutil"
 	"net/http"
 	"strings"
 	"testing"
 	"time"
+
+	"github.com/kinbiko/jsonassert"
+	"github.com/opensearch-project/opensearch-go/v2"
+	"github.com/opensearch-project/opensearch-go/v2/opensearchapi"
+	"github.com/stretchr/testify/require"
 )
 
 type DataStreamRequest interface {
@@ -32,7 +32,9 @@ type DataStreamRequest interface {
 }
 
 func TestIndicesDataStreams_Do(t *testing.T) {
-	name := fmt.Sprintf("demo-%s", time.Now().Format("2006-01-02-15-04-05"))
+	// We need two datastreams to ensure endpoints that fetch both are tested appropriately
+	dataStream1 := fmt.Sprintf("demo-1-%s", time.Now().Format("2006-01-02-15-04-05"))
+	dataStream2 := fmt.Sprintf("demo-2-%s", time.Now().Format("2006-01-02-15-04-05"))
 
 	tests := []struct {
 		name     string
@@ -44,7 +46,27 @@ func TestIndicesDataStreams_Do(t *testing.T) {
 		{
 			name: "TestIndicesCreateDataStreamRequest_Do",
 			r: opensearchapi.IndicesCreateDataStreamRequest{
-				Name:       name,
+				Name:       dataStream1,
+				Pretty:     true,
+				Human:      true,
+				ErrorTrace: true,
+				Header: map[string][]string{
+					"Content-Type": {"application/json"},
+				},
+			},
+			want: &opensearchapi.Response{
+				StatusCode: 200,
+				Header: http.Header{
+					"Content-Type": []string{"application/json; charset=UTF-8"},
+				},
+			},
+			wantBody: `{"acknowledged":true}`,
+			wantErr:  false,
+		},
+		{
+			name: "TestIndicesCreateDataStream2Request_Do",
+			r: opensearchapi.IndicesCreateDataStreamRequest{
+				Name:       dataStream2,
 				Pretty:     true,
 				Human:      true,
 				ErrorTrace: true,
@@ -64,7 +86,7 @@ func TestIndicesDataStreams_Do(t *testing.T) {
 		{
 			name: "TestIndicesGetDataStreamRequest_Do",
 			r: opensearchapi.IndicesGetDataStreamRequest{
-				Name:       name,
+				Name:       dataStream1,
 				Pretty:     true,
 				Human:      true,
 				ErrorTrace: true,
@@ -101,7 +123,26 @@ func TestIndicesDataStreams_Do(t *testing.T) {
 		{
 			name: "TestIndicesGetStatsDataStreamRequest_Do",
 			r: opensearchapi.IndicesGetDataStreamStatsRequest{
-				Name:       name,
+				Name:       dataStream1,
+				Pretty:     true,
+				Human:      true,
+				ErrorTrace: true,
+				Header: map[string][]string{
+					"Content-Type": {"application/json"},
+				},
+			},
+			want: &opensearchapi.Response{
+				StatusCode: 200,
+				Header: http.Header{
+					"Content-Type": []string{"application/json; charset=UTF-8"},
+				},
+			},
+			wantBody: fmt.Sprintf(`{"_shards":{"total":2,"successful":1,"failed":0},"data_stream_count":1,"backing_indices":1,"total_store_size":"208b","total_store_size_bytes":208,"data_streams":[{"data_stream":"%s","backing_indices":1,"store_size":"208b","store_size_bytes":208,"maximum_timestamp":0}]}`, dataStream1),
+			wantErr:  false,
+		},
+		{
+			name: "TestIndicesGetAllStatsDataStreamRequest_Do",
+			r: opensearchapi.IndicesGetDataStreamStatsRequest{
 				Pretty:     true,
 				Human:      true,
 				ErrorTrace: true,
@@ -115,13 +156,33 @@ func TestIndicesDataStreams_Do(t *testing.T) {
 					"Content-Type": []string{"application/json; charset=UTF-8"},
 				},
 			},
-			wantBody: fmt.Sprintf(`{"_shards":{"total":2,"successful":1,"failed":0},"data_stream_count":1,"backing_indices":1,"total_store_size":"208b","total_store_size_bytes":208,"data_streams":[{"data_stream":"%s","backing_indices":1,"store_size":"208b","store_size_bytes":208,"maximum_timestamp":0}]}`, name),
+			wantBody: fmt.Sprintf(`{"_shards":{"total":4,"successful":2,"failed":0},"data_stream_count":2,"backing_indices":2,"total_store_size":"416b","total_store_size_bytes":416,"data_streams":["<<UNORDERED>>",{"data_stream":"%s","backing_indices":1,"store_size":"208b","store_size_bytes":208,"maximum_timestamp":0},{"data_stream":"%s","backing_indices":1,"store_size":"208b","store_size_bytes":208,"maximum_timestamp":0}]}`, dataStream2, dataStream1),
 			wantErr:  false,
 		},
 		{
 			name: "TestIndicesDeleteDataStreamRequest_Do",
 			r: opensearchapi.IndicesDeleteDataStreamRequest{
-				Name:       name,
+				Name:       dataStream1,
+				Pretty:     true,
+				Human:      true,
+				ErrorTrace: true,
+				Header: map[string][]string{
+					"Content-Type": {"application/json"},
+				},
+			},
+			want: &opensearchapi.Response{
+				StatusCode: 200,
+				Header: http.Header{
+					"Content-Type": []string{"application/json; charset=UTF-8"},
+				},
+			},
+			wantBody: `{"acknowledged":true}`,
+			wantErr:  false,
+		},
+		{
+			name: "TestIndicesDeleteDataStream2Request_Do",
+			r: opensearchapi.IndicesDeleteDataStreamRequest{
+				Name:       dataStream2,
 				Pretty:     true,
 				Human:      true,
 				ErrorTrace: true,
@@ -177,12 +238,8 @@ func TestIndicesDataStreams_Do(t *testing.T) {
 				body, err := ioutil.ReadAll(got.Body)
 				require.NoError(t, err)
 
-				buffer := new(bytes.Buffer)
-				if err := json.Compact(buffer, body); err != nil {
-					fmt.Println(err)
-				}
-
-				require.Equalf(t, buffer.String(), tt.wantBody, "Do() got = %v, want %v", got.String(), tt.wantBody)
+				ja := jsonassert.New(t)
+				ja.Assertf(string(body), tt.wantBody)
 			}
 		})
 	}
diff --git a/opensearchapi/api.indices.get_datastream_stats_test.go b/opensearchapi/api.indices.get_datastream_stats_test.go
new file mode 100644
index 0000000..1285c6c
--- /dev/null
+++ b/opensearchapi/api.indices.get_datastream_stats_test.go
@@ -0,0 +1,58 @@
+// 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.
+
+package opensearchapi
+
+import (
+	"context"
+	"fmt"
+	"net/http"
+	"testing"
+
+	"github.com/stretchr/testify/require"
+)
+
+type stubTransport struct {
+	req *http.Request
+}
+
+func (t *stubTransport) Perform(req *http.Request) (*http.Response, error) {
+	t.req = req
+	return &http.Response{}, nil
+}
+
+func TestIndicesGetDataStreamStatsRequest(t *testing.T) {
+	tt := stubTransport{}
+	req := IndicesGetDataStreamStatsRequest{}
+
+	expectedPath := "/_data_stream/_stats"
+
+	_, err := req.Do(context.Background(), &tt)
+	if err != nil {
+		t.Fatalf("Error getting response: %s", err)
+	}
+
+	require.Equal(t, expectedPath, tt.req.URL.Path)
+}
+
+func TestIndicesGetDataStreamStatsRequestOne(t *testing.T) {
+	tt := stubTransport{}
+	req := IndicesGetDataStreamStatsRequest{
+		Name: "demo-1",
+	}
+
+	expectedPath := fmt.Sprintf("/_data_stream/%s/_stats", req.Name)
+
+	_, err := req.Do(context.Background(), &tt)
+	if err != nil {
+		t.Fatalf("Error getting response: %s", err)
+	}
+
+	require.Equal(t, expectedPath, tt.req.URL.Path)
+}