Beispiel #1
0
 def delete(self, device_id: int):
     """
     Deletes the resource with the given name.
     """
     device = self._get_or_abort(device_id)
     session.delete(device)
     session.commit()
     return '', 204
Beispiel #2
0
 def delete(self, device_id: int):
     """
     Deletes the resource with the given name.
     """
     device = self._get_or_abort(device_id)
     session.delete(device)
     session.commit()
     return '', 204
Beispiel #3
0
 def delete(self, vpn_id: int):
     """
     Deletes the resource with the given name.
     """
     vpn = self._get_or_abort(vpn_id)
     session.delete(vpn)
     session.commit()
     return '', 204
Beispiel #4
0
 def delete(self, user_name: str):
     """
     Deletes the resource with the given name.
     """
     user = self._get_or_abort(user_name)
     session.delete(user)
     session.commit()
     return '', 204
Beispiel #5
0
def create_admin(username, password, config=None):
    _init_app(config)
    user = User()
    user.name = username
    user.password = password
    user.is_admin = True
    user.generate_api_key()
    session.add(user)
    session.commit()
Beispiel #6
0
 def post(self) -> Device:
     device = Device()
     session.add(device)
     self.update(device)
     session.flush()
     session.commit()
     return device, 201, {
         'Location': url_for('device', device_id=device.id)
     }
Beispiel #7
0
def create_admin(username, password, config=None):
    _init_app(config)
    user = User()
    user.name = username
    user.password = password
    user.is_admin = True
    user.generate_api_key()
    session.add(user)
    session.commit()
Beispiel #8
0
 def put(self, vpn_id: int) -> Vpn:
     """
     Updates the Vpn Resource with the
     name.
     """
     vpn = self._get_or_abort(vpn_id)
     self.update(vpn)
     session.commit()
     return vpn
Beispiel #9
0
 def post(self) -> Device:
     device = Device()
     session.add(device)
     self.update(device)
     session.flush()
     session.commit()
     return device, 201, {
         'Location': url_for('device', device_id=device.id)
     }
Beispiel #10
0
 def put(self, device_id: int) -> Device:
     """
     Updates the Device Resource with the
     name.
     """
     device = self._get_or_abort(device_id)
     self.update(device)
     session.commit()
     session.add(device)
     return device
Beispiel #11
0
 def put(self, device_id: int) -> Device:
     """
     Updates the Device Resource with the
     name.
     """
     device = self._get_or_abort(device_id)
     self.update(device)
     session.commit()
     session.add(device)
     return device
Beispiel #12
0
def reset_password(username, password=None, config=None):
    _init_app(config)
    user = session.query(User).filter(User.name == username).first()
    if user is None:
        print('User %s not found' % username)
    if password is None:
        password = getpass('Enter new password: '******'Password reset done for user %s' % username)
Beispiel #13
0
def reset_password(username, password=None, config=None):
    _init_app(config)
    user = session.query(User).filter(User.name == username).first()
    if user is None:
        print('User %s not found' % username)
    if password is None:
        password = getpass('Enter new password: '******'Password reset done for user %s' % username)
Beispiel #14
0
 def post(self) -> Vpn:
     """
     Creates the vpn with the given data.
     """
     vpn = Vpn()
     session.add(vpn)
     self.update(vpn)
     session.flush()
     session.commit()
     return vpn, 201, {
         'Location': url_for('vpn', vpn_id=vpn.id)
     }
Beispiel #15
0
 def post(self) -> User:
     args = parser.parse_args()
     user = self._get_by_username(args.name)
     if user is not None:
         abort(409, message='User already exists')
     user = User()
     self.update(user)
     session.add(user)
     session.commit()
     return user, 201, {
         'Location': url_for('user', user_name=user.name)
     }
Beispiel #16
0
 def put(self, user_name: str) -> User:
     """
     Updates the User Resource with the
     name.
     """
     current = current_user()
     if current.name == user_name or current.is_admin:
         user = self._get_or_abort(user_name)
         self.update(user)
         session.commit()
         session.add(user)
         return user
     else:
         abort(403)