Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
History
=======

1.1.3 (2025-09-18)
-------------------

* Removes the eol product from dependencies by @hiwakaba
* Updates packages by @hiwakaba
* Update dependencies by @hiwakaba
* Update dependencies by @hiwakaba
* Updates requests by @hiwakaba
* Fix the docs by @hiwakaba

1.1.2 (2024-10-11)
-------------------

Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Let's try to get a token and create a resource.::
>>> k2hr3_token_url = "http://127.0.0.1:18080"
>>> myhttp = K2hr3Http(k2hr3_token_url)
>>> myhttp.POST(mytoken.create())
>>> mytoken.token // k2hr3 token
>>> mytoken.token # k2hr3 token
>>>
>>> from k2hr3client.resource import K2hr3Resource
>>> k2hr3_resource_name = "test_resource"
Expand All @@ -74,7 +74,7 @@ Let's try to get a token and create a resource.::
... "chmpx-slave-ctrlport": "8031"},
... alias=[])
... )
>>> myresource.resp.body // {"result":true...
>>> myresource.resp.body # {"result":true...


Settings
Expand Down
2 changes: 1 addition & 1 deletion src/k2hr3client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"""K2HR3 Python Client of Token API."""

__author__ = 'Hirotaka Wakabayashi <hiwakaba@lycorp.co.jp>'
__version__ = '1.1.2'
__version__ = '1.1.3'

import configparser
import logging
Expand Down
2 changes: 1 addition & 1 deletion src/k2hr3client/acr.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# 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...
mytoken.token # gAAAAA...

# POST a request to add member to K2HR3 ACR API.
myacr = K2hr3Acr(mytoken.token, "service")
Expand Down
1 change: 1 addition & 0 deletions src/k2hr3client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
# Import modules from k2hr3client package
from k2hr3client import version
v = version.K2hr3Version()
v.get()
from k2hr3client import http as khttp
httpreq = khttp.K2hr3Http('http://127.0.0.1:18080')

Expand Down
4 changes: 2 additions & 2 deletions src/k2hr3client/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
# 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...
mytoken.token # gAAAAA...

# GET a request to get list from K2HR3 List API.
mylist = K2hr3List(mytoken.token, "service")
myhttp.GET(mylist.get())
mylist.resp.body // {"result":true...
mylist.resp.body # {"result":true...

"""

Expand Down
4 changes: 2 additions & 2 deletions src/k2hr3client/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# 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...
mytoken.token # gAAAAA...

# POST request to get a K2HR3 Policy API.
mypolicy = K2hr3Policy(mytoken.token)
Expand All @@ -50,7 +50,7 @@
alias=[]
)
)
mypolicy.resp.body // {"result":true...
mypolicy.resp.body # {"result":true...

"""

Expand Down
24 changes: 18 additions & 6 deletions src/k2hr3client/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# 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...
mytoken.token # gAAAAA...

# POST a request to create a K2HDKC resource.
myresource = K2hr3Resource(mytoken.token)
Expand All @@ -51,7 +51,7 @@
"chmpx-slave-ctrlport": "8031"},
alias=[])
)
myresource.resp.body // {"result":true...
myresource.resp.body # {"result":true...

"""

Expand Down Expand Up @@ -350,6 +350,15 @@ def resource_path(self, val): # type: ignore # noqa: F811
if getattr(self, '_resource_path', None) is None:
self._resource_path = val

@staticmethod
def json_dumps(params):
"""Return the json params after deleting None data."""
for k in list(params.keys()):
if params[k] is None:
del params[k]
json_params = json.dumps(params)
return json_params

#
# abstract methos that must be implemented in subclasses
#
Expand Down Expand Up @@ -380,29 +389,32 @@ def _api_path(self, method: K2hr3HTTPMethod) -> Optional[str]: # pylint: disable
return f'{self.version}/{self.basepath}'
return f'{self.version}/{self.basepath}/{self.resource_path}'
if method == K2hr3HTTPMethod.GET:
# NOTE(hiwkby): service should not be passed if it is None.
if self.api_id == 3:
self.urlparams = json.dumps({
self.urlparams = K2hr3Resource.json_dumps({
'expand': self.expand,
'service': self.service
})
return f'{self.version}/{self.basepath}/{self.resource_path}'
if self.api_id == 4:
self.urlparams = json.dumps({
self.urlparams = K2hr3Resource.json_dumps({
'type': self.data_type,
'keys': self.keys,
'service': self.service
})
return f'{self.version}/{self.basepath}/{self.resource_path}'
if method == K2hr3HTTPMethod.HEAD:
# NOTE(hiwkby): service should not be passed if it is None.
if self.api_id == 5:
self.urlparams = json.dumps({
self.urlparams = K2hr3Resource.json_dumps({
'type': self.data_type,
'keys': self.keys,
'service': self.service
})
return f'{self.version}/{self.basepath}/{self.resource_path}'
# NOTE(hiwkby): service should not be passed if it is None.
if self.api_id == 6:
self.urlparams = json.dumps({
self.urlparams = K2hr3Resource.json_dumps({
'port': self.port,
'cuk': self.cuk,
'role': self.role,
Expand Down
4 changes: 2 additions & 2 deletions src/k2hr3client/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# 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...
mytoken.token # gAAAAA...

# POST a request to create a service to K2HR3 Service API.
myservice = K2hr3Service(mytoken.token, "test_service")
Expand All @@ -44,7 +44,7 @@
verify = "http://example.com/verify_url.php"
)
)
myservice.resp.body // {"result":true...
myservice.resp.body # {"result":true...

"""

Expand Down
4 changes: 2 additions & 2 deletions src/k2hr3client/tenant.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# 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...
mytoken.token # gAAAAA...

# POST a request to create a tenant to K2HR3 Tenant API.
mytenant = K2hr3Tenant(mytoken.token)
Expand All @@ -47,7 +47,7 @@
display = "test tenant display"
)
)
mytenant.resp.body // {"result":true...
mytenant.resp.body # {"result":true...

"""

Expand Down
2 changes: 1 addition & 1 deletion src/k2hr3client/userdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
myhttp.GET(
myuserdata.provides_userdata_script()
)
myuserdata.resp.body // {"result":true...
myuserdata.resp.body # {"result":true...

"""
import logging
Expand Down
1 change: 1 addition & 0 deletions src/k2hr3client/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# Import modules from k2hr3client package
from k2hr3client import version
v = version.K2hr3Version()
v.get()
from k2hr3client import http as khttp
httpreq = khttp.K2hr3Http('http://127.0.0.1:18080')

Expand Down
36 changes: 36 additions & 0 deletions src/tests/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,42 @@ def test_resource_get_resource_using_get(self, mock_HTTP_REQUEST_METHOD):
# 4. assert Request body
self.assertEqual(myresource.body, None)

#
# TestCases using GET Requests that include service=None
#
# GET
# http(s)://API SERVER:PORT/v1/resource/resource path or yrn full resource path?urlarg # noqa
# http(s)://API SERVER:PORT/v1/resource/resource path or yrn full resource path?urlarg # noqa
# http(s)://API SERVER:PORT/v1/resource/yrn full resource path?urlarg
#
@patch('k2hr3client.http.K2hr3Http._HTTP_REQUEST_METHOD')
def test_resource_get_resource_using_get_service_none(self, mock_HTTP_REQUEST_METHOD):
myresource = kresource.K2hr3Resource("token",
resource_path=self.resource_path)
self.assertEqual(myresource.r3token, "token")
"""Get root path."""
myresource.get(self.expand, None)
httpreq = khttp.K2hr3Http(self.base_url)
self.assertTrue(httpreq.GET(myresource))

# 1. assert URL
self.assertEqual(httpreq.url, f"{self.base_url}/v1/resource/{self.resource_path}") # noqa
# 2. assert URL params
# NOTE(hiwkby) urlparams should not include the service param.
s_s_urlparams_without_service = {
'expand': self.expand
}
s_urlparams_without_service = urllib.parse.urlencode(s_s_urlparams_without_service)
self.assertEqual(httpreq.urlparams, f"{s_urlparams_without_service}")
# 3. assert Request headers
headers = {
'Content-Type': 'application/json',
'x-auth-token': 'U=token'
}
self.assertEqual(myresource.headers, headers)
# 4. assert Request body
self.assertEqual(myresource.body, None)

#
# TestCases using GET Requests
#
Expand Down