Allow to return as list or csv
parent
b45cd82196
commit
95fa51a403
|
@ -14,11 +14,8 @@ class Models:
|
||||||
'signup': fields.Boolean(default=False,description="True when subscriptions are open, else False"),
|
'signup': fields.Boolean(default=False,description="True when subscriptions are open, else False"),
|
||||||
'user_post_ratio': fields.Float(description="Users to Post Ratio"),
|
'user_post_ratio': fields.Float(description="Users to Post Ratio"),
|
||||||
})
|
})
|
||||||
self.input_model_SusInstances_post = api.model('SuspiciousInstancesListInput', {
|
self.response_model_model_SusInstances_get = api.model('SuspiciousInstancesDomainList', {
|
||||||
'user_to_post_ratio': fields.Integer(default=20,description="The threshold over which to consider instances suspicious."),
|
'instances': fields.List(fields.Nested(self.response_model_suspicious_instances)),
|
||||||
'whitelist': fields.List(fields.String(description="List of domains to avoid returning in the supicion list.")),
|
'domains': fields.List(fields.String(description="The suspicious domains as a list.")),
|
||||||
'blacklist': fields.List(fields.String(description="List of domains to append to the supicion list.")),
|
'csv': fields.String(description="The suspicious domains as a csv."),
|
||||||
})
|
|
||||||
self.response_model_model_SusInstances_post = api.model('SuspiciousInstancesDomainList', {
|
|
||||||
'domains': fields.List(fields.String(description="The domains in shit suspicious list.")),
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -19,43 +19,22 @@ def get_request_path():
|
||||||
class SusInstances(Resource):
|
class SusInstances(Resource):
|
||||||
get_parser = reqparse.RequestParser()
|
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")
|
get_parser.add_argument("Client-Agent", default="unknown:0:unknown", type=str, required=False, help="The client name and version.", location="headers")
|
||||||
|
get_parser.add_argument("domains", required=False, default=False, type=bool, help="Set to true to return just the domains as a list. Mutually exclusive with csv", location="args")
|
||||||
get_parser.add_argument("user_to_post_ratio", required=False, default=20, type=int, help="The amount of local users / amount of local posts to consider suspicious", location="args")
|
get_parser.add_argument("user_to_post_ratio", required=False, default=20, type=int, help="The amount of local users / amount of local posts to consider suspicious", location="args")
|
||||||
|
get_parser.add_argument("csv", required=False, default=False, type=bool, help="Set to true to return just the domains as a csv. Mutually exclusive with domains", location="args")
|
||||||
|
|
||||||
@api.expect(get_parser)
|
@api.expect(get_parser)
|
||||||
@logger.catch(reraise=True)
|
@logger.catch(reraise=True)
|
||||||
@cache.cached(timeout=10, query_string=True)
|
@cache.cached(timeout=10, query_string=True)
|
||||||
@api.marshal_with(models.response_model_suspicious_instances, code=200, description='Suspicious Instances', as_list=True, skip_none=True)
|
@api.marshal_with(models.response_model_model_SusInstances_get, code=200, description='Suspicious Instances', skip_none=True)
|
||||||
def get(self):
|
def get(self):
|
||||||
'''A List with the details of all suspicious instances
|
'''A List with the details of all suspicious instances
|
||||||
'''
|
'''
|
||||||
self.args = self.get_parser.parse_args()
|
self.args = self.get_parser.parse_args()
|
||||||
return retrieve_suspicious_instances(self.args.user_to_post_ratio),200
|
|
||||||
|
|
||||||
post_parser = reqparse.RequestParser()
|
|
||||||
post_parser.add_argument("Client-Agent", default="unknown:0:unknown", type=str, required=False, help="The client name and version.", location="headers")
|
|
||||||
post_parser.add_argument("user_to_post_ratio", required=False, default=20, type=int, help="The amount of local users / amount of local posts to consider suspicious", location="json")
|
|
||||||
post_parser.add_argument("whitelist", type=list, required=False, help="Workers to whitelist even if we think they're suspicious", location="json")
|
|
||||||
post_parser.add_argument("blacklist", type=list, required=False, help="Extra workers to blacklist.", location="json")
|
|
||||||
|
|
||||||
@api.expect(post_parser, models.input_model_SusInstances_post, validate=True)
|
|
||||||
@logger.catch(reraise=True)
|
|
||||||
# @cache.cached(timeout=10, query_string=True)
|
|
||||||
@api.marshal_with(models.response_model_model_SusInstances_post, code=200, description='Suspicious Instances List')
|
|
||||||
@api.response(400, 'Validation Error', models.response_model_error)
|
|
||||||
def post(self):
|
|
||||||
'''A List with just the domains of all suspicious instances
|
|
||||||
This can then be easily converted into a defederation list
|
|
||||||
'''
|
|
||||||
self.args = self.post_parser.parse_args()
|
|
||||||
logger.debug(self.args)
|
|
||||||
sus_instances = retrieve_suspicious_instances(self.args.user_to_post_ratio)
|
sus_instances = retrieve_suspicious_instances(self.args.user_to_post_ratio)
|
||||||
final_list = []
|
logger.debug(self.args)
|
||||||
if self.args.blacklist:
|
if self.args.csv:
|
||||||
final_list = self.args.blacklist
|
return {"csv": ",".join([instance["domain"] for instance in sus_instances])},200
|
||||||
whitelist = []
|
if self.args.domains:
|
||||||
if self.args.whitelist:
|
return {"domains": [instance["domain"] for instance in sus_instances]},200
|
||||||
whitelist = self.args.whitelist
|
return {"instances": sus_instances},200
|
||||||
for instance in sus_instances:
|
|
||||||
if instance["domain"] not in whitelist:
|
|
||||||
final_list.append(instance["domain"])
|
|
||||||
return {"domains": final_list},200
|
|
||||||
|
|
Loading…
Reference in New Issue