Skip to content

Commit

Permalink
Support DefaultIdentificationHydrator in cosmosdb state component (#1121
Browse files Browse the repository at this point in the history
)

Follow-up to #1104 to support AD Auth codepath as well.

`NewConfig()` and `NewConfigWithServicePrincipal()` both set the
`Config.IdentificationHydrator` to the `DefaultIdentificationHydrator`
in the underlying a8m/documentdb library. That implementation ends up
calling `reflect.Value.Elem.FieldByName()`, which requires that the
value passed to it is an interface or pointer, otherwise the Elem()
call fails to dereference which causes a panic.

cosmosdb.go passes the input to `UpsertDocument` by value today,
which is eventually passed to the `DefaultIdentificationHydrator`,
so changing the value passed to a pointer resolves the failure.

Co-authored-by: Dapr Bot <56698301+dapr-bot@users.noreply.github.com>
  • Loading branch information
CodeMonkeyLeet and dapr-bot committed Sep 3, 2021
1 parent a0542ec commit 4f35813
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions state/azure/cosmosdb/cosmosdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,9 @@ func (c *StateStore) Init(meta state.Metadata) error {
// Create the client; first, try authenticating with a master key, if present
var config *documentdb.Config
if m.MasterKey != "" {
config = &documentdb.Config{
MasterKey: &documentdb.Key{
Key: m.MasterKey,
},
}
config = documentdb.NewConfig(&documentdb.Key{
Key: m.MasterKey,
})
} else {
// Fallback to using Azure AD
env, errB := azure.NewEnvironmentSettings("cosmosdb", meta.Properties)
Expand Down Expand Up @@ -273,7 +271,7 @@ func (c *StateStore) Set(req *state.SetRequest) error {
if err != nil {
return err
}
_, err = c.client.UpsertDocument(c.collection.Self, doc, options...)
_, err = c.client.UpsertDocument(c.collection.Self, &doc, options...)

if err != nil {
if req.ETag != nil {
Expand Down

0 comments on commit 4f35813

Please sign in to comment.