From 26dea0c1c20e7f3a05a5c625d82abb201a1504cc Mon Sep 17 00:00:00 2001 From: "Alessandro (Ale) Segala" <43508+ItalyPaleAle@users.noreply.github.com> Date: Wed, 12 Apr 2023 14:25:03 -0700 Subject: [PATCH] Add metadata for bindings.azure.signalr (#2772) Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com> --- bindings/azure/signalr/metadata.yaml | 79 ++++++++++++++++++++++++++++ bindings/azure/signalr/signalr.go | 16 +++--- 2 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 bindings/azure/signalr/metadata.yaml diff --git a/bindings/azure/signalr/metadata.yaml b/bindings/azure/signalr/metadata.yaml new file mode 100644 index 000000000..f12cf0cfb --- /dev/null +++ b/bindings/azure/signalr/metadata.yaml @@ -0,0 +1,79 @@ +# yaml-language-server: $schema=../../../component-metadata-schema.json +schemaVersion: "v1" +type: "bindings" +name: "azure.signalr" +version: "v1" +status: "alpha" +title: "Azure SignalR" +urls: + - title: "Reference" + url: "https://docs.dapr.io/reference/components-reference/supported-bindings/signalr/" +binding: + output: true + input: false + operations: + - name: "create" + description: "Send a message to SignalR" +capabilities: [] +authenticationProfiles: + - title: "Connection string with access key" + description: "Authenticate using a connection string with an access key." + metadata: + - name: "connectionString" + required: true + sensitive: true + description: "The Azure SignalR connection string." + example: | + "Endpoint=https://.service.signalr.net;AccessKey=;Version=1.0;" + - name: "endpoint" + description: "Endpoint of Azure SignalR. Required if not included in the connection string." + example: | + "https://.service.signalr.net" + - title: "Access key" + description: "Authenticate using an access key." + metadata: + - name: "accessKey" + required: true + sensitive: true + description: "The access key for Azure SignalR." + example: | + "your-access-key" + - name: "endpoint" + required: true + description: "Endpoint of Azure SignalR. Required if not included in the connection string." + example: | + "https://.service.signalr.net" + - title: "Connection string with Azure AD credentials" + description: "Authenticate using Azure AD credentials defined in the connection string." + metadata: + - name: "connectionString" + required: true + sensitive: true + description: | + The Azure SignalR connection string containing Azure AD credentials. This includes the `AuthType=aad` option. + Note that you cannot use a connection string if your application's ClientSecret contains a `;` character. + # Note the example below contains Markdown inside a string + example: | + - With a system-assigned managed identity: `"Endpoint=https://.service.signalr.net;AuthType=aad;Version=1.0;"` + - With a user-assigned managed identity: `"Endpoint=https://.service.signalr.net;AuthType=aad;ClientId=;Version=1.0;"` + - With an Azure AD application: `"Endpoint=https://.service.signalr.net;AuthType=aad;ClientId=;ClientSecret=;TenantId=;Version=1.0;"` + - name: "endpoint" + description: "Endpoint of Azure SignalR. Required if not included in the connection string." + example: | + "https://.service.signalr.net" +builtinAuthenticationProfiles: + - name: "azuread" + metadata: + - name: "endpoint" + description: "Endpoint of Azure SignalR" + example: | + "https://.service.signalr.net" + required: true +metadata: + - name: "hub" + description: | + Defines the hub in which the message will be sent. + This value can also be set for each invocation of the binding by passing the metadata option `hub`` with the invocation request. + example: | + "myhub" + diff --git a/bindings/azure/signalr/signalr.go b/bindings/azure/signalr/signalr.go index 2555b1100..a446ffc9a 100644 --- a/bindings/azure/signalr/signalr.go +++ b/bindings/azure/signalr/signalr.go @@ -16,6 +16,8 @@ package signalr import ( "bytes" "context" + "crypto/tls" + "errors" "fmt" "io" "net/http" @@ -35,9 +37,6 @@ import ( ) const ( - errorPrefix = "azure signalr error:" - logPrefix = "azure signalr:" - connectionStringKey = "connectionString" accessKeyKey = "accessKey" endpointKey = "endpoint" @@ -63,6 +62,11 @@ var httpClient *http.Client func init() { httpClient = &http.Client{ Timeout: 30 * time.Second, + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{ + MinVersion: tls.VersionTLS12, + }, + }, } } @@ -192,7 +196,7 @@ func (s *SignalR) resolveAPIURL(req *bindings.InvokeRequest) (string, error) { hub = s.hub } if hub == "" { - return "", fmt.Errorf("%s missing hub", errorPrefix) + return "", errors.New("missing hub") } // Hub name is lower-cased in the official SDKs (e.g. .NET) @@ -233,10 +237,10 @@ func (s *SignalR) sendMessageToSignalR(ctx context.Context, url string, token st } if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusAccepted { - return fmt.Errorf("%s azure signalr failed with code %d, content is '%s'", errorPrefix, resp.StatusCode, string(body)) + return fmt.Errorf("azure signalr failed with code %d, content is '%s'", resp.StatusCode, string(body)) } - s.logger.Debugf("%s azure signalr call to '%s' completed with code %d", logPrefix, url, resp.StatusCode) + s.logger.Debugf("azure signalr call to '%s' completed with code %d", url, resp.StatusCode) return nil }