Sample code and fixes for connecting to syngenta training data
This commit is contained in:
parent
4bd7e8d09b
commit
7dc03d7781
@ -0,0 +1,12 @@
|
||||
package com.knecon.fforesight.tenantusermanagement.dev;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
|
||||
@Configuration
|
||||
@Profile("dev")
|
||||
@EnableConfigurationProperties(DevTenantProperties.class)
|
||||
public class DevConfiguration {
|
||||
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
package com.knecon.fforesight.tenantusermanagement.dev;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@ConfigurationProperties("dev.tenant")
|
||||
public class DevTenantProperties {
|
||||
|
||||
private boolean recreateTenant = false;
|
||||
private DevDatabaseProperties db = new DevDatabaseProperties();
|
||||
private DevStorageProperties storage = new DevStorageProperties();
|
||||
|
||||
@Data
|
||||
public static class DevStorageProperties {
|
||||
|
||||
private DevStorageMode mode = DevStorageMode.S3;
|
||||
private DevS3StorageProperties s3 = new DevS3StorageProperties();
|
||||
private DevAzureStorageProperties azure = new DevAzureStorageProperties();
|
||||
|
||||
}
|
||||
|
||||
public enum DevStorageMode {
|
||||
S3,
|
||||
AZURE
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class DevS3StorageProperties {
|
||||
|
||||
private String key;
|
||||
private String secret;
|
||||
private String bucket;
|
||||
|
||||
private String endpoint;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class DevAzureStorageProperties {
|
||||
|
||||
private String containerName;
|
||||
private String connectionString;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class DevDatabaseProperties {
|
||||
|
||||
private int port;
|
||||
private String host;
|
||||
private String database;
|
||||
private String schema;
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -17,6 +17,7 @@ import org.springframework.jdbc.datasource.SingleConnectionDataSource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.knecon.fforesight.tenantcommons.model.AzureStorageConnection;
|
||||
import com.knecon.fforesight.tenantcommons.model.DatabaseConnection;
|
||||
import com.knecon.fforesight.tenantcommons.model.S3StorageConnection;
|
||||
import com.knecon.fforesight.tenantcommons.model.SearchConnection;
|
||||
@ -42,10 +43,15 @@ public class DevTestTenantService {
|
||||
@Value("${spring.datasource.url:}")
|
||||
private String masterJDBCURL;
|
||||
|
||||
private final DevTenantProperties devTenantProperties;
|
||||
|
||||
|
||||
@SneakyThrows
|
||||
public void createTestTenantIfNotExists(String tenantId, List<TenantUser> users) {
|
||||
|
||||
if (devTenantProperties.isRecreateTenant()) {
|
||||
tenantRepository.deleteByQuery(tenantId);
|
||||
}
|
||||
try {
|
||||
tenantManagementService.getTenant(tenantId);
|
||||
} catch (Exception e) {
|
||||
@ -75,12 +81,12 @@ public class DevTestTenantService {
|
||||
.defaultUsers(users != null ? users : new ArrayList<>())
|
||||
.databaseConnection(DatabaseConnection.builder()
|
||||
.driver("postgresql")
|
||||
.host("localhost")
|
||||
.port("15432")
|
||||
.database("red-tenant")
|
||||
.schema("public")
|
||||
.username("tenant")
|
||||
.password("r3dact3d")
|
||||
.host(devTenantProperties.getDb().getHost())
|
||||
.port(devTenantProperties.getDb().getPort() + "")
|
||||
.database(devTenantProperties.getDb().getDatabase())
|
||||
.schema(devTenantProperties.getDb().getSchema())
|
||||
.username(devTenantProperties.getDb().getUsername())
|
||||
.password(devTenantProperties.getDb().getPassword())
|
||||
.build())
|
||||
.searchConnection(SearchConnectionRequest.builder()
|
||||
.hosts(Set.of("localhost"))
|
||||
@ -88,13 +94,19 @@ public class DevTestTenantService {
|
||||
.scheme("http")
|
||||
.numberOfShards("1")
|
||||
.numberOfReplicas("5")
|
||||
.build())
|
||||
.s3StorageConnection(S3StorageConnection.builder().key("minioadmin").secret("minioadmin")
|
||||
.region("eu-central-1")
|
||||
.bucketName("redaction").endpoint("http://localhost:9000").build())
|
||||
.build();
|
||||
.build());
|
||||
|
||||
tenantManagementService.createTenant(tenantRequest);
|
||||
if (devTenantProperties.getStorage().getMode() == DevTenantProperties.DevStorageMode.S3) {
|
||||
tenantRequest.s3StorageConnection(S3StorageConnection.builder().key(devTenantProperties.getStorage().getS3().getKey())
|
||||
.secret(devTenantProperties.getStorage().getS3().getSecret())
|
||||
.region("eu-central-1")
|
||||
.bucketName(devTenantProperties.getStorage().getS3().getBucket()).endpoint(devTenantProperties.getStorage().getS3().getEndpoint()).build());
|
||||
} else {
|
||||
tenantRequest.azureStorageConnection(AzureStorageConnection.builder().connectionString(devTenantProperties.getStorage().getAzure().getConnectionString())
|
||||
.containerName(devTenantProperties.getStorage().getAzure().getContainerName()).build());
|
||||
}
|
||||
|
||||
tenantManagementService.createTenant(tenantRequest.build());
|
||||
|
||||
}
|
||||
|
||||
@ -139,5 +151,4 @@ public class DevTestTenantService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -21,3 +21,34 @@ spring:
|
||||
|
||||
cors.enabled: true
|
||||
|
||||
|
||||
|
||||
#dev.tenant.db:
|
||||
# port: 15432
|
||||
# host: localhost
|
||||
# database: red-tenant
|
||||
# schema: public
|
||||
# username: tenant
|
||||
# password: r3dact3d
|
||||
|
||||
dev.tenant.recreateTenant: true
|
||||
|
||||
dev.tenant.db:
|
||||
port: 5432
|
||||
host: syngenta-training-clone.postgres.database.azure.com
|
||||
database: syngenta-training-<YOUR_DB_COPY_NAME>
|
||||
schema: syngentatraining
|
||||
username: <YOUR_AZURE_USERNAME>
|
||||
password: <YOUR_AZURE_TOKEN>
|
||||
|
||||
dev.tenant.storage:
|
||||
mode: 'S3'
|
||||
s3:
|
||||
key: minioadmin
|
||||
secret: minioadmin
|
||||
bucket: redaction
|
||||
endpoint: http://localhost:9000
|
||||
# mode: 'AZURE'
|
||||
azure:
|
||||
containerName: syngenta-training-<YOUR_BLOB_COPY_NAME>
|
||||
connectionString: <AZURE_BLOB_CONNECTION_STRING_FROM_WIKI>
|
||||
|
||||
@ -11,3 +11,5 @@ databaseChangeLog:
|
||||
file: db/changelog/master/6-add-index-name-column.changelog.yaml
|
||||
- include:
|
||||
file: db/changelog/master/7-change-index-name-to-index-prefix.changelog.yaml
|
||||
- include:
|
||||
file: db/changelog/master/8-tenant-connection-data-string-length.changelog.yaml
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
databaseChangeLog:
|
||||
- changeSet:
|
||||
id: azure-connection-string-length
|
||||
author: timo
|
||||
changes:
|
||||
- modifyDataType:
|
||||
columnName: storage_azure_connection_string
|
||||
newDataType: VARCHAR(4000)
|
||||
tableName: tenant
|
||||
- modifyDataType:
|
||||
columnName: db_password
|
||||
newDataType: VARCHAR(4000)
|
||||
tableName: tenant
|
||||
Loading…
x
Reference in New Issue
Block a user