fetchPasswords static method
Implementation
static Future<List<PasswordInfo>> fetchPasswords(
final Client cloudApiClient, {
required final String projectId,
}) async {
late List<String> userSecrets;
late List<String> managedSecrets;
try {
userSecrets = await cloudApiClient.secrets.list(projectId);
managedSecrets = await cloudApiClient.secrets.listManaged(projectId);
} on Exception catch (e, s) {
throw FailureException.nested(e, s, 'Failed to list passwords');
}
final passwordInfos = <String, PasswordInfo>{};
for (final managedSecret in managedSecrets) {
final passwordName = PasswordDefinitions.stripPrefix(managedSecret);
if (passwordName != null) {
final category = PasswordDefinitions.getCategory(passwordName);
final notes = PasswordDefinitions.getNotes(passwordName);
passwordInfos[passwordName] = PasswordInfo(
name: passwordName,
category: category,
notes: notes,
isPlatformManaged: true,
isUserSet: false,
);
}
}
for (final secret in userSecrets) {
final passwordName = PasswordDefinitions.stripPrefix(secret);
if (passwordName != null) {
final category = PasswordDefinitions.getCategory(passwordName);
final notes = PasswordDefinitions.getNotes(passwordName);
passwordInfos[passwordName] = PasswordInfo(
name: passwordName,
category: category,
notes: notes,
isPlatformManaged: managedSecrets.contains(secret),
isUserSet: true,
);
}
}
return passwordInfos.values.toList();
}