delete instance

pull/3/head
db0 2023-06-22 02:37:25 +02:00
parent 75ddffb0c1
commit c21caa6d08
2 changed files with 27 additions and 0 deletions

View File

@ -5,6 +5,9 @@ class Models:
self.response_model_error = api.model('RequestError', { self.response_model_error = api.model('RequestError', {
'message': fields.String(description="The error message for this status code."), 'message': fields.String(description="The error message for this status code."),
}) })
self.response_model_simple_response = api.model('SimpleResponse', {
"message": fields.String(default='OK',required=True, description="The result of this operation."),
})
self.response_model_suspicious_instances = api.model('SuspiciousInstances', { self.response_model_suspicious_instances = api.model('SuspiciousInstances', {
'domain': fields.String(description="The instance domain"), 'domain': fields.String(description="The instance domain"),
'uptime_alltime': fields.Float(description="The instance uptime pct. 100% and thousand of users is unlikely"), 'uptime_alltime': fields.Float(description="The instance uptime pct. 100% and thousand of users is unlikely"),

View File

@ -131,3 +131,27 @@ class Whitelist(Resource):
instance.api_key = hash_api_key(new_key) instance.api_key = hash_api_key(new_key)
db.session.commit() db.session.commit()
return instance.get_details(),200 return instance.get_details(),200
delete_parser = reqparse.RequestParser()
delete_parser.add_argument("apikey", type=str, required=True, help="The sending instance's API key.", location='headers')
delete_parser.add_argument("Client-Agent", default="unknown:0:unknown", type=str, required=False, help="The client name and version.", location="headers")
delete_parser.add_argument("domain", required=False, type=str, help="The instance domain. It MUST be alredy registered in https://overctrl.dbzer0.com", location="json")
@api.expect(delete_parser)
@api.marshal_with(models.response_model_simple_response, code=200, description='Instances', skip_none=True)
def delete(self):
'''Delete instance from overseer
'''
self.args = self.patch_parser.parse_args()
if not self.args.apikey:
raise e.Unauthorized("You must provide the API key that was PM'd to your overctrl.dbzer0.com account")
instance = database.find_authenticated_instance(self.args.domain, self.args.apikey)
if not instance:
raise e.BadRequest(f"No Instance found matching provided API key and domain. Have you remembered to register it?")
if self.args.domain == os.getenv('OVERSEER_LEMMY_DOMAIN'):
raise e.Forbidden("Cannot delete overseer control instance")
db.session.delete(instance)
db.session.commit()
logger.warning(f"{self.args.domain} deleted")
return {"message":'OK'}, 200