Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Add credentials v2.1.1 and corresponding modules. #3

Merged
merged 20 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
8c9b6e6
feat: Change versions module structure to version supported structure…
oleksandr-bozbei-ew Aug 31, 2023
d88b68c
fix: Remove default date_to pagination filter which could cause wrong…
oleksandr-bozbei-ew Aug 31, 2023
a6b30c9
feat: Change structure of core endpoints to use different versioning;…
oleksandr-bozbei-ew Aug 31, 2023
9234b20
feat: Add credentials module support version v_2_1_1; update enums an…
oleksandr-bozbei-ew Aug 31, 2023
c3ae9d1
feat: Add api support for locations v_2_1_1
oleksandr-bozbei-ew Aug 31, 2023
d0ff84d
fix: remove typo
oleksandr-bozbei-ew Aug 31, 2023
4040af7
fix: Deepcopy location obj before changing it
oleksandr-bozbei-ew Aug 31, 2023
1a2daf2
fix: Add response in case evse wasn't found while patching.
oleksandr-bozbei-ew Aug 31, 2023
5f488e2
fix: Add invalid status response in case evse on connector add or upd…
oleksandr-bozbei-ew Aug 31, 2023
c76a273
feat: Change app initialization from only v_2_2_1 to support differen…
oleksandr-bozbei-ew Sep 1, 2023
b20a9a6
fix: tariff endpoint in v_2_2_1 wrong format
oleksandr-bozbei-ew Sep 1, 2023
e1c33af
test: fix broken testcases after the changes
oleksandr-bozbei-ew Sep 1, 2023
f517fd5
test: move v_2_2_1 tests to separate folder
oleksandr-bozbei-ew Sep 1, 2023
a46f875
test: move v_2_2_1 tests to separate folder
oleksandr-bozbei-ew Sep 1, 2023
fb4f54a
test: add versions module tests for version 2_1_1
oleksandr-bozbei-ew Sep 1, 2023
acb0029
test: Add testcases for credentials module v_2_1_1
oleksandr-bozbei-ew Sep 18, 2023
0764de0
test: add testcasese to locations module
oleksandr-bozbei-ew Sep 18, 2023
1064c38
docs: update README
oleksandr-bozbei-ew Sep 18, 2023
736adac
fix: Use only one return statement in location api module
oleksandr-bozbei-ew Sep 20, 2023
67955fb
fix: Add break statement
oleksandr-bozbei-ew Sep 20, 2023
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
2 changes: 1 addition & 1 deletion py_ocpi/core/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_endpoints():

def pagination_filters(
date_from: datetime = Query(default=None),
date_to: datetime = Query(default=datetime.now()),
date_to: datetime = Query(default=None),
oleksandr-bozbei-ew marked this conversation as resolved.
Show resolved Hide resolved
offset: int = Query(default=0),
limit: int = Query(default=50),
):
Expand Down
2 changes: 1 addition & 1 deletion py_ocpi/core/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from py_ocpi.core.dependencies import get_crud, get_adapter
from py_ocpi.core.enums import ModuleID, RoleEnum
from py_ocpi.core.config import settings
from py_ocpi.modules.versions.enums import InterfaceRole, VersionNumber
from py_ocpi.modules.versions.v_2_2_1.enums import InterfaceRole, VersionNumber


def client_url(module_id: ModuleID, object_id: str, base_url: str) -> str:
Expand Down
9 changes: 9 additions & 0 deletions py_ocpi/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ def get_auth_token(request: Request) -> Union[str, None]:
return decode_string_base64(token)


def get_auth_token_from_header(request: Request) -> str | None:
headers = request.headers
headers_token = headers.get("authorization", "Token Null")
token = headers_token.split()[1]
if token == "Null":
return None
return token


async def get_list(
response: Response,
filters: dict,
Expand Down
2 changes: 1 addition & 1 deletion py_ocpi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
)
from py_ocpi.core.endpoints import ENDPOINTS

