fix: Support ssl (close #75)

This commit is contained in:
qianmoQ 2022-10-17 23:25:57 +08:00
parent aad5098616
commit 918b6f9e48
10 changed files with 78 additions and 4 deletions

View File

@ -78,6 +78,10 @@ public class SourceEntity
@Column(name = "create_time", columnDefinition = "datetime default CURRENT_TIMESTAMP()")
private Timestamp createTime;
// Add from 1.1.0.20221115
@Column(name = "_ssl", columnDefinition = "boolean default false")
private Boolean ssl;
@OneToMany(mappedBy = "plugin", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
@JsonIgnore
private List<PluginAuditEntity> pluginAudits;

View File

@ -55,6 +55,7 @@ public class ExecuteServiceImpl
_configure.setUsername(Optional.ofNullable(entity.getUsername()));
_configure.setPassword(Optional.ofNullable(entity.getPassword()));
_configure.setDatabase(Optional.ofNullable(entity.getDatabase()));
_configure.setSsl(Optional.ofNullable(entity.getSsl()));
_configure.setEnv(Optional.ofNullable(configure.getEnv()));
_configure.setFormat(configure.getFormat());
plugin.connect(_configure);

View File

@ -75,6 +75,7 @@ public class SourceServiceImpl
_configure.setPassword(Optional.ofNullable(configure.getPassword()));
_configure.setDatabase(Optional.ofNullable(configure.getDatabase()));
_configure.setEnv(Optional.empty());
_configure.setSsl(Optional.ofNullable(configure.getSsl()));
_configure.setFormat(FormatType.JSON);
plugin.connect(_configure);
io.edurt.datacap.spi.model.Response response = plugin.execute(plugin.validator());

View File

@ -0,0 +1,2 @@
ALTER TABLE `datacap`.`source`
ADD COLUMN `_ssl` boolean default false;

View File

@ -37,13 +37,21 @@ public class JdbcConnection
buffer.append("/");
buffer.append(this.jdbcConfigure.getDatabase().get());
}
if (this.jdbcConfigure.getSsl().isPresent()) {
buffer.append(String.format("?ssl=%s", this.jdbcConfigure.getSsl().get()));
}
if (this.jdbcConfigure.getEnv().isPresent()) {
Map<String, Object> env = this.jdbcConfigure.getEnv().get();
List<String> flatEnv = env.entrySet()
.stream()
.map(value -> String.format("%s=%s", value.getKey(), value.getValue()))
.collect(Collectors.toList());
buffer.append("?");
if (!this.jdbcConfigure.getSsl().isPresent()) {
buffer.append("?");
}
else {
buffer.append("&");
}
buffer.append(String.join("&", flatEnv));
}
return buffer.toString();

View File

@ -21,5 +21,6 @@ public class Configure
private Optional<String> password = Optional.empty();
private Optional<String> database = Optional.empty();
private Optional<Map<String, Object>> env = Optional.empty();
private Optional<Boolean> ssl = Optional.empty();
private FormatType format = FormatType.NONE;
}

View File

@ -0,0 +1,46 @@
package io.edurt.datacap.spi.connection;
import io.edurt.datacap.spi.model.Response;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public class JdbcConnectionTest
{
private JdbcConfigure jdbcConfigure;
private Response response;
@Before
public void before()
{
this.jdbcConfigure = new JdbcConfigure();
this.jdbcConfigure.setJdbcType("datacap");
this.jdbcConfigure.setJdbcDriver("io.edurt.datacap.DataCapDriver");
this.jdbcConfigure.setHost("127.0.0.1");
this.jdbcConfigure.setPort(9096);
this.response = new Response();
}
@Test
public void testFormatJdbcUrl()
{
Connection connection = new JdbcConnection(this.jdbcConfigure, this.response);
Assert.assertEquals(connection.formatJdbcUrl(), "jdbc:datacap://127.0.0.1:9096");
this.jdbcConfigure.setSsl(Optional.ofNullable(true));
connection = new JdbcConnection(this.jdbcConfigure, this.response);
Assert.assertEquals(connection.formatJdbcUrl(), "jdbc:datacap://127.0.0.1:9096?ssl=true");
Map<String, Object> env = new HashMap<>();
env.put("useUnicode", "true");
env.put("zeroDateTimeBehavior", "convertToNull");
this.jdbcConfigure.setEnv(Optional.ofNullable(env));
connection = new JdbcConnection(this.jdbcConfigure, this.response);
Assert.assertEquals(connection.formatJdbcUrl(), "jdbc:datacap://127.0.0.1:9096?ssl=true&useUnicode=true&zeroDateTimeBehavior=convertToNull");
}
}

View File

@ -12,4 +12,5 @@ export interface SourceModel
database: string;
type: string;
createTime?: number;
ssl?: boolean
}

View File

@ -21,12 +21,12 @@
<a-menu>
<a-menu-item>
<a target="_blank" href="https://github.com/EdurtIO/incubator-datacap/fork">
<img alt="GitHub forks" src="https://img.shields.io/github/forks/EdurtIO/incubator-datacap">
Forks <img alt="GitHub forks" src="https://img.shields.io/github/forks/EdurtIO/incubator-datacap?color=%20&label=%20&logo=%20&style=flat">
</a>
</a-menu-item>
<a-menu-item>
<a href="https://github.com/EdurtIO/incubator-datacap/stargazers">
<img alt="GitHub stars" src="https://img.shields.io/github/stars/EdurtIO/incubator-datacap">
Stars <img alt="GitHub forks" src="https://img.shields.io/github/stars/EdurtIO/incubator-datacap?color=%20&label=%20&logo=%20&style=flat">
</a>
</a-menu-item>
<a-menu-item>

View File

@ -99,6 +99,16 @@
<a-input v-model:value="formState.password"/>
</a-form-item>
</a-tab-pane>
<a-tab-pane :disabled="!formState.type" key="ssl">
<template #tab>
<span>
<safety-outlined/> SSL
</span>
</template>
<a-form-item :name="['ssl']" label="SSL">
<a-switch v-model:checked="formState.ssl"/>
</a-form-item>
</a-tab-pane>
<a-tab-pane :disabled="!formState.type" key="advanced">
<template #tab>
<span>
@ -176,7 +186,7 @@ export default defineComponent({
return {
title: '',
isUpdate: false,
formState: {},
formState: {} as SourceModel,
plugins: [],
testInfo: {} as TestInfo,
connectionLoading: false,