multiple_domains
parent
459c8afd6c
commit
f7ae4cc7b0
|
@ -11,22 +11,25 @@ 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
|
||||
if self.args.domains:
|
||||
return {"domains": [instance["domain"] for instance in instance_details]},200
|
||||
return {"instances": instance_details},200
|
||||
|
||||
|
||||
class Endorsements(Resource):
|
||||
get_parser = reqparse.RequestParser()
|
||||
get_parser.add_argument("Client-Agent", default="unknown:0:unknown", type=str, required=False, help="The client name and version.", location="headers")
|
||||
|
@ -140,4 +143,4 @@ class Endorsements(Resource):
|
|||
instance=target_instance,
|
||||
)
|
||||
logger.info(f"{instance.domain} Withdrew endorsement from {domain}")
|
||||
return {"message":'Changed'}, 200
|
||||
return {"message":'Changed'}, 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
|
||||
|
@ -247,4 +253,4 @@ def get_instances_by_ids(instance_ids):
|
|||
query = Instance.query.filter(
|
||||
Instance.id.in_(instance_ids)
|
||||
)
|
||||
return query
|
||||
return query
|
||||
|
|
Loading…
Reference in New Issue