multiple_domains
parent
459c8afd6c
commit
f7ae4cc7b0
|
@ -11,15 +11,18 @@ class Approvals(Resource):
|
|||
@cache.cached(timeout=10, query_string=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)
|
||||
def get(self, domain):
|
||||
'''Display all endorsements given by a specific domain
|
||||
def get(self, domains):
|
||||
'''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()
|
||||
instance = database.find_instance_by_domain(domain)
|
||||
if not instance:
|
||||
raise e.NotFound(f"No Instance found matching provided domain. Have you remembered to register it?")
|
||||
instances = database.find_multiple_instance_by_domains(domains_list)
|
||||
if not instances:
|
||||
raise e.NotFound(f"No Instances found matching any of the provided domains. Have you remembered to register them?")
|
||||
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())
|
||||
if self.args.csv:
|
||||
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()
|
||||
|
||||
|
||||
def get_all_endorsed_instances_by_approving_id(approving_id):
|
||||
def get_all_endorsed_instances_by_approving_id(approving_ids):
|
||||
query = db.session.query(
|
||||
Instance
|
||||
).outerjoin(
|
||||
|
@ -43,13 +43,13 @@ def get_all_endorsed_instances_by_approving_id(approving_id):
|
|||
).options(
|
||||
joinedload(Instance.endorsements),
|
||||
).filter(
|
||||
Endorsement.approving_id == approving_id
|
||||
Endorsement.approving_id.in_(approving_ids)
|
||||
).group_by(
|
||||
Instance.id
|
||||
)
|
||||
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(
|
||||
Instance
|
||||
).outerjoin(
|
||||
|
@ -57,7 +57,7 @@ def get_all_approving_instances_by_endorsed_id(endorsed_id):
|
|||
).options(
|
||||
joinedload(Instance.approvals),
|
||||
).filter(
|
||||
Endorsement.endorsed_id == endorsed_id
|
||||
Endorsement.endorsed_id.in_(endorsed_ids)
|
||||
).group_by(
|
||||
Instance.id
|
||||
)
|
||||
|
@ -156,6 +156,12 @@ def find_instance_by_domain(domain):
|
|||
instance = Instance.query.filter_by(domain=domain).first()
|
||||
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):
|
||||
instance = Instance.query.join(
|
||||
Claim
|
||||
|
|
Loading…
Reference in New Issue