// Factory constructors can't be async....
static Future<Credentials> fromPlatformStorage([String name = 'PVE']) async {
final origin = await getPlatformAwareOrigin();
- if (origin == null || origin.isEmpty)
+ if (origin == null || origin.isEmpty) {
throw ArgumentError('Could not determine origin');
+ }
final ticketEndpoint = Uri.parse('$origin/api2/json/access/ticket');
final ticket = await getTicketFromStorage();
- if (ticket == null || ticket.isEmpty)
+ if (ticket == null || ticket.isEmpty) {
throw ArgumentError('Ticket not found');
+ }
final matches = RegExp(r'(?:PVE|PMG|PMGQUAR):(?:(\S+):)?([A-Z0-9]{8})')
.firstMatch(ticket);
if (matches == null) throw FormatException('invalid cookie format');
final username = matches.group(1);
- if (username == null)
+ if (username == null) {
throw FormatException('No username - invalid cookie format');
+ }
final time = DateTime.fromMillisecondsSinceEpoch(
int.parse(matches.group(2), radix: 16) * 1000);
- if (time == null)
+ if (time == null) {
throw FormatException('No expiration time - invalid cookie format');
+ }
return Credentials(ticketEndpoint, username,
ticket: ticket, expiration: time);
Map<String, dynamic> get pending;
dynamic getPending(String field) {
- if (pending == null || pending.isEmpty)
+ if (pending == null || pending.isEmpty) {
throw StateError('No pending values available');
+ }
if (pending[field] != null && pending[field]['pending'] != null) {
return pending[field]['pending'];
}
Map<String, dynamic> get pending;
dynamic getPending(String field) {
- if (pending == null || pending.isEmpty)
+ if (pending == null || pending.isEmpty) {
throw StateError('No pending values available');
+ }
if (pending[field] != null && pending[field]['pending'] != null) {
return pending[field]['pending'];
}