createServiceAccount method
Implementation
Future<ServiceAccount> createServiceAccount(
String projectId,
String name, {
String? displayName,
String? description,
Map<String, dynamic>? metadata,
Map<String, String>? annotations,
}) async {
final encodedProjectId = Uri.encodeComponent(projectId);
final uri = Uri.parse('$baseUrl/accounts/projects/$encodedProjectId/service-accounts');
final body = <String, dynamic>{'name': name};
if (displayName != null) {
body['display_name'] = displayName;
}
if (description != null) {
body['description'] = description;
}
if (metadata != null) {
body['metadata'] = metadata;
}
if (annotations != null) {
body['annotations'] = annotations;
}
final response = await httpClient.post(uri, body: jsonEncode(body));
if (response.statusCode >= 400) {
throw MeshagentException(
'Failed to create service account. '
'Status code: ${response.statusCode}, body: ${response.body}',
);
}
return ServiceAccount.fromJson(jsonDecode(response.body) as Map<String, dynamic>);
}