setPasswords static method

Future<void> setPasswords(
  1. Client cloudApiClient, {
  2. required CommandLogger logger,
  3. required String projectId,
  4. required Map<String, String> passwords,
  5. bool suppressCommandMessages = false,
})

Implementation

static Future<void> setPasswords(
  final Client cloudApiClient, {
  required final CommandLogger logger,
  required final String projectId,
  required final Map<String, String> passwords,
  final bool suppressCommandMessages = false,
}) async {
  for (final MapEntry(key: name, value: value) in passwords.entries) {
    final validationError = PasswordDefinitions.isValidValue(name, value);
    if (validationError != null) {
      throw ErrorExitException('Password "$name": $validationError');
    }
  }

  final secrets = {
    for (final MapEntry(key: name, value: value) in passwords.entries)
      PasswordDefinitions.getFullSecretName(name): value,
  };

  try {
    await cloudApiClient.secrets.upsert(
      secrets: secrets,
      cloudCapsuleId: projectId,
    );
  } on Exception catch (e, s) {
    throw FailureException.nested(e, s, 'Failed to set passwords');
  }
}