aws-doc-sdk-examples
aws-doc-sdk-examples copied to clipboard
[Enhancement]: Support hiding password while input.
Background story
I use this tool to demo AWS services, but the password will be show to the audiences during the environment set up. I don't feel comfortable about it.
What does this example accomplish?
I want to hide the password while I'm typing it.
Which AWS service(s)?
RDS (and more)
Which AWS SDKs or tools?
- [ ] All languages
- [ ] .NET
- [ ] C++
- [ ] Go (v2)
- [ ] Java
- [ ] Java (v2)
- [ ] JavaScript
- [ ] JavaScript (v3)
- [ ] Kotlin
- [ ] PHP
- [X] Python
- [ ] Ruby
- [ ] Rust
- [ ] Swift
- [ ] Not applicable
Are there existing code examples to leverage?
No response
Do you have any reference code?
diff --git a/python/demo_tools/question.py b/python/demo_tools/question.py
index fca618a7f..0bda11de9 100644
--- a/python/demo_tools/question.py
+++ b/python/demo_tools/question.py
@@ -8,7 +8,7 @@ and converts input, and returns answers.
# snippet-start:[python.demo_tools.Question]
-def ask(question, *validators):
+def ask(question, *validators, **kwargs):
"""
Asks a single question and validates it against a list of validators.
When an answer fails validation, the complaint is printed and the question
@@ -18,9 +18,10 @@ def ask(question, *validators):
:param validators: The list of validators that the answer must pass.
:return: The answer, converted to its final form by the validators.
"""
+ import getpass
answer = None
while answer is None:
- answer = input(question)
+ answer = getpass.getpass(question) if kwargs.get('get_pass', False) else input(question)
for validator in validators:
answer, complaint = validator(answer)
if answer is None:
@@ -29,6 +30,11 @@ def ask(question, *validators):
return answer
+def get_pass(question, *validators):
+ kwargs = dict(get_pass=True)
+ return ask(question, *validators, **kwargs)
+
+
def choose(question, choices):
for index, choice in enumerate(choices):
print(f"{index+1}. {choice}")
diff --git a/python/example_code/rds/scenario_get_started_instances.py b/python/example_code/rds/scenario_get_started_instances.py
index e09cec0fb..497164af4 100644
--- a/python/example_code/rds/scenario_get_started_instances.py
+++ b/python/example_code/rds/scenario_get_started_instances.py
@@ -104,7 +104,7 @@ class RdsInstanceScenario:
if db_inst is None:
print("Let's create a DB instance.")
admin_username = q.ask("Enter an administrator user name for the database: ", q.non_empty)
- admin_password = q.ask(
+ admin_password = q.get_pass(
"Enter a password for the administrator (at least 8 characters): ", q.non_empty)
engine_versions = self.instance_wrapper.get_engine_versions(
db_engine, parameter_group['DBParameterGroupFamily'])
Marked stale by the Shirriff. Notifying @awsdocs/aws-sdk-docs-code-maintainers