Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GET specific template version #2802

Merged
merged 9 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ENHANCEMENTS:
* Renamed several airlock fields to make them more descriptive and added a createdBy field. Included migration for backwards compatibility ([#2779](https://github.com/microsoft/AzureTRE/pull/2779))
* Show error message when Review VMs are not configured in the current workspace
* CLI: Add missing endpoints and minor bug fixes (#2784)
* Added optional parameter to allow a client to retrieve a template by name and version ([#2802](https://github.com/microsoft/AzureTRE/pull/2802))

BUG FIXES:
* Show the correct createdBy value for airlock requests in UI and in API queries ([#2779](https://github.com/microsoft/AzureTRE/pull/2779))
Expand Down
2 changes: 1 addition & 1 deletion api_app/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.9"
damoodamoo marked this conversation as resolved.
Show resolved Hide resolved
__version__ = "0.5.10"
6 changes: 4 additions & 2 deletions api_app/api/routes/resource_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ async def send_custom_action_message(resource: Resource, resource_repo: Resource
raise HTTPException(status_code=status.HTTP_503_SERVICE_UNAVAILABLE, detail=strings.SERVICE_BUS_GENERAL_ERROR_MESSAGE)


def get_current_template_by_name(template_name: str, template_repo: ResourceTemplateRepository, resource_type: ResourceType, parent_service_template_name: str = "", is_update: bool = False) -> dict:
def get_template(template_name: str, template_repo: ResourceTemplateRepository, resource_type: ResourceType, parent_service_template_name: str = "", is_update: bool = False, version: str = None) -> dict:
try:
template = template_repo.get_current_template(template_name, resource_type, parent_service_template_name)
template = template_repo.get_template_by_name_and_version(template_name, version, resource_type, parent_service_template_name) if version \
else template_repo.get_current_template(template_name, resource_type, parent_service_template_name)

return template_repo.enrich_template(template, is_update=is_update)
except EntityDoesNotExist:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=strings.TEMPLATE_DOES_NOT_EXIST)
Expand Down
6 changes: 3 additions & 3 deletions api_app/api/routes/shared_service_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from models.schemas.shared_service_template import SharedServiceTemplateInCreate, SharedServiceTemplateInResponse
from resources import strings
from services.authentication import get_current_admin_user, get_current_tre_user_or_tre_admin
from .resource_helpers import get_current_template_by_name
from api.routes.resource_helpers import get_template


shared_service_templates_core_router = APIRouter(dependencies=[Depends(get_current_tre_user_or_tre_admin)])
Expand All @@ -22,9 +22,9 @@ async def get_shared_service_templates(authorized_only: bool = False, template_r


@shared_service_templates_core_router.get("/shared-service-templates/{shared_service_template_name}", response_model=SharedServiceTemplateInResponse, response_model_exclude_none=True, name=strings.API_GET_SHARED_SERVICE_TEMPLATE_BY_NAME, dependencies=[Depends(get_current_tre_user_or_tre_admin)])
async def get_current_shared_service_template_by_name(shared_service_template_name: str, is_update: bool = False, template_repo=Depends(get_repository(ResourceTemplateRepository))) -> SharedServiceTemplateInResponse:
async def get_shared_service_template(shared_service_template_name: str, is_update: bool = False, version: str = None, template_repo=Depends(get_repository(ResourceTemplateRepository))) -> SharedServiceTemplateInResponse:
try:
template = get_current_template_by_name(shared_service_template_name, template_repo, ResourceType.SharedService, is_update=is_update)
template = get_template(shared_service_template_name, template_repo, ResourceType.SharedService, is_update=is_update, version=version)
return parse_obj_as(SharedServiceTemplateInResponse, template)
except EntityDoesNotExist:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=strings.SHARED_SERVICE_TEMPLATE_DOES_NOT_EXIST)
Expand Down
6 changes: 3 additions & 3 deletions api_app/api/routes/user_resource_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from api.dependencies.database import get_repository
from api.dependencies.workspace_service_templates import get_workspace_service_template_by_name_from_path
from api.routes.workspace_templates import get_current_template_by_name
from api.routes.resource_helpers import get_template
from db.errors import EntityVersionExist
from db.repositories.resource_templates import ResourceTemplateRepository
from models.domain.resource import ResourceType
Expand All @@ -24,8 +24,8 @@ async def get_user_resource_templates_for_service_template(service_template_name


@user_resource_templates_core_router.get("/workspace-service-templates/{service_template_name}/user-resource-templates/{user_resource_template_name}", response_model=UserResourceTemplateInResponse, response_model_exclude_none=True, name=strings.API_GET_USER_RESOURCE_TEMPLATE_BY_NAME, dependencies=[Depends(get_current_tre_user_or_tre_admin)])
async def get_current_user_resource_template_by_name(service_template_name: str, user_resource_template_name: str, is_update: bool = False, template_repo=Depends(get_repository(ResourceTemplateRepository))) -> UserResourceTemplateInResponse:
template = get_current_template_by_name(user_resource_template_name, template_repo, ResourceType.UserResource, service_template_name, is_update=is_update)
async def get_user_resource_template(service_template_name: str, user_resource_template_name: str, is_update: bool = False, version: str = None, template_repo=Depends(get_repository(ResourceTemplateRepository))) -> UserResourceTemplateInResponse:
template = get_template(user_resource_template_name, template_repo, ResourceType.UserResource, service_template_name, is_update=is_update, version=version)
return parse_obj_as(UserResourceTemplateInResponse, template)


Expand Down
6 changes: 3 additions & 3 deletions api_app/api/routes/workspace_service_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pydantic import parse_obj_as

from api.dependencies.database import get_repository
from api.routes.workspace_templates import get_current_template_by_name
from api.routes.resource_helpers import get_template
from db.errors import EntityVersionExist
from db.repositories.resource_templates import ResourceTemplateRepository
from models.domain.resource import ResourceType
Expand All @@ -22,8 +22,8 @@ async def get_workspace_service_templates(template_repo=Depends(get_repository(R


@workspace_service_templates_core_router.get("/workspace-service-templates/{service_template_name}", response_model=WorkspaceServiceTemplateInResponse, response_model_exclude_none=True, name=strings.API_GET_WORKSPACE_SERVICE_TEMPLATE_BY_NAME, dependencies=[Depends(get_current_tre_user_or_tre_admin)])
async def get_current_workspace_service_template_by_name(service_template_name: str, is_update: bool = False, template_repo=Depends(get_repository(ResourceTemplateRepository))) -> WorkspaceServiceTemplateInResponse:
template = get_current_template_by_name(service_template_name, template_repo, ResourceType.WorkspaceService, is_update=is_update)
async def get_workspace_service_template(service_template_name: str, is_update: bool = False, version: str = None, template_repo=Depends(get_repository(ResourceTemplateRepository))) -> WorkspaceServiceTemplateInResponse:
template = get_template(service_template_name, template_repo, ResourceType.WorkspaceService, is_update=is_update, version=version)
return parse_obj_as(WorkspaceServiceTemplateInResponse, template)


Expand Down
14 changes: 7 additions & 7 deletions api_app/api/routes/workspace_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@
from models.schemas.resource_template import ResourceTemplateInResponse, ResourceTemplateInformationInList
from models.schemas.workspace_template import WorkspaceTemplateInCreate, WorkspaceTemplateInResponse
from resources import strings
from services.authentication import get_current_tre_user_or_tre_admin, get_current_admin_user
from .resource_helpers import get_current_template_by_name
from services.authentication import get_current_admin_user
from api.routes.resource_helpers import get_template


workspace_templates_admin_router = APIRouter(dependencies=[Depends(get_current_tre_user_or_tre_admin)])
workspace_templates_admin_router = APIRouter(dependencies=[Depends(get_current_admin_user)])


@workspace_templates_admin_router.get("/workspace-templates", response_model=ResourceTemplateInformationInList, name=strings.API_GET_WORKSPACE_TEMPLATES)
async def get_workspace_templates(authorized_only: bool = False, template_repo=Depends(get_repository(ResourceTemplateRepository)), user=Depends(get_current_tre_user_or_tre_admin)) -> ResourceTemplateInformationInList:
async def get_workspace_templates(authorized_only: bool = False, template_repo=Depends(get_repository(ResourceTemplateRepository)), user=Depends(get_current_admin_user)) -> ResourceTemplateInformationInList:
templates_infos = template_repo.get_templates_information(ResourceType.Workspace, user.roles if authorized_only else None)
return ResourceTemplateInformationInList(templates=templates_infos)


@workspace_templates_admin_router.get("/workspace-templates/{workspace_template_name}", response_model=WorkspaceTemplateInResponse, name=strings.API_GET_WORKSPACE_TEMPLATE_BY_NAME, response_model_exclude_none=True)
async def get_current_workspace_template_by_name(workspace_template_name: str, is_update: bool = False, template_repo=Depends(get_repository(ResourceTemplateRepository)), user=Depends(get_current_tre_user_or_tre_admin)) -> WorkspaceTemplateInResponse:
template = get_current_template_by_name(workspace_template_name, template_repo, ResourceType.Workspace, is_update=is_update)
async def get_workspace_template(workspace_template_name: str, is_update: bool = False, version: str = None, template_repo=Depends(get_repository(ResourceTemplateRepository))) -> WorkspaceTemplateInResponse:
template = get_template(workspace_template_name, template_repo, ResourceType.Workspace, is_update=is_update, version=version)
return parse_obj_as(WorkspaceTemplateInResponse, template)


@workspace_templates_admin_router.post("/workspace-templates", status_code=status.HTTP_201_CREATED, response_model=WorkspaceTemplateInResponse, response_model_exclude_none=True, name=strings.API_CREATE_WORKSPACE_TEMPLATES)
async def register_workspace_template(template_input: WorkspaceTemplateInCreate, template_repo=Depends(get_repository(ResourceTemplateRepository)), user=Depends(get_current_admin_user)) -> ResourceTemplateInResponse:
async def register_workspace_template(template_input: WorkspaceTemplateInCreate, template_repo=Depends(get_repository(ResourceTemplateRepository))) -> ResourceTemplateInResponse:
try:
return template_repo.create_and_validate_template(template_input, ResourceType.Workspace)
except EntityVersionExist:
Expand Down
10 changes: 5 additions & 5 deletions api_app/resources/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@

API_CREATE_WORKSPACE_TEMPLATES = "Register workspace template"
API_GET_WORKSPACE_TEMPLATES = "Get workspace templates"
API_GET_WORKSPACE_TEMPLATE_BY_NAME = "Get workspace template by name"
API_GET_WORKSPACE_TEMPLATE_BY_NAME = "Get workspace template by name and optional version"

API_CREATE_WORKSPACE_SERVICE_TEMPLATES = "Register workspace service template"
API_GET_WORKSPACE_SERVICE_TEMPLATES = "Get workspace service templates"
API_GET_WORKSPACE_SERVICE_TEMPLATES_IN_WORKSPACE = "Get workspace service templates (on workspace level)" # only returns templates that the authenticated user is authorized to use
API_GET_WORKSPACE_SERVICE_TEMPLATE_BY_NAME = "Get workspace service template by name"
API_GET_WORKSPACE_SERVICE_TEMPLATE_BY_NAME = "Get workspace service template by name and optional version"

API_CREATE_SHARED_SERVICE_TEMPLATES = "Register shared service template"
API_GET_SHARED_SERVICE_TEMPLATES = "Get shared service templates"
API_GET_SHARED_SERVICE_TEMPLATE_BY_NAME = "Get shared service template by name"
API_GET_SHARED_SERVICE_TEMPLATE_BY_NAME = "Get shared service template by name and optional version"

API_GET_ALL_SHARED_SERVICES = "Get all shared services"
API_GET_SHARED_SERVICE_BY_ID = "Get shared service by ID"
Expand All @@ -63,7 +63,7 @@
API_CREATE_USER_RESOURCE_TEMPLATES = "Register user resource template"
API_GET_USER_RESOURCE_TEMPLATES = "Get user resource templates applicable to the workspace service template"
API_GET_USER_RESOURCE_TEMPLATES_IN_WORKSPACE = "Get user resource templates applicable to the workspace service template (on workspace level)" # only returns templates that the authenticated user is authorized to use
API_GET_USER_RESOURCE_TEMPLATE_BY_NAME = "Get user resource template by name and workspace service"
API_GET_USER_RESOURCE_TEMPLATE_BY_NAME = "Get user resource template by name and workspace service and optional version"

# cost report
API_GET_COSTS = "Get overall costs"
Expand Down Expand Up @@ -132,7 +132,7 @@
CUSTOM_ACTIONS_DO_NOT_EXIST = "The resource being targeted does not implement any custom actions."

WORKSPACE_SERVICE_TEMPLATE_DOES_NOT_EXIST = "Could not retrieve the workspace service template specified"
TEMPLATE_DOES_NOT_EXIST = "Could not retrieve the 'current' template with this name"
TEMPLATE_DOES_NOT_EXIST = "Could not retrieve the template with this name, or name-version pair"
NO_UNIQUE_CURRENT_FOR_TEMPLATE = "The template has multiple 'current' versions"

SHARED_SERVICE_DOES_NOT_EXIST = "Shared service does not exist"
Expand Down
4 changes: 2 additions & 2 deletions api_app/service_bus/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def update_resource_for_step(operation_step: OperationStep, resource_repo: Resou
if primary_resource.resourceType == ResourceType.UserResource:
primary_parent_workspace_service = resource_repo.get_resource_by_id(primary_resource.parentWorkspaceServiceId)
primary_parent_service_name = primary_parent_workspace_service.templateName
primary_template = resource_template_repo.get_current_template(primary_resource.templateName, primary_resource.resourceType, primary_parent_service_name)
primary_template = resource_template_repo.get_template_by_name_and_version(primary_resource.templateName, primary_resource.templateVersion, primary_resource.resourceType, primary_parent_service_name)

# get the template step
template_step = None
Expand Down Expand Up @@ -117,7 +117,7 @@ def try_upgrade(resource_repo: ResourceRepository, resource_template_repo: Resou
if resource_to_update.resourceType == ResourceType.UserResource:
parent_service_name = resource_to_update["parentWorkspaceServiceId"]

resource_template_to_send = resource_template_repo.get_current_template(resource_to_update.templateName, resource_to_update.resourceType, parent_service_name)
resource_template_to_send = resource_template_repo.get_template_by_name_and_version(resource_to_update.templateName, resource_to_update.templateVersion, resource_to_update.resourceType, parent_service_name)

# create the patch
patch = ResourcePatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async def test_multi_step_document_sends_first_step(
temp_workspace_service,
basic_shared_service,
]
resource_template_repo.get_current_template.side_effect = [
resource_template_repo.get_template_by_name_and_version.side_effect = [
multi_step_resource_template,
basic_shared_service_template,
]
Expand Down