Skip to content

Commit

Permalink
Merge remote-tracking branch 'interuss/main' into make-image
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminPelletier committed Oct 20, 2023
2 parents ee32c96 + 3e73874 commit 970de6c
Show file tree
Hide file tree
Showing 72 changed files with 2,263 additions and 2,932 deletions.
11 changes: 1 addition & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ jobs:
- name: Shell lint
run: make shell-lint

monitorlib-test:
name: monitorlib tests
uses: ./.github/workflows/monitoring-test.yml
with:
name: monitorlib
script: |
cd monitoring/monitorlib
make test
mock_uss-test:
name: mock_uss tests
uses: ./.github/workflows/monitoring-test.yml
Expand Down Expand Up @@ -71,7 +62,7 @@ jobs:
publish-gh-pages:
name: Publish GitHub Pages
needs: [hygiene-tests, monitorlib-test, mock_uss-test, uss_qualifier-test, prober-test]
needs: [hygiene-tests, mock_uss-test, uss_qualifier-test, prober-test]
if: ${{ always() && contains(join(needs.*.result, ','), 'success') }}
runs-on: ubuntu-latest
permissions:
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ endif

.PHONY: format
format: json-schema
docker run --rm -v "$(CURDIR):/code" -w /code pyfound/black:22.10.0 black --exclude /interfaces .
cd monitoring && make format

.PHONY: lint
lint: shell-lint
lint: shell-lint python-lint
cd monitoring && make lint
cd schemas && make lint

Expand All @@ -23,7 +24,7 @@ check-hygiene: python-lint hygiene validate-uss-qualifier-docs shell-lint

.PHONY: python-lint
python-lint:
cd monitoring && make python-lint
docker run --rm -v "$(CURDIR):/code" -w /code pyfound/black:22.10.0 black --check --exclude /interfaces . || (echo "Linter didn't succeed. You can use the following command to fix python linter issues: make format" && exit 1)

.PHONY: hygiene
hygiene:
Expand Down
14 changes: 0 additions & 14 deletions monitoring/Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
.PHONY: lint
lint:
cd uss_qualifier && make lint
cd mock_uss && make lint
cd monitorlib && make lint
cd prober && make lint

.PHONY: python-lint
python-lint:
cd uss_qualifier && make python-lint
cd mock_uss && make python-lint
cd monitorlib && make python-lint
cd prober && make python-lint

.PHONY: format
format:
cd uss_qualifier && make format
cd mock_uss && make format
cd monitorlib && make format
cd prober && make format

image: ../requirements.txt $(shell find . -type f ! -path "*/output/*" ! -name image) $(shell find ../interfaces -type f)
# Building image due to changes in the following files: $?
./build.sh

.PHONY: test
test:
cd monitorlib && make test
cd mock_uss && make test
cd uss_qualifier && make test
cd prober && make test
14 changes: 1 addition & 13 deletions monitoring/mock_uss/Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
.PHONY: lint
lint: python-lint
echo "mock_uss lint complete"

.PHONY: python-lint
python-lint:
docker run --rm -v "$(CURDIR):/code" -w /code pyfound/black:22.10.0 black --check . || (echo "Linter didn't succeed. You can use the following command to fix python linter issues: make format" && exit 1)

.PHONY: format
format:
docker run --rm -v "$(CURDIR):/code" -w /code pyfound/black:22.10.0 black .

.PHONY: test
test: lint
test:
./run_locally_test_geoawareness.sh
13 changes: 0 additions & 13 deletions monitoring/monitorlib/Makefile

This file was deleted.

26 changes: 15 additions & 11 deletions monitoring/monitorlib/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,29 @@ class NoAuth(AuthAdapter):

EXPIRATION = 3600 # seconds

def __init__(self, sub: str = "uss_noauth"):
def __init__(self, sub: str = "uss_noauth", aud_override: Optional[str] = None):
super().__init__()
self.sub = sub
self._aud_override = aud_override

