Skip to content

Commit

Permalink
server: remove token from WS servers, #TASK-4791, #TASK-4641
Browse files Browse the repository at this point in the history
  • Loading branch information
jtarraga committed Aug 31, 2023
1 parent 3ecac67 commit 76c5791
Show file tree
Hide file tree
Showing 33 changed files with 53 additions and 433 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public class VariantAnnotationCommandOptions {
@Parameter(names = {"--data-release"}, description = "Data release. To use the default data relese, please, set this parameter to 0", required = false, arity = 1)
public int dataRelease = 0;

@Parameter(names = {"--token"}, description = "Data token to get access to licensed/restricted data sources such as COSMIC or HGMD", required = false, arity = 1)
public String token;
@Parameter(names = {"--api-key"}, description = "API key to get access to licensed/restricted data sources such as COSMIC or HGMD", required = false, arity = 1)
public String apiKey;

@Parameter(names = {"-l", "--local"}, description = "Database credentials for local annotation are read from configuration.json file", required = false, arity = 0)
public boolean local;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private boolean runAnnotation() throws Exception {
CellBaseManagerFactory cellBaseManagerFactory = new CellBaseManagerFactory(configuration);
VariantAnnotationCalculator variantAnnotationCalculator =
new VariantAnnotationCalculator(this.species, this.assembly, variantAnnotationCommandOptions.dataRelease,
variantAnnotationCommandOptions.token, cellBaseManagerFactory);
variantAnnotationCommandOptions.apiKey, cellBaseManagerFactory);
List<CellBaseDataResult<VariantAnnotation>> annotationByVariantList =
variantAnnotationCalculator.getAnnotationByVariantList(variants, serverQueryOptions);

Expand Down Expand Up @@ -480,7 +480,7 @@ private VariantAnnotator createCellBaseAnnotator() throws CellBaseException {
// equals the number of returned annotations
CellBaseManagerFactory cellBaseManagerFactory = new CellBaseManagerFactory(configuration);
return new CellBaseLocalVariantAnnotator(new VariantAnnotationCalculator(species, assembly,
variantAnnotationCommandOptions.dataRelease, variantAnnotationCommandOptions.token, cellBaseManagerFactory),
variantAnnotationCommandOptions.dataRelease, variantAnnotationCommandOptions.apiKey, cellBaseManagerFactory),
serverQueryOptions);
} else {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public class CellBaseClient {
private final String assembly;
private final String dataRelease;
private final String apiKey;
@Deprecated
private final String token;
private ClientConfiguration clientConfiguration;

private final Map<String, ParentRestClient> clients;
Expand Down Expand Up @@ -62,7 +60,6 @@ public CellBaseClient(String species, String assembly, String dataRelease, Strin
this.species = species;
this.assembly = StringUtils.isEmpty(assembly) ? null : assembly;
this.dataRelease = StringUtils.isEmpty(dataRelease) ? null : dataRelease;
this.token = apiKey;
this.apiKey = apiKey;
if (clientConfiguration != null && clientConfiguration.getRest() != null
&& clientConfiguration.getRest().getHosts() != null
Expand Down Expand Up @@ -151,11 +148,6 @@ public String getApiKey() {
return apiKey;
}

@Deprecated
public String getToken() {
return apiKey;
}

public ClientConfiguration getClientConfiguration() {
return clientConfiguration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ private <U> CellBaseDataResponse<U> restCall(List<String> hosts, String version,
String apiKeyParam = null;
if (VersionUtils.isMinVersion("v5.7", configuration.getVersion())) {
apiKeyParam = API_KEY_PARAM;
} else if (VersionUtils.isMinVersion("v5.3", configuration.getVersion())) {
} else if (VersionUtils.isMinVersion("v5.4", configuration.getVersion())) {
apiKeyParam = TOKEN_PARAM;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public Type type() {
public static final String API_KEY_PARAM = "apiKey";
public static final String API_KEY_DESCRIPTION = "API key to allow access to licensed/restricted data sources such as"
+ " Cosmic or HGMD";
// For backward-compatibility, but it should be deprecated
// For backward-compatibility, from v5.7 "token" is not used anymore
public static final String TOKEN_PARAM = "token";


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public enum Order {
public CellBaseQueryOptions() {
}

public CellBaseQueryOptions(Integer limit, Integer skip, Boolean count, String sort, Order order, String facet, String token) {
public CellBaseQueryOptions(Integer limit, Integer skip, Boolean count, String sort, Order order, String facet) {
this.limit = limit;
this.skip = skip;
this.count = count;
Expand All @@ -55,7 +55,7 @@ public CellBaseQueryOptions(Integer limit, Integer skip, Boolean count, String s
this.facet = facet;
}

public CellBaseQueryOptions(Integer limit, Integer skip, Boolean count, String sort, Order order, String facet, String token,
public CellBaseQueryOptions(Integer limit, Integer skip, Boolean count, String sort, Order order, String facet,
List<String> includes, List<String> excludes) {
super(includes, excludes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ default CellBaseDataResult<Long> count(Q query) throws CellBaseException {

CellBaseDataResult<String> distinct(Q query) throws CellBaseException;

List<CellBaseDataResult<T>> info(List<String> ids, ProjectionQueryOptions queryOptions, int dataRelease, String token)
List<CellBaseDataResult<T>> info(List<String> ids, ProjectionQueryOptions queryOptions, int dataRelease, String apiKey)
throws CellBaseException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public CellBaseDataResult<Variant> search(ClinicalVariantQuery query) throws Que

Set<String> validSources = apiKeyManager.getValidSources(query.getApiKey(), ApiKeyLicensedDataUtils.UNLICENSED_CLINICAL_DATA);

// Check if is necessary to use the token licensed variant iterator
// Check if is necessary to use the API key licensed variant iterator
if (ApiKeyLicensedDataUtils.needFiltering(validSources, ApiKeyLicensedDataUtils.LICENSED_CLINICAL_DATA)) {
return ApiKeyLicensedDataUtils.filterDataSources(results, validSources);
} else {
Expand All @@ -89,13 +89,13 @@ public List<CellBaseDataResult<Variant>> search(List<ClinicalVariantQuery> queri
}

@Override
public List<CellBaseDataResult<Variant>> info(List<String> ids, CellBaseQueryOptions queryOptions, int dataRelease, String token)
public List<CellBaseDataResult<Variant>> info(List<String> ids, CellBaseQueryOptions queryOptions, int dataRelease, String apiKey)
throws CellBaseException {
List<CellBaseDataResult<Variant>> results = getDBAdaptor().info(ids, queryOptions, dataRelease, token);
List<CellBaseDataResult<Variant>> results = getDBAdaptor().info(ids, queryOptions, dataRelease, apiKey);

Set<String> validSources = apiKeyManager.getValidSources(token, ApiKeyLicensedDataUtils.UNLICENSED_CLINICAL_DATA);
Set<String> validSources = apiKeyManager.getValidSources(apiKey, ApiKeyLicensedDataUtils.UNLICENSED_CLINICAL_DATA);

// Check if is necessary to use the token licensed variant iterator
// Check if is necessary to use the API key licensed variant iterator
if (ApiKeyLicensedDataUtils.needFiltering(validSources, ApiKeyLicensedDataUtils.LICENSED_CLINICAL_DATA)) {
return ApiKeyLicensedDataUtils.filterDataSources(results, validSources);
} else {
Expand All @@ -107,7 +107,7 @@ public List<CellBaseDataResult<Variant>> info(List<String> ids, CellBaseQueryOpt
public CellBaseIterator<Variant> iterator(ClinicalVariantQuery query) throws CellBaseException {
Set<String> validSources = apiKeyManager.getValidSources(query.getApiKey(), ApiKeyLicensedDataUtils.UNLICENSED_CLINICAL_DATA);

// Check if is necessary to use the token licensed variant iterator
// Check if is necessary to use the API key licensed variant iterator
if (ApiKeyLicensedDataUtils.needFiltering(validSources, ApiKeyLicensedDataUtils.LICENSED_CLINICAL_DATA)) {
return new ApiKeyFilteredVariantIterator(getDBAdaptor().iterator(query), validSources);
} else {
Expand All @@ -129,7 +129,7 @@ public CellBaseDataResult<Variant> search(Query query, QueryOptions queryOptions
includes = Arrays.asList(queryOptions.getString(EXCLUDE).split(","));
}

// Check if is necessary to use the token licensed variant iterator
// Check if is necessary to use the API key licensed variant iterator
if (ApiKeyLicensedDataUtils.needFiltering(validSources, ApiKeyLicensedDataUtils.LICENSED_CLINICAL_DATA)) {
return ApiKeyLicensedDataUtils.filterDataSources(result, validSources);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public CellBaseCoreDBAdaptor<GeneQuery, Gene> getDBAdaptor() {
}

public List<CellBaseDataResult<Gene>> info(List<String> ids, ProjectionQueryOptions query, String source, int dataRelease,
String token) throws CellBaseException {
return geneDBAdaptor.info(ids, query, source, dataRelease, token);
String apiKey) throws CellBaseException {
return geneDBAdaptor.info(ids, query, source, dataRelease, apiKey);
}

public CellBaseDataResult<GenomeSequenceFeature> getSequence(GeneQuery query) throws CellBaseException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public CellBaseCoreDBAdaptor<PharmaChemicalQuery, PharmaChemical> getDBAdaptor()
}

public List<CellBaseDataResult<PharmaChemical>> info(List<String> ids, ProjectionQueryOptions query, int dataRelease,
String token) throws CellBaseException {
return pharmacogenomicsDBAdaptor.info(ids, query, dataRelease, token);
String apiKey) throws CellBaseException {
return pharmacogenomicsDBAdaptor.info(ids, query, dataRelease, apiKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public CellBaseCoreDBAdaptor<TranscriptQuery, Transcript> getDBAdaptor() {
}

public List<CellBaseDataResult<Transcript>> info(List<String> ids, ProjectionQueryOptions query, String source, int dataRelease,
String token) throws CellBaseException {
return transcriptDBAdaptor.info(ids, query, source, dataRelease, token);
String apiKey) throws CellBaseException {
return transcriptDBAdaptor.info(ids, query, source, dataRelease, apiKey);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public List<CellBaseDataResult<VariantAnnotation>> getAnnotationByVariant(QueryO
Boolean checkAminoAcidChange,
String consequenceTypeSource,
int dataRelease,
String token)
String apiKey)
throws ExecutionException, InterruptedException, CellBaseException, QueryException, IllegalAccessException {
List<Variant> variantList = parseVariants(variants);
logger.debug("queryOptions: " + queryOptions);
Expand Down Expand Up @@ -194,7 +194,7 @@ public List<CellBaseDataResult<VariantAnnotation>> getAnnotationByVariant(QueryO
}

VariantAnnotationCalculator variantAnnotationCalculator = new VariantAnnotationCalculator(species, assembly,
dataRelease, token, cellbaseManagerFactory);
dataRelease, apiKey, cellbaseManagerFactory);
List<CellBaseDataResult<VariantAnnotation>> queryResults = variantAnnotationCalculator.getAnnotationByVariantList(variantList,
queryOptions);
return queryResults;
Expand Down Expand Up @@ -310,8 +310,8 @@ public List<CellBaseDataResult<Variant>> getPopulationFrequencyByVariant(List<Va
return variantDBAdaptor.getPopulationFrequencyByVariant(variants, queryOptions, dataRelease);
}

public CellBaseDataResult<SpliceScore> getSpliceScoreVariant(Variant variant, String token, int dataRelease) throws CellBaseException {
Set<String> validSources = apiKeyManager.getValidSources(token, ApiKeyLicensedDataUtils.UNLICENSED_SPLICE_SCORES_DATA);
public CellBaseDataResult<SpliceScore> getSpliceScoreVariant(Variant variant, String apiKey, int dataRelease) throws CellBaseException {
Set<String> validSources = apiKeyManager.getValidSources(apiKey, ApiKeyLicensedDataUtils.UNLICENSED_SPLICE_SCORES_DATA);

CellBaseDataResult<SpliceScore> result = spliceDBAdaptor.getScores(variant.getChromosome(), variant.getStart(),
variant.getReference(), variant.getAlternate(), dataRelease);
Expand All @@ -323,9 +323,9 @@ public CellBaseDataResult<SpliceScore> getSpliceScoreVariant(Variant variant, St
}
}

public List<CellBaseDataResult<SpliceScore>> getSpliceScoreVariant(List<Variant> variants, String token, int dataRelease)
public List<CellBaseDataResult<SpliceScore>> getSpliceScoreVariant(List<Variant> variants, String apiKey, int dataRelease)
throws CellBaseException {
Set<String> validSources = apiKeyManager.getValidSources(token, ApiKeyLicensedDataUtils.UNLICENSED_SPLICE_SCORES_DATA);
Set<String> validSources = apiKeyManager.getValidSources(apiKey, ApiKeyLicensedDataUtils.UNLICENSED_SPLICE_SCORES_DATA);

List<CellBaseDataResult<SpliceScore>> cellBaseDataResults = new ArrayList<>(variants.size());
if (ApiKeyLicensedDataUtils.needFiltering(validSources, ApiKeyLicensedDataUtils.LICENSED_SPLICE_SCORES_DATA)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class GenericMongoDBAdaptorTest {

private DataReleaseManager dataReleaseManager;
protected int dataRelease;
protected String token;
protected String apiKey;

protected String cellBaseName;

Expand All @@ -68,6 +68,7 @@ public class GenericMongoDBAdaptorTest {
protected CellBaseConfiguration cellBaseConfiguration;
protected CellBaseManagerFactory cellBaseManagerFactory;

// API keys for testing
protected String UNIVERSAL_ACCES_API_KEY = "eyJhbGciOiJIUzI1NiJ9.eyJzb3VyY2VzIjp7ImNvc21pYyI6OTIyMzM3MjAzNjg1NDc3NTgwNywiaGdtZCI6OTIyMzM3MjAzNjg1NDc3NTgwNywic3BsaWNlYWkiOjkyMjMzNzIwMzY4NTQ3NzU4MDd9LCJtYXhOdW1RdWVyaWVzIjoxMDAwMDAwMCwidmVyc2lvbiI6IjEuMCIsInN1YiI6IlRFU1QiLCJpYXQiOjE2ODk4MzczODZ9.ALdEFGmVuatoUEj-K3HAHt2KlqeNm2Fv7m-DODhz0LU";
protected String HGMD_ACCESS_API_KEY = "eyJhbGciOiJIUzI1NiJ9.eyJzb3VyY2VzIjp7ImhnbWQiOjkyMjMzNzIwMzY4NTQ3NzU4MDd9LCJtYXhOdW1RdWVyaWVzIjoxMDAwMDAwMCwidmVyc2lvbiI6IjEuMCIsInN1YiI6IlRFU1QiLCJpYXQiOjE2ODk4Mzc0MjZ9.zqEU-WhIzhbpbmwGWnAjgmgfOtBbP5nXq2uqX5wV5uY";
protected String COSMIC_ACCESS_API_KEY = "eyJhbGciOiJIUzI1NiJ9.eyJzb3VyY2VzIjp7ImNvc21pYyI6OTIyMzM3MjAzNjg1NDc3NTgwN30sIm1heE51bVF1ZXJpZXMiOjEwMDAwMDAwLCJ2ZXJzaW9uIjoiMS4wIiwic3ViIjoiVEVTVCIsImlhdCI6MTY4OTgzNzQ2MX0.K6SEGvScpJ2a99SLPaUi4KRJ8FJ_LNPduoHW_LSSNGU";
Expand All @@ -77,8 +78,6 @@ public class GenericMongoDBAdaptorTest {
protected String COSMIC_SPLICEAI_ACCESS_API_KEY = "eyJhbGciOiJIUzI1NiJ9.eyJzb3VyY2VzIjp7ImNvc21pYyI6OTIyMzM3MjAzNjg1NDc3NTgwNywic3BsaWNlYWkiOjkyMjMzNzIwMzY4NTQ3NzU4MDd9LCJtYXhOdW1RdWVyaWVzIjoxMDAwMDAwMCwidmVyc2lvbiI6IjEuMCIsInN1YiI6IlRFU1QiLCJpYXQiOjE2ODk4Mzc1MzZ9.CkXvpNg0NWAXL3N06R2gCqe0kF4ptBk0MPvaAdDSEpQ";

protected LoadRunner loadRunner = null;
// protected MongoDBAdaptorFactory dbAdaptorFactory;


protected Logger logger = LoggerFactory.getLogger(this.getClass());

Expand All @@ -87,11 +86,6 @@ public GenericMongoDBAdaptorTest() {
cellBaseConfiguration = CellBaseConfiguration.load(
GenericMongoDBAdaptorTest.class.getClassLoader().getResourceAsStream("configuration.test.yaml"),
CellBaseConfiguration.ConfigurationFileFormat.YAML);
// cellBaseConfiguration.getDatabases().getMongodb().setHost("localhost:27037");
// cellBaseConfiguration.getDatabases().getMongodb().setUser("cellbase");
// cellBaseConfiguration.getDatabases().getMongodb().setPassword("cellbase");
// cellBaseConfiguration.getDatabases().getMongodb().getOptions().put("authenticationDatabase", "admin");
// cellBaseConfiguration.getDatabases().getMongodb().getOptions().put("authenticationMechanism", "SCRAM-SHA-256");

String[] versionSplit = GitRepositoryState.get().getBuildVersion().split("\\.");
cellBaseConfiguration.setVersion("v" + versionSplit[0] + "." + versionSplit[1]);
Expand Down
Loading

0 comments on commit 76c5791

Please sign in to comment.