Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 6 additions & 44 deletions src/openutm_verification/auth/dev_auth.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import datetime
import urllib.parse
import uuid
from typing import Dict, List, Optional
from abc import ABC, abstractmethod
from typing import List

import jwcrypto.common
import jwcrypto.jwk
import jwcrypto.jws
import jwcrypto.jwt
import jwt
import requests

ALL_SCOPES = [
"dss.write.identification_service_areas",
Expand All @@ -23,47 +19,13 @@
CLIENT_TIMEOUT = 60 # seconds


class AuthAdapter(object):
"""Base class for an adapter that add JWTs to requests."""

def __init__(self):
self._tokens = {}
class AuthAdapter(ABC):
"""Abstract base class for an adapter that adds JWTs to requests."""

@abstractmethod
def issue_token(self, intended_audience: str, scopes: List[str]) -> str:
"""Subclasses must return a bearer token for the given audience."""

raise NotImplementedError()

def get_headers(self, url: str, scopes: List[str] = None) -> Dict[str, str]:
if scopes is None:
scopes = ALL_SCOPES
intended_audience = urllib.parse.urlparse(url).hostname
scope_string = " ".join(scopes)
if intended_audience not in self._tokens:
self._tokens[intended_audience] = {}
if scope_string not in self._tokens[intended_audience]:
token = self.issue_token(intended_audience, scopes)
else:
token = self._tokens[intended_audience][scope_string]
payload = jwt.decode(token, options={"verify_signature": False})
expires = EPOCH + datetime.timedelta(seconds=payload["exp"])
if datetime.datetime.utcnow() > expires - TOKEN_REFRESH_MARGIN:
token = self.issue_token(intended_audience, scopes)
self._tokens[intended_audience][scope_string] = token
return {"Authorization": "Bearer " + token}

def add_headers(self, request: requests.PreparedRequest, scopes: List[str]):
for k, v in self.get_headers(request.url, scopes).items():
request.headers[k] = v

def get_sub(self) -> Optional[str]:
"""Retrieve `sub` claim from one of the existing tokens"""
for _, tokens_by_scope in self._tokens.items():
for token in tokens_by_scope.values():
payload = jwt.decode(token, options={"verify_signature": False})
if "sub" in payload:
return payload["sub"]
return None
pass


class NoAuth(AuthAdapter):
Expand Down
3 changes: 0 additions & 3 deletions src/openutm_verification/auth/noauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
class NoAuthCredentialsGetter:
"""Credentials getter that uses dummy authentication for development."""

def __init__(self):
pass

def get_cached_credentials(self, audience: str, scopes: List[str]):
"""Get cached credentials using dummy authentication."""
if not audience:
Expand Down
159 changes: 0 additions & 159 deletions src/openutm_verification/auth/passport_client.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hrishiballal to confirm if this file should be deleted

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RomanPszonka All the code was duplication. It's available in the other auth files.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import uuid
from typing import Any, Dict, List, Optional
from typing import Optional
from uuid import UUID

from loguru import logger
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
from typing import Optional, Tuple

import httpx
from loguru import logger
from pydantic_settings import BaseSettings

from openutm_verification.auth.oauth2 import OAuth2Client
from openutm_verification.core.execution.config_models import get_settings

config = get_settings()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
from typing import Optional

import pandas as pd
Expand All @@ -9,11 +8,7 @@
OpenSkySettings,
)
from openutm_verification.core.execution.scenario_runner import scenario_step
from openutm_verification.simulator.geo_json_telemetry import (
GeoJSONAirtrafficSimulator,
)
from openutm_verification.simulator.models.flight_data_types import (
AirTrafficGeneratorConfiguration,
FlightObservationSchema,
)

Expand Down
4 changes: 2 additions & 2 deletions src/openutm_verification/core/reporting/reporting_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"""

from enum import StrEnum
from typing import Any, Dict, List, Literal, Optional
from typing import Any, Dict, List, Optional

from pydantic import BaseModel, Field
from pydantic import BaseModel

from openutm_verification.core.execution.config_models import DeploymentDetails

Expand Down
3 changes: 0 additions & 3 deletions src/openutm_verification/drip/auth_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@

For more information about the DRIP protocol and the Authentication message format, refer to the ASTM F3411 specification.
"""

import ctypes
import struct
from ctypes import POINTER, Structure, c_char, c_double, c_float, c_uint8, c_uint16, c_uint32, c_void_p, sizeof

import openutm_verification.drip.drip_messages as common

Expand Down
3 changes: 1 addition & 2 deletions src/openutm_verification/drip/drip_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
"""

import ctypes
import struct
from ctypes import POINTER, Structure, c_char, c_double, c_float, c_uint8, c_uint16, c_uint32, c_void_p, sizeof
from ctypes import Structure, c_char, c_double, c_float, c_uint8, c_uint16, c_uint32, c_void_p

# Size constants for DRIP messages
DRIP_ID_SIZE = 20
Expand Down
4 changes: 1 addition & 3 deletions src/openutm_verification/drip/import_drip_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import argparse
import ctypes
import os
import struct

import openutm_verification.drip.drip_messages as common
from openutm_verification.drip.auth_decoder import AuthDecoder
Expand All @@ -48,7 +47,6 @@ def decode_drone_id(uas_data, raw_data):

if common.DRIP_MESSAGE_SIZE <= message_size:
msg_type = raw_data[0] >> 4
message_type_bytes = struct.pack("B", raw_data[0])

if msg_type == common.DRIP_MESSAGE_BASIC_ID:
print("DRIP_MESSAGE_BASIC_ID")
Expand Down Expand Up @@ -112,7 +110,7 @@ def decodeMessagePack(data):
uasData = common.DRIP_UAS_Data()
pack = common.DRIP_MessagePack_encoded()
ctypes.memmove(ctypes.addressof(pack), data, ctypes.sizeof(pack))
ret = decode_message_pack(uasData, pack, data)
decode_message_pack(uasData, pack, data)

return uasData

Expand Down
1 change: 0 additions & 1 deletion src/openutm_verification/drip/location_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
For more information about the DRIP protocol and the Location message format, refer to the ASTM F3411 specification.
"""

import ctypes
import struct

import openutm_verification.drip.drip_messages as common
Expand Down
2 changes: 0 additions & 2 deletions src/openutm_verification/drip/operator_id_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
For more information about the DRIP protocol and the Operator ID message format, refer to the ASTM F3411 specification.
"""

import ctypes

from openutm_verification.drip import drip_messages as common


Expand Down
2 changes: 0 additions & 2 deletions src/openutm_verification/drip/self_id_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
For more information about the DRIP protocol and the Self ID message format, refer to the ASTM F3411 specification.
"""

import ctypes

from openutm_verification.drip import drip_messages as common


Expand Down
2 changes: 0 additions & 2 deletions src/openutm_verification/drip/system_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
For more information about the DRIP protocol and the System message format, refer to the ASTM F3411 specification.
"""

import ctypes

from openutm_verification.drip import drip_messages as common


Expand Down
3 changes: 1 addition & 2 deletions src/openutm_verification/importers/amqp_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import pika
from dotenv import find_dotenv, load_dotenv

load_dotenv(find_dotenv())


def parse_args(argv: List[str]):
parser = argparse.ArgumentParser(description="Retrieve an access token")
Expand All @@ -24,6 +22,7 @@ def parse_args(argv: List[str]):


def main(queue_id):
load_dotenv(find_dotenv())
amqp_connection_url = env.get("AMQP_URL", "localhost")
params = pika.URLParameters(amqp_connection_url)
connection = pika.BlockingConnection(params)
Expand Down
Loading