Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add alphanumeric check to app/api key config creation #781

Merged
merged 4 commits into from
Jul 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions datadog/dogshell/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,22 @@ def load(self, config_file, api_key, app_key, api_host):
response = get_input("%s does not exist. Would you like to" " create it? [Y/n] " % config_file)
if response.strip().lower() in ["", "y"]:
# Read the api and app keys from stdin
api_key = get_input(
"What is your api key? (Get it here: "
"https://app.datadoghq.com/account/settings#api) "
)
app_key = get_input(
"What is your application key? (Generate one here: "
"https://app.datadoghq.com/account/settings#api) "
)
while True:
api_key = get_input(
"What is your api key? (Get it here: "
"https://app.datadoghq.com/account/settings#api) "
)
if api_key.isalnum():
break
print("Datadog api keys can only contain alphanumeric characters.")
while True:
app_key = get_input(
"What is your app key? (Get it here: "
"https://app.datadoghq.com/account/settings#api) "
)
if app_key.isalnum():
break
print("Datadog app keys can only contain alphanumeric characters.")

# Write the config file
config.add_section("Connection")
Expand All @@ -98,7 +106,7 @@ def load(self, config_file, api_key, app_key, api_host):
# Abort
print_err("Exiting\n")
sys.exit(1)
except KeyboardInterrupt:
except (KeyboardInterrupt, EOFError):
# Abort
print_err("\nExiting")
sys.exit(1)
Expand Down