enrollAgent method
Enrolls an agent name in networkId, authenticated with an
owner/admin-class token (management JWT or owner/admin sessionToken —
a plain member sessionToken gets 403).
POST /api/networks/{id}/agents/enroll with body {name}; expects
201 only. There is no revoke/delete endpoint: to rotate (and thereby
revoke) an agent's secret, call enrollAgent again with the same
name — re-enrollment silently returns a fresh 201 enrollment and
the old secret dies. A 503 means the hub is offline (the error body
may carry hub_unavailable); invalid names (FanetAgentName.isValid)
get 400 with invalid_credentials.
Implementation
Future<FanetAgentEnrollment> enrollAgent(
String networkId, {
required String token,
required String name,
}) async {
final response = await _client.post(
_uri('/api/networks/${Uri.encodeComponent(networkId)}/agents/enroll'),
headers: {
'content-type': 'application/json',
'authorization': 'Bearer $token',
},
body: jsonEncode({'name': name}),
);
_expectStatus(response, const {201}, 'enrollAgent($name)');
return FanetAgentEnrollment.fromJson(_jsonObject(response));
}