johnclara commented on a change in pull request #1918:
URL: https://github.com/apache/iceberg/pull/1918#discussion_r541315424



##########
File path: 
crypto/src/main/java/org/apache/iceberg/encryption/dekprovider/AbstractKmsDekProvider.java
##########
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iceberg.encryption.dekprovider;
+
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicReference;
+import org.apache.iceberg.encryption.Dek;
+import org.apache.iceberg.encryption.KekId;
+import org.apache.iceberg.util.Tasks;
+import org.apache.iceberg.util.conf.Conf;
+
+public abstract class AbstractKmsDekProvider extends 
DekProvider<AbstractKmsDekProvider.KmsKekId> {
+  public static final String NAME = "kms";
+  public static final String KEK_ID = "kekId";
+
+  // Visible for testing
+  protected static final byte[] DUMMY_IV = new byte[0];
+
+  protected abstract KmsGenerateDekResponse getDekFromKms(KmsKekId kmsKekId, 
int numBytes);
+
+  protected abstract KmsDecryptResponse getPlaintextFromKms(KmsKekId kmsKekId, 
byte[] encryptedDek);
+
+  @Override
+  public KmsKekId loadKekId(Conf conf) {
+    String kekId = conf.propertyAsString(KEK_ID);
+    return KmsKekId.of(kekId);
+  }
+
+  @Override
+  public Dek getNewDek(KmsKekId kekId, int dekLength, int ivLength) {
+    AtomicReference<KmsGenerateDekResponse> kmsResponseHolder = new 
AtomicReference<>();
+
+    // Based on: BaseMetastoreTableOperations#refreshFromMetadataLocation
+    Tasks.foreach(0)
+        .retry(5000)
+        .exponentialBackoff(100, 5000, 600000, 4.0 /* 100, 400, 1600, ... */)
+        .throwFailureWhenFinished()
+        .run(i -> kmsResponseHolder.set(getDekFromKms(kekId, dekLength)));
+
+    KmsGenerateDekResponse kmsResponse = kmsResponseHolder.get();
+    return new Dek(kmsResponse.encryptedDek, kmsResponse.plaintextDek, 
DUMMY_IV);
+  }
+
+  @Override
+  public Dek getPlaintextDek(KmsKekId kekId, Dek dek) {
+    AtomicReference<KmsDecryptResponse> kmsResponseHolder = new 
AtomicReference<>();
+
+    // Based on: BaseMetastoreTableOperations#refreshFromMetadataLocation
+    Tasks.foreach(0)

Review comment:
       https://github.com/apache/iceberg/pull/1845 tried changing tasks here to 
get a result, but got scared about making a change here




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to