# Overrides method in AuthAdapter
def issue_token(self, intended_audience: str, scopes: List[str]) -> str:
timestamp = int((datetime.datetime.utcnow() - _UNIX_EPOCH).total_seconds())
claims = {
"sub": self.sub,
"client_id": self.sub,
"scope": " ".join(scopes),
"aud": intended_audience,
"nbf": timestamp - 1,
"exp": timestamp + NoAuth.EXPIRATION,
"iss": "NoAuth",
"jti": str(uuid.uuid4()),
}
if self._aud_override is not None:
claims["aud"] = self._aud_override
jwt = jwcrypto.jwt.JWT(
header={"typ": "JWT", "alg": "RS256"},
claims={
"sub": self.sub,
"client_id": self.sub,
"scope": " ".join(scopes),
"aud": intended_audience,
"nbf": timestamp - 1,
"exp": timestamp + NoAuth.EXPIRATION,
"iss": "NoAuth",
"jti": str(uuid.uuid4()),
},
claims=claims,
algs=["RS256"],
)
jwt.make_signed_token(NoAuth.dummy_private_key)
Expand Down
6 changes: 3 additions & 3 deletions monitoring/monitorlib/clients/versioning/client_interuss.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class InterUSSVersioningClient(VersioningClient):
def __init__(self, session: UTMClientSession, participant_id: ParticipantID):
super(InterUSSVersioningClient, self).__init__(participant_id)
self._session = session
self._server_id = participant_id
self._participant_id = participant_id

def get_version(self, version_type: Optional[str]) -> GetVersionResponse:
op = api.OPERATIONS[api.OperationID.GetVersion]
Expand All @@ -29,8 +29,8 @@ def get_version(self, version_type: Optional[str]) -> GetVersionResponse:
"query_type": QueryType.InterUSSVersioningGetVersion,
"scope": Scope.ReadSystemVersions,
}
if self._server_id:
kwargs["server_id"] = self._server_id
if self._participant_id:
kwargs["participant_id"] = self._participant_id
query = query_and_describe(**kwargs)
if query.status_code != 200:
raise VersionQueryError(
Expand Down
16 changes: 8 additions & 8 deletions monitoring/monitorlib/fetch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class Query(ImplicitDict):
request: RequestDescription
response: ResponseDescription

server_id: Optional[str]
participant_id: Optional[str]
"""If specified, identifier of the USS/participant hosting the server involved in this query."""

query_type: Optional[QueryType]
Expand Down Expand Up @@ -283,16 +283,16 @@ def describe_query(
resp: requests.Response,
initiated_at: datetime.datetime,
query_type: Optional[QueryType] = None,
server_id: Optional[str] = None,
participant_id: Optional[str] = None,
) -> Query:
query = Query(
request=describe_request(resp.request, initiated_at),
response=describe_response(resp),
)
if query_type is not None:
query.query_type = query_type
if server_id is not None:
query.server_id = server_id
if participant_id is not None:
query.participant_id = participant_id
return query


Expand All @@ -301,7 +301,7 @@ def query_and_describe(
verb: str,
url: str,
query_type: Optional[QueryType] = None,
server_id: Optional[str] = None,
participant_id: Optional[str] = None,
**kwargs,
) -> Query:
"""Attempt to perform a query, and then describe the results of that attempt.
Expand All @@ -314,7 +314,7 @@ def query_and_describe(
verb: HTTP verb to perform at the specified URL.
url: URL to query.
query_type: If specified, the known type of query that this is.
server_id: If specified, the participant identifier of the server being queried.
participant_id: If specified, the participant identifier of the server being queried.
**kwargs: Any keyword arguments that should be applied to the <session>.request method when invoking it.
Returns:
Expand Down Expand Up @@ -350,7 +350,7 @@ def query_and_describe(
client.request(verb, url, **req_kwargs),
t0,
query_type=query_type,
server_id=server_id,
participant_id=participant_id,
)
except (requests.Timeout, urllib3.exceptions.ReadTimeoutError) as e:
failure_message = f"query_and_describe attempt {attempt + 1} from PID {os.getpid()} to {verb} {url} failed with timeout {type(e).__name__}: {str(e)}"
Expand Down Expand Up @@ -380,7 +380,7 @@ def query_and_describe(
elapsed_s=(t1 - t0).total_seconds(),
reported=StringBasedDateTime(t1),
),
server_id=server_id,
participant_id=participant_id,
)
if query_type is not None:
result.query_type = query_type
Expand Down
Loading

0 comments on commit 970de6c

Please sign in to comment.