Ejemplo n.º 1
0
 def buy_post(self, ctx, member_id: int, payment_method: int,
              products: List[int]):
     try:
         self.product_manager.buy(ctx, member_id, payment_method, products)
         return None, 204
     except Exception as e:
         return handle_error(ctx, e)
Ejemplo n.º 2
0
 def get_from_number(self, ctx, vlan_number):
     """ Get the state of a port """
     try:
         return self.vlan_manager.get_from_number(
             ctx, vlan_number).to_dict(), 200
     except Exception as e:
         return handle_error(ctx, e)
Ejemplo n.º 3
0
Archivo: room.py Proyecto: minet/adh6
 def member_get(self, ctx, id_: int):
     try:
         if ctx.get(CTX_ADMIN) != id_ and Roles.ADMIN_WRITE.value not in ctx.get(CTX_ROLES, []):
             raise UnauthorizedError("Unauthorize to access this resource")
         return self.room_manager.room_from_member(ctx, id_), 200
     except Exception as e:
         return handle_error(ctx, e)
Ejemplo n.º 4
0
 def post(self, ctx, body: Dict[str, Any]):
     try:
         return self.api_key_manager.create(ctx=ctx,
                                            login=body.get('login', ''),
                                            roles=body.get('roles',
                                                           [])), 200
     except Exception as e:
         return handle_error(ctx, e)
Ejemplo n.º 5
0
 def member_put(self, ctx, id_: int, body: Dict[str, int]):
     try:
         if ctx.get(CTX_ADMIN) != id_ and Roles.ADMIN_WRITE.value not in ctx.get(CTX_ROLES, []):
             raise UnauthorizedError("Unauthorize to access this resource")
         self.mailinglist_manager.update_member_mailinglist(ctx, id_, body['value'])
         return NoContent, 204
     except Exception as e:
         return handle_error(ctx, e)
Ejemplo n.º 6
0
 def _update(self, ctx, function, klass: Type[Model], body, id: Optional[int] = None):
     try:
         body['id'] = 0  # Set a dummy id to pass the initial validation
         to_update = klass.from_dict(body) 
         the_object, created = function(ctx, to_update, id=id)
         return the_object.to_dict(), 201 if created else 204
     except Exception as e:
         return handle_error(ctx, e)
Ejemplo n.º 7
0
 def profile(self, ctx):
     try:
         member, roles = self.member_manager.get_profile(ctx)
         if member.id != ctx.get(CTX_ADMIN):
             raise UnauthorizedError(
                 "Not authorize to access this ressource")
         return {"member": member.to_dict(), "roles": roles}, 200
     except Exception as e:
         return handle_error(ctx, e)
Ejemplo n.º 8
0
Archivo: role.py Proyecto: minet/adh6
 def post(self, ctx, body: Dict[str, Any]):
     try:
         self.role_manager.create(ctx=ctx,
                                  auth=body["auth"],
                                  identifier=body["identifier"],
                                  roles=body["roles"])
         return NoContent, 201
     except Exception as e:
         return handle_error(ctx, e)
Ejemplo n.º 9
0
 def member_get(self, ctx, charter_id: int, id_: int):
     try:
         if ctx.get(CTX_ADMIN
                    ) != id_ and Roles.ADMIN_READ.value not in ctx.get(
                        CTX_ROLES, []):
             raise UnauthorizedError("Unauthorize to access this resource")
         return self.charter_manager.get(ctx, charter_id, id_), 200
     except Exception as e:
         return handle_error(ctx, e)
Ejemplo n.º 10
0
Archivo: member.py Proyecto: minet/adh6
 def subscription_patch(self, ctx, id_, body):
     try:
         LOG.debug("membership_patch_called",
                   extra=log_extra(ctx, body=body, id=id_))
         to_update = SubscriptionBody.from_dict(body)
         self.member_manager.update_subscription(ctx, id_, to_update)
         return NoContent, 204
     except Exception as e:
         return handle_error(ctx, e)
