Skip to content

Commit

Permalink
Merge 6ae1b46 into bcea95d
Browse files Browse the repository at this point in the history
  • Loading branch information
netsettler committed Aug 17, 2020
2 parents bcea95d + 6ae1b46 commit 781ef9d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 62 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
# Note: Various modules refer to this system as "encoded", not "cgap-portal".
name = "encoded"
version = "2.4.7"
version = "2.4.8"
description = "Clinical Genomics Analysis Platform"
authors = ["4DN-DCIC Team <support@4dnucleome.org>"]
license = "MIT"
Expand Down
6 changes: 1 addition & 5 deletions src/encoded/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from unittest import mock
from dcicutils.qa_utils import ControlledTime
from ..util import (
debuglog, deduplicate_list, gunzip_content, resolve_file_path, ENCODED_ROOT_DIR, generate_fastq_file,
debuglog, deduplicate_list, gunzip_content, resolve_file_path, ENCODED_ROOT_DIR,
)
from .. import util as util_module

Expand Down Expand Up @@ -231,7 +231,3 @@ def log_content():
os.remove(filename)
except Exception:
pass


# def test_generate_fastq_file():
# ... Need test of generate_fastq_file here ...
15 changes: 3 additions & 12 deletions src/encoded/types/cohort.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from snovault.util import debug_log
from webtest import TestApp
from xml.etree.ElementTree import fromstring
from .base import Item, get_item_or_none
from .base import Item
from ..util import get_trusted_email


log = structlog.getLogger(__name__)
Expand Down Expand Up @@ -115,17 +116,7 @@ def process_pedigree(context, request):
ped_timestamp = ped_datetime.isoformat() + '+00:00'
app = get_app(config_uri, 'app')
# get user email for TestApp authentication
email = getattr(request, '_auth0_authenticated', None)
if not email:
user_uuid = None
for principal in request.effective_principals:
if principal.startswith('userid.'):
user_uuid = principal[7:]
break
if not user_uuid:
raise HTTPUnprocessableEntity('Cohort %s: Must provide authentication' % cohort)
user_props = get_item_or_none(request, user_uuid)
email = user_props['email']
email = get_trusted_email(request, context="Cohort %s" % cohort)
environ = {'HTTP_ACCEPT': 'application/json', 'REMOTE_USER': email}
testapp = TestApp(app, environ)

Expand Down
13 changes: 2 additions & 11 deletions src/encoded/types/family.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from webtest import TestApp
from xml.etree.ElementTree import fromstring
from .base import Item, get_item_or_none
from ..util import get_trusted_email


log = structlog.getLogger(__name__)
Expand Down Expand Up @@ -598,17 +599,7 @@ def process_pedigree(context, request):
ped_timestamp = ped_datetime.isoformat() + '+00:00'
app = get_app(config_uri, 'app')
# get user email for TestApp authentication
email = getattr(request, '_auth0_authenticated', None)
if not email:
user_uuid = None
for principal in request.effective_principals:
if principal.startswith('userid.'):
user_uuid = principal[7:]
break
if not user_uuid:
raise HTTPUnprocessableEntity('Family %s: Must provide authentication' % family_item)
user_props = get_item_or_none(request, user_uuid)
email = user_props['email']
email = get_trusted_email(request, context="Family %s" % family_item)
environ = {'HTTP_ACCEPT': 'application/json', 'REMOTE_USER': email}
testapp = TestApp(app, environ)

Expand Down
63 changes: 30 additions & 33 deletions src/encoded/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import gzip
import io
import os
import random
import pyramid.request
import tempfile

from dcicutils.misc_utils import check_true
from io import BytesIO
from pyramid.httpexceptions import HTTPUnprocessableEntity
from snovault import COLLECTIONS, Collection
from snovault.crud_views import collection_add as sno_collection_add
from snovault.embed import make_subrequest
from snovault.schema_utils import validate_request
from typing import Type
from .types.base import get_item_or_none


ENCODED_ROOT_DIR = os.path.dirname(__file__)
Expand Down Expand Up @@ -238,38 +238,35 @@ def create_empty_s3_file(s3_client, bucket: str, key: str):
s3_client.upload_file(empty_file, Bucket=bucket, Key=key)


def generate_fastq_file(filename, num=10, length=10):
def get_trusted_email(request, context=None, raise_errors=True):
"""
Creates a new fastq file with the given name, containing (pseudo)randomly generated content.
Get an email address on behalf of which we can issue other requests.
Example usage:
fastq_generator('fastq_sample.fastq.gz', 25, 50)
creates a new fastq file with 25 sequences, each of length 50.
fastq_generator('fastq_sample.fastq.gz')
creates a new fastq file with default characteristics (10 sequences, each of length 10).
Args:
filename str: the name of a file to create
num int: the number of random sequences (default 10)
length int: the length of the random sequences (default 10)
Returns:
the filename
If auth0 has authenticated user info to offer, return that.
Otherwise, look for a userid.xxx among request.effective_principals and get the email from that.
This will raise HTTPUnprocessableEntity if there's a problem obtaining the mail.
"""
if not filename.endswith('.fastq.gz'):
filename = filename.rstrip('fastq').rstrip('fq').rstrip('.') + '.fastq.gz'
content = ''
bases = 'ACTG'

for i in range(num):
content += '@SEQUENCE{} length={}\n'.format(i, length)
content += ''.join(random.choice(bases) for i in range(length)) + '\n'
content += '+\n'
content += 'I' * length + '\n'
with gzip.open(filename, 'w') as outfile:
outfile.write(content.encode('ascii'))

return filename
try:
# import pdb;pdb.set_trace()
context = context or "Requirement"
email = getattr(request, '_auth0_authenticated', None)
if not email:
user_uuid = None
for principal in request.effective_principals:
if principal.startswith('userid.'):
user_uuid = principal[7:]
break
if not user_uuid:
raise HTTPUnprocessableEntity('%s: Must provide authentication' % context)
user_props = get_item_or_none(request, user_uuid)
if not user_props:
raise HTTPUnprocessableEntity('%s: User profile missing' % context)
if 'email' not in user_props:
raise HTTPUnprocessableEntity('%s: Entry for "email" missing in user profile.' % context)
email = user_props['email']
return email
except Exception:
if raise_errors:
raise
return None

0 comments on commit 781ef9d

Please sign in to comment.