Skip to content
Merged
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 src/MGRAST/lib/Auth.pm
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ sub authenticate {
$json->allow_nonref;
my $agent = LWP::UserAgent->new;
eval {
my @args = ();#('Authorization', "OAuth ".$Conf::mgrast_oauth_token);
my @args = ('Authorization', "mgrast ".$pref->[0]->{value});
my $url = $Conf::shock_url.'/node/'.$nodeid;
my $get = $agent->get($url, @args);
$response = $json->decode( $get->content );
Expand Down
23 changes: 21 additions & 2 deletions src/MGRAST/lib/resources/project.pm
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,32 @@ sub prepare_data {
$obj->{samples} = \@samples;
$obj->{libraries} = \@libraries;
}
if (($self->cgi->param('verbosity') eq 'verbose') || ($self->cgi->param('verbosity') eq 'full')) {
if (($self->cgi->param('verbosity') eq 'verbose') || ($self->cgi->param('verbosity') eq 'full') || ($self->cgi->param('verbosity') eq 'summary')) {
my $metadata = $project->data();
my $desc = $metadata->{project_description} || $metadata->{study_abstract} || " - ";
my $fund = $metadata->{project_funding} || " - ";
$obj->{metadata} = $metadata;
$obj->{description} = $desc;
$obj->{funding_source} = $fund;
$obj->{funding_source} = $fund;

if ($self->cgi->param('verbosity') eq 'summary') {
my $jdata = $project->metagenomes_summary();
$obj->{metagenomes} = [];
foreach my $row (@$jdata) {
push(@{$obj->{metagenomes}}, { metagenome_id => $row->[0],
name => $row->[1],
basepairs => $row->[2],
sequences => $row->[3],
biome => $row->[4],
feature => $row->[5],
material => $row->[6],
location => $row->[7],
country => $row->[8],
coordinates => $row->[9],
sequence_type => $row->[10],
sequencing_method => $row->[11] });
}
}
} elsif ($self->cgi->param('verbosity') ne 'minimal') {
$self->return_data( {"ERROR" => "invalid value for option verbosity"}, 400 );
}
Expand Down
106 changes: 78 additions & 28 deletions src/MGRAST/lib/resources/resource.pm
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,12 @@ sub download_text {

# stream a file from shock to browser
sub return_shock_file {
my ($self, $id, $size, $name, $auth) = @_;
my ($self, $id, $size, $name, $auth, $authPrefix) = @_;

if (! $authPrefix) {
$authPrefix = "OAuth";
}

my $response = undef;
# print headers
print "Content-Type:application/x-download\n";
Expand All @@ -560,7 +564,7 @@ sub return_shock_file {
eval {
my $url = $Conf::shock_url.'/node/'.$id.'?download_raw';
my @args = (
$auth ? ('Authorization', "OAuth $auth") : (),
$auth ? ('Authorization', "$authPrefix $auth") : (),
':read_size_hint', 8192,
':content_cb', sub{ my ($chunk) = @_; print $chunk; }
);
Expand All @@ -575,12 +579,16 @@ sub return_shock_file {

## download array of info for metagenome files in shock
sub get_download_set {
my ($self, $mgid, $auth, $seq_only) = @_;
my ($self, $mgid, $auth, $seq_only, $authPrefix) = @_;

if (! $authPrefix) {
$authPrefix = "OAuth";
}

my %seen = ();
my %subset = ('preprocess' => 1, 'dereplication' => 1, 'screen' => 1);
my $stages = [];
my $mgdata = $self->get_shock_query({'type' => 'metagenome', 'id' => 'mgm'.$mgid}, $auth);
my $mgdata = $self->get_shock_query({'type' => 'metagenome', 'id' => 'mgm'.$mgid}, $auth, $authPrefix);
@$mgdata = grep { exists($_->{attributes}{stage_id}) && exists($_->{attributes}{data_type}) } @$mgdata;
@$mgdata = sort { ($a->{attributes}{stage_id} cmp $b->{attributes}{stage_id}) ||
($a->{attributes}{data_type} cmp $b->{attributes}{data_type}) } @$mgdata;
Expand Down Expand Up @@ -665,16 +673,20 @@ sub get_download_set {

# add or delete an ACL based on username
sub edit_shock_acl {
my ($self, $id, $auth, $user, $action, $acl) = @_;
my ($self, $id, $auth, $user, $action, $acl, $authPrefix) = @_;

if (! $authPrefix) {
$authPrefix = "OAuth";
}

my $response = undef;
my $url = $Conf::shock_url.'/node/'.$id.'/acl/'.$acl.'?users='.$user;
eval {
my $tmp = undef;
if ($action eq 'delete') {
$tmp = $self->agent->delete($url, 'Authorization' => "OAuth $auth");
$tmp = $self->agent->delete($url, 'Authorization' => "$authPrefix $auth");
} elsif ($action eq 'put') {
$tmp = $self->agent->put($url, 'Authorization' => "OAuth $auth");
$tmp = $self->agent->put($url, 'Authorization' => "$authPrefix $auth");
} else {
$self->return_data( {"ERROR" => "Invalid Shock ACL action: $action"}, 500 );
}
Expand All @@ -692,8 +704,11 @@ sub edit_shock_acl {
# create node with optional file and/or attributes
# file is json struct by default
sub set_shock_node {
my ($self, $name, $file, $attr, $auth, $not_json) = @_;
my ($self, $name, $file, $attr, $auth, $not_json, $authPrefix) = @_;

if (! $authPrefix) {
$authPrefix = "OAuth";
}
my $response = undef;
my $content = {};
if ($file) {
Expand All @@ -705,7 +720,7 @@ sub set_shock_node {
}
eval {
my @args = (
$auth ? ('Authorization', "OAuth $auth") : (),
$auth ? ('Authorization', "$authPrefix $auth") : (),
'Content_Type', 'multipart/form-data',
$content ? ('Content', $content) : ()
);
Expand All @@ -723,13 +738,17 @@ sub set_shock_node {

# set node file_name
sub update_shock_node_file_name {
my ($self, $id, $fname, $auth) = @_;
my ($self, $id, $fname, $auth, $authPrefix) = @_;

if (! $authPrefix) {
$authPrefix = "OAuth";
}

my $response = undef;
my $content = {file_name => $fname};
eval {
my @args = (
$auth ? ('Authorization', "OAuth $auth") : (),
$auth ? ('Authorization', "$authPrefix $auth") : (),
'Content_Type', 'multipart/form-data',
$content ? ('Content', $content) : ()
);
Expand All @@ -750,13 +769,16 @@ sub update_shock_node_file_name {

# edit node attributes
sub update_shock_node {
my ($self, $id, $attr, $auth) = @_;
my ($self, $id, $attr, $auth, $authPrefix) = @_;

if (! $authPrefix) {
$authPrefix = "OAuth";
}
my $response = undef;
my $content = {attributes => [undef, "n/a", Content => $self->json->encode($attr)]};
eval {
my @args = (
$auth ? ('Authorization', "OAuth $auth") : (),
$auth ? ('Authorization', "$authPrefix $auth") : (),
'Content_Type', 'multipart/form-data',
$content ? ('Content', $content) : ()
);
Expand All @@ -776,11 +798,15 @@ sub update_shock_node {

# get node contents
sub get_shock_node {
my ($self, $id, $auth) = @_;
my ($self, $id, $auth, $authPrefix) = @_;

if (! $authPrefix) {
$authPrefix = "OAuth";
}

my $response = undef;
eval {
my @args = $auth ? ('Authorization', "OAuth $auth") : ();
my @args = $auth ? ('Authorization', "$authPrefix $auth") : ();
my $get = $self->agent->get($Conf::shock_url.'/node/'.$id, @args);
$response = $self->json->decode( $get->content );
};
Expand All @@ -795,11 +821,15 @@ sub get_shock_node {

# get the shock preauth url for a file
sub get_shock_preauth {
my ($self, $id, $auth, $fn) = @_;
my ($self, $id, $auth, $fn, $authPrefix) = @_;

if (! $authPrefix) {
$authPrefix = "OAuth";
}

my $response = undef;
eval {
my @args = $auth ? ('Authorization', "OAuth $auth") : ();
my @args = $auth ? ('Authorization', "$authPrefix $auth") : ();
my $get = $self->agent->get($Conf::shock_url.'/node/'.$id.'?download_url'.($fn ? "&filename=".$fn : ""), @args);
$response = $self->json->decode( $get->content );
};
Expand All @@ -814,11 +844,15 @@ sub get_shock_preauth {

# write file content to given filepath, else return file content as string
sub get_shock_file {
my ($self, $id, $file, $auth, $index) = @_;
my ($self, $id, $file, $auth, $index, $authPrefix) = @_;

if (! $authPrefix) {
$authPrefix = "OAuth";
}

my $response = undef;
my $fhdl = undef;
my @args = $auth ? ('Authorization', "OAuth $auth") : ();
my @args = $auth ? ('Authorization', "$authPrefix $auth") : ();

if ($file) {
open($fhdl, ">$file") || return undef;
Expand All @@ -840,15 +874,19 @@ sub get_shock_file {

# get list of nodes for query
sub get_shock_query {
my ($self, $params, $auth) = @_;

my ($self, $params, $auth, $authPrefix) = @_;

if (! $authPrefix) {
$authPrefix = "OAuth";
}

my $response = undef;
my $query = '?query&limit=0';
if ($params && (scalar(keys %$params) > 0)) {
map { $query .= '&'.$_.'='.$params->{$_} } keys %$params;
}
eval {
my @args = $auth ? ('Authorization', "OAuth $auth") : ();
my @args = $auth ? ('Authorization', "$authPrefix $auth") : ();
my $get = $self->agent->get($Conf::shock_url.'/node'.$query, @args);
$response = $self->json->decode( $get->content );
};
Expand All @@ -863,7 +901,11 @@ sub get_shock_query {

# submit job to awe
sub post_awe_job {
my ($self, $workflow, $shock_auth, $awe_auth, $is_string) = @_;
my ($self, $workflow, $shock_auth, $awe_auth, $is_string, $authPrefix) = @_;

if (! $authPrefix) {
$authPrefix = "OAuth";
}

my $content = undef;
if ($is_string) {
Expand All @@ -876,7 +918,7 @@ sub post_awe_job {
eval {
my $post = $self->agent->post($Conf::awe_url.'/job',
'Datatoken', $shock_auth,
'Authorization', 'OAuth '.$awe_auth,
'Authorization', "$authPrefix ".$awe_auth,
'Content-Type', 'multipart/form-data',
'Content', $content);
$response = $self->json->decode( $post->content );
Expand All @@ -893,11 +935,15 @@ sub post_awe_job {

# PUT command to perfrom action on a job
sub awe_job_action {
my ($self, $id, $action, $auth) = @_;
my ($self, $id, $action, $auth, $authPrefix) = @_;

if (! $authPrefix) {
$authPrefix = "OAuth";
}

my $response = undef;
eval {
my @args = $auth ? ('Authorization', "OAuth $auth") : ();
my @args = $auth ? ('Authorization', "$authPrefix $auth") : ();
my $req = POST($Conf::awe_url.'/job/'.$id.'?'.$action, @args);
$req->method('PUT');
my $put = $self->agent->request($req);
Expand All @@ -912,8 +958,12 @@ sub awe_job_action {

# get list of jobs for query
sub get_awe_query {
my ($self, $params, $auth) = @_;
my ($self, $params, $auth, $authPrefix) = @_;

if (! $authPrefix) {
$authPrefix = "OAuth";
}

my $response = undef;
my $query = '?query';
if ($params && (scalar(keys %$params) > 0)) {
Expand All @@ -922,7 +972,7 @@ sub get_awe_query {
}
}
eval {
my @args = $auth ? ('Authorization', "OAuth $auth") : ();
my @args = $auth ? ('Authorization', "$authPrefix $auth") : ();
my $get = $self->agent->get($Conf::awe_url.'/job'.$query, @args);
$response = $self->json->decode( $get->content );
};
Expand Down
22 changes: 19 additions & 3 deletions src/MGRAST/lib/resources/user.pm
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,22 @@ sub instance {

# preferences were passed
if (defined $rest->[1] && $rest->[1] eq "preferences") {
my $userToken = $master->Preferences->get_objects({ user => $user, name => "WebServicesKey" });
if (scalar(@$userToken)) {
$userToken = $userToken->[0]->{value};
} else {
$self->return_data( {"ERROR" => "insufficient permissions for this user call"}, 401 );
}
my $prefs = { 'type' => 'preference', 'app' => 'MGRAST', 'id' => 'mgu'.$self->user->_id, "pref" => $self->json->decode($self->cgi->param('prefs')) };

my $pref_id = $master->Preferences->get_objects({ user => $user, name => "shock_pref_node" });
my $nodeid;
my $retval = {};
if (scalar(@$pref_id)) {
$nodeid = $pref_id->[0]->{value};
$retval = $self->update_shock_node($nodeid, $prefs);#, $self->mgrast_token);
$retval = $self->update_shock_node($nodeid, $prefs, $userToken, "mgrast");
} else {
$retval = $self->set_shock_node("preferences", undef, $prefs);#, $self->mgrast_token);
$retval = $self->set_shock_node("preferences", undef, $prefs, $userToken, undef, "mgrast");
$master->Preferences->create({ user => $user, name => "shock_pref_node", value => $retval->{id} });
}
$self->return_data( {"OK" => $retval->{attributes}->{pref}}, 200 );
Expand Down Expand Up @@ -430,7 +436,17 @@ sub instance {
}
}
if ($nodeid) {
my $shockprefs = $self->get_shock_node($nodeid, $self->mgrast_token);
my $userToken;
foreach my $p (@$prefs) {
if ($p->{name} eq "WebServicesKey") {
$userToken = $p->{value};
last;
}
}
unless ($userToken) {
$self->return_data( {"ERROR" => "insufficient permissions for this user call"}, 401 );
}
my $shockprefs = $self->get_shock_node($nodeid, $userToken, "mgrast");
if ($shockprefs) {
push(@{$user->{preferences}}, { name => 'shock', value => $shockprefs->{attributes}->{pref} } );
}
Expand Down