hawk9821 commented on code in PR #10361: URL: https://github.com/apache/seatunnel/pull/10361#discussion_r2740417970
########## seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/encrypt/FieldEncryptTransform.java: ########## @@ -0,0 +1,144 @@ +/* + * 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.seatunnel.transform.encrypt; + +import org.apache.seatunnel.shade.org.apache.commons.lang3.StringUtils; + +import org.apache.seatunnel.api.configuration.ReadonlyConfig; +import org.apache.seatunnel.api.table.catalog.CatalogTable; +import org.apache.seatunnel.api.table.catalog.Column; +import org.apache.seatunnel.api.table.catalog.TableIdentifier; +import org.apache.seatunnel.api.table.catalog.TableSchema; +import org.apache.seatunnel.api.table.type.BasicType; +import org.apache.seatunnel.api.table.type.SeaTunnelRow; +import org.apache.seatunnel.common.exception.CommonError; +import org.apache.seatunnel.transform.common.AbstractCatalogSupportMapTransform; + +import lombok.NonNull; + +import java.util.ArrayList; +import java.util.List; + +public class FieldEncryptTransform extends AbstractCatalogSupportMapTransform { + public static final String PLUGIN_NAME = "FieldEncrypt"; + + private static final String ENCRYPT = "ENCRYPT"; + private static final String DECRYPT = "DECRYPT"; + + private final List<String> fields = new ArrayList<>(); + private final String key; + private final EncryptAlgorithm encryptAlgorithm; + private final String mode; + + private transient volatile Encryptor encryptor; + private int[] encryptFieldIndexes; + + public FieldEncryptTransform( + @NonNull ReadonlyConfig config, @NonNull CatalogTable catalogTable) { + super(catalogTable); + + this.fields.addAll(config.get(FieldEncryptTransformConfig.FIELDS)); + this.key = config.get(FieldEncryptTransformConfig.KEY); + this.encryptAlgorithm = config.get(FieldEncryptTransformConfig.ALGORITHM); + this.mode = config.get(FieldEncryptTransformConfig.MODE); + + initializeFieldIndexes(); + } + + @Override + protected SeaTunnelRow transformRow(SeaTunnelRow inputRow) { + if (encryptor == null) { + switch (encryptAlgorithm) { Review Comment: Adopt the Strategy Pattern plus SPI injection: inject all encryptors in a unified way and match them with configurations for better scalability. Pseudocode: ``` List<Encryptor> encryptors = SPI injection; Encryptor encrypt = encryptors.stream().filter(encrypt -> encrypt.support(encryptAlgorithm)).findFirst(); encryptor.encrypt(value); ``` -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
