diff --git a/app/server/appsmith-plugins/mongoPlugin/src/main/resources/form.json b/app/server/appsmith-plugins/mongoPlugin/src/main/resources/form.json new file mode 100644 index 0000000000..5aa0ac787b --- /dev/null +++ b/app/server/appsmith-plugins/mongoPlugin/src/main/resources/form.json @@ -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" + } + ] + } + ] +} diff --git a/app/server/appsmith-plugins/postgresPlugin/src/main/resources/form.json b/app/server/appsmith-plugins/postgresPlugin/src/main/resources/form.json new file mode 100644 index 0000000000..122a5b367c --- /dev/null +++ b/app/server/appsmith-plugins/postgresPlugin/src/main/resources/form.json @@ -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" + } + ] + } + ] + } + ] +} diff --git a/app/server/appsmith-plugins/rapidApiPlugin/src/main/resources/form.json b/app/server/appsmith-plugins/rapidApiPlugin/src/main/resources/form.json new file mode 100644 index 0000000000..4602da5aec --- /dev/null +++ b/app/server/appsmith-plugins/rapidApiPlugin/src/main/resources/form.json @@ -0,0 +1,15 @@ +{ + "form": [ + { + "sectionName": "General", + "id": 1, + "children": [ + { + "label": "Rapid Api Connection Name", + "configProperty": "connectionName", + "controlType": "INPUT_TEXT" + } + ] + } + ] +} diff --git a/app/server/appsmith-plugins/restApiPlugin/src/main/resources/form.json b/app/server/appsmith-plugins/restApiPlugin/src/main/resources/form.json new file mode 100644 index 0000000000..4602da5aec --- /dev/null +++ b/app/server/appsmith-plugins/restApiPlugin/src/main/resources/form.json @@ -0,0 +1,15 @@ +{ + "form": [ + { + "sectionName": "General", + "id": 1, + "children": [ + { + "label": "Rapid Api Connection Name", + "configProperty": "connectionName", + "controlType": "INPUT_TEXT" + } + ] + } + ] +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/PluginController.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/PluginController.java index 2284278bd2..79513f2000 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/PluginController.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/PluginController.java @@ -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 new ResponseDTO<>(HttpStatus.OK.value(), resources, null)); } + + @GetMapping("/{pluginId}/form") + public Mono> getDatasourceForm(@PathVariable String pluginId) { + return service.getFormConfig(pluginId) + .map(form -> new ResponseDTO<>(HttpStatus.OK.value(), form, null)); + } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java index 0992286be6..aaafba8aac 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java @@ -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; diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/PluginService.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/PluginService.java index 42bbf8f0e3..630fca324f 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/PluginService.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/PluginService.java @@ -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 { Flux getDefaultPlugins(); @@ -22,4 +24,8 @@ public interface PluginService extends CrudService { Mono findById(String id); Plugin redisInstallPlugin(InstallPluginRedisDTO installPluginRedisDTO); + + Mono getFormConfig(String pluginId); + + Mono getPluginResource(String pluginId, String resourcePath); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/PluginServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/PluginServiceImpl.java index 7c5e2a8c04..faca5ba8bb 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/PluginServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/PluginServiceImpl.java @@ -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 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 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); + }); + } }