Skip to content

Commit

Permalink
Bump version and path add (#640)
Browse files Browse the repository at this point in the history
* Add path / ip to audit_log fields

* Bump version: 6.5.1 → 6.6.0

* Add more params to projectless connection

* Linting

---------

Co-authored-by: Michael Franklin <[email protected]>
  • Loading branch information
illusional and illusional authored Jan 5, 2024
1 parent f6c226d commit c275b7b
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 6.5.1
current_version = 6.6.0
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>[A-z0-9-]+)
Expand Down
2 changes: 1 addition & 1 deletion api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from api.settings import PROFILE_REQUESTS, SKIP_DATABASE_CONNECTION

# This tag is automatically updated by bump2version
_VERSION = '6.5.1'
_VERSION = '6.6.0'

logger = get_logger()

Expand Down
25 changes: 19 additions & 6 deletions api/utils/db.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from os import getenv
import logging
from os import getenv

from fastapi import Depends, HTTPException, Request
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from google.auth.transport import requests
from google.oauth2 import id_token

from api.settings import get_default_user
from api.utils.gcp import email_from_id_token
from db.python.connect import SMConnections, Connection
from db.python.connect import Connection, SMConnections
from db.python.gcp_connect import BqConnection, PubSubConnection
from db.python.tables.project import ProjectPermissionsTable

Expand Down Expand Up @@ -61,22 +61,27 @@ def authenticate(
logging.info(f'Using {default_user} as authenticated user')
return default_user

raise HTTPException(status_code=401, detail=f'Not authenticated :(')
raise HTTPException(status_code=401, detail='Not authenticated :(')


async def dependable_get_write_project_connection(
project: str,
request: Request,
author: str = Depends(authenticate),
ar_guid: str = Depends(get_ar_guid),
on_behalf_of: str | None = Depends(get_on_behalf_of),
) -> Connection:
"""FastAPI handler for getting connection WITH project"""
meta = {'path': request.url.path}
if request.client:
meta['ip'] = request.client.host
return await ProjectPermissionsTable.get_project_connection(
project_name=project,
author=author,
readonly=False,
ar_guid=ar_guid,
on_behalf_of=on_behalf_of,
meta=meta,
)


Expand All @@ -96,10 +101,18 @@ async def dependable_get_readonly_project_connection(


async def dependable_get_connection(
author: str = Depends(authenticate), ar_guid: str = Depends(get_ar_guid)
request: Request,
author: str = Depends(authenticate),
ar_guid: str = Depends(get_ar_guid),
):
"""FastAPI handler for getting connection withOUT project"""
return await SMConnections.get_connection_no_project(author, ar_guid=ar_guid)
meta = {'path': request.url.path}
if request.client:
meta['ip'] = request.client.host

return await SMConnections.get_connection_no_project(
author, ar_guid=ar_guid, meta=meta
)


async def dependable_get_bq_connection(author: str = Depends(authenticate)):
Expand Down
10 changes: 8 additions & 2 deletions db/python/connect.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pylint: disable=unused-import
# pylint: disable=unused-import,too-many-instance-attributes
# flake8: noqa
"""
Code for connecting to Postgres database
Expand Down Expand Up @@ -51,13 +51,15 @@ def __init__(
on_behalf_of: str | None,
readonly: bool,
ar_guid: str | None,
meta: dict[str, str] | None = None,
):
self.connection: databases.Database = connection
self.project: int | None = project
self.author: str = author
self.on_behalf_of: str | None = on_behalf_of
self.readonly: bool = readonly
self.ar_guid: str | None = ar_guid
self.meta = meta

self._audit_log_id: int | None = None

Expand All @@ -81,6 +83,7 @@ async def audit_log_id(self):
ar_guid=self.ar_guid,
comment=None,
project=self.project,
meta=self.meta,
)

return self._audit_log_id
Expand Down Expand Up @@ -223,7 +226,9 @@ async def get_made_connection():
return conn

@staticmethod
async def get_connection_no_project(author: str, ar_guid: str):
async def get_connection_no_project(
author: str, ar_guid: str, meta: dict[str, str]
):
"""Get a db connection from a project and user"""
# maybe it makes sense to perform permission checks here too
logger.debug(f'Authenticate no-project connection with {author!r}')
Expand All @@ -240,4 +245,5 @@ async def get_connection_no_project(author: str, ar_guid: str):
on_behalf_of=None,
ar_guid=ar_guid,
readonly=False,
meta=meta,
)
2 changes: 2 additions & 0 deletions db/python/tables/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ async def get_project_connection(
readonly: bool,
ar_guid: str,
on_behalf_of: str | None = None,
meta: dict[str, str] | None = None,
):
"""Get a db connection from a project and user"""
# maybe it makes sense to perform permission checks here too
Expand All @@ -80,6 +81,7 @@ async def get_project_connection(
readonly=readonly,
on_behalf_of=on_behalf_of,
ar_guid=ar_guid,
meta=meta,
)

async def audit_log_id(self):
Expand Down
2 changes: 1 addition & 1 deletion deploy/python/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.5.1
6.6.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
setup(
name=PKG,
# This tag is automatically updated by bump2version
version='6.5.1',
version='6.6.0',
description='Python API for interacting with the Sample API system',
long_description=readme,
long_description_content_type='text/markdown',
Expand Down
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metamist",
"version": "6.5.1",
"version": "6.6.0",
"private": true,
"dependencies": {
"@apollo/client": "^3.7.3",
Expand Down

0 comments on commit c275b7b

Please sign in to comment.