From 3021ba77df8fd312f01449df4c577580467223ac Mon Sep 17 00:00:00 2001 From: Hirotaka Wakabayashi Date: Fri, 4 Oct 2024 20:22:03 +0900 Subject: [PATCH] Release 1.1.0 --- .github/workflows/python-package.yml | 19 +- .gitignore | 14 +- .readthedocs.yaml | 15 +- HISTORY.rst | 7 + Makefile | 14 +- README.rst | 2 - docs/.gitignore | 14 +- docs/Makefile | 12 +- docs/conf.py | 14 +- docs/locale/ja/LC_MESSAGES/history.po | 38 +- docs/locale/ja/LC_MESSAGES/k2hr3client.po | 13 +- docs/make.bat | 12 +- docs/requirements.txt | 12 +- setup.py | 13 +- src/k2hr3client/__init__.py | 14 +- src/k2hr3client/acr.py | 12 +- src/k2hr3client/api.py | 14 +- src/k2hr3client/examples/create_role.py | 324 ------------------ src/k2hr3client/examples/example_resource.txt | 145 -------- src/k2hr3client/examples/get_registerpath.py | 189 ---------- src/k2hr3client/examples/identity_api.py | 133 ------- src/k2hr3client/examples/registerpath.py | 189 ---------- src/k2hr3client/examples/token_api.py | 91 ----- src/k2hr3client/exception.py | 12 +- src/k2hr3client/extdata.py | 12 +- src/k2hr3client/http.py | 12 +- src/k2hr3client/list.py | 12 +- src/k2hr3client/policy.py | 12 +- src/k2hr3client/resource.py | 95 +---- src/k2hr3client/role.py | 307 +++++++++++++++-- src/k2hr3client/service.py | 12 +- src/k2hr3client/tenant.py | 12 +- src/k2hr3client/token.py | 176 +++++++++- src/k2hr3client/userdata.py | 12 +- src/k2hr3client/version.py | 12 +- src/tests/__init__.py | 12 +- src/tests/test_acr.py | 12 +- src/tests/test_api.py | 12 +- src/tests/test_extdata.py | 12 +- src/tests/test_list.py | 12 +- src/tests/test_policy.py | 12 +- src/tests/test_resource.py | 17 +- src/tests/test_role.py | 12 +- src/tests/test_service.py | 12 +- src/tests/test_tenant.py | 12 +- src/tests/test_token.py | 12 +- src/tests/test_userdata.py | 12 +- src/tests/test_version.py | 33 +- 48 files changed, 753 insertions(+), 1425 deletions(-) delete mode 100644 src/k2hr3client/examples/create_role.py delete mode 100644 src/k2hr3client/examples/example_resource.txt delete mode 100644 src/k2hr3client/examples/get_registerpath.py delete mode 100644 src/k2hr3client/examples/identity_api.py delete mode 100644 src/k2hr3client/examples/registerpath.py delete mode 100644 src/k2hr3client/examples/token_api.py diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 328f983..f8663b1 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -1,10 +1,16 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # -# Copyright (c) 2020 Yahoo Japan Corporation +# Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. +# # For the full copyright and license information, please view # the license file that was distributed with this source code. # @@ -29,11 +35,6 @@ jobs: build: runs-on: ubuntu-latest - environment: - name: pypi - url: https://pypi.org/p/k2hr3client - permissions: - id-token: write strategy: fail-fast: false matrix: @@ -74,7 +75,9 @@ jobs: run: python -m build - name: Publish distribution to PyPI if: ${{ matrix.python-version == '3.11' && startsWith(github.ref, 'refs/tags') }} - uses: pypa/gh-action-pypi-publish@release/v1 + uses: pypa/gh-action-pypi-publish@master + with: + password: ${{ secrets.PYPI_API_TOKEN }} # # Local variables: diff --git a/.gitignore b/.gitignore index 4c665d9..097dcfc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,15 @@ # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. -# +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. +# # For the full copyright and license information, please view # the license file that was distributed with this source code. # diff --git a/.readthedocs.yaml b/.readthedocs.yaml index a4edfd2..63e260e 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -1,11 +1,18 @@ -# K2HDKC DBaaS based on Trove -# -# Copyright (c) 2022 Yahoo Japan Corporation +# +# k2hr3client - Python client for K2HR3 REST API +# +# Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. +# # For the full copyright and license information, please view # the license file that was distributed with this source code. -# +# # AUTHOR: Hirotaka Wakabayashi # CREATE: Tue Feb 08 2022 # REVISION: diff --git a/HISTORY.rst b/HISTORY.rst index 83d8b42..c6411e2 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,6 +2,13 @@ History ======= +1.1.0 (2024-10-04) +------------------- + +* Removes the deprecated Interfaces +* Removes the examples +* Updates the docs + 1.0.3 (2024-10-03) ------------------- diff --git a/Makefile b/Makefile index 75fa85f..4c5aa04 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,15 @@ # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. -# +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. +# # For the full copyright and license information, please view # the license file that was distributed with this source code. # diff --git a/README.rst b/README.rst index 41f1713..acf02f9 100644 --- a/README.rst +++ b/README.rst @@ -67,8 +67,6 @@ Let's try to get a token and create a resource.:: ... name=k2hr3_resource_name, ... data_type="string", ... data="testresourcedata", - ... tenant="demo", - ... cluster_name="testcluster", ... keys={ ... "cluster-name": "test-cluster", ... "chmpx-server-port": "8020", diff --git a/docs/.gitignore b/docs/.gitignore index f6c8fe8..a87baee 100644 --- a/docs/.gitignore +++ b/docs/.gitignore @@ -1,15 +1,15 @@ # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. -# +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. +# # For the full copyright and license information, please view # the license file that was distributed with this source code. # diff --git a/docs/Makefile b/docs/Makefile index 9b59039..36fa89c 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -1,9 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # -# Copyright (c) 2022 Yahoo Japan Corporation -# Copyright (c) 2024 LY Corporation +# Copyright 2020 Yahoo Japan Corporation +# Copyright 2024 LY Corporation +# +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/docs/conf.py b/docs/conf.py index 04dddef..5e8ca63 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,9 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove -# -# Copyright (c) 2022 Yahoo Japan Corporation -# Copyright (c) 2024 LY Corporation +# k2hr3client - Python client for K2HR3 REST API +# +# Copyright 2020 Yahoo Japan Corporation +# Copyright 2024 LY Corporation +# +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/docs/locale/ja/LC_MESSAGES/history.po b/docs/locale/ja/LC_MESSAGES/history.po index 45e337f..f8e97f4 100644 --- a/docs/locale/ja/LC_MESSAGES/history.po +++ b/docs/locale/ja/LC_MESSAGES/history.po @@ -10,7 +10,7 @@ msgid "" msgstr "" "Project-Id-Version: k2hr3client \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-10-03 18:04+0900\n" +"POT-Creation-Date: 2024-10-04 20:13+0900\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language: ja\n" @@ -26,46 +26,62 @@ msgid "History" msgstr "歴史" #: ../../../HISTORY.rst:6 -msgid "1.0.3 (2024-10-03)" +msgid "1.1.0 (2024-10-04)" msgstr "" #: ../../../HISTORY.rst:8 +msgid "Removes the deprecated Interfaces" +msgstr "非推奨のインタフェースを削除" + +#: ../../../HISTORY.rst:9 +msgid "Removes the examples" +msgstr "例示プログラムの削除" + +#: ../../../HISTORY.rst:10 +msgid "Updates the docs" +msgstr "ドキュメントの更新" + +#: ../../../HISTORY.rst:13 +msgid "1.0.3 (2024-10-03)" +msgstr "" + +#: ../../../HISTORY.rst:15 msgid "Fixes the K2hr3 API version" msgstr "K2hr3 APIのバージョンを固定化" -#: ../../../HISTORY.rst:9 +#: ../../../HISTORY.rst:16 msgid "Deprecates K2hr3Resource.create_conf_resource params" msgstr "K2hr3Resource.create_conf_resourceのパラメータを一部非推奨化" -#: ../../../HISTORY.rst:12 +#: ../../../HISTORY.rst:19 msgid "1.0.2 (2024-09-26)" msgstr "" -#: ../../../HISTORY.rst:14 +#: ../../../HISTORY.rst:21 msgid "Fixes lint errors" msgstr "静的解析ツールのエラーを修正" -#: ../../../HISTORY.rst:17 +#: ../../../HISTORY.rst:24 msgid "1.0.1 (2024-09-25)" msgstr "" -#: ../../../HISTORY.rst:19 +#: ../../../HISTORY.rst:26 msgid "Fixes resource API bugs" msgstr "Resource APIの不具合を修正" -#: ../../../HISTORY.rst:22 +#: ../../../HISTORY.rst:29 msgid "1.0.0 (2024-08-28)" msgstr "" -#: ../../../HISTORY.rst:24 +#: ../../../HISTORY.rst:31 msgid "Supports the other APIs" msgstr "他のAPIをサポート" -#: ../../../HISTORY.rst:27 +#: ../../../HISTORY.rst:34 msgid "0.0.1 (2020-08-28)" msgstr "" -#: ../../../HISTORY.rst:29 +#: ../../../HISTORY.rst:36 msgid "Supports Token, Resource, Policy and Role API" msgstr "トークン、リソース、ポリシーおよびロールAPIをサポート" diff --git a/docs/locale/ja/LC_MESSAGES/k2hr3client.po b/docs/locale/ja/LC_MESSAGES/k2hr3client.po index 8aadf57..5188a0e 100644 --- a/docs/locale/ja/LC_MESSAGES/k2hr3client.po +++ b/docs/locale/ja/LC_MESSAGES/k2hr3client.po @@ -10,7 +10,7 @@ msgid "" msgstr "" "Project-Id-Version: k2hr3client \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-09-26 10:42+0900\n" +"POT-Creation-Date: 2024-10-04 20:13+0900\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language: ja\n" @@ -325,10 +325,6 @@ msgstr "https://k2hr3.antpick.ax/api_resource.html を参照する" msgid "Create the resource." msgstr "リソースを作成する" -#: k2hr3client.resource.K2hr3Resource.data:1 of -msgid "Return data." -msgstr "データを返す" - #: k2hr3client.resource.K2hr3Resource.delete_with_notoken:1 of msgid "Delete the resource without token." msgstr "ロールトークン情報なしでリソースを削除する" @@ -649,11 +645,11 @@ msgstr "https://k2hr3.antpick.ax/api_version.html を参照する" #: k2hr3client.version.K2hr3Version.get:1 of msgid "Get the version." -msgstr "" +msgstr "Version APIからバージョンを取得する" #: ../../k2hr3client.rst:120 msgid "Module contents" -msgstr "" +msgstr "モジュールのコンテンツ" #: k2hr3client.get_version:1 of #, fuzzy @@ -674,3 +670,6 @@ msgstr "バージョン" msgid "Return type" msgstr "データを返す" +#~ msgid "Return data." +#~ msgstr "データを返す" + diff --git a/docs/make.bat b/docs/make.bat index 52035ce..1ffec07 100644 --- a/docs/make.bat +++ b/docs/make.bat @@ -1,9 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # -# Copyright (c) 2022 Yahoo Japan Corporation -# Copyright (c) 2024 LY Corporation +# Copyright 2020 Yahoo Japan Corporation +# Copyright 2024 LY Corporation +# +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/docs/requirements.txt b/docs/requirements.txt index 3fc5655..f32dabb 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,9 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # -# Copyright (c) 2022 Yahoo Japan Corporation -# Copyright (c) 2024 LY Corporation +# Copyright 2020 Yahoo Japan Corporation +# Copyright 2024 LY Corporation +# +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/setup.py b/setup.py index ddbbab6..17cfe50 100644 --- a/setup.py +++ b/setup.py @@ -1,16 +1,15 @@ # -*- coding: utf-8 -*- # -# -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/src/k2hr3client/__init__.py b/src/k2hr3client/__init__.py index e444602..7e0144a 100644 --- a/src/k2hr3client/__init__.py +++ b/src/k2hr3client/__init__.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. @@ -22,7 +22,7 @@ """K2HR3 Python Client of Token API.""" __author__ = 'Hirotaka Wakabayashi ' -__version__ = '1.0.3' +__version__ = '1.1.0' import sys diff --git a/src/k2hr3client/acr.py b/src/k2hr3client/acr.py index 9ec0b50..b037cfa 100644 --- a/src/k2hr3client/acr.py +++ b/src/k2hr3client/acr.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/src/k2hr3client/api.py b/src/k2hr3client/api.py index 33f88c5..1eb4a75 100644 --- a/src/k2hr3client/api.py +++ b/src/k2hr3client/api.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. @@ -167,7 +167,7 @@ def __init__(self, basepath: str, params: Optional[str] = None, # pylint: disab self.urlparams = params self.headers = hdrs self.body = body - self.version = K2hr3Api.DEFAULT_VERSION + self.version = version # following attrs are dynamically set later. self.resp = None # type: ignore diff --git a/src/k2hr3client/examples/create_role.py b/src/k2hr3client/examples/create_role.py deleted file mode 100644 index f20c8d6..0000000 --- a/src/k2hr3client/examples/create_role.py +++ /dev/null @@ -1,324 +0,0 @@ -# -*- coding: utf-8 -*- -# -# K2HDKC DBaaS based on Trove -# -# Copyright 2020 Yahoo Japan Corporation -# Copyright 2024 LY Corporation -# -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. -# -# For the full copyright and license information, please view -# the license file that was distributed with this source code. -# -# AUTHOR: Hirotaka Wakabayashi -# CREATE: Mon Sep 14 2020 -# REVISION: -# -# -"""K2HR3 Python Client of Resource API.""" - -from __future__ import (absolute_import, division, print_function, - unicode_literals) -import argparse -import json -import os -from pathlib import Path -import re -import sys -import urllib.parse -import urllib.request - -here = os.path.dirname(__file__) -src_dir = os.path.join(here, '..') -if os.path.exists(src_dir): - sys.path.append(src_dir) - -import k2hr3client # type: ignore # pylint: disable=import-error, wrong-import-position # noqa -from k2hr3client.exception import K2hr3Exception # type: ignore # pylint: disable=import-error, wrong-import-position # noqa -from k2hr3client.http import K2hr3Http # type: ignore # pylint: disable=import-error, wrong-import-position # noqa -from k2hr3client.token import K2hr3Token # type: ignore # pylint: disable=import-error, wrong-import-position # noqa -from k2hr3client.resource import K2hr3Resource # type: ignore # pylint: disable=import-error, wrong-import-position # noqa -from k2hr3client.policy import K2hr3Policy # type: ignore # pylint: disable=import-error, wrong-import-position # noqa -from k2hr3client.role import K2hr3Role # type: ignore # pylint: disable=import-error, wrong-import-position # noqa - -_MAX_LINE_LENGTH = 1024 * 8 - -IDENTITY_V3_PASSWORD_AUTH_JSON_DATA = """ -{ - "auth": { - "identity": { - "methods": [ - "password" - ], - "password": { - "user": { - "name": "admin", - "domain": { - "name": "Default" - }, - "password": "devstacker" - } - } } - } -} -""" - -IDENTITY_V3_TOKEN_AUTH_JSON_DATA = """ -{ - "auth": { - "identity": { - "methods": [ - "token" - ], - "token": { - "id": "" - } - }, - "scope": { - "project": { - "domain": { - "id": "default" - }, - "name": "" - } - } - } -} -""" - - -def get_scoped_token_id(url, user, password, project): - """Get a scoped token id from openstack identity.""" - # unscoped token-id - # https://docs.openstack.org/api-ref/identity/v3/index.html#password-authentication-with-unscoped-authorization - python_data = json.loads(IDENTITY_V3_PASSWORD_AUTH_JSON_DATA) - python_data['auth']['identity']['password']['user']['name'] = user - python_data['auth']['identity']['password']['user']['password'] = password - headers = { - 'User-Agent': 'hiwkby-sample', - 'Content-Type': 'application/json' - } - req = urllib.request.Request(url, - json.dumps(python_data).encode('ascii'), - headers, - method="POST") - with urllib.request.urlopen(req) as res: - unscoped_token_id = dict(res.info()).get('X-Subject-Token') - print('unscoped_token_id:[{}]'.format(unscoped_token_id)) - - # scoped token-id - # https://docs.openstack.org/api-ref/identity/v3/index.html?expanded=#token-authentication-with-scoped-authorization - python_data = json.loads(IDENTITY_V3_TOKEN_AUTH_JSON_DATA) - python_data['auth']['identity']['token']['id'] = unscoped_token_id - python_data['auth']['scope']['project']['name'] = project - headers = { - 'User-Agent': 'hiwkby-sample', - 'Content-Type': 'application/json' - } - req = urllib.request.Request(url, - json.dumps(python_data).encode('ascii'), - headers, - method="POST") - with urllib.request.urlopen(req) as res: - scoped_token_id = dict(res.info()).get('X-Subject-Token') - print('scoped_token_id:[{}]'.format(scoped_token_id)) - return scoped_token_id - - -def set_data(val: Path, projectname: str, clustername: str) -> str: - """Set data.""" - if val.exists() is False: - raise K2hr3Exception(f'path must exist, not {val}') - if val.is_file() is False: - raise K2hr3Exception( - f'path must be a regular file, not {val}') - data = "" - with val.open(encoding='utf-8') as f: # pylint: disable=no-member - line_len = 0 - for line in iter(f.readline, ''): - # 3. replace TROVE_K2HDKC_CLUSTER_NAME with clustername - line = re.sub('__TROVE_K2HDKC_CLUSTER_NAME__', clustername, - line) - # 4. replace TROVE_K2HDKC_TENANT_NAME with projectname - line = re.sub('__TROVE_K2HDKC_TENANT_NAME__', projectname, - line) - line_len += len(line) - if line_len > _MAX_LINE_LENGTH: - raise K2hr3Exception('data too big') - data = "".join([data, line]) # type: ignore - - return data - - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='k2hr3 token api example') - parser.add_argument( - '--url', - dest='url', - default='http://127.0.0.1/identity/v3/auth/tokens', - help='identity api url. ex) http://127.0.0.1/identity/v3/auth/tokens') - parser.add_argument('--user', - dest='user', - default='demo', - help='openstack user') - parser.add_argument('--password', - dest='password', - default='password', - help='openstack user password') - parser.add_argument('--project', - dest='project', - default='demo', - help='openstack project') - parser.add_argument('--k2hr3_url', - dest='k2hr3_url', - default='http://localhost:18080', - help='k2hr3 api url') - parser.add_argument('--resource', - dest='resource', - default='k2hdkccluster', - help='resource name') - parser.add_argument('--policy', - dest='policy', - default='k2hdkccluster', - help='policy name') - parser.add_argument('--role', - dest='role', - default='k2hdkccluster', - help='k2hr3 rolename') - - args = parser.parse_args() - - # 1. Gets a openstack token id from openstack identity server - openstack_token = get_scoped_token_id(args.url, args.user, args.password, - args.project) - - # 2. Gets a k2hr3 token from the openstack token - k2hr3_token = K2hr3Token(args.project, openstack_token) - http = K2hr3Http(args.k2hr3_url) - http.POST(k2hr3_token.create()) - - # 3. Makes a new k2hr3 resource - k2hr3_resource = K2hr3Resource(k2hr3_token.token) - k2hr3client_init_py = Path(k2hr3client.__file__) - val = k2hr3client_init_py.parent.joinpath('examples', - 'example_resource.txt') - data = set_data(val, projectname=args.project, clustername=args.resource) - - http.POST( - k2hr3_resource.create_conf_resource( - name=args.resource, - data_type='string', - resource_data=data, - keys={ - "cluster-name": args.resource, - "chmpx-server-port": "8020", - "chmpx-server-ctlport": "8021", - "chmpx-slave-ctlport": "8031" - }, - alias=[] - ) - ) - - # debug - # print(k2hr3_resource.resp.body) - # sys.exit(0) - - # 3.1. Makes a new k2hr3 resource for server - k2hr3_resource_server = K2hr3Resource(k2hr3_token.token) - http.POST( - k2hr3_resource_server.create_conf_resource( - name="/".join([args.resource, "server"]), - data_type='string', - resource_data="", - keys={"chmpx-mode": "SERVER", - "k2hr3-init-packages": "", - "k2hr3-init-packagecloud-packages": "", - "k2hr3-init-systemd-packages": ""}, - alias=[] - ) - ) - - # 3.2. Makes a new k2hr3 resource for slave - k2hr3_resource_slave = K2hr3Resource(k2hr3_token.token) - http.POST( - k2hr3_resource_slave.create_conf_resource( - name="/".join([args.resource, "slave"]), - data_type='string', - resource_data="", - keys={"chmpx-mode": "SLAVE", - "k2hr3-init-packages": "", - "k2hr3-init-packagecloud-packages": "", - "k2hr3-init-systemd-packages": "", - "k2hdkc-dbaas-add-user": 1}, - alias=[] - ) - ) - - # debug - # print(k2hr3_resource_slave.resp.body) - # sys.exit(0) - - # 4. Makes a new k2hr3 policy for the resource - k2hr3_policy = K2hr3Policy(k2hr3_token.token) - SERVER_RESOURCE_PATH = "yrn:yahoo:::{}:resource:{}/server".format( - args.project, args.resource) - SLAVE_RESOURCE_PATH = "yrn:yahoo:::{}:resource:{}/slave".format( - args.project, args.resource) - http.POST( - k2hr3_policy.create( - name=args.policy, - effect='allow', - action=['yrn:yahoo::::action:read'], - resource=[SERVER_RESOURCE_PATH, SLAVE_RESOURCE_PATH], - condition=None, - alias=[] - ) - ) - - # debug - # print(k2hr3_policy.resp.body) - # sys.exit(0) - - # 5. Makes a new k2hr3 role for the policy - POLICY_PATH = "yrn:yahoo:::{}:policy:{}".format(args.project, args.policy) - k2hr3_role = K2hr3Role(k2hr3_token.token) - http.POST( - k2hr3_role.create( - name=args.role, - policies=[POLICY_PATH], - alias=[] - ) - ) - server_role = K2hr3Role(k2hr3_token.token) - http.POST( - server_role.create( - name="/".join([args.role, "server"]), - policies=[], - alias=[] - ) - ) - slave_role = K2hr3Role(k2hr3_token.token) - http.POST( - slave_role.create( - name="/".join([args.role, "slave"]), - policies=[], - alias=[] - ) - ) - - # debug - # print(slave_role.resp.body) - # sys.exit(0) - -# -# Local variables: -# tab-width: 4 -# c-basic-offset: 4 -# End: -# vim600: expandtab sw=4 ts=4 fdm=marker -# vim<600: expandtab sw=4 ts=4 -# diff --git a/src/k2hr3client/examples/example_resource.txt b/src/k2hr3client/examples/example_resource.txt deleted file mode 100644 index 7fb2d7a..0000000 --- a/src/k2hr3client/examples/example_resource.txt +++ /dev/null @@ -1,145 +0,0 @@ -{{#!k2hr3template }} -# -# K2HDKC DBaaS based on Trove -# -# Copyright 2020 Yahoo Japan Corporation -# Copyright 2024 LY Corporation -# -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. -# -# For the full copyright and license information, please view -# the license file that was distributed with this source code. -# -# AUTHOR: Takeshi Nakatani -# CREATE: Mon Sep 14 2020 -# REVISION: -# - -# -# GLOBAL SECTION -# -[GLOBAL] -FILEVERSION = 1 -DATE = Thu, 28 May 2020 04:56:20 0000 -GROUP = {{= %cluster-name% }} -MODE = {{= %chmpx-mode% }} -CHMPXIDTYPE = NAME -DELIVERMODE = hash -MAXCHMPX = 256 -REPLICA = 1 -MAXMQSERVER = 8 -MAXMQCLIENT = 128 -MQPERATTACH = 8 -MAXQPERSERVERMQ = 8 -MAXQPERCLIENTMQ = 8 -MAXMQPERCLIENT = 16 -MAXHISTLOG = 0 -{{ if 'SERVER' == %chmpx-mode% }} -PORT = {{= %chmpx-server-port% }} -CTLPORT = {{= %chmpx-server-ctlport% }} -SELFCTLPORT = {{= %chmpx-server-ctlport% }} -{{ else }} -CTLPORT = {{= %chmpx-slave-ctlport% }} -SELFCTLPORT = {{= %chmpx-slave-ctlport% }} -{{ endif }} -SELFCUK = __SELF_INSTANCE_ID__ -RWTIMEOUT = 10000 -RETRYCNT = 500 -CONTIMEOUT = 1000 -MQRWTIMEOUT = 500 -MQRETRYCNT = 10000 -MQACK = no -AUTOMERGE = on -DOMERGE = on -MERGETIMEOUT = 0 -SOCKTHREADCNT = 8 -MQTHREADCNT = 8 -MAXSOCKPOOL = 16 -SOCKPOOLTIMEOUT = 0 -SSL = no -K2HFULLMAP = on -K2HMASKBIT = 4 -K2HCMASKBIT = 8 -K2HMAXELE = 16 - -# -# SERVER NODES SECTION -# -{{ foreach %host_key% in %yrn:yahoo:::__TROVE_K2HDKC_TENANT_NAME__:role:__TROVE_K2HDKC_CLUSTER_NAME__/server/hosts/ip% }} - {{ %one_host% = %yrn:yahoo:::__TROVE_K2HDKC_TENANT_NAME__:role:__TROVE_K2HDKC_CLUSTER_NAME__/server/hosts/ip%{%host_key%} }} -[SVRNODE] -NAME = {{= %one_host%{'host'} }} -CUK = {{= %one_host%{'cuk'} }} -PORT = {{= %chmpx-server-port% }} -CTLPORT = {{= %chmpx-server-ctlport% }} -SSL = no - {{ if %one_host%{'inboundip'} }} -ENDPOINTS = {{= %one_host%{'inboundip'} }}:{{= %chmpx-server-port% }} -CTLENDPOINTS = {{= %one_host%{'inboundip'} }}:{{= %chmpx-server-ctlport% }} -REVERSE_PEERS = {{= %one_host%{'inboundip'} }} - {{ endif }} - {{ if %one_host%{'outboundip'} }} -FORWARD_PEERS = {{= %one_host%{'outboundip'} }} - {{ endif }} -{{ done }} - -# -# SLAVE NODES SECTION -# -{{ if 0 < %yrn:yahoo:::__TROVE_K2HDKC_TENANT_NAME__:role:__TROVE_K2HDKC_CLUSTER_NAME__/slave/hosts/ip%.length }} - {{ foreach %host_key% in %yrn:yahoo:::__TROVE_K2HDKC_TENANT_NAME__:role:__TROVE_K2HDKC_CLUSTER_NAME__/slave/hosts/ip% }} - {{ %one_host% = %yrn:yahoo:::__TROVE_K2HDKC_TENANT_NAME__:role:__TROVE_K2HDKC_CLUSTER_NAME__/slave/hosts/ip%{%host_key%} }} -[SLVNODE] -NAME = {{= %one_host%{'host'} }} -CUK = {{= %one_host%{'cuk'} }} -CTLPORT = {{= %chmpx-slave-ctlport% }} -SSL = no - {{ if %one_host%{'inboundip'} }} -CTLENDPOINTS = {{= %one_host%{'inboundip'} }}:{{= %chmpx-slave-ctlport% }} -REVERSE_PEERS = {{= %one_host%{'inboundip'} }} - {{ endif }} - {{ if %one_host%{'outboundip'} }} -FORWARD_PEERS = {{= %one_host%{'outboundip'} }} - {{ endif }} - {{ done }} -{{ else }} -# -# This is output as a dummy slave node when there are no slave nodes. -# If the slave node definition does not exist, CHMPX will not start. -# To avoid this, register only one localhost as a dummy. -# -[SLVNODE] -NAME = 127.0.0.1 -CUK = dummy_cuk -CTLPORT = {{= %chmpx-slave-ctlport% }} -SSL = no -{{ endif }} - -{{ if 'SERVER' == %chmpx-mode% }} -# -# K2HDKC SECTION -# -[K2HDKC] -K2HTYPE = file -K2HFILE = /var/lib/antpickax/data/k2hdkc.k2h -K2HFULLMAP = on -K2HINIT = no -K2HMASKBIT = 8 -K2HCMASKBIT = 8 -K2HMAXELE = 32 -K2HPAGESIZE = 512 -MAXTHREAD = 20 -{{ endif }} - -# -# Local variables: -# tab-width: 4 -# c-basic-offset: 4 -# End: -# vim600: expandtab sw=4 ts=4 fdm=marker -# vim<600: expandtab sw=4 ts=4 -# diff --git a/src/k2hr3client/examples/get_registerpath.py b/src/k2hr3client/examples/get_registerpath.py deleted file mode 100644 index 0b1e9de..0000000 --- a/src/k2hr3client/examples/get_registerpath.py +++ /dev/null @@ -1,189 +0,0 @@ -# -*- coding: utf-8 -*- -# -# K2HDKC DBaaS based on Trove -# -# Copyright 2020 Yahoo Japan Corporation -# Copyright 2024 LY Corporation -# -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. -# -# For the full copyright and license information, please view -# the license file that was distributed with this source code. -# -# AUTHOR: Hirotaka Wakabayashi -# CREATE: Mon Sep 14 2020 -# REVISION: -# -# -"""K2HR3 Python Client of Token API.""" - -from __future__ import (absolute_import, division, print_function, - unicode_literals) -import argparse -import os -import sys -import json -import urllib.parse -import urllib.request - -here = os.path.dirname(__file__) -src_dir = os.path.join(here, '..') -if os.path.exists(src_dir): - sys.path.append(src_dir) - -from k2hr3client.http import K2hr3Http # type: ignore # pylint: disable=import-error, wrong-import-position # noqa -from k2hr3client.token import K2hr3Token # type: ignore # pylint: disable=import-error, wrong-import-position # noqa -from k2hr3client.token import K2hr3RoleToken # pylint: disable=import-error, wrong-import-position # noqa -from k2hr3client.token import K2hr3RoleTokenList # pylint: disable=import-error, wrong-import-position # noqa - -IDENTITY_V3_PASSWORD_AUTH_JSON_DATA = """ -{ - "auth": { - "identity": { - "methods": [ - "password" - ], - "password": { - "user": { - "name": "admin", - "domain": { - "name": "Default" - }, - "password": "devstacker" - } - } } - } -} -""" - -IDENTITY_V3_TOKEN_AUTH_JSON_DATA = """ -{ - "auth": { - "identity": { - "methods": [ - "token" - ], - "token": { - "id": "" - } - }, - "scope": { - "project": { - "domain": { - "id": "default" - }, - "name": "" - } - } - } -} -""" - - -def get_scoped_token_id(url, user, password, project): - """Get a scoped token id from openstack identity.""" - # unscoped token-id - # https://docs.openstack.org/api-ref/identity/v3/index.html#password-authentication-with-unscoped-authorization - python_data = json.loads(IDENTITY_V3_PASSWORD_AUTH_JSON_DATA) - python_data['auth']['identity']['password']['user']['name'] = user - python_data['auth']['identity']['password']['user']['password'] = password - headers = { - 'User-Agent': 'hiwkby-sample', - 'Content-Type': 'application/json' - } - req = urllib.request.Request(url, - json.dumps(python_data).encode('ascii'), - headers, - method="POST") - with urllib.request.urlopen(req) as res: - unscoped_token_id = dict(res.info()).get('X-Subject-Token') - # print('unscoped_token_id:[{}]'.format(unscoped_token_id)) - - # scoped token-id - # https://docs.openstack.org/api-ref/identity/v3/index.html?expanded=#token-authentication-with-scoped-authorization - python_data = json.loads(IDENTITY_V3_TOKEN_AUTH_JSON_DATA) - python_data['auth']['identity']['token']['id'] = unscoped_token_id - python_data['auth']['scope']['project']['name'] = project - headers = { - 'User-Agent': 'hiwkby-sample', - 'Content-Type': 'application/json' - } - req = urllib.request.Request(url, - json.dumps(python_data).encode('ascii'), - headers, - method="POST") - with urllib.request.urlopen(req) as res: - scoped_token_id = dict(res.info()).get('X-Subject-Token') - # print('scoped_token_id:[{}]'.format(scoped_token_id)) - return scoped_token_id - - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='k2hr3 token api example') - parser.add_argument( - '--url', - dest='url', - default='http://127.0.0.1/identity/v3/auth/tokens', - help='identity api url. ex) http://127.0.0.1/identity/v3/auth/tokens') - parser.add_argument('--user', - dest='user', - default='demo', - help='openstack user') - parser.add_argument('--password', - dest='password', - default='password', - help='openstack user password') - parser.add_argument('--project', - dest='project', - default='demo', - help='openstack project') - parser.add_argument('--k2hr3_url', - dest='k2hr3_url', - default='http://localhost:18080', - help='k2hr3 api url') - parser.add_argument('--role', - dest='role', - default='k2hdkccluster', - help='k2hr3 rolename') - args = parser.parse_args() - - # 1. Gets a openstack token id from openstack identity server - openstack_token = get_scoped_token_id(args.url, args.user, args.password, - args.project) - - # 2. Gets a k2hr3 token from the openstack token - k2hr3_token = K2hr3Token(args.project, openstack_token) - http = K2hr3Http(args.k2hr3_url) - http.POST(k2hr3_token.create()) - - # 3. Gets a k2hr3 role token from the k2hr3 token - k2hr3_role_token = K2hr3RoleToken(k2hr3_token.token, - role=args.role, - expire=0) - http.GET(k2hr3_role_token) - roletoken = k2hr3_role_token.token - print("roletoken {}".format(roletoken)) - - # 4. Gets a k2hr3 role token list from the k2hr3 token - k2hr3_role_token_list = K2hr3RoleTokenList(k2hr3_token.token, - role=args.role, - expand=True) - http.GET(k2hr3_role_token_list) - - # 4. Gets the registerpath of the k2hr3 role token - registerpath = k2hr3_role_token_list.registerpath(roletoken) - print("{}".format(registerpath)) - sys.exit(0) - -# -# Local variables: -# tab-width: 4 -# c-basic-offset: 4 -# End: -# vim600: expandtab sw=4 ts=4 fdm=marker -# vim<600: expandtab sw=4 ts=4 -# diff --git a/src/k2hr3client/examples/identity_api.py b/src/k2hr3client/examples/identity_api.py deleted file mode 100644 index c4c819b..0000000 --- a/src/k2hr3client/examples/identity_api.py +++ /dev/null @@ -1,133 +0,0 @@ -# -*- coding: utf-8 -*- -# -# K2HDKC DBaaS based on Trove -# -# Copyright 2020 Yahoo Japan Corporation -# Copyright 2024 LY Corporation -# -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. -# -# For the full copyright and license information, please view -# the license file that was distributed with this source code. -# -# AUTHOR: Hirotaka Wakabayashi -# CREATE: Mon Sep 14 2020 -# REVISION: -# -# -"""An example for OpenStack Identity API.""" - -from __future__ import (absolute_import, division, print_function, - unicode_literals) -import argparse -import os -import sys -import json -import urllib.parse -import urllib.request - -here = os.path.dirname(__file__) -src_dir = os.path.join(here, '..') -if os.path.exists(src_dir): - sys.path.append(src_dir) - -IDENTITY_V3_PASSWORD_AUTH_JSON_DATA = """ -{ - "auth": { - "identity": { - "methods": [ - "password" - ], - "password": { - "user": { - "name": "admin", - "domain": { - "name": "Default" - }, - "password": "devstacker" - } - } } - } -} -""" - -IDENTITY_V3_TOKEN_AUTH_JSON_DATA = """ -{ - "auth": { - "identity": { - "methods": [ - "token" - ], - "token": { - "id": "" - } - }, - "scope": { - "project": { - "domain": { - "id": "default" - }, - "name": "" - } - } - } -} -""" - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='k2hr3 token api example') - parser.add_argument('--url', dest='url', - default='http://127.0.0.1/identity/v3/auth/tokens', - help='ex) http://127.0.0.1/identity/v3/auth/tokens') - parser.add_argument('--user', dest='user', - default='demo', help='openstack user') - parser.add_argument('--password', dest='password', default='password', - help='openstack user password') - parser.add_argument('--project', - dest='project', - default='demo', - help='openstack project') - args = parser.parse_args() - - # unscoped token-id - # https://docs.openstack.org/api-ref/identity/v3/index.html#password-authentication-with-unscoped-authorization - url = args.url - pydata = json.loads(IDENTITY_V3_PASSWORD_AUTH_JSON_DATA) - pydata['auth']['identity']['password']['user']['name'] = args.user - pydata['auth']['identity']['password']['user']['password'] = args.password - headers = {'User-Agent': 'hiwkby-sample', - 'Content-Type': 'application/json'} - req = urllib.request.Request(url, json.dumps(pydata).encode('ascii'), - headers, method="POST") - with urllib.request.urlopen(req) as res: - unscoped_token_id = dict(res.info()).get('X-Subject-Token') - print('unscoped_token_id:[{}]'.format(unscoped_token_id)) - - # scoped token-id - # https://docs.openstack.org/api-ref/identity/v3/index.html?expanded=#token-authentication-with-scoped-authorization - my_project_name = args.project - pydata = json.loads(IDENTITY_V3_TOKEN_AUTH_JSON_DATA) - pydata['auth']['identity']['token']['id'] = unscoped_token_id - pydata['auth']['scope']['project']['name'] = my_project_name - headers = {'User-Agent': 'hiwkby-sample', - 'Content-Type': 'application/json'} - req = urllib.request.Request(url, json.dumps(pydata).encode('ascii'), - headers, method="POST") - with urllib.request.urlopen(req) as res: - scoped_token_id = dict(res.info()).get('X-Subject-Token') - print('scoped_token_id:[{}]'.format(scoped_token_id)) - - sys.exit(0) - -# -# Local variables: -# tab-width: 4 -# c-basic-offset: 4 -# End: -# vim600: expandtab sw=4 ts=4 fdm=marker -# vim<600: expandtab sw=4 ts=4 -# diff --git a/src/k2hr3client/examples/registerpath.py b/src/k2hr3client/examples/registerpath.py deleted file mode 100644 index 63926a4..0000000 --- a/src/k2hr3client/examples/registerpath.py +++ /dev/null @@ -1,189 +0,0 @@ -# -*- coding: utf-8 -*- -# -# K2HDKC DBaaS based on Trove -# -# Copyright 2020 Yahoo Japan Corporation -# Copyright 2024 LY Corporation -# -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. -# -# For the full copyright and license information, please view -# the license file that was distributed with this source code. -# -# AUTHOR: Hirotaka Wakabayashi -# CREATE: Mon Sep 14 2020 -# REVISION: -# -# -"""K2HR3 Python Client of Token API.""" - -from __future__ import (absolute_import, division, print_function, - unicode_literals) -import argparse -import os -import sys -import json -import urllib.parse -import urllib.request - -here = os.path.dirname(__file__) -src_dir = os.path.join(here, '..') -if os.path.exists(src_dir): - sys.path.append(src_dir) - -from k2hr3client.http import K2hr3Http # type: ignore # pylint: disable=import-error, wrong-import-position # noqa -from k2hr3client.token import K2hr3Token # type: ignore # pylint: disable=import-error, wrong-import-position # noqa -from k2hr3client.token import K2hr3RoleToken # pylint: disable=import-error, wrong-import-position # noqa -from k2hr3client.token import K2hr3RoleTokenList # pylint: disable=import-error, wrong-import-position # noqa - -IDENTITY_V3_PASSWORD_AUTH_JSON_DATA = """ -{ - "auth": { - "identity": { - "methods": [ - "password" - ], - "password": { - "user": { - "name": "admin", - "domain": { - "name": "Default" - }, - "password": "devstacker" - } - } } - } -} -""" - -IDENTITY_V3_TOKEN_AUTH_JSON_DATA = """ -{ - "auth": { - "identity": { - "methods": [ - "token" - ], - "token": { - "id": "" - } - }, - "scope": { - "project": { - "domain": { - "id": "default" - }, - "name": "" - } - } - } -} -""" - - -def get_scoped_token_id(url, user, password, project): - """Get a scoped token id from openstack identity.""" - # unscoped token-id - # https://docs.openstack.org/api-ref/identity/v3/index.html#password-authentication-with-unscoped-authorization - python_data = json.loads(IDENTITY_V3_PASSWORD_AUTH_JSON_DATA) - python_data['auth']['identity']['password']['user']['name'] = user - python_data['auth']['identity']['password']['user']['password'] = password - headers = { - 'User-Agent': 'hiwkby-sample', - 'Content-Type': 'application/json' - } - req = urllib.request.Request(url, - json.dumps(python_data).encode('ascii'), - headers, - method="POST") - with urllib.request.urlopen(req) as res: - unscoped_token_id = dict(res.info()).get('X-Subject-Token') - # print('unscoped_token_id:[{}]'.format(unscoped_token_id)) - - # scoped token-id - # https://docs.openstack.org/api-ref/identity/v3/index.html?expanded=#token-authentication-with-scoped-authorization - python_data = json.loads(IDENTITY_V3_TOKEN_AUTH_JSON_DATA) - python_data['auth']['identity']['token']['id'] = unscoped_token_id - python_data['auth']['scope']['project']['name'] = project - headers = { - 'User-Agent': 'hiwkby-sample', - 'Content-Type': 'application/json' - } - req = urllib.request.Request(url, - json.dumps(python_data).encode('ascii'), - headers, - method="POST") - with urllib.request.urlopen(req) as res: - scoped_token_id = dict(res.info()).get('X-Subject-Token') - # print('scoped_token_id:[{}]'.format(scoped_token_id)) - return scoped_token_id - - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='k2hr3 token api example') - parser.add_argument( - '--url', - dest='url', - default='http://127.0.0.1/identity/v3/auth/tokens', - help='identity api url. ex) http://127.0.0.1/identity/v3/auth/tokens') - parser.add_argument('--user', - dest='user', - default='demo', - help='openstack user') - parser.add_argument('--password', - dest='password', - default='password', - help='openstack user password') - parser.add_argument('--project', - dest='project', - default='demo', - help='openstack project') - parser.add_argument('--k2hr3_url', - dest='k2hr3_url', - default='http://localhost:18080/v1', - help='k2hr3 api url') - parser.add_argument('--role', - dest='role', - default='k2hdkccluster', - help='k2hr3 rolename') - args = parser.parse_args() - - # 1. Gets a openstack token id from openstack identity server - openstack_token = get_scoped_token_id(args.url, args.user, args.password, - args.project) - - # 2. Gets a k2hr3 token from the openstack token - k2hr3_token = K2hr3Token(args.project, openstack_token) - http = K2hr3Http(args.k2hr3_url) - http.POST(k2hr3_token.create()) - - # 3. Gets a k2hr3 role token from the k2hr3 token - k2hr3_role_token = K2hr3RoleToken(k2hr3_token.token, - role=args.role, - expire=0) - http.GET(k2hr3_role_token) - roletoken = k2hr3_role_token.token - # print("roletoken {}".format(roletoken)) - - # 4. Gets a k2hr3 role token list from the k2hr3 token - k2hr3_role_token_list = K2hr3RoleTokenList(k2hr3_token.token, - role=args.role, - expand=True) - http.GET(k2hr3_role_token_list) - - # 4. Gets the registerpath of the k2hr3 role token - registerpath = k2hr3_role_token_list.registerpath(roletoken) - print("{}".format(registerpath)) - sys.exit(0) - -# -# Local variables: -# tab-width: 4 -# c-basic-offset: 4 -# End: -# vim600: expandtab sw=4 ts=4 fdm=marker -# vim<600: expandtab sw=4 ts=4 -# diff --git a/src/k2hr3client/examples/token_api.py b/src/k2hr3client/examples/token_api.py deleted file mode 100644 index 84c38d6..0000000 --- a/src/k2hr3client/examples/token_api.py +++ /dev/null @@ -1,91 +0,0 @@ -# -*- coding: utf-8 -*- -# -# K2HDKC DBaaS based on Trove -# -# Copyright 2020 Yahoo Japan Corporation -# Copyright 2024 LY Corporation -# -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. -# -# For the full copyright and license information, please view -# the license file that was distributed with this source code. -# -# AUTHOR: Hirotaka Wakabayashi -# CREATE: Mon Sep 14 2020 -# REVISION: -# -# -"""K2HR3 Python Client of Token API.""" - -from __future__ import (absolute_import, division, print_function, - unicode_literals) -import argparse -import os -import sys - -here = os.path.dirname(__file__) -src_dir = os.path.join(here, '..') -if os.path.exists(src_dir): - sys.path.append(src_dir) - -from k2hr3client.http import K2hr3Http # type: ignore # pylint: disable=import-error, wrong-import-position # noqa -from k2hr3client.token import K2hr3Token # type: ignore # pylint: disable=import-error, wrong-import-position # noqa -from k2hr3client.token import K2hr3RoleToken # pylint: disable=import-error, wrong-import-position # noqa -from k2hr3client.token import K2hr3RoleTokenList # pylint: disable=import-error, wrong-import-position # noqa - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='k2hr3 token api example') - parser.add_argument('--url', - dest='url', - default='http://localhost:18080/v1', - help='k2hr3 api url') - parser.add_argument('--project', - dest='project', - default='demo', - help='openstack project') - parser.add_argument('--token', - dest='token', - default='foobar', - help='openstack token') - args = parser.parse_args() - - # 1. Gets a k2hr3 token from the openstack token - k2hr3_token = K2hr3Token(args.project, args.token) - http = K2hr3Http(args.url) - http.POST(k2hr3_token.create()) - - # 2. Gets a k2hr3 role token from the k2hr3 token - k2hr3_role_token = K2hr3RoleToken( - k2hr3_token.token, - role="k2hdkccluster", - expire=0 - ) - http.GET(k2hr3_role_token) - roletoken = k2hr3_role_token.token - print("roletoken {}".format(roletoken)) - - # 3. Gets a k2hr3 role token list from the k2hr3 token - k2hr3_role_token_list = K2hr3RoleTokenList( - k2hr3_token.token, - role="k2hdkccluster", - expand=True - ) - http.GET(k2hr3_role_token_list) - - # 4. Gets the registerpath of the k2hr3 role token - registerpath = k2hr3_role_token_list.registerpath(roletoken) - print("registerpath {}".format(registerpath)) - sys.exit(0) - -# -# Local variables: -# tab-width: 4 -# c-basic-offset: 4 -# End: -# vim600: expandtab sw=4 ts=4 fdm=marker -# vim<600: expandtab sw=4 ts=4 -# diff --git a/src/k2hr3client/exception.py b/src/k2hr3client/exception.py index bad48ce..8561b21 100644 --- a/src/k2hr3client/exception.py +++ b/src/k2hr3client/exception.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/src/k2hr3client/extdata.py b/src/k2hr3client/extdata.py index 87a901e..a914830 100644 --- a/src/k2hr3client/extdata.py +++ b/src/k2hr3client/extdata.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/src/k2hr3client/http.py b/src/k2hr3client/http.py index 8e994a0..cfbaf86 100644 --- a/src/k2hr3client/http.py +++ b/src/k2hr3client/http.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/src/k2hr3client/list.py b/src/k2hr3client/list.py index df523f2..956ccf7 100644 --- a/src/k2hr3client/list.py +++ b/src/k2hr3client/list.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/src/k2hr3client/policy.py b/src/k2hr3client/policy.py index 0bd88e5..d3724f5 100644 --- a/src/k2hr3client/policy.py +++ b/src/k2hr3client/policy.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/src/k2hr3client/resource.py b/src/k2hr3client/resource.py index 60ee8d4..237de0c 100644 --- a/src/k2hr3client/resource.py +++ b/src/k2hr3client/resource.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. @@ -37,15 +37,13 @@ myhttp.POST(mytoken.create()) mytoken.token // gAAAAA... - # POST a request to create a resource from K2HR3 Resource API. + # POST a request to create a K2HDKC resource. myresource = K2hr3Resource(mytoken.token) myhttp.POST( myresource.create_conf_resource( name="test_resource", data_type="string", - data="testresourcedata", - tenant="demo", - cluster_name="testcluster", + resource_data="testresourcedata", keys={ "cluster-name": "test-cluster", "chmpx-server-port": "8020", @@ -59,14 +57,9 @@ import json import logging -from pathlib import Path -import re -from typing import Optional, Any -import warnings +from typing import Optional -import k2hr3client from k2hr3client.api import K2hr3Api, K2hr3HTTPMethod -from k2hr3client.exception import K2hr3Exception LOG = logging.getLogger(__name__) @@ -140,8 +133,8 @@ def __init__(self, r3token: Optional[str] = None, self.body = None self.urlparams = None # attributes that are unique to this class - self.name = None self.resource_data = None + self.name = None self.data_type = None self.keys = None self.alias = None @@ -150,7 +143,6 @@ def __init__(self, r3token: Optional[str] = None, self.port = None self.cuk = None self.role = None - self._data = None # ---- POST/PUT ---- # POST http(s)://API SERVER:PORT/v1/resource @@ -179,9 +171,6 @@ def __init__(self, r3token: Optional[str] = None, # keys=json key value object # def create_conf_resource(self, name: str, data_type: str, resource_data: str, # pylint: disable=R0917 # noqa - data: Optional[Any] = None, - tenant: Optional[str] = None, - cluster_name: Optional[str] = None, keys: Optional[dict] = None, alias: Optional[list] = None): """Create the resource.""" @@ -189,29 +178,6 @@ def create_conf_resource(self, name: str, data_type: str, resource_data: str, # self.name = name # type: ignore self.resource_data = resource_data # type: ignore self.data_type = data_type # type: ignore - if resource_data is None and data is not None: - warnings.warn( - "The 'datae' parameter to 'create_conf_resource' " - "is deprecated and slated for removal in " - "k2hr3client-1.1.0", - DeprecationWarning, - stacklevel=1) - self.resource_data = data - if tenant is not None: - warnings.warn( - "The 'tenant' parameter to 'create_conf_resource' " - "is deprecated and slated for removal in " - "k2hr3client-1.1.0", - DeprecationWarning, - stacklevel=1) - if cluster_name is not None: - warnings.warn( - "The 'cluster_name' parameter to 'create_conf_resource' " - "is deprecated and slated for removal in " - "k2hr3client-1.1.0", - DeprecationWarning, - stacklevel=1) - self._set_data(resource_data, tenant, cluster_name) # type: ignore self.keys = keys # type: ignore self.alias = alias # type: ignore return self @@ -351,43 +317,6 @@ def __repr__(self) -> str: values = ', '.join(['%s=%s' % i for i in attrs]) return '' - @property # type: ignore - def data(self) -> str: - """Return data.""" - return self._data # type: ignore - - def _set_data(self, val: Any, projectname: str, clustername: str) -> None: - """Set data.""" - if getattr(self, '_data', None) is None: - self._data = val - if isinstance(val, Path) is False: - self._data = val - else: - self._data = "" # type: ignore - if val.exists() is False: - raise K2hr3Exception(f'path must exist, not {val}') - if val.is_file() is False: - raise K2hr3Exception( - f'path must be a regular file, not {val}') - # NOTE(hiwakaba): val must not be an arbitrary value. - # for backward compat, the resource template is used. - k2hr3client_init_py = Path(k2hr3client.__file__) - val = k2hr3client_init_py.parent.joinpath('examples', - 'example_resource.txt') - with val.open(encoding='utf-8') as f: # pylint: disable=no-member - line_len = 0 - for line in iter(f.readline, ''): - # 3. replace TROVE_K2HDKC_CLUSTER_NAME with clustername - line = re.sub('__TROVE_K2HDKC_CLUSTER_NAME__', clustername, - line) - # 4. replace TROVE_K2HDKC_TENANT_NAME with projectname - line = re.sub('__TROVE_K2HDKC_TENANT_NAME__', projectname, - line) - line_len += len(line) - if line_len > _MAX_LINE_LENGTH: - raise K2hr3Exception('data too big') - self._data = "".join([self._data, line]) # type: ignore - @property # type: ignore def r3token(self): """Return the r3token.""" @@ -431,7 +360,7 @@ def _api_path(self, method: K2hr3HTTPMethod) -> Optional[str]: # pylint: disable python_data = json.loads(_RESOURCE_API_CREATE_RESOURCE) python_data['resource']['name'] = self.name python_data['resource']['type'] = self.data_type - python_data['resource']['data'] = self.data + python_data['resource']['data'] = self.resource_data python_data['resource']['keys'] = self.keys python_data['resource']['alias'] = self.alias self.body = json.dumps(python_data) @@ -443,7 +372,7 @@ def _api_path(self, method: K2hr3HTTPMethod) -> Optional[str]: # pylint: disable self.urlparams = json.dumps({ 'name': self.name, 'type': self.data_type, - 'data': self.data, + 'data': self.resource_data, 'keys': self.keys, 'alias': self.alias }) diff --git a/src/k2hr3client/role.py b/src/k2hr3client/role.py index 1e4d0b2..ae7c07e 100644 --- a/src/k2hr3client/role.py +++ b/src/k2hr3client/role.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. @@ -23,30 +23,285 @@ .. code-block:: python - # Import modules from k2hr3client package. - from k2hr3client.token import K2hr3Token + # Simple CUI application to create a full k2hdkc dbaas resource. + from __future__ import (absolute_import, division, print_function, + unicode_literals) + import argparse + import json + import os + from pathlib import Path + import re + import sys + import urllib.parse + import urllib.request + + here = os.path.dirname(__file__) + src_dir = os.path.join(here, '..') + if os.path.exists(src_dir): + sys.path.append(src_dir) + + import k2hr3client + from k2hr3client.exception import K2hr3Exception from k2hr3client.http import K2hr3Http + from k2hr3client.token import K2hr3Token + from k2hr3client.resource import K2hr3Resource + from k2hr3client.policy import K2hr3Policy from k2hr3client.role import K2hr3Role - iaas_project = "demo" - iaas_token = "gAAAAA..." - mytoken = K2hr3Token(iaas_project, iaas_token) - - # POST a request to create a token to K2HR3 Token API. - myhttp = K2hr3Http("http://127.0.0.1:18080") - myhttp.POST(mytoken.create()) - mytoken.token // gAAAAA... - - # POST a request to create a role to K2HR3 Role API. - myrole = K2hr3Role(mytoken.token) - myhttp.POST( - myrole.create( - name = "test_role", - policies = ['yrn:yahoo:::demo:policy:test_policy'], - alias = [] + _MAX_LINE_LENGTH = 1024 * 8 + + IDENTITY_V3_PASSWORD_AUTH_JSON_DATA = ''' + { + "auth": { + "identity": { + "methods": [ + "password" + ], + "password": { + "user": { + "name": "admin", + "domain": { + "name": "Default" + }, + "password": "devstacker" + } + } } + } + } + ''' + + IDENTITY_V3_TOKEN_AUTH_JSON_DATA = ''' + { + "auth": { + "identity": { + "methods": [ + "token" + ], + "token": { + "id": "" + } + }, + "scope": { + "project": { + "domain": { + "id": "default" + }, + "name": "" + } + } + } + } + ''' + + def get_scoped_token_id(url, user, password, project): + # Get a scoped token id from openstack identity. + # unscoped token-id + # https://docs.openstack.org/api-ref/identity/v3/index.html#password-authentication-with-unscoped-authorization + python_data = json.loads(IDENTITY_V3_PASSWORD_AUTH_JSON_DATA) + python_data['auth']['identity']['password']['user']['name'] = user + python_data['auth']['identity']['password']['user']['password'] = password + headers = { + 'User-Agent': 'hiwkby-sample', + 'Content-Type': 'application/json' + } + req = urllib.request.Request(url, + json.dumps(python_data).encode('ascii'), + headers, + method="POST") + with urllib.request.urlopen(req) as res: + unscoped_token_id = dict(res.info()).get('X-Subject-Token') + print('unscoped_token_id:[{}]'.format(unscoped_token_id)) + + # scoped token-id + # https://docs.openstack.org/api-ref/identity/v3/index.html?expanded=#token-authentication-with-scoped-authorization + python_data = json.loads(IDENTITY_V3_TOKEN_AUTH_JSON_DATA) + python_data['auth']['identity']['token']['id'] = unscoped_token_id + python_data['auth']['scope']['project']['name'] = project + headers = { + 'User-Agent': 'hiwkby-sample', + 'Content-Type': 'application/json' + } + req = urllib.request.Request(url, + json.dumps(python_data).encode('ascii'), + headers, + method="POST") + with urllib.request.urlopen(req) as res: + scoped_token_id = dict(res.info()).get('X-Subject-Token') + print('scoped_token_id:[{}]'.format(scoped_token_id)) + return scoped_token_id + + + def set_data(val: Path, projectname: str, clustername: str) -> str: + # Set data. + if val.exists() is False: + raise K2hr3Exception(f'path must exist, not {val}') + if val.is_file() is False: + raise K2hr3Exception( + f'path must be a regular file, not {val}') + data = "" + with val.open(encoding='utf-8') as f: # pylint: disable=no-member + line_len = 0 + for line in iter(f.readline, ''): + # 3. replace TROVE_K2HDKC_CLUSTER_NAME with clustername + line = re.sub('__TROVE_K2HDKC_CLUSTER_NAME__', clustername, + line) + # 4. replace TROVE_K2HDKC_TENANT_NAME with projectname + line = re.sub('__TROVE_K2HDKC_TENANT_NAME__', projectname, + line) + line_len += len(line) + if line_len > _MAX_LINE_LENGTH: + raise K2hr3Exception('data too big') + data = "".join([data, line]) # type: ignore + + return data + + + if __name__ == '__main__': + parser = argparse.ArgumentParser(description='k2hr3 token api example') + parser.add_argument( + '--url', + dest='url', + default='http://127.0.0.1/identity/v3/auth/tokens', + help='identity api url. ex) http://127.0.0.1/identity/v3/auth/tokens') # noqa + parser.add_argument('--user', + dest='user', + default='demo', + help='openstack user') + parser.add_argument('--password', + dest='password', + default='password', + help='openstack user password') + parser.add_argument('--project', + dest='project', + default='demo', + help='openstack project') + parser.add_argument('--k2hr3_url', + dest='k2hr3_url', + default='http://localhost:18080', + help='k2hr3 api url') + parser.add_argument('--resource', + dest='resource', + default='k2hdkccluster', + help='resource name') + parser.add_argument('--policy', + dest='policy', + default='k2hdkccluster', + help='policy name') + parser.add_argument('--role', + dest='role', + default='k2hdkccluster', + help='k2hr3 rolename') + + args = parser.parse_args() + + # 1. Gets a openstack token id from openstack identity server + openstack_token = get_scoped_token_id(args.url, args.user, args.password, + args.project) + + # 2. Gets a k2hr3 token from the openstack token + k2hr3_token = K2hr3Token(args.project, openstack_token) + http = K2hr3Http(args.k2hr3_url) + http.POST(k2hr3_token.create()) + + # 3. Makes a new k2hr3 resource + k2hr3_resource = K2hr3Resource(k2hr3_token.token) + k2hr3client_init_py = Path(k2hr3client.__file__) + val = k2hr3client_init_py.parent.joinpath('examples', + 'example_resource.txt') + data = set_data(val, projectname=args.project, clustername=args.resource) + + http.POST( + k2hr3_resource.create_conf_resource( + name=args.resource, + data_type='string', + resource_data=data, + keys={ + "cluster-name": args.resource, + "chmpx-server-port": "8020", + "chmpx-server-ctlport": "8021", + "chmpx-slave-ctlport": "8031" + }, + alias=[] + ) + ) + + # 3.1. Makes a new k2hr3 resource for server + k2hr3_resource_server = K2hr3Resource(k2hr3_token.token) + http.POST( + k2hr3_resource_server.create_conf_resource( + name="/".join([args.resource, "server"]), + data_type='string', + resource_data="", + keys={"chmpx-mode": "SERVER", + "k2hr3-init-packages": "", + "k2hr3-init-packagecloud-packages": "", + "k2hr3-init-systemd-packages": ""}, + alias=[] + ) + ) + + # 3.2. Makes a new k2hr3 resource for slave + k2hr3_resource_slave = K2hr3Resource(k2hr3_token.token) + http.POST( + k2hr3_resource_slave.create_conf_resource( + name="/".join([args.resource, "slave"]), + data_type='string', + resource_data="", + keys={"chmpx-mode": "SLAVE", + "k2hr3-init-packages": "", + "k2hr3-init-packagecloud-packages": "", + "k2hr3-init-systemd-packages": "", + "k2hdkc-dbaas-add-user": 1}, + alias=[] + ) + ) + + # 4. Makes a new k2hr3 policy for the resource + k2hr3_policy = K2hr3Policy(k2hr3_token.token) + SERVER_RESOURCE_PATH = "yrn:yahoo:::{}:resource:{}/server".format( + args.project, args.resource) + SLAVE_RESOURCE_PATH = "yrn:yahoo:::{}:resource:{}/slave".format( + args.project, args.resource) + http.POST( + k2hr3_policy.create( + name=args.policy, + effect='allow', + action=['yrn:yahoo::::action:read'], + resource=[SERVER_RESOURCE_PATH, SLAVE_RESOURCE_PATH], + condition=None, + alias=[] + ) + ) + + # 5. Makes a new k2hr3 role for the policy + POLICY_PATH = "yrn:yahoo:::{}:policy:{}".format(args.project, args.policy) + k2hr3_role = K2hr3Role(k2hr3_token.token) + http.POST( + k2hr3_role.create( + name=args.role, + policies=[POLICY_PATH], + alias=[] + ) + ) + server_role = K2hr3Role(k2hr3_token.token) + http.POST( + server_role.create( + name="/".join([args.role, "server"]), + policies=[], + alias=[] + ) ) - ) - myrole.resp.body // {"result":true... + slave_role = K2hr3Role(k2hr3_token.token) + http.POST( + slave_role.create( + name="/".join([args.role, "slave"]), + policies=[], + alias=[] + ) + ) + + print(slave_role.resp.body) + sys.exit(0) """ diff --git a/src/k2hr3client/service.py b/src/k2hr3client/service.py index bdec56e..bc8852d 100644 --- a/src/k2hr3client/service.py +++ b/src/k2hr3client/service.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/src/k2hr3client/tenant.py b/src/k2hr3client/tenant.py index 56fb757..ec6f66d 100644 --- a/src/k2hr3client/tenant.py +++ b/src/k2hr3client/tenant.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/src/k2hr3client/token.py b/src/k2hr3client/token.py index 41fce31..e95b988 100644 --- a/src/k2hr3client/token.py +++ b/src/k2hr3client/token.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. @@ -23,18 +23,164 @@ .. code-block:: python - # Import modules from k2hr3client package. - from k2hr3client.token import K2hr3Token + # Simple CUI application to get registerpath for k2hdkc dbaas. + from __future__ import (absolute_import, division, print_function, + unicode_literals) + import argparse + import os + import sys + import json + import urllib.parse + import urllib.request + + here = os.path.dirname(__file__) + src_dir = os.path.join(here, '..') + if os.path.exists(src_dir): + sys.path.append(src_dir) + from k2hr3client.http import K2hr3Http + from k2hr3client.token import K2hr3Token + from k2hr3client.token import K2hr3RoleToken + from k2hr3client.token import K2hr3RoleTokenList + + IDENTITY_V3_PASSWORD_AUTH_JSON_DATA = ''' + { + "auth": { + "identity": { + "methods": [ + "password" + ], + "password": { + "user": { + "name": "admin", + "domain": { + "name": "Default" + }, + "password": "devstacker" + } + } } + } + } + ''' + + IDENTITY_V3_TOKEN_AUTH_JSON_DATA = ''' + { + "auth": { + "identity": { + "methods": [ + "token" + ], + "token": { + "id": "" + } + }, + "scope": { + "project": { + "domain": { + "id": "default" + }, + "name": "" + } + } + } + } + ''' + + def get_scoped_token_id(url, user, password, project): + # Get a scoped token id from openstack identity. + # unscoped token-id + # https://docs.openstack.org/api-ref/identity/v3/index.html#password-authentication-with-unscoped-authorization + python_data = json.loads(IDENTITY_V3_PASSWORD_AUTH_JSON_DATA) + python_data['auth']['identity']['password']['user']['name'] = user + python_data['auth']['identity']['password']['user']['password'] = password # noqa + headers = { + 'User-Agent': 'hiwkby-sample', + 'Content-Type': 'application/json' + } + req = urllib.request.Request(url, + json.dumps(python_data).encode('ascii'), + headers, + method="POST") + with urllib.request.urlopen(req) as res: + unscoped_token_id = dict(res.info()).get('X-Subject-Token') + # print('unscoped_token_id:[{}]'.format(unscoped_token_id)) + + # scoped token-id + # https://docs.openstack.org/api-ref/identity/v3/index.html?expanded=#token-authentication-with-scoped-authorization + python_data = json.loads(IDENTITY_V3_TOKEN_AUTH_JSON_DATA) + python_data['auth']['identity']['token']['id'] = unscoped_token_id + python_data['auth']['scope']['project']['name'] = project + headers = { + 'User-Agent': 'hiwkby-sample', + 'Content-Type': 'application/json' + } + req = urllib.request.Request(url, + json.dumps(python_data).encode('ascii'), + headers, + method="POST") + with urllib.request.urlopen(req) as res: + scoped_token_id = dict(res.info()).get('X-Subject-Token') + # print('scoped_token_id:[{}]'.format(scoped_token_id)) + return scoped_token_id + - iaas_project = "demo" - iaas_token = "gAAAAA..." - mytoken = K2hr3Token(iaas_project, iaas_token) + if __name__ == '__main__': + parser = argparse.ArgumentParser(description='k2hr3 token api example') + parser.add_argument( + '--url', + dest='url', + default='http://127.0.0.1/identity/v3/auth/tokens', + help='identity api url. ex) http://127.0.0.1/identity/v3/auth/tokens') # noqa + parser.add_argument('--user', + dest='user', + default='demo', + help='openstack user') + parser.add_argument('--password', + dest='password', + default='password', + help='openstack user password') + parser.add_argument('--project', + dest='project', + default='demo', + help='openstack project') + parser.add_argument('--k2hr3_url', + dest='k2hr3_url', + default='http://localhost:18080', + help='k2hr3 api url') + parser.add_argument('--role', + dest='role', + default='k2hdkccluster', + help='k2hr3 rolename') + args = parser.parse_args() + + # 1. Gets a openstack token id from openstack identity server + openstack_token = get_scoped_token_id(args.url, args.user, args.password, # noqa + args.project) + + # 2. Gets a k2hr3 token from the openstack token + k2hr3_token = K2hr3Token(args.project, openstack_token) + http = K2hr3Http(args.k2hr3_url) + http.POST(k2hr3_token.create()) + + # 3. Gets a k2hr3 role token from the k2hr3 token + k2hr3_role_token = K2hr3RoleToken(k2hr3_token.token, + role=args.role, + expire=0) + http.GET(k2hr3_role_token) + roletoken = k2hr3_role_token.token + print("roletoken {}".format(roletoken)) + + # 4. Gets a k2hr3 role token list from the k2hr3 token + k2hr3_role_token_list = K2hr3RoleTokenList(k2hr3_token.token, + role=args.role, + expand=True) + http.GET(k2hr3_role_token_list) + + # 4. Gets the registerpath of the k2hr3 role token + registerpath = k2hr3_role_token_list.registerpath(roletoken) + print("{}".format(registerpath)) + sys.exit(0) - # POST a request to create a token to K2HR3 Token API. - myhttp = K2hr3Http("http://127.0.0.1:18080") - myhttp.POST(mytoken.create()) - mytoken.token // gAAAAA... """ from enum import Enum diff --git a/src/k2hr3client/userdata.py b/src/k2hr3client/userdata.py index 1598d78..1145388 100644 --- a/src/k2hr3client/userdata.py +++ b/src/k2hr3client/userdata.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/src/k2hr3client/version.py b/src/k2hr3client/version.py index 92953fb..9f8ed4f 100644 --- a/src/k2hr3client/version.py +++ b/src/k2hr3client/version.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/src/tests/__init__.py b/src/tests/__init__.py index 6e95b86..c867d84 100644 --- a/src/tests/__init__.py +++ b/src/tests/__init__.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/src/tests/test_acr.py b/src/tests/test_acr.py index f86735b..9e070d3 100644 --- a/src/tests/test_acr.py +++ b/src/tests/test_acr.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/src/tests/test_api.py b/src/tests/test_api.py index ef821c4..aa1ab70 100644 --- a/src/tests/test_api.py +++ b/src/tests/test_api.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/src/tests/test_extdata.py b/src/tests/test_extdata.py index 1a872e9..be27525 100644 --- a/src/tests/test_extdata.py +++ b/src/tests/test_extdata.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/src/tests/test_list.py b/src/tests/test_list.py index cea7a13..91558f7 100644 --- a/src/tests/test_list.py +++ b/src/tests/test_list.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/src/tests/test_policy.py b/src/tests/test_policy.py index 8da28d2..73ff222 100644 --- a/src/tests/test_policy.py +++ b/src/tests/test_policy.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/src/tests/test_resource.py b/src/tests/test_resource.py index f22ea3f..0888443 100644 --- a/src/tests/test_resource.py +++ b/src/tests/test_resource.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. @@ -45,11 +45,8 @@ def setUp(self): self.base_url = "http://127.0.0.1:18080" self.resource_path = "test_resource_path" self.name = "test_resource" - # self.project = "test_project" self.data_type = 'string' self.resource_data = "testresourcedata" - self.tenant = "mytenant" - self.cluster_name = "mycluster" self.keys = { "cluster-name": "testcluster", "chmpx-server-port": "8020", @@ -97,8 +94,6 @@ def test_resource_create_resource_using_put(self, name = self.name, data_type = self.data_type, resource_data = self.resource_data, - tenant = self.tenant, - cluster_name = self.cluster_name, keys = self.keys, alias = self.alias) httpreq = khttp.K2hr3Http(self.base_url) diff --git a/src/tests/test_role.py b/src/tests/test_role.py index ed610e5..1223fe0 100644 --- a/src/tests/test_role.py +++ b/src/tests/test_role.py @@ -1,15 +1,15 @@ # -*- Coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/src/tests/test_service.py b/src/tests/test_service.py index fb858f9..7d0271e 100644 --- a/src/tests/test_service.py +++ b/src/tests/test_service.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/src/tests/test_tenant.py b/src/tests/test_tenant.py index 898aa93..f0a16b6 100644 --- a/src/tests/test_tenant.py +++ b/src/tests/test_tenant.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/src/tests/test_token.py b/src/tests/test_token.py index ca9b8c3..f693d4c 100644 --- a/src/tests/test_token.py +++ b/src/tests/test_token.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/src/tests/test_userdata.py b/src/tests/test_userdata.py index 8877594..44c713d 100644 --- a/src/tests/test_userdata.py +++ b/src/tests/test_userdata.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. diff --git a/src/tests/test_version.py b/src/tests/test_version.py index dc1db35..33cac4f 100644 --- a/src/tests/test_version.py +++ b/src/tests/test_version.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # -# K2HDKC DBaaS based on Trove +# k2hr3client - Python client for K2HR3 REST API # # Copyright 2020 Yahoo Japan Corporation # Copyright 2024 LY Corporation # -# K2HDKC DBaaS is a Database as a Service compatible with Trove which -# is DBaaS for OpenStack. -# Using K2HR3 as backend and incorporating it into Trove to provide -# DBaaS functionality. K2HDKC, K2HR3, CHMPX and K2HASH are components -# provided as AntPickax. +# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers +# common management information for the cloud. +# K2HR3 can dynamically manage information as "who", "what", "operate". +# These are stored as roles, resources, policies in K2hdkc, and the +# client system can dynamically read and modify these information. # # For the full copyright and license information, please view # the license file that was distributed with this source code. @@ -58,6 +58,27 @@ def test_k2hr3version_repr(self): # Note: The order of _error and _code is unknown! self.assertRegex(repr(myversion), '') + @patch('k2hr3client.http.K2hr3Http._HTTP_REQUEST_METHOD') + def test_k2hr3version_root_get_ok(self, mock_HTTP_REQUEST_METHOD): + """Get root path.""" + myversion = kversion.K2hr3Version() + self.assertEqual(myversion.name, "") + myversion.get() + httpreq = khttp.K2hr3Http(self.base_url) + self.assertTrue(httpreq.GET(myversion)) + + # 1. assert URL + self.assertEqual(httpreq.url, f"{self.base_url}/") + # 2. assert URL params + self.assertEqual(myversion.urlparams, None) + # 3. assert Request header + headers = { + 'Content-Type': 'application/json', + } + self.assertEqual(myversion.headers, headers) + # 4. assert Request body + self.assertEqual(myversion.body, None) + @patch('k2hr3client.http.K2hr3Http._HTTP_REQUEST_METHOD') def test_k2hr3version_root_get_v1_ok(self, mock_HTTP_REQUEST_METHOD): """Get root path."""