Skip to content

Commit

Permalink
RCTab Models (#35)
Browse files Browse the repository at this point in the history
* Use rctab_models for usage function

* Use rctab_models for controller function

* Use rctab_models for status function

* Add Type Hints to Usage Function (#33)

* WIP

* Add typing to usage function

* Black formatting (#34)

* Remove black from status deps

* Remove black from controller deps

* Remove black from usage deps

* Update black hook

* Run updated black

* Run black

* Fix test failures

* Run black
  • Loading branch information
Iain-S authored Sep 4, 2024
1 parent 17055ba commit fa1a7bd
Show file tree
Hide file tree
Showing 35 changed files with 1,439 additions and 1,699 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
args: ["--autofix", "--no-ensure-ascii", "--no-sort-keys"]
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 24.8.0
hooks:
- id: black
- repo: https://github.com/jackdewinter/pymarkdown
Expand Down
4 changes: 3 additions & 1 deletion controller_function/controller/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""An Azure Function App to disable subscriptions."""

import logging
from datetime import datetime
from typing import Iterable
Expand All @@ -7,9 +8,10 @@
import azure.functions as func
from azure.core.exceptions import HttpResponseError
from pydantic import HttpUrl
from rctab_models import models
from requests import get

from controller import models, settings
from controller import settings
from controller.auth import BearerAuth
from controller.logutils import add_log_handler_once
from controller.subscription import disable_subscription, enable_subscription
Expand Down
1 change: 1 addition & 0 deletions controller_function/controller/logutils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utils to send logs to Azure Application Insights."""

import logging
from typing import Optional

Expand Down
33 changes: 0 additions & 33 deletions controller_function/controller/models.py

This file was deleted.

1 change: 1 addition & 0 deletions controller_function/controller/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Configuration for the app."""

from functools import lru_cache
from typing import Optional

Expand Down
1 change: 1 addition & 0 deletions controller_function/controller/subscription.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Manage subscription life cycle."""

import logging
from uuid import UUID

Expand Down
894 changes: 436 additions & 458 deletions controller_function/poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion controller_function/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ pydantic = "^2.7.1"
pydantic-settings = "^2.2.1"
PyJWT = {extras = ["crypto"], version = "^2.8.0"}
requests = "^2.31.0"
rctab_models = { git = "https://github.com/alan-turing-institute/rctab-models", tag = "0.1.0" }

[tool.poetry.group.dev.dependencies]
black = "^24.4.2"
coverage = "^7.5.1"
flake8 = "^3.9.2"
isort = "^5.13.2"
Expand Down
1 change: 1 addition & 0 deletions controller_function/run_now.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Force our Azure function to run, regardless of the time."""

import types

from controller import main
Expand Down
3 changes: 2 additions & 1 deletion controller_function/tests/test_function_app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for controller package."""

import json
import logging
from typing import Final
Expand All @@ -11,9 +12,9 @@
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import rsa
from pydantic import HttpUrl, TypeAdapter
from rctab_models.models import DesiredState

import controller
from controller.models import DesiredState

HTTP_ADAPTER: Final = TypeAdapter(HttpUrl)
VALID_URL: Final = HTTP_ADAPTER.validate_python("https://my.org")
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Configuration file for the Sphinx documentation builder."""

import os
import pathlib
import sys
Expand Down
894 changes: 436 additions & 458 deletions status_function/poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion status_function/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ pydantic = "^2.7.1"
pydantic-settings = "^2.2.1"
PyJWT = {extras = ["crypto"], version = "^2.8.0"}
requests = "^2.31.0"
rctab_models = { git = "https://github.com/alan-turing-institute/rctab-models", tag = "0.1.0" }

[tool.poetry.group.dev.dependencies]
black = "^24.4.2"
coverage = "^7.5.1"
flake8 = "^3.9.2"
isort = "^5.13.2"
Expand Down
1 change: 1 addition & 0 deletions status_function/run_now.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Force our Azure function to run, regardless of the time."""

import types

from status import main
Expand Down
7 changes: 4 additions & 3 deletions status_function/status/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Azure AD graph. See https://docs.microsoft.com/en-us/graph/auth-v2-service#4-get-an-access-token # noqa pylint: disable=C0301
"""

import logging
from datetime import datetime
from functools import lru_cache
Expand All @@ -21,11 +22,11 @@
from azure.mgmt.subscription import SubscriptionClient
from msrestazure.azure_exceptions import CloudError
from pydantic import HttpUrl
from rctab_models import models

from status import models, settings
from status import settings
from status.auth import BearerAuth
from status.logutils import add_log_handler_once
from status.models import RoleAssignment
from status.wrapper import CredentialWrapper

logging.basicConfig(
Expand Down Expand Up @@ -254,7 +255,7 @@ def get_role_assignment_models(
def get_subscription_role_assignment_models(
subscription: Any,
graph_client: GraphRbacManagementClient,
) -> list[RoleAssignment]:
) -> list[models.RoleAssignment]:
"""Get the role assignment models for each a subscription.
Args:
Expand Down
1 change: 1 addition & 0 deletions status_function/status/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ACCESS_TOKEN_EXPIRE_MINUTES: The number of minutes before an access token.
value is 5.
"""

from datetime import datetime, timedelta

import jwt
Expand Down
1 change: 1 addition & 0 deletions status_function/status/logutils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utils to send logs to Azure Application Insights."""

import logging
from typing import Optional

Expand Down
74 changes: 0 additions & 74 deletions status_function/status/models.py

This file was deleted.

1 change: 1 addition & 0 deletions status_function/status/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Configuration for the app."""

from functools import lru_cache
from typing import Optional
from uuid import UUID
Expand Down
1 change: 1 addition & 0 deletions status_function/status/wrapper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Copied from https://stackoverflow.com/a/64129363/3324095 and slightly modified."""

from typing import Optional

from azure.core.pipeline import PipelineContext, PipelineRequest
Expand Down
3 changes: 2 additions & 1 deletion status_function/tests/test_function_app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for status package."""

import logging
from datetime import datetime
from importlib import import_module
Expand All @@ -14,9 +15,9 @@
from cryptography.hazmat.primitives.asymmetric import rsa
from msrestazure.azure_exceptions import CloudError
from pydantic import HttpUrl, TypeAdapter
from rctab_models.models import RoleAssignment, SubscriptionState, SubscriptionStatus

import status
from status.models import RoleAssignment, SubscriptionState, SubscriptionStatus

HTTP_ADAPTER: Final = TypeAdapter(HttpUrl)
VALID_URL: Final = HTTP_ADAPTER.validate_python("https://my.org")
Expand Down
3 changes: 2 additions & 1 deletion usage_function/costmanagement/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""An Azure function to collect cost-management information."""

import logging
from datetime import datetime, timedelta
from typing import Final
Expand All @@ -16,9 +17,9 @@
QueryTimePeriod,
TimeframeType,
)
from rctab_models import models

import utils.settings
from utils import models
from utils.auth import BearerAuth
from utils.logutils import add_log_handler_once

Expand Down
1 change: 1 addition & 0 deletions usage_function/monthly_usage/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""An Azure Function App to collect usage information for the previous month."""

import logging
import time
from datetime import date, datetime, timedelta
Expand Down
Loading

0 comments on commit fa1a7bd

Please sign in to comment.