Skip to content

Commit

Permalink
Added support for specifying that an actor ID is actually an alias wh…
Browse files Browse the repository at this point in the history
…en using the 'actors aliases *' commands.
  • Loading branch information
mwvaughn committed Sep 29, 2021
1 parent 20993d0 commit ba7f409
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 12 deletions.
20 changes: 18 additions & 2 deletions tapis_cli/commands/taccapis/v2/actors/nonces_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class ActorsNoncesCreate(ActorsFormatOne, ActorIdentifier):

HELP_STRING = 'Create a Nonce for the specified Actor'
HELP_STRING = 'Create a Nonce for the specified Actor (or Alias)'
LEGACY_COMMMAND_STRING = None

VERBOSITY = Verbosity.BRIEF
Expand All @@ -36,13 +36,29 @@ def get_parser(self, prog_name):
help=
'Optional Max number of times Nonce can be redeemed (default: -1)',
)
parser.add_argument(
'-A',
dest='is_alias',
action='store_true',
help='Identifier is an ALIAS rather than an ACTOR_ID')

return parser

def take_action(self, parsed_args):
parsed_args = self.preprocess_args(parsed_args)
actor_id = ActorIdentifier.get_identifier(self, parsed_args)
body = {'level': parsed_args.level, 'maxUses': parsed_args.max_uses}
rec = self.tapis_client.actors.addNonce(actorId=actor_id, body=body)

# Use the requests_client because AgavePy is not configured
# with the alias-specific nonces endpoint
if parsed_args.is_alias:
api_path = 'aliases/' + actor_id + '/nonces'
self.requests_client.setup(API_NAME, SERVICE_VERSION, api_path)
rec = self.requests_client.post(data=body)
else:
rec = self.tapis_client.actors.addNonce(actorId=actor_id,
body=body)

headers = self.render_headers(Nonce, parsed_args)
data = []
for key in headers:
Expand Down
29 changes: 24 additions & 5 deletions tapis_cli/commands/taccapis/v2/actors/nonces_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class ActorsNoncesDelete(ActorsFormatOne, ActorIdentifier, NonceIdentifier):

HELP_STRING = 'Delete a Nonce'
HELP_STRING = 'Delete a Nonce from an Actor (or Alias)'
LEGACY_COMMMAND_STRING = None

VERBOSITY = Verbosity.RECORD
Expand All @@ -19,23 +19,42 @@ def get_parser(self, prog_name):
parser = super(ActorsNoncesDelete, self).get_parser(prog_name)
parser = ActorIdentifier().extend_parser(parser)
parser = NonceIdentifier().extend_parser(parser)
parser.add_argument(
'-A',
dest='is_alias',
action='store_true',
help='Identifier is an ALIAS rather than an ACTOR_ID')
return parser

def take_action(self, parsed_args):
parsed_args = self.preprocess_args(parsed_args)
actor_id = ActorIdentifier().get_identifier(self, parsed_args)
nonce_id = NonceIdentifier().get_identifier(self, parsed_args)
actor_id = ActorIdentifier().get_identifier(parsed_args)
nonce_id = NonceIdentifier().get_identifier(parsed_args)

headers = ['deleted', 'messages']
deleted = []
messages = []

try:
self.tapis_client.actors.deleteNonce(actorId=actor_id,
nonceId=nonce_id)
# Use the requests_client because AgavePy is not configured
# with the alias-specific nonces endpoint
if parsed_args.is_alias:
api_path = 'aliases/' + actor_id + '/nonces/' + nonce_id
self.requests_client.setup(API_NAME, SERVICE_VERSION, api_path)
rec = self.requests_client.delete()
else:
rec = self.tapis_client.actors.deleteNonce(actorId=actor_id,
nonceId=nonce_id)
deleted.append(nonce_id)
except Exception as err:
messages.append(str(err))

# # try:
# # self.tapis_client.actors.deleteNonce(actorId=actor_id,
# # nonceId=nonce_id)
# # deleted.append(nonce_id)
# # except Exception as err:
# # messages.append(str(err))
data = [deleted, messages]

return (tuple(headers), tuple(data))
17 changes: 15 additions & 2 deletions tapis_cli/commands/taccapis/v2/actors/nonces_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class ActorsNoncesList(ActorsFormatManyUnlimited, ActorIdentifier,
GlobListFilter):

HELP_STRING = 'List Nonces for the specified Actor'
HELP_STRING = 'List Nonces for the specified Actor (or Alias)'
LEGACY_COMMMAND_STRING = None

VERBOSITY = Verbosity.BRIEF
Expand All @@ -25,12 +25,25 @@ def get_parser(self, prog_name):
parser = super(ActorsNoncesList, self).get_parser(prog_name)
parser = ActorIdentifier().extend_parser(parser)
parser = GlobListFilter.extend_parser(self, parser)
parser.add_argument(
'-A',
dest='is_alias',
action='store_true',
help='Identifier is an ALIAS rather than an ACTOR_ID')
return parser

def take_action(self, parsed_args):
parsed_args = self.preprocess_args(parsed_args)
actor_id = ActorIdentifier().get_identifier(parsed_args)
results = self.tapis_client.actors.listNonces(actorId=actor_id)

# Use the requests_client because AgavePy is not configured
# with the alias-specific nonces endpoint
if parsed_args.is_alias:
api_path = 'aliases/' + actor_id + '/nonces'
self.requests_client.setup(API_NAME, SERVICE_VERSION, api_path)
results = self.requests_client.get()
else:
results = self.tapis_client.actors.listNonces(actorId=actor_id)

headers = self.render_headers(Nonce, parsed_args)
records = []
Expand Down
18 changes: 15 additions & 3 deletions tapis_cli/commands/taccapis/v2/actors/nonces_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class ActorsNoncesShow(ActorsFormatOne, ActorIdentifier, NonceIdentifier):

HELP_STRING = 'Show details for a Nonce'
HELP_STRING = 'Show details for a Nonce attached to an Actor (or Alias)'
LEGACY_COMMMAND_STRING = None

VERBOSITY = Verbosity.BRIEF
Expand All @@ -21,14 +21,26 @@ def get_parser(self, prog_name):
parser = super(ActorsNoncesShow, self).get_parser(prog_name)
parser = ActorIdentifier().extend_parser(parser)
parser = NonceIdentifier().extend_parser(parser)
parser.add_argument(
'-A',
dest='is_alias',
action='store_true',
help='Identifier is an ALIAS rather than an ACTOR_ID')
return parser

def take_action(self, parsed_args):
parsed_args = self.preprocess_args(parsed_args)
actor_id = ActorIdentifier().get_identifier(parsed_args)
nonce_id = NonceIdentifier().get_identifier(parsed_args)
rec = self.tapis_client.actors.getNonce(actorId=actor_id,
nonceId=nonce_id)
# Use the requests_client because AgavePy is not configured
# with the alias-specific nonces endpoint
if parsed_args.is_alias:
api_path = 'aliases/' + actor_id + '/nonces/' + nonce_id
self.requests_client.setup(API_NAME, SERVICE_VERSION, api_path)
rec = self.requests_client.get()
else:
rec = self.tapis_client.actors.listNonces(actorId=actor_id)

headers = self.render_headers(Nonce, parsed_args)
data = []
for key in headers:
Expand Down

0 comments on commit ba7f409

Please sign in to comment.