Skip to content

Commit 8058c19

Browse files
authored
Merge branch 'main' into 3318-RavenDB-state-store-new
2 parents eae0f77 + 9088baa commit 8058c19

File tree

31 files changed

+502
-41
lines changed

31 files changed

+502
-41
lines changed

bindings/azure/servicebusqueues/servicebusqueues.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (a *AzureServiceBusQueues) Init(ctx context.Context, metadata bindings.Meta
6262
return err
6363
}
6464

65-
a.client, err = impl.NewClient(a.metadata, metadata.Properties)
65+
a.client, err = impl.NewClient(a.metadata, metadata.Properties, a.logger)
6666
if err != nil {
6767
return err
6868
}

bindings/gcp/bucket/bucket.go

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,7 @@ func (g *GCPStorage) Init(ctx context.Context, metadata bindings.Metadata) error
110110
return err
111111
}
112112

113-
b, err := json.Marshal(m)
114-
if err != nil {
115-
return err
116-
}
117-
118-
clientOptions := option.WithCredentialsJSON(b)
119-
client, err := storage.NewClient(ctx, clientOptions)
113+
client, err := g.getClient(ctx, m)
120114
if err != nil {
121115
return err
122116
}
@@ -127,6 +121,41 @@ func (g *GCPStorage) Init(ctx context.Context, metadata bindings.Metadata) error
127121
return nil
128122
}
129123

124+
func (g *GCPStorage) getClient(ctx context.Context, m *gcpMetadata) (*storage.Client, error) {
125+
var client *storage.Client
126+
var err error
127+
128+
if m.Bucket == "" {
129+
return nil, errors.New("missing property `bucket` in metadata")
130+
}
131+
if m.ProjectID == "" {
132+
return nil, errors.New("missing property `project_id` in metadata")
133+
}
134+
135+
// Explicit authentication
136+
if m.PrivateKeyID != "" {
137+
var b []byte
138+
b, err = json.Marshal(m)
139+
if err != nil {
140+
return nil, err
141+
}
142+
143+
clientOptions := option.WithCredentialsJSON(b)
144+
client, err = storage.NewClient(ctx, clientOptions)
145+
if err != nil {
146+
return nil, err
147+
}
148+
} else {
149+
// Implicit authentication, using GCP Application Default Credentials (ADC)
150+
// Credentials search order: https://cloud.google.com/docs/authentication/application-default-credentials#order
151+
client, err = storage.NewClient(ctx)
152+
if err != nil {
153+
return nil, err
154+
}
155+
}
156+
return client, nil
157+
}
158+
130159
func (g *GCPStorage) parseMetadata(meta bindings.Metadata) (*gcpMetadata, error) {
131160
m := gcpMetadata{}
132161
err := kitmd.DecodeMetadata(meta.Properties, &m)

bindings/gcp/bucket/bucket_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package bucket
1515

1616
import (
1717
"encoding/json"
18+
"errors"
1819
"testing"
1920

2021
"github.com/stretchr/testify/assert"
@@ -234,6 +235,30 @@ func TestMergeWithRequestMetadata(t *testing.T) {
234235
})
235236
}
236237

238+
func TestInit(t *testing.T) {
239+
t.Run("Init missing bucket from metadata", func(t *testing.T) {
240+
m := bindings.Metadata{}
241+
m.Properties = map[string]string{
242+
"projectID": "my_project_id",
243+
}
244+
gs := GCPStorage{logger: logger.NewLogger("test")}
245+
err := gs.Init(t.Context(), m)
246+
require.Error(t, err)
247+
assert.Equal(t, err, errors.New("missing property `bucket` in metadata"))
248+
})
249+
250+
t.Run("Init missing projectID from metadata", func(t *testing.T) {
251+
m := bindings.Metadata{}
252+
m.Properties = map[string]string{
253+
"bucket": "my_bucket",
254+
}
255+
gs := GCPStorage{logger: logger.NewLogger("test")}
256+
err := gs.Init(t.Context(), m)
257+
require.Error(t, err)
258+
assert.Equal(t, err, errors.New("missing property `project_id` in metadata"))
259+
})
260+
}
261+
237262
func TestGetOption(t *testing.T) {
238263
gs := GCPStorage{logger: logger.NewLogger("test")}
239264
gs.metadata = &gcpMetadata{}

bindings/redis/metadata.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,30 @@ authenticationProfiles:
4242
secret reference
4343
example: "KeFg23!"
4444
default: ""
45+
- name: sentinelUsername
46+
type: string
47+
required: false
48+
description: |
49+
Username for Redis Sentinel. Applicable only when "failover" is true, and
50+
Redis Sentinel has authentication enabled. Defaults to empty.
51+
example: "my-sentinel-username"
52+
default: ""
53+
url:
54+
title: "Redis Sentinel authentication documentation"
55+
url: "https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/#configuring-sentinel-instances-with-authentication"
56+
- name: sentinelPassword
57+
type: string
58+
required: false
59+
sensitive: true
60+
description: |
61+
Password for Redis Sentinel. Applicable only when "failover" is true, and
62+
Redis Sentinel has authentication enabled. Use secretKeyRef for
63+
secret reference. Defaults to empty.
64+
example: "KeFg23!"
65+
default: ""
66+
url:
67+
title: "Redis Sentinel authentication documentation"
68+
url: "https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/#configuring-sentinel-instances-with-authentication"
4569
metadata:
4670
- name: redisHost
4771
required: true

common/component/azure/servicebus/client.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package servicebus
1616
import (
1717
"context"
1818
"fmt"
19+
"strings"
1920
"sync"
2021
"time"
2122

@@ -40,7 +41,7 @@ type Client struct {
4041
}
4142

4243
// NewClient creates a new Client object.
43-
func NewClient(metadata *Metadata, rawMetadata map[string]string) (*Client, error) {
44+
func NewClient(metadata *Metadata, rawMetadata map[string]string, log logger.Logger) (*Client, error) {
4445
client := &Client{
4546
metadata: metadata,
4647
lock: &sync.RWMutex{},
@@ -86,9 +87,17 @@ func NewClient(metadata *Metadata, rawMetadata map[string]string) (*Client, erro
8687
}
8788

8889
if !metadata.DisableEntityManagement {
89-
client.adminClient, err = sbadmin.NewClient(metadata.NamespaceName, token, nil)
90-
if err != nil {
91-
return nil, err
90+
if isAzureEmulator(metadata.ConnectionString) {
91+
log.Warn(
92+
"UseDevelopmentEmulator=true detected in connection string. " +
93+
"Azure emulator does not support topic management APIs. " +
94+
"Dapr will skip admin operations. " +
95+
"To suppress this warning, explicitly set disableEntityManagement: true.")
96+
} else {
97+
client.adminClient, err = sbadmin.NewClient(metadata.NamespaceName, token, nil)
98+
if err != nil {
99+
return nil, err
100+
}
92101
}
93102
}
94103
}
@@ -394,3 +403,7 @@ func notEqual(a, b *bool) bool {
394403
}
395404
return *a != *b
396405
}
406+
407+
func isAzureEmulator(connectionString string) bool {
408+
return strings.Contains(strings.ToLower(connectionString), "usedevelopmentemulator=true")
409+
}

common/component/redis/redis_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const (
2525
host = "redisHost"
2626
password = "redisPassword"
2727
username = "redisUsername"
28+
sentinelUsername = "sentinelUsername"
29+
sentinelPassword = "sentinelPassword"
2830
db = "redisDB"
2931
redisType = "redisType"
3032
redisMaxRetries = "redisMaxRetries"
@@ -51,6 +53,8 @@ func getFakeProperties() map[string]string {
5153
host: "fake.redis.com",
5254
password: "fakePassword",
5355
username: "fakeUsername",
56+
sentinelUsername: "fakeSentinelUsername",
57+
sentinelPassword: "fakeSentinelPassword",
5458
redisType: "node",
5559
enableTLS: "true",
5660
clientCert: "fakeCert",
@@ -86,6 +90,8 @@ func TestParseRedisMetadata(t *testing.T) {
8690
assert.Equal(t, fakeProperties[host], m.Host)
8791
assert.Equal(t, fakeProperties[password], m.Password)
8892
assert.Equal(t, fakeProperties[username], m.Username)
93+
assert.Equal(t, fakeProperties[sentinelUsername], m.SentinelUsername)
94+
assert.Equal(t, fakeProperties[sentinelPassword], m.SentinelPassword)
8995
assert.Equal(t, fakeProperties[redisType], m.RedisType)
9096
assert.True(t, m.EnableTLS)
9197
assert.Equal(t, fakeProperties[clientCert], m.ClientCert)

common/component/redis/settings.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ type Settings struct {
2929
Password string `mapstructure:"redisPassword"`
3030
// The Redis username
3131
Username string `mapstructure:"redisUsername"`
32+
// The Redis Sentinel password
33+
SentinelPassword string `mapstructure:"sentinelPassword"`
34+
// The Redis Sentinel username
35+
SentinelUsername string `mapstructure:"sentinelUsername"`
3236
// Database to be selected after connecting to the server.
3337
DB int `mapstructure:"redisDB"`
3438
// The redis type node or cluster

common/component/redis/v8client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ func newV8FailoverClient(s *Settings) (RedisClient, error) {
330330
DB: s.DB,
331331
MasterName: s.SentinelMasterName,
332332
SentinelAddrs: []string{s.Host},
333+
SentinelUsername: s.SentinelUsername,
334+
SentinelPassword: s.SentinelPassword,
333335
Password: s.Password,
334336
Username: s.Username,
335337
MaxRetries: s.RedisMaxRetries,

common/component/redis/v9client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ func newV9FailoverClient(s *Settings) (RedisClient, error) {
330330
DB: s.DB,
331331
MasterName: s.SentinelMasterName,
332332
SentinelAddrs: []string{s.Host},
333+
SentinelUsername: s.SentinelUsername,
334+
SentinelPassword: s.SentinelPassword,
333335
Password: s.Password,
334336
Username: s.Username,
335337
MaxRetries: s.RedisMaxRetries,

configuration/redis/metadata.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,30 @@ authenticationProfiles:
3030
secret reference
3131
example: "KeFg23!"
3232
default: ""
33+
- name: sentinelUsername
34+
type: string
35+
required: false
36+
description: |
37+
Username for Redis Sentinel. Applicable only when "failover" is true, and
38+
Redis Sentinel has authentication enabled. Defaults to empty.
39+
example: "my-sentinel-username"
40+
default: ""
41+
url:
42+
title: "Redis Sentinel authentication documentation"
43+
url: "https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/#configuring-sentinel-instances-with-authentication"
44+
- name: sentinelPassword
45+
type: string
46+
required: false
47+
sensitive: true
48+
description: |
49+
Password for Redis Sentinel. Applicable only when "failover" is true, and
50+
Redis Sentinel has authentication enabled. Use secretKeyRef for
51+
secret reference. Defaults to empty.
52+
example: "KeFg23!"
53+
default: ""
54+
url:
55+
title: "Redis Sentinel authentication documentation"
56+
url: "https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/#configuring-sentinel-instances-with-authentication"
3357
metadata:
3458
- name: redisHost
3559
required: true

0 commit comments

Comments
 (0)