feat: find_instance

pull/8/head
db0 2023-06-26 00:24:00 +02:00
parent 453ac4ca19
commit 0cd7cf31cd
3 changed files with 33 additions and 1 deletions

View File

@ -39,3 +39,9 @@ class Models:
'domains': fields.List(fields.String(description="The instance domains as a list.")), 'domains': fields.List(fields.String(description="The instance domains as a list.")),
'csv': fields.String(description="The instance domains as a csv."), 'csv': fields.String(description="The instance domains as a csv."),
}) })
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."),
})

View File

@ -3,9 +3,11 @@ import fediseer.apis.v1.whitelist as whitelist
import fediseer.apis.v1.endorsements as endorsements import fediseer.apis.v1.endorsements as endorsements
import fediseer.apis.v1.guarantees as guarantees import fediseer.apis.v1.guarantees as guarantees
import fediseer.apis.v1.activitypub as activitypub import fediseer.apis.v1.activitypub as activitypub
import fediseer.apis.v1.find as find
from fediseer.apis.v1.base import api from fediseer.apis.v1.base import api
api.add_resource(base.Suspicions, "/instances") api.add_resource(base.Suspicions, "/instances")
api.add_resource(find.FindInstance, "/find_instance")
api.add_resource(activitypub.User, "/user/<string:username>") api.add_resource(activitypub.User, "/user/<string:username>")
api.add_resource(activitypub.Inbox, "/inbox/<string:username>") api.add_resource(activitypub.Inbox, "/inbox/<string:username>")
api.add_resource(whitelist.Whitelist, "/whitelist") api.add_resource(whitelist.Whitelist, "/whitelist")

View File

@ -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