@@ -6,13 +6,16 @@ const users = require("@arangodb/users");
66const router = createRouter ( ) ;
77const joi = require ( 'joi' ) ;
88
9+ const aisisInstances = "aisisInstances"
10+
911module . context . use ( router ) ;
1012
1113router . post ( '/createDB' , function ( req , res ) {
1214 const data = req . body ;
1315 const dbName = data . dbName ? data . dbName : randomStringGenerator ( ) ;
1416 const username = data . username ? data . username : randomStringGenerator ( ) ;
1517 const password = data . password ? data . password : randomStringGenerator ( ) ;
18+ const email = data . email ? data . email : 'noreply@arangodb.com'
1619
1720
1821// If user doesn't exist, create the user
@@ -29,12 +32,27 @@ router.post('/createDB', function (req,res) {
2932 res . send ( "Database already exists or invalid name supplied, please supply new dbName." ) . status ( 400 ) ;
3033 }
3134
35+
3236 users . save ( username , password , true ) ;
37+ // Grants user access only to newly created database
38+ users . grantDatabase ( username , dbName , 'rw' ) ;
39+
40+
41+
42+ // @TODO : obtain hostname and port of external deployment if necessary.
43+ // Returns hostname and port
3344 let hostname = req . hostname
3445 let port = req . port
3546
36- // Grants user access only to newly created database
37- users . grantDatabase ( username , dbName , 'rw' ) ;
47+ let insertDoc = query `INSERT {
48+ "dbName": ${ dbName } ,
49+ "username": ${ username } ,
50+ "hostname": ${ hostname } ,
51+ "port": ${ port } ,
52+ "email": ${ email } ,
53+ "timestamp": DATE_NOW()
54+ } INTO aisisInstances`
55+
3856 res . send ( { dbName, username, password, hostname, port} ) ;
3957 }
4058} )
0 commit comments