selfprivacy-rest-api/selfprivacy_api/resources/services/bitwarden.py

67 lines
1.5 KiB
Python
Raw Normal View History

2021-11-11 20:31:28 +02:00
#!/usr/bin/env python3
2021-11-16 18:14:01 +02:00
"""Bitwarden management module"""
from flask_restful import Resource
2021-11-11 20:31:28 +02:00
from selfprivacy_api.resources.services import api
2021-11-22 18:50:50 +02:00
from selfprivacy_api.utils import WriteUserData
2021-11-11 20:31:28 +02:00
2021-11-16 18:14:01 +02:00
2021-11-11 20:31:28 +02:00
class EnableBitwarden(Resource):
2021-11-16 18:14:01 +02:00
"""Enable Bitwarden"""
2021-11-11 20:31:28 +02:00
def post(self):
2021-11-16 18:14:01 +02:00
"""
Enable Bitwarden
---
tags:
- Bitwarden
security:
- bearerAuth: []
responses:
200:
description: Bitwarden enabled
401:
description: Unauthorized
"""
2021-11-22 18:50:50 +02:00
with WriteUserData() as data:
if "bitwarden" not in data:
data["bitwarden"] = {}
data["bitwarden"]["enable"] = True
2021-11-11 20:31:28 +02:00
return {
"status": 0,
"message": "Bitwarden enabled",
}
class DisableBitwarden(Resource):
2021-11-16 18:14:01 +02:00
"""Disable Bitwarden"""
2021-11-11 20:31:28 +02:00
def post(self):
2021-11-16 18:14:01 +02:00
"""
Disable Bitwarden
---
tags:
- Bitwarden
security:
- bearerAuth: []
responses:
200:
description: Bitwarden disabled
401:
description: Unauthorized
"""
2021-11-22 18:50:50 +02:00
with WriteUserData() as data:
if "bitwarden" not in data:
data["bitwarden"] = {}
data["bitwarden"]["enable"] = False
2021-11-11 20:31:28 +02:00
return {
"status": 0,
"message": "Bitwarden disabled",
}
api.add_resource(EnableBitwarden, "/bitwarden/enable")
api.add_resource(DisableBitwarden, "/bitwarden/disable")