from py_ocpi.modules.versions.api import (
from py_ocpi.modules.versions import (
router as versions_router,
versions_v_2_2_1_router,
)
Expand Down
3 changes: 3 additions & 0 deletions py_ocpi/modules/versions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .main import router
from .v_2_2_1.api import router as versions_v_2_2_1_router
from .v_2_1_1.api import router as versions_v_2_1_1_router
2 changes: 0 additions & 2 deletions py_ocpi/modules/versions/api/__init__.py

This file was deleted.

15 changes: 0 additions & 15 deletions py_ocpi/modules/versions/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,3 @@ class VersionNumber(str, Enum):
v_2_2 = "2.2"
v_2_2_1 = "2.2.1"
latest = "2.2.1"


class InterfaceRole(str, Enum):
"""
https://github.com/ocpi/ocpi/blob/2.2.1/version_information_endpoint.asciidoc#123-interfacerole-enum
"""

# Sender Interface implementation.
# Interface implemented by the owner of data,
# so the Receiver can Pull information from the data Sender/owner.
sender = "SENDER"
# Receiver Interface implementation.
# Interface implemented by the receiver of data,
# so the Sender/owner can Push information to the Receiver.
receiver = "RECEIVER"
File renamed without changes.
24 changes: 1 addition & 23 deletions py_ocpi/modules/versions/schemas.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from typing import List

from pydantic import BaseModel

from py_ocpi.modules.versions.enums import VersionNumber, InterfaceRole
from py_ocpi.modules.versions.enums import VersionNumber
from py_ocpi.core.data_types import URL
from py_ocpi.core.enums import ModuleID


class Version(BaseModel):
Expand All @@ -14,22 +11,3 @@ class Version(BaseModel):

version: VersionNumber
url: URL


class Endpoint(BaseModel):
"""
https://github.com/ocpi/ocpi/blob/2.2.1/version_information_endpoint.asciidoc#122-endpoint-class
"""

identifier: ModuleID
role: InterfaceRole
url: URL


class VersionDetail(BaseModel):
"""
https://github.com/ocpi/ocpi/blob/2.2.1/version_information_endpoint.asciidoc#121-data
"""

version: VersionNumber
endpoints: List[Endpoint]
1 change: 1 addition & 0 deletions py_ocpi/modules/versions/v_2_1_1/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .main import router
47 changes: 47 additions & 0 deletions py_ocpi/modules/versions/v_2_1_1/api/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from fastapi import (
APIRouter,
Depends,
Request,
HTTPException,
status as fastapistatus,
)

from py_ocpi.core.crud import Crud
from py_ocpi.core import status
from py_ocpi.core.schemas import OCPIResponse
from py_ocpi.core.dependencies import get_endpoints, get_crud
from py_ocpi.core.utils import get_auth_token_from_header
from py_ocpi.core.enums import Action, ModuleID

from py_ocpi.modules.versions.v_2_1_1.schemas import (
VersionDetail,
VersionNumber,
)

router = APIRouter()


@router.get("/2.1.1/details", response_model=OCPIResponse)
async def get_version_details(
request: Request,
endpoints=Depends(get_endpoints),
crud: Crud = Depends(get_crud),
):
auth_token = get_auth_token_from_header(request)

server_cred = await crud.do(
ModuleID.credentials_and_registration,
None,
Action.get_client_token,
auth_token=auth_token,
)
if server_cred is None:
raise HTTPException(fastapistatus.HTTP_401_UNAUTHORIZED, "Unauthorized")

return OCPIResponse(
data=VersionDetail(
version=VersionNumber.v_2_1_1,
endpoints=endpoints[VersionNumber.v_2_1_1],
).dict(),
**status.OCPI_1000_GENERIC_SUCESS_CODE,
)
1 change: 1 addition & 0 deletions py_ocpi/modules/versions/v_2_1_1/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from py_ocpi.modules.versions.enums import * # noqa
25 changes: 25 additions & 0 deletions py_ocpi/modules/versions/v_2_1_1/schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from typing import List

from pydantic import BaseModel

from py_ocpi.modules.versions.v_2_1_1.enums import VersionNumber
from py_ocpi.core.data_types import URL
from py_ocpi.core.enums import ModuleID


class Endpoint(BaseModel):
"""
https://github.com/ocpi/ocpi/blob/release-2.1.1-bugfixes/version_information_endpoint.md#endpoint-class
"""

identifier: ModuleID
url: URL


class VersionDetail(BaseModel):
"""
https://github.com/ocpi/ocpi/blob/release-2.1.1-bugfixes/version_information_endpoint.md#data-1
"""

version: VersionNumber
endpoints: List[Endpoint]
1 change: 1 addition & 0 deletions py_ocpi/modules/versions/v_2_2_1/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .main import router
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
status as fastapistatus,
)

from py_ocpi.modules.versions.schemas import VersionDetail
from py_ocpi.modules.versions.enums import VersionNumber
from py_ocpi.core.crud import Crud
from py_ocpi.core import status
from py_ocpi.core.schemas import OCPIResponse
from py_ocpi.core.dependencies import get_endpoints, get_crud
from py_ocpi.core.utils import get_auth_token
from py_ocpi.core.enums import Action, ModuleID

from py_ocpi.modules.versions.v_2_2_1.schemas import (
VersionDetail,
VersionNumber,
)

router = APIRouter()


Expand Down
16 changes: 16 additions & 0 deletions py_ocpi/modules/versions/v_2_2_1/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from py_ocpi.modules.versions.enums import * # noqa


class InterfaceRole(str, Enum): # noqa
"""
https://github.com/ocpi/ocpi/blob/2.2.1/version_information_endpoint.asciidoc#123-interfacerole-enum
"""

# Sender Interface implementation.
# Interface implemented by the owner of data,
# so the Receiver can Pull information from the data Sender/owner.
sender = "SENDER"
# Receiver Interface implementation.
# Interface implemented by the receiver of data,
# so the Sender/owner can Push information to the Receiver.
receiver = "RECEIVER"
26 changes: 26 additions & 0 deletions py_ocpi/modules/versions/v_2_2_1/schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from typing import List

from pydantic import BaseModel

from py_ocpi.modules.versions.v_2_2_1.enums import InterfaceRole, VersionNumber
from py_ocpi.core.data_types import URL
from py_ocpi.core.enums import ModuleID


class Endpoint(BaseModel):
"""
https://github.com/ocpi/ocpi/blob/2.2.1/version_information_endpoint.asciidoc#122-endpoint-class
"""

identifier: ModuleID
role: InterfaceRole
url: URL


class VersionDetail(BaseModel):
"""
https://github.com/ocpi/ocpi/blob/2.2.1/version_information_endpoint.asciidoc#121-data
"""

version: VersionNumber
endpoints: List[Endpoint]