Skip to content

Commit

Permalink
Merge branch 'env_secret_support' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
infinityofspace committed Sep 25, 2024
2 parents 9ca95a5 + a1e8b43 commit 31cfc66
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
5 changes: 3 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ pkb-client -k <YOUR-API-KEY> -s <YOUR-API-SECRET> ping
```

If you don't want to specify the key and secret in the program call, because for example the command line calls are
logged and you don't want to log the API access, then you can also omit both arguments and *pkb-client* asks for a user
input.
logged and you don't want to log the API access, then you can also set the environment variables `PKB_API_KEY` and
`PKB_API_SECRET`. If you not specify API key and secret in any way, *pkb-client* asks for a user input. The command line
arguments of the API key and secret have the highest priority.

You can see an overview of all usable API methods via the help:

Expand Down
32 changes: 20 additions & 12 deletions pkb_client/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import dataclasses
import json
import os
import textwrap
from datetime import datetime

Expand Down Expand Up @@ -163,22 +164,29 @@ def main():
exit(0)

if args.key is None:
while True:
api_key = input("Please enter your API key you got from Porkbun (usually starts with \"pk\"): ")
if len(api_key) == 0:
print("The api key can not be empty.")
else:
break
# try to get the api key from the environment variable or fallback to user input
api_key = os.environ.get("PKB_API_KEY", "")
if len(api_key.strip()) == 0:
while True:
api_key = input("Please enter your API key you got from Porkbun (usually starts with \"pk\"): ")
if len(api_key.strip()) == 0:
print("The api key can not be empty.")
else:
break
else:
api_key = args.key

if args.secret is None:
while True:
api_secret = input("Please enter your API key secret you got from Porkbun (usually starts with \"sk\"): ")
if len(api_secret) == 0:
print("The api key secret can not be empty.")
else:
break
# try to get the api secret from the environment variable or fallback to user input
api_secret = os.environ.get("PKB_API_SECRET", "")
if len(api_secret.strip()) == 0:
while True:
api_secret = input(
"Please enter your API key secret you got from Porkbun (usually starts with \"sk\"): ")
if len(api_secret.strip()) == 0:
print("The api key secret can not be empty.")
else:
break
else:
api_secret = args.secret

Expand Down

0 comments on commit 31cfc66

Please sign in to comment.