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

TASK-4913 - Unable to update cellbase-token #2330

Closed
wants to merge 19 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

test:
uses: ./.github/workflows/test-analysis.yml
needs: deploy-docker-ext-tools
needs: build
with:
test_profile: runShortTests,runMediumTests
secrets: inherit
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/docker-ext-tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:
- TASK-*
paths:
- opencga-app/app/cloud/docker/opencga-ext-tools/Dockerfile
workflow_dispatch:

jobs:
build:
Expand All @@ -19,5 +18,4 @@ jobs:
needs: build
with:
cli: python3 ./build/cloud/docker/docker-build.py push --images ext-tools --tag ${{ needs.build.outputs.version }}
secrets: inherit

secrets: inherit
4 changes: 2 additions & 2 deletions .github/workflows/long-test-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ name: Long test for run only on weekend
on:
schedule:
- cron: '10 1 * * 6'
workflow_dispatch:

jobs:
test:
uses: ./.github/workflows/test-analysis.yml
secrets: inherit
with:
test_profile: runLongTests,runMediumTests,runShortTests
report_context: development
test_profile: runShortTests,runMediumTests,runLongTests,


50 changes: 50 additions & 0 deletions .github/workflows/manual-deploy-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Manual deploy Docker base
on:
workflow_dispatch:
inputs:
branch:
description: "The branch, tag or SHA of the source code to build docker."
type: string
required: true
tag:
description: "The tag for the new docker."
type: string
required: true

jobs:
build:
name: Build Java app
runs-on: ubuntu-22.04
outputs:
version: ${{ steps.get_project_version.outputs.version }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: '10'
ref: "${{ inputs.branch }}"
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '8'
cache: 'maven'
- name: Install dependencies branches
run: |
if [ -f "./.github/workflows/scripts/get_same_branch.sh" ]; then
chmod +x ./.github/workflows/scripts/get_same_branch.sh
./.github/workflows/scripts/get_same_branch.sh ${{ github.ref_name }}
fi
- name: Maven Build (skip tests)
run: mvn -T 2 clean install -DskipTests
- uses: actions/upload-artifact@v3
with:
name: build-folder
path: build


deploy-docker:
uses: opencb/java-common-libs/.github/workflows/deploy-docker-hub-workflow.yml@develop
needs: build
with:
cli: python3 ./build/cloud/docker/docker-build.py push --images base,init --tag ${{ inputs.tag }}
secrets: inherit
50 changes: 50 additions & 0 deletions .github/workflows/manual-deploy-ext-tools.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Manual deploy Docker Ext-Tools
on:
workflow_dispatch:
inputs:
branch:
description: "The branch, tag or SHA of the source code to build docker."
type: string
required: true
tag:
description: "The tag for the new docker."
type: string
required: true

jobs:
build:
name: Build Java app
runs-on: ubuntu-22.04
outputs:
version: ${{ steps.get_project_version.outputs.version }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: '10'
ref: "${{ inputs.branch }}"
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '8'
cache: 'maven'
- name: Install dependencies branches
run: |
if [ -f "./.github/workflows/scripts/get_same_branch.sh" ]; then
chmod +x ./.github/workflows/scripts/get_same_branch.sh
./.github/workflows/scripts/get_same_branch.sh ${{ github.ref_name }}
fi
- name: Maven Build (skip tests)
run: mvn -T 2 clean install -DskipTests
- uses: actions/upload-artifact@v3
with:
name: build-folder
path: build


deploy-docker-ext-tools:
uses: opencb/java-common-libs/.github/workflows/deploy-docker-hub-workflow.yml@develop
needs: build
with:
cli: python3 ./build/cloud/docker/docker-build.py push --images ext-tools --tag ${{ inputs.tag }}
secrets: inherit
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ jobs:
file: |
opencga-client-${{ needs.build.outputs.version }}.tar.gz
clients/R/opencgaR_${{ needs.build.outputs.version }}.tar.gz

Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package org.opencb.opencga.core.cellbase;

import io.jsonwebtoken.JwtException;
import org.apache.commons.lang3.StringUtils;
import org.opencb.biodata.models.variant.avro.VariantAnnotation;
import org.opencb.cellbase.client.rest.CellBaseClient;
import org.opencb.cellbase.core.config.SpeciesConfiguration;
import org.opencb.cellbase.core.config.SpeciesProperties;
import org.opencb.cellbase.core.models.DataRelease;
import org.opencb.cellbase.core.result.CellBaseDataResponse;
import org.opencb.cellbase.core.token.DataAccessTokenManager;
import org.opencb.cellbase.core.token.DataAccessTokenSources;
import org.opencb.commons.datastore.core.QueryOptions;
import org.opencb.opencga.core.common.VersionUtils;
import org.opencb.opencga.core.config.storage.CellBaseConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -46,6 +50,7 @@ private CellBaseClient newCellBaseClient(CellBaseConfiguration cellBaseConfigura
toCellBaseSpeciesName(species),
assembly,
cellBaseConfiguration.getDataRelease(),
cellBaseConfiguration.getToken(),
cellBaseConfiguration.toClientConfiguration());
}

Expand Down Expand Up @@ -136,7 +141,7 @@ public void validate() throws IOException {
validate(false);
}

public CellBaseConfiguration validate(boolean autoComplete) throws IOException {
private CellBaseConfiguration validate(boolean autoComplete) throws IOException {
CellBaseConfiguration cellBaseConfiguration = getCellBaseConfiguration();
String inputVersion = getVersion();
CellBaseDataResponse<SpeciesProperties> species;
Expand Down Expand Up @@ -189,6 +194,38 @@ public CellBaseConfiguration validate(boolean autoComplete) throws IOException {
}
}
}
if (getToken() != null) {
// Check it's supported
if (!supportsToken(serverVersion)) {
throw new IllegalArgumentException("Token not supported for cellbase "
+ "url: '" + getURL() + "'"
+ ", version: '" + inputVersion + "'");
}

// Check it's an actual token
DataAccessTokenManager tokenManager = new DataAccessTokenManager();
try {
tokenManager.decode(getToken());
} catch (JwtException e) {
throw new IllegalArgumentException("Malformed token for cellbase "
+ "url: '" + getURL() + "'"
+ ", version: '" + inputVersion
+ "', species: '" + getSpecies()
+ "', assembly: '" + getAssembly() + "'");
}

// Check it's a valid token
CellBaseDataResponse<VariantAnnotation> response = cellBaseClient.getVariantClient()
.getAnnotationByVariantIds(Collections.singletonList("1:1:N:C"), new QueryOptions(), true);
if (response.firstResult() == null) {
throw new IllegalArgumentException("Invalid token for cellbase "
+ "url: '" + getURL() + "'"
+ ", version: '" + inputVersion
+ "', species: '" + getSpecies()
+ "', assembly: '" + getAssembly() + "'");
}
}

return cellBaseConfiguration;
}

Expand Down Expand Up @@ -231,6 +268,11 @@ public static boolean supportsDataReleaseActiveByDefaultIn(String serverVersion)
return VersionUtils.isMinVersion("5.5.0", serverVersion, true);
}

public static boolean supportsToken(String serverVersion) {
// Tokens support starts at version 5.4.0
return VersionUtils.isMinVersion("5.4.0", serverVersion);
}

public String getVersionFromServerMajor() throws IOException {
return major(getVersionFromServer());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.opencb.opencga.core.cellbase;

import org.apache.commons.lang3.StringUtils;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
Expand Down Expand Up @@ -70,4 +72,37 @@ public void testNoActiveReleases() throws IOException {
thrown.expectMessage("No active data releases found on cellbase");
CellBaseValidator.validate(new CellBaseConfiguration(ParamConstants.CELLBASE_URL, "v5.1", null, null), "mmusculus", "GRCm38", true);
}

@Test
public void testToken() throws IOException {
String token = System.getenv("CELLBASE_HGMD_TOKEN");
Assume.assumeTrue(StringUtils.isNotEmpty(token));
CellBaseConfiguration validated = CellBaseValidator.validate(new CellBaseConfiguration(ParamConstants.CELLBASE_URL, "v5.4", null, token), "hsapiens", "grch38", true);
Assert.assertNotNull(validated.getToken());
}

@Test
public void testTokenNotSupported() throws IOException {
String token = System.getenv("CELLBASE_HGMD_TOKEN");
Assume.assumeTrue(StringUtils.isNotEmpty(token));
CellBaseConfiguration validated = CellBaseValidator.validate(new CellBaseConfiguration(ParamConstants.CELLBASE_URL, "v5.1", null, token), "hsapiens", "grch38", true);
Assert.assertNotNull(validated.getToken());
}

@Test
public void testMalformedToken() throws IOException {
thrown.expectMessage("Malformed token for cellbase");
String token = "MALFORMED_TOKEN";
CellBaseConfiguration validated = CellBaseValidator.validate(new CellBaseConfiguration(ParamConstants.CELLBASE_URL, "v5.4", null, token), "hsapiens", "grch38", true);
Assert.assertNotNull(validated.getToken());
}

@Test
public void testUnsignedToken() throws IOException {
thrown.expectMessage("Invalid token for cellbase");
String token = "eyJhbGciOiJIUzI1NiJ9.eyJzb3VyY2VzIjp7ImhnbWQiOjkyMjMzNzIwMzY4NTQ3NzU4MDd9LCJ2ZXJzaW9uIjoiMS4wIiwic3ViIjoiWkVUVEEiLCJpYXQiOjE2OTMyMTY5MDd9.invalidsignature";
CellBaseConfiguration validated = CellBaseValidator.validate(new CellBaseConfiguration(ParamConstants.CELLBASE_URL, "v5.4", null, token), "hsapiens", "grch38", true);
Assert.assertNotNull(validated.getToken());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public enum VariantField {
ANNOTATION_CONSERVATION(ANNOTATION, "annotation.conservation"),
ANNOTATION_CANCER_HOTSPOTS(ANNOTATION, "annotation.cancerHotspots"),
ANNOTATION_GENE_EXPRESSION(ANNOTATION, "annotation.geneExpression"),
ANNOTATION_PHARMACOGENOMICS(ANNOTATION, "annotation.pharmacogenomics"),
ANNOTATION_GENE_TRAIT_ASSOCIATION(ANNOTATION, "annotation.geneTraitAssociation"),
ANNOTATION_GENE_DRUG_INTERACTION(ANNOTATION, "annotation.geneDrugInteraction"),
ANNOTATION_GENE_CANCER_ASSOCIATIONS(ANNOTATION, "annotation.geneCancerAssociations"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public List<VariantAnnotation> annotate(List<Variant> variants) throws VariantAn
public ProjectMetadata.VariantAnnotationMetadata getVariantAnnotationMetadata() throws VariantAnnotatorException {
return new ProjectMetadata.VariantAnnotationMetadata(-1, null, null,
new ProjectMetadata.VariantAnnotatorProgram("MyAnnotator", key, null),
Collections.singletonList(new ObjectMap("data", "genes")), null);
Collections.singletonList(new ObjectMap("data", "genes")), null,null);
}

}
Loading