multiple_domains
parent
459c8afd6c
commit
f7ae4cc7b0
|
@ -11,15 +11,18 @@ class Approvals(Resource):
|
||||||
@cache.cached(timeout=10, query_string=True)
|
@cache.cached(timeout=10, query_string=True)
|
||||||
@api.marshal_with(models.response_model_model_Whitelist_get, code=200, description='Instances', skip_none=True)
|
@api.marshal_with(models.response_model_model_Whitelist_get, code=200, description='Instances', skip_none=True)
|
||||||
@api.response(404, 'Instance not registered', models.response_model_error)
|
@api.response(404, 'Instance not registered', models.response_model_error)
|
||||||
def get(self, domain):
|
def get(self, domains):
|
||||||
'''Display all endorsements given by a specific domain
|
'''Display all endorsements given out by one or more domains
|
||||||
|
You can pass a comma-separated list of domain names and the results will be a set of all their
|
||||||
|
endorsements together.
|
||||||
'''
|
'''
|
||||||
|
domains_list = domains.split(',')
|
||||||
self.args = self.get_parser.parse_args()
|
self.args = self.get_parser.parse_args()
|
||||||
instance = database.find_instance_by_domain(domain)
|
instances = database.find_multiple_instance_by_domains(domains_list)
|
||||||
if not instance:
|
if not instances:
|
||||||
raise e.NotFound(f"No Instance found matching provided domain. Have you remembered to register it?")
|
raise e.NotFound(f"No Instances found matching any of the provided domains. Have you remembered to register them?")
|
||||||
instance_details = []
|
instance_details = []
|
||||||
for instance in database.get_all_endorsed_instances_by_approving_id(instance.id):
|
for instance in database.get_all_endorsed_instances_by_approving_id([instance.id for instance in instances]):
|
||||||
instance_details.append(instance.get_details())
|
instance_details.append(instance.get_details())
|
||||||
if self.args.csv:
|
if self.args.csv:
|
||||||
return {"csv": ",".join([instance["domain"] for instance in instance_details])},200
|
return {"csv": ",".join([instance["domain"] for instance in instance_details])},200
|
||||||
|
|
|
@ -35,7 +35,7 @@ def get_all_instances(min_endorsements = 0, min_guarantors = 1):
|
||||||
return query.all()
|
return query.all()
|
||||||
|
|
||||||
|
|
||||||
def get_all_endorsed_instances_by_approving_id(approving_id):
|
def get_all_endorsed_instances_by_approving_id(approving_ids):
|
||||||
query = db.session.query(
|
query = db.session.query(
|
||||||
Instance
|
Instance
|
||||||
).outerjoin(
|
).outerjoin(
|
||||||
|
@ -43,13 +43,13 @@ def get_all_endorsed_instances_by_approving_id(approving_id):
|
||||||
).options(
|
).options(
|
||||||
joinedload(Instance.endorsements),
|
joinedload(Instance.endorsements),
|
||||||
).filter(
|
).filter(
|
||||||
Endorsement.approving_id == approving_id
|
Endorsement.approving_id.in_(approving_ids)
|
||||||
).group_by(
|
).group_by(
|
||||||
Instance.id
|
Instance.id
|
||||||
)
|
)
|
||||||
return query.all()
|
return query.all()
|
||||||
|
|
||||||
def get_all_approving_instances_by_endorsed_id(endorsed_id):
|
def get_all_approving_instances_by_endorsed_id(endorsed_ids):
|
||||||
query = db.session.query(
|
query = db.session.query(
|
||||||
Instance
|
Instance
|
||||||
).outerjoin(
|
).outerjoin(
|
||||||
|
@ -57,7 +57,7 @@ def get_all_approving_instances_by_endorsed_id(endorsed_id):
|
||||||
).options(
|
).options(
|
||||||
joinedload(Instance.approvals),
|
joinedload(Instance.approvals),
|
||||||
).filter(
|
).filter(
|
||||||
Endorsement.endorsed_id == endorsed_id
|
Endorsement.endorsed_id.in_(endorsed_ids)
|
||||||
).group_by(
|
).group_by(
|
||||||
Instance.id
|
Instance.id
|
||||||
)
|
)
|
||||||
|
@ -156,6 +156,12 @@ def find_instance_by_domain(domain):
|
||||||
instance = Instance.query.filter_by(domain=domain).first()
|
instance = Instance.query.filter_by(domain=domain).first()
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
def find_multiple_instance_by_domains(domains):
|
||||||
|
instance = Instance.query.filter(
|
||||||
|
Instance.domain.in_(domains)
|
||||||
|
).all()
|
||||||
|
return instance
|
||||||
|
|
||||||
def find_authenticated_instance(domain,api_key):
|
def find_authenticated_instance(domain,api_key):
|
||||||
instance = Instance.query.join(
|
instance = Instance.query.join(
|
||||||
Claim
|
Claim
|
||||||
|
|
Loading…
Reference in New Issue