Skip to content

Commit 0402b49

Browse files
author
AWS SDK for Go v2 automation user
committed
Regenerated Clients
1 parent a185f3b commit 0402b49

22 files changed

+1347
-280
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "3e8f46be-f063-4ecc-a6d7-9ce47de3e1b1",
3+
"type": "feature",
4+
"description": "Added new params copySource and key to copyObject API for supporting S3 Access Grants plugin. These changes will not change any of the existing S3 API functionality.",
5+
"modules": [
6+
"service/s3"
7+
]
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "8e1bf54e-e9c5-4a05-b900-fcae96c40f9e",
3+
"type": "feature",
4+
"description": "This release contains a new optional ip-addresses input field for the update accelerator and update custom routing accelerator apis. This input enables consumers to replace IPv4 addresses on existing accelerators with addresses provided in the input.",
5+
"modules": [
6+
"service/globalaccelerator"
7+
]
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "d3790cc1-943e-4cad-b454-d0a30bb36060",
3+
"type": "feature",
4+
"description": "AWS Glue now supports native SaaS connectivity: Salesforce connector available now",
5+
"modules": [
6+
"service/glue"
7+
]
8+
}

feature/dynamodbstreams/attributevalue/decode.go

+37-10
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,18 @@ type DecoderOptions struct {
231231
// Default string parsing format is time.RFC3339
232232
// Default number parsing format is seconds since January 1, 1970 UTC
233233
DecodeTime DecodeTimeAttributes
234+
235+
// When enabled, the decoder will use implementations of
236+
// encoding.TextUnmarshaler and encoding.BinaryUnmarshaler when present on
237+
// unmarshaling targets.
238+
//
239+
// If a target implements [Unmarshaler], encoding unmarshaler
240+
// implementations are ignored.
241+
//
242+
// If the attributevalue is a string, its underlying value will be used to
243+
// call UnmarshalText on the target. If the attributevalue is a binary, its
244+
// value will be used to call UnmarshalBinary.
245+
UseEncodingUnmarshalers bool
234246
}
235247

236248
// A Decoder provides unmarshaling AttributeValues to Go value types.
@@ -288,17 +300,30 @@ func (d *Decoder) decode(av types.AttributeValue, v reflect.Value, fieldTag tag)
288300
var u Unmarshaler
289301
_, isNull := av.(*types.AttributeValueMemberNULL)
290302
if av == nil || isNull {
291-
u, v = indirect(v, indirectOptions{decodeNull: true})
303+
u, v = indirect[Unmarshaler](v, indirectOptions{decodeNull: true})
292304
if u != nil {
293305
return u.UnmarshalDynamoDBStreamsAttributeValue(av)
294306
}
295307
return d.decodeNull(v)
296308
}
297309

298-
u, v = indirect(v, indirectOptions{})
310+
v0 := v
311+
u, v = indirect[Unmarshaler](v, indirectOptions{})
299312
if u != nil {
300313
return u.UnmarshalDynamoDBStreamsAttributeValue(av)
301314
}
315+
if d.options.UseEncodingUnmarshalers {
316+
if s, ok := av.(*types.AttributeValueMemberS); ok {
317+
if u, _ := indirect[encoding.TextUnmarshaler](v0, indirectOptions{}); u != nil {
318+
return u.UnmarshalText([]byte(s.Value))
319+
}
320+
}
321+
if b, ok := av.(*types.AttributeValueMemberB); ok {
322+
if u, _ := indirect[encoding.BinaryUnmarshaler](v0, indirectOptions{}); u != nil {
323+
return u.UnmarshalBinary(b.Value)
324+
}
325+
}
326+
}
302327

