-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from wtsi-npg/devel
Release to master
- Loading branch information
Showing
38 changed files
with
1,079 additions
and
394 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,7 @@ | |
__pycache__ | ||
*.egg-info | ||
.vscode | ||
.eggs | ||
.eggs | ||
build | ||
.pytest_cache | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[build-system] | ||
requires = ["setuptools>=61"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "npg_porch" | ||
requires-python = ">=3.10" | ||
authors = [{name="Marina Gourtovaia", email="[email protected]"}, {name="Kieron Taylor", email="[email protected]"}] | ||
description = "API server for tracking unique workflow executions" | ||
readme = "README.md" | ||
license = {file = "LICENSE.md"} | ||
dependencies = [ | ||
"aiosqlite", | ||
"asyncpg", | ||
"fastapi", | ||
"pydantic > 2.0.0", | ||
"pysqlite3", | ||
"psycopg2-binary", | ||
"sqlalchemy >2", | ||
"ujson", | ||
"uvicorn", | ||
"uuid" | ||
] | ||
dynamic = ["version"] | ||
|
||
[project.optional-dependencies] | ||
test = [ | ||
"pytest", | ||
"pytest-asyncio", | ||
"requests", | ||
"flake8", | ||
"httpx" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/usr/bin/env python | ||
|
||
import argparse | ||
from sqlalchemy import create_engine, select | ||
from sqlalchemy.orm import sessionmaker | ||
from sqlalchemy.orm.exc import NoResultFound | ||
|
||
from npg.porchdb.models import Token, Pipeline | ||
|
||
parser = argparse.ArgumentParser( | ||
description='Creates a token in the backend DB and returns it' | ||
) | ||
|
||
parser.add_argument( | ||
'-H', '--host', help='Postgres host', required=True | ||
) | ||
parser.add_argument( | ||
'-d', '--database', help='Postgres database', default='npg_porch' | ||
) | ||
parser.add_argument( | ||
'-s', '--schema', help='Postgres schema', default='npg_porch' | ||
) | ||
parser.add_argument( | ||
'-u', '--user', help='Postgres rw user', required=True | ||
) | ||
parser.add_argument( | ||
'-p', '--password', help='Postgres rw password', required=True | ||
) | ||
parser.add_argument( | ||
'-P', '--port', help='Postgres port', required=True | ||
) | ||
parser.add_argument( | ||
'-n', '--pipeline', help='Pipeline name. If given, create ' | ||
) | ||
parser.add_argument( | ||
'-D', '--description', help='Description of token purpose', required=True | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
|
||
db_url = f'postgresql+psycopg2://{args.user}:{args.password}@{args.host}:{args.port}/{args.database}' | ||
|
||
engine = create_engine(db_url, connect_args={'options': f'-csearch_path={args.schema}'}) | ||
SessionFactory = sessionmaker(bind=engine) | ||
session = SessionFactory() | ||
|
||
token = None | ||
pipeline = None | ||
|
||
if args.pipeline: | ||
try: | ||
pipeline = session.execute( | ||
select(Pipeline) | ||
.where(Pipeline.name == args.pipeline) | ||
).scalar_one() | ||
except NoResultFound: | ||
raise Exception( | ||
'Pipeline with name {} not found in database'.format(args.pipeline) | ||
) | ||
|
||
token = Token( | ||
pipeline=pipeline, | ||
description=args.description | ||
) | ||
else: | ||
token = Token(description=args.description) | ||
|
||
session.add(token) | ||
session.commit() | ||
|
||
print(token.token) | ||
|
||
session.close() | ||
engine.dispose() |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright (C) 2022 Genome Research Ltd. | ||
# | ||
# Author: Kieron Taylor [email protected] | ||
# Author: Marina Gourtovaia [email protected] | ||
# | ||
# This file is part of npg_porch | ||
# | ||
# npg_porch is free software: you can redistribute it and/or modify it | ||
# under the terms of the GNU General Public License as published by the Free | ||
# Software Foundation; either version 3 of the License, or (at your option) any | ||
# later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import logging | ||
from fastapi import Depends | ||
from fastapi.security import HTTPBearer | ||
from fastapi import HTTPException | ||
|
||
from npg.porchdb.connection import get_CredentialsValidator | ||
from npg.porchdb.auth import CredentialsValidationException | ||
|
||
auth_scheme = HTTPBearer() | ||
|
||
async def validate( | ||
creds = Depends(auth_scheme), | ||
validator = Depends(get_CredentialsValidator) | ||
): | ||
|
||
token = creds.credentials | ||
p = None | ||
try: | ||
p = await validator.token2permission(token) | ||
except CredentialsValidationException as e: | ||
logger = logging.getLogger(__name__) | ||
logger.warning(str(e)) | ||
raise HTTPException(status_code=403, detail="Invalid token") | ||
|
||
return p |
Oops, something went wrong.