Skip to content
Merged
Show file tree
Hide file tree
Changes from 35 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
9 changes: 9 additions & 0 deletions qiita_core/configuration_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ def _get_main(self, config):
self.valid_upload_extension = []
print 'No files will be allowed to be uploaded.'

self.certificate_file = config.get('main', 'CERTIFICATE_FILE')
if not self.certificate_file:
self.certificate_file = join(install_dir, 'qiita_core',
'support_files', 'server.crt')
self.key_file = config.get('main', 'KEY_FILE')
if not self.key_file:
self.key_file = join(install_dir, 'qiita_core', 'support_files',
'server.key')

def _get_postgres(self, config):
"""Get the configuration of the postgres section"""
self.user = config.get('postgres', 'USER')
Expand Down
10 changes: 7 additions & 3 deletions qiita_core/support_files/config_test.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ LOG_PATH =
REQUIRE_APPROVAL = True

# Base URL: DO NOT ADD TRAILING SLASH
BASE_URL = http://localhost
BASE_URL = https://localhost

# Download path files
UPLOAD_DATA_DIR = /tmp/
Expand All @@ -39,12 +39,16 @@ BASE_DATA_DIR =
# Valid upload extension, comma separated. Empty for no uploads
VALID_UPLOAD_EXTENSION = fastq,fastq.gz,txt,tsv,sff,fna,qual

#Portal the site is working under
# Portal the site is working under
PORTAL = QIITA

#Script used for launching plugins
# Script used for launching plugins
PLUGIN_LAUNCHER = qiita-plugin-launcher

# Webserver certificate files
CERTIFICATE_FILE =
KEY_FILE =

# ----------------------------- SMTP settings -----------------------------
[smtp]
# The hostname to connect to
Expand Down
20 changes: 20 additions & 0 deletions qiita_core/support_files/server.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-----BEGIN CERTIFICATE-----
MIIDVjCCAj4CCQCP4XnDqToF2zANBgkqhkiG9w0BAQUFADBtMQswCQYDVQQGEwJV
UzETMBEGA1UECBMKQ2FsaWZvcm5pYTESMBAG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WYSw2
-----END CERTIFICATE-----
17 changes: 17 additions & 0 deletions qiita_core/support_files/server.csr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-----BEGIN CERTIFICATE REQUEST-----
MIICsjCCAZoCAQAwbTELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWEx
EjAQBgNVBAcTCVNhbiBEaWVnbzENMAsGA1UEChMEVUNTRDESMBAGA1UECxMJS25p
Z2h0TGFiMRIwEAYDVQQDEwlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IB
DwAwggEKAoIBAQC3WCBbgz+Xdamu7j7YKuieeppRYPQiYueR0BuYOOEaIJ0qp1vz
LMt4qKkZpFjfzeB3m8xYewoHUje34TMVaJh/F3XYS/HoxQhdVlKR0KieT7zGWYnl
trUeDLurMStjv4c62CqbXKXKpO45nK/dSa/RboRMtXP9qV/PFOWoCS+4mfsjtGtt
jzUjdvlI5TElO2P2k/CRm1U4PSFrcUfQsG6UTiiLqtBCHMhtQNYshNlEK16mVXmK
RsLcmponukOJic4g+dFHRQX7F3JOI69I0fxasq4B0YY373Q8O3x+BA7Cm0TmX9Eb
KgnaifueVKPlysO1jNdcNjDQMLO4UbXadlUXAgMBAAGgADANBgkqhkiG9w0BAQUF
AAOCAQEAJD/s9Z150miwTYW08DklPoCjR1NijtFBUUkh176GCljNFe+rhnn2OLiV
skunJ4EiVAZ8O3bjgxGc53FnEMVrwisFugvnORTJAZpp7tKxBqpP++gqXf79wElN
ySTLjg9vFQgDjUxM2gO/8lH12HBw9xUDHFN2hOZ9ozPFf7KZUa6KUzh2AgHJ4UCF
9kFceNAvUamAHjv7BwDqoakLTuEBSZOycimDKiW8aBFGYCHFO2NMCzAKyVxmLtkB
K7+e5iWwvy3LewiPX/eK+jtRVwY+ujcvOZeCv6Th+oQv1BxstpJwOlca+5s1Rdke
kUu++nvrQUvWSsdQzxZq855r2TBA/w==
-----END CERTIFICATE REQUEST-----
27 changes: 27 additions & 0 deletions qiita_core/support_files/server.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm missing something here...

Should this be a public key, not a private key?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, the server needs the private key to run.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the server key be automatically regenerated? Otherwise, distributing a
private key is usually not a good idea
On Dec 22, 2015 09:13, "Jose Navas" notifications@github.com wrote:

In qiita_core/support_files/server.key
#1584 (comment):

@@ -0,0 +1,27 @@
+-----BEGIN RSA PRIVATE KEY-----

Nope, the server needs the private key to run.


Reply to this email directly or view it on GitHub
https://github.com/biocore/qiita/pull/1584/files#r48275147.

MIIEogIBAAKCAQEAt1ggW4M/l3Wpru4+2CronnqaUWD0ImLnkdAbmDjhGiCdKqdb
8yzLeKipGaRY383gd5vMWHsKB1I3t+EzFWiYfxd12Evx6MUIXVZSkdConk+8xlmJ
5ba1Hgy7qzErY7+HOtgqm1ylyqTuOZyv3Umv0W6ETLVz/alfzxTlqAkvuJn7I7Rr
bY81I3b5SOUxJTtj9pPwkZtVOD0ha3FH0LBulE4oi6rQQhzIbUDWLITZRCteplV5
ikbC3JqaJ7pDiYnOIPnRR0UF+xdyTiOvSNH8WrKuAdGGN+90PDt8fgQOwptE5l/R
GyoJ2on7nlSj5crDtYzXXDYw0DCzuFG12nZVFwIDAQABAoIBAAWPwsuD27X4d8E6
sOVVx+Cmz2+QhVdVsLiXm36umwVz39CfawahYTqzww1oEtoXIKwAKd61PMSkFdSa
HDaWCaoxR/3br+bjszFBoReTQMosmQlbRfeV50CWGktDHpHUCYIbdI9p7A2Nmzxc
KGmKBq9Pruu0xWP4c1OQyraiMLRkyjdPxV42t/cpolzkk+zt94om2DdmaZHgrwfM
TIC/PkgINlwIQfATFSaZSeTQ3bhfMzlLLaiDicf/ZUF8HnIToQjXwfApLv9/2DQB
BBjFXVXPODYADG0ddczX4GflO4cdyKeJALooQ2v1R7+F7XbTCHGSewFQsYN1cebP
Shnw4iECgYEA3t2wik92tLDD9yTw3Gl7KcoafW7yVMVjY7DrQqx5VLNN6H2ToIw0
1eaWx1xvabh8F4GyZ6hLqQJs2yOvuBcdEgvjs7rEAktT9w60MNQHP/9LxC7AloUR
QCpcp4kgf6QuYNBH5eeDMPXt/AyItlTBu1tLWvIyArZDFyFpQ1R+UFUCgYEA0po7
78yzQ2zTxxg+Zg1oFhojo8eqbBCxcnaeMMobaUvRlYdQn3FEgYEzAi39ajw+ApKO
megCBEc58mlWRaCEBzmOSdttCL/hZR5QD3tMyE97xZxu4qvty7mS8+Qx7VXi4E+R
9iB3QW2IdnO0ny0LL+/FRlseFd9Xi48HPEfGC7sCgYBZ4bC0Z03pm6y8/PIDAquA
dBjw45DqLV1jNFP9ZM/eIB5YmGS0iDc62S+QIbBxQ80QMeeAtLgm5mp+isrwhKnd
wFvJ/ZXVkwm/BvgXBTwTTGQDMBPN4MbPSQZrLvujXtSxiO6mQxN+6IBdebSdTFuB
s1UVzb3rqBQwvPHWDLqQrQKBgEQoemFfZFzb6aYzqG4qxJbymro0smkK9gLPdN7h
agGn8gpsoqEXbU5kW/fGno81M/RtLg2NUqnDy3MyuCMMke4sqGoqw5zjTLUHHG4G
P5FMeAg6WoCtl+YpBvA72BSxiR2DYv++/hmEs3dydvBVCZvYA4aDkrcNcy3Nek/+
ApBlAoGAQOXrFJa0kMKK89D6luYd7KWTHze7fSNmohxXKm4OW/9V/IxcDFASRasm
Ld45yQ6CRk42Ry0xA/TiEs9Gv8hPrJEzNXVzBMA+s0h6uY13p5cMgZdMA7XotM95
UgtsatiprRqzpYQItbPCYyPmDAscA+jsdoZzbXFjlOYz/9BZRCc=
-----END RSA PRIVATE KEY-----
119 changes: 119 additions & 0 deletions qiita_db/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

from __future__ import division
from future.utils import viewitems
from itertools import chain
from datetime import datetime

import networkx as nx

import qiita_db as qdb


Expand Down Expand Up @@ -79,6 +82,63 @@ def iter_public(cls):
"""
return cls.iter_by_visibility('public')

@classmethod
def copy(cls, artifact, prep_template):
"""Creates a copy of `artifact` and attaches it to `prep_template`

Parameters
----------
artifact : qiita_db.artifact.Artifact
Artifact to copy from
prep_template : qiita_db.metadata_template.prep_template.PrepTemplate
The prep template to attach the new artifact to

Returns
-------
qiita_db.artifact.Artifact
A new instance of Artifact
"""
with qdb.sql_connection.TRN:
visibility_id = qdb.util.convert_to_id("sandbox", "visibility")
atype = artifact.artifact_type
atype_id = qdb.util.convert_to_id(atype, "artifact_type")
dtype_id = qdb.util.convert_to_id(
prep_template.data_type(), "data_type")
sql = """INSERT INTO qiita.artifact (
generated_timestamp, visibility_id, artifact_type_id,
data_type_id, can_be_submitted_to_ebi,
can_be_submitted_to_vamps, submitted_to_vamps)
VALUES (%s, %s, %s, %s, %s, %s, %s)
RETURNING artifact_id"""
sql_args = [datetime.now(), visibility_id, atype_id, dtype_id,
artifact.can_be_submitted_to_ebi,
artifact.can_be_submitted_to_vamps, False]
qdb.sql_connection.TRN.add(sql, sql_args)
a_id = qdb.sql_connection.TRN.execute_fetchlast()

# Associate the artifact with the prep template
instance = cls(a_id)
prep_template.artifact = instance

# Associate the artifact with the study
sql = """INSERT INTO qiita.study_artifact (study_id, artifact_id)
VALUES (%s, %s)"""
sql_args = [prep_template.study_id, a_id]
qdb.sql_connection.TRN.add(sql, sql_args)

# Associate the artifact with its filepaths
filepaths = [(fp, f_type) for _, fp, f_type in artifact.filepaths]
fp_ids = qdb.util.insert_filepaths(
filepaths, a_id, atype, "filepath", copy=True)
sql = """INSERT INTO qiita.artifact_filepath
(artifact_id, filepath_id)
VALUES (%s, %s)"""
sql_args = [[a_id, fp_id] for fp_id in fp_ids]
qdb.sql_connection.TRN.add(sql, sql_args, many=True)
qdb.sql_connection.TRN.execute()

return instance

@classmethod
def create(cls, filepaths, artifact_type, prep_template=None,
parents=None, processing_parameters=None,
Expand Down Expand Up @@ -646,6 +706,65 @@ def parents(self):
return [Artifact(p_id)
for p_id in qdb.sql_connection.TRN.execute_fetchflatten()]

def _create_lineage_graph_from_edge_list(self, edge_list):
"""Generates an artifact graph from the given `edge_list`

Parameters
----------
edge_list : list of (int, int)
List of (parent_artifact_id, artifact_id)

Returns
-------
networkx.DiGraph
The graph representing the artifact lineage stored in `edge_list`
"""
lineage = nx.DiGraph()
# In case the edge list is empty, only 'self' is present in the graph
if edge_list:
# By creating all the artifacts here we are saving DB calls
nodes = {a_id: Artifact(a_id)
for a_id in set(chain.from_iterable(edge_list))}

for parent, child in edge_list:
lineage.add_edge(nodes[parent], nodes[child])
else:
lineage.add_node(self)

return lineage

@property
def ancestors(self):
"""Returns the ancestors of the artifact

Returns
-------
networkx.DiGraph
The ancestors of the artifact
"""
with qdb.sql_connection.TRN:
sql = """SELECT parent_id, artifact_id
FROM qiita.artifact_ancestry(%s)"""
qdb.sql_connection.TRN.add(sql, [self.id])
edges = qdb.sql_connection.TRN.execute_fetchindex()
return self._create_lineage_graph_from_edge_list(edges)

@property
def descendants(self):
"""Returns the descendants of the artifact

Returns
-------
networkx.DiGraph
The descendants of the artifact
"""
with qdb.sql_connection.TRN:
sql = """SELECT parent_id, artifact_id
FROM qiita.artifact_descendants(%s)"""
qdb.sql_connection.TRN.add(sql, [self.id])
edges = qdb.sql_connection.TRN.execute_fetchindex()
return self._create_lineage_graph_from_edge_list(edges)

@property
def children(self):
"""Returns the list of children of the artifact
Expand Down
39 changes: 39 additions & 0 deletions qiita_db/support_files/patches/33.sql
Original file line number Diff line number Diff line change
Expand Up @@ -811,3 +811,42 @@ BEGIN
END IF;
END
$$ LANGUAGE plpgsql;


-- Create a function to return the ancestors of an Artifact
CREATE FUNCTION qiita.artifact_ancestry(a_id bigint) RETURNS SETOF qiita.parent_artifact AS $$
BEGIN
IF EXISTS(SELECT * FROM qiita.parent_artifact WHERE artifact_id = a_id) THEN
RETURN QUERY WITH RECURSIVE root AS (
SELECT artifact_id, parent_id
FROM qiita.parent_artifact
WHERE artifact_id = a_id
UNION
SELECT p.artifact_id, p.parent_id
FROM qiita.parent_artifact p
JOIN root r ON (r.parent_id = p.artifact_id)
)
SELECT DISTINCT artifact_id, parent_id
FROM root;
END IF;
END
$$ LANGUAGE plpgsql;

-- Create a function to return the descendants of an artifact
CREATE FUNCTION qiita.artifact_descendants(a_id bigint) RETURNS SETOF qiita.parent_artifact AS $$
BEGIN
IF EXISTS(SELECT * FROM qiita.parent_artifact WHERE parent_id = a_id) THEN
RETURN QUERY WITH RECURSIVE root AS (
SELECT artifact_id, parent_id
FROM qiita.parent_artifact
WHERE parent_id = a_id
UNION
SELECT p.artifact_id, p.parent_id
FROM qiita.parent_artifact p
JOIN root r ON (r.artifact_id = p.parent_id)
)
SELECT DISTINCT artifact_id, parent_id
FROM root;
END IF;
END
$$ LANGUAGE plpgsql;
18 changes: 18 additions & 0 deletions qiita_db/support_files/patches/python_patches/34.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from random import SystemRandom
from string import ascii_letters, digits

from qiita_db.sql_connection import TRN

pool = ascii_letters + digits
client_id = ''.join([SystemRandom().choice(pool) for _ in range(50)])
client_secret = ''.join([SystemRandom().choice(pool) for _ in range(255)])

with TRN:
sql = """INSERT INTO qiita.oauth_identifiers (client_id, client_secret)
VALUES (%s, %s)"""
TRN.add(sql, [client_id, client_secret])
TRN.execute()

print "Please, add these values to your target gene plugin configuration file:"
print "CLIENT_ID = %s" % client_id
print "CLIENT_SECRET = %s" % client_secret
Loading