Skip to content

Commit

Permalink
Merge pull request #203 from lalithkota/17.0-develop-disctrict-code
Browse files Browse the repository at this point in the history
Fixed utc Datetimes and REST API modules dependency graphs
  • Loading branch information
shibu-narayanan authored Nov 11, 2024
2 parents a5164da + 57d987a commit a439edd
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 24 deletions.
6 changes: 3 additions & 3 deletions g2p_encryption_keymanager/models/encryption_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
import os
import secrets
from datetime import datetime
from datetime import datetime, timezone

import requests
from cryptography import x509
Expand Down Expand Up @@ -39,7 +39,7 @@ def _km_random_secret(self):

@api.model
def km_generate_current_time(self):
return f'{datetime.utcnow().isoformat(timespec = "milliseconds")}Z'
return f'{datetime.now(timezone.utc).isoformat(timespec = "milliseconds")}Z'

keymanager_api_base_url = fields.Char("Keymanager API Base URL", default=KEYMANAGER_API_BASE_URL)
keymanager_api_timeout = fields.Integer("Keymanager API Timeout", default=10)
Expand Down Expand Up @@ -261,7 +261,7 @@ def km_get_access_token(self):
if (
self.keymanager_access_token
and self.keymanager_access_token_expiry
and self.keymanager_access_token_expiry > datetime.utcnow()
and self.keymanager_access_token_expiry > datetime.now(timezone.utc)
):
return self.keymanager_access_token
data = {
Expand Down
1 change: 0 additions & 1 deletion g2p_encryption_rest_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from . import models
from . import routers
4 changes: 2 additions & 2 deletions g2p_encryption_rest_api/models/fastapi_endpoint_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from odoo import api, fields, models

from ..routers.well_known import well_known_router


class SecurityFastApiEndpoint(models.Model):
_inherit = "fastapi.endpoint"
Expand All @@ -15,6 +13,8 @@ class SecurityFastApiEndpoint(models.Model):
def _get_fastapi_routers(self) -> list[APIRouter]:
routers = super()._get_fastapi_routers()
if self.app == "security":
from ..routers.well_known import well_known_router

routers.append(well_known_router)
return routers

Expand Down
1 change: 0 additions & 1 deletion g2p_encryption_rest_api/routers/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from . import well_known
6 changes: 3 additions & 3 deletions g2p_openid_vci/models/vci_issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import os
import uuid
from datetime import datetime
from datetime import datetime, timezone

import jq
import requests
Expand Down Expand Up @@ -136,7 +136,7 @@ def issue_vc_Registry(self, auth_claims, credential_request):
partner_dict = partner.read()[0]
reg_ids_dict = {reg_id.id_type.name: reg_id.read()[0] for reg_id in partner.reg_ids}

curr_datetime = f'{datetime.utcnow().isoformat(timespec = "milliseconds")}Z'
curr_datetime = f'{datetime.now(timezone.utc).isoformat(timespec = "milliseconds")}Z'
credential = jq.first(
self.credential_format,
VCJSONEncoder.python_dict_to_json_dict(
Expand Down Expand Up @@ -183,7 +183,7 @@ def sign_and_issue_credential(self, credential: dict) -> dict:

def build_empty_ld_proof(self):
self.ensure_one()
curr_datetime = f'{datetime.utcnow().isoformat(timespec = "milliseconds")}Z'
curr_datetime = f'{datetime.now(timezone.utc).isoformat(timespec = "milliseconds")}Z'
web_base_url = self.env["ir.config_parameter"].sudo().get_param("web.base.url").rstrip("/")
# TODO: Remove this hardcoding
return {
Expand Down
12 changes: 6 additions & 6 deletions g2p_openid_vci/tests/test_openid_vc_issuer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import base64
import os
from datetime import datetime
from datetime import datetime, timezone
from unittest.mock import MagicMock, patch

import requests
Expand Down Expand Up @@ -67,7 +67,7 @@ def setUp(self):
"iss": "http://openg2p.local/auth",
"aud": "http://openg2p.local/api/v1/vci/credential",
"sub": self.registrant_national_id,
"exp": int(datetime.utcnow().timestamp()) + 5 * 60,
"exp": int(datetime.now(timezone.utc).timestamp()) + 5 * 60,
},
self.jwk,
algorithm="RS256",
Expand Down Expand Up @@ -144,7 +144,7 @@ def test_issue_vc_no_scope(self):
"iss": "http://openg2p.local/auth",
"aud": "http://openg2p.local/api/v1/vci/credential",
"sub": self.registrant_national_id,
"exp": int(datetime.utcnow().timestamp()) + 5 * 60,
"exp": int(datetime.now(timezone.utc).timestamp()) + 5 * 60,
},
self.jwk,
algorithm="RS256",
Expand All @@ -164,7 +164,7 @@ def test_issue_vc_invalid_id(self, mock_request):
"iss": "http://openg2p.local/auth",
"aud": "http://openg2p.local/api/v1/vci/credential",
"sub": "random-value",
"exp": int(datetime.utcnow().timestamp()) + 5 * 60,
"exp": int(datetime.now(timezone.utc).timestamp()) + 5 * 60,
},
self.jwk,
algorithm="RS256",
Expand All @@ -187,7 +187,7 @@ def test_issue_vc_check_audience(self, mock_request):
"iss": "http://openg2p.local/auth",
"aud": ["http://random.url/credential"],
"sub": self.registrant_national_id,
"exp": int(datetime.utcnow().timestamp()) + 5 * 60,
"exp": int(datetime.now(timezone.utc).timestamp()) + 5 * 60,
},
self.jwk,
algorithm="RS256",
Expand All @@ -207,7 +207,7 @@ def test_issue_vc_auth_expired(self, mock_request):
"iss": "http://openg2p.local/auth",
"aud": "http://openg2p.local/api/v1/vci/credential",
"sub": self.registrant_national_id,
"exp": int(datetime.utcnow().timestamp()) - 5 * 60,
"exp": int(datetime.now(timezone.utc).timestamp()) - 5 * 60,
},
self.jwk,
algorithm="RS256",
Expand Down
1 change: 0 additions & 1 deletion g2p_openid_vci_rest_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from . import schemas
from . import models
from . import routers
4 changes: 2 additions & 2 deletions g2p_openid_vci_rest_api/models/fastapi_endpoint_vci.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from odoo import api, fields, models

from ..routers.openid_vci import openid_vci_router


class VCIFastApiEndpoint(models.Model):
_inherit = "fastapi.endpoint"
Expand All @@ -13,6 +11,8 @@ class VCIFastApiEndpoint(models.Model):
def _get_fastapi_routers(self) -> list[APIRouter]:
routers = super()._get_fastapi_routers()
if self.app == "vci":
from ..routers.openid_vci import openid_vci_router

routers.append(openid_vci_router)
return routers

Expand Down
1 change: 0 additions & 1 deletion g2p_openid_vci_rest_api/routers/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from . import openid_vci
4 changes: 2 additions & 2 deletions g2p_openid_vci_rest_api/tests/test_vci_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timezone
from unittest.mock import patch

from odoo.tests import tagged
Expand All @@ -21,7 +21,7 @@ def mock_issue_vc(self):
"id": "1234",
"type": ["VerifiableCredential", "OpenG2PTestVerifiableCredential"],
"issuer": "did:example:test12345678abcdefgh",
"issuanceDate": f'{datetime.utcnow().isoformat(timespec = "milliseconds")}Z',
"issuanceDate": f'{datetime.now(timezone.utc).isoformat(timespec = "milliseconds")}Z',
"credentialSubject": {
"vcVer": "VC-V1",
"id": "http://openg2p.local/individual/1",
Expand Down
4 changes: 2 additions & 2 deletions mts_connector/models/mts_connector.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import logging
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone

import jq
import requests
Expand Down Expand Up @@ -161,7 +161,7 @@ def mts_onetime_action(self, _id: int):
_logger.info("Being called everytime. Id: " + str(_id))
current_conf: MTSConnector = self.env["mts.connector"].browse(_id)
# execute here
dt_now = datetime.utcnow()
dt_now = datetime.now(timezone.utc)
mts_request = {
"id": "string",
"version": "string",
Expand Down

0 comments on commit a439edd

Please sign in to comment.