From 60322a1f1c1c5cbadbd8f7b7e00baa9ce5c5681a Mon Sep 17 00:00:00 2001 From: Roberto Rojas Date: Wed, 2 Aug 2023 16:50:40 -0400 Subject: [PATCH 1/2] [AWS State DynamoDB] Adds Component Metadata Schema (#2906) Signed-off-by: Roberto J Rojas Signed-off-by: Roberto Rojas Co-authored-by: Alessandro (Ale) Segala <43508+ItalyPaleAle@users.noreply.github.com> Co-authored-by: Artur Souza --- state/aws/dynamodb/dynamodb.go | 8 +++-- state/aws/dynamodb/metadata.yaml | 59 ++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 state/aws/dynamodb/metadata.yaml diff --git a/state/aws/dynamodb/dynamodb.go b/state/aws/dynamodb/dynamodb.go index ba7c3ab96b..33592d5706 100644 --- a/state/aws/dynamodb/dynamodb.go +++ b/state/aws/dynamodb/dynamodb.go @@ -46,11 +46,13 @@ type StateStore struct { } type dynamoDBMetadata struct { + // Ignored by metadata parser because included in built-in authentication profile + AccessKey string `json:"accessKey" mapstructure:"accessKey" mdignore:"true"` + SecretKey string `json:"secretKey" mapstructure:"secretKey" mdignore:"true"` + SessionToken string `json:"sessionToken" mapstructure:"sessionToken" mdignore:"true"` + Region string `json:"region"` Endpoint string `json:"endpoint"` - AccessKey string `json:"accessKey"` - SecretKey string `json:"secretKey"` - SessionToken string `json:"sessionToken"` Table string `json:"table"` TTLAttributeName string `json:"ttlAttributeName"` PartitionKey string `json:"partitionKey"` diff --git a/state/aws/dynamodb/metadata.yaml b/state/aws/dynamodb/metadata.yaml new file mode 100644 index 0000000000..ed0c9a3fbc --- /dev/null +++ b/state/aws/dynamodb/metadata.yaml @@ -0,0 +1,59 @@ +# yaml-language-server: $schema=../../../component-metadata-schema.json +schemaVersion: v1 +type: state +name: aws.dynamodb +version: v1 +status: stable +title: "AWS DynamoDB" +urls: + - title: Reference + url: https://docs.dapr.io/reference/components-reference/supported-state-stores/setup-dynamodb/ +capabilities: + - crud + - transactional + - etag + - ttl + - actorStateStore +builtinAuthenticationProfiles: + - name: "aws" +metadata: + - name: table + required: true + description: | + The name of the DynamoDB table to use. + example: '"Contracts"' + type: string + - name: region + required: false + description: | + The AWS region to use. Ensure that DynamoDB is available in that region. + See the `Amazon DynamoDB endpoints and quotas` documentation. + url: + title: Amazon DynamoDB endpoints and quotas + url: https://docs.aws.amazon.com/general/latest/gr/ddb.html + example: '"us-east-1"' + type: string + - name: endpoint + required: false + description: | + AWS endpoint for the component to use. Only used for local development. + The endpoint is not necessary when running against production AWS. + example: '"http://localhost:4566"' + type: string + - name: ttlAttributeName + required: false + description: | + The table attribute name which should be used for TTL. + example: '"expiresAt"' + type: string + - name: partitionKey + required: false + description: | + The table primary key or partition key attribute name. + This field is used to replace the default primary key attribute name "key". + url: + title: More details + url: https://docs.dapr.io/reference/components-reference/supported-state-stores/setup-dynamodb/#partition-keys + example: '"ContractID"' + type: string + \ No newline at end of file From 566c7fd31adbd81740ba66995729a7eadeb3444a Mon Sep 17 00:00:00 2001 From: Robert Oh <36242112+robert-oh@users.noreply.github.com> Date: Wed, 2 Aug 2023 23:27:46 +0200 Subject: [PATCH 2/2] use rabbitmq message's header values as metadata values in the binding (#3031) Signed-off-by: Ohlicher Robert Signed-off-by: Alessandro (Ale) Segala <43508+ItalyPaleAle@users.noreply.github.com> Co-authored-by: Ohlicher Robert Co-authored-by: Alessandro (Ale) Segala <43508+ItalyPaleAle@users.noreply.github.com> --- bindings/rabbitmq/rabbitmq.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/bindings/rabbitmq/rabbitmq.go b/bindings/rabbitmq/rabbitmq.go index e10f7422f3..4188851342 100644 --- a/bindings/rabbitmq/rabbitmq.go +++ b/bindings/rabbitmq/rabbitmq.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "math" + "net/url" "reflect" "strconv" "sync" @@ -464,8 +465,20 @@ func (r *RabbitMQ) handleMessage(ctx context.Context, handler bindings.Handler, r.logger.Info("Input binding channel closed") return } + + metadata := make(map[string]string, len(d.Headers)) + // Passthrough any custom metadata to the handler. + for k, v := range d.Headers { + if s, ok := v.(string); ok { + // Escape the key and value to ensure they are valid URL query parameters. + // This is necessary for them to be sent as HTTP Metadata. + metadata[url.QueryEscape(k)] = url.QueryEscape(s) + } + } + _, err := handler(ctx, &bindings.ReadResponse{ - Data: d.Body, + Data: d.Body, + Metadata: metadata, }) if err != nil { ch.Nack(d.DeliveryTag, false, true)