Skip to content

Commit 804b34f

Browse files
committed
fix CI job and default query for delete command
1 parent 72c505f commit 804b34f

2 files changed

Lines changed: 40 additions & 28 deletions

File tree

‎.github/workflows/main.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,16 @@ jobs:
9898
-- create
9999
nfctl \
100100
--verbose \
101+
--profile default \
101102
--network ${NETWORK_NAME}
102103
nfctl \
103104
--verbose \
105+
--profile default \
104106
--network ${NETWORK_NAME} \
105107
list services
106108
nfctl \
107109
--verbose \
110+
--profile default \
108111
--network ${NETWORK_NAME} \
109112
--yes \
110113
delete network

‎netfoundry/ctl.py‎

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ class StoreDictKeyPair(argparse.Action):
4949
def __call__(self, parser, namespace, values, option_string=None):
5050
"""Split comma-separated key=value pairs."""
5151
my_dict = {}
52-
for kv in values.split(","):
53-
k,v = kv.split("=")
54-
my_dict[k] = v
52+
if values is not None: # and len(values.split(',')) > 0:
53+
for kv in values.split(','):
54+
k,v = kv.split('=')
55+
my_dict[k] = v
5556
setattr(namespace, self.dest, my_dict)
5657

5758
class StoreListKeys(argparse.Action):
@@ -74,16 +75,18 @@ def main(cli):
7475
"""Configure the CLI to manage a network."""
7576
login(cli, api="organization")
7677

77-
@cli.argument('-e','--eval', help=argparse.SUPPRESS, arg_only=True, action="store_true", default=False)
78+
@cli.argument('-s','--shell', help=argparse.SUPPRESS, arg_only=True, action="store_true", default=False)
7879
@cli.argument('api', help=argparse.SUPPRESS, arg_only=True, nargs='?', default="organization", choices=['organization', 'ziti'])
7980
@cli.argument('-z','--ziti-cli', help=argparse.SUPPRESS)
8081
@cli.subcommand('login to a management API', hidden=True)
81-
def login(cli, api: str=None, eval: bool=False):
82+
def login(cli, api: str=None, shell: bool=None):
8283
"""Login to an API and cache the expiring token."""
8384
if api:
8485
cli.args.api = api
85-
if eval:
86-
cli.args.eval = eval
86+
if shell is not None:
87+
cli.args.shell = shell
88+
else:
89+
cli.args.shell = False
8790
# if logging in to a NF org (default)
8891
if cli.args.api == "organization":
8992
# first destroy any existing session with the same login profile name
@@ -119,7 +122,7 @@ def login(cli, api: str=None, eval: bool=False):
119122
if network:
120123
summary['network'] = network.describe
121124

122-
if not cli.args.eval and cli.config.general.output == "text":
125+
if not cli.args.shell and cli.config.general.output == "text":
123126
cli.echo(
124127
'{fg_lightgreen_ex}'
125128
+'Logged in as {fullname} ({email}) of {org_name} ({org_label}@{env}) until {expiry_timestamp} ({expiry_seconds}s)'.format(
@@ -152,17 +155,17 @@ def login(cli, api: str=None, eval: bool=False):
152155
)
153156
)
154157

155-
elif not cli.args.eval and cli.config.general.output == "yaml":
158+
elif not cli.args.shell and cli.config.general.output == "yaml":
156159
cli.echo(
157160
'{fg_lightgreen_ex}'
158161
+yaml_dumps(summary, indent=4)
159162
)
160-
elif not cli.args.eval and cli.config.general.output == "json":
163+
elif not cli.args.shell and cli.config.general.output == "json":
161164
cli.echo(
162165
'{fg_lightgreen_ex}'
163166
+json_dumps(summary, indent=4)
164167
)
165-
if cli.args.eval:
168+
if cli.args.shell:
166169
cli.echo(
167170
"""
168171
# source this output like
@@ -424,7 +427,7 @@ def list(cli):
424427
cli.echo(json_dumps(matches, indent=4))
425428

426429
@cli.argument('resource_type', arg_only=True, help='type of resource', choices=[singular(type) for type in RESOURCES.keys()])
427-
@cli.argument('query', arg_only=True, action=StoreDictKeyPair, help="query params as k=v,k=v comma-separated pairs")
430+
@cli.argument('query', arg_only=True, action=StoreDictKeyPair, nargs='?', help="query params as k=v,k=v comma-separated pairs", default=None)
428431
@cli.subcommand('delete a resource')
429432
def delete(cli):
430433
"""Delete a resource."""
@@ -437,20 +440,23 @@ def delete(cli):
437440
)
438441

439442
if cli.args.resource_type == "network":
440-
if cli.args.query is not {}:
443+
if not cli.args.query == {}:
441444
cli.log.warn("ignoring name='%s' because this operation applies to the entire network that is already selected", str(cli.args.query))
442-
if cli.args.yes or questions.yesno("confirm delete network '{name}'".format(name=network.name), default=False):
443-
spinner = cli.spinner(text='deleting {net}'.format(net=network.name), spinner='dots12')
444-
try:
445-
spinner.start()
446-
network.delete_network(progress=False)
447-
spinner.stop()
448-
except KeyboardInterrupt as e:
449-
cli.log.debug("wait cancelled by user")
450-
else:
451-
cli.echo("not deleting network '{name}'.".format(name=network.name))
445+
try:
446+
if cli.args.yes or questions.yesno("confirm delete network '{name}'".format(name=network.name), default=False):
447+
spinner = cli.spinner(text='deleting {net}'.format(net=network.name), spinner='dots12')
448+
try:
449+
spinner.start()
450+
network.delete_network(progress=False)
451+
spinner.stop()
452+
except KeyboardInterrupt as e:
453+
cli.log.debug("wait cancelled by user")
454+
else:
455+
cli.echo("not deleting network '{name}'.".format(name=network.name))
456+
except KeyboardInterrupt as e:
457+
cli.log.debug("input cancelled by user")
452458
else:
453-
if cli.args.query is {}:
459+
if not cli.args.query:
454460
cli.log.error("need query to select a resource")
455461
exit(1)
456462
matches = network.get_resources(type=cli.args.resource_type, **cli.args.query)
@@ -462,10 +468,13 @@ def delete(cli):
462468
exit(1)
463469
if len(matches) == 1:
464470
cli.log.debug("found one %s '%s'", cli.args.resource_type, str(cli.args.query))
465-
if cli.args.yes or questions.yesno("confirm delete {type} '{name}'".format(type=cli.args.resource_type, name=matches[0]['name']), default=False):
466-
network.delete_resource(type=cli.args.resource_type, id=matches[0]['id'])
467-
else:
468-
cli.echo("not deleting {type} '{name}'".format(type=cli.args.resource_type, name=matches[0]['name']))
471+
try:
472+
if cli.args.yes or questions.yesno("confirm delete {type} '{name}'".format(type=cli.args.resource_type, name=matches[0]['name']), default=False):
473+
network.delete_resource(type=cli.args.resource_type, id=matches[0]['id'])
474+
else:
475+
cli.echo("not deleting {type} '{name}'".format(type=cli.args.resource_type, name=matches[0]['name']))
476+
except KeyboardInterrupt as e:
477+
cli.log.debug("input cancelled by user")
469478

470479
def use_organization():
471480
"""Assume an identity in an organization."""

0 commit comments

Comments
 (0)