Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add models for ADR-validator boefje #181

Merged
merged 2 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions octopoes/octopoes/models/ooi/findings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def format_reference_human_readable(cls, reference: Reference) -> str:
return reference.tokenized.id


class ADRFindingType(FindingType):
object_type: Literal["ADRFindingType"] = "ADRFindingType"


class CVEFindingType(FindingType):
object_type: Literal["CVEFindingType"] = "CVEFindingType"

Expand Down
65 changes: 64 additions & 1 deletion octopoes/octopoes/models/ooi/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@

from pydantic import AnyUrl

from octopoes.models import OOI, Reference
from octopoes.models import OOI, Reference, PrimaryKeyToken
from octopoes.models.ooi.certificate import X509Certificate
from octopoes.models.ooi.dns.zone import Hostname
from octopoes.models.ooi.network import IPAddress, Network
from octopoes.models.ooi.service import IPService
from octopoes.models.persistence import ReferenceField


def format_web_url_token(token: PrimaryKeyToken) -> str:
port = f":{token.port}" if token.port else ""
try:
netloc = token.netloc.address
except KeyError:
netloc = token.netloc.name

return f"{token.scheme}://{netloc}{port}{token.path}"


class Website(OOI):
object_type: Literal["Website"] = "Website"

Expand Down Expand Up @@ -221,3 +231,56 @@ def format_reference_human_readable(cls, reference: Reference) -> str:
address = t.resource.website.ip_service.ip_port.address.address

return f"{web_url} @ {address}"


class RESTAPI(OOI):
object_type: Literal["RESTAPI"] = "RESTAPI"

api_url: Reference = ReferenceField(WebURL)

_natural_key_attrs = ["api_url"]
_reverse_relation_names = {
"api_url": "api_url_of",
}

@classmethod
def format_reference_human_readable(cls, reference: Reference) -> str:
return format_web_url_token(reference.tokenized.api_url)


class APIDesignRule(OOI):
object_type: Literal["APIDesignRule"] = "APIDesignRule"

name: str

_natural_key_attrs = ["name"]
_reverse_relation_names = {}
_traversable = False

@classmethod
def format_reference_human_readable(cls, reference: Reference) -> str:
return reference.tokenized.name


class APIDesignRuleResult(OOI):
object_type: Literal["APIDesignRuleResult"] = "APIDesignRuleResult"

rest_api: Reference = ReferenceField(RESTAPI)
rule: Reference = ReferenceField(APIDesignRule)
passed: bool
message: str

_natural_key_attrs = ["rest_api", "rule"]
_reverse_relation_names = {
"rest_api": "api_design_rule_results",
"rule": "results",
}

@classmethod
def format_reference_human_readable(cls, reference: Reference) -> str:
t = reference.tokenized

rule = t.rule.name
api_url = format_web_url_token(t.rest_api.api_url)

return f"{rule} @ {api_url}"
14 changes: 11 additions & 3 deletions octopoes/octopoes/models/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from octopoes.models.ooi.dns.zone import Hostname, DNSZone, ResolvedHostname
from octopoes.models.ooi.findings import (
Finding,
ADRFindingType,
KATFindingType,
CVEFindingType,
CWEFindingType,
Expand Down Expand Up @@ -63,6 +64,9 @@
HTTPHeaderURL,
HTTPHeaderHostname,
ImageMetadata,
RESTAPI,
APIDesignRule,
APIDesignRuleResult,
)

CertificateType = Union[
Expand All @@ -83,8 +87,8 @@
ResolvedHostname,
NXDOMAIN,
]
FindingType = Union[
Finding,
FindingTypeType = Union[
ADRFindingType,
KATFindingType,
CVEFindingType,
RetireJSFindingType,
Expand Down Expand Up @@ -113,6 +117,9 @@
HTTPHeaderURL,
HTTPHeaderHostname,
ImageMetadata,
RESTAPI,
APIDesignRule,
APIDesignRuleResult,
]
EmailSecurityType = Union[
DNSSPFRecord,
Expand All @@ -130,7 +137,6 @@
CertificateType,
DnsType,
DnsRecordType,
FindingType,
NetworkType,
ServiceType,
SoftwareType,
Expand All @@ -141,6 +147,8 @@
DNSSPFRecord,
MonitoringType,
EmailSecurityType,
Finding,
FindingTypeType,
]


Expand Down
85 changes: 85 additions & 0 deletions rocky/OOI_database_seed.json
Original file line number Diff line number Diff line change
Expand Up @@ -1173,5 +1173,90 @@
},
"consult_api": false
}
},
{
"model": "tools.ooiinformation",
"pk": "ADRFindingType|API-03",
"fields": {
"last_updated": "2023-02-09T15:42:42.000Z",
"data": {
"description": "Only apply standard HTTP methods",
"risk": "Recommendation"
},
"consult_api": false
}
},
{
"model": "tools.ooiinformation",
"pk": "ADRFindingType|API-16",
"fields": {
"last_updated": "2023-02-09T15:42:42.000Z",
"data": {
"description": "Use OpenAPI Specification for documentation",
"risk": "Recommendation"

},
"consult_api": false
}
},
{
"model": "tools.ooiinformation",
"pk": "ADRFindingType|API-20",
"fields": {
"last_updated": "2023-02-09T15:42:42.000Z",
"data": {
"description": "Include the major version number in the URI",
"risk": "Recommendation"
},
"consult_api": false
}
},
{
"model": "tools.ooiinformation",
"pk": "ADRFindingType|API-48",
"fields": {
"last_updated": "2023-02-09T15:42:42.000Z",
"data": {
"description": "Leave off trailing slashes from URIs",
"risk": "Recommendation"
},
"consult_api": false
}
},
{
"model": "tools.ooiinformation",
"pk": "ADRFindingType|API-51",
"fields": {
"last_updated": "2023-02-09T15:42:42.000Z",
"data": {
"description": "Publish OAS document at a standard location in JSON-format",
"risk": "Recommendation"
},
"consult_api": false
}
},
{
"model": "tools.ooiinformation",
"pk": "ADRFindingType|API-56",
"fields": {
"last_updated": "2023-02-09T15:42:42.000Z",
"data": {
"description": "Adhere to the Semantic Versioning model when releasing API changes",
"risk": "Recommendation"
},
"consult_api": false
}
},
{
"model": "tools.ooiinformation",
"pk": "ADRFindingType|API-57",
"fields": {
"last_updated": "2023-02-09T15:42:42.000Z",
"data": {
"description": "Return the full version number in a response header",
"risk": "Recommendation"
},
"consult_api": false
}
}
]