Skip to content

Commit

Permalink
fix: Adjustting asyncapi and requirements versions (#186)
Browse files Browse the repository at this point in the history
* fix: Adjustting asyncapi and requirements versions

* Correct marker

* Split requirements correctly

* Use proper requirements parsing method

* Do not use env markers
  • Loading branch information
dedoussis authored Feb 12, 2022
1 parent a5df034 commit 40799ae
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 42 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def admin_error(e):
Example specification located at `./docs/asyncapi.yaml`:

```yaml
asyncapi: 2.2.0
asyncapi: 2.3.0

info:
title: User Account Service
Expand Down Expand Up @@ -176,7 +176,7 @@ Without Asynction, one would need to add additional boilerplate to register the

## Security (Authentication and Authorization)

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.
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.

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.

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

### Security handers

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:
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:

- A Security Scheme Object of `oauth2` type MUST include the `x-tokenInfoFunc` field.
- A Security Scheme Object of `oauth2` type MAY include the `x-scopeValidateFunc` field.
Expand Down
30 changes: 15 additions & 15 deletions asynction/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class HTTPAuthenticationScheme(Enum):

class OAuth2FlowType(Enum):
"""
https://www.asyncapi.com/docs/specifications/v2.2.0#oauthFlowsObject
https://www.asyncapi.com/docs/specifications/v2.3.0#oauthFlowsObject
"""

IMPLICIT = "implicit"
Expand All @@ -46,7 +46,7 @@ class OAuth2FlowType(Enum):
@dataclass
class OAuth2Flow:
"""
https://www.asyncapi.com/docs/specifications/v2.2.0#oauthFlowObject
https://www.asyncapi.com/docs/specifications/v2.3.0#oauthFlowObject
"""

scopes: Mapping[str, str]
Expand Down Expand Up @@ -126,7 +126,7 @@ def supported_scopes(self) -> Iterator[str]:

class SecuritySchemesType(Enum):
"""
https://www.asyncapi.com/docs/specifications/v2.2.0#securitySchemeObjectType
https://www.asyncapi.com/docs/specifications/v2.3.0#securitySchemeObjectType
"""

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

class ApiKeyLocation(Enum):
"""
https://www.asyncapi.com/docs/specifications/v2.2.0#securitySchemeObject
https://www.asyncapi.com/docs/specifications/v2.3.0#securitySchemeObject
"""

USER = "user"
Expand All @@ -159,7 +159,7 @@ class ApiKeyLocation(Enum):
@dataclass
class SecurityScheme:
"""
https://www.asyncapi.com/docs/specifications/v2.2.0#securitySchemeObject
https://www.asyncapi.com/docs/specifications/v2.3.0#securitySchemeObject
"""

type: SecuritySchemesType
Expand Down Expand Up @@ -264,7 +264,7 @@ class MessageAck:
@dataclass
class Message:
"""
https://www.asyncapi.com/docs/specifications/2.2.0#messageObject
https://www.asyncapi.com/docs/specifications/2.3.0#messageObject
The above message object is extended as follows:
* `x-handler`: Allows the coupling of the message specification to
Expand All @@ -275,7 +275,7 @@ class Message:
to the callback of the `emit`/`send` function. Deserialized to `x_ack`.
The extentions are implemented as per:
https://www.asyncapi.com/docs/specifications/2.2.0#specificationExtensions
https://www.asyncapi.com/docs/specifications/2.3.0#specificationExtensions
"""

name: str
Expand Down Expand Up @@ -326,7 +326,7 @@ def with_name(self, name: str) -> Optional[Message]:

@dataclass
class Operation:
"""https://www.asyncapi.com/docs/specifications/2.2.0#operationObject"""
"""https://www.asyncapi.com/docs/specifications/2.3.0#operationObject"""

message: OneOfMessages

Expand All @@ -345,7 +345,7 @@ class WebSocketsChannelBindings:

@dataclass
class ChannelBindings:
"""https://www.asyncapi.com/docs/specifications/2.2.0#channelBindingsObject"""
"""https://www.asyncapi.com/docs/specifications/2.3.0#channelBindingsObject"""

ws: WebSocketsChannelBindings

Expand All @@ -360,11 +360,11 @@ class ChannelHandlers:
@dataclass
class Channel:
"""
https://www.asyncapi.com/docs/specifications/2.2.0#channelItemObject
https://www.asyncapi.com/docs/specifications/2.3.0#channelItemObject
The above channel item object is extended to
support default namespace handlers as per:
https://www.asyncapi.com/docs/specifications/2.2.0#specificationExtensions
https://www.asyncapi.com/docs/specifications/2.3.0#specificationExtensions
The `x_handlers` field is serialized as `x-handlers`.
"""
Expand Down Expand Up @@ -412,7 +412,7 @@ class ServerProtocol(Enum):

@dataclass
class Server:
"""https://www.asyncapi.com/docs/specifications/2.2.0#serverObject"""
"""https://www.asyncapi.com/docs/specifications/2.3.0#serverObject"""

url: str
protocol: ServerProtocol
Expand All @@ -421,7 +421,7 @@ class Server:

@dataclass
class Info:
"""https://www.asyncapi.com/docs/specifications/v2.2.0#infoObject"""
"""https://www.asyncapi.com/docs/specifications/v2.3.0#infoObject"""

title: str
version: str
Expand All @@ -430,7 +430,7 @@ class Info:

@dataclass
class Components:
"""https://www.asyncapi.com/docs/specifications/v2.2.0#componentsObject"""
"""https://www.asyncapi.com/docs/specifications/v2.3.0#componentsObject"""

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

Expand All @@ -451,7 +451,7 @@ def forge(

@dataclass
class AsyncApiSpec:
"""https://www.asyncapi.com/docs/specifications/2.2.0#A2SObject"""
"""https://www.asyncapi.com/docs/specifications/2.3.0#A2SObject"""

asyncapi: str
channels: Mapping[str, Channel]
Expand Down
2 changes: 1 addition & 1 deletion example/asyncapi.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
asyncapi: 2.2.0
asyncapi: 2.3.0

info:
title: Socket.IO chat demo service
Expand Down
6 changes: 2 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
readme = readme_file.read()


with open("requirements.txt") as requiremets_file:
requirements = requiremets_file.read().split()


def parse_requirements(file_path: Path) -> Sequence[str]:
reqs = []
with file_path.open() as f:
Expand Down Expand Up @@ -50,6 +46,8 @@ def make_extra_requirements() -> Mapping[str, str]:
return extra_requirements


requirements = parse_requirements(Path(__file__).parent / "requirements.txt")

version = os.environ["PKG_VERSION"]


Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/array_vs_tuple.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
asyncapi: 2.2.0
asyncapi: 2.3.0
info:
title: Simple API
version: 0.0.1
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/echo.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
asyncapi: 2.2.0
asyncapi: 2.3.0
info:
title: Echo API
version: 0.0.1
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/namespace_security.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
asyncapi: 2.2.0
asyncapi: 2.3.0
info:
title: Test
version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/security.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
asyncapi: 2.2.0
asyncapi: 2.3.0
info:
title: Test
version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/security_oauth2.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
asyncapi: 2.2.0
asyncapi: 2.3.0
info:
title: Test
version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/simple.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
asyncapi: 2.2.0
asyncapi: 2.3.0
info:
title: Simple API
version: 0.0.1
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/simple_with_servers.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
asyncapi: 2.2.0
asyncapi: 2.3.0
info:
title: Simple API with Servers
version: 0.0.1
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_mock_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def test_register_handlers_registers_connection_handler_with_bindings_validation
def test_register_namespace_handlers_includes_server_security_validation():
channel_handlers = ChannelHandlers(connect="tests.fixtures.handlers.connect")
spec = AsyncApiSpec(
asyncapi="2.2.0",
asyncapi="2.3.0",
info=Info("test", "1.0.0"),
servers={
"test": Server("https://localhost/", ServerProtocol.WSS, [{"basic": []}])
Expand Down Expand Up @@ -389,7 +389,7 @@ def test_register_namespace_handlers_includes_server_security_validation():
def test_register_namespace_handlers_channel_security_overrides_server_security():
channel_handlers = ChannelHandlers(connect="tests.fixtures.handlers.connect")
spec = AsyncApiSpec(
asyncapi="2.2.0",
asyncapi="2.3.0",
info=Info("test", "1.0.0"),
servers={"test": Server("https://localhost/", ServerProtocol.WSS, [])},
channels={
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def my_default_error_handler(_):

def test_resolve_references_resolves_successfully():
raw_spec = {
"asyncapi": "2.2.0",
"asyncapi": "2.3.0",
"info": {
"title": "My API",
"version": "0.0.0",
Expand Down Expand Up @@ -174,7 +174,7 @@ def test_resolve_references_resolves_successfully():
}

resolved = {
"asyncapi": "2.2.0",
"asyncapi": "2.3.0",
"info": {
"title": "My API",
"version": "0.0.0",
Expand Down Expand Up @@ -504,7 +504,7 @@ def test_register_namespace_handlers_omits_bindings_validator_if_validation_disa
def test_register_namespace_handlers_includes_server_security_validation():
channel_handlers = ChannelHandlers(connect="tests.fixtures.handlers.connect")
spec = AsyncApiSpec(
asyncapi="2.2.0",
asyncapi="2.3.0",
info=Info("test", "1.0.0"),
servers={
"test": Server("https://localhost/", ServerProtocol.WSS, [{"basic": []}])
Expand Down Expand Up @@ -547,7 +547,7 @@ def test_register_namespace_handlers_channel_security_overrides_server_security(
channel_handlers = ChannelHandlers(connect="tests.fixtures.handlers.connect")
channel_security = [{"basic": []}]
spec = AsyncApiSpec(
asyncapi="2.2.0",
asyncapi="2.3.0",
info=Info("test", "1.0.0"),
servers={"test": Server("https://localhost/", ServerProtocol.WSS, [])},
channels={
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def test_channel_raises_value_error_if_publish_messages_miss_handler(faker: Fake

def test_async_api_spec_from_and_to_dict(faker: Faker):
data = {
"asyncapi": "2.2.0",
"asyncapi": "2.3.0",
"info": {
"title": faker.sentence(),
"version": faker.pystr(),
Expand Down Expand Up @@ -309,7 +309,7 @@ def test_security_scheme_validation():

def test_asyncapi_spec_validation_invalid_security_requirement(faker: Faker):
data = {
"asyncapi": "2.2.0",
"asyncapi": "2.3.0",
"info": {
"title": faker.sentence(),
"version": faker.pystr(),
Expand Down Expand Up @@ -348,7 +348,7 @@ def test_asyncapi_spec_validation_invalid_security_requirement(faker: Faker):

def test_asyncapi_spec_validation_invalid_security_requirement_scopes(faker: Faker):
data = {
"asyncapi": "2.2.0",
"asyncapi": "2.3.0",
"info": {
"title": faker.sentence(),
"version": faker.pystr(),
Expand Down Expand Up @@ -389,7 +389,7 @@ def test_asyncapi_spec_validation_invalid_security_requirement_undefined_scopes(
faker: Faker,
):
data = {
"asyncapi": "2.2.0",
"asyncapi": "2.3.0",
"info": {
"title": faker.sentence(),
"version": faker.pystr(),
Expand Down Expand Up @@ -430,7 +430,7 @@ def test_asyncapi_spec_validation_invalid_security_requirement_on_namespace(
faker: Faker,
):
data = {
"asyncapi": "2.2.0",
"asyncapi": "2.3.0",
"info": {
"title": faker.sentence(),
"version": faker.pystr(),
Expand Down Expand Up @@ -472,7 +472,7 @@ def test_asyncapi_spec_validation_invalid_security_requirement_on_namespace(

def test_asyncapi_spec_validation_missing_security_scheme(faker: Faker):
data = {
"asyncapi": "2.2.0",
"asyncapi": "2.3.0",
"info": {
"title": faker.sentence(),
"version": faker.pystr(),
Expand Down

0 comments on commit 40799ae

Please sign in to comment.