Skip to content

Commit

Permalink
Merge branch 'main' into better-match-info
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin5605 authored Aug 9, 2024
2 parents 92560f3 + b6a1b3e commit 586548b
Show file tree
Hide file tree
Showing 11 changed files with 872 additions and 586 deletions.
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ which will invoke `docker compose` for you.
We use `pytest` to run our tests. Tests go in the `tests/` directory.
The tests for each python module should go in a separate tests file.

We use `requests` for making requests to the API. Use the fixture `api_url` for the URL to make requests to.
We use `httpx` for making requests to the API. Use the fixture `api_url` for the URL to make requests to.
For example:

```py
def test_root(api_url: str):
r = requests.get(api_url)
r = httpx.get(api_url)
assert r.status_code == 200
```

Expand All @@ -91,7 +91,7 @@ For example:

```py
def test_query(api_url: str, db_session: Session):
r = requests.get(api_url + "/package?name=a&version=0.1.0")
r = httpx.get(api_url + "/package?name=a&version=0.1.0")
data = r.json()
assert r["name"] == "a"
```
Expand Down
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ FROM python:3.12-slim@sha256:6bab0b6977b98f24a1c65855a1592152f3c4268afd19adc4da3
RUN pip install -U pip setuptools wheel
RUN pip install pdm

RUN apt-get -y update
RUN apt-get -y install git

WORKDIR /app
COPY pyproject.toml pdm.lock ./
RUN mkdir __pypackages__ && pdm install --prod --no-lock --no-editable
Expand Down Expand Up @@ -33,6 +36,7 @@ COPY alembic/ alembic/
COPY alembic.ini ./
COPY src/ src/
COPY entrypoint.sh ./
COPY logging/ logging/
RUN chmod +x entrypoint.sh

CMD ["sh", "./entrypoint.sh"]
Expand Down
86 changes: 86 additions & 0 deletions docs/source/database_schema.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
Database Schema
===============

.. code-block:: sql
CREATE EXTENSION IF NOT EXISTS pg_stat_statements WITH SCHEMA public;
CREATE TYPE public.status AS ENUM (
'QUEUED',
'PENDING',
'FINISHED',
'FAILED'
);
CREATE TABLE public.download_urls (
id uuid NOT NULL,
scan_id uuid NOT NULL,
url text NOT NULL
);
CREATE TABLE public.package_rules (
scan_id uuid NOT NULL,
rule_id uuid NOT NULL
);
CREATE TABLE public.rules (
name text NOT NULL,
id uuid NOT NULL
);
CREATE TABLE public.scans (
scan_id uuid NOT NULL,
name text NOT NULL,
status public.status NOT NULL,
score integer,
version text NOT NULL,
queued_at timestamp without time zone,
pending_at timestamp without time zone,
finished_at timestamp without time zone,
reported_at timestamp without time zone,
inspector_url text,
reported_by text,
queued_by text NOT NULL,
pending_by text,
finished_by text,
commit_hash text,
fail_reason text
);
ALTER TABLE ONLY public.download_urls
ADD CONSTRAINT download_urls_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.scans
ADD CONSTRAINT name_version_unique UNIQUE (name, version);
ALTER TABLE ONLY public.package_rules
ADD CONSTRAINT package_rules_pkey PRIMARY KEY (scan_id, rule_id);
ALTER TABLE ONLY public.scans
ADD CONSTRAINT packages_pkey PRIMARY KEY (scan_id);
ALTER TABLE ONLY public.rules
ADD CONSTRAINT rules_name_key UNIQUE (name);
ALTER TABLE ONLY public.rules
ADD CONSTRAINT rules_pkey PRIMARY KEY (id);
CREATE INDEX ix_download_urls_scan_id ON public.download_urls USING btree (scan_id);
CREATE INDEX ix_scans_finished_at ON public.scans USING btree (finished_at);
CREATE INDEX ix_scans_status ON public.scans USING btree (status) WHERE ((status = 'QUEUED'::public.status) OR (status = 'PENDING'::public.status));
ALTER TABLE ONLY public.download_urls
ADD CONSTRAINT download_urls_scan_id_fkey FOREIGN KEY (scan_id) REFERENCES public.scans(scan_id);
ALTER TABLE ONLY public.package_rules
ADD CONSTRAINT package_rules_rule_id_fkey FOREIGN KEY (rule_id) REFERENCES public.rules(id);
ALTER TABLE ONLY public.package_rules
ADD CONSTRAINT package_rules_scan_id_fkey FOREIGN KEY (scan_id) REFERENCES public.scans(scan_id);
.. image:: /images/schema.svg
:alt: ER Diagram
:width: 800px
:align: center
19 changes: 19 additions & 0 deletions logging/development.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[handlers.default]
level = "DEBUG"
class = "logging.StreamHandler"
formatter = "development"

[loggers.""]
handlers = ["default"]
level = "DEBUG"
propagate = true

[loggers."sqlalchemy.engine"]
handlers = ["default"]
level = "INFO"
propagate = true

[loggers."sqlalchemy.pool"]
handlers = ["default"]
level = "DEBUG"
propagate = true
9 changes: 9 additions & 0 deletions logging/production.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[handlers.default]
level = "INFO"
class = "logging.StreamHandler"
formatter = "json"

[loggers.""]
handlers = ["default"]
level = "INFO"
propagate = true
Loading

0 comments on commit 586548b

Please sign in to comment.