Skip to content

Commit

Permalink
connman: migration-strategy demo
Browse files Browse the repository at this point in the history
  • Loading branch information
akphi committed Nov 16, 2023
1 parent 0060453 commit 58eab23
Show file tree
Hide file tree
Showing 36 changed files with 676 additions and 225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.finos.legend.connection.DatabaseSupport;
import org.finos.legend.connection.LegendEnvironment;
import org.finos.legend.connection.impl.CoreAuthenticationMechanismType;
import org.finos.legend.connection.impl.HACKY__SnowflakeConnectionAdapter;
import org.finos.legend.connection.impl.KerberosCredentialExtractor;
import org.finos.legend.connection.impl.KeyPairCredentialBuilder;
import org.finos.legend.connection.impl.RelationalDatabaseType;
Expand Down Expand Up @@ -80,7 +79,6 @@
import org.finos.legend.engine.functionActivator.api.FunctionActivatorAPI;
import org.finos.legend.engine.generation.artifact.api.ArtifactGenerationExtensionApi;
import org.finos.legend.engine.language.hostedService.api.HostedServiceService;
import org.finos.legend.engine.protocol.hostedService.deployment.HostedServiceDeploymentConfiguration;
import org.finos.legend.engine.language.pure.compiler.api.Compile;
import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel;
import org.finos.legend.engine.language.pure.grammar.api.grammarToJson.GrammarToJson;
Expand All @@ -95,7 +93,6 @@
import org.finos.legend.engine.language.pure.modelManager.sdlc.SDLCLoader;
import org.finos.legend.engine.language.pure.relational.api.relationalElement.RelationalElementAPI;
import org.finos.legend.engine.language.snowflakeApp.api.SnowflakeAppService;
import org.finos.legend.engine.protocol.snowflakeApp.deployment.SnowflakeAppDeploymentConfiguration;
import org.finos.legend.engine.plan.execution.PlanExecutor;
import org.finos.legend.engine.plan.execution.api.ExecutePlanLegacy;
import org.finos.legend.engine.plan.execution.api.ExecutePlanStrategic;
Expand All @@ -120,10 +117,12 @@
import org.finos.legend.engine.plan.execution.stores.service.plugin.ServiceStoreExecutorBuilder;
import org.finos.legend.engine.plan.generation.extension.PlanGeneratorExtension;
import org.finos.legend.engine.protocol.bigqueryFunction.metamodel.BigQueryFunctionDeploymentConfiguration;
import org.finos.legend.engine.protocol.hostedService.deployment.HostedServiceDeploymentConfiguration;
import org.finos.legend.engine.protocol.pure.v1.PureProtocolObjectMapperFactory;
import org.finos.legend.engine.protocol.pure.v1.model.PureProtocol;
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.protocol.snowflakeApp.deployment.SnowflakeAppDeploymentConfiguration;
import org.finos.legend.engine.pure.code.core.PureCoreExtensionLoader;
import org.finos.legend.engine.query.graphQL.api.debug.GraphQLDebug;
import org.finos.legend.engine.query.graphQL.api.execute.GraphQLExecute;
Expand Down Expand Up @@ -291,9 +290,6 @@ public void run(T serverConfiguration, Environment environment)
relationalExecution.setFlowProviderConfiguration(new LegendDefaultDatabaseAuthenticationFlowProviderConfiguration());
}
relationalExecution.setConnectionFactory(this.setupConnectionFactory(serverConfiguration.vaults));
relationalExecution.setRelationalDatabaseConnectionAdapters(Lists.mutable.of(
new HACKY__SnowflakeConnectionAdapter.WithKeyPair()
));

relationalStoreExecutor = (RelationalStoreExecutor) Relational.build(serverConfiguration.relationalexecution);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.util.Collections;
import java.util.List;
import java.util.Map;

