lint: tidy up code some more, pylint is enforcing

This commit is contained in:
Iain Learmonth 2022-06-17 14:02:10 +01:00
parent 66b3ccc0f0
commit 61564e8c01
17 changed files with 72 additions and 38 deletions

View file

@ -24,7 +24,7 @@ class AbstractConfiguration(db.Model): # type: ignore
@property
@abstractmethod
def brn(self) -> str:
def brn(self) -> BRN:
raise NotImplementedError()
def destroy(self) -> None:
@ -80,12 +80,12 @@ class AbstractResource(db.Model): # type: ignore
def deprecate(self, *, reason: str) -> None:
if self.deprecated is not None:
logging.info("Deprecating %s (reason=%s)", (self.brn, reason))
logging.info("Deprecating %s (reason=%s)", self.brn, reason)
self.deprecated = datetime.utcnow()
self.deprecation_reason = reason
self.updated = datetime.utcnow()
else:
logging.info("Not deprecating %s (reason=%s) because it's already deprecated", (self.brn, reason))
logging.info("Not deprecating %s (reason=%s) because it's already deprecated", self.brn, reason)
def destroy(self) -> None:
if self.deprecated is None:

View file

@ -21,9 +21,9 @@ class Activity(db.Model): # type: ignore
text: str,
added: Optional[datetime.datetime] = None,
**kwargs: Any) -> None:
if type(activity_type) != str or len(activity_type) > 20 or activity_type == "":
if not isinstance(activity_type, str) or len(activity_type) > 20 or activity_type == "":
raise TypeError("expected string for activity type between 1 and 20 characters")
if type(text) != str:
if not isinstance(text, str):
raise TypeError("expected string for text")
super().__init__(id=id,
group_id=group_id,

View file

@ -1,6 +1,7 @@
import datetime
import enum
from app.brm.brn import BRN
from app.extensions import db
from app.models import AbstractConfiguration, AbstractResource
@ -21,6 +22,16 @@ class Automation(AbstractConfiguration):
logs = db.relationship("AutomationLogs", back_populates="automation")
@property
def brn(self) -> BRN:
return BRN(
group_id=0,
product="core",
provider="",
resource_type="automation",
resource_id=self.short_name
)
def kick(self) -> None:
self.enabled = True
self.next_run = datetime.datetime.utcnow()
@ -32,3 +43,13 @@ class AutomationLogs(AbstractResource):
logs = db.Column(db.Text)
automation = db.relationship("Automation", back_populates="logs")
@property
def brn(self) -> BRN:
return BRN(
group_id=0,
product="core",
provider="",
resource_type="automationlog",
resource_id=self.id
)

View file

@ -1,6 +1,5 @@
from typing import Optional, List
from flask import current_app
from tldextract import extract
from app.brm.brn import BRN
@ -20,8 +19,14 @@ class Origin(AbstractConfiguration):
proxies = db.relationship("Proxy", back_populates="origin")
@property
def brn(self) -> str:
return f"brn:{current_app.config['GLOBAL_NAMESPACE']}:{self.group_id}:mirror:conf:origin/{self.domain_name}"
def brn(self) -> BRN:
return BRN(
group_id=self.group_id,
product="mirror",
provider="conf",
resource_type="origin",
resource_id="self.domain_name"
)
@classmethod
def csv_header(cls) -> List[str]: