forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
78 lines (65 loc) · 2.26 KB
/
__init__.py
File metadata and controls
78 lines (65 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import graphene
from graphene import relay
from graphene_sqlalchemy import SQLAlchemyObjectType
from graphene_sqlalchemy.types import ORMField
from models import Domains, Web_scans, Mail_scans
from scalars.slug import Slug
from scalars.url import URL
from schemas.shared_structures.domain.mail_scan import MailScan
from schemas.shared_structures.domain.web_scan import WebScan
class Domain(SQLAlchemyObjectType):
class Meta:
model = Domains
interfaces = (relay.Node,)
exclude_fields = (
"id",
"domain",
"last_run",
"selectors",
"organization_id",
"organization",
"web_scans",
"mail_scans",
"slug",
"dmarc_reports",
)
url = URL(description="The domain the scan was run on")
slug = Slug(description="Slug of the url")
last_ran = graphene.DateTime(
description="The last time that a scan was ran on this domain"
)
selectors = graphene.List(lambda: graphene.String, description="",)
organization = ORMField(model_attr="organization")
email = graphene.ConnectionField(
MailScan._meta.connection, description="DKIM, DMARC, and SPF scan results"
)
web = graphene.ConnectionField(
WebScan._meta.connection, description="HTTPS, and SSL scan results"
)
def resolve_url(self: Domains, info, **kwargs):
return self.domain
def resolve_slug(self: Domains, info, **kwargs):
return self.slug
def resolve_last_ran(self: Domains, info, **kwargs):
return self.last_run
def resolve_selectors(self: Domains, info, **kwargs):
return self.selectors
def resolve_email(self: Domains, info, **kwargs):
query = MailScan.get_query(info)
query = (
query.filter(Mail_scans.domain_id == self.id)
.order_by(Mail_scans.id.desc())
.all()
)
return query
def resolve_web(self: Domains, info, **kwargs):
query = WebScan.get_query(info)
query = (
query.filter(Web_scans.domain_id == self.id)
.order_by(Web_scans.id.desc())
.all()
)
return query
class DomainConnection(relay.Connection):
class Meta:
node = Domain