Skip to content

Commit

Permalink
add alphanumeric check to app/api key config creation (#781)
Browse files Browse the repository at this point in the history
* add alphanumeric check to app/api key config creation

* refactor api/app key reading and handle EOF from pipe
  • Loading branch information
nkzou authored Jul 12, 2023
1 parent 8ae1cf6 commit 9bcf517
Showing 1 changed file with 17 additions and 9 deletions.
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

0 comments on commit 9bcf517

Please sign in to comment.