Ejemplo n.º 11
0
Archivo: member.py Proyecto: minet/adh6
    def subscription_post(self, ctx, id_: int, body: dict):
        """ Add a membership record in the database """
        LOG.debug("http_member_post_membership_called",
                  extra=log_extra(ctx, id=id_, request=body))

        try:
            created_membership = self.member_manager.create_subscription(
                ctx, id_, SubscriptionBody.from_dict(body))
            return created_membership.to_dict(), 200  # 200 OK
        except Exception as e:
            return handle_error(ctx, e)
Ejemplo n.º 12
0
Archivo: member.py Proyecto: minet/adh6
 def statuses_search(self, ctx, id_: int):
     try:
         return list(
             map(lambda x: x.to_dict(),
                 self.member_manager.get_statuses(ctx, id_))), 200
     except Exception as e:
         if isinstance(
                 e, NotFoundError
         ) and Roles.ADMIN_READ.value not in ctx.get(CTX_ROLES):
             e = UnauthorizedError("cannot access this resource")
         return handle_error(ctx, e)
Ejemplo n.º 13
0
Archivo: device.py Proyecto: minet/adh6
 def post(self, ctx, body: dict = {}):
     try:
         device_body = DeviceBody.from_dict(body)
         if ctx.get(
                 CTX_ADMIN
         ) != device_body.member and Roles.ADMIN_WRITE.value not in ctx.get(
                 CTX_ROLES, []):
             raise UnauthorizedError("Unauthorize to access this resource")
         return self.device_manager.create(ctx, device_body).id, 201
     except Exception as e:
         return handle_error(ctx, e)
Ejemplo n.º 14
0
Archivo: role.py Proyecto: minet/adh6
 def search(self, ctx, auth: str, id_: Union[str, None] = None):
     try:
         result, count = self.role_manager.search(ctx=ctx,
                                                  auth=auth,
                                                  identifier=id_)
         headers = {
             "X-Total-Count": str(count),
             'access-control-expose-headers': 'X-Total-Count'
         }
         return list(map(lambda x: x.to_dict(), result)), 200, headers
     except Exception as e:
         return handle_error(ctx, e)
Ejemplo n.º 15
0
Archivo: member.py Proyecto: minet/adh6
 def charter_put(self, ctx, id_, charter_id) -> Tuple[Any, int]:
     try:
         if ctx.get(CTX_ADMIN
                    ) != id_ and Roles.ADMIN_READ.value not in ctx.get(
                        CTX_ROLES, []):
             raise UnauthorizedError("Unauthorize to access this resource")
         self.charter_manager.sign(ctx,
                                   charter_id=charter_id,
                                   member_id=id_)
         return NoContent, 204
     except Exception as e:
         return handle_error(ctx, e)
Ejemplo n.º 16
0
 def vlan_put(self, ctx, id_, body):
     LOG.debug("http_port_vlan_put_called", extra=log_extra(ctx, id=id_))
     try:
         if (self.switch_network_manager.get_port_vlan(ctx, port_id=id_)
             ) == "No Such Instance currently exists at this OID":
             return 1, 200
         self.switch_network_manager.update_port_vlan(ctx,
                                                      port_id=id_,
                                                      vlan=int(body))
         return int(body), 204
     except Exception as e:
         return handle_error(ctx, e)
Ejemplo n.º 17
0
 def get(self, ctx, id_: int, only: Optional[List[str]]=None):
     try:
         def remove(entity: Any) -> Any:
             if isinstance(entity, dict) and only is not None:
                 entity_cp = entity.copy()
                 for k in entity_cp.keys():
                     if k not in only + ["id"]:
                         del entity[k]
             return entity
         return remove(self.main_manager.get_by_id(ctx, id=id_).to_dict()), 200
     except Exception as e:
         return handle_error(ctx, e)
Ejemplo n.º 18
0
Archivo: member.py Proyecto: minet/adh6
    def password_put(self, ctx, id_, body):
        """ Set the password of a member. """

        try:
            self.member_manager.change_password(ctx, id_, body.get('password'),
                                                body.get("hashedPassword"))
            return NoContent, 204  # 204 No Content
        except Exception as e:
            if isinstance(
                    e, NotFoundError
            ) and Roles.ADMIN_WRITE.value not in ctx.get(CTX_ROLES):
                e = UnauthorizedError("cannot access this resource")
            return handle_error(ctx, e)
