Skip to content

Commit 2b3673f

Browse files
pull master and update authutils
2 parents 6fe11c2 + 906dcd8 commit 2b3673f

15 files changed

+841
-796
lines changed

.github/workflows/integration_tests.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ jobs:
2121
CI_TEST_ORCID_PASSWORD: ${{ secrets.CI_TEST_ORCID_PASSWORD }}
2222
CI_TEST_RAS_USERID: ${{ secrets.CI_TEST_RAS_USERID }}
2323
CI_TEST_RAS_PASSWORD: ${{ secrets.CI_TEST_RAS_PASSWORD }}
24+
CI_TEST_RAS_2_USERID: ${{ secrets.CI_TEST_RAS_2_USERID }}
25+
CI_TEST_RAS_2_PASSWORD: ${{ secrets.CI_TEST_RAS_2_PASSWORD }}
2426
CI_SLACK_BOT_TOKEN: ${{ secrets.CI_SLACK_BOT_TOKEN }}
2527
CI_SLACK_CHANNEL_ID: ${{ secrets.CI_SLACK_CHANNEL_ID }}

.secrets.baseline

+6-2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
{
7676
"path": "detect_secrets.filters.allowlist.is_line_allowlisted"
7777
},
78+
{
79+
"path": "detect_secrets.filters.common.is_baseline_file",
80+
"filename": ".secrets.baseline"
81+
},
7882
{
7983
"path": "detect_secrets.filters.common.is_ignored_due_to_verification_policies",
8084
"min_level": 2
@@ -123,7 +127,7 @@
123127
"filename": "bin/settings.py",
124128
"hashed_secret": "347cd9c53ff77d41a7b22aa56c7b4efaf54658e3",
125129
"is_verified": false,
126-
"line_number": 46
130+
"line_number": 54
127131
}
128132
],
129133
"peregrine/blueprints/coremetadata.py": [
@@ -273,5 +277,5 @@
273277
}
274278
]
275279
},
276-
"generated_at": "2023-11-01T14:27:13Z"
280+
"generated_at": "2024-11-01T18:38:15Z"
277281
}

Dockerfile

+30-51
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,42 @@
1-
# To run:
2-
# - Create and fill out `creds.json`:
3-
# {
4-
# "fence_host": "",
5-
# "fence_username": "",
6-
# "fence_password": "",
7-
# "fence_database": "",
8-
# "db_host": "",
9-
# "db_username": "",
10-
# "db_password": "",
11-
# "db_database": "",
12-
# "gdcapi_secret_key": "",
13-
# "hostname": ""
14-
# }
15-
# - Build the image: `docker build . -t peregrine -f Dockerfile`
16-
# - Run: `docker run -v /full/path/to/creds.json:/var/www/peregrine/creds.json -p 81:80 peregrines`
17-
# To check running container: `docker exec -it peregrine /bin/bash`
18-
19-
FROM quay.io/cdis/python:python3.9-buster-2.0.0
1+
ARG AZLINUX_BASE_VERSION=master
2+
3+
FROM quay.io/cdis/python-nginx-al:${AZLINUX_BASE_VERSION} AS base
204

215
ENV appname=peregrine
226

23-
RUN apt-get update && apt-get install -y --no-install-recommends \
24-
build-essential libffi-dev musl-dev gcc libxml2-dev libxslt-dev \
25-
curl bash git vim
26-
RUN pip install --upgrade pip poetry
7+
WORKDIR /${appname}
8+
9+
RUN chown -R gen3:gen3 /${appname}
10+
11+
# Builder stage
12+
FROM base AS builder
13+
14+
RUN dnf install -y python3-devel postgresql-devel gcc
15+
16+
USER gen3
17+
18+
COPY poetry.lock pyproject.toml /${appname}/
19+
20+
RUN poetry install -vv --only main --no-interaction
2721

28-
RUN mkdir -p /var/www/$appname \
29-
&& mkdir -p /var/www/.cache/Python-Eggs/ \
30-
&& mkdir /run/nginx/ \
31-
&& ln -sf /dev/stdout /var/log/nginx/access.log \
32-
&& ln -sf /dev/stderr /var/log/nginx/error.log \
33-
&& chown nginx -R /var/www/.cache/Python-Eggs/ \
34-
&& chown nginx /var/www/$appname
22+
COPY --chown=gen3:gen3 . /${appname}
3523

36-
EXPOSE 80
24+
# Run poetry again so this app itself gets installed too
25+
RUN poetry install --without dev --no-interaction
3726

38-
WORKDIR /$appname
27+
RUN git config --global --add safe.directory /${appname} && COMMIT=`git rev-parse HEAD` && echo "COMMIT=\"${COMMIT}\"" > /${appname}/version_data.py \
28+
&& VERSION=`git describe --always --tags` && echo "VERSION=\"${VERSION}\"" >> /${appname}/version_data.py
3929

40-
# copy ONLY poetry artifact, install the dependencies but not indexd
41-
# this will make sure than the dependencies is cached
42-
COPY poetry.lock pyproject.toml /$appname/
43-
RUN poetry config virtualenvs.create false \
44-
&& poetry install -vv --no-root --no-dev --no-interaction \
45-
&& poetry show -v
30+
# Final stage
31+
FROM base
4632

47-
# copy source code ONLY after installing dependencies
48-
COPY . /$appname
49-
COPY ./deployment/uwsgi/uwsgi.ini /etc/uwsgi/uwsgi.ini
50-
COPY ./bin/settings.py /var/www/$appname/settings.py
51-
COPY ./bin/confighelper.py /var/www/$appname/confighelper.py
33+
RUN yum install -y postgresql-libs
5234

53-
# install peregrine
54-
RUN poetry config virtualenvs.create false \
55-
&& poetry install -vv --no-dev --no-interaction \
56-
&& poetry show -v
35+
COPY --from=builder /${appname} /${appname}
5736

58-
RUN COMMIT=`git rev-parse HEAD` && echo "COMMIT=\"${COMMIT}\"" >$appname/version_data.py \
59-
&& VERSION=`git describe --always --tags` && echo "VERSION=\"${VERSION}\"" >>$appname/version_data.py
37+
# Switch to non-root user 'gen3' for the serving process
38+
USER gen3
6039

61-
WORKDIR /var/www/$appname
40+
WORKDIR /${appname}
6241

63-
CMD /dockerrun.sh
42+
CMD ["/bin/bash", "-c", "/${appname}/dockerrun.bash"]

bin/settings.py

+36-50
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from peregrine.api import app, app_init
22
from os import environ
3-
import confighelper
3+
import bin.confighelper as confighelper
44

55
APP_NAME = "peregrine"
66

@@ -12,74 +12,60 @@ def load_json(file_name):
1212
conf_data = load_json("creds.json")
1313
config = app.config
1414

15-
config["AUTH"] = "https://auth.service.consul:5000/v3/"
16-
config["AUTH_ADMIN_CREDS"] = None
17-
config["INTERNAL_AUTH"] = None
1815

1916
# ARBORIST deprecated, replaced by ARBORIST_URL
2017
# ARBORIST_URL is initialized in app_init() directly
2118
config["ARBORIST"] = "http://arborist-service/"
2219

23-
# Signpost: deprecated, replaced by index client.
24-
config["SIGNPOST"] = {
25-
"host": environ.get("SIGNPOST_HOST") or "http://indexd-service",
26-
"version": "v0",
27-
"auth": ("gdcapi", conf_data.get("indexd_password", "{{indexd_password}}")),
28-
}
20+
2921
config["INDEX_CLIENT"] = {
3022
"host": environ.get("INDEX_CLIENT_HOST") or "http://indexd-service",
3123
"version": "v0",
32-
"auth": ("gdcapi", conf_data.get("indexd_password", "{{indexd_password}}")),
24+
# The user should be "sheepdog", but for legacy reasons, we use "gdcapi" instead
25+
"auth": (
26+
(
27+
environ.get("INDEXD_USER", "gdcapi"),
28+
environ.get("INDEXD_PASS")
29+
or conf_data.get("indexd_password", "{{indexd_password}}"),
30+
)
31+
),
3332
}
34-
config["FAKE_AUTH"] = False
33+
3534
config["PSQLGRAPH"] = {
36-
"host": conf_data.get("db_host", "{{db_host}}"),
37-
"user": conf_data.get("db_username", "{{db_username}}"),
38-
"password": conf_data.get("db_password", "{{db_password}}"),
39-
"database": conf_data.get("db_database", "{{db_database}}"),
35+
"host": environ.get("PGHOST") or conf_data.get("db_host", "{{db_host}}"),
36+
"user": environ.get("PGUSER") or conf_data.get("db_username", "{{db_username}}"),
37+
"password": environ.get("PGPASSWORD")
38+
or conf_data.get("db_password", "{{db_password}}"),
39+
"database": environ.get("PGDB") or conf_data.get("db_database", "{{db_database}}"),
4040
}
4141

