From 55943a3b09faaa170bdf81ec96f43101050e9a35 Mon Sep 17 00:00:00 2001 From: Robert Yokota Date: Tue, 6 Aug 2024 15:35:48 -0700 Subject: [PATCH] Improve missing KMS error message (#6) (#2279) * Improve missing KMS error message Also enhance examples, some minor cleanup * Fix tests --- examples/AvroGenericEncryption/Program.cs | 6 +++++- examples/AvroSpecificEncryption/Program.cs | 6 +++++- examples/JsonEncryption/Program.cs | 4 ++++ examples/ProtobufEncryption/Program.cs | 6 +++++- src/Confluent.SchemaRegistry.Encryption/KmsRegistry.cs | 3 ++- .../Rest/DataContracts/Schema.cs | 9 +++------ 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/examples/AvroGenericEncryption/Program.cs b/examples/AvroGenericEncryption/Program.cs index 0c7917c5e..a8b966f83 100644 --- a/examples/AvroGenericEncryption/Program.cs +++ b/examples/AvroGenericEncryption/Program.cs @@ -48,6 +48,7 @@ static async Task Main(string[] args) AzureKmsDriver.Register(); GcpKmsDriver.Register(); HcVaultKmsDriver.Register(); + LocalKmsDriver.Register(); FieldEncryptionExecutor.Register(); string bootstrapServers = args[0]; @@ -79,7 +80,10 @@ static async Task Main(string[] args) // optional Avro serializer properties: BufferBytes = 100 }; - + // KMS properties can be passed as follows + // avroSerializerConfig.Set("rules.secret.access.key", "xxx"); + // avroSerializerConfig.Set("rules.access.key.id", "xxx"); + RuleSet ruleSet = new RuleSet(new List(), new List { diff --git a/examples/AvroSpecificEncryption/Program.cs b/examples/AvroSpecificEncryption/Program.cs index a277ff9f5..96e6245b0 100644 --- a/examples/AvroSpecificEncryption/Program.cs +++ b/examples/AvroSpecificEncryption/Program.cs @@ -45,6 +45,7 @@ static void Main(string[] args) AzureKmsDriver.Register(); GcpKmsDriver.Register(); HcVaultKmsDriver.Register(); + LocalKmsDriver.Register(); FieldEncryptionExecutor.Register(); string bootstrapServers = args[0]; @@ -82,7 +83,10 @@ static void Main(string[] args) // optional Avro serializer properties: BufferBytes = 100 }; - + // KMS properties can be passed as follows + // avroSerializerConfig.Set("rules.secret.access.key", "xxx"); + // avroSerializerConfig.Set("rules.access.key.id", "xxx"); + RuleSet ruleSet = new RuleSet(new List(), new List { diff --git a/examples/JsonEncryption/Program.cs b/examples/JsonEncryption/Program.cs index 90992832f..5e6b072cb 100644 --- a/examples/JsonEncryption/Program.cs +++ b/examples/JsonEncryption/Program.cs @@ -82,6 +82,7 @@ static async Task Main(string[] args) AzureKmsDriver.Register(); GcpKmsDriver.Register(); HcVaultKmsDriver.Register(); + LocalKmsDriver.Register(); FieldEncryptionExecutor.Register(); string bootstrapServers = args[0]; @@ -135,6 +136,9 @@ static async Task Main(string[] args) UseLatestVersion = true, BufferBytes = 100 }; + // KMS properties can be passed as follows + // jsonSerializerConfig.Set("rules.secret.access.key", "xxx"); + // jsonSerializerConfig.Set("rules.access.key.id", "xxx"); RuleSet ruleSet = new RuleSet(new List(), new List diff --git a/examples/ProtobufEncryption/Program.cs b/examples/ProtobufEncryption/Program.cs index 99f589b01..e9c34df10 100644 --- a/examples/ProtobufEncryption/Program.cs +++ b/examples/ProtobufEncryption/Program.cs @@ -50,6 +50,7 @@ static async Task Main(string[] args) AzureKmsDriver.Register(); GcpKmsDriver.Register(); HcVaultKmsDriver.Register(); + LocalKmsDriver.Register(); FieldEncryptionExecutor.Register(); string bootstrapServers = args[0]; @@ -96,7 +97,10 @@ message User { // optional Avro serializer properties: BufferBytes = 100 }; - + // KMS properties can be passed as follows + // protobufSerializerConfig.Set("rules.secret.access.key", "xxx"); + // protobufSerializerConfig.Set("rules.access.key.id", "xxx"); + RuleSet ruleSet = new RuleSet(new List(), new List { diff --git a/src/Confluent.SchemaRegistry.Encryption/KmsRegistry.cs b/src/Confluent.SchemaRegistry.Encryption/KmsRegistry.cs index 127828b80..5bbf905ab 100644 --- a/src/Confluent.SchemaRegistry.Encryption/KmsRegistry.cs +++ b/src/Confluent.SchemaRegistry.Encryption/KmsRegistry.cs @@ -14,6 +14,7 @@ // // Refer to LICENSE for more information. +using System; using System.Collections.Generic; using System.Threading; @@ -61,7 +62,7 @@ public static IKmsDriver GetKmsDriver(string keyUrl) kmsDriversMutex.Release(); } - return null; + throw new ArgumentException("No KMS driver found for key URL: " + keyUrl); ; } public static void RegisterKmsClient(IKmsClient kmsClient) diff --git a/src/Confluent.SchemaRegistry/Rest/DataContracts/Schema.cs b/src/Confluent.SchemaRegistry/Rest/DataContracts/Schema.cs index a76514098..3b5746a70 100644 --- a/src/Confluent.SchemaRegistry/Rest/DataContracts/Schema.cs +++ b/src/Confluent.SchemaRegistry/Rest/DataContracts/Schema.cs @@ -30,21 +30,18 @@ public class Schema : IComparable, IEquatable #region API backwards-compatibility hack /// - /// DEPRECATED. The subject the schema is registered against. + /// The subject the schema is registered against. /// - [Obsolete("Included to maintain API backwards compatibility only. Use RegisteredSchema instead. This property will be removed in a future version of the library.")] public virtual string Subject { get; set; } /// - /// DEPRECATED. The schema version. + /// The schema version. /// - [Obsolete("Included to maintain API backwards compatibility only. Use RegisteredSchema instead. This property will be removed in a future version of the library.")] public virtual int Version { get; set; } /// - /// DEPRECATED. Unique identifier of the schema. + /// Unique identifier of the schema. /// - [Obsolete("Included to maintain API backwards compatibility only. Use RegisteredSchema instead. This property will be removed in a future version of the library.")] public virtual int Id { get; set; } ///