Skip to content

Commit 6bf8480

Browse files
committed
updates
1 parent 95e8fed commit 6bf8480

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

internal/integration/unified/client_entity.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package unified
88

99
import (
1010
"context"
11+
"encoding/base64"
1112
"fmt"
1213
"os"
1314
"strings"
@@ -302,7 +303,11 @@ func createAutoEncryptionOptions(opts bson.Raw) (*options.AutoEncryptionOptions,
302303
"clientSecret": azureClientSecret,
303304
}
304305
case "local":
305-
_, key := providerOpt.Document().Lookup("key").Binary()
306+
str := providerOpt.Document().Lookup("key").StringValue()
307+
key, err := base64.StdEncoding.DecodeString(str)
308+
if err != nil {
309+
return nil, err
310+
}
306311
providers["local"] = map[string]any{
307312
"key": key,
308313
}
@@ -321,6 +326,8 @@ func createAutoEncryptionOptions(opts bson.Raw) (*options.AutoEncryptionOptions,
321326
case "keyVaultNamespace":
322327
kvnsFound = true
323328
aeo.SetKeyVaultNamespace(opt.StringValue())
329+
case "bypassQueryAnalysis":
330+
aeo.SetBypassQueryAnalysis(opt.Boolean())
324331
default:
325332
return nil, fmt.Errorf("unrecognized option: %v", name)
326333
}

internal/integration/unified/collection_data.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ type collectionData struct {
2727
}
2828

2929
type createOptions struct {
30-
Capped *bool `bson:"capped"`
31-
SizeInBytes *int64 `bson:"size"`
30+
Capped *bool `bson:"capped"`
31+
SizeInBytes *int64 `bson:"size"`
32+
EncryptedFields any `bson:"encryptedFields"`
3233
}
3334

3435
// createCollection configures the collection represented by the receiver using the internal client. This function
@@ -49,14 +50,15 @@ func (c *collectionData) createCollection(ctx context.Context) error {
4950
if c.Options.SizeInBytes != nil {
5051
createOpts = createOpts.SetSizeInBytes(*c.Options.SizeInBytes)
5152
}
53+
if c.Options.EncryptedFields != nil {
54+
createOpts = createOpts.SetEncryptedFields(c.Options.EncryptedFields)
55+
}
5256

5357
if err := db.CreateCollection(ctx, c.CollectionName, createOpts); err != nil {
5458
return fmt.Errorf("error creating collection: %w", err)
5559
}
56-
}
57-
58-
// If neither documents nor options are provided, still create the collection with write concern "majority".
59-
if len(c.Documents) == 0 && c.Options == nil {
60+
} else {
61+
// If options are provided, still create the collection with write concern "majority".
6062
// The write concern has to be manually specified in the command document because RunCommand does not honor
6163
// the database's write concern.
6264
create := bson.D{
@@ -68,13 +70,15 @@ func (c *collectionData) createCollection(ctx context.Context) error {
6870
if err := db.RunCommand(ctx, create).Err(); err != nil {
6971
return fmt.Errorf("error creating collection: %w", err)
7072
}
71-
return nil
7273
}
7374

74-
docs := bsonutil.RawToInterfaces(c.Documents...)
75-
if _, err := coll.InsertMany(ctx, docs); err != nil {
76-
return fmt.Errorf("error inserting data: %w", err)
75+
if len(c.Documents) != 0 {
76+
docs := bsonutil.RawToInterfaces(c.Documents...)
77+
if _, err := coll.InsertMany(ctx, docs); err != nil {
78+
return fmt.Errorf("error inserting data: %w", err)
79+
}
7780
}
81+
7882
return nil
7983
}
8084

0 commit comments

Comments
 (0)