42-
config["HMAC_ENCRYPTION_KEY"] = conf_data.get("hmac_key", "{{hmac_key}}")
43-
config["FLASK_SECRET_KEY"] = conf_data.get("gdcapi_secret_key", "{{gdcapi_secret_key}}")
44-
config["PSQL_USER_DB_CONNECTION"] = "postgresql://%s:%s@%s:5432/%s" % tuple(
45-
[
46-
conf_data.get(key, key)
47-
for key in ["fence_username", "fence_password", "fence_host", "fence_database"]
48-
]
42+
fence_username = environ.get("FENCE_DB_USER") or conf_data.get(
43+
"fence_username", "{{fence_username}}"
44+
)
45+
fence_password = environ.get("FENCE_DB_PASS") or conf_data.get(
46+
"fence_password", "{{fence_password}}"
47+
)
48+
fence_host = environ.get("FENCE_DB_HOST") or conf_data.get(
49+
"fence_host", "{{fence_host}}"
50+
)
51+
fence_database = environ.get("FENCE_DB_DBNAME") or conf_data.get(
52+
"fence_database", "{{fence_database}}"
4953
)
54+
config["PSQL_USER_DB_CONNECTION"] = "postgresql://%s:%s@%s:5432/%s" % (
55+
fence_username,
56+
fence_password,
57+
fence_host,
58+
fence_database,
59+
)
60+
5061

5162
config["DICTIONARY_URL"] = environ.get(
5263
"DICTIONARY_URL",
5364
"https://s3.amazonaws.com/dictionary-artifacts/datadictionary/develop/schema.json",
5465
)
5566

56-
config["SUBMISSION"] = {"bucket": conf_data.get("bagit_bucket", "{{bagit_bucket}}")}
57-
58-
config["STORAGE"] = {
59-
"s3": {
60-
"access_key": conf_data.get("s3_access", "{{s3_access}}"),
61-
"secret_key": conf_data.get("s3_secret", "{{s3_secret}}"),
62-
}
63-
}
64-
65-
config["OIDC_ISSUER"] = "https://%s/user" % conf_data["hostname"]
66-
67-
config["OAUTH2"] = {
68-
"client_id": conf_data.get("oauth2_client_id", "{{oauth2_client_id}}"),
69-
"client_secret": conf_data.get("oauth2_client_secret", "{{oauth2_client_secret}}"),
70-
"api_base_url": "https://%s/user/" % conf_data["hostname"],
71-
"authorize_url": "https://%s/user/oauth2/authorize" % conf_data["hostname"],
72-
"access_token_url": "https://%s/user/oauth2/token" % conf_data["hostname"],
73-
"refresh_token_url": "https://%s/user/oauth2/token" % conf_data["hostname"],
74-
"client_kwargs": {
75-
"redirect_uri": "https://%s/api/v0/oauth2/authorize" % conf_data["hostname"],
76-
"scope": "openid data user",
77-
},
78-
# deprecated key values, should be removed after all commons use new oidc
79-
"internal_oauth_provider": "http://fence-service/oauth2/",
80-
"oauth_provider": "https://%s/user/oauth2/" % conf_data["hostname"],
81-
"redirect_uri": "https://%s/api/v0/oauth2/authorize" % conf_data["hostname"],
82-
}
67+
hostname = environ.get("CONF_HOSTNAME") or conf_data["hostname"]
68+
config["OIDC_ISSUER"] = "https://%s/user" % hostname
8369

8470
config["USER_API"] = config["OIDC_ISSUER"] # for use by authutils
8571
# use the USER_API URL instead of the public issuer URL to accquire JWT keys

bin/setup_notifications.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55

66
from sqlalchemy import create_engine
7-
from gdcdatamodel.models.notifications import Base
7+
from gen3datamodel.models.notifications import Base
88

99

1010
def setup(host, user, password, database):

bin/setup_psqlgraph.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from sqlalchemy import create_engine
33
import logging
44

5-
from gdcdatamodel.models import *
5+
from gen3datamodel.models import *
66
from psqlgraph import create_all, Node, Edge
77

88

bin/setup_transactionlogs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import argparse
77
from sqlalchemy import create_engine
8-
from gdcdatamodel.models.submission import Base
8+
from gen3datamodel.models.submission import Base
99

1010

1111
def setup(host, user, password, database):

deployment/uwsgi/uwsgi.ini

-34
This file was deleted.

deployment/wsgi/gunicorn.conf.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
wsgi_app = "bin.settings:application"
2+
bind = "0.0.0.0:8000"
3+
workers = 1
4+
user = "gen3"
5+
group = "gen3"
6+
timeout = 300

dockerrun.bash

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
nginx
4+
poetry run gunicorn -c /peregrine/deployment/wsgi/gunicorn.conf.py

peregrine/api.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ def dictionary_init(app):
103103

104104
d = gdcdictionary.gdcdictionary
105105
dictionary.init(d)
106-
from gdcdatamodel import models as md
107-
from gdcdatamodel import validators as vd
106+
from gen3datamodel import models as md
107+
from gen3datamodel import validators as vd
108108

109109
datamodelutils.validators.init(vd)
110110
datamodelutils.models.init(md)
@@ -133,10 +133,6 @@ def app_init(app):
133133
submission.graphql.make_graph_traversal_dict(app)
134134
app.graphql_schema = submission.graphql.get_schema()
135135
app.schema_file = submission.generate_schema_file(app.graphql_schema, app.logger)
136-
try:
137-
app.secret_key = app.config["FLASK_SECRET_KEY"]
138-
except KeyError:
139-
app.logger.error("Secret key not set in config! Authentication will not work")
140136
async_pool_init(app)
141137

142138
# ARBORIST deprecated, replaced by ARBORIST_URL

peregrine/models.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
"""
22
This module generalizes the data model used by the peregrine blueprint, and
33
must be initialized using another ``models`` module to set the attributes of
4-
this module. For example, using ``gdcdatamodel.models`` as the models:
4+
this module. For example, using ``gen3datamodel.models`` as the models:
55
66
.. code-block:: python
77
8-
peregrine.models.init(gdcdatamodel.models)
8+
peregrine.models.init(gen3datamodel.models)
99
1010
Then this module can be imported elsewhere in ``peregrine``:
1111
1212
.. code-block:: python
1313
1414
from peregrine import models
1515
16-
# This is effectively an alias of ``gdcdatamodel.models.Project``.
16+
# This is effectively an alias of ``gen3datamodel.models.Project``.
1717
models.Project
1818
"""
1919

peregrine/resources/submission/graphql/node.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
peregrine.resources.submission.graphql.node
44
----------------------------------
55
6-
Implements GraphQL queries for each gdcdatamodel.model node type
6+
Implements GraphQL queries for each gen3datamodel.model node type
77
using the Graphene GraphQL library
88
"""
99

@@ -424,7 +424,7 @@ def resolve_node(self, info, **args):
424424
425425
:returns:
426426
A list of graphene object classes (e.g. a Case query object
427-
(not a gdcdatamodel Case)).
427+
(not a gen3datamodel Case)).
428428
429429
"""
430430

0 commit comments

Comments
 (0)