Beispiel #1
0
def get_version(utm_client: DSSTestSession,
                uss_base_url: str) -> Tuple[StatusResponse, fetch.Query]:
    url = '{}/v1/status'.format(uss_base_url)
    print("[SCD] GET {}".format(url))

    initiated_at = datetime.utcnow()
    resp = utm_client.get(url, scope=SCOPE_SCD_QUALIFIER_INJECT)
    if resp.status_code != 200:
        raise QueryError(
            'Unexpected response code for get_version {}. Response: {}'.format(
                resp.status_code, resp.content.decode('utf-8')),
            fetch.describe_query(resp, initiated_at))

    return ImplicitDict.parse(resp.json(),
                              StatusResponse), fetch.describe_query(
                                  resp, initiated_at)
Beispiel #2
0
def delete_flight(utm_client: DSSTestSession, uss_base_url: str,
                  flight_id: str) -> Tuple[DeleteFlightResponse, fetch.Query]:
    url = '{}/v1/flights/{}'.format(uss_base_url, flight_id)
    print("[SCD] DELETE {}".format(url))

    initiated_at = datetime.utcnow()
    resp = utm_client.delete(url, scope=SCOPE_SCD_QUALIFIER_INJECT)
    if resp.status_code != 200:
        raise QueryError(
            'Unexpected response code for deleteFlight {}. Response: {}'.
            format(resp.status_code, resp.content.decode('utf-8')),
            fetch.describe_query(resp, initiated_at))

    return ImplicitDict.parse(resp.json(),
                              DeleteFlightResponse), fetch.describe_query(
                                  resp, initiated_at)
Beispiel #3
0
def create_flight(
    utm_client: DSSTestSession, uss_base_url: str,
    flight_request: InjectFlightRequest
) -> Tuple[str, InjectFlightResponse, fetch.Query]:
    flight_id = str(uuid.uuid4())
    url = '{}/v1/flights/{}'.format(uss_base_url, flight_id)
    print("[SCD] PUT {}".format(url))

    initiated_at = datetime.utcnow()
    resp = utm_client.put(url,
                          json=flight_request,
                          scope=SCOPE_SCD_QUALIFIER_INJECT)
    if resp.status_code != 200:
        raise QueryError(
            'Unexpected response code for createFlight {}. Response: {}'.
            format(resp.status_code, resp.content.decode('utf-8')),
            fetch.describe_query(resp, initiated_at))
    return flight_id, ImplicitDict.parse(
        resp.json(),
        InjectFlightResponse), fetch.describe_query(resp, initiated_at)
Beispiel #4
0
 def observe_flight_details(
     self, flight_id: str
 ) -> Tuple[Optional[observation_api.GetDetailsResponse], fetch.Query]:
     initiated_at = datetime.datetime.utcnow()
     resp = self.session.get('/display_data/{}'.format(flight_id))
     try:
         result = ImplicitDict.parse(resp.json(),
                                     observation_api.GetDetailsResponse
                                     ) if resp.status_code == 200 else None
     except ValueError:
         result = None
     return (result, fetch.describe_query(resp, initiated_at))
Beispiel #5
0
    def submit_test(self, payload: CreateTestParameters, test_id: str, setup: reports.Setup) -> None:
        injection_path = '/tests/{}'.format(test_id)

        initiated_at = datetime.datetime.utcnow()
        response = self.uss_session.put(url=injection_path, json=payload, scope=SCOPE_RID_QUALIFIER_INJECT)
        #TODO: Use response to specify flights as actually-injected rather than assuming no modifications
        setup.injections.append(fetch.describe_query(response, initiated_at))

        if response.status_code == 200:
            print("New test with ID %s created" % test_id)
        else:
            raise RuntimeError('Error {} submitting test ID {} to {}: {}'.format(
                response.status_code, test_id, self._base_url, response.content.decode('utf-8')))
 def observe_system(
     self, rect: s2sphere.LatLngRect
 ) -> Tuple[Optional[observation_api.GetDisplayDataResponse], fetch.Query]:
     initiated_at = datetime.datetime.utcnow()
     resp = self.session.get('/display_data?view={},{},{},{}'.format(
         rect.lo().lat().degrees,
         rect.lo().lng().degrees,
         rect.hi().lat().degrees,
         rect.hi().lng().degrees),
                             scope=rid.SCOPE_READ)
     try:
         result = (ImplicitDict.parse(
             resp.json(), observation_api.GetDisplayDataResponse)
                   if resp.status_code == 200 else None)
     except ValueError as e:
         result = None
     return (result, fetch.describe_query(resp, initiated_at))
    def submit_test(self, payload: CreateTestParameters, test_id: str,
                    setup: reports.Setup) -> None:
        injection_path = '/tests/{}'.format(test_id)

        initiated_at = datetime.datetime.utcnow()
        response = self.uss_session.put(
            url=injection_path,
            json=payload,
            scope=injection_api.SCOPE_RID_QUALIFIER_INJECT)
        #TODO: Use response to specify flights as actually-injected rather than assuming no modifications
        setup.injections.append(fetch.describe_query(response, initiated_at))

        if response.status_code == 200:
            print("New test with ID %s created" % test_id)

        elif response.status_code == 409:
            raise RuntimeError("Test with ID %s already exists" % test_id)

        elif response.status_code == 404:
            raise RuntimeError(
                "Test with ID %s not submitted, the requested endpoint was not found on the server"
                % test_id)

        elif response.status_code == 401:
            raise RuntimeError(
                "Test with ID %s not submitted, the access token was not provided in the Authorization header, or the token could not be decoded, or token was invalid"
                % test_id)

        elif response.status_code == 403:
            raise RuntimeError(
                "Test with ID %s not submitted, the access token was decoded successfully but did not include the appropriate scope"
                % test_id)

        elif response.status_code == 413:
            raise RuntimeError(
                "Test with ID %s not submitted, the injection payload was too large"
                % test_id)

        else:
            raise RuntimeError(
                "Test with ID %(test_id)s not submitted, the server returned the following HTTP error code: %(status_code)d"
                % {
                    'test_id': test_id,
                    'status_code': response.status_code
                })