mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-09 16:39:49 -04:00
more
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import uuid
|
||||
from datetime import timedelta
|
||||
|
||||
from sqlalchemy import func, or_
|
||||
from sqlalchemy import func, or_, select
|
||||
|
||||
from app import db
|
||||
from app.dao.dao_utils import autocommit, version_class
|
||||
@@ -23,16 +23,26 @@ def save_model_api_key(api_key):
|
||||
@autocommit
|
||||
@version_class(ApiKey)
|
||||
def expire_api_key(service_id, api_key_id):
|
||||
api_key = ApiKey.query.filter_by(id=api_key_id, service_id=service_id).one()
|
||||
api_key = (
|
||||
db.session.execute(
|
||||
select(ApiKey).filter_by(id=api_key_id, service_id=service_id)
|
||||
)
|
||||
.scalars()
|
||||
.one()
|
||||
)
|
||||
api_key.expiry_date = utc_now()
|
||||
db.session.add(api_key)
|
||||
|
||||
|
||||
def get_model_api_keys(service_id, id=None):
|
||||
if id:
|
||||
return ApiKey.query.filter_by(
|
||||
id=id, service_id=service_id, expiry_date=None
|
||||
).one()
|
||||
return (
|
||||
db.session.execute(
|
||||
select(ApiKey).filter_by(id=id, service_id=service_id, expiry_date=None)
|
||||
)
|
||||
.scalars()
|
||||
.one()
|
||||
)
|
||||
seven_days_ago = utc_now() - timedelta(days=7)
|
||||
return ApiKey.query.filter(
|
||||
or_(
|
||||
@@ -47,7 +57,13 @@ def get_unsigned_secrets(service_id):
|
||||
"""
|
||||
This method can only be exposed to the Authentication of the api calls.
|
||||
"""
|
||||
api_keys = ApiKey.query.filter_by(service_id=service_id, expiry_date=None).all()
|
||||
api_keys = (
|
||||
db.session.execute(
|
||||
select(ApiKey).filter_by(service_id=service_id, expiry_date=None)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
keys = [x.secret for x in api_keys]
|
||||
return keys
|
||||
|
||||
@@ -56,5 +72,9 @@ def get_unsigned_secret(key_id):
|
||||
"""
|
||||
This method can only be exposed to the Authentication of the api calls.
|
||||
"""
|
||||
api_key = ApiKey.query.filter_by(id=key_id, expiry_date=None).one()
|
||||
api_key = (
|
||||
db.session.execute(select(ApiKey).filter_by(id=key_id, expiry_date=None))
|
||||
.scalars()
|
||||
.one()
|
||||
)
|
||||
return api_key.secret
|
||||
|
||||
Reference in New Issue
Block a user