Пример #1
0
def test_equality():
    expected = uuid4()
    actual = UUID(str(expected))
    other = uuid4()

    assert expected == actual
    assert expected != other
Пример #2
0
class UserFeed(OrjsonModel):
    """UserFeed Input model"""

    behaviour: Behaviour = Field(..., description="Behaviour of the user")
    company_code: str = Field(
        ...,
        title="Company Code",
        description="ID of the Company",
        example="GP0000000004",
    )
    company_trip_type: TypeOfTrack = Field(
        ..., title="Type of track", example="private"
    )
    distance: int = Field(..., description="Overall distance covered", example=1939)
    elapsedTime: str = Field(
        ...,
        title="Elapsed Time",
        description="Overall amount of time elapsed",
        example="0:16:15",
    )
    endDate: int = Field(
        ...,
        title="Ending Date",
        description="UTC timestamp expressed in ms",
        example=1611820537461,
    )
    id: str = Field(
        ...,
        title="Device ID",
        description="Anonymous UUID_V4 assigned to the device",
        example=str(uuid4()),
    )

    mainTypeSpace: str = Field(
        ...,
        title="Main Type Space",
        description="Main type of mobility with respect to the space covered",
        example="bicycle",
    )
    mainTypeTime: str = Field(
        ...,
        title="Main Type Time",
        description="Main type of mobility with respect to time elapsed",
        example="bicycle",
    )
    startDate: int = Field(
        ...,
        title="Starting Date",
        description="UTC timestamp expressed in ms",
        example=1611820537452,
    )
    sensors_information: List[SensorInformation] = Field(
        ..., description="List of sensors information"
    )
    trace_information: List[PositionObject] = Field(
        ...,
        title="Trace Information",
        description="list of position objects, collected through the Galileo navigation system",
    )
Пример #3
0
async def authenticate(
    back_ground_tasks: BackgroundTasks,
    request: Request,
    requester: Requester = Depends(user_feed_auth),
    user_feed: UserFeedInput = Body(...),
):
    """
    This endpoint provides a unique point of access to let external users and applications to send standardized data
    through a JSON payload via https POST requests.
    It enables the authentication of positions collected by third-party applications.\n
    After the security framework approval, it responds by embedding a unique, random, and anonymous id,
    generated on the cloud, for the specific track provided. Finally, the content of the message received
    is parsed and sanitized.\n
    The logic developed enables the reception of a set of locations embedding Galileo raw data.
    It requires the presence of the entire Galileo navigation messages received while the external
    devices were computing their positions.\n
    The latitude and longitude of the list of positions received are extracted at run-time
    by the Reference System Manager library and exploited for the proper selection of the
    U-Blox Reference System instance.\n
    ![image](https:/serengeti/static/user_feed_authenticate.png)
    """
    # Analyze requester
    if requester.client == "get_token_client" and requester.user == "goeasy_bq_library":
        source_app = "ApesMobility"
    else:
        source_app = requester.client

    # Generate an unique id for the journey
    journey_id = str(uuid4())

    # Wait some time before adding the background task
    await frequency_limiter(store_semaphore())

    # Store the data in the anonengine in the background
    back_ground_tasks.add_task(
        store_android_data,
        user_feed,
        time.time(),
        request.client.host,
        journey_id,
        source_app,
        requester.client,
        requester.user,
        store_semaphore(),
    )

    # Return the id of the resource
    return Resource(journey_id=journey_id)
Пример #4
0
async def iot_authentication(
        back_ground_tasks: BackgroundTasks,
        request: Request,
        requester: Requester = Depends(iot_auth),
        iot_input: IotInput = Body(...),
):
    """
    This endpoint provides a unique point of access to let IoT devices and LBS applications to send standardized
    data through a JSON payload via https POST requests.\n
    It enables the authentication of positions collected by third-party applications.\n
    After the security framework approval, it responds by embedding a unique, random, and anonymous id,
    generated on the cloud, for the specific track provided.\n
    Finally, the content of the message received is parsed and sanitized.\n
    The logic developed enables the reception of a set of locations embedding Galileo raw data.\n
    It requires the presence of the entire Galileo navigation messages received while the
    external devices were computing their positions.\n
    The latitude and longitude of the list of positions received are
    extracted at run-time by the Reference System Manager library
    and exploited for the proper selection of the U-Blox Reference System instance.
    """

    # Analyze requester
    if requester.client == "get_token_client" and requester.user == "goeasy_bq_library":
        source_app = "ApesMobility"
    else:
        source_app = requester.client

    # Generate GEPid
    obesrvation_gepid = str(uuid4())

    # Wait some time before adding the background task
    await frequency_limiter(store_semaphore())

    back_ground_tasks.add_task(
        store_iot_data,
        iot_input,
        time.time(),
        request.client.host,
        obesrvation_gepid,
        source_app,
        requester.client,
        requester.user,
        store_semaphore(),
    )
    return Resource(observationGEPid=obesrvation_gepid)
Пример #5
0
def test_uuid5():
    expected = uuid5(uuid4(), b"foo")
    assert expected.version == 5
    assert expected.variant == "specified in RFC 4122"
    assert UUID_REGEX.match(str(expected))
    assert str(expected) == str(uuid.UUID(str(expected)))
Пример #6
0
 def setup() -> str:
     clear_test()
     return str(uuid4())
Пример #7
0
class UserFeedOutput(OrjsonModel):
    """UserFeed Output Model"""

    app_defined_behaviour: Any = Field(
        ...,
        title="Application Defined Behaviour",
        description="Mobile application standalone detection of mobility types and the segments within the journey",
        example=[],
    )
    tpv_defined_behaviour: Any = Field(
        ...,
        title="Third Party Defined Behaviour",
        description="Autonomous detection of mobility types and the segments within the journey",
        example=[],
    )
    user_defined_behaviour: List[TrackSegmentsOutput] = Field(
        ...,
        title="User Defined Behaviour",
        description="""The users specify through the mobile app the type of mobility
                        (necessary to produce legitimate data to be used for the learning process of the third-party system)
                        """,
    )

    company_code: str = Field(
        ...,
        title="Company Code",
        description="ID of the Company",
        example="GP0000000004",
    )
    company_trip_type: TypeOfTrack = Field(
        ..., title="Type of track", example="private"
    )
    distance: int = Field(..., description="Overall distance covered", example=1939)
    elapsedTime: str = Field(
        ...,
        title="Elapsed Time",
        description="Overall amount of time elapsed",
        example="0:16:15",
    )
    endDate: int = Field(
        ...,
        title="Ending Date",
        description="UTC timestamp expressed in ms",
        example=1611820537461,
    )
    deviceId: str = Field(
        ...,
        title="Device ID",
        description="Anonymous UUID_V4 assigned to the device",
        example=str(uuid4()),
    )
    journeyId: str = Field(
        ...,
        title="Journey ID",
        description="Anonymous UUID_V4 assigned to the track",
        example=str(uuid4()),
    )
    mainTypeSpace: str = Field(
        ...,
        title="Main Type Space",
        description="Main type of mobility with respect to the space covered",
        example="bicycle",
    )
    mainTypeTime: str = Field(
        ...,
        title="Main Type Time",
        description="Main type of mobility with respect to time elapsed",
        example="bicycle",
    )
    startDate: int = Field(
        ...,
        title="Starting Date",
        description="UTC timestamp expressed in ms",
        example=1611820537452,
    )
    sensors: List[SensorInformation] = Field(
        ..., description="List of sensors information"
    )
    positions: List[PositionObject] = Field(
        ...,
        title="Trace Information",
        description="list of position objects, collected through the Galileo navigation system",
    )
    sourceApp: str = Field(default="ApesMobility")