Skip to content

Commit

Permalink
get_valid_org_auth_tokens (#531)
Browse files Browse the repository at this point in the history
  • Loading branch information
ykeremy committed Jun 29, 2024
1 parent dba3d7f commit 6a6119b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions skyvern/forge/sdk/db/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ async def get_valid_org_auth_token(
.filter_by(organization_id=organization_id)
.filter_by(token_type=token_type)
.filter_by(valid=True)
.order_by(OrganizationAuthTokenModel.created_at.desc())
)
).first():
return convert_to_organization_auth_token(token)
Expand All @@ -536,6 +537,30 @@ async def get_valid_org_auth_token(
LOG.error("UnexpectedError", exc_info=True)
raise

async def get_valid_org_auth_tokens(
self,
organization_id: str,
token_type: OrganizationAuthTokenType,
) -> list[OrganizationAuthToken]:
try:
async with self.Session() as session:
tokens = (
await session.scalars(
select(OrganizationAuthTokenModel)
.filter_by(organization_id=organization_id)
.filter_by(token_type=token_type)
.filter_by(valid=True)
.order_by(OrganizationAuthTokenModel.created_at.desc())
)
).all()
return [convert_to_organization_auth_token(token) for token in tokens]
except SQLAlchemyError:
LOG.error("SQLAlchemyError", exc_info=True)
raise
except Exception:
LOG.error("UnexpectedError", exc_info=True)
raise

async def validate_org_auth_token(
self,
organization_id: str,
Expand Down

0 comments on commit 6a6119b

Please sign in to comment.