Skip to content

Commit 2a709a1

Browse files
authored
Release 1.1.1 (#7)
This PR * removes hardcodings * adds configuration interface * updates docs
1 parent 5bfc92a commit 2a709a1

File tree

6 files changed

+123
-22
lines changed

6 files changed

+123
-22
lines changed

HISTORY.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
History
33
=======
44

5+
1.1.1 (2024-10-09)
6+
-------------------
7+
8+
* Removes hardcodings
9+
* Adds Configuration Interface
10+
* Updates the docs
11+
512
1.1.0 (2024-10-04)
613
-------------------
714

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
include HISTORY.rst
44
include LICENSE
55
include README.rst
6+
include conf/k2hr3client.ini
67

78
recursive-include k2hr3client *
89
recursive-exclude * __pycache__

conf/k2hr3client.ini

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[DEFAULT]
2+
debug = False
3+
iaas_url = "http://172.24.4.1"
4+
iaas_project = "demo"
5+
iaas_user = "demo"
6+
iaas_password = "password"
7+
log_file = sys.stdout
8+
log_dir = logs
9+
log_level = logging.INFO
10+
11+
[k2hr3]
12+
api_url = "http://127.0.0.1:18080"
13+
api_version = "v1"
14+
15+
[http]
16+
timeout_seconds = 30
17+
retry_interval_seconds = 60
18+
max_retries = 3
19+
allow_self_signed_cert = True

docs/locale/ja/LC_MESSAGES/history.po

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ msgid ""
1010
msgstr ""
1111
"Project-Id-Version: k2hr3client \n"
1212
"Report-Msgid-Bugs-To: \n"
13-
"POT-Creation-Date: 2024-10-04 20:13+0900\n"
13+
"POT-Creation-Date: 2024-10-09 15:10+0900\n"
1414
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1515
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1616
"Language: ja\n"
@@ -26,62 +26,74 @@ msgid "History"
2626
msgstr "歴史"
2727

2828
#: ../../../HISTORY.rst:6
29-
msgid "1.1.0 (2024-10-04)"
29+
msgid "1.1.1 (2024-10-09)"
3030
msgstr ""
3131

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

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

40-
#: ../../../HISTORY.rst:10
40+
#: ../../../HISTORY.rst:10 ../../../HISTORY.rst:17
4141
msgid "Updates the docs"
4242
msgstr "ドキュメントの更新"
4343

4444
#: ../../../HISTORY.rst:13
45-
msgid "1.0.3 (2024-10-03)"
45+
msgid "1.1.0 (2024-10-04)"
4646
msgstr ""
4747

4848
#: ../../../HISTORY.rst:15
49+
msgid "Removes the deprecated Interfaces"
50+
msgstr "非推奨のインタフェースを削除"
51+
52+
#: ../../../HISTORY.rst:16
53+
msgid "Removes the examples"
54+
msgstr "例示プログラムの削除"
55+
56+
#: ../../../HISTORY.rst:20
57+
msgid "1.0.3 (2024-10-03)"
58+
msgstr ""
59+
60+
#: ../../../HISTORY.rst:22
4961
msgid "Fixes the K2hr3 API version"
5062
msgstr "K2hr3 APIのバージョンを固定化"
5163

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

56-
#: ../../../HISTORY.rst:19
68+
#: ../../../HISTORY.rst:26
5769
msgid "1.0.2 (2024-09-26)"
5870
msgstr ""
5971

60-
#: ../../../HISTORY.rst:21
72+
#: ../../../HISTORY.rst:28
6173
msgid "Fixes lint errors"
6274
msgstr "静的解析ツールのエラーを修正"
6375

64-
#: ../../../HISTORY.rst:24
76+
#: ../../../HISTORY.rst:31
6577
msgid "1.0.1 (2024-09-25)"
6678
msgstr ""
6779

68-
#: ../../../HISTORY.rst:26
80+
#: ../../../HISTORY.rst:33
6981
msgid "Fixes resource API bugs"
7082
msgstr "Resource APIの不具合を修正"
7183

72-
#: ../../../HISTORY.rst:29
84+
#: ../../../HISTORY.rst:36
7385
msgid "1.0.0 (2024-08-28)"
7486
msgstr ""
7587

76-
#: ../../../HISTORY.rst:31
88+
#: ../../../HISTORY.rst:38
7789
msgid "Supports the other APIs"
7890
msgstr "他のAPIをサポート"
7991

80-
#: ../../../HISTORY.rst:34
92+
#: ../../../HISTORY.rst:41
8193
msgid "0.0.1 (2020-08-28)"
8294
msgstr ""
8395

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

src/k2hr3client/__init__.py

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
"""K2HR3 Python Client of Token API."""
2323

2424
__author__ = 'Hirotaka Wakabayashi <hiwakaba@lycorp.co.jp>'
25-
__version__ = '1.1.0'
25+
__version__ = '1.1.1'
2626

27+
import configparser
28+
from pathlib import Path
2729
import sys
2830

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

4143

44+
# 1. Defines the default config as a package level variable.
45+
CONFIG = configparser.ConfigParser()
46+
# [DEFAULT]
47+
# debug = False
48+
# iaas_url = http://172.24.4.1
49+
# iaas_project = demo
50+
# iaas_user = demo
51+
# iaas_password = password
52+
# log_file = sys.stdout
53+
# log_dir = logs
54+
# log_format = %(asctime)-15s %(levelname)s %(name)s %(message)s
55+
# log_level = logging.INFO
56+
default_section = CONFIG['DEFAULT']
57+
default_section['debug'] = "False"
58+
default_section['iaas_url'] = "http://172.24.4.1"
59+
default_section['iaas_project'] = "demo"
60+
default_section['iaas_user'] = "demo"
61+
default_section['iaas_password'] = "password"
62+
default_section['log_file'] = "sys.stderr"
63+
default_section['log_dir'] = "logs"
64+
default_section['log_level'] = "logging.INFO"
65+
66+
# [k2hr3]
67+
# api_url = "http://127.0.0.1:18080"
68+
# api_version = "v1"
69+
CONFIG['k2hr3'] = {}
70+
k2hr3_section = CONFIG['k2hr3']
71+
k2hr3_section['api_url'] = "http://127.0.0.1:18080"
72+
k2hr3_section['api_version'] = "v1"
73+
74+
# [http]
75+
# timeout_seconds = 30
76+
# retry_interval_seconds = 60
77+
# max_retries = 3
78+
# allow_self_signed_cert = True
79+
CONFIG['http'] = {}
80+
http_section = CONFIG['http']
81+
http_section['timeout_seconds'] = "30"
82+
http_section['retry_interval_seconds'] = "60"
83+
http_section['max_retries'] = "3"
84+
http_section['allow_self_signed_cert'] = "True"
85+
86+
# 2. Overrides the default config by the config file.
87+
# Find the config using precedence of the location:
88+
# ./k2hr3client.ini
89+
# ~/.k2hr3client.ini
90+
# /etc/antpickax/k2hr3client.ini
91+
# NOTE:
92+
# Using the configuration value may occur KeyError.
93+
# All values are string. Use getboolean or something.
94+
config_path = [Path("k2hr3client.ini"),
95+
Path(Path.home() / '.k2hr3client.ini'),
96+
Path('/etc/antpickax/k2hr3client.ini')]
97+
for my_config in config_path:
98+
if my_config.is_file():
99+
# Override the value if the key is defined.
100+
CONFIG.read(my_config.absolute())
101+
break
102+
42103
#
43104
# Local variables:
44105
# tab-width: 4

src/k2hr3client/http.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151

5252
from k2hr3client.api import K2hr3HTTPMethod, K2hr3Api
5353
from k2hr3client.exception import K2hr3Exception
54+
from k2hr3client import CONFIG
5455

5556
LOG = logging.getLogger(__name__)
5657

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

8586
def __repr__(self) -> str:
8687
"""Represent the members."""

0 commit comments

Comments
 (0)