Skip to content

Commit

Permalink
data-push: POC server (#2368)
Browse files Browse the repository at this point in the history
  • Loading branch information
akphi authored Nov 16, 2023
1 parent 84c62a1 commit 0060453
Show file tree
Hide file tree
Showing 132 changed files with 4,108 additions and 2,041 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
166 changes: 166 additions & 0 deletions docs/connection/new-connection-framework.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,34 @@
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-authentication-connection-factory</artifactId>
<artifactId>legend-engine-xt-connection-factory</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-connection-protocol</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-relationalStore-connection</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-relationalStore-protocol</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-relationalStore-postgres-test-support</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-relationalStore-snowflake-protocol</artifactId>
<scope>test</scope>
</dependency>
<!-- ENGINE -->

<!-- RUNTIME -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,87 +17,90 @@
import org.finos.legend.authentication.vault.CredentialVault;
import org.finos.legend.authentication.vault.impl.EnvironmentCredentialVault;
import org.finos.legend.authentication.vault.impl.SystemPropertiesCredentialVault;
import org.finos.legend.connection.AuthenticationMechanismConfiguration;
import org.finos.legend.connection.AuthenticationMechanism;
import org.finos.legend.connection.Authenticator;
import org.finos.legend.connection.Connection;
import org.finos.legend.connection.ConnectionFactory;
import org.finos.legend.connection.DatabaseSupport;
import org.finos.legend.connection.DatabaseType;
import org.finos.legend.connection.IdentityFactory;
import org.finos.legend.connection.IdentitySpecification;
import org.finos.legend.connection.impl.InstrumentedStoreInstanceProvider;
import org.finos.legend.connection.LegendEnvironment;
import org.finos.legend.connection.RelationalDatabaseStoreSupport;
import org.finos.legend.connection.StoreInstance;
import org.finos.legend.connection.impl.EncryptedPrivateKeyPairAuthenticationConfiguration;
import org.finos.legend.connection.impl.CoreAuthenticationMechanismType;
import org.finos.legend.connection.impl.KerberosCredentialExtractor;
import org.finos.legend.connection.impl.KeyPairCredentialBuilder;
import org.finos.legend.connection.impl.RelationalDatabaseType;
import org.finos.legend.connection.impl.SnowflakeConnectionBuilder;
import org.finos.legend.connection.impl.UserPasswordAuthenticationConfiguration;
import org.finos.legend.connection.impl.UserPasswordCredentialBuilder;
import org.finos.legend.connection.impl.StaticJDBCConnectionBuilder;
import org.finos.legend.connection.protocol.AuthenticationConfiguration;
import org.finos.legend.connection.protocol.AuthenticationMechanismType;
import org.finos.legend.connection.impl.UserPasswordCredentialBuilder;
import org.finos.legend.engine.protocol.pure.v1.packageableElement.connection.AuthenticationConfiguration;
import org.finos.legend.engine.protocol.pure.v1.packageableElement.connection.ConnectionSpecification;
import org.finos.legend.engine.protocol.pure.v1.packageableElement.connection.EncryptedPrivateKeyPairAuthenticationConfiguration;
import org.finos.legend.engine.protocol.pure.v1.packageableElement.connection.UserPasswordAuthenticationConfiguration;
import org.finos.legend.engine.shared.core.identity.Identity;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public abstract class AbstractConnectionFactoryTest<T>
{
protected static final String TEST_STORE_INSTANCE_NAME = "test-store";

protected LegendEnvironment environment;
protected IdentityFactory identityFactory;
protected InstrumentedStoreInstanceProvider storeInstanceProvider;
protected ConnectionFactory connectionFactory;

@BeforeEach
public void initialize()
{
this.setup();

LegendEnvironment.Builder environmentBuilder = new LegendEnvironment.Builder()
.withVaults(
LegendEnvironment.Builder environmentBuilder = LegendEnvironment.builder()
.vaults(
new SystemPropertiesCredentialVault(),
new EnvironmentCredentialVault()
)
.withStoreSupports(
new RelationalDatabaseStoreSupport.Builder(DatabaseType.POSTGRES)
.withIdentifier("Postgres")
.withAuthenticationMechanismConfigurations(
new AuthenticationMechanismConfiguration.Builder(AuthenticationMechanismType.USER_PASSWORD).withAuthenticationConfigurationTypes(
UserPasswordAuthenticationConfiguration.class
).build()
.databaseSupports(
DatabaseSupport.builder()
.type(RelationalDatabaseType.POSTGRES)
.authenticationMechanisms(
AuthenticationMechanism.builder()
.type(CoreAuthenticationMechanismType.USER_PASSWORD)
.authenticationConfigurationTypes(
UserPasswordAuthenticationConfiguration.class
).build()
)
.build(),
new RelationalDatabaseStoreSupport.Builder(DatabaseType.SNOWFLAKE)
.withIdentifier("Snowflake")
.withAuthenticationMechanismConfigurations(
new AuthenticationMechanismConfiguration.Builder(AuthenticationMechanismType.KEY_PAIR).withAuthenticationConfigurationTypes(
EncryptedPrivateKeyPairAuthenticationConfiguration.class
).build()
DatabaseSupport.builder()
.type(RelationalDatabaseType.SNOWFLAKE)
.authenticationMechanisms(
AuthenticationMechanism.builder()
.type(CoreAuthenticationMechanismType.KEY_PAIR)
.authenticationConfigurationTypes(
EncryptedPrivateKeyPairAuthenticationConfiguration.class
).build()
)
.build()
);

CredentialVault credentialVault = this.getCredentialVault();
if (credentialVault != null)
{
environmentBuilder.withVault(credentialVault);
environmentBuilder.vault(credentialVault);
}

this.environment = environmentBuilder.build();

this.identityFactory = new IdentityFactory.Builder(this.environment)
this.identityFactory = IdentityFactory.builder()
.environment(this.environment)
.build();

this.storeInstanceProvider = new InstrumentedStoreInstanceProvider();
this.connectionFactory = new ConnectionFactory.Builder(this.environment, this.storeInstanceProvider)
.withCredentialBuilders(
this.connectionFactory = ConnectionFactory.builder()
.environment(this.environment)
.credentialBuilders(
new KerberosCredentialExtractor(),
new UserPasswordCredentialBuilder(),
new KeyPairCredentialBuilder()
)
.withConnectionBuilders(
.connectionBuilders(
new StaticJDBCConnectionBuilder.WithPlaintextUsernamePassword(),
new SnowflakeConnectionBuilder.WithKeyPair()
)
Expand All @@ -119,22 +122,32 @@ public CredentialVault getCredentialVault()
return null;
}

public abstract StoreInstance getStoreInstance();

public abstract Identity getIdentity();

public abstract DatabaseType getDatabaseType();

public abstract ConnectionSpecification getConnectionSpecification();

public abstract AuthenticationConfiguration getAuthenticationConfiguration();

public abstract void runTestWithConnection(T connection) throws Exception;

@Test
public void runTest() throws Exception
{
this.storeInstanceProvider.injectStoreInstance(this.getStoreInstance());
Identity identity = this.getIdentity();
DatabaseType databaseType = this.getDatabaseType();
ConnectionSpecification connectionSpecification = this.getConnectionSpecification();
AuthenticationConfiguration authenticationConfiguration = this.getAuthenticationConfiguration();

Authenticator authenticator = this.connectionFactory.getAuthenticator(identity, TEST_STORE_INSTANCE_NAME, authenticationConfiguration);
Connection databaseConnection = Connection.builder()
.databaseSupport(this.environment.getDatabaseSupport(databaseType))
.identifier("test::connection")
.connectionSpecification(connectionSpecification)
.authenticationConfiguration(authenticationConfiguration)
.build();

Authenticator authenticator = this.connectionFactory.getAuthenticator(identity, databaseConnection);
T connection = this.connectionFactory.getConnection(identity, authenticator);

this.runTestWithConnection(connection);
Expand All @@ -146,8 +159,8 @@ public void runTest() throws Exception
protected static Identity getAnonymousIdentity(IdentityFactory identityFactory)
{
return identityFactory.createIdentity(
new IdentitySpecification.Builder()
.withName("test-user")
IdentitySpecification.builder()
.name("test-user")
.build()
);
}
Expand Down
Loading

0 comments on commit 0060453

Please sign in to comment.