303328
switch tv := av.(type) {
304329
case *types.AttributeValueMemberB:
@@ -420,7 +445,7 @@ func (d *Decoder) decodeBinarySet(bs [][]byte, v reflect.Value) error {
420445
if !isArray {
421446
v.SetLen(i + 1)
422447
}
423-
u, elem := indirect(v.Index(i), indirectOptions{})
448+
u, elem := indirect[Unmarshaler](v.Index(i), indirectOptions{})
424449
if u != nil {
425450
return u.UnmarshalDynamoDBStreamsAttributeValue(&types.AttributeValueMemberBS{Value: bs})
426451
}
@@ -555,7 +580,7 @@ func (d *Decoder) decodeNumberSet(ns []string, v reflect.Value) error {
555580
if !isArray {
556581
v.SetLen(i + 1)
557582
}
558-
u, elem := indirect(v.Index(i), indirectOptions{})
583+
u, elem := indirect[Unmarshaler](v.Index(i), indirectOptions{})
559584
if u != nil {
560585
return u.UnmarshalDynamoDBStreamsAttributeValue(&types.AttributeValueMemberNS{Value: ns})
561586
}
@@ -634,7 +659,7 @@ func (d *Decoder) decodeMap(avMap map[string]types.AttributeValue, v reflect.Val
634659
for k, av := range avMap {
635660
key := reflect.New(keyType).Elem()
636661
// handle pointer keys
637-
_, indirectKey := indirect(key, indirectOptions{skipUnmarshaler: true})
662+
_, indirectKey := indirect[Unmarshaler](key, indirectOptions{skipUnmarshaler: true})
638663
if err := decodeMapKey(k, indirectKey, tag{}); err != nil {
639664
return &UnmarshalTypeError{
640665
Value: fmt.Sprintf("map key %q", k),
@@ -777,7 +802,7 @@ func (d *Decoder) decodeStringSet(ss []string, v reflect.Value) error {
777802
if !isArray {
778803
v.SetLen(i + 1)
779804
}
780-
u, elem := indirect(v.Index(i), indirectOptions{})
805+
u, elem := indirect[Unmarshaler](v.Index(i), indirectOptions{})
781806
if u != nil {
782807
return u.UnmarshalDynamoDBStreamsAttributeValue(&types.AttributeValueMemberSS{Value: ss})
783808
}
@@ -825,7 +850,7 @@ type indirectOptions struct {
825850
//
826851
// Based on the enoding/json type reflect value type indirection in Go Stdlib
827852
// https://golang.org/src/encoding/json/decode.go indirect func.
828-
func indirect(v reflect.Value, opts indirectOptions) (Unmarshaler, reflect.Value) {
853+
func indirect[U any](v reflect.Value, opts indirectOptions) (U, reflect.Value) {
829854
// Issue #24153 indicates that it is generally not a guaranteed property
830855
// that you may round-trip a reflect.Value by calling Value.Addr().Elem()
831856
// and expect the value to still be settable for values derived from
@@ -859,7 +884,8 @@ func indirect(v reflect.Value, opts indirectOptions) (Unmarshaler, reflect.Value
859884
continue
860885
}
861886
if e.Kind() != reflect.Ptr && e.IsValid() {
862-
return nil, e
887+
var u U
888+
return u, e
863889
}
864890
}
865891
if v.Kind() != reflect.Ptr {
@@ -880,7 +906,7 @@ func indirect(v reflect.Value, opts indirectOptions) (Unmarshaler, reflect.Value
880906
v.Set(reflect.New(v.Type().Elem()))
881907
}
882908
if !opts.skipUnmarshaler && v.Type().NumMethod() > 0 && v.CanInterface() {
883-
if u, ok := v.Interface().(Unmarshaler); ok {
909+
if u, ok := v.Interface().(U); ok {
884910
return u, reflect.Value{}
885911
}
886912
}
@@ -893,7 +919,8 @@ func indirect(v reflect.Value, opts indirectOptions) (Unmarshaler, reflect.Value
893919
}
894920
}
895921

896-
return nil, v
922+
var u U
923+
return u, v
897924
}
898925

899926
// A Number represents a Attributevalue number literal.

feature/dynamodbstreams/attributevalue/decode_test.go

+95
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"reflect"
66
"strconv"
7+
"strings"
78
"testing"
89
"time"
910

@@ -1173,3 +1174,97 @@ func TestUnmarshalMap_keyPtrTypes(t *testing.T) {
11731174
}
11741175

11751176
}
1177+
1178+
type textUnmarshalerString string
1179+
1180+
func (v *textUnmarshalerString) UnmarshalText(text []byte) error {
1181+
*v = textUnmarshalerString("[[" + string(text) + "]]")
1182+
return nil
1183+
}
1184+
1185+
func TestUnmarshalTextString(t *testing.T) {
1186+
in := &types.AttributeValueMemberS{Value: "foo"}
1187+
1188+
var actual textUnmarshalerString
1189+
err := UnmarshalWithOptions(in, &actual, func(o *DecoderOptions) {
1190+
o.UseEncodingUnmarshalers = true
1191+
})
1192+
if err != nil {
1193+
t.Fatalf("expect no error, got %v", err)
1194+
}
1195+
1196+
if string(actual) != "[[foo]]" {
1197+
t.Errorf("expected [[foo]], got %s", actual)
1198+
}
1199+
}
1200+
1201+
func TestUnmarshalTextStringDisabled(t *testing.T) {
1202+
in := &types.AttributeValueMemberS{Value: "foo"}
1203+
1204+
var actual textUnmarshalerString
1205+
err := UnmarshalWithOptions(in, &actual, func(o *DecoderOptions) {
1206+
o.UseEncodingUnmarshalers = false
1207+
})
1208+
if err != nil {
1209+
t.Fatalf("expect no error, got %v", err)
1210+
}
1211+
1212+
if string(actual) != "foo" {
1213+
t.Errorf("expected foo, got %s", actual)
1214+
}
1215+
}
1216+
1217+
type textUnmarshalerStruct struct {
1218+
I, J string
1219+
}
1220+
1221+
func (v *textUnmarshalerStruct) UnmarshalText(text []byte) error {
1222+
parts := strings.Split(string(text), ";")
1223+
v.I = parts[0]
1224+
v.J = parts[1]
1225+
return nil
1226+
}
1227+
1228+
func TestUnmarshalTextStruct(t *testing.T) {
1229+
in := &types.AttributeValueMemberS{Value: "foo;bar"}
1230+
1231+
var actual textUnmarshalerStruct
1232+
err := UnmarshalWithOptions(in, &actual, func(o *DecoderOptions) {
1233+
o.UseEncodingUnmarshalers = true
1234+
})
1235+
if err != nil {
1236+
t.Fatalf("expect no error, got %v", err)
1237+
}
1238+
1239+
expected := textUnmarshalerStruct{"foo", "bar"}
1240+
if actual != expected {
1241+
t.Errorf("expected %v, got %v", expected, actual)
1242+
}
1243+
}
1244+
1245+
type binaryUnmarshaler struct {
1246+
I, J byte
1247+
}
1248+
1249+
func (v *binaryUnmarshaler) UnmarshalBinary(b []byte) error {
1250+
v.I = b[0]
1251+
v.J = b[1]
1252+
return nil
1253+
}
1254+
1255+
func TestUnmarshalBinary(t *testing.T) {
1256+
in := &types.AttributeValueMemberB{Value: []byte{1, 2}}
1257+
1258+
var actual binaryUnmarshaler
1259+
err := UnmarshalWithOptions(in, &actual, func(o *DecoderOptions) {
1260+
o.UseEncodingUnmarshalers = true
1261+
})
1262+
if err != nil {
1263+
t.Fatalf("expect no error, got %v", err)
1264+
}
1265+
1266+
expected := binaryUnmarshaler{1, 2}
1267+
if actual != expected {
1268+
t.Errorf("expected %v, got %v", expected, actual)
1269+
}
1270+
}

feature/dynamodbstreams/attributevalue/encode.go

+43-5
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,7 @@ func MarshalListWithOptions(in interface{}, optFns ...func(*EncoderOptions)) ([]
354354
return asList.Value, nil
355355
}
356356

357-
// EncoderOptions is a collection of options shared between marshaling
358-
// and unmarshaling
357+
// EncoderOptions is a collection of options used by the marshaler.
359358
type EncoderOptions struct {
360359
// Support other custom struct tag keys, such as `yaml`, `json`, or `toml`.
361360
// Note that values provided with a custom TagKey must also be supported
@@ -380,6 +379,19 @@ type EncoderOptions struct {
380379
//
381380
// Default encoding is time.RFC3339Nano in a DynamoDBStreams String (S) data type.
382381
EncodeTime func(time.Time) (types.AttributeValue, error)
382+
383+
// When enabled, the encoder will use implementations of
384+
// encoding.TextMarshaler and encoding.BinaryMarshaler when present on
385+
// marshaled values.
386+
//
387+
// Implementations are checked in the following order:
388+
// - [Marshaler]
389+
// - encoding.TextMarshaler
390+
// - encoding.BinaryMarshaler
391+
//
392+
// The results of a MarshalText call will convert to string (S), results
393+
// from a MarshalBinary call will convert to binary (B).
394+
UseEncodingMarshalers bool
383395
}
384396

385397
// An Encoder provides marshaling Go value types to AttributeValues.
@@ -438,7 +450,7 @@ func (e *Encoder) encode(v reflect.Value, fieldTag tag) (types.AttributeValue, e
438450
v = valueElem(v)
439451

440452
if v.Kind() != reflect.Invalid {
441-
if av, err := tryMarshaler(v); err != nil {
453+
if av, err := e.tryMarshaler(v); err != nil {
442454
return nil, err
443455
} else if av != nil {
444456
return av, nil
@@ -822,7 +834,7 @@ func isNullableZeroValue(v reflect.Value) bool {
822834
return false
823835
}
824836

825-
func tryMarshaler(v reflect.Value) (types.AttributeValue, error) {
837+
func (e *Encoder) tryMarshaler(v reflect.Value) (types.AttributeValue, error) {
826838
if v.Kind() != reflect.Ptr && v.Type().Name() != "" && v.CanAddr() {
827839
v = v.Addr()
828840
}
@@ -831,9 +843,35 @@ func tryMarshaler(v reflect.Value) (types.AttributeValue, error) {
831843
return nil, nil
832844
}
833845

834-
if m, ok := v.Interface().(Marshaler); ok {
846+
i := v.Interface()
847+
if m, ok := i.(Marshaler); ok {
835848
return m.MarshalDynamoDBStreamsAttributeValue()
836849
}
850+
if e.options.UseEncodingMarshalers {
851+
return e.tryEncodingMarshaler(i)
852+
}
853+
854+
return nil, nil
855+
}
856+
857+
func (e *Encoder) tryEncodingMarshaler(v any) (types.AttributeValue, error) {
858+
if m, ok := v.(encoding.TextMarshaler); ok {
859+
s, err := m.MarshalText()
860+
if err != nil {
861+
return nil, err
862+
}
863+
864+
return &types.AttributeValueMemberS{Value: string(s)}, nil
865+
}
866+
867+
if m, ok := v.(encoding.BinaryMarshaler); ok {
868+
b, err := m.MarshalBinary()
869+
if err != nil {
870+
return nil, err
871+
}
872+
873+
return &types.AttributeValueMemberB{Value: b}, nil
874+
}
837875

838876
return nil, nil
839877
}

0 commit comments

Comments
 (0)