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

fixing makefile bugs and typo #55

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- 'develop'
- 'feature/**'
- 'fix/**'

jobs:
lint:
Expand Down
6 changes: 3 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ help:
@echo " release version=<sem. version> bumps the project version to <sem. version>, using poetry;"
@echo " Updates also docs/source/conf.py version;"
@echo " If no version is provided, poetry outputs the current project version"
@echo " test run all the tests and linting"
@echo " tests run all the tests and linting"
@echo " update updates the dependencies in poetry.lock"
@echo ""
@echo "Check the Makefile to know exactly what each target is doing."
Expand All @@ -34,8 +34,8 @@ install: .install-poetry
poetry install

tests: .install-poetry
poetry run flake8 ocpp tests
poetry run py.test -vvv --cov=ocpp --cov-report=term-missing tests/
poetry run flake8 py_ocpi tests
poetry run py.test -vvv --cov=py_ocpi --cov-report=term-missing tests/

build: .install-poetry
poetry build
Expand Down
2 changes: 1 addition & 1 deletion py_ocpi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Python Implementation of OCPI"""

__version__ = "0.3.0"
__version__ = "0.3.1"

from .core import enums, data_types
from .main import get_application
6 changes: 5 additions & 1 deletion py_ocpi/core/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ def get_versions():
return [
Version(
version=VersionNumber.v_2_2_1,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/{VersionNumber.v_2_2_1}/details')
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/{VersionNumber.v_2_2_1.value}/details')
).dict(),
]


def get_endpoints():
return {}


def pagination_filters(
date_from: datetime = Query(default=None),
date_to: datetime = Query(default=datetime.now()),
Expand Down
195 changes: 98 additions & 97 deletions py_ocpi/core/endpoints.py
Original file line number Diff line number Diff line change
@@ -1,107 +1,108 @@
from py_ocpi.core.enums import ModuleID
from py_ocpi.core.enums import ModuleID, RoleEnum
from py_ocpi.core.data_types import URL
from py_ocpi.core.config import settings
from py_ocpi.modules.versions.schemas import Endpoint
from py_ocpi.modules.versions.enums import VersionNumber, InterfaceRole

ENDPOINTS = {
VersionNumber.v_2_2_1: [
VersionNumber.v_2_2_1: {
# ###############--CPO--###############

# locations
Endpoint(
identifier=ModuleID.locations,
role=InterfaceRole.sender,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/cpo'
f'/{VersionNumber.v_2_2_1}/{ModuleID.locations}')
),
# sessions
Endpoint(
identifier=ModuleID.sessions,
role=InterfaceRole.sender,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/cpo'
f'/{VersionNumber.v_2_2_1}/{ModuleID.sessions}')
),
# credentials
Endpoint(
identifier=ModuleID.credentials_and_registration,
role=InterfaceRole.receiver,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/cpo'
f'/{VersionNumber.v_2_2_1}/{ModuleID.credentials_and_registration}')
),
# tariffs
Endpoint(
identifier=ModuleID.tariffs,
role=InterfaceRole.sender,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/cpo'
f'/{VersionNumber.v_2_2_1}/{ModuleID.tariffs}')
),
# cdrs
Endpoint(
identifier=ModuleID.cdrs,
role=InterfaceRole.sender,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/cpo'
f'/{VersionNumber.v_2_2_1}/{ModuleID.cdrs}')
),
# tokens
Endpoint(
identifier=ModuleID.tokens,
role=InterfaceRole.receiver,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/cpo'
f'/{VersionNumber.v_2_2_1}/{ModuleID.tokens}')
),
RoleEnum.cpo: [
# locations
Endpoint(
identifier=ModuleID.locations,
role=InterfaceRole.sender,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/cpo'
f'/{VersionNumber.v_2_2_1.value}/{ModuleID.locations.value}')
),
# sessions
Endpoint(
identifier=ModuleID.sessions,
role=InterfaceRole.sender,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/cpo'
f'/{VersionNumber.v_2_2_1.value}/{ModuleID.sessions.value}')
),
# credentials
Endpoint(
identifier=ModuleID.credentials_and_registration,
role=InterfaceRole.receiver,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/cpo'
f'/{VersionNumber.v_2_2_1.value}/{ModuleID.credentials_and_registration.value}')
),
# tariffs
Endpoint(
identifier=ModuleID.tariffs,
role=InterfaceRole.sender,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/cpo'
f'/{VersionNumber.v_2_2_1.value}/{ModuleID.tariffs.value}')
),
# cdrs
Endpoint(
identifier=ModuleID.cdrs,
role=InterfaceRole.sender,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/cpo'
f'/{VersionNumber.v_2_2_1.value}/{ModuleID.cdrs.value}')
),
# tokens
Endpoint(
identifier=ModuleID.tokens,
role=InterfaceRole.receiver,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/cpo'
f'/{VersionNumber.v_2_2_1.value}/{ModuleID.tokens.value}')
),
],

# ###############--EMSP--###############

# credentials
Endpoint(
identifier=ModuleID.credentials_and_registration,
role=InterfaceRole.receiver,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/emsp'
f'/{VersionNumber.v_2_2_1}/{ModuleID.credentials_and_registration}')
),
# locations
Endpoint(
identifier=ModuleID.locations,
role=InterfaceRole.receiver,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/emsp'
f'/{VersionNumber.v_2_2_1}/{ModuleID.locations}')
),
# sessions
Endpoint(
identifier=ModuleID.sessions,
role=InterfaceRole.receiver,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/emsp'
f'/{VersionNumber.v_2_2_1}/{ModuleID.sessions}')
),
# cdrs
Endpoint(
identifier=ModuleID.cdrs,
role=InterfaceRole.receiver,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/emsp'
f'/{VersionNumber.v_2_2_1}/{ModuleID.cdrs}')
),
# tariffs
Endpoint(
identifier=ModuleID.tariffs,
role=InterfaceRole.receiver,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/emsp'
f'/{VersionNumber.v_2_2_1}/{ModuleID.tariffs}')
),
# commands
Endpoint(
identifier=ModuleID.commands,
role=InterfaceRole.sender,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/emsp'
f'/{VersionNumber.v_2_2_1}/{ModuleID.commands}')
),
# tokens
Endpoint(
identifier=ModuleID.tokens,
role=InterfaceRole.sender,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/emsp'
f'/{VersionNumber.v_2_2_1}/{ModuleID.tokens}')
),
]

RoleEnum.emsp: [
# credentials
Endpoint(
identifier=ModuleID.credentials_and_registration,
role=InterfaceRole.receiver,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/emsp'
f'/{VersionNumber.v_2_2_1.value}/{ModuleID.credentials_and_registration.value}')
),
# locations
Endpoint(
identifier=ModuleID.locations,
role=InterfaceRole.receiver,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/emsp'
f'/{VersionNumber.v_2_2_1.value}/{ModuleID.locations.value}')
),
# sessions
Endpoint(
identifier=ModuleID.sessions,
role=InterfaceRole.receiver,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/emsp'
f'/{VersionNumber.v_2_2_1.value}/{ModuleID.sessions.value}')
),
# cdrs
Endpoint(
identifier=ModuleID.cdrs,
role=InterfaceRole.receiver,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/emsp'
f'/{VersionNumber.v_2_2_1.value}/{ModuleID.cdrs.value}')
),
# tariffs
Endpoint(
identifier=ModuleID.tariffs,
role=InterfaceRole.receiver,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/emsp'
f'/{VersionNumber.v_2_2_1.value}/{ModuleID.tariffs.value}')
),
# commands
Endpoint(
identifier=ModuleID.commands,
role=InterfaceRole.sender,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/emsp'
f'/{VersionNumber.v_2_2_1.value}/{ModuleID.commands.value}')
),
# tokens
Endpoint(
identifier=ModuleID.tokens,
role=InterfaceRole.sender,
url=URL(f'https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/emsp'
f'/{VersionNumber.v_2_2_1.value}/{ModuleID.tokens.value}')
),
]
}
}
4 changes: 2 additions & 2 deletions py_ocpi/core/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from py_ocpi.core.adapter import Adapter
from py_ocpi.core.crud import Crud
from py_ocpi.core.schemas import Push, PushResponse, ReceiverResponse
from py_ocpi.core.utils import get_auth_token
from py_ocpi.core.utils import encode_string_base64, get_auth_token
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
Expand Down Expand Up @@ -66,7 +66,7 @@ async def push_object(version: VersionNumber, push: Push, crud: Crud, adapter: A
receiver_responses = []
for receiver in push.receivers:
# get client endpoints
client_auth_token = f'Token {receiver.auth_token}'
client_auth_token = f'Token {encode_string_base64(receiver.auth_token)}'
async with httpx.AsyncClient() as client:
response = await client.get(receiver.endpoints_url,
headers={'authorization': client_auth_token})
Expand Down
4 changes: 2 additions & 2 deletions py_ocpi/core/schemas.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime, timezone
from typing import List
from typing import List, Union

from pydantic import BaseModel

Expand All @@ -11,7 +11,7 @@ class OCPIResponse(BaseModel):
"""
https://github.com/ocpi/ocpi/blob/2.2.1/transport_and_format.asciidoc#117-response-format
"""
data: list
data: Union[list, dict]
status_code: int
status_message: String(255)
timestamp: DateTime = str(datetime.now(timezone.utc))
Expand Down
16 changes: 15 additions & 1 deletion py_ocpi/core/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import urllib
import base64

from fastapi import Response, Request
from pydantic import BaseModel
Expand All @@ -18,7 +19,10 @@ def set_pagination_headers(response: Response, link: str, total: int, limit: int
def get_auth_token(request: Request) -> str:
headers = request.headers
headers_token = headers.get('authorization', 'Token Null')
return headers_token.split()[1]
token = headers_token.split()[1]
if token == 'Null': # nosec
return None
return decode_string_base64(token)


async def get_list(response: Response, filters: dict, module: ModuleID, role: RoleEnum,
Expand All @@ -40,3 +44,13 @@ async def get_list(response: Response, filters: dict, module: ModuleID, role: Ro
def partially_update_attributes(instance: BaseModel, attributes: dict):
for key, value in attributes.items():
setattr(instance, key, value)


def encode_string_base64(input: str) -> str:
input_bytes = base64.b64encode(bytes(input, 'utf-8'))
return input_bytes.decode('utf-8')


def decode_string_base64(input: str) -> str:
input_bytes = base64.b64decode(bytes(input, 'utf-8'))
return input_bytes.decode('utf-8')
Loading