From f00c679f515f51afcc08d37cc8015e1b385cdcea Mon Sep 17 00:00:00 2001 From: Mayur Singal <39544459+ulixius9@users.noreply.github.com> Date: Tue, 27 Feb 2024 16:56:17 +0530 Subject: [PATCH] MINOR: Fix Hive Metastore Password Encryption (#15329) --- .../converter/ClassConverterFactory.java | 1 + .../HiveConnectionClassConverter.java | 41 +++++++++++++++++++ .../converter/ClassConverterFactoryTest.java | 2 +- 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 openmetadata-service/src/main/java/org/openmetadata/service/secrets/converter/HiveConnectionClassConverter.java diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/secrets/converter/ClassConverterFactory.java b/openmetadata-service/src/main/java/org/openmetadata/service/secrets/converter/ClassConverterFactory.java index 0da02d5a894..5f59733c345 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/secrets/converter/ClassConverterFactory.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/secrets/converter/ClassConverterFactory.java @@ -47,6 +47,7 @@ public final class ClassConverterFactory { Map.entry(BigTableConnection.class, new BigTableConnectionClassConverter()), Map.entry(DatalakeConnection.class, new DatalakeConnectionClassConverter()), Map.entry(MysqlConnection.class, new MysqlConnectionClassConverter()), + Map.entry(HiveConnection.class, new HiveConnectionClassConverter()), Map.entry(TrinoConnection.class, new TrinoConnectionClassConverter()), Map.entry(PostgresConnection.class, new PostgresConnectionClassConverter()), Map.entry(DbtGCSConfig.class, new DbtGCSConfigClassConverter()), diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/secrets/converter/HiveConnectionClassConverter.java b/openmetadata-service/src/main/java/org/openmetadata/service/secrets/converter/HiveConnectionClassConverter.java new file mode 100644 index 00000000000..4eeec5d82cd --- /dev/null +++ b/openmetadata-service/src/main/java/org/openmetadata/service/secrets/converter/HiveConnectionClassConverter.java @@ -0,0 +1,41 @@ +/* + * Copyright 2021 Collate + * Licensed 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.openmetadata.service.secrets.converter; + +import java.util.List; +import org.openmetadata.schema.services.connections.database.HiveConnection; +import org.openmetadata.schema.services.connections.database.MysqlConnection; +import org.openmetadata.schema.services.connections.database.PostgresConnection; +import org.openmetadata.service.util.JsonUtils; + +/** Converter class to get an `DatalakeConnection` object. */ +public class HiveConnectionClassConverter extends ClassConverter { + + private static final List> CONFIG_SOURCE_CLASSES = + List.of(MysqlConnection.class, PostgresConnection.class); + + public HiveConnectionClassConverter() { + super(HiveConnection.class); + } + + @Override + public Object convert(Object object) { + HiveConnection hiveConnection = (HiveConnection) JsonUtils.convertValue(object, this.clazz); + + tryToConvert(hiveConnection.getMetastoreConnection(), CONFIG_SOURCE_CLASSES) + .ifPresent(hiveConnection::setMetastoreConnection); + + return hiveConnection; + } +} diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/secrets/converter/ClassConverterFactoryTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/secrets/converter/ClassConverterFactoryTest.java index fbdcdfa1efd..0e16b4a5fac 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/secrets/converter/ClassConverterFactoryTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/secrets/converter/ClassConverterFactoryTest.java @@ -58,6 +58,6 @@ public class ClassConverterFactoryTest { @Test void testClassConvertedMapIsNotModified() { - assertEquals(19, ClassConverterFactory.getConverterMap().size()); + assertEquals(20, ClassConverterFactory.getConverterMap().size()); } }