-
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.
Merge pull request #6 from trocco-io/feature/oauth-m2m
Implementation of oauth-m2m authentication
- Loading branch information
Showing
12 changed files
with
226 additions
and
15 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
rootProject.name = "embulk-input-databricks" | ||
include "shadow-databricks-jdbc" |
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,36 @@ | ||
apply plugin: "java" | ||
apply plugin: "com.github.johnrengelman.shadow" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
group = "io.trocco" | ||
version = "${rootProject.version}" | ||
description = "A helper library for embulk-input-databricks" | ||
|
||
sourceCompatibility = 1.8 | ||
targetCompatibility = 1.8 | ||
|
||
configurations { | ||
runtimeClasspath { | ||
resolutionStrategy.activateDependencyLocking() | ||
} | ||
shadow { | ||
resolutionStrategy.activateDependencyLocking() | ||
transitive = false | ||
} | ||
} | ||
|
||
dependencies { | ||
compile('com.databricks:databricks-jdbc:2.6.38') | ||
} | ||
|
||
shadowJar { | ||
// suppress the following undesirable log (https://stackoverflow.com/a/61475766/24393181) | ||
// | ||
// ERROR StatusLogger Unrecognized format specifier [d] | ||
// ERROR StatusLogger Unrecognized conversion specifier [d] starting at position 16 in conversion pattern. | ||
// ... | ||
exclude "**/Log4j2Plugins.dat" | ||
} |
4 changes: 4 additions & 0 deletions
4
shadow-databricks-jdbc/gradle/dependency-locks/runtimeClasspath.lockfile
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,4 @@ | ||
# This is a Gradle generated file for dependency locking. | ||
# Manual edits can break the build and are not advised. | ||
# This file is expected to be part of source control. | ||
com.databricks:databricks-jdbc:2.6.38 |
3 changes: 3 additions & 0 deletions
3
shadow-databricks-jdbc/gradle/dependency-locks/shadow.lockfile
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,3 @@ | ||
# This is a Gradle generated file for dependency locking. | ||
# Manual edits can break the build and are not advised. | ||
# This file is expected to be part of source control. |
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
102 changes: 102 additions & 0 deletions
102
src/test/java/org/embulk/input/databricks/TestDatabricksInputPluginAuthType.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,102 @@ | ||
package org.embulk.input.databricks; | ||
|
||
import static org.embulk.test.EmbulkTests.readFile; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.function.Function; | ||
import org.embulk.config.ConfigException; | ||
import org.embulk.config.ConfigSource; | ||
import org.embulk.exec.PartialExecutionException; | ||
import org.embulk.input.databricks.util.ConfigUtil; | ||
import org.embulk.input.databricks.util.ConnectionUtil; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class TestDatabricksInputPluginAuthType extends AbstractTestDatabricksInputPlugin { | ||
@Test | ||
public void testAuthTypeDefault() throws IOException { | ||
final ConfigUtil.TestTask t = ConfigUtil.createTestTask(); | ||
testRun((x) -> x.set("personal_access_token", t.getPersonalAccessToken())); | ||
} | ||
|
||
@Test | ||
public void testAuthTypePat() throws IOException { | ||
final ConfigUtil.TestTask t = ConfigUtil.createTestTask(); | ||
testRun( | ||
(x) -> x.set("auth_type", "pat").set("personal_access_token", t.getPersonalAccessToken())); | ||
} | ||
|
||
@Test | ||
public void testAtuTypePatWithoutPersonalAccessToken() { | ||
testConfigException((x) -> x.set("auth_type", "pat"), "personal_access_token"); | ||
} | ||
|
||
@Test | ||
public void testAuthTypeM2MOauth() throws IOException { | ||
final ConfigUtil.TestTask t = ConfigUtil.createTestTask(); | ||
testRun( | ||
(x) -> | ||
x.set("auth_type", "oauth-m2m") | ||
.set("oauth2_client_id", t.getOauth2ClientId()) | ||
.set("oauth2_client_secret", t.getOauth2ClientSecret())); | ||
} | ||
|
||
@Test | ||
public void testAuthTypeM2MOauthWithoutOauth2ClientId() { | ||
final ConfigUtil.TestTask t = ConfigUtil.createTestTask(); | ||
testConfigException( | ||
(x) -> | ||
x.set("auth_type", "oauth-m2m").set("oauth2_client_secret", t.getOauth2ClientSecret()), | ||
"oauth2_client_id"); | ||
} | ||
|
||
@Test | ||
public void testAuthTypeM2MOauthWithoutOauth2ClientSecret() { | ||
final ConfigUtil.TestTask t = ConfigUtil.createTestTask(); | ||
testConfigException( | ||
(x) -> x.set("auth_type", "oauth-m2m").set("oauth2_client_id", t.getOauth2ClientId()), | ||
"oauth2_client_secret"); | ||
} | ||
|
||
@Test | ||
public void testInvalidAuthType() { | ||
testConfigException((x) -> x.set("auth_type", "invalid"), "auth_type"); | ||
} | ||
|
||
private void testRun(Function<ConfigSource, ConfigSource> setConfigSource) throws IOException { | ||
final String quotedFullTableName = ConfigUtil.createRandomQuotedFullTableName(); | ||
ConnectionUtil.run( | ||
String.format("create table %s (_c0 LONG)", quotedFullTableName), | ||
String.format("INSERT INTO %s VALUES (1)", quotedFullTableName)); | ||
final ConfigUtil.TestTask t = ConfigUtil.createTestTask(); | ||
ConfigSource configSource = | ||
createMinimumConfigSource() | ||
.set("query", String.format("select * from %s", quotedFullTableName)); | ||
Path out = embulk.createTempFile("csv"); | ||
embulk.runInput(setConfigSource.apply(configSource), out); | ||
Assert.assertEquals("1\n", readFile(out)); | ||
} | ||
|
||
private void testConfigException( | ||
Function<ConfigSource, ConfigSource> setConfigSource, String containedMessage) { | ||
ConfigSource configSource = createMinimumConfigSource(); | ||
Path out = embulk.createTempFile("csv"); | ||
Exception e = | ||
Assert.assertThrows( | ||
PartialExecutionException.class, | ||
() -> embulk.runInput(setConfigSource.apply(configSource), out)); | ||
Assert.assertTrue(e.getCause() instanceof ConfigException); | ||
Assert.assertTrue( | ||
String.format("「%s」 does not contains '%s'", e.getMessage(), containedMessage), | ||
e.getMessage().contains(containedMessage)); | ||
} | ||
|
||
private ConfigSource createMinimumConfigSource() { | ||
final ConfigUtil.TestTask t = ConfigUtil.createTestTask(); | ||
return ConfigUtil.emptyConfigSource() | ||
.set("type", "databricks") | ||
.set("server_hostname", t.getServerHostname()) | ||
.set("http_path", t.getHTTPPath()); | ||
} | ||
} |
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