Added commands to print user/host certificate data.
This commit is contained in:
parent
cf271466bc
commit
154cf13765
@ -1,3 +1,4 @@
|
|||||||
- project:
|
- project:
|
||||||
|
name: openstack/python-tatuclient
|
||||||
templates:
|
templates:
|
||||||
- tatu-devstack-jobs
|
- tatu-devstack-jobs
|
||||||
|
@ -30,7 +30,7 @@ packages =
|
|||||||
|
|
||||||
[entry_points]
|
[entry_points]
|
||||||
tatuclient.versions =
|
tatuclient.versions =
|
||||||
2 = tatuclient.v1.client:Client
|
1 = tatuclient.v1.client:Client
|
||||||
|
|
||||||
openstack.cli.extension =
|
openstack.cli.extension =
|
||||||
ssh = tatuclient.osc.plugin
|
ssh = tatuclient.osc.plugin
|
||||||
@ -39,14 +39,18 @@ openstack.ssh.v1 =
|
|||||||
usercert_create = tatuclient.v1.cli.usercert:CreateUserCertCommand
|
usercert_create = tatuclient.v1.cli.usercert:CreateUserCertCommand
|
||||||
usercert_list = tatuclient.v1.cli.usercert:ListUserCertCommand
|
usercert_list = tatuclient.v1.cli.usercert:ListUserCertCommand
|
||||||
usercert_show = tatuclient.v1.cli.usercert:ShowUserCertCommand
|
usercert_show = tatuclient.v1.cli.usercert:ShowUserCertCommand
|
||||||
|
usercert_cert_show = tatuclient.v1.cli.usercert:ShowUserCertCertCommand
|
||||||
usercert_revoke = tatuclient.v1.cli.usercert:RevokeUserCertCommand
|
usercert_revoke = tatuclient.v1.cli.usercert:RevokeUserCertCommand
|
||||||
|
|
||||||
hostcert_list = tatuclient.v1.cli.hostcert:ListHostCertCommand
|
hostcert_list = tatuclient.v1.cli.hostcert:ListHostCertCommand
|
||||||
hostcert_show = tatuclient.v1.cli.hostcert:ShowHostCertCommand
|
hostcert_show = tatuclient.v1.cli.hostcert:ShowHostCertCommand
|
||||||
|
hostcert_cert_show = tatuclient.v1.cli.hostcert:ShowHostCertCertCommand
|
||||||
|
|
||||||
sshca_create = tatuclient.v1.cli.ca:CreateCACommand
|
sshca_create = tatuclient.v1.cli.ca:CreateCACommand
|
||||||
sshca_list = tatuclient.v1.cli.ca:ListCACommand
|
sshca_list = tatuclient.v1.cli.ca:ListCACommand
|
||||||
sshca_show = tatuclient.v1.cli.ca:ShowCACommand
|
sshca_show = tatuclient.v1.cli.ca:ShowCACommand
|
||||||
|
sshca_user_key_show = tatuclient.v1.cli.ca:ShowCAUserKeyCommand
|
||||||
|
sshca_host_key_show = tatuclient.v1.cli.ca:ShowCAHostKeyCommand
|
||||||
|
|
||||||
[build_sphinx]
|
[build_sphinx]
|
||||||
builders = html,man
|
builders = html,man
|
||||||
|
@ -92,6 +92,7 @@ def get_versions():
|
|||||||
return dict([(ep.name, ep.plugin) for ep in mgr.extensions])
|
return dict([(ep.name, ep.plugin) for ep in mgr.extensions])
|
||||||
|
|
||||||
|
|
||||||
|
#TODO(pino): can this be removed? Is it used anywhere?
|
||||||
def Client(version, *args, **kwargs): # noqa
|
def Client(version, *args, **kwargs): # noqa
|
||||||
versions = get_versions()
|
versions = get_versions()
|
||||||
if version not in versions:
|
if version not in versions:
|
||||||
|
@ -69,21 +69,25 @@ def get_item_properties(item, fields, mixed_case_fields=[], formatters={}):
|
|||||||
if field in formatters:
|
if field in formatters:
|
||||||
row.append(formatters[field](item))
|
row.append(formatters[field](item))
|
||||||
else:
|
else:
|
||||||
if field in mixed_case_fields:
|
row.append(get_property(item, field, mixed_case_fields))
|
||||||
field_name = field.replace(' ', '_')
|
|
||||||
else:
|
|
||||||
field_name = field.lower().replace(' ', '_')
|
|
||||||
if not hasattr(item, field_name) and \
|
|
||||||
(isinstance(item, dict) and field_name in item):
|
|
||||||
data = item[field_name]
|
|
||||||
else:
|
|
||||||
data = getattr(item, field_name, '')
|
|
||||||
if data is None:
|
|
||||||
data = ''
|
|
||||||
row.append(data)
|
|
||||||
return tuple(row)
|
return tuple(row)
|
||||||
|
|
||||||
|
|
||||||
|
def get_item_property(item, field, mixed_case_fields=[]):
|
||||||
|
if field in mixed_case_fields:
|
||||||
|
field_name = field.replace(' ', '_')
|
||||||
|
else:
|
||||||
|
field_name = field.lower().replace(' ', '_')
|
||||||
|
if not hasattr(item, field_name) and \
|
||||||
|
(isinstance(item, dict) and field_name in item):
|
||||||
|
data = item[field_name]
|
||||||
|
else:
|
||||||
|
data = getattr(item, field_name, '')
|
||||||
|
if data is None:
|
||||||
|
data = ''
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
def get_columns(data):
|
def get_columns(data):
|
||||||
"""
|
"""
|
||||||
Some row's might have variable count of columns, ensure that we have the
|
Some row's might have variable count of columns, ensure that we have the
|
||||||
|
@ -53,13 +53,32 @@ class ShowCACommand(command.ShowOne):
|
|||||||
common.add_all_common_options(parser)
|
common.add_all_common_options(parser)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def _get_data(self, parsed_args):
|
||||||
client = self.app.client_manager.ssh
|
client = self.app.client_manager.ssh
|
||||||
common.set_all_common_headers(client, parsed_args)
|
common.set_all_common_headers(client, parsed_args)
|
||||||
data = client.ca.get(parsed_args.auth_id)
|
return client.ca.get(parsed_args.auth_id)
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
data = self._get_data(parsed_args)
|
||||||
return _names, utils.get_item_properties(data, _columns)
|
return _names, utils.get_item_properties(data, _columns)
|
||||||
|
|
||||||
|
|
||||||
|
class ShowCAUserKeyCommand(ShowCACommand):
|
||||||
|
"""Print the CA's unformatted public key for user certificates."""
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
data = self._get_data(parsed_args)
|
||||||
|
self.app.stdout.write(utils.get_item_property(data, 'user_pub_key'))
|
||||||
|
|
||||||
|
|
||||||
|
class ShowCAHostKeyCommand(ShowCACommand):
|
||||||
|
"""Print the CA's unformatted public key for user certificates."""
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
data = self._get_data(parsed_args)
|
||||||
|
self.app.stdout.write(utils.get_item_property(data, 'host_pub_key'))
|
||||||
|
|
||||||
|
|
||||||
class CreateCACommand(command.ShowOne):
|
class CreateCACommand(command.ShowOne):
|
||||||
"""Create new CA"""
|
"""Create new CA"""
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@ from tatuclient.v1.utils import get_all
|
|||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
_columns = ['host_id', 'srv_url', 'pat_bastions', 'fingerprint', 'cert']
|
_columns = ['host_id', 'srv_url', 'pat_bastions', 'fingerprint']
|
||||||
_names = ['Instance ID', 'SRV URL', 'PAT Bastions', 'Fingerprint', 'SSH Certificate']
|
_names = ['Instance ID', 'SRV URL', 'PAT Bastions', 'Fingerprint']
|
||||||
|
|
||||||
|
|
||||||
class ListHostCertCommand(command.Lister):
|
class ListHostCertCommand(command.Lister):
|
||||||
@ -53,8 +53,19 @@ class ShowHostCertCommand(command.ShowOne):
|
|||||||
common.add_all_common_options(parser)
|
common.add_all_common_options(parser)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def _get_data(self, parsed_args):
|
||||||
client = self.app.client_manager.ssh
|
client = self.app.client_manager.ssh
|
||||||
common.set_all_common_headers(client, parsed_args)
|
common.set_all_common_headers(client, parsed_args)
|
||||||
data = client.hostcert.get(parsed_args.host_id, parsed_args.fingerprint)
|
return client.hostcert.get(parsed_args.host_id, parsed_args.fingerprint)
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
data = self._get_data(parsed_args)
|
||||||
return _names, utils.get_item_properties(data, _columns)
|
return _names, utils.get_item_properties(data, _columns)
|
||||||
|
|
||||||
|
|
||||||
|
class ShowUserCertCertCommand(ShowUserCertCommand):
|
||||||
|
"""Print the HostCert's unformatted certificate data."""
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
data = self._get_data(parsed_args)
|
||||||
|
self.app.stdout.write(utils.get_item_property(data, 'cert'))
|
||||||
|
@ -24,8 +24,8 @@ from tatuclient.v1.utils import get_all
|
|||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
_columns = ['serial', 'revoked', 'user_id', 'auth_id', 'fingerprint', 'cert']
|
_columns = ['serial', 'revoked', 'user_id', 'auth_id', 'fingerprint']
|
||||||
_names = ['Serial Number', 'Revoked', 'User ID', 'Project/CA ID', 'Fingerprint', 'SSH Certificate']
|
_names = ['Serial Number', 'Revoked', 'User ID', 'Project/CA ID', 'Fingerprint']
|
||||||
|
|
||||||
|
|
||||||
class ListUserCertCommand(command.Lister):
|
class ListUserCertCommand(command.Lister):
|
||||||
@ -52,26 +52,37 @@ class ShowUserCertCommand(command.ShowOne):
|
|||||||
common.add_all_common_options(parser)
|
common.add_all_common_options(parser)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def _get_data(self, parsed_args):
|
||||||
client = self.app.client_manager.ssh
|
client = self.app.client_manager.ssh
|
||||||
common.set_all_common_headers(client, parsed_args)
|
common.set_all_common_headers(client, parsed_args)
|
||||||
data = client.usercert.get(parsed_args.serial)
|
return client.usercert.get(parsed_args.serial)
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
data = self._get_data(parsed_args)
|
||||||
return _names, utils.get_item_properties(data, _columns)
|
return _names, utils.get_item_properties(data, _columns)
|
||||||
|
|
||||||
|
|
||||||
|
class ShowUserCertCertCommand(ShowUserCertCommand):
|
||||||
|
"""Print the UserCert's unformatted certificate data."""
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
data = self._get_data(parsed_args)
|
||||||
|
self.app.stdout.write(utils.get_item_property(data, 'cert'))
|
||||||
|
|
||||||
|
|
||||||
class CreateUserCertCommand(command.ShowOne):
|
class CreateUserCertCommand(command.ShowOne):
|
||||||
"""Create new UserCert"""
|
"""Create new UserCert"""
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(CreateUserCertCommand, self).get_parser(prog_name)
|
parser = super(CreateUserCertCommand, self).get_parser(prog_name)
|
||||||
parser.add_argument('user_id', help="User ID")
|
|
||||||
parser.add_argument('auth_id', help="Project/CA ID")
|
|
||||||
parser.add_argument('pub_key', help="Public Key")
|
parser.add_argument('pub_key', help="Public Key")
|
||||||
common.add_all_common_options(parser)
|
common.add_all_common_options(parser)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
client = self.app.client_manager.ssh
|
client = self.app.client_manager.ssh
|
||||||
|
parsed_args.user_id = client.session.get_user_id()
|
||||||
|
parsed_args.auth_id = client.session.get_project_id()
|
||||||
common.set_all_common_headers(client, parsed_args)
|
common.set_all_common_headers(client, parsed_args)
|
||||||
data = client.usercert.create(parsed_args)
|
data = client.usercert.create(parsed_args)
|
||||||
return _names, utils.get_item_properties(data, _columns)
|
return _names, utils.get_item_properties(data, _columns)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user