Skip to content

Commit

Permalink
Merge branch 'main' into tborisova/1830-enable-purge-protection-2
Browse files Browse the repository at this point in the history
  • Loading branch information
tanya-borisova committed Jun 13, 2022
2 parents a6f39bc + 2336cab commit 2b169cd
Show file tree
Hide file tree
Showing 27 changed files with 540 additions and 155 deletions.
108 changes: 0 additions & 108 deletions .github/workflows/e2e.yml

This file was deleted.

79 changes: 39 additions & 40 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ FULL_IMAGE_NAME_PREFIX:=`echo "${FULL_CONTAINER_REGISTRY_NAME}/${IMAGE_NAME_PREF
target_title = @echo -e "\n\e[34m»»» 🧩 \e[96m$(1)\e[0m..."

all: bootstrap mgmt-deploy images tre-deploy
images: build-and-push-api build-and-push-resource-processor build-and-push-gitea build-and-push-guacamole build-and-push-mlflow build-and-push-airlock-processor
tre-deploy: deploy-core build-and-deploy-ui deploy-shared-services db-migrate show-core-output

images: build-and-push-api build-and-push-resource-processor build-and-push-gitea build-and-push-guacamole build-and-push-mlflow build-and-push-airlock-processor
build-and-push-api: build-api-image push-api-image
build-and-push-resource-processor: build-resource-processor-vm-porter-image push-resource-processor-vm-porter-image
build-and-push-gitea: build-gitea-image push-gitea-image
build-and-push-guacamole: build-guacamole-image push-guacamole-image
build-and-push-mlflow: build-mlflow-image push-mlflow-image
tre-deploy: deploy-core build-and-deploy-ui deploy-shared-services db-migrate show-core-output
build-and-push-airlock-processor: build-airlock-processor push-airlock-processor
deploy-shared-services:
$(MAKE) firewall-install \
&& . ./devops/scripts/load_env.sh ./templates/core/.env \

deploy-shared-services: firewall-install
. ${MAKEFILE_DIR}/devops/scripts/load_env.sh ./templates/core/.env \
&& if [ "$${DEPLOY_GITEA}" == "true" ]; then $(MAKE) gitea-install; fi \
&& if [ "$${DEPLOY_NEXUS}" == "true" ]; then $(MAKE) nexus-install; fi

Expand Down Expand Up @@ -92,24 +92,6 @@ build-mlflow-image:
build-airlock-processor:
$(call build_image,"airlock-processor","${MAKEFILE_DIR}/airlock_processor/_version.py","${MAKEFILE_DIR}/airlock_processor/Dockerfile","${MAKEFILE_DIR}/airlock_processor/")

firewall-install:
$(MAKE) bundle-build DIR=${MAKEFILE_DIR}/templates/shared_services/firewall/ \
&& $(MAKE) bundle-publish DIR=${MAKEFILE_DIR}/templates/shared_services/firewall/ \
&& $(MAKE) bundle-register DIR="${MAKEFILE_DIR}/templates/shared_services/firewall" BUNDLE_TYPE=shared_service \
&& $(MAKE) deploy-shared-service DIR=${MAKEFILE_DIR}/templates/shared_services/firewall/ BUNDLE_TYPE=shared_service

nexus-install:
$(MAKE) bundle-build DIR=${MAKEFILE_DIR}/templates/shared_services/sonatype-nexus/ \
&& $(MAKE) bundle-publish DIR=${MAKEFILE_DIR}/templates/shared_services/sonatype-nexus/ \
&& $(MAKE) bundle-register DIR="${MAKEFILE_DIR}/templates/shared_services/sonatype-nexus" BUNDLE_TYPE=shared_service \
&& $(MAKE) deploy-shared-service DIR=${MAKEFILE_DIR}/templates/shared_services/sonatype-nexus/ BUNDLE_TYPE=shared_service

gitea-install:
$(MAKE) bundle-build DIR=${MAKEFILE_DIR}/templates/shared_services/gitea/ \
&& $(MAKE) bundle-publish DIR=${MAKEFILE_DIR}/templates/shared_services/gitea/ \
&& $(MAKE) bundle-register DIR="${MAKEFILE_DIR}/templates/shared_services/gitea" BUNDLE_TYPE=shared_service \
&& $(MAKE) deploy-shared-service DIR=${MAKEFILE_DIR}/templates/shared_services/gitea/ BUNDLE_TYPE=shared_service

# A recipe for pushing images. Parameters:
# 1. Image name suffix
# 2. Version file path
Expand Down Expand Up @@ -176,7 +158,7 @@ letsencrypt:
&& . ${MAKEFILE_DIR}/devops/scripts/load_terraform_env.sh ./devops/.env \
&& . ${MAKEFILE_DIR}/devops/scripts/load_terraform_env.sh ./templates/core/.env \
&& pushd ${MAKEFILE_DIR}/templates/core/terraform/ > /dev/null && . ./outputs.sh && popd > /dev/null \
&& . ${MAKEFILE_DIR}/devops/scripts/load_env.sh ./templates/core/private.env \
&& . ${MAKEFILE_DIR}/devops/scripts/load_env.sh ${MAKEFILE_DIR}/templates/core/private.env \
&& ${MAKEFILE_DIR}/templates/core/terraform/scripts/letsencrypt.sh

tre-start:
Expand Down Expand Up @@ -332,22 +314,21 @@ bundle-register:
&& cd ${DIR} \
&& ${MAKEFILE_DIR}/devops/scripts/register_bundle_with_api.sh --acr-name "$${ACR_NAME}" --bundle-type "$${BUNDLE_TYPE}" --current --insecure --tre_url "$${TRE_URL:-https://$${TRE_ID}.$${LOCATION}.cloudapp.azure.com}" --verify --workspace-service-name "$${WORKSPACE_SERVICE_NAME}"

workspace_bundle = $(MAKE) bundle-build DIR=./templates/workspaces/$(1)/ \
&& $(MAKE) bundle-publish DIR=./templates/workspaces/$(1)/ \
&& $(MAKE) bundle-register DIR="./templates/workspaces/$(1)" BUNDLE_TYPE=workspace

workspace_service_bundle = $(MAKE) bundle-build DIR=./templates/workspace_services/$(1)/ \
&& $(MAKE) bundle-publish DIR=./templates/workspace_services/$(1)/ \
&& $(MAKE) bundle-register DIR="./templates/workspace_services/$(1)" BUNDLE_TYPE=workspace_service
workspace_bundle = $(MAKE) bundle-build DIR=${MAKEFILE_DIR}/templates/workspaces/$(1)/ \
&& $(MAKE) bundle-publish DIR=${MAKEFILE_DIR}/templates/workspaces/$(1)/ \
&& $(MAKE) bundle-register DIR="${MAKEFILE_DIR}/templates/workspaces/$(1)" BUNDLE_TYPE=workspace

shared_service_bundle = $(MAKE) bundle-build DIR=./templates/shared_services/$(1)/ \
&& $(MAKE) bundle-publish DIR=./templates/shared_services/$(1)/ \
&& $(MAKE) bundle-register DIR="./templates/shared_services/$(1)" BUNDLE_TYPE=shared_service
workspace_service_bundle = $(MAKE) bundle-build DIR=${MAKEFILE_DIR}/templates/workspace_services/$(1)/ \
&& $(MAKE) bundle-publish DIR=${MAKEFILE_DIR}/templates/workspace_services/$(1)/ \
&& $(MAKE) bundle-register DIR="${MAKEFILE_DIR}/templates/workspace_services/$(1)" BUNDLE_TYPE=workspace_service

user_resource_bundle = $(MAKE) bundle-build DIR=./templates/workspace_services/$(1)/user_resources/$(2)/ \
&& $(MAKE) bundle-publish DIR=./templates/workspace_services/$(1)/user_resources/$(2) \
&& $(MAKE) bundle-register DIR="./templates/workspace_services/$(1)/user_resources/$(2)" BUNDLE_TYPE=user_resource WORKSPACE_SERVICE_NAME=tre-service-$(1)
shared_service_bundle = $(MAKE) bundle-build DIR=${MAKEFILE_DIR}/templates/shared_services/$(1)/ \
&& $(MAKE) bundle-publish DIR=${MAKEFILE_DIR}/templates/shared_services/$(1)/ \
&& $(MAKE) bundle-register DIR="${MAKEFILE_DIR}/templates/shared_services/$(1)" BUNDLE_TYPE=shared_service

user_resource_bundle = $(MAKE) bundle-build DIR=${MAKEFILE_DIR}/templates/workspace_services/$(1)/user_resources/$(2)/ \
&& $(MAKE) bundle-publish DIR=${MAKEFILE_DIR}/templates/workspace_services/$(1)/user_resources/$(2) \
&& $(MAKE) bundle-register DIR="${MAKEFILE_DIR}/templates/workspace_services/$(1)/user_resources/$(2)" BUNDLE_TYPE=user_resource WORKSPACE_SERVICE_NAME=tre-service-$(1)

deploy-shared-service:
@# NOTE: ACR_NAME below comes from the env files, so needs the double '$$'. Others are set on command execution and don't
Expand All @@ -359,6 +340,24 @@ deploy-shared-service:
&& cd ${DIR} \
&& ${MAKEFILE_DIR}/devops/scripts/deploy_shared_service.sh --insecure --tre_url "$${TRE_URL:-https://$${TRE_ID}.$${LOCATION}.cloudapp.azure.com}"

firewall-install:
$(MAKE) bundle-build DIR=${MAKEFILE_DIR}/templates/shared_services/firewall/ \
&& $(MAKE) bundle-publish DIR=${MAKEFILE_DIR}/templates/shared_services/firewall/ \
&& $(MAKE) bundle-register DIR="${MAKEFILE_DIR}/templates/shared_services/firewall" BUNDLE_TYPE=shared_service \
&& $(MAKE) deploy-shared-service DIR=${MAKEFILE_DIR}/templates/shared_services/firewall/ BUNDLE_TYPE=shared_service

nexus-install:
$(MAKE) bundle-build DIR=${MAKEFILE_DIR}/templates/shared_services/sonatype-nexus/ \
&& $(MAKE) bundle-publish DIR=${MAKEFILE_DIR}/templates/shared_services/sonatype-nexus/ \
&& $(MAKE) bundle-register DIR="${MAKEFILE_DIR}/templates/shared_services/sonatype-nexus" BUNDLE_TYPE=shared_service \
&& $(MAKE) deploy-shared-service DIR=${MAKEFILE_DIR}/templates/shared_services/sonatype-nexus/ BUNDLE_TYPE=shared_service

gitea-install:
$(MAKE) bundle-build DIR=${MAKEFILE_DIR}/templates/shared_services/gitea/ \
&& $(MAKE) bundle-publish DIR=${MAKEFILE_DIR}/templates/shared_services/gitea/ \
&& $(MAKE) bundle-register DIR="${MAKEFILE_DIR}/templates/shared_services/gitea" BUNDLE_TYPE=shared_service \
&& $(MAKE) deploy-shared-service DIR=${MAKEFILE_DIR}/templates/shared_services/gitea/ BUNDLE_TYPE=shared_service

temp-do-upload:
$(MAKE) static-web-upload DIR=${MAKEFILE_DIR}/dummy

Expand Down Expand Up @@ -423,7 +422,7 @@ setup-local-debugging:
&& . ${MAKEFILE_DIR}/devops/scripts/load_env.sh ./templates/core/.env \
&& . ${MAKEFILE_DIR}/devops/scripts/load_env.sh ./devops/.env \
&& pushd ${MAKEFILE_DIR}/templates/core/terraform/ > /dev/null && . ./outputs.sh && popd > /dev/null \
&& . ${MAKEFILE_DIR}/devops/scripts/load_env.sh ./templates/core/private.env \
&& . ${MAKEFILE_DIR}/devops/scripts/load_env.sh ${MAKEFILE_DIR}/templates/core/private.env \
&& . ${MAKEFILE_DIR}/scripts/setup_local_debugging.sh

auth:
Expand All @@ -442,13 +441,13 @@ api-healthcheck:
&& . ${MAKEFILE_DIR}/devops/scripts/check_dependencies.sh nodocker \
&& . ${MAKEFILE_DIR}/devops/scripts/load_env.sh ./templates/core/.env \
&& . ${MAKEFILE_DIR}/devops/scripts/load_env.sh ./devops/.env \
&& . ${MAKEFILE_DIR}/devops/scripts/load_env.sh ./templates/core/private.env \
&& . ${MAKEFILE_DIR}/devops/scripts/load_env.sh ${MAKEFILE_DIR}/templates/core/private.env \
&& ${MAKEFILE_DIR}/devops/scripts/api_healthcheck.sh

db-migrate:
$(call target_title,"Migrating Cosmos Data") \
&& . ${MAKEFILE_DIR}/devops/scripts/check_dependencies.sh nodocker \
&& pushd ${MAKEFILE_DIR}/templates/core/terraform/ > /dev/null && . ./outputs.sh && popd > /dev/null \
&& . ${MAKEFILE_DIR}/devops/scripts/load_env.sh ./templates/core/.env \
&& . ${MAKEFILE_DIR}/devops/scripts/load_env.sh ./templates/core/private.env \
&& . ${MAKEFILE_DIR}/devops/scripts/load_env.sh ${MAKEFILE_DIR}/templates/core/private.env \
&& python ${MAKEFILE_DIR}/scripts/db_migrations.py
5 changes: 5 additions & 0 deletions api_app/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ SERVICE_BUS_FULLY_QUALIFIED_NAMESPACE=__CHANGE_ME__
SERVICE_BUS_RESOURCE_REQUEST_QUEUE=workspacequeue
SERVICE_BUS_DEPLOYMENT_STATUS_UPDATE_QUEUE=deploymentstatus

# Event grid configuration
# -------------------------
EVENT_GRID_TOPIC_ENDPOINT=__CHANGE_ME__
EVENT_GRID_ACCESS_KEY=__CHANGE_ME__

# Logging and monitoring
# ----------------------
# Application Insights connection string - can be left blank when debugging locally
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.3.8"
__version__ = "0.3.9"
19 changes: 19 additions & 0 deletions api_app/api/dependencies/airlock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from fastapi import Depends, HTTPException, Path, status
from pydantic import UUID4

from api.dependencies.database import get_repository
from db.repositories.airlock_requests import AirlockRequestRepository
from models.domain.airlock_request import AirlockRequest
from db.errors import EntityDoesNotExist
from resources import strings


def get_airlock_request_by_id(airlock_request_id: UUID4, airlock_request_repo: AirlockRequestRepository) -> AirlockRequest:
try:
return airlock_request_repo.get_airlock_request_by_id(airlock_request_id)
except EntityDoesNotExist:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=strings.AIRLOCK_REQUEST_DOES_NOT_EXIST)


async def get_airlock_request_by_id_from_path(airlock_request_id: UUID4 = Path(...), airlock_request_repo=Depends(get_repository(AirlockRequestRepository))) -> AirlockRequest:
return get_airlock_request_by_id(airlock_request_id, airlock_request_repo)
37 changes: 37 additions & 0 deletions api_app/api/routes/airlock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import logging

from fastapi import APIRouter, Depends, HTTPException, status

from jsonschema.exceptions import ValidationError

from api.dependencies.database import get_repository
from api.dependencies.workspaces import get_workspace_by_id_from_path, get_deployed_workspace_by_id_from_path
from api.dependencies.airlock import get_airlock_request_by_id_from_path
from models.domain.airlock_resource import AirlockRequestStatus

from db.repositories.airlock_requests import AirlockRequestRepository
from models.schemas.airlock_request import AirlockRequestInCreate, AirlockRequestInResponse
from resources import strings
from services.authentication import get_current_workspace_owner_or_researcher_user

from .airlock_resource_helpers import save_and_publish_event_airlock_request, update_status_and_publish_event_airlock_request

airlock_workspace_router = APIRouter(dependencies=[Depends(get_current_workspace_owner_or_researcher_user)])


# airlock
@airlock_workspace_router.post("/workspaces/{workspace_id}/requests", status_code=status.HTTP_201_CREATED, response_model=AirlockRequestInResponse, name=strings.API_CREATE_AIRLOCK_REQUEST, dependencies=[Depends(get_workspace_by_id_from_path)])
async def create_draft_request(airlock_request_input: AirlockRequestInCreate, user=Depends(get_current_workspace_owner_or_researcher_user), airlock_request_repo=Depends(get_repository(AirlockRequestRepository)), workspace=Depends(get_deployed_workspace_by_id_from_path)) -> AirlockRequestInResponse:
try:
airlock_request = airlock_request_repo.create_airlock_request_item(airlock_request_input, workspace.id)
except (ValidationError, ValueError) as e:
logging.error(f"Failed create air lock request model instance: {e}")
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e))
await save_and_publish_event_airlock_request(airlock_request, airlock_request_repo, user)
return AirlockRequestInResponse(airlock_request=airlock_request)


@airlock_workspace_router.post("/workspaces/{workspace_id}/requests/{airlock_request_id}/submit", status_code=status.HTTP_200_OK, response_model=AirlockRequestInResponse, name=strings.API_SUBMIT_AIRLOCK_REQUEST, dependencies=[Depends(get_workspace_by_id_from_path)])
async def create_submit_request(airlock_request=Depends(get_airlock_request_by_id_from_path), user=Depends(get_current_workspace_owner_or_researcher_user), airlock_request_repo=Depends(get_repository(AirlockRequestRepository))) -> AirlockRequestInResponse:
updated_resource = await update_status_and_publish_event_airlock_request(airlock_request, airlock_request_repo, user, AirlockRequestStatus.Submitted)
return AirlockRequestInResponse(airlock_request=updated_resource)
Loading

0 comments on commit 2b169cd

Please sign in to comment.