Ejemplo n.º 19
0
 def search(self, ctx, limit, offset, login: Union[str, None] = None):
     try:
         result, count = self.api_key_manager.search(ctx=ctx,
                                                     limit=limit,
                                                     offset=offset,
                                                     login=login)
         headers = {
             "X-Total-Count": str(count),
             'access-control-expose-headers': 'X-Total-Count'
         }
         return [r.to_dict() for r in result], 200, headers
     except Exception as e:
         return handle_error(ctx, e)
Ejemplo n.º 20
0
Archivo: device.py Proyecto: minet/adh6
 def delete(self, ctx, id_: int):
     try:
         if ctx.get(CTX_ADMIN) != self.device_manager.get_owner(
                 ctx, id_) and Roles.ADMIN_WRITE.value not in ctx.get(
                     CTX_ROLES, []):
             raise UnauthorizedError("Unauthorize to access this resource")
         self.main_manager.delete(ctx, id=id_)
         return NoContent, 204  # 204 No Content
     except Exception as e:
         if isinstance(
                 e, NotFoundError
         ) and Roles.ADMIN_WRITE.value not in ctx.get(CTX_ROLES):
             e = UnauthorizedError("cannot access this resource")
         return handle_error(ctx, e)
Ejemplo n.º 21
0
Archivo: device.py Proyecto: minet/adh6
 def vendor_search(self, ctx, id_: int):
     """ Return the vendor associated with the given device """
     try:
         device = self.device_manager.get_by_id(ctx=ctx, id=id_)
         if ctx.get(
                 CTX_ADMIN
         ) != device.member and Roles.ADMIN_READ.value not in ctx.get(
                 CTX_ROLES, []):
             raise UnauthorizedError("Unauthorize to access this resource")
         return self.device_manager.get_mac_vendor(ctx, id=id_), 200
     except Exception as e:
         if isinstance(
                 e, NotFoundError
         ) and Roles.ADMIN_READ.value not in ctx.get(CTX_ROLES):
             e = UnauthorizedError("cannot access this resource")
         return handle_error(ctx, e)
Ejemplo n.º 22
0
 def search(self,
            ctx,
            limit=DEFAULT_LIMIT,
            offset=DEFAULT_OFFSET,
            terms=None):
     try:
         result, total_count = self.account_type_manager.search(
             ctx, limit=limit, offset=offset, terms=terms)
         headers = {
             "X-Total-Count": str(total_count),
             'access-control-expose-headers': 'X-Total-Count'
         }
         result = list(map(lambda x: x.to_dict(), result))
         return result, 200, headers
     except Exception as e:
         return handle_error(ctx, e)
Ejemplo n.º 23
0
 def search(self, ctx, limit=DEFAULT_LIMIT, offset=DEFAULT_OFFSET, terms=None, filter_: Optional[Any] = None, only: Optional[List[str]]=None):
     try:
         def remove(entity: Any) -> Any:
             if isinstance(entity, dict) and only is not None:
                 entity_cp = entity.copy()
                 for k in entity_cp.keys():
                     if k not in only + ["id"]:
                         del entity[k]
             return entity
         filter_ = self.abstract_entity_class.from_dict(filter_) if filter_ else None
         result, total_count = self.main_manager.search(ctx, limit=limit, offset=offset, terms=terms, filter_=filter_)
         headers = {
             "X-Total-Count": str(total_count),
             'access-control-expose-headers': 'X-Total-Count'
         }
         return list(map(remove, map(lambda x: x.to_dict(), result))), 200, headers
     except Exception as e:
         return handle_error(ctx, e)
