getCredentialedAccounts method

Future<List<String>> getCredentialedAccounts()

All credentialed accounts gcloud knows about (gcloud auth list --format=value(account)), in arbitrary order.

Returns an empty list when the command fails or when no accounts are credentialed. Used by the IAM gate to find a non-service-account principal that can be used to run add-iam-policy-binding calls without forcing the user to log in again.

Implementation

Future<List<String>> getCredentialedAccounts() async {
  final ProcessResult r = await _runner.run('gcloud', <String>[
    'auth',
    'list',
    '--format=value(account)',
  ]);
  if (!r.success) return const <String>[];
  return _stripAnsi(r.stdout)
      .split('\n')
      .map((String s) => s.trim())
      .where((String s) => s.isNotEmpty)
      .toList(growable: false);
}