Skip to content

Commit

Permalink
Release 1.1.1 (#7)
Browse files Browse the repository at this point in the history
This PR
* removes hardcodings
* adds configuration interface
* updates docs
  • Loading branch information
hiwakaba authored Oct 9, 2024
1 parent 5bfc92a commit 2a709a1
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 22 deletions.
7 changes: 7 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
History
=======

1.1.1 (2024-10-09)
-------------------

* Removes hardcodings
* Adds Configuration Interface
* Updates the docs

1.1.0 (2024-10-04)
-------------------

Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
include HISTORY.rst
include LICENSE
include README.rst
include conf/k2hr3client.ini

recursive-include k2hr3client *
recursive-exclude * __pycache__
Expand Down
19 changes: 19 additions & 0 deletions conf/k2hr3client.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[DEFAULT]
debug = False
iaas_url = "http://172.24.4.1"
iaas_project = "demo"
iaas_user = "demo"
iaas_password = "password"
log_file = sys.stdout
log_dir = logs
log_level = logging.INFO

[k2hr3]
api_url = "http://127.0.0.1:18080"
api_version = "v1"

[http]
timeout_seconds = 30
retry_interval_seconds = 60
max_retries = 3
allow_self_signed_cert = True
46 changes: 29 additions & 17 deletions docs/locale/ja/LC_MESSAGES/history.po
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ msgid ""
msgstr ""
"Project-Id-Version: k2hr3client \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-10-04 20:13+0900\n"
"POT-Creation-Date: 2024-10-09 15:10+0900\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: ja\n"
Expand All @@ -26,62 +26,74 @@ msgid "History"
msgstr "歴史"

#: ../../../HISTORY.rst:6
msgid "1.1.0 (2024-10-04)"
msgid "1.1.1 (2024-10-09)"
msgstr ""

#: ../../../HISTORY.rst:8
msgid "Removes the deprecated Interfaces"
msgstr "非推奨のインタフェースを削除"
msgid "Removes hardcodings"
msgstr "ハードコーディングを削除"

#: ../../../HISTORY.rst:9
msgid "Removes the examples"
msgstr "例示プログラムの削除"
msgid "Adds Configuration Interface"
msgstr "設定用インターフェースを追加"

#: ../../../HISTORY.rst:10
#: ../../../HISTORY.rst:10 ../../../HISTORY.rst:17
msgid "Updates the docs"
msgstr "ドキュメントの更新"

#: ../../../HISTORY.rst:13
msgid "1.0.3 (2024-10-03)"
msgid "1.1.0 (2024-10-04)"
msgstr ""

#: ../../../HISTORY.rst:15
msgid "Removes the deprecated Interfaces"
msgstr "非推奨のインタフェースを削除"

#: ../../../HISTORY.rst:16
msgid "Removes the examples"
msgstr "例示プログラムの削除"

#: ../../../HISTORY.rst:20
msgid "1.0.3 (2024-10-03)"
msgstr ""

#: ../../../HISTORY.rst:22
msgid "Fixes the K2hr3 API version"
msgstr "K2hr3 APIのバージョンを固定化"

#: ../../../HISTORY.rst:16
#: ../../../HISTORY.rst:23
msgid "Deprecates K2hr3Resource.create_conf_resource params"
msgstr "K2hr3Resource.create_conf_resourceのパラメータを一部非推奨化"

#: ../../../HISTORY.rst:19
#: ../../../HISTORY.rst:26
msgid "1.0.2 (2024-09-26)"
msgstr ""

#: ../../../HISTORY.rst:21
#: ../../../HISTORY.rst:28
msgid "Fixes lint errors"
msgstr "静的解析ツールのエラーを修正"

#: ../../../HISTORY.rst:24
#: ../../../HISTORY.rst:31
msgid "1.0.1 (2024-09-25)"
msgstr ""

#: ../../../HISTORY.rst:26
#: ../../../HISTORY.rst:33
msgid "Fixes resource API bugs"
msgstr "Resource APIの不具合を修正"

#: ../../../HISTORY.rst:29
#: ../../../HISTORY.rst:36
msgid "1.0.0 (2024-08-28)"
msgstr ""

#: ../../../HISTORY.rst:31
#: ../../../HISTORY.rst:38
msgid "Supports the other APIs"
msgstr "他のAPIをサポート"

#: ../../../HISTORY.rst:34
#: ../../../HISTORY.rst:41
msgid "0.0.1 (2020-08-28)"
msgstr ""

#: ../../../HISTORY.rst:36
#: ../../../HISTORY.rst:43
msgid "Supports Token, Resource, Policy and Role API"
msgstr "トークン、リソース、ポリシーおよびロールAPIをサポート"

63 changes: 62 additions & 1 deletion src/k2hr3client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
"""K2HR3 Python Client of Token API."""

__author__ = 'Hirotaka Wakabayashi <[email protected]>'
__version__ = '1.1.0'
__version__ = '1.1.1'

import configparser
from pathlib import Path
import sys

if sys.platform.startswith('win'):
Expand All @@ -39,6 +41,65 @@ def get_version() -> str:
return __version__


# 1. Defines the default config as a package level variable.
CONFIG = configparser.ConfigParser()
# [DEFAULT]
# debug = False
# iaas_url = http://172.24.4.1
# iaas_project = demo
# iaas_user = demo
# iaas_password = password
# log_file = sys.stdout
# log_dir = logs
# log_format = %(asctime)-15s %(levelname)s %(name)s %(message)s
# log_level = logging.INFO
default_section = CONFIG['DEFAULT']
default_section['debug'] = "False"
default_section['iaas_url'] = "http://172.24.4.1"
default_section['iaas_project'] = "demo"
default_section['iaas_user'] = "demo"
default_section['iaas_password'] = "password"
default_section['log_file'] = "sys.stderr"
default_section['log_dir'] = "logs"
default_section['log_level'] = "logging.INFO"

# [k2hr3]
# api_url = "http://127.0.0.1:18080"
# api_version = "v1"
CONFIG['k2hr3'] = {}
k2hr3_section = CONFIG['k2hr3']
k2hr3_section['api_url'] = "http://127.0.0.1:18080"
k2hr3_section['api_version'] = "v1"

# [http]
# timeout_seconds = 30
# retry_interval_seconds = 60
# max_retries = 3
# allow_self_signed_cert = True
CONFIG['http'] = {}
http_section = CONFIG['http']
http_section['timeout_seconds'] = "30"
http_section['retry_interval_seconds'] = "60"
http_section['max_retries'] = "3"
http_section['allow_self_signed_cert'] = "True"

# 2. Overrides the default config by the config file.
# Find the config using precedence of the location:
# ./k2hr3client.ini
# ~/.k2hr3client.ini
# /etc/antpickax/k2hr3client.ini
# NOTE:
# Using the configuration value may occur KeyError.
# All values are string. Use getboolean or something.
config_path = [Path("k2hr3client.ini"),
Path(Path.home() / '.k2hr3client.ini'),
Path('/etc/antpickax/k2hr3client.ini')]
for my_config in config_path:
if my_config.is_file():
# Override the value if the key is defined.
CONFIG.read(my_config.absolute())
break

#
# Local variables:
# tab-width: 4
Expand Down
9 changes: 5 additions & 4 deletions src/k2hr3client/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

from k2hr3client.api import K2hr3HTTPMethod, K2hr3Api
from k2hr3client.exception import K2hr3Exception
from k2hr3client import CONFIG

LOG = logging.getLogger(__name__)

Expand All @@ -75,12 +76,12 @@ class K2hr3Http(): # pylint: disable=too-many-instance-attributes
def __init__(self, baseurl: str) -> None:
"""Init the members."""
self._set_baseurl(baseurl)
self._timeout_seconds = 30
self._timeout_seconds = CONFIG['http'].getint('timeout_seconds')
self._url = None # type: Optional[str]
self._urlparams = None # type: Optional[str]
self._retry_interval_seconds = 60 # type: int
self._retries = 3 # type: int
self._allow_self_signed_cert = True # type: bool
self._retry_interval_seconds = CONFIG['http'].getint('retry_interval_seconds') # noqa
self._retries = CONFIG['http'].getint('retries')
self._allow_self_signed_cert = CONFIG['http'].getboolean('allow_self_signed_cert') # noqa

def __repr__(self) -> str:
"""Represent the members."""
Expand Down

0 comments on commit 2a709a1

Please sign in to comment.