Unverified Commit 435b8690 authored by Dan Jones's avatar Dan Jones
Browse files

feat: return existing client if exists

+ add silent option to return parseable json response
+ add api arg to allow response to be used as-is
parent 266acc14
"""
Create a set of client credentials programmatically or return existing
if a client matching the id has already been configured.
Usage: client_create.py \
--id=soar-hydrogen \
--name="Hydrogen Interface" \
--sub="soar.#" \
--api="https://nucleus.noc.ac.uk/soar/api" \
[--silent]
"""
import argparse
import json
......@@ -24,20 +36,40 @@ parser.add_argument(
default="#",
help="A rabbitmq topic pattern for the client to subscribe to *=one-word-wildcard #=multi-word-wildcard",
)
parser.print_help()
parser.add_argument(
"--api",
type=str,
default="http://localhost:8087",
help="The root api endpoint",
)
parser.add_argument('--silent', action='store_true')
parser.set_defaults(silent=False)
args = parser.parse_args()
client_model = ClientModel()
if not args.silent:
parser.print_help()
client_model.add(
{
"client_id": args.id,
"client_name": args.name,
"subscription": args.sub,
}
)
client_model = ClientModel()
# Get existing client if already exists
client = client_model.find(args.id)
print("Here is your credentials file:")
if not client:
client = client_model.add(
{
"client_id": args.id,
"client_name": args.name,
"subscription": args.sub,
}
)
# Add the API endpoint to the credentials file
client['api'] = args.api
if not args.silent:
print("Here is your credentials file:")
print(json.dumps(client, indent=2))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment