Skip to content

Commit

Permalink
Use Int representations
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas ONeil <[email protected]>
  • Loading branch information
loneil committed Sep 13, 2024
1 parent 76e6a4d commit 6004c89
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions oidc-controller/api/verificationConfigs/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
from typing import Optional, List
from typing import Optional, List, Union
from pydantic import BaseModel, ConfigDict, Field

from .examples import ex_ver_config
Expand Down Expand Up @@ -27,7 +27,7 @@ class ReqPred(BaseModel):
name: str
label: Optional[str] = None
restrictions: List[AttributeFilter]
p_value: str
p_value: Union[int, str]
p_type: str


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ def test_get_now():

def test_get_today_date():
vsm = VariableSubstitutionMap()
assert vsm.get_today_date() == datetime.today().strftime("%Y%m%d")
assert vsm.get_today_date() == int(datetime.today().strftime("%Y%m%d"))


def test_get_tomorrow_date():
vsm = VariableSubstitutionMap()
assert vsm.get_tomorrow_date() == (datetime.today() + timedelta(days=1)).strftime(
"%Y%m%d"
assert vsm.get_tomorrow_date() == int(
(datetime.today() + timedelta(days=1)).strftime("%Y%m%d")
)


Expand All @@ -33,8 +33,8 @@ def test_get_threshold_years_date():
def test_contains_static_variable():
vsm = VariableSubstitutionMap()
assert "$now" in vsm
assert "$today_str" in vsm
assert "$tomorrow_str" in vsm
assert "$today_int" in vsm
assert "$tomorrow_int" in vsm


def test_contains_dynamic_variable():
Expand All @@ -45,8 +45,8 @@ def test_contains_dynamic_variable():
def test_getitem_static_variable():
vsm = VariableSubstitutionMap()
assert callable(vsm["$now"])
assert callable(vsm["$today_str"])
assert callable(vsm["$tomorrow_str"])
assert callable(vsm["$today_int"])
assert callable(vsm["$tomorrow_int"])


def test_getitem_dynamic_variable():
Expand Down
20 changes: 10 additions & 10 deletions oidc-controller/api/verificationConfigs/variableSubstitutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def __init__(self):
# This class defines threshold_years_X as a dynamic one
self.static_map = {
"$now": self.get_now,
"$today_str": self.get_today_date,
"$tomorrow_str": self.get_tomorrow_date,
"$today_int": self.get_today_date,
"$tomorrow_int": self.get_tomorrow_date,
}

def get_threshold_years_date(self, years: int) -> int:
Expand All @@ -42,23 +42,23 @@ def get_now(self) -> int:
"""
return int(time.time())

def get_today_date(self) -> str:
def get_today_date(self) -> int:
"""
Get today's date in YYYYMMDD format.
Get today's date in YYYYMMDD format as a number.
Returns:
str: Today's date in YYYYMMDD format.
int: Today's date in YYYYMMDD format.
"""
return datetime.today().strftime("%Y%m%d")
return int(datetime.today().strftime("%Y%m%d"))

def get_tomorrow_date(self) -> str:
def get_tomorrow_date(self) -> int:
"""
Get tomorrow's date in YYYYMMDD format.
Get tomorrow's date in YYYYMMDD format as a number.
Returns:
str: Tomorrow's date in YYYYMMDD format.
int: Tomorrow's date in YYYYMMDD format.
"""
return (datetime.today() + timedelta(days=1)).strftime("%Y%m%d")
return int((datetime.today() + timedelta(days=1)).strftime("%Y%m%d"))

# For "dynamic" variables, use a regex to match the key and return a lambda function
# So a proof request can use $threshold_years_X to get the years back for X years
Expand Down

0 comments on commit 6004c89

Please sign in to comment.