Пример #1
0
def create_test(test_id: str) -> Tuple[str, int]:
  """Implements test creation in RID automated testing injection API."""

  try:
    json = flask.request.json
    if json is None:
      raise ValueError('Request did not contain a JSON payload')
    req_body: injection_api.CreateTestParameters = ImplicitDict.parse(json, injection_api.CreateTestParameters)
    record = database.TestRecord(version=str(uuid.uuid4()), flights=req_body.requested_flights)
  except ValueError as e:
    msg = 'Create test {} unable to parse JSON: {}'.format(test_id, e)
    return msg, 400

  # Create ISA in DSS
  (t0, t1) = req_body.get_span()
  t1 += RECENT_POSITIONS_BUFFER
  rect = req_body.get_rect()
  flights_url = '{}/v1/uss/flights'.format(webapp.config.get(config.KEY_BASE_URL))
  mutated_isa = mutate.put_isa(resources.dss_client, rect, t0, t1, flights_url, record.version)
  if not mutated_isa.dss_response.success:
    response = rid.ErrorResponse(message='Unable to create ISA in DSS')
    response['errors'] = mutated_isa.dss_response.errors
    return flask.jsonify(response), 412
  record.isa_version = mutated_isa.dss_response.isa.version
  for (url, notification) in mutated_isa.notifications.items():
    code = notification.response.status_code
    if code != 204 and code != 200:
      pass #TODO: Log notification failures (maybe also log incorrect 200s)

  db.tests[test_id] = record
  return flask.jsonify(injection_api.ChangeTestResponse(version=record.version, injected_flights=record.flights))
Пример #2
0
def delete_test(test_id: str) -> Tuple[str, int]:
    """Implements test deletion in RID automated testing injection API."""

    record = db.value.tests.get(test_id, None)

    if record is None:
        return 'Test "{}" not found'.format(test_id), 404

    # Delete ISA from DSS
    deleted_isa = mutate.delete_isa(resources.utm_client, record.version,
                                    record.isa_version)
    if not deleted_isa.dss_response.success:
        response = rid.ErrorResponse(message='Unable to delete ISA from DSS')
        response['errors'] = deleted_isa.dss_response.errors
        return flask.jsonify(response), 412
    for (url, notification) in deleted_isa.notifications.items():
        code = notification.response.status_code
        if code != 204 and code != 200:
            pass  #TODO: Log notification failures (maybe also log incorrect 200s)

    with db as tx:
        del tx.tests[test_id]
    return flask.jsonify(
        injection_api.ChangeTestResponse(version=record.version,
                                         injected_flights=record.flights))
Пример #3
0
def delete_test(sp_id: str, test_id: str) -> Tuple[str, int]:
  """Implements test deletion in RID automated testing injection API."""

  # TODO: Validate token signature & scope

  if sp_id not in db.sps:
    return 'RID Service Provider "{}" not found'.format(sp_id), 404
  if test_id not in db.sps[sp_id].tests:
    return 'Test "{}" not found for RID Service Provider "{}"'.format(test_id, sp_id), 404

  record = db.sps[sp_id].tests[test_id]
  del db.sps[sp_id].tests[test_id]
  return flask.jsonify(injection_api.ChangeTestResponse(version=record.version, injected_flights=record.flights))
Пример #4
0
def create_test(sp_id: str, test_id: str) -> Tuple[str, int]:
  """Implements test creation in RID automated testing injection API."""

  # TODO: Validate token signature & scope

  try:
    json = flask.request.json
    if json is None:
      raise ValueError('Request did not contain a JSON payload')
    req_body: injection_api.CreateTestParameters = ImplicitDict.parse(json, injection_api.CreateTestParameters)
    record = database.TestRecord(version=str(uuid.uuid4()), flights=req_body.requested_flights)
    if sp_id not in db.sps:
      db.sps[sp_id] = database.RIDSP()
    db.sps[sp_id].tests[test_id] = record

    return flask.jsonify(injection_api.ChangeTestResponse(version=record.version, injected_flights=record.flights))
  except ValueError as e:
    msg = 'Create test {} for Service Provider {} unable to parse JSON: {}'.format(test_id, sp_id, e)
    return msg, 400