forked from apache/seatunnel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix HiveMetaStoreProxy#enableKerberos will return true if doesn't ena…
…ble kerberos
- Loading branch information
1 parent
576919b
commit c04a629
Showing
7 changed files
with
197 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...in/java/org/apache/seatunnel/connectors/seatunnel/hive/utils/HiveMetaStoreProxyUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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.connectors.seatunnel.hive.utils; | ||
|
||
import org.apache.seatunnel.shade.com.typesafe.config.Config; | ||
|
||
import org.apache.seatunnel.connectors.seatunnel.file.config.BaseSourceConfigOptions; | ||
|
||
import lombok.experimental.UtilityClass; | ||
|
||
@UtilityClass | ||
public class HiveMetaStoreProxyUtils { | ||
|
||
public boolean enableKerberos(Config config) { | ||
boolean kerberosPrincipalEmpty = | ||
config.hasPath(BaseSourceConfigOptions.KERBEROS_PRINCIPAL.key()); | ||
boolean kerberosKeytabPathEmpty = | ||
config.hasPath(BaseSourceConfigOptions.KERBEROS_KEYTAB_PATH.key()); | ||
if (kerberosKeytabPathEmpty && kerberosPrincipalEmpty) { | ||
return true; | ||
} | ||
if (!kerberosPrincipalEmpty && !kerberosKeytabPathEmpty) { | ||
return false; | ||
} | ||
if (kerberosPrincipalEmpty) { | ||
throw new IllegalArgumentException("Please set kerberosPrincipal"); | ||
} | ||
throw new IllegalArgumentException("Please set kerberosKeytabPath"); | ||
} | ||
|
||
public boolean enableRemoteUser(Config config) { | ||
return config.hasPath(BaseSourceConfigOptions.REMOTE_USER.key()); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...ava/org/apache/seatunnel/connectors/seatunnel/hive/utils/HiveMetaStoreProxyUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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.connectors.seatunnel.hive.utils; | ||
|
||
import org.apache.seatunnel.shade.com.typesafe.config.Config; | ||
import org.apache.seatunnel.shade.com.typesafe.config.ConfigFactory; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import lombok.SneakyThrows; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
import java.nio.file.Paths; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class HiveMetaStoreProxyUtilsTest { | ||
|
||
@Test | ||
void enableKerberos() { | ||
Config config = parseConfig("/hive_without_kerberos.conf"); | ||
assertFalse(HiveMetaStoreProxyUtils.enableKerberos(config)); | ||
assertFalse(HiveMetaStoreProxyUtils.enableRemoteUser(config)); | ||
|
||
config = parseConfig("/hive_with_kerberos.conf"); | ||
assertTrue(HiveMetaStoreProxyUtils.enableKerberos(config)); | ||
assertFalse(HiveMetaStoreProxyUtils.enableRemoteUser(config)); | ||
|
||
config = parseConfig("/hive_with_remoteuser.conf"); | ||
assertTrue(HiveMetaStoreProxyUtils.enableRemoteUser(config)); | ||
} | ||
|
||
@SneakyThrows | ||
private Config parseConfig(String configFile) { | ||
URL resource = HiveMetaStoreProxyUtilsTest.class.getResource(configFile); | ||
String filePath = Paths.get(resource.toURI()).toString(); | ||
return ConfigFactory.parseFile(new File(filePath)); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
seatunnel-connectors-v2/connector-hive/src/test/resources/hive_with_kerberos.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# | ||
# 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. | ||
# | ||
{ | ||
table_name="temp.group_brand_order_list_board" | ||
metastore_uri="thrift://localhost:9083" | ||
hdfs_site_path = "/etc/hadoop/conf/hdfs-site.xml" | ||
kerberos_principal = "hadoop" | ||
kerberos_keytab_path = "/home/hadoop/hadoop.keytab" | ||
} |
22 changes: 22 additions & 0 deletions
22
seatunnel-connectors-v2/connector-hive/src/test/resources/hive_with_remoteuser.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# | ||
# 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. | ||
# | ||
{ | ||
table_name="temp.group_brand_order_list_board" | ||
metastore_uri="thrift://localhost:9083" | ||
hdfs_site_path = "/etc/hadoop/conf/hdfs-site.xml" | ||
remote_user = "hadoop" | ||
} |
21 changes: 21 additions & 0 deletions
21
seatunnel-connectors-v2/connector-hive/src/test/resources/hive_without_kerberos.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# | ||
# 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. | ||
# | ||
{ | ||
table_name="temp.group_brand_order_list_board" | ||
metastore_uri="thrift://localhost:9083" | ||
hdfs_site_path = "/etc/hadoop/conf/hdfs-site.xml" | ||
} |