getRandomPassword method

Future<GetRandomPasswordResponse> getRandomPassword({
  1. String? excludeCharacters,
  2. bool? excludeLowercase,
  3. bool? excludeNumbers,
  4. bool? excludePunctuation,
  5. bool? excludeUppercase,
  6. bool? includeSpace,
  7. int? passwordLength,
  8. bool? requireEachIncludedType,
})

Generates a random password. We recommend that you specify the maximum length and include every character type that the system you are generating a password for can support. By default, Secrets Manager uses uppercase and lowercase letters, numbers, and the following characters in passwords: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~

Secrets Manager generates a CloudTrail log entry when you call this action.

Required permissions: secretsmanager:GetRandomPassword. For more information, see IAM policy actions for Secrets Manager and Authentication and access control in Secrets Manager.

May throw InternalServiceError. May throw InvalidParameterException. May throw InvalidRequestException.

Parameter excludeCharacters : A string of the characters that you don't want in the password.

Parameter excludeLowercase : Specifies whether to exclude lowercase letters from the password. If you don't include this switch, the password can contain lowercase letters.

Parameter excludeNumbers : Specifies whether to exclude numbers from the password. If you don't include this switch, the password can contain numbers.

Parameter excludePunctuation : Specifies whether to exclude the following punctuation characters from the password: ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~. If you don't include this switch, the password can contain punctuation.

Parameter excludeUppercase : Specifies whether to exclude uppercase letters from the password. If you don't include this switch, the password can contain uppercase letters.

Parameter includeSpace : Specifies whether to include the space character. If you include this switch, the password can contain space characters.

Parameter passwordLength : The length of the password. If you don't include this parameter, the default length is 32 characters.

Parameter requireEachIncludedType : Specifies whether to include at least one upper and lowercase letter, one number, and one punctuation. If you don't include this switch, the password contains at least one of every character type.

Implementation

Future<GetRandomPasswordResponse> getRandomPassword({
  String? excludeCharacters,
  bool? excludeLowercase,
  bool? excludeNumbers,
  bool? excludePunctuation,
  bool? excludeUppercase,
  bool? includeSpace,
  int? passwordLength,
  bool? requireEachIncludedType,
}) async {
  _s.validateNumRange(
    'passwordLength',
    passwordLength,
    1,
    4096,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'secretsmanager.GetRandomPassword'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      if (excludeCharacters != null) 'ExcludeCharacters': excludeCharacters,
      if (excludeLowercase != null) 'ExcludeLowercase': excludeLowercase,
      if (excludeNumbers != null) 'ExcludeNumbers': excludeNumbers,
      if (excludePunctuation != null)
        'ExcludePunctuation': excludePunctuation,
      if (excludeUppercase != null) 'ExcludeUppercase': excludeUppercase,
      if (includeSpace != null) 'IncludeSpace': includeSpace,
      if (passwordLength != null) 'PasswordLength': passwordLength,
      if (requireEachIncludedType != null)
        'RequireEachIncludedType': requireEachIncludedType,
    },
  );

  return GetRandomPasswordResponse.fromJson(jsonResponse.body);
}