Esempio n. 1
0
    def view_all(self):  # -> Collection[PlacementDto]:
        """
        Fetch a full list of DTOs of all stored objects

        :return: a collection of DTOs
        """
        return [build_dto(i) for i in self._placements.load_all()]
Esempio n. 2
0
    def view_all(self):  # -> Collection[UserDto]:
        """
        Fetch a full list of DTOs of all stored objects

        :return: a collection of DTOs
        """
        return [
            build_dto(user)
            for user in self._user_repo.load_all()
        ]
Esempio n. 3
0
    def view(self, domain_id: TDomainId) -> SessionDto:
        """
        Fetch a DTO of stored object by the ID specified

        :param domain_id: id of object to be fetched
        :return: a DTO of stored object
        :raises ServiceResolutionError: if the entity with
                the specified ID can't be found
        """
        return build_dto(self._sessions.load(domain_id))
Esempio n. 4
0
    def view(self, domain_id: TDomainId) -> UserDto:
        """
        Fetch a DTO of stored object by the ID specified

        :param domain_id: id of object to be fetched
        :return: a DTO of stored object
        :raises ServiceResolutionError: if the entity with
                the specified ID can't be found
        """
        resolved = self._resolve_entity(self._user_repo, domain_id)
        return build_dto(resolved)
Esempio n. 5
0
    def view_by_user(self, user_id: TDomainId):  # -> Collection[SessionDto]
        """
        Returns a collection of Sessions (Session DTOs to
        be exact) that are associated with the specified
        User

        :param user_id: an identifier of the User in question
        :return: a collection of SessionDto objects
        """
        resolved = self._sessions.select_by_user(user_id)

        return [build_dto(i) for i in resolved]
Esempio n. 6
0
    def view_by_username(self, username: str) -> UserDto:
        """
        Allows to fetch a User (UserDto, to be exact) by
        User's username

        :param username: username of the User to be fetched
        :return: an instance of User DTO
        :raises ServiceEntityResolutionError: if the User
                with the specified username was not found
        """
        resolved = self._user_repo.find_by_username(username)
        self._check_resolved(resolved)

        return build_dto(resolved)
Esempio n. 7
0
    def view_older_than(self, timestamp: float):  # -> Collection[SessionDto]
        """
        Allows to fetch all Sessions that was created before
        the specified point in time (UNIX time)

        :param timestamp: UNIX time, maximum value of the
               time_created field
        :return: a collection of Sessions (their DTOs, to be
                 exact) that was created before the specified
                 point in time
        """
        resolved = self._sessions.select_older_than(timestamp)

        return [build_dto(i) for i in resolved]
Esempio n. 8
0
    def view(self, domain_id: TDomainId) -> ThingDto:
        """
        Fetch a DTO of stored object by the ID specified

        :param domain_id: id of object to be fetched
        :return: a DTO of stored object
        :raises ServiceResolutionError: if the entity with
                the specified ID can't be found
        """
        thing = self._things.load(domain_id)

        if thing is None:
            raise ServiceEntityResolutionError()

        return build_dto(thing)
Esempio n. 9
0
    def select_by_placement(
            self, placement_id: Optional[TDomainId]
    ):  # -> Collection[ThingDto]:
        """
        Selects all Things that are physically present in the
        specified Placement

        :param placement_id: an identifier of the Placement
               of interest; or None (null) to fetch all Things
               that are not assigned to any Placement yet
        :return: a collection of Things that are placed in the
                 specified Placement
        """
        return [
            build_dto(i) for i in self._things.select_by_placement(placement_id)
        ]
Esempio n. 10
0
    def view(self, domain_id: TDomainId) -> PlacementDto:
        """
        Fetch a DTO of stored object by the ID specified

        :param domain_id: id of object to be fetched
        :return: a DTO of stored object
        :raises ServiceResolutionError: if the entity with
                the specified ID can't be found
        """
        placement = self._placements.load(domain_id)

        if placement is None:
            raise ServiceEntityResolutionError(
                "A Placement with the specified ID can't "
                "be found: %s" % domain_id)

        return build_dto(placement)
Esempio n. 11
0
    def view_by_access_token(self, access_token: str) -> SessionDto:
        """
        Allows to determine and fetch a Session which contains
        the specified access token

        :param access_token: an access token associated with Session
        :return: Session DTO
        :raises ServiceEntityResolutionError: if there is no
                session with the specified access token existing
                (access token was revoked or not existing at all)
        """
        resolved = self._sessions.find_by_access_token(access_token)

        if resolved is None:
            raise ServiceEntityResolutionError()

        return build_dto(resolved)
Esempio n. 12
0
    def authenticate(self, username: str, password: str) -> UserDto:
        """
        Authenticate the User by the specified username-password
        combination.

        :param username: username of the User to be authenticated
        :param password: password of the User to be authenticated
        :return: an instance of User (User DTO, to be exact)
                 which has the specified username-password combination
        :raises AuthInvalidUserPasswordCombinationError:
                if the specified username-password combination is invalid
        """
        resolved = self._user_repo.find_by_username(username)

        if resolved is None:
            raise AuthInvalidUserPasswordCombinationError()

        password_ok = resolved.verify_password(password)

        if not password_ok:
            raise AuthInvalidUserPasswordCombinationError()

        return build_dto(resolved)