]> git.proxmox.com Git - flutter/proxmox_dart_api_client.git/commitdiff
fix wrong null check
authorTim Marx <t.marx@proxmox.com>
Fri, 17 Apr 2020 10:53:46 +0000 (12:53 +0200)
committerTim Marx <t.marx@proxmox.com>
Fri, 17 Apr 2020 10:53:46 +0000 (12:53 +0200)
Signed-off-by: Tim Marx <t.marx@proxmox.com>
lib/src/credentials.dart

index 989320cd63c7e8f6c1f7f94093d2ae066271c10b..6d48f6fca0ed8f3e638e21355a06931fd0b12672 100644 (file)
@@ -28,25 +28,31 @@ class Credentials {
 
   // Factory constructors can't be async....
   static Future<Credentials> fromPlatformStorage([String name = 'PVE']) async {
-
     final origin = await getPlatformAwareOrigin();
-    if (origin != null || origin.isEmpty) throw ArgumentError('Could not determine origin');
+    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) throw ArgumentError('Ticket not found');
+    if (ticket == null || ticket.isEmpty)
+      throw ArgumentError('Ticket not found');
 
-    final matches = RegExp(r"(?:PVE|PMG|PMGQUAR):(?:(\S+):)?([A-Z0-9]{8})").firstMatch(ticket);
+    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) throw FormatException('No username - invalid cookie format');
+    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) throw FormatException('No expiration time - invalid cookie format');
+    final time = DateTime.fromMillisecondsSinceEpoch(
+        int.parse(matches.group(2), radix: 16) * 1000);
+    if (time == null)
+      throw FormatException('No expiration time - invalid cookie format');
 
-    return Credentials(ticketEndpoint, username, ticket: ticket, expiration: time);
+    return Credentials(ticketEndpoint, username,
+        ticket: ticket, expiration: time);
   }
 
   Future<Credentials> refresh({http.Client httpClient}) async {
@@ -68,8 +74,8 @@ class Credentials {
     var body = {'username': username, 'password': ticket};
 
     var response = await httpClient.post(ticketEndpoint, body: body);
-    var credentials = await handleAccessTicketResponse(
-        response, username, ticketEndpoint);
+    var credentials =
+        await handleAccessTicketResponse(response, username, ticketEndpoint);
 
     return credentials;
   }