diff --git a/setup.cfg b/setup.cfg index 24b0f01..4c11ddb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -36,22 +36,27 @@ openstack.cli.extension = ssh = tatuclient.osc.plugin openstack.ssh.v1 = - usercert_create = tatuclient.v1.cli.usercert:CreateUserCertCommand - usercert_list = tatuclient.v1.cli.usercert:ListUserCertCommand - usercert_show = tatuclient.v1.cli.usercert:ShowUserCertCommand + ssh_usercert_create = tatuclient.v1.cli.usercert:CreateUserCertCommand + ssh_usercert_list = tatuclient.v1.cli.usercert:ListUserCertCommand + ssh_usercert_show = tatuclient.v1.cli.usercert:ShowUserCertCommand usercert_cert_show = tatuclient.v1.cli.usercert:ShowUserCertCertCommand - usercert_revoke = tatuclient.v1.cli.usercert:RevokeUserCertCommand + ssh_usercert_revoke = tatuclient.v1.cli.usercert:RevokeUserCertCommand - hostcert_list = tatuclient.v1.cli.hostcert:ListHostCertCommand - hostcert_show = tatuclient.v1.cli.hostcert:ShowHostCertCommand + ssh_host_list = tatuclient.v1.cli.host:ListHostCommand + ssh_host_show = tatuclient.v1.cli.host:ShowHostCommand + + ssh_hostcert_list = tatuclient.v1.cli.hostcert:ListHostCertCommand + ssh_hostcert_show = tatuclient.v1.cli.hostcert:ShowHostCertCommand hostcert_cert_show = tatuclient.v1.cli.hostcert:ShowHostCertCertCommand - sshca_create = tatuclient.v1.cli.ca:CreateCACommand - sshca_list = tatuclient.v1.cli.ca:ListCACommand - sshca_show = tatuclient.v1.cli.ca:ShowCACommand + ssh_ca_create = tatuclient.v1.cli.ca:CreateCACommand + ssh_ca_list = tatuclient.v1.cli.ca:ListCACommand + ssh_ca_show = tatuclient.v1.cli.ca:ShowCACommand sshca_user_key_show = tatuclient.v1.cli.ca:ShowCAUserKeyCommand sshca_host_key_show = tatuclient.v1.cli.ca:ShowCAHostKeyCommand + ssh_pat_list = tatuclient.v1.cli.pat:ListPATCommand + [build_sphinx] builders = html,man all-files = 1 diff --git a/tatuclient/v1/ca.py b/tatuclient/v1/ca.py index e310115..1e23746 100644 --- a/tatuclient/v1/ca.py +++ b/tatuclient/v1/ca.py @@ -13,7 +13,6 @@ # under the License. from tatuclient.v1.base import V1Controller -from tatuclient.v1 import utils as v1_utils class CAController(V1Controller): diff --git a/tatuclient/v1/cli/host.py b/tatuclient/v1/cli/host.py new file mode 100644 index 0000000..1f442b6 --- /dev/null +++ b/tatuclient/v1/cli/host.py @@ -0,0 +1,62 @@ +# Copyright 2018 Huawei, Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import argparse +import logging + +from osc_lib.command import command + +from tatuclient import utils +from tatuclient.v1.cli import common +from tatuclient.v1.utils import get_all + + +LOG = logging.getLogger(__name__) + +_columns = ['id', 'name', 'srv_url', 'pat_bastions'] +_names = ['Instance ID', 'Hostname', 'SRV URL', 'PAT Bastions'] + + +class ListHostCommand(command.Lister): + """List Hosts""" + + def get_parser(self, prog_name): + parser = super(ListHostCommand, self).get_parser(prog_name) + common.add_all_common_options(parser) + return parser + + def take_action(self, parsed_args): + client = self.app.client_manager.ssh + common.set_all_common_headers(client, parsed_args) + data = get_all(client.host.list) + return _names, (utils.get_item_properties(s, _columns) for s in data) + + +class ShowHostCommand(command.ShowOne): + """Show Host details""" + + def get_parser(self, prog_name): + parser = super(ShowHostCommand, self).get_parser(prog_name) + parser.add_argument('id', help="Instance ID") + common.add_all_common_options(parser) + return parser + + def _get_data(self, parsed_args): + client = self.app.client_manager.ssh + common.set_all_common_headers(client, parsed_args) + return client.host.get(parsed_args.id) + + def take_action(self, parsed_args): + data = self._get_data(parsed_args) + return _names, utils.get_item_properties(data, _columns) diff --git a/tatuclient/v1/cli/hostcert.py b/tatuclient/v1/cli/hostcert.py index b62028c..c1f6685 100644 --- a/tatuclient/v1/cli/hostcert.py +++ b/tatuclient/v1/cli/hostcert.py @@ -24,8 +24,8 @@ from tatuclient.v1.utils import get_all LOG = logging.getLogger(__name__) -_columns = ['host_id', 'srv_url', 'pat_bastions', 'fingerprint'] -_names = ['Instance ID', 'SRV URL', 'PAT Bastions', 'Fingerprint'] +_columns = ['host_id', 'fingerprint', 'hostname', 'created_at', 'expires_at'] +_names = ['Instance ID', 'Fingerprint', 'Hostname', 'Created', 'Expires'] class ListHostCertCommand(command.Lister): diff --git a/tatuclient/v1/cli/pat.py b/tatuclient/v1/cli/pat.py new file mode 100644 index 0000000..1a6ac75 --- /dev/null +++ b/tatuclient/v1/cli/pat.py @@ -0,0 +1,43 @@ +# Copyright 2018 Huawei, Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import argparse +import logging + +from osc_lib.command import command + +from tatuclient import utils +from tatuclient.v1.cli import common +from tatuclient.v1.utils import get_all + + +LOG = logging.getLogger(__name__) + + +_columns = ['IP', 'Chassis', 'LPort'] + + +class ListPATCommand(command.Lister): + """List PATs""" + + def get_parser(self, prog_name): + parser = super(ListCACommand, self).get_parser(prog_name) + common.add_all_common_options(parser) + return parser + + def take_action(self, parsed_args): + client = self.app.client_manager.ssh + common.set_all_common_headers(client, parsed_args) + data = get_all(client.pat.list) + return _columns, (utils.get_item_properties(s, _columns) for s in data) diff --git a/tatuclient/v1/cli/usercert.py b/tatuclient/v1/cli/usercert.py index 3e2f931..94c7e2d 100644 --- a/tatuclient/v1/cli/usercert.py +++ b/tatuclient/v1/cli/usercert.py @@ -24,8 +24,8 @@ from tatuclient.v1.utils import get_all LOG = logging.getLogger(__name__) -_columns = ['serial', 'revoked', 'user_id', 'auth_id', 'fingerprint'] -_names = ['Serial Number', 'Revoked', 'User ID', 'Project/CA ID', 'Fingerprint'] +_columns = ['serial', 'revoked', 'user_name', 'user_id', 'fingerprint', 'created_at', 'expires_at'] +_names = ['Serial Number', 'Revoked', 'User Name', 'User ID', 'Fingerprint', 'Created', 'Expires'] class ListUserCertCommand(command.Lister): diff --git a/tatuclient/v1/client.py b/tatuclient/v1/client.py index 976dfb8..69acc6f 100644 --- a/tatuclient/v1/client.py +++ b/tatuclient/v1/client.py @@ -108,5 +108,7 @@ class Client(object): ) self.ca = CAController(self) + self.host = HostController self.hostcert = HostCertController(self) self.usercert = UserCertController(self) + self.pat = PATController(self) diff --git a/tatuclient/v1/host.py b/tatuclient/v1/host.py new file mode 100644 index 0000000..05eca7b --- /dev/null +++ b/tatuclient/v1/host.py @@ -0,0 +1,25 @@ +# Copyright 2018 Huawei, Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from tatuclient.v1.base import V1Controller + + +class PATController(V1Controller): + + def list(self, criterion=None, marker=None, limit=None): + url = self.build_url('/noauth/hosts', criterion, marker, limit) + return self._get(url, response_key='pats') + + def get(self, host_id): + return self._get('/noauth/hosts/%s' % (host_id)) diff --git a/tatuclient/v1/hostcert.py b/tatuclient/v1/hostcert.py index 879894b..827abd4 100644 --- a/tatuclient/v1/hostcert.py +++ b/tatuclient/v1/hostcert.py @@ -13,7 +13,6 @@ # under the License. from tatuclient.v1.base import V1Controller -from tatuclient.v1 import utils as v1_utils class HostCertController(V1Controller): diff --git a/tatuclient/v1/pat.py b/tatuclient/v1/pat.py new file mode 100644 index 0000000..db77e87 --- /dev/null +++ b/tatuclient/v1/pat.py @@ -0,0 +1,22 @@ +# Copyright 2018 Huawei, Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from tatuclient.v1.base import V1Controller + + +class PATController(V1Controller): + + def list(self, criterion=None, marker=None, limit=None): + url = self.build_url('/noauth/pats', criterion, marker, limit) + return self._get(url, response_key='pats') diff --git a/tatuclient/v1/usercert.py b/tatuclient/v1/usercert.py index fd614cc..f3684f5 100644 --- a/tatuclient/v1/usercert.py +++ b/tatuclient/v1/usercert.py @@ -13,7 +13,6 @@ # under the License. from tatuclient.v1.base import V1Controller -from tatuclient.v1 import utils as v1_utils class UserCertController(V1Controller):