public interface ConnectionExtension
{
Expand All @@ -28,4 +29,9 @@ default List<AuthenticationMechanismType> getExtraAuthenticationMechanismTypes()
{
return Collections.emptyList();
}

default Map<String, DatabaseType> getExtraDatabaseTypeMapping()
{
return Collections.emptyMap();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,18 @@ protected LegendEnvironment(List<CredentialVault> vaults, List<DatabaseSupport>
// load database types
List<DatabaseType> databaseTypes = connectionExtensions.flatCollect(ConnectionExtension::getExtraDatabaseTypes);
Map<String, DatabaseType> databaseTypesIndex = new LinkedHashMap<>();
Map<String, DatabaseType> mappedDatabaseTypesIndex = new LinkedHashMap<>();
connectionExtensions.forEach(extension -> mappedDatabaseTypesIndex.putAll(extension.getExtraDatabaseTypeMapping()));
databaseTypes.forEach(databaseType ->
{
if (databaseTypesIndex.containsKey(databaseType.getIdentifier()))
{
throw new RuntimeException(String.format("Found multiple authentication mechanisms with label '%s'", databaseType.getIdentifier()));
throw new RuntimeException(String.format("Found multiple database types with label '%s'", databaseType.getIdentifier()));
}
databaseTypesIndex.put(databaseType.getIdentifier(), databaseType);
});
this.databaseTypesIndex = Maps.immutable.withAll(databaseTypesIndex);
mappedDatabaseTypesIndex.putAll(databaseTypesIndex);
this.databaseTypesIndex = Maps.immutable.withAll(mappedDatabaseTypesIndex);

// load authentication configuration types
Map<String, Class<? extends AuthenticationConfiguration>> authenticationConfigurationTypesIndex = new LinkedHashMap<>();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
package org.finos.legend.connection.impl;

import org.eclipse.collections.api.factory.Lists;
import org.finos.legend.connection.AuthenticationMechanismType;
import org.eclipse.collections.api.factory.Maps;
import org.finos.legend.connection.ConnectionExtension;
import org.finos.legend.connection.DatabaseType;

import java.util.List;
import java.util.Map;

public class RelationalConnectionExtension implements ConnectionExtension
{
Expand All @@ -28,4 +29,15 @@ public List<DatabaseType> getExtraDatabaseTypes()
{
return Lists.mutable.of(RelationalDatabaseType.values());
}

@Override
public Map<String, DatabaseType> getExtraDatabaseTypeMapping()
{
return Maps.mutable.with(
org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseType.H2.name(), RelationalDatabaseType.H2,
org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseType.Snowflake.name(), RelationalDatabaseType.SNOWFLAKE,
org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseType.Postgres.name(), RelationalDatabaseType.POSTGRES,
org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseType.BigQuery.name(), RelationalDatabaseType.BIG_QUERY
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2023 Goldman Sachs
//
// 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.finos.legend.connection.impl;

import org.finos.legend.engine.protocol.pure.v1.connection.SnowflakeConnectionSpecification;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.authentication.vault.PropertiesFileSecret;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseType;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnectionProtocolConverter;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.authentication.AuthenticationConfigurationWrapper;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.authentication.SnowflakePublicAuthenticationStrategy;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.specification.ConnectionSpecificationWrapper;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.specification.SnowflakeDatasourceSpecification;
import org.finos.legend.engine.protocol.pure.v1.packageableElement.connection.EncryptedPrivateKeyPairAuthenticationConfiguration;

public class SnowflakeRelationalDatabaseConnectionProtocolConverter
{
public static class ForSnowflakeWithKeyPairFlow extends RelationalDatabaseConnectionProtocolConverter<SnowflakeDatasourceSpecification, SnowflakePublicAuthenticationStrategy>
{
@Override
protected DatabaseType getDatabaseType()
{
return DatabaseType.Snowflake;
}

@Override
protected RelationalDatabaseConnection convert(SnowflakeDatasourceSpecification datasourceSpecification, SnowflakePublicAuthenticationStrategy authenticationStrategy, RelationalDatabaseConnection relationalDatabaseConnection)
{
SnowflakeConnectionSpecification connectionSpecification = new SnowflakeConnectionSpecification();
connectionSpecification.accountName = datasourceSpecification.accountName;
connectionSpecification.region = datasourceSpecification.region;
connectionSpecification.warehouseName = datasourceSpecification.warehouseName;
connectionSpecification.databaseName = datasourceSpecification.databaseName;
connectionSpecification.cloudType = datasourceSpecification.cloudType;
connectionSpecification.quotedIdentifiersIgnoreCase = datasourceSpecification.quotedIdentifiersIgnoreCase;
connectionSpecification.enableQueryTags = datasourceSpecification.enableQueryTags;
connectionSpecification.proxyHost = datasourceSpecification.proxyHost;
connectionSpecification.proxyPort = datasourceSpecification.proxyPort;
connectionSpecification.nonProxyHosts = datasourceSpecification.nonProxyHosts;
connectionSpecification.organization = datasourceSpecification.organization;
connectionSpecification.accountType = datasourceSpecification.accountType;
connectionSpecification.role = datasourceSpecification.role;
ConnectionSpecificationWrapper connectionSpecificationWrapper = new ConnectionSpecificationWrapper();
connectionSpecificationWrapper.value = connectionSpecification;
relationalDatabaseConnection.datasourceSpecification = connectionSpecificationWrapper;

EncryptedPrivateKeyPairAuthenticationConfiguration authenticationConfiguration = new EncryptedPrivateKeyPairAuthenticationConfiguration();
authenticationConfiguration.userName = authenticationStrategy.publicUserName;
authenticationConfiguration.privateKey = new PropertiesFileSecret(authenticationStrategy.privateKeyVaultReference);
authenticationConfiguration.passphrase = new PropertiesFileSecret(authenticationStrategy.passPhraseVaultReference);
AuthenticationConfigurationWrapper authenticationConfigurationWrapper = new AuthenticationConfigurationWrapper();
authenticationConfigurationWrapper.value = authenticationConfiguration;
relationalDatabaseConnection.authenticationStrategy = authenticationConfigurationWrapper;

return relationalDatabaseConnection;
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.finos.legend.connection.impl.SnowflakeRelationalDatabaseConnectionProtocolConverter$ForSnowflakeWithKeyPairFlow
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,7 @@
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-relationalStore-connection</artifactId>
<exclusions>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
<artifactId>legend-engine-xt-connection-protocol</artifactId>
</dependency>
<!-- ENGINE -->

Expand Down
Loading

0 comments on commit 58eab23

Please sign in to comment.