Is valid connection string¶
Opens a connection with the string given and closes it : the check the Test Instance button of the instances page makes. Useful for an onboarding screen which lets a customer register their own database, or before writing a tenant row.
| Method | POST |
| URL | /api/system-api/admin/is-valid-connection-string : admin is the user path of your account |
| Body | { connectionString, instanceType, oracleDBUsername?, oracleDBPassword?, oracleDBPrivilege? } or an array of them |
| Answer | data : { success, data: true | false, error? }, or an array of them |
| From code | g.sys.system.isValidConnectionString |
The call¶
Body
{ "connectionString": "postgresql://crm:secret@db-1:5432/crm_acme", "instanceType": "POSTGRE_SQL_DB" }
Answer when the database refuses
{ "success": true, "statusCode": 200, "data": { "success": false, "data": false, "error": "password authentication failed for user \"crm\"" } }
| Key | Meaning |
|---|---|
connectionString |
The string, in the format of the database : see the connection strings pages. |
instanceType |
MONGO_DB, MYSQL_DB, MARIA_DB, SQL_SERVER_DB, POSTGRE_SQL_DB or ORACLE_DB. |
oracleDBUsername, oracleDBPassword, oracleDBPrivilege |
Oracle : the user, the password and the privilege, as on the instance form. |
- An array of bodies checks several strings in one call and answers an array in the same order.
From code¶
import "fmt"
cs := g.Req.Body().String("connectionString")
check, err := g.Sys.System.IsValidConnectionString(am.IsValidConnectionString{ConnectionString: cs, InstanceType: "POSTGRE_SQL_DB"})
if err != nil {
return nil, err
}
if !check.Success {
return nil, fmt.Errorf("This database can not be reached : %v", check.Error)
}
let cs = g.req.body()["connectionString"].as_str().unwrap_or_default().to_owned();
let check = g.sys.system.is_valid_connection_string(IsValidConnectionString::new(cs, "POSTGRE_SQL_DB"))?;
if !check.success {
return Err(am::fail(500, &format!("This database can not be reached : {}", check.error)));
}
Access, headers and errors¶
- Over HTTP, a system API answers only once its settings open it :
TOKEN_ACCESS(the token of an API user whose group grants this system API) orIS_PUBLIC. Without settings it isNO_ACCESS: only your code (g.sys) and the admin panel reach it. - The settings can also keep the answer in the cache, or ask for the token of a person (
authProviders). Pre and post hooks run around it, as around any API. - It takes the request headers and answers the envelope.
401: no valid token, or the API isNO_ACCESS.403: no group grants it.400: the body is wrong, and the message names the key.
Related : All APIs · System API settings · System APIs from code