Skip to content

Instantly share code, notes, and snippets.

@klang
Created April 6, 2022 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klang/6399e8d6d9db3a3157066d64bbc0b38d to your computer and use it in GitHub Desktop.
Save klang/6399e8d6d9db3a3157066d64bbc0b38d to your computer and use it in GitHub Desktop.
Oracle has som annoying rules about passwords that don't seem to be followed by rds.Credentials.from_generated_secret(username="nexcom", exclude_characters="^ %+~`#&*()|[]{}:;,-<>?!'/\\\",="),
# Another way to fix this is to let SecretsManager handle it when creating/updating the DatabaseInstance
# The SecretsManager will produce a 30 character string and I’ll leave it as an exercise to the reader to calculate
# the probability of generating a string that does NOT include at least 3 of the character groups indicated above.
exclude_characters=string.printable
.replace(string.ascii_letters, "")
.replace(string.digits, "")
.replace(string.whitespace, " ")
.replace('#', "")
.replace("$", "")
.replace("_", "")
rds.DatabaseInstance(self, "Oracle",
engine=rds.DatabaseInstanceEngine.oracle_ ...
...
credentials=rds.Credentials.from_generated_secret(username="admin", exclude_characters=exclude_characters),
...
import string
import random
def random_oracle_password(length):
assert length > 14
""" Your Oracle Password must contain at least 15 characters and include 3 of the following:
- At least one uppercase letter
- At least one lowercase letter
- At least one digit
- At least 1 special character
- only the following special characters are allowed: # $ _
"""
characters = list(string.ascii_letters + string.digits + "#$_")
password = [
random.choice(string.ascii_uppercase),
random.choice(string.ascii_lowercase),
random.choice(string.digits),
random.choice("#$_")]
for i in range(length - 4):
password.append(random.choice(characters))
random.shuffle(password)
return "".join(password)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment