Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a1ec146

Browse files
author
ajoino
authoredSep 29, 2021
Merge pull request #32 from gehwolf/fix_service_registration
Fix service registration for decorated member methods.
2 parents 9f6409b + b2a17a5 commit a1ec146

File tree

3 files changed

+101
-10
lines changed

3 files changed

+101
-10
lines changed
 

‎arrowhead_client/client/client_async.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import traceback
12
import arrowhead_client.client.core_service_forms.client
23
from arrowhead_client import errors as errors
34
from arrowhead_client.client import core_service_responses as responses
@@ -113,9 +114,12 @@ async def _register_all_services(self):
113114
try:
114115
await self._register_service(rule.provided_service)
115116
except errors.CoreServiceInputError as e:
116-
# TODO: logging
117117
if str(e).endswith('already exists.'):
118118
rule.is_provided = True
119+
else:
120+
print(f"ERROR: {__name__} failed to register provider: {e}")
121+
traceback.print_exception(type(e), e, e.__traceback__)
122+
119123
else:
120124
rule.is_provided = True
121125

‎arrowhead_client/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def make(
143143
return cls(
144144
service_definition=service_definition,
145145
service_uri=service_uri,
146-
interface=ServiceInterface(
146+
interface=ServiceInterface.with_access_policy(
147147
protocol,
148148
access_policy,
149149
payload_format,
Lines changed: 95 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,114 @@
11
from arrowhead_client.client.implementations import SyncClient
22
from arrowhead_client.client import provided_service
33

4-
def test_provided_service():
4+
5+
def test_provided_service_insecure_with_service_descriptor():
6+
class CustomClient(SyncClient):
7+
def __init__(self, *args, format='', **kwargs):
8+
super().__init__(*args, **kwargs)
9+
self.format = format
10+
11+
@provided_service(
12+
service_definition='hello-arrowhead',
13+
service_uri='hello',
14+
protocol='HTTP',
15+
method='GET',
16+
payload_format='JSON',
17+
access_policy='NOT_SECURE',
18+
)
19+
def service_function(self, request):
20+
return {'fmt': self.format}
21+
22+
test_client = CustomClient.create(
23+
'custom_client', '127.0.0.1', 1337, format='1Ab')
24+
25+
test_client.setup()
26+
27+
rule = list(test_client.registration_rules)[0]
28+
29+
assert rule.service_definition == 'hello-arrowhead'
30+
assert rule.provided_service.interface.dto() == "HTTP-INSECURE-JSON"
31+
assert rule.provided_service.access_policy == "NOT_SECURE"
32+
33+
34+
def test_provided_service_secure_with_service_descriptor():
535
class CustomClient(SyncClient):
636
def __init__(self, *args, format='', **kwargs):
737
super().__init__(*args, **kwargs)
838
self.format = format
939

1040
@provided_service(
11-
service_definition='hello-arrowhead',
12-
service_uri='hello',
13-
protocol='HTTP',
14-
method='GET',
15-
payload_format='JSON',
16-
access_policy='NOT_SECURE',
41+
service_definition='hello-arrowhead',
42+
service_uri='hello',
43+
protocol='HTTP',
44+
method='GET',
45+
payload_format='JSON',
46+
access_policy='CERTIFICATE',
1747
)
1848
def service_function(self, request):
1949
return {'fmt': self.format}
2050

21-
test_client = CustomClient.create('custom_client', '127.0.0.1', 1337, format='1Ab')
51+
test_client = CustomClient.create(
52+
'custom_client', '127.0.0.1', 1337, format='1Ab')
2253

2354
test_client.setup()
2455

2556
rule = list(test_client.registration_rules)[0]
2657

2758
assert rule.service_definition == 'hello-arrowhead'
59+
assert rule.provided_service.interface.dto() == "HTTP-SECURE-JSON"
60+
assert rule.provided_service.access_policy == "CERTIFICATE"
61+
62+
63+
def test_provided_service_insecure_with_function_decorator():
64+
class CustomClient(SyncClient):
65+
def __init__(self, *args, format='', **kwargs):
66+
super().__init__(*args, **kwargs)
67+
self.format = format
68+
69+
test_client = CustomClient.create(
70+
'custom_client', '127.0.0.1', 1337, format='1Ab')
71+
72+
@test_client.provided_service(
73+
service_definition='hello-arrowhead',
74+
service_uri='hello',
75+
protocol='HTTP',
76+
method='GET',
77+
payload_format='JSON',
78+
access_policy='NOT_SECURE',
79+
)
80+
def service_function(request):
81+
return {'fmt': '1Ab'}
82+
83+
rule = list(test_client.registration_rules)[0]
84+
85+
assert rule.service_definition == 'hello-arrowhead'
86+
assert rule.provided_service.interface.dto() == "HTTP-INSECURE-JSON"
87+
assert rule.provided_service.access_policy == "NOT_SECURE"
88+
89+
90+
def test_provided_service_secure_with_function_decorator():
91+
class CustomClient(SyncClient):
92+
def __init__(self, *args, format='', **kwargs):
93+
super().__init__(*args, **kwargs)
94+
self.format = format
95+
96+
test_client = CustomClient.create(
97+
'custom_client', '127.0.0.1', 1337, format='1Ab')
98+
99+
@test_client.provided_service(
100+
service_definition='hello-arrowhead',
101+
service_uri='hello',
102+
protocol='HTTP',
103+
method='GET',
104+
payload_format='JSON',
105+
access_policy='CERTIFICATE',
106+
)
107+
def service_function(request):
108+
return {'fmt': '1Ab'}
109+
110+
rule = list(test_client.registration_rules)[0]
111+
112+
assert rule.service_definition == 'hello-arrowhead'
113+
assert rule.provided_service.interface.dto() == "HTTP-SECURE-JSON"
114+
assert rule.provided_service.access_policy == "CERTIFICATE"

0 commit comments

Comments
 (0)
Please sign in to comment.