Ejemplo n.º 24
0
Archivo: member.py Proyecto: minet/adh6
    def get(self, ctx, id_: int, only: Optional[List[str]] = None):
        try:

            def remove(entity: Any) -> Any:
                if isinstance(entity, dict) and only is not None:
                    entity_cp = entity.copy()
                    for k in entity_cp.keys():
                        if k not in only + ["id"]:
                            del entity[k]
                return entity

            return remove(self.main_manager.get_by_id(ctx,
                                                      id=id_).to_dict()), 200
        except Exception as e:
            if isinstance(
                    e, NotFoundError
            ) and Roles.ADMIN_READ.value not in ctx.get(CTX_ROLES):
                e = UnauthorizedError("cannot access this resource")
            return handle_error(ctx, e)
Ejemplo n.º 25
0
Archivo: member.py Proyecto: minet/adh6
 def search(self,
            ctx,
            limit: int = DEFAULT_LIMIT,
            offset: int = DEFAULT_OFFSET,
            terms: Union[str, None] = None,
            filter_: Optional[Any] = None):
     try:
         filter_ = MemberFilter.from_dict(filter_) if filter_ else None
         result, total_count = self.main_manager.search(ctx,
                                                        limit=limit,
                                                        offset=offset,
                                                        terms=terms,
                                                        filter_=filter_)
         headers = {
             "X-Total-Count": str(total_count),
             'access-control-expose-headers': 'X-Total-Count'
         }
         return result, 200, headers
     except Exception as e:
         return handle_error(ctx, e)
Ejemplo n.º 26
0
Archivo: device.py Proyecto: minet/adh6
 def search(self,
            ctx,
            limit=DEFAULT_LIMIT,
            offset=DEFAULT_OFFSET,
            filter_: dict = {}):
     try:
         device_filter = DeviceFilter.from_dict(filter_)
         if ctx.get(
                 CTX_ADMIN
         ) != device_filter.member and Roles.ADMIN_READ.value not in ctx.get(
                 CTX_ROLES, []):
             raise UnauthorizedError("Unauthorize to access this resource")
         result, total_count = self.device_manager.search(
             ctx, limit=limit, offset=offset, device_filter=device_filter)
         headers = {
             "X-Total-Count": str(total_count),
             'access-control-expose-headers': 'X-Total-Count'
         }
         return result, 200, headers
     except Exception as e:
         return handle_error(ctx, e)
Ejemplo n.º 27
0
Archivo: device.py Proyecto: minet/adh6
    def get(self, ctx, id_: int, only: t.Optional[t.List[str]] = None):
        try:
            device = self.device_manager.get_by_id(ctx, id=id_)
            if ctx.get(
                    CTX_ADMIN
            ) != device.member and Roles.ADMIN_READ.value not in ctx.get(
                    CTX_ROLES, []):
                raise UnauthorizedError("Unauthorize to access this resource")

            def remove(entity: t.Any) -> t.Any:
                if isinstance(entity, dict) and only is not None:
                    entity_cp = entity.copy()
                    for k in entity_cp.keys():
                        if k not in only + ["id"]:
                            del entity[k]
                return entity

            return remove(device.to_dict()), 200
        except Exception as e:
            if isinstance(
                    e, NotFoundError
            ) and Roles.ADMIN_READ.value not in ctx.get(CTX_ROLES):
                e = UnauthorizedError("cannot access this resource")
            return handle_error(ctx, e)
Ejemplo n.º 28
0
Archivo: device.py Proyecto: minet/adh6
 def member_search(self, ctx, id_: int):
     try:
         return self.device_manager.get_owner(ctx=ctx, device_id=id_), 200
     except Exception as e:
         return handle_error(ctx, e)
Ejemplo n.º 29
0
Archivo: device.py Proyecto: minet/adh6
 def mab_post(self, ctx, id_: int):
     """ Return the vendor associated with the given device """
     try:
         return self.device_manager.put_mab(ctx, id=id_), 200
     except Exception as e:
         return handle_error(ctx, e)
Ejemplo n.º 30
0
 def get(self, ctx, id_: int):
     try:
         return self.account_type_manager.get_by_id(ctx,
                                                    id=id_).to_dict(), 200
     except Exception as e:
         return handle_error(ctx, e)