connect method
Future<bool>
connect(
- dynamic db_name,
- dynamic username,
- dynamic password, {
- bool useBasic = true,
Connect to the db
Implementation
Future<bool> connect(db_name, username, password,
{bool useBasic = true}) async {
this.db_name = db_name;
if (useBasic) {
auth = 'Basic ' + base64Encode(utf8.encode('$username:$password'));
} else {
var response = await post(Uri.parse(url + '/_open/auth'),
body: {'username': '$username', 'password': '$password'});
print(response.body);
auth = 'bearer ' + jsonDecode(response.body)['jwt'];
// TODO: JWT will expire after one hour by default
}
uri = Uri.parse(url + '/_db/' + this.db_name);
client = ArangoClient(auth, uri);
var current = await this.current();
if (current != null && !current['error']) {
state = ConnectionState.connected;
path = current['result']['path'];
isSystem = current['result']['isSystem'];
id = current['result']['id'];
return true;
} else {
throw ClientException('No connection', uri);
}
}