Skip to content

Commit 40799ae

Browse files
authored
fix: Adjustting asyncapi and requirements versions (#186)
* fix: Adjustting asyncapi and requirements versions * Correct marker * Split requirements correctly * Use proper requirements parsing method * Do not use env markers
1 parent a5df034 commit 40799ae

14 files changed

+40
-42
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def admin_error(e):
8383
Example specification located at `./docs/asyncapi.yaml`:
8484

8585
```yaml
86-
asyncapi: 2.2.0
86+
asyncapi: 2.3.0
8787

8888
info:
8989
title: User Account Service
@@ -176,7 +176,7 @@ Without Asynction, one would need to add additional boilerplate to register the
176176

177177
## Security (Authentication and Authorization)
178178

179-
Asynction supports authentication of incoming connections through the security mechanisms specified in the AsyncAPI spec of an application. See [this guide](https://www.asyncapi.com/docs/getting-started/security) on how to add security as part of an API specification. To take advantage of this feature, a security handler callable should be attached to each security scheme definition under the [components](https://www.asyncapi.com/docs/specifications/v2.2.0#componentsObjectSecuritySchemes) section. To attach a security handler(s), see the [security specification extention](#security-handers) section below.
179+
Asynction supports authentication of incoming connections through the security mechanisms specified in the AsyncAPI spec of an application. See [this guide](https://www.asyncapi.com/docs/getting-started/security) on how to add security as part of an API specification. To take advantage of this feature, a security handler callable should be attached to each security scheme definition under the [components](https://www.asyncapi.com/docs/specifications/v2.3.0#componentsObjectSecuritySchemes) section. To attach a security handler(s), see the [security specification extention](#security-handers) section below.
180180

181181
The security handler callable(s) will be called upon every new client connection and MUST return a [`SecurityInfo`](https://asynction.dedouss.is/#asynction.SecurityInfo) typed dictionary (which allows extra keys). Asynction then validates this returned dictionary, refusing the connection to any unauthenticated/unauthorised requests. Finally, the validated `SecurityInfo` dictionary is passed to the connection handler as an extra `token_info` kwarg, to allow further/custom processing if needed.
182182

@@ -336,7 +336,7 @@ In the future, the Message Ack Object may be extended with extra fields to enabl
336336

337337
### Security handers
338338

339-
In order to support the [AuthN/AuthZ functionality](#security-authentication-and-authorization) of asynction, the [Security Scheme Object](https://www.asyncapi.com/docs/specifications/v2.2.0#securitySchemeObject) needs to be extended as follows:
339+
In order to support the [AuthN/AuthZ functionality](#security-authentication-and-authorization) of asynction, the [Security Scheme Object](https://www.asyncapi.com/docs/specifications/v2.3.0#securitySchemeObject) needs to be extended as follows:
340340

341341
- A Security Scheme Object of `oauth2` type MUST include the `x-tokenInfoFunc` field.
342342
- A Security Scheme Object of `oauth2` type MAY include the `x-scopeValidateFunc` field.

asynction/types.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class HTTPAuthenticationScheme(Enum):
3434

3535
class OAuth2FlowType(Enum):
3636
"""
37-
https://www.asyncapi.com/docs/specifications/v2.2.0#oauthFlowsObject
37+
https://www.asyncapi.com/docs/specifications/v2.3.0#oauthFlowsObject
3838
"""
3939

4040
IMPLICIT = "implicit"
@@ -46,7 +46,7 @@ class OAuth2FlowType(Enum):
4646
@dataclass
4747
class OAuth2Flow:
4848
"""
49-
https://www.asyncapi.com/docs/specifications/v2.2.0#oauthFlowObject
49+
https://www.asyncapi.com/docs/specifications/v2.3.0#oauthFlowObject
5050
"""
5151

5252
scopes: Mapping[str, str]
@@ -126,7 +126,7 @@ def supported_scopes(self) -> Iterator[str]:
126126

127127
class SecuritySchemesType(Enum):
128128
"""
129-
https://www.asyncapi.com/docs/specifications/v2.2.0#securitySchemeObjectType
129+
https://www.asyncapi.com/docs/specifications/v2.3.0#securitySchemeObjectType
130130
"""
131131

132132
USER_PASSWORD = "userPassword"
@@ -146,7 +146,7 @@ class SecuritySchemesType(Enum):
146146

147147
class ApiKeyLocation(Enum):
148148
"""
149-
https://www.asyncapi.com/docs/specifications/v2.2.0#securitySchemeObject
149+
https://www.asyncapi.com/docs/specifications/v2.3.0#securitySchemeObject
150150
"""
151151

152152
USER = "user"
@@ -159,7 +159,7 @@ class ApiKeyLocation(Enum):
159159
@dataclass
160160
class SecurityScheme:
161161
"""
162-
https://www.asyncapi.com/docs/specifications/v2.2.0#securitySchemeObject
162+
https://www.asyncapi.com/docs/specifications/v2.3.0#securitySchemeObject
163163
"""
164164

165165
type: SecuritySchemesType
@@ -264,7 +264,7 @@ class MessageAck:
264264
@dataclass
265265
class Message:
266266
"""
267-
https://www.asyncapi.com/docs/specifications/2.2.0#messageObject
267+
https://www.asyncapi.com/docs/specifications/2.3.0#messageObject
268268
269269
The above message object is extended as follows:
270270
* `x-handler`: Allows the coupling of the message specification to
@@ -275,7 +275,7 @@ class Message:
275275
to the callback of the `emit`/`send` function. Deserialized to `x_ack`.
276276
277277
The extentions are implemented as per:
278-
https://www.asyncapi.com/docs/specifications/2.2.0#specificationExtensions
278+
https://www.asyncapi.com/docs/specifications/2.3.0#specificationExtensions
279279
"""
280280

281281
name: str
@@ -326,7 +326,7 @@ def with_name(self, name: str) -> Optional[Message]:
326326

327327
@dataclass
328328
class Operation:
329-
"""https://www.asyncapi.com/docs/specifications/2.2.0#operationObject"""
329+
"""https://www.asyncapi.com/docs/specifications/2.3.0#operationObject"""
330330

331331
message: OneOfMessages
332332

@@ -345,7 +345,7 @@ class WebSocketsChannelBindings:
345345

346346
@dataclass
347347
class ChannelBindings:
348-
"""https://www.asyncapi.com/docs/specifications/2.2.0#channelBindingsObject"""
348+
"""https://www.asyncapi.com/docs/specifications/2.3.0#channelBindingsObject"""
349349

350350
ws: WebSocketsChannelBindings
351351

@@ -360,11 +360,11 @@ class ChannelHandlers:
360360
@dataclass
361361
class Channel:
362362
"""
363-
https://www.asyncapi.com/docs/specifications/2.2.0#channelItemObject
363+
https://www.asyncapi.com/docs/specifications/2.3.0#channelItemObject
364364
365365
The above channel item object is extended to
366366
support default namespace handlers as per:
367-
https://www.asyncapi.com/docs/specifications/2.2.0#specificationExtensions
367+
https://www.asyncapi.com/docs/specifications/2.3.0#specificationExtensions
368368
369369
The `x_handlers` field is serialized as `x-handlers`.
370370
"""
@@ -412,7 +412,7 @@ class ServerProtocol(Enum):
412412

413413
@dataclass
414414
class Server:
415-
"""https://www.asyncapi.com/docs/specifications/2.2.0#serverObject"""
415+
"""https://www.asyncapi.com/docs/specifications/2.3.0#serverObject"""
416416

417417
url: str
418418
protocol: ServerProtocol
@@ -421,7 +421,7 @@ class Server:
421421

422422
@dataclass
423423
class Info:
424-
"""https://www.asyncapi.com/docs/specifications/v2.2.0#infoObject"""
424+
"""https://www.asyncapi.com/docs/specifications/v2.3.0#infoObject"""
425425

426426
title: str
427427
version: str
@@ -430,7 +430,7 @@ class Info:
430430

431431
@dataclass
432432
class Components:
433-
"""https://www.asyncapi.com/docs/specifications/v2.2.0#componentsObject"""
433+
"""https://www.asyncapi.com/docs/specifications/v2.3.0#componentsObject"""
434434

435435
security_schemes: Mapping[str, SecurityScheme] = field(default_factory=dict)
436436

@@ -451,7 +451,7 @@ def forge(
451451

452452
@dataclass
453453
class AsyncApiSpec:
454-
"""https://www.asyncapi.com/docs/specifications/2.2.0#A2SObject"""
454+
"""https://www.asyncapi.com/docs/specifications/2.3.0#A2SObject"""
455455

456456
asyncapi: str
457457
channels: Mapping[str, Channel]

example/asyncapi.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
asyncapi: 2.2.0
1+
asyncapi: 2.3.0
22

33
info:
44
title: Socket.IO chat demo service

setup.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
readme = readme_file.read()
1313

1414

15-
with open("requirements.txt") as requiremets_file:
16-
requirements = requiremets_file.read().split()
17-
18-
1915
def parse_requirements(file_path: Path) -> Sequence[str]:
2016
reqs = []
2117
with file_path.open() as f:
@@ -50,6 +46,8 @@ def make_extra_requirements() -> Mapping[str, str]:
5046
return extra_requirements
5147

5248

49+
requirements = parse_requirements(Path(__file__).parent / "requirements.txt")
50+
5351
version = os.environ["PKG_VERSION"]
5452

5553

tests/fixtures/array_vs_tuple.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
asyncapi: 2.2.0
1+
asyncapi: 2.3.0
22
info:
33
title: Simple API
44
version: 0.0.1

tests/fixtures/echo.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
asyncapi: 2.2.0
1+
asyncapi: 2.3.0
22
info:
33
title: Echo API
44
version: 0.0.1

tests/fixtures/namespace_security.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
asyncapi: 2.2.0
1+
asyncapi: 2.3.0
22
info:
33
title: Test
44
version: 1.0.0

tests/fixtures/security.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
asyncapi: 2.2.0
1+
asyncapi: 2.3.0
22
info:
33
title: Test
44
version: 1.0.0

tests/fixtures/security_oauth2.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
asyncapi: 2.2.0
1+
asyncapi: 2.3.0
22
info:
33
title: Test
44
version: 1.0.0

tests/fixtures/simple.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
asyncapi: 2.2.0
1+
asyncapi: 2.3.0
22
info:
33
title: Simple API
44
version: 0.0.1

tests/fixtures/simple_with_servers.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
asyncapi: 2.2.0
1+
asyncapi: 2.3.0
22
info:
33
title: Simple API with Servers
44
version: 0.0.1

tests/unit/test_mock_server.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def test_register_handlers_registers_connection_handler_with_bindings_validation
352352
def test_register_namespace_handlers_includes_server_security_validation():
353353
channel_handlers = ChannelHandlers(connect="tests.fixtures.handlers.connect")
354354
spec = AsyncApiSpec(
355-
asyncapi="2.2.0",
355+
asyncapi="2.3.0",
356356
info=Info("test", "1.0.0"),
357357
servers={
358358
"test": Server("https://localhost/", ServerProtocol.WSS, [{"basic": []}])
@@ -389,7 +389,7 @@ def test_register_namespace_handlers_includes_server_security_validation():
389389
def test_register_namespace_handlers_channel_security_overrides_server_security():
390390
channel_handlers = ChannelHandlers(connect="tests.fixtures.handlers.connect")
391391
spec = AsyncApiSpec(
392-
asyncapi="2.2.0",
392+
asyncapi="2.3.0",
393393
info=Info("test", "1.0.0"),
394394
servers={"test": Server("https://localhost/", ServerProtocol.WSS, [])},
395395
channels={

tests/unit/test_server.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def my_default_error_handler(_):
126126

127127
def test_resolve_references_resolves_successfully():
128128
raw_spec = {
129-
"asyncapi": "2.2.0",
129+
"asyncapi": "2.3.0",
130130
"info": {
131131
"title": "My API",
132132
"version": "0.0.0",
@@ -174,7 +174,7 @@ def test_resolve_references_resolves_successfully():
174174
}
175175

176176
resolved = {
177-
"asyncapi": "2.2.0",
177+
"asyncapi": "2.3.0",
178178
"info": {
179179
"title": "My API",
180180
"version": "0.0.0",
@@ -504,7 +504,7 @@ def test_register_namespace_handlers_omits_bindings_validator_if_validation_disa
504504
def test_register_namespace_handlers_includes_server_security_validation():
505505
channel_handlers = ChannelHandlers(connect="tests.fixtures.handlers.connect")
506506
spec = AsyncApiSpec(
507-
asyncapi="2.2.0",
507+
asyncapi="2.3.0",
508508
info=Info("test", "1.0.0"),
509509
servers={
510510
"test": Server("https://localhost/", ServerProtocol.WSS, [{"basic": []}])
@@ -547,7 +547,7 @@ def test_register_namespace_handlers_channel_security_overrides_server_security(
547547
channel_handlers = ChannelHandlers(connect="tests.fixtures.handlers.connect")
548548
channel_security = [{"basic": []}]
549549
spec = AsyncApiSpec(
550-
asyncapi="2.2.0",
550+
asyncapi="2.3.0",
551551
info=Info("test", "1.0.0"),
552552
servers={"test": Server("https://localhost/", ServerProtocol.WSS, [])},
553553
channels={

tests/unit/test_types.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def test_channel_raises_value_error_if_publish_messages_miss_handler(faker: Fake
169169

170170
def test_async_api_spec_from_and_to_dict(faker: Faker):
171171
data = {
172-
"asyncapi": "2.2.0",
172+
"asyncapi": "2.3.0",
173173
"info": {
174174
"title": faker.sentence(),
175175
"version": faker.pystr(),
@@ -309,7 +309,7 @@ def test_security_scheme_validation():
309309

310310
def test_asyncapi_spec_validation_invalid_security_requirement(faker: Faker):
311311
data = {
312-
"asyncapi": "2.2.0",
312+
"asyncapi": "2.3.0",
313313
"info": {
314314
"title": faker.sentence(),
315315
"version": faker.pystr(),
@@ -348,7 +348,7 @@ def test_asyncapi_spec_validation_invalid_security_requirement(faker: Faker):
348348

349349
def test_asyncapi_spec_validation_invalid_security_requirement_scopes(faker: Faker):
350350
data = {
351-
"asyncapi": "2.2.0",
351+
"asyncapi": "2.3.0",
352352
"info": {
353353
"title": faker.sentence(),
354354
"version": faker.pystr(),
@@ -389,7 +389,7 @@ def test_asyncapi_spec_validation_invalid_security_requirement_undefined_scopes(
389389
faker: Faker,
390390
):
391391
data = {
392-
"asyncapi": "2.2.0",
392+
"asyncapi": "2.3.0",
393393
"info": {
394394
"title": faker.sentence(),
395395
"version": faker.pystr(),
@@ -430,7 +430,7 @@ def test_asyncapi_spec_validation_invalid_security_requirement_on_namespace(
430430
faker: Faker,
431431
):
432432
data = {
433-
"asyncapi": "2.2.0",
433+
"asyncapi": "2.3.0",
434434
"info": {
435435
"title": faker.sentence(),
436436
"version": faker.pystr(),
@@ -472,7 +472,7 @@ def test_asyncapi_spec_validation_invalid_security_requirement_on_namespace(
472472

473473
def test_asyncapi_spec_validation_missing_security_scheme(faker: Faker):
474474
data = {
475-
"asyncapi": "2.2.0",
475+
"asyncapi": "2.3.0",
476476
"info": {
477477
"title": faker.sentence(),
478478
"version": faker.pystr(),

0 commit comments

Comments
 (0)