From 0cd7cf31cd36316dbde040d9144fa7f11073761a Mon Sep 17 00:00:00 2001 From: db0 Date: Mon, 26 Jun 2023 00:24:00 +0200 Subject: [PATCH] feat: find_instance --- fediseer/apis/models/v1.py | 8 +++++++- fediseer/apis/v1/__init__.py | 2 ++ fediseer/apis/v1/find.py | 24 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 fediseer/apis/v1/find.py diff --git a/fediseer/apis/models/v1.py b/fediseer/apis/models/v1.py index 9a0dcbb..e4879d6 100644 --- a/fediseer/apis/models/v1.py +++ b/fediseer/apis/models/v1.py @@ -38,4 +38,10 @@ class Models: 'instances': fields.List(fields.Nested(self.response_model_instances)), 'domains': fields.List(fields.String(description="The instance domains as a list.")), 'csv': fields.String(description="The instance domains as a csv."), - }) \ No newline at end of file + }) + self.response_model_model_Suspicions_get = api.model('SuspiciousInstances', { + 'self': fields.Nested(self.response_model_instances), + 'guaranteed': fields.List(fields.Nested(self.response_model_instances)), + 'endorsed': fields.List(fields.String(description="The suspicious domains as a list.")), + 'endorsing': fields.String(description="The suspicious domains as a csv."), + }) diff --git a/fediseer/apis/v1/__init__.py b/fediseer/apis/v1/__init__.py index c999cb4..9742f26 100644 --- a/fediseer/apis/v1/__init__.py +++ b/fediseer/apis/v1/__init__.py @@ -3,9 +3,11 @@ import fediseer.apis.v1.whitelist as whitelist import fediseer.apis.v1.endorsements as endorsements import fediseer.apis.v1.guarantees as guarantees import fediseer.apis.v1.activitypub as activitypub +import fediseer.apis.v1.find as find from fediseer.apis.v1.base import api api.add_resource(base.Suspicions, "/instances") +api.add_resource(find.FindInstance, "/find_instance") api.add_resource(activitypub.User, "/user/") api.add_resource(activitypub.Inbox, "/inbox/") api.add_resource(whitelist.Whitelist, "/whitelist") diff --git a/fediseer/apis/v1/find.py b/fediseer/apis/v1/find.py new file mode 100644 index 0000000..c69dfe5 --- /dev/null +++ b/fediseer/apis/v1/find.py @@ -0,0 +1,24 @@ +from fediseer.apis.v1.base import * + + +class FindInstance(Resource): + + get_parser = reqparse.RequestParser() + get_parser.add_argument("apikey", type=str, required=True, help="The sending instance's API key.", location='headers') + get_parser.add_argument("Client-Agent", default="unknown:0:unknown", type=str, required=False, help="The client name and version.", location="headers") + + + @api.expect(get_parser) + @api.marshal_with(models.response_model_instances, code=200, description='Instance', skip_none=True) + @api.response(401, 'Invalid API Key', models.response_model_error) + def get(self): + '''Retrieve instance information via API Key + ''' + self.args = self.get_parser.parse_args() + if not self.args.apikey: + raise e.Unauthorized("You must provide the API key that was PM'd admin account") + user = database.find_user_by_api_key(self.args.apikey) + if not user: + raise e.NotFound("API key not found. Please Claim an instance first and use the API key that is PM'd to you") + instance = database.find_instance_by_user(user) + return instance.get_details(),200