diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 8991c9f..dbc20d0 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -15,7 +15,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUBSECRET2 }} - - uses: actions/checkout@v3.0.0 + - uses: actions/checkout@v3.0.2 - name: Extract branch name shell: bash diff --git a/src/os_credits/settings.py b/src/os_credits/settings.py index 1c852ff..3cac2a1 100644 --- a/src/os_credits/settings.py +++ b/src/os_credits/settings.py @@ -169,7 +169,7 @@ class Config(TypedDict): API_CONTACT_BASE_URL: str MAIL_CONTACT_URL: str ENDPOINTS_ONLY: bool - OS_CREDITS_PRECISION: int + OS_CREDITS_PRECISION: str default_config = Config( @@ -186,7 +186,7 @@ class Config(TypedDict): API_CONTACT_BASE_URL="", MAIL_CONTACT_URL="", ENDPOINTS_ONLY=False, - OS_CREDITS_PRECISION=2 + OS_CREDITS_PRECISION="0.01" ) @@ -215,8 +215,7 @@ def parse_config_from_environment() -> Config: for int_value_key in [ "OS_CREDITS_WORKERS", - "POSTGRES_PORT", - "OS_CREDITS_PRECISION" + "POSTGRES_PORT" ]: try: int_value = int(environ[int_value_key]) diff --git a/src/os_credits/views.py b/src/os_credits/views.py index 15105da..86f0241 100644 --- a/src/os_credits/views.py +++ b/src/os_credits/views.py @@ -362,11 +362,12 @@ async def costs_per_hour(request: web.Request) -> web.Response: except JSONDecodeError: raise web.HTTPBadRequest(reason="Invalid JSON") returned_costs_per_hour = Decimal(0) + quantize_precision = Decimal(config["OS_CREDITS_PRECISION"]) for metric_name, spec in machine_specs.items(): try: cost = Decimal(config["METRICS_TO_BILL"][metric_name]) spec = Decimal(spec) - returned_costs_per_hour += (spec * cost).quantize(config["OS_CREDITS_PRECISION"]) + returned_costs_per_hour += (spec * cost).quantize(quantize_precision) except KeyError: raise web.HTTPNotFound(reason=f"Unknown measurement `{metric_name}`.") except TypeError: @@ -374,7 +375,7 @@ async def costs_per_hour(request: web.Request) -> web.Response: reason=f"Parameter {metric_name} had wrong type." ) return web.json_response( - float(returned_costs_per_hour.quantize(config["OS_CREDITS_PRECISION"])) + float(returned_costs_per_hour.quantize(quantize_precision)) ) @@ -392,5 +393,5 @@ async def get_current_credits(request: web.Request) -> web.Response: if not project: raise web.HTTPNotFound(reason=f"No credits found for {project_name}.") return web.json_response( - {"current_credits": float(project[0].used_credits)} + {"current_credits": float(project[0].used_credits), "granted_credits": float(project[0].granted_credits)} )