Skip to content
Snippets Groups Projects
Verified Commit d6bfba28 authored by Daniel Göbel's avatar Daniel Göbel
Browse files

Make token optional in workflow credentials schema

#49
parent a28260c1
No related branches found
No related tags found
2 merge requests!69Delete dev branch,!46Resolve "Make token optional in schema for getting the workflow credentials"
Pipeline #36613 passed
...@@ -8,7 +8,7 @@ from app.core.config import settings ...@@ -8,7 +8,7 @@ from app.core.config import settings
from app.crud.crud_workflow import CRUDWorkflow from app.crud.crud_workflow import CRUDWorkflow
from app.crud.crud_workflow_version import CRUDWorkflowVersion from app.crud.crud_workflow_version import CRUDWorkflowVersion
from app.git_repository import build_repository from app.git_repository import build_repository
from app.schemas.workflow import WorkflowCredentialsIn from app.schemas.workflow import WorkflowCredentialsIn, WorkflowCredentialsOut
from app.scm import SCM, Provider from app.scm import SCM, Provider
router = APIRouter(prefix="/workflows/{wid}/credentials", tags=["Workflow Credentials"]) router = APIRouter(prefix="/workflows/{wid}/credentials", tags=["Workflow Credentials"])
...@@ -20,7 +20,7 @@ Authorization = Annotated[Callable[[str], Awaitable[Any]], Depends(workflow_auth ...@@ -20,7 +20,7 @@ Authorization = Annotated[Callable[[str], Awaitable[Any]], Depends(workflow_auth
@router.get("", status_code=status.HTTP_200_OK, summary="Get the credentials of a workflow") @router.get("", status_code=status.HTTP_200_OK, summary="Get the credentials of a workflow")
async def get_workflow_credentials( async def get_workflow_credentials(
workflow: CurrentWorkflow, current_user: CurrentUser, authorization: Authorization workflow: CurrentWorkflow, current_user: CurrentUser, authorization: Authorization
) -> WorkflowCredentialsIn: ) -> WorkflowCredentialsOut:
""" """
Get the credentials for the repository of a workflow. Only the developer of a workflow can do this.\n Get the credentials for the repository of a workflow. Only the developer of a workflow can do this.\n
Permission "workflow:update" required. Permission "workflow:update" required.
...@@ -44,7 +44,7 @@ async def get_workflow_credentials( ...@@ -44,7 +44,7 @@ async def get_workflow_credentials(
raise HTTPException( raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN, detail="Only the developer can retrieve the repository credentials" status_code=status.HTTP_403_FORBIDDEN, detail="Only the developer can retrieve the repository credentials"
) )
return WorkflowCredentialsIn(token=workflow.credentials_token) return WorkflowCredentialsOut(token=workflow.credentials_token)
@router.put("", status_code=status.HTTP_200_OK, summary="Update the credentials of a workflow") @router.put("", status_code=status.HTTP_200_OK, summary="Update the credentials of a workflow")
......
...@@ -19,6 +19,7 @@ from app.api.utils import delete_remote_icon, upload_icon ...@@ -19,6 +19,7 @@ from app.api.utils import delete_remote_icon, upload_icon
from app.core.config import settings from app.core.config import settings
from app.crud import CRUDWorkflowVersion from app.crud import CRUDWorkflowVersion
from app.git_repository import build_repository from app.git_repository import build_repository
from app.schemas.workflow_version import IconUpdateOut
from app.schemas.workflow_version import WorkflowVersion as WorkflowVersionSchema from app.schemas.workflow_version import WorkflowVersion as WorkflowVersionSchema
from app.schemas.workflow_version import WorkflowVersionStatus from app.schemas.workflow_version import WorkflowVersionStatus
...@@ -305,7 +306,7 @@ async def upload_workflow_version_icon( ...@@ -305,7 +306,7 @@ async def upload_workflow_version_icon(
current_user: CurrentUser, current_user: CurrentUser,
db: DBSession, db: DBSession,
icon: UploadFile = File(..., description="Optional Icon for the Workflow."), icon: UploadFile = File(..., description="Optional Icon for the Workflow."),
) -> str: ) -> IconUpdateOut:
""" """
Upload an icon for the workflow version and returns the new icon URL.\n Upload an icon for the workflow version and returns the new icon URL.\n
Permission "workflow:update" required. Permission "workflow:update" required.
...@@ -343,7 +344,7 @@ async def upload_workflow_version_icon( ...@@ -343,7 +344,7 @@ async def upload_workflow_version_icon(
# Delete old icon if possible # Delete old icon if possible
if old_slug is not None: if old_slug is not None:
background_tasks.add_task(delete_remote_icon, s3=s3, db=db, icon_slug=old_slug) background_tasks.add_task(delete_remote_icon, s3=s3, db=db, icon_slug=old_slug)
return str(settings.OBJECT_GATEWAY_URI) + "/".join([settings.ICON_BUCKET, icon_slug]) return IconUpdateOut(icon_url=str(settings.OBJECT_GATEWAY_URI) + "/".join([settings.ICON_BUCKET, icon_slug]))
@router.delete( @router.delete(
......
...@@ -121,6 +121,15 @@ class WorkflowCredentialsIn(BaseModel): ...@@ -121,6 +121,15 @@ class WorkflowCredentialsIn(BaseModel):
) )
class WorkflowCredentialsOut(BaseModel):
token: Optional[str] = Field(
None,
description="Token to access the content git repository",
examples=["vnpau89avpa48iunga984gh9h89pvhj"],
max_length=128,
)
class WorkflowUpdate(BaseModel): class WorkflowUpdate(BaseModel):
version: str = Field( version: str = Field(
..., ...,
......
...@@ -83,3 +83,11 @@ class WorkflowVersion(WorkflowVersionStatus): ...@@ -83,3 +83,11 @@ class WorkflowVersion(WorkflowVersionStatus):
if load_modes and len(db_version.workflow_modes) > 0 if load_modes and len(db_version.workflow_modes) > 0
else mode_ids, else mode_ids,
) )
class IconUpdateOut(BaseModel):
icon_url: AnyHttpUrl = Field(
...,
description="URL to the uploaded icon",
examples=[f"{settings.OBJECT_GATEWAY_URI}{settings.ICON_BUCKET}/{uuid4().hex}.png"],
)
...@@ -290,7 +290,36 @@ class TestWorkflowCredentialsRoutesDelete(_TestWorkflowCredentialRoutes): ...@@ -290,7 +290,36 @@ class TestWorkflowCredentialsRoutesDelete(_TestWorkflowCredentialRoutes):
class TestWorkflowCredentialsRoutesGet(_TestWorkflowCredentialRoutes): class TestWorkflowCredentialsRoutesGet(_TestWorkflowCredentialRoutes):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_get_workflow_credentials( async def test_get_workflow_credentials_of_public_workflow(
self,
db: AsyncSession,
client: AsyncClient,
random_user: UserWithAuthHeader,
random_workflow: WorkflowOut,
) -> None:
"""
Test for getting the credentials of a public workflow as the developer.
Parameters
----------
db : sqlalchemy.ext.asyncio.AsyncSession.
Async database session to perform query on.
client : httpx.AsyncClient
HTTP Client to perform the request on.
random_user : app.tests.utils.user.UserWithAuthHeader
Random user for testing.
random_workflow : app.schemas.workflow.WorkflowOut
Random workflow for testing.
"""
response = await client.get(
"/".join([self.base_path, str(random_workflow.workflow_id), "credentials"]),
headers=random_user.auth_headers,
)
assert response.status_code == status.HTTP_200_OK
assert response.json()["token"] is None
@pytest.mark.asyncio
async def test_get_workflow_credentials_of_private_workflow(
self, self,
db: AsyncSession, db: AsyncSession,
client: AsyncClient, client: AsyncClient,
...@@ -298,7 +327,7 @@ class TestWorkflowCredentialsRoutesGet(_TestWorkflowCredentialRoutes): ...@@ -298,7 +327,7 @@ class TestWorkflowCredentialsRoutesGet(_TestWorkflowCredentialRoutes):
random_private_workflow: WorkflowOut, random_private_workflow: WorkflowOut,
) -> None: ) -> None:
""" """
Test for getting the credentials on a workflow as the developer. Test for getting the credentials of a private workflow as the developer.
Parameters Parameters
---------- ----------
......
...@@ -380,7 +380,7 @@ class TestWorkflowVersionIconRoutes(_TestWorkflowVersionRoutes): ...@@ -380,7 +380,7 @@ class TestWorkflowVersionIconRoutes(_TestWorkflowVersionRoutes):
files=files, files=files,
) )
assert response.status_code == status.HTTP_201_CREATED assert response.status_code == status.HTTP_201_CREATED
icon_url = response.json() icon_url = response.json()["icon_url"]
icon_slug = icon_url.split("/")[-1] icon_slug = icon_url.split("/")[-1]
assert icon_slug in mock_s3_service.Bucket(settings.ICON_BUCKET).objects.all_keys() assert icon_slug in mock_s3_service.Bucket(settings.ICON_BUCKET).objects.all_keys()
db_version = await db.scalar( db_version = await db.scalar(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment