checkNode method
Checks the supported versions of the SDN protocol and the supported
login types. Throws an exception if the server is not compatible with the
client and sets node to nodeUrl
if it is. Supports the
types Uri
and String
.
Implementation
Future<NodeSummary> checkNode(
Uri nodeUrl, {
bool checkWellKnown = true,
Set<String>? overrideSupportedVersions,
}) async {
final supportedVersions =
overrideSupportedVersions ?? Client.supportedVersions;
try {
node = nodeUrl.stripTrailingSlash();
// Look up well known
DiscoveryInformation? wellKnown;
if (checkWellKnown) {
try {
wellKnown = await getWellknown();
node = wellKnown.mNode.baseUrl.stripTrailingSlash();
} catch (e) {
Logs().v('Found no well known information', e);
}
}
// Check if server supports at least one supported version
final versions = await getVersions();
if (!versions.versions
.any((version) => supportedVersions.contains(version))) {
throw BadServerVersionsException(
versions.versions.toSet(),
supportedVersions,
);
}
final loginTypes = await getLoginFlows() ?? [];
if (!loginTypes.any((f) => supportedLoginTypes.contains(f.type))) {
throw BadServerLoginTypesException(
loginTypes.map((f) => f.type ?? '').toSet(), supportedLoginTypes);
}
print(
'NodeSummary wellKnown:${wellKnown?.mNode} ${wellKnown?.mIdentityServer}');
return NodeSummary(
discoveryInformation: wellKnown,
versions: versions,
loginFlows: loginTypes,
);
} catch (_) {
node = null;
rethrow;
}
}