Use unmarshaling for AutoEncryptOpts in the unified spec test

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • Go Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Context

      The entityOptions.AutoEncryptOpts should be updated to use unmarshaling to create a struct matching the unified spec test requirements.

      Definition of done

      AutoEncryptOpts should be defined unambigously:

      type awsKMSProvider struct {
      	AccessKeyID     string `bson:"accessKeyId"`
      	SecretAccessKey string `bson:"secretAccessKey"`
      	SessionToken    string `bson:"sessionToken,omitempty"`
      }
      
      type KMSProviders struct {
      	AWS *awsKMSProvider `bson:"aws"`
      	// etc
      }
      
      type autoEncryptOpts struct {
      	KMSProviders         KMSProviders   `bson:"kmsProviders,omitempty"`
      	SchemaMap            map[string]any `bson:"schemaMap,omitempty"`
      	KeyVaultNamespace    string         `bson:"keyVaultNamespace,omitempty"`
      	BypassAutoEncryption bool           `bson:"bypassAutoEncryption,omitempty"`
      	EncryptedFieldsMap   map[string]any `bson:"encryptedFieldsMap,omitempty"`
      	BypassQueryAnalysis  bool           `bson:"bypassQueryAnalysis,omitempty"`
      }
      
      type clientEntity struct {
      	AutoEncryptOpts *autoEncryptOpts `bson:"autoEncryptOpts"`
      }
      

      Then each KMS provider (e.g awsKMSPRovider) can implement bson.Unmarshaler rather than depending on bson.Raw elements patter:

      	elems, err := opts.Elements()
      	if err != nil {
      		return nil, err
      	}
      
      	for _, elem := range elems {
      		name := elem.Key()
      		opt := elem.Value()
                      // ...
              }
      

      See POC here: https://github.com/prestonvasquez/go-playground/blob/1cce584a1eb443e4eba30c52f6251d7787ab92bc/mgd_auto_encrypt_opts_test.go#L15

            Assignee:
            Unassigned
            Reporter:
            Preston Vasquez
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: