Commit d2ffd8c9 authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion
Browse files

add requirement for JWT token to create database

parent 9821e311
Pipeline #19395 failed with stages
in 2 minutes and 17 seconds
...@@ -116,7 +116,7 @@ REST_FRAMEWORK = { ...@@ -116,7 +116,7 @@ REST_FRAMEWORK = {
# JWT Authorization settings # JWT Authorization settings
JWT_AUTH = { JWT_AUTH = {
'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=3600) 'JWT_EXPIRATION_DELTA': datetime.timedelta(days=7)
} }
......
...@@ -24,12 +24,12 @@ class ImportIGCGenes(object): ...@@ -24,12 +24,12 @@ class ImportIGCGenes(object):
GENUS_COL = 'taxo_genus' GENUS_COL = 'taxo_genus'
SELECTED_KEYS = ['gene_id', 'length', 'kegg_ko', PHYLUM_COL, GENUS_COL] SELECTED_KEYS = ['gene_id', 'length', 'kegg_ko', PHYLUM_COL, GENUS_COL]
def __init__(self, annotation_file, url, skip_tax=False, skip_functions=False): def __init__(self, annotation_file, url, jwt_token, skip_tax=False, skip_functions=False):
self.annotation_file = annotation_file self.annotation_file = annotation_file
self.url = url self.url = url
self.metagenedb_gene_api = self.METAGENEDB_GENE_API(base_url=self.url) self.metagenedb_gene_api = self.METAGENEDB_GENE_API(base_url=self.url, jwt_token=jwt_token)
self.metagenedb_taxonomy_api = self.METAGENEDB_TAXONOMY_API(base_url=self.url) self.metagenedb_taxonomy_api = self.METAGENEDB_TAXONOMY_API(base_url=self.url, jwt_token=jwt_token)
self.metagenedb_function_api = self.METAGENEDB_FUNCTION_API(base_url=self.url) self.metagenedb_function_api = self.METAGENEDB_FUNCTION_API(base_url=self.url, jwt_token=jwt_token)
self.total_genes = self._get_number_genes() self.total_genes = self._get_number_genes()
self._reset_counters() self._reset_counters()
# Skip some insertion if specified in script options # Skip some insertion if specified in script options
...@@ -177,6 +177,7 @@ def parse_arguments(): ...@@ -177,6 +177,7 @@ def parse_arguments():
# Common arguments for analysis and annotations # Common arguments for analysis and annotations
parser.add_argument('annotation', help='IGC annotation file') parser.add_argument('annotation', help='IGC annotation file')
parser.add_argument('--url', help='base URL of the instance.', default='http://localhost/') parser.add_argument('--url', help='base URL of the instance.', default='http://localhost/')
parser.add_argument('-t', '--jwt_token', help='your JWT token obtain from web app', required=True)
parser.add_argument('--chunk_size', type=int, default=1000, parser.add_argument('--chunk_size', type=int, default=1000,
help='How many genes to handle and create in the same time.') help='How many genes to handle and create in the same time.')
parser.add_argument('--skip_taxonomy', action='store_true', help='Skip taxonomy information from genes.') parser.add_argument('--skip_taxonomy', action='store_true', help='Skip taxonomy information from genes.')
...@@ -194,7 +195,7 @@ def run(): ...@@ -194,7 +195,7 @@ def run():
args = parse_arguments() args = parse_arguments()
if args.verbose: if args.verbose:
logger.setLevel(logging.INFO) logger.setLevel(logging.INFO)
import_igc_genes = ImportIGCGenes(args.annotation, args.url, import_igc_genes = ImportIGCGenes(args.annotation, args.url, args.jwt_token,
skip_tax=args.skip_taxonomy, skip_functions=args.skip_functions) skip_tax=args.skip_taxonomy, skip_functions=args.skip_functions)
import_igc_genes.load_annotation_file_to_db_in_chunks(chunk_size=args.chunk_size, test=args.test) import_igc_genes.load_annotation_file_to_db_in_chunks(chunk_size=args.chunk_size, test=args.test)
......
...@@ -18,8 +18,8 @@ class ImportNCBITaxonomy(object): ...@@ -18,8 +18,8 @@ class ImportNCBITaxonomy(object):
METAGENEDB_TAX_API = MetageneDBCatalogTaxonomyAPI METAGENEDB_TAX_API = MetageneDBCatalogTaxonomyAPI
FOREIGN_KEY_FIELDS = ['parent_tax_id'] FOREIGN_KEY_FIELDS = ['parent_tax_id']
def __init__(self, url, tax_names_file, tax_nodes_file): def __init__(self, url, jwt_token, tax_names_file, tax_nodes_file):
self.metagenedb_tax_api = self.METAGENEDB_TAX_API(base_url=url) self.metagenedb_tax_api = self.METAGENEDB_TAX_API(base_url=url, jwt_token=jwt_token)
self.tax_names_file = tax_names_file self.tax_names_file = tax_names_file
self.tax_nodes_file = tax_nodes_file self.tax_nodes_file = tax_nodes_file
self.total_tax = self._get_number_nodes() self.total_tax = self._get_number_nodes()
...@@ -104,6 +104,7 @@ def parse_arguments(): ...@@ -104,6 +104,7 @@ def parse_arguments():
parser.add_argument('--names', help='names.dmp file from ncbi_taxonomy', required=True) parser.add_argument('--names', help='names.dmp file from ncbi_taxonomy', required=True)
parser.add_argument('--skip_creation', action='store_true', help='Skip taxonomy creation.') parser.add_argument('--skip_creation', action='store_true', help='Skip taxonomy creation.')
parser.add_argument('--url', help='base URL of the instance.', default='http://localhost/') parser.add_argument('--url', help='base URL of the instance.', default='http://localhost/')
parser.add_argument('-t', '--jwt_token', help='your JWT token obtain from web app', required=True)
parser.add_argument('-v', '--verbose', action='store_true') parser.add_argument('-v', '--verbose', action='store_true')
try: try:
...@@ -116,7 +117,7 @@ def run(): ...@@ -116,7 +117,7 @@ def run():
args = parse_arguments() args = parse_arguments()
if args.verbose: if args.verbose:
logger.setLevel(logging.INFO) logger.setLevel(logging.INFO)
import_ncbi_tax = ImportNCBITaxonomy(args.url, args.names, args.nodes) import_ncbi_tax = ImportNCBITaxonomy(args.url, args.jwt_token, args.names, args.nodes)
taxonomy_names = import_ncbi_tax.import_names() taxonomy_names = import_ncbi_tax.import_names()
if not args.skip_creation: if not args.skip_creation:
import_ncbi_tax.create_taxo_nodes(taxonomy_names) import_ncbi_tax.create_taxo_nodes(taxonomy_names)
......
...@@ -21,9 +21,9 @@ class ImportKEGGKO(object): ...@@ -21,9 +21,9 @@ class ImportKEGGKO(object):
ORM_SOURCE_KEY = 'source' ORM_SOURCE_KEY = 'source'
KEGG_SOURCE = 'kegg' KEGG_SOURCE = 'kegg'
def __init__(self, url, kegg_ko_list_api=KEGG_KO_LIST_API): def __init__(self, url, jwt_token, kegg_ko_list_api=KEGG_KO_LIST_API):
self.kegg_ko_list_api = kegg_ko_list_api self.kegg_ko_list_api = kegg_ko_list_api
self.metagenedb_function_api = self.METAGENEDB_FUNCTION_API(base_url=url) self.metagenedb_function_api = self.METAGENEDB_FUNCTION_API(base_url=url, jwt_token=jwt_token)
self.processed_kegg = 0 self.processed_kegg = 0
self.created_kegg = 0 self.created_kegg = 0
self.updated_kegg = 0 self.updated_kegg = 0
...@@ -55,6 +55,7 @@ def parse_arguments(): ...@@ -55,6 +55,7 @@ def parse_arguments():
""" """
parser = argparse.ArgumentParser(description=f'Populate KEGG KO database from {KEGG_KO_LIST_API}.') parser = argparse.ArgumentParser(description=f'Populate KEGG KO database from {KEGG_KO_LIST_API}.')
parser.add_argument('--url', help='base URL of the instance.', default='http://localhost/') parser.add_argument('--url', help='base URL of the instance.', default='http://localhost/')
parser.add_argument('-t', '--jwt_token', help='your JWT token obtain from web app', required=True)
parser.add_argument('-v', '--verbose', action='store_true') parser.add_argument('-v', '--verbose', action='store_true')
try: try:
return parser.parse_args() return parser.parse_args()
...@@ -66,7 +67,7 @@ def run(): ...@@ -66,7 +67,7 @@ def run():
args = parse_arguments() args = parse_arguments()
if args.verbose: if args.verbose:
logger.setLevel(logging.INFO) logger.setLevel(logging.INFO)
import_kegg_ko = ImportKEGGKO(args.url) import_kegg_ko = ImportKEGGKO(args.url, args.jwt_token)
import_kegg_ko.load_all_kegg_ko() import_kegg_ko.load_all_kegg_ko()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment