Skip to content

Commit

Permalink
Merge branch 'qa/v2.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
brouillette committed Sep 20, 2021
2 parents 7a64b6d + c4dd9ce commit f49ee9c
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 72 deletions.
17 changes: 5 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ build-gateway: stop-gateway clean-gateway
echo "-- Building Gateway Container --"
docker-compose -f docker-compose.yaml build gateway

build-api-go-alpine-binaries:
build-api-binaries:
@echo "-- Building Golang-Api-Alpine Binaries --"

cd src/api && \
Expand All @@ -55,10 +55,10 @@ build-api-go-alpine-binaries:
cd ../.. && \
upx --brute bin/api_${GOOS}_${GOARCH}

build-api-go-alpine-container: stop-api-go-alpine clean-api-go-alpine build-api-go-alpine-binaries
build-api-container: stop-api clean-api build-api-binaries
@echo "-- Building Golang-Api-Alpine Container --"
cp bin/api_${GOOS}_${GOARCH} src/api
docker-compose -f docker-compose.yaml build api-go-alpine
docker-compose -f docker-compose.yaml build api
rm src/api/api_${GOOS}_${GOARCH}

build-drs: stop-drs clean-drs
Expand Down Expand Up @@ -86,15 +86,7 @@ clean-gateway:
docker rm ${GOHAN_GATEWAY_CONTAINER_NAME} --force; \
docker rmi ${GOHAN_GATEWAY_IMAGE}:${GOHAN_GATEWAY_VERSION} --force;

# clean-api:
# docker rm ${GOHAN_API_CONTAINER_NAME} --force; \
# docker rmi ${GOHAN_API_IMAGE}:${GOHAN_API_VERSION} --force;

# clean-api-alpine:
# docker rm ${GOHAN_API_CONTAINER_NAME} --force; \
# docker rmi ${GOHAN_API_IMAGE}:${GOHAN_API_VERSION} --force;

clean-api-go-alpine:
clean-api:
rm -f bin/api_${GOOS}_${GOARCH}
docker rm ${GOHAN_API_CONTAINER_NAME} --force; \
docker rmi ${GOHAN_API_IMAGE}:${GOHAN_API_VERSION} --force;
Expand All @@ -108,6 +100,7 @@ clean-authz:
docker rmi ${GOHAN_AUTHZ_OPA_IMAGE}:${GOHAN_AUTHZ_OPA_IMAGE_VERSION} --force;



## -- WARNING: DELETES ALL LOCAL ELASTICSEARCH DATA
clean-elastic-data:
docker-compose -f docker-compose.yaml down
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ Local Release:
 From the project root, run
```
make build-api-go-alpine-binaries
make build-api-binaries
```
Expand Down Expand Up @@ -427,8 +427,8 @@ Containerized Alpine Release:
 When ready, build the `docker image` and spawn the `container` by running
```
make build-api-go-alpine-container
make run-api-go-alpine
make build-api-container
make run-api
```
 and the `docker-compose.yaml` file will handle the configuration.
Expand All @@ -445,7 +445,7 @@ All in all, run
make run-elasticsearch
make run-drs
make build-gateway && make run-gateway
make build-api-go-alpine && make run-api-go-alpine
make build-api && make run-api

# and optionally
make run-kibana
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.dev.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
version: '2.4'

services:
api-go-alpine:
api:
ports:
- "${GOHAN_API_EXTERNAL_PORT}:${GOHAN_API_INTERNAL_PORT}"
extends:
file: docker-compose.yaml
service: api-go-alpine
service: api


elasticsearch:
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ services:
- "80:80"
- "443:443"

api-go-alpine:
api:
build:
context: $PWD/src/api
args:
BASE_IMAGE: ${GOHAN_API_ALPINE_BASE_IMAGE}
BASE_IMAGE: ${GOHAN_API_BASE_IMAGE}
API_EXECUTABLE_FILENAME: api_linux_amd64
# also passed in as an ENV from within Dockerfile :
GOHAN_API_INTERNAL_PORT: ${GOHAN_API_INTERNAL_PORT}
image: ${GOHAN_API_GO_IMAGE}:${GOHAN_API_GO_VERSION}
image: ${GOHAN_API_IMAGE}:${GOHAN_API_VERSION}
container_name: ${GOHAN_API_CONTAINER_NAME}
networks:
- bridge-net
Expand Down
15 changes: 2 additions & 13 deletions etc/example.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Gohan Environment Variables

GOHAN_SERVICES=gateway api-go-alpine elasticsearch kibana drs authorization
GOHAN_SERVICES=gateway api elasticsearch kibana drs authorization

# Host
GOHAN_PUBLIC_PROTO=https
Expand All @@ -26,14 +26,8 @@ GOHAN_GATEWAY_CONTAINER_NAME=gohan-gateway
GOHAN_API_IMAGE=gohan-api
GOHAN_API_VERSION=latest

GOHAN_API_GO_IMAGE=gohan-api
GOHAN_API_GO_VERSION=latest
GOHAN_API_BASE_IMAGE=alpine

GOHAN_API_BASE_IMAGE=mcr.microsoft.com/dotnet/aspnet:3.1.13-buster-slim
GOHAN_API_ALPINE_BASE_IMAGE=alpine

GOHAN_API_SRC_DIR=./bin/Release/netcoreapp3.1/linux-x64/publish
GOHAN_API_ALPINE_SRC_DIR=./bin/ReleaseAlpine/netcoreapp3.1/linux-musl-x64/publish
GOHAN_API_CONTAINER_NAME=gohan-api
GOHAN_API_SERVICE_HOST=0.0.0.0
GOHAN_API_EXTERNAL_PORT=5000
Expand All @@ -57,9 +51,6 @@ GOHAN_API_AUTHZ_REQHEADS=X-CUSTOM-1,X-CUSTOM-2
GOHAN_ES_USERNAME=elastic
GOHAN_ES_PASSWORD=changeme!

GOHAN_ES_PUBLIC_GATEWAY_PATH=/es
GOHAN_ES_GATEWAY_PATH=/

GOHAN_ES_BASE_IMAGE=elasticsearch
GOHAN_ES_BASE_VERSION=7.10.1
GOHAN_ES_CONTAINER_NAME=elasticsearch
Expand Down Expand Up @@ -108,8 +99,6 @@ GOHAN_DRS_BASIC_AUTH_PASSWORD=drspasswordchangeme!

GOHAN_DRS_DATA_DIR=./data/drs

GOHAN_DRS_PUBLIC_GATEWAY_PATH=/drs



# AUTHORIZATION
Expand Down
4 changes: 4 additions & 0 deletions src/api/middleware/calibratedBoundsMiddleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@ func MandateCalibratedBounds(next echo.HandlerFunc) echo.HandlerFunc {
upperBoundPointer *int
)

// check for a 'lowerBound' query paramter
lowerBoundQP := c.QueryParam("lowerBound")
if len(lowerBoundQP) > 0 {
// try to convert to an integer
lb, conversionErr := strconv.Atoi(lowerBoundQP)
if conversionErr == nil {
lowerBound = lb
lowerBoundPointer = &lowerBound
}
}

// check for an 'upperBoundQP' query paramter
upperBoundQP := c.QueryParam("upperBound")
if len(upperBoundQP) > 0 {
// try to convert to an integer
ub, conversionErr := strconv.Atoi(upperBoundQP)
if conversionErr == nil {
upperBound = ub
Expand Down
4 changes: 4 additions & 0 deletions src/api/middleware/chromosomeMiddleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"github.com/labstack/echo"
)

/*
Echo middleware to ensure a valid `chromosome` HTTP query parameter was provided
*/
func MandateChromosomeAttribute(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
// check for chromosome query parameter
Expand All @@ -16,6 +19,7 @@ func MandateChromosomeAttribute(next echo.HandlerFunc) echo.HandlerFunc {
return echo.NewHTTPError(http.StatusBadRequest, "Missing 'chromosome' query parameter for querying!")
}

// verify:
i, conversionErr := strconv.Atoi(chromQP)
if conversionErr != nil {
// if invalid chromosome
Expand Down
8 changes: 7 additions & 1 deletion src/api/middleware/genotypeMiddleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ import (
"github.com/labstack/echo"
)

/*
Echo middleware to ensure the validity of the optionally provided `genotype` HTTP query parameter
*/
func ValidatePotentialGenotypeQueryParameter(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
// check for a genotype query parameter
genotypeQP := c.QueryParam("genotype")

if len(genotypeQP) > 0 {
// validate that the genotype string
// converts to a valid GenotypeQuery
// (skips "UNCALLED" values)
_, genotypeErr := gq.CastToGenoType(genotypeQP)
if genotypeErr != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid genotype query %s, %s", genotypeQP, genotypeErr))
Expand Down
6 changes: 6 additions & 0 deletions src/api/middleware/sampleMiddleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"github.com/labstack/echo"
)

/*
Echo middleware to ensure a singular `id` HTTP query parameter was provided
*/
func MandateSampleIdsSingularAttribute(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
// check for id query parameter
Expand All @@ -20,6 +23,9 @@ func MandateSampleIdsSingularAttribute(next echo.HandlerFunc) echo.HandlerFunc {
}
}

/*
Echo middleware to ensure a pluralized `id` (spelled `ids`) HTTP query parameter was provided
*/
func MandateSampleIdsPluralAttribute(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
// check for id's query parameter
Expand Down
16 changes: 10 additions & 6 deletions src/api/models/constants/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package constants

type enumString string
type enumInt int
/*
Defines a set of base level
constants and enums to be used
throughout Gohan and it's
associated services.
*/
type GenotypeQuery string
type SearchOperation string
type SortDirection string

type GenotypeQuery enumString
type SearchOperation enumString

type Zygosity enumInt
type Zygosity int
23 changes: 23 additions & 0 deletions src/api/models/constants/sort/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package sort

import (
"api/models/constants"
"strings"
)

const (
Undefined constants.SortDirection = ""
Ascending constants.SortDirection = "asc"
Descending constants.SortDirection = "desc"
)

func CastToSortDirection(text string) constants.SortDirection {
switch strings.ToLower(text) {
case "asc":
return Ascending
case "desc":
return Descending
default:
return Undefined
}
}
3 changes: 2 additions & 1 deletion src/api/mvc/variants.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"api/models"
"api/models/constants"
gq "api/models/constants/genotype-query"
s "api/models/constants/sort"
"api/models/ingest"
esRepo "api/repositories/elasticsearch"
"api/utils"
Expand Down Expand Up @@ -322,7 +323,7 @@ func executeGetByIds(c echo.Context, ids []string, isVariantIdQuery bool) error
}
}

sortByPosition := c.QueryParam("sortByPosition")
sortByPosition := s.CastToSortDirection(c.QueryParam("sortByPosition"))

includeSamplesInResultSetQP := c.QueryParam("includeSamplesInResultSet")
var (
Expand Down
25 changes: 6 additions & 19 deletions src/api/repositories/elasticsearch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

c "api/models/constants"
gq "api/models/constants/genotype-query"
s "api/models/constants/sort"
z "api/models/constants/zygosity"

"github.com/elastic/go-elasticsearch"
Expand All @@ -21,7 +22,7 @@ func GetDocumentsContainerVariantOrSampleIdInPositionRange(es *elasticsearch.Cli
chromosome string, lowerBound int, upperBound int,
variantId string, sampleId string,
reference string, alternative string,
size int, sortByPosition string,
size int, sortByPosition c.SortDirection,
includeSamplesInResultSet bool, genotype c.GenotypeQuery) map[string]interface{} {

// begin building the request body.
Expand Down Expand Up @@ -163,28 +164,14 @@ func GetDocumentsContainerVariantOrSampleIdInPositionRange(es *elasticsearch.Cli
}

// set up sorting
sortDirection := "asc"
if sortByPosition != "" {
switch sortByPosition {
case "asc":
fmt.Println("Already set 'sortByPosition' keyword 'asc' to query")
break
case "desc":
fmt.Println("Setting 'sortByPosition' keyword 'desc' to query")
sortDirection = "desc"
break
default:
fmt.Printf("Found unknown 'sortByPosition' keyword : %s -- ignoring\n", sortByPosition)
break
}

} else {
fmt.Println("Found empty 'sortByPosition' keyword -- defaulting to 'asc'")
if sortByPosition == s.Undefined {
// default to ascending order
sortByPosition = s.Ascending
}

// append sorting components
query["sort"] = map[string]string{
"pos": sortDirection,
"pos": string(sortByPosition),
}

// encode the query
Expand Down
Loading

0 comments on commit f49ee9c

Please sign in to comment.