Merge branch 'feature/datasource-form-config-apis' into 'release'

Add form config JSONs for individual plugins and an API for GETting them.

See merge request theappsmith/internal-tools-server!295
This commit is contained in:
Shrikant Kandula 2020-04-21 12:23:23 +00:00
commit 3dfc62034f
8 changed files with 459 additions and 2 deletions

View File

@ -0,0 +1,187 @@
{
"form": [
{
"sectionName": "General",
"children": [
{
"label": "Connection Mode",
"configProperty": "datasourceConfiguration.connection.mode",
"controlType": "DROP_DOWN",
"options": [
{
"label": "Read Only",
"value": "READ_ONLY"
},
{
"label": "Read / Write",
"value": "READ_WRITE"
}
]
}
]
},
{
"sectionName": "Connection",
"children": [
{
"label": "Connection Type",
"configProperty": "datasourceConfiguration.connection.type",
"controlType": "DROP_DOWN",
"options": [
{
"label": "Direct Connection",
"value": "DIRECT"
},
{
"label": "Replica set",
"value": "REPLICA_SET"
}
]
},
{
"sectionName": null,
"children": [
{
"label": "Host Address",
"configProperty": "datasourceConfiguration.endpoints[*].host",
"controlType": "KEYVALUE_ARRAY"
},
{
"label": "Port",
"configProperty": "datasourceConfiguration.endpoints[*].port",
"dataType": "NUMBER",
"controlType": "KEYVALUE_ARRAY"
}
]
},
{
"label": "Database Name",
"configProperty": "datasourceConfiguration.authentication.databaseName",
"controlType": "INPUT_TEXT"
},
{
"label": "Authentication Type",
"configProperty": "datasourceConfiguration.authentication.authType",
"controlType": "DROP_DOWN",
"options": [
{
"label": "SCRAM-SHA-1",
"value": "SCRAM_SHA_1"
},
{
"label": "SCRAM-SHA-256",
"value": "SCRAM_SHA_256"
},
{
"label": "MONGODB-CR",
"value": "MONGODB_CR"
}
]
},
{
"sectionName": null,
"children": [
{
"label": "Username",
"configProperty": "datasourceConfiguration.authentication.username",
"controlType": "INPUT_TEXT"
},
{
"label": "Password",
"configProperty": "datasourceConfiguration.authentication.password",
"dataType": "PASSWORD",
"controlType": "INPUT_TEXT"
}
]
}
]
},
{
"sectionName": "SSL (optional)",
"children": [
{
"label": "Authentication Mechanism",
"configProperty": "datasourceConfiguration.connection.ssl.authType",
"controlType": "DROP_DOWN",
"options": [
{
"label": "CA Certificate",
"value": "CA_CERTIFICATE"
},
{
"label": "Self Signed Certificate",
"value": "SELF_SIGNED_CERTIFICATE"
}
]
},
{
"label": "CA Certificate",
"configProperty": "datasourceConfiguration.connection.ssl.caCertificate",
"controlType": "FILE_PICKER"
},
{
"label": "PEM Certificate",
"configProperty": "datasourceConfiguration.connection.ssl.pemCertificate",
"controlType": "FILE_PICKER"
}
]
},
{
"sectionName": "SSH Tunnel (optional)",
"children": [
{
"label": "Enable SSH Tunneling",
"configProperty": "sshTunneling",
"controlType": "SWITCH"
},
{
"sectionName": null,
"children": [
{
"label": "SSH Address",
"configProperty": "datasourceConfiguration.sshProxy.host",
"controlType": "INPUT_TEXT"
},
{
"label": "Port",
"configProperty": "datasourceConfiguration.sshProxy.port",
"controlType": "INPUT_TEXT"
}
]
},
{
"label": "Username",
"configProperty": "datasourceConfiguration.sshProxy.username",
"controlType": "INPUT_TEXT"
},
{
"label": "Authentication Type",
"configProperty": "datasourceConfiguration.authenticationType",
"controlType": "DROP_DOWN",
"options": [
{
"label": "Password",
"value": "PASSWORD"
},
{
"label": "Identity File",
"value": "IDENTITY_FILE"
}
]
},
{
"label": "Password",
"configProperty": "datasourceConfiguration.ssh.tunnelPassword",
"dataType": "PASSWORD",
"controlType": "INPUT_TEXT"
},
{
"label": "Passphrase",
"configProperty": "datasourceConfiguration.ssh.tunnelPassphrase",
"dataType": "PASSWORD",
"controlType": "INPUT_TEXT"
}
]
}
]
}

View File

@ -0,0 +1,194 @@
{
"form": [
{
"sectionName": "General",
"id": 1,
"children": [
{
"label": "Connection Mode",
"configProperty": "datasourceConfiguration.connection.mode",
"controlType": "DROP_DOWN",
"isRequired": true,
"options": [
{
"label": "Read Only",
"value": "READ_ONLY"
},
{
"label": "Read / Write",
"value": "READ_WRITE"
}
]
}
]
},
{
"sectionName": "Connection",
"id": 2,
"children": [
{
"sectionName": null,
"children": [
{
"label": "Host Address",
"configProperty": "datasourceConfiguration.endpoints[*].host",
"controlType": "KEYVALUE_ARRAY"
},
{
"label": "Port",
"configProperty": "datasourceConfiguration.endpoints[*].port",
"dataType": "NUMBER",
"controlType": "KEYVALUE_ARRAY"
}
]
},
{
"label": "Database Name",
"configProperty": "datasourceConfiguration.authentication.databaseName",
"controlType": "INPUT_TEXT"
},
{
"sectionName": null,
"children": [
{
"label": "Username",
"configProperty": "datasourceConfiguration.authentication.username",
"controlType": "INPUT_TEXT"
},
{
"label": "Password",
"configProperty": "datasourceConfiguration.authentication.password",
"dataType": "PASSWORD",
"controlType": "INPUT_TEXT"
}
]
}
]
},
{
"id": 3,
"sectionName": "SSL (optional)",
"children": [
{
"label": "SSL Mode",
"configProperty": "datasourceConfiguration.connection.ssl.authType",
"controlType": "DROP_DOWN",
"options": [
{
"label": "Allow",
"value": "ALLOW"
},
{
"label": "Prefer",
"value": "PREFER"
},
{
"label": "Require",
"value": "REQUIRE"
},
{
"label": "Disable",
"value": "DISABLE"
},
{
"label": "Verify-CA",
"value": "VERIFY_CA"
},
{
"label": "Verify-Full",
"value": "VERIFY_FULL"
}
]
},
{
"sectionName": null,
"children": [
{
"label": "Key File",
"configProperty": "datasourceConfiguration.connection.ssl.keyFile",
"controlType": "FILE_PICKER"
},
{
"label": "Certificate",
"configProperty": "datasourceConfiguration.connection.ssl.certificateFile",
"controlType": "FILE_PICKER"
}
]
},
{
"sectionName": null,
"children": [
{
"label": "CA Certificate",
"configProperty": "datasourceConfiguration.connection.ssl.caCertificateFile",
"controlType": "FILE_PICKER"
},
{
"label": "PEM Certificate",
"configProperty": "datasourceConfiguration.connection.ssl.pemCertificate.file",
"controlType": "FILE_PICKER"
},
{
"label": "PEM Passphrase",
"configProperty": "datasourceConfiguration.connection.ssl.pemCertificate.password",
"dataType": "PASSWORD",
"controlType": "INPUT_TEXT"
}
]
}
]
},
{
"sectionName": "SSH (optional)",
"id": 4,
"children": [
{
"label": "Enable SSH",
"configProperty": "enableSSH",
"controlType": "SWITCH"
},
{
"sectionName": null,
"children": [
{
"label": "Tunnel Host",
"configProperty": "datasourceConfiguration.sshProxy.host",
"controlType": "INPUT_TEXT"
},
{
"label": "Tunnel Port",
"configProperty": "datasourceConfiguration.sshProxy.port",
"controlType": "INPUT_TEXT"
}
]
},
{
"label": "Username",
"configProperty": "datasourceConfiguration.sshProxy.username",
"controlType": "INPUT_TEXT"
},
{
"label": "Password",
"configProperty": "datasourceConfiguration.sshProxy.password",
"dataType": "PASSWORD",
"controlType": "INPUT_TEXT"
},
{
"label": "Authentication Type",
"configProperty": "datasourceConfiguration.sshProxy.authType",
"controlType": "DROP_DOWN",
"options": [
{
"label": "Password",
"value": "PASSWORD"
},
{
"label": "Identity File",
"value": "IDENTITY_FILE"
}
]
}
]
}
]
}

View File

@ -0,0 +1,15 @@
{
"form": [
{
"sectionName": "General",
"id": 1,
"children": [
{
"label": "Rapid Api Connection Name",
"configProperty": "connectionName",
"controlType": "INPUT_TEXT"
}
]
}
]
}

View File

@ -0,0 +1,15 @@
{
"form": [
{
"sectionName": "General",
"id": 1,
"children": [
{
"label": "Rapid Api Connection Name",
"configProperty": "connectionName",
"controlType": "INPUT_TEXT"
}
]
}
]
}

View File

@ -10,9 +10,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
@ -52,4 +52,10 @@ public class PluginController extends BaseController<PluginService, Plugin, Stri
return service.get(params).collectList()
.map(resources -> new ResponseDTO<>(HttpStatus.OK.value(), resources, null));
}
@GetMapping("/{pluginId}/form")
public Mono<ResponseDTO<Object>> getDatasourceForm(@PathVariable String pluginId) {
return service.getFormConfig(pluginId)
.map(form -> new ResponseDTO<>(HttpStatus.OK.value(), form, null));
}
}

View File

@ -40,7 +40,9 @@ public enum AppsmithError {
PLUGIN_INSTALLATION_FAILED_DOWNLOAD_ERROR(500, 5002, "Plugin installation failed due to an error while downloading it. Check the jar location & try again."),
PLUGIN_RUN_FAILED(500, 5003, "Plugin execution failed with error {0}"),
PLUGIN_EXECUTION_TIMEOUT(504, 5040, "Plugin Execution exceeded the maximum allowed time. Please increase the timeout in your action settings or check your backend action endpoint"),
MARKETPLACE_TIMEOUT(504, 5041, "Marketplace is responding too slowly. Please check the internet connection");
MARKETPLACE_TIMEOUT(504, 5041, "Marketplace is responding too slowly. Please check the internet connection"),
PLUGIN_LOAD_FORM_JSON_FAIL(500, 5004, "Unable to load datasource form configuration. Details: {0}."),
;
private Integer httpErrorCode;

View File

@ -7,6 +7,8 @@ import com.appsmith.server.dtos.PluginOrgDTO;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.io.InputStream;
public interface PluginService extends CrudService<Plugin, String> {
Flux<Plugin> getDefaultPlugins();
@ -22,4 +24,8 @@ public interface PluginService extends CrudService<Plugin, String> {
Mono<Plugin> findById(String id);
Plugin redisInstallPlugin(InstallPluginRedisDTO installPluginRedisDTO);
Mono<Object> getFormConfig(String pluginId);
Mono<InputStream> getPluginResource(String pluginId, String resourcePath);
}

View File

@ -33,10 +33,13 @@ import reactor.core.scheduler.Scheduler;
import javax.validation.Validator;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@ -278,4 +281,33 @@ public class PluginServiceImpl extends BaseService<PluginRepository, Plugin, Str
return Mono.just(plugin);
}
@Override
public Mono<Object> getFormConfig(String pluginId) {
return getPluginResource(pluginId, "form.json")
.flatMap(jsonStream -> {
try {
return Mono.just(new ObjectMapper().readValue(jsonStream, Map.class));
} catch (IOException e) {
return Mono.error(new AppsmithException(AppsmithError.PLUGIN_LOAD_FORM_JSON_FAIL, e.getMessage()));
}
});
}
@Override
public Mono<InputStream> getPluginResource(String pluginId, String resourcePath) {
return findById(pluginId)
.flatMap(plugin -> {
InputStream formResourceStream = pluginManager
.getPlugin(plugin.getPackageName())
.getPluginClassLoader()
.getResourceAsStream(resourcePath);
if (formResourceStream == null) {
return Mono.error(new AppsmithException(AppsmithError.PLUGIN_LOAD_FORM_JSON_FAIL, "Resource not found"));
}
return Mono.just(formResourceStream);
});
}
}