Skip to content

Commit 96d52fc

Browse files
authored
Merge pull request #369 from CanDIG/daisieh/refactor
DHDPS-414: split out DRS from htsget
2 parents 4cdef30 + 03656f9 commit 96d52fc

File tree

17 files changed

+462
-2289
lines changed

17 files changed

+462
-2289
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 67 deletions
This file was deleted.

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ RUN groupadd -r candig && useradd -rm candig -g candig
1010

1111
RUN apt-get update && apt-get -y install \
1212
cron \
13-
sqlite3 \
1413
postgresql-client \
15-
postgresql
14+
postgresql
1615

1716
COPY requirements.txt /app/htsget_server/requirements.txt
1817

@@ -22,6 +21,8 @@ COPY . /app/htsget_server
2221

2322
WORKDIR /app/htsget_server
2423

24+
COPY data/files /data/
25+
2526
RUN chown -R candig:candig /app/htsget_server
2627

2728
USER candig

README.md

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,17 @@ Thank you to [gel-htsget](https://github.com/genomicsengland/gel-htsget) for bei
2020
- Python 3
2121
- [Pysam](https://pysam.readthedocs.io/en/latest/api.html)
2222
- Pytest
23-
- Travis-CI
2423

2524
## Installation
2625

27-
The server software can be installed in a virtual environment:
28-
```
29-
python setup.py install
30-
```
31-
32-
## Running
33-
34-
This application can be configured by way of the config.ini file in the root of the project.
35-
The server can be run with:
36-
37-
```
38-
python htsget_server/server.py
39-
```
40-
41-
This application can also be set up in a docker container. A docker-compose file and Dockerfile are provided.
26+
The server is meant to be run in the context of the [CanDIG stack](https://candig.github.io/CanDIGv2/deployment/local/).
4227

4328
The default MinIO location specified in the config.ini file is the sandbox at MinIO, but a different location can be specified there as well. Be sure to update the access key and secret key values in config.ini.
4429

4530

4631
## Testing
4732

48-
For testing, a small test suite under tests/test_htsget_server.py can be run by starting the server and running:
49-
33+
An automated test suite is provided, but can only be run in the docker container stack context. If you are running the CanDIG stack, you can run the tests with
5034
```
51-
pytest
35+
docker exec candigv2_htsget_1 pytest
5236
```
53-
54-
For automated testing, activate the repo with [Travis-CI](https://travis-ci.com/getting_started)

config.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ AGGREGATE_COUNT_THRESHOLD = <AGGREGATE_COUNT_THRESHOLD>
99
[paths]
1010
DBPath = sqlite:///./data/files.db
1111
PGPath = postgresql+psycopg2://<POSTGRES_USERNAME>:PASSWORD@HOST:5432/genomic
12+
DRSPath = postgresql+psycopg2://<POSTGRES_USERNAME>:PASSWORD@HOST:5432/drs
1213

1314
[authz]
1415
CANDIG_OPA_URL = <OPA_URL>

data/files.sql

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,4 @@
11
BEGIN TRANSACTION;
2-
CREATE TABLE program (
3-
id VARCHAR NOT NULL,
4-
statistics JSONB,
5-
PRIMARY KEY (id)
6-
);
7-
CREATE TABLE drs_object (
8-
id VARCHAR NOT NULL,
9-
name VARCHAR,
10-
self_uri VARCHAR,
11-
size BIGINT,
12-
created_time VARCHAR,
13-
updated_time VARCHAR,
14-
version VARCHAR,
15-
mime_type VARCHAR,
16-
checksums VARCHAR,
17-
description VARCHAR,
18-
aliases VARCHAR,
19-
program_id VARCHAR,
20-
meta_data JSONB,
21-
PRIMARY KEY (id),
22-
FOREIGN KEY(program_id) REFERENCES program (id)
23-
);
24-
CREATE TABLE access_method (
25-
id SERIAL PRIMARY KEY,
26-
drs_object_id VARCHAR,
27-
type VARCHAR,
28-
access_id VARCHAR,
29-
region VARCHAR,
30-
url VARCHAR,
31-
headers VARCHAR,
32-
FOREIGN KEY(drs_object_id) REFERENCES drs_object (id)
33-
);
34-
CREATE TABLE content_object (
35-
id SERIAL PRIMARY KEY,
36-
drs_object_id VARCHAR,
37-
name VARCHAR,
38-
contents_id VARCHAR,
39-
drs_uri VARCHAR,
40-
contents VARCHAR,
41-
FOREIGN KEY(drs_object_id) REFERENCES drs_object (id)
42-
);
432
CREATE TABLE contig (
443
id VARCHAR NOT NULL,
454
PRIMARY KEY (id)
@@ -137,8 +96,8 @@ CREATE TABLE variantfile (
13796
indexed INTEGER,
13897
chr_prefix VARCHAR,
13998
reference_genome VARCHAR,
140-
PRIMARY KEY (id),
141-
FOREIGN KEY(drs_object_id) REFERENCES drs_object (id)
99+
PRIMARY KEY (id)
100+
-- FOREIGN KEY(drs_object_id) REFERENCES drs_object (id)
142101
);
143102
CREATE TABLE pos_bucket (
144103
id SERIAL PRIMARY KEY,

htsget_server/authz.py

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
import json
21
from config import AUTHZ, TEST_KEY
3-
from flask import Flask
4-
import database
52
import authx.auth
63
from candigv2_logging.logging import CanDIGLogger
74

85

96
logger = CanDIGLogger(__file__)
107

118

12-
app = Flask(__name__)
13-
14-
159
class AuthzRequest:
1610
headers = {}
1711
method = None
@@ -29,49 +23,6 @@ def is_testing(request):
2923
return True
3024

3125

32-
def is_authed(id_, request):
33-
if request is None:
34-
return 401
35-
if is_testing(request):
36-
return 200 # no auth
37-
if has_full_authz(request):
38-
return 200
39-
if "Authorization" in request.headers:
40-
obj = database.get_drs_object(id_)
41-
if obj is not None and 'program' in obj:
42-
if is_program_authorized(request, obj['program']):
43-
return 200
44-
else:
45-
return 404
46-
else:
47-
return 401
48-
return 403
49-
50-
51-
def get_authorized_programs(request):
52-
req = AuthzRequest(request.headers, request.method, request.url.path)
53-
if has_full_authz(req):
54-
return list(map(lambda x: x['id'], database.list_programs()))
55-
if is_testing(req):
56-
return ["test-htsget"]
57-
try:
58-
return authx.auth.get_opa_datasets(req)
59-
except Exception as e:
60-
logger.warning(f"Couldn't authorize programs: {type(e)} {str(e)}")
61-
return []
62-
63-
64-
def is_program_authorized(request, program_id):
65-
req = AuthzRequest(request.headers, request.method, request.url.path)
66-
if is_testing(req):
67-
return True
68-
if has_full_authz(req):
69-
return True
70-
if not "Authorization" in request.headers:
71-
return False
72-
return authx.auth.is_action_allowed_for_program(authx.auth.get_auth_token(req), method=req.method, path=req.path, program=program_id)
73-
74-
7526
def has_full_authz(request):
7627
"""
7728
Is the user associated with the token a site admin? Alternately, is this request from query or ingest?

0 commit comments

Comments
 (0)