at_client_sdk icon indicating copy to clipboard operation
at_client_sdk copied to clipboard

AtClient: Add useRemote (or similar option name) to atClient.getKeys/.getAtKeys

Open XavierChanth opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe.

SSH No Ports requires that we fetch the keys from remote (since we intentionally do not have a local store for ssh no ports), but there are no client options that support scanning directly from remote.

Right now the workaround is to manually build a scan verb:

Future<List<AtKey>> _getAtKeysRemote(
      {String? regex,
      String? sharedBy,
      String? sharedWith,
      bool showHiddenKeys = false}) async {
    var builder = ScanVerbBuilder()
      ..sharedWith = sharedWith
      ..sharedBy = sharedBy
      ..regex = regex
      ..showHiddenKeys = showHiddenKeys
      ..auth = true;
    var scanResult = await atClient.getRemoteSecondary()?.executeVerb(builder);
    scanResult = scanResult?.replaceFirst('data:', '') ?? '';
    var result = <AtKey?>[];
    if (scanResult.isNotEmpty) {
      result = List<String>.from(jsonDecode(scanResult)).map((key) {
        try {
          return AtKey.fromString(key);
        } on InvalidSyntaxException {
          logger.severe('$key is not a well-formed key');
        } on Exception catch (e) {
          logger.severe(
              'Exception occurred: ${e.toString()}. Unable to form key $key');
        }
      }).toList();
    }
    result.removeWhere((element) => element == null);
    return result.cast<AtKey>();
  }

Describe the solution you'd like

Add an options object which contains something similar to atClient.get's byPassCache option or atClient.put's useRemoteAtServer option.

Describe alternatives you've considered

No response

Additional context

No response

XavierChanth avatar Oct 31 '23 18:10 XavierChanth

Please note that this item is not urgent (probably only a p2 or p3), since the above workaround works perfectly fine for the time being. However it would be helpful to eventually add a feature like this, hence the ticket.

XavierChanth avatar Oct 31 '23 19:10 XavierChanth