Skip to content

Commit f6c1d48

Browse files
author
Tianyi Wang
committed
sync polly presigner from main
1 parent 396f97a commit f6c1d48

File tree

9 files changed

+380
-2
lines changed

9 files changed

+380
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"id": "419f3a1b-33d8-4177-9c96-56a7d69c63e6",
3+
"type": "feature",
4+
"description": "Add support for polly SynthesizeSpeech GET request presigner",
5+
"modules": [
6+
".",
7+
"service/polly"
8+
]
9+
}

aws/protocol/query/object.go

+13
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ func (o *Object) Key(name string) Value {
4141
return o.key(name, false)
4242
}
4343

44+
// KeyWithValues adds the given named key to the Query object.
45+
// Returns a Value encoder that should be used to encode a Query list of values.
46+
func (o *Object) KeyWithValues(name string) Value {
47+
return o.keyWithValues(name, false)
48+
}
49+
4450
// FlatKey adds the given named key to the Query object.
4551
// Returns a Value encoder that should be used to encode a Query value type. The
4652
// value will be flattened if it is a map or array.
@@ -54,3 +60,10 @@ func (o *Object) key(name string, flatValue bool) Value {
5460
}
5561
return newValue(o.values, name, flatValue)
5662
}
63+
64+
func (o *Object) keyWithValues(name string, flatValue bool) Value {
65+
if o.prefix != "" {
66+
return newAppendValue(o.values, fmt.Sprintf("%s.%s", o.prefix, name), flatValue)
67+
}
68+
return newAppendValue(o.values, name, flatValue)
69+
}

aws/protocol/query/value.go

+9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ func newValue(values url.Values, key string, flat bool) Value {
2727
}
2828
}
2929

30+
func newAppendValue(values url.Values, key string, flat bool) Value {
31+
return Value{
32+
values: values,
33+
key: key,
34+
flat: flat,
35+
queryValue: httpbinding.NewQueryValue(values, key, true),
36+
}
37+
}
38+
3039
func newBaseValue(values url.Values) Value {
3140
return Value{
3241
values: values,

codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AwsHttpPresignURLClientGenerator.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ public class AwsHttpPresignURLClientGenerator implements GoIntegration {
101101
ShapeId.from("com.amazonaws.sts#AWSSecurityTokenServiceV20110615"), SetUtils.of(
102102
ShapeId.from("com.amazonaws.sts#GetCallerIdentity"),
103103
ShapeId.from("com.amazonaws.sts#AssumeRole")
104+
),
105+
ShapeId.from("com.amazonaws.polly#Parrot_v1"), SetUtils.of(
106+
ShapeId.from("com.amazonaws.polly#SynthesizeSpeech")
104107
)
105108
);
106109

@@ -381,8 +384,8 @@ private void writeConvertToPresignMiddleware(
381384
writer.write("return err");
382385
});
383386

384-
// if protocol used is ec2query or query
385-
if (serviceShape.hasTrait(AwsQueryTrait.ID) || serviceShape.hasTrait(Ec2QueryTrait.ID)) {
387+
// if protocol used is ec2query or query or if service is polly
388+
if (serviceShape.hasTrait(AwsQueryTrait.ID) || serviceShape.hasTrait(Ec2QueryTrait.ID) || isPollyServiceShape(serviceShape)) {
386389
// presigned url should convert to Get request
387390
Symbol queryAsGetMiddleware = SymbolUtils.createValueSymbolBuilder("AddAsGetRequestMiddleware",
388391
AwsGoDependency.AWS_QUERY_PROTOCOL).build();
@@ -392,6 +395,15 @@ private void writeConvertToPresignMiddleware(
392395
writer.write("if err != nil { return err }");
393396
}
394397

398+
// polly presigner needs to serialize input param into query string
399+
if (isPollyServiceShape(serviceShape)) {
400+
Symbol serializeInputMiddleware = SymbolUtils.createValueSymbolBuilder("AddPresignSynthesizeSpeechMiddleware",
401+
AwsGoDependency.AWS_QUERY_PROTOCOL).build();
402+
writer.writeDocs("use query encoder to encode GET request query string");
403+
writer.write("err = AddPresignSynthesizeSpeechMiddleware(stack)");
404+
writer.write("if err != nil { return err }");
405+
}
406+
395407
// s3 service needs expires and sets unsignedPayload if input is stream
396408
if (isS3ServiceShape(model, serviceShape)) {
397409

@@ -682,5 +694,9 @@ private final boolean isS3ServiceShape(Model model, ServiceShape service) {
682694
String serviceId = service.expectTrait(ServiceTrait.class).getSdkId();
683695
return serviceId.equalsIgnoreCase("S3");
684696
}
697+
698+
private final boolean isPollyServiceShape(ServiceShape service) {
699+
return service.expectTrait(ServiceTrait.class).getSdkId().equalsIgnoreCase("Polly");
700+
}
685701
}
686702

service/polly/api_client.go

+108
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/polly/api_op_SynthesizeSpeech.go

+24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/polly/generated.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"github.com/aws/aws-sdk-go-v2": "v1.4.0",
44
"github.com/aws/aws-sdk-go-v2/internal/configsources": "v0.0.0-00010101000000-000000000000",
55
"github.com/aws/aws-sdk-go-v2/internal/endpoints/v2": "v2.0.0-00010101000000-000000000000",
6+
"github.com/aws/aws-sdk-go-v2/service/internal/presigned-url": "v1.0.7",
67
"github.com/aws/smithy-go": "v1.4.0",
78
"github.com/google/go-cmp": "v0.5.4"
89
},

service/polly/presign.go

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package polly
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"fmt"
7+
"github.com/aws/aws-sdk-go-v2/aws/protocol/query"
8+
"github.com/aws/smithy-go"
9+
"github.com/aws/smithy-go/middleware"
10+
smithyhttp "github.com/aws/smithy-go/transport/http"
11+
)
12+
13+
// AddPresignSynthesizeSpeechMiddleware adds presignOpSynthesizeSpeechInput into middleware stack to
14+
// parse SynthesizeSpeechInput into request stream
15+
func AddPresignSynthesizeSpeechMiddleware(stack *middleware.Stack) error {
16+
return stack.Serialize.Insert(&presignOpSynthesizeSpeechInput{}, "Query:AsGetRequest", middleware.Before)
17+
}
18+
19+
// presignOpSynthesizeSpeechInput encodes SynthesizeSpeechInput into url format
20+
// query string and put that into request stream for later presign-url build
21+
type presignOpSynthesizeSpeechInput struct {
22+
}
23+
24+
func (*presignOpSynthesizeSpeechInput) ID() string {
25+
return "PresignSerializer"
26+
}
27+
28+
func (m *presignOpSynthesizeSpeechInput) HandleSerialize(ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler) (
29+
out middleware.SerializeOutput, metadata middleware.Metadata, err error,
30+
) {
31+
request, ok := in.Request.(*smithyhttp.Request)
32+
if !ok {
33+
return out, metadata, &smithy.SerializationError{Err: fmt.Errorf("unknown transport type %T", in.Request)}
34+
}
35+
36+
input, ok := in.Parameters.(*SynthesizeSpeechInput)
37+
_ = input
38+
if !ok {
39+
return out, metadata, &smithy.SerializationError{Err: fmt.Errorf("unknown input parameters type %T", in.Parameters)}
40+
}
41+
42+
bodyWriter := bytes.NewBuffer(nil)
43+
bodyEncoder := query.NewEncoder(bodyWriter)
44+
45+
if err := presignSerializeOpDocumentSynthesizeSpeechInput(input, bodyEncoder.Value); err != nil {
46+
return out, metadata, &smithy.SerializationError{Err: err}
47+
}
48+
49+
err = bodyEncoder.Encode()
50+
if err != nil {
51+
return out, metadata, &smithy.SerializationError{Err: err}
52+
}
53+
54+
if request, err = request.SetStream(bytes.NewReader(bodyWriter.Bytes())); err != nil {
55+
return out, metadata, &smithy.SerializationError{Err: err}
56+
}
57+
58+
in.Request = request
59+
60+
return next.HandleSerialize(ctx, in)
61+
}
62+
63+
func presignSerializeOpDocumentSynthesizeSpeechInput(v *SynthesizeSpeechInput, value query.Value) error {
64+
object := value.Object()
65+
_ = object
66+
67+
if v.LexiconNames != nil && len(v.LexiconNames) > 0 {
68+
objectKey := object.KeyWithValues("LexiconNames")
69+
for _, name := range v.LexiconNames {
70+
objectKey.String(name)
71+
}
72+
}
73+
74+
if len(v.OutputFormat) > 0 {
75+
objectKey := object.Key("OutputFormat")
76+
objectKey.String(string(v.OutputFormat))
77+
}
78+
79+
if v.SampleRate != nil {
80+
objectKey := object.Key("SampleRate")
81+
objectKey.String(*v.SampleRate)
82+
}
83+
84+
if v.Text != nil {
85+
objectKey := object.Key("Text")
86+
objectKey.String(*v.Text)
87+
}
88+
89+
if len(v.TextType) > 0 {
90+
objectKey := object.Key("TextType")
91+
objectKey.String(string(v.TextType))
92+
}
93+
94+
if len(v.VoiceId) > 0 {
95+
objectKey := object.Key("VoiceId")
96+
objectKey.String(string(v.VoiceId))
97+
}
98+
99+
return nil
100+
}

0 commit comments

Comments
 (0)