localTeams function

Future<List<String>> localTeams({
  1. ProcessRunner run = boundedRun,
})

The team ids of the Apple Development certificates in this Mac's keychain.

Implementation

Future<List<String>> localTeams({ProcessRunner run = boundedRun}) async {
  final ids = await run('security', ['find-identity', '-v', '-p', 'codesigning']);
  final names = RegExp(r'"(Apple Development: [^"]+)"').allMatches('${ids.stdout}').map((m) => m.group(1)!).toSet();
  final teams = <String>{};
  for (final name in names) {
    final pem =
        await run('sh', ['-c', 'security find-certificate -c "\$1" -p | openssl x509 -noout -subject', 'sh', name]);
    final team = RegExp(r'OU\s*=\s*([A-Z0-9]{10})').firstMatch('${pem.stdout}')?.group(1);
    if (team != null) teams.add(team);
  }
  return teams.toList()..sort();
}