From 92bb7f459ff97fffb06294a5235e14938b0bd458 Mon Sep 17 00:00:00 2001 From: Robert Olson Date: Tue, 21 Jul 2015 14:23:57 -0500 Subject: [PATCH 01/21] Fix zero-size update bug --- lib/Bio/P3/Workspace/WorkspaceImpl.pm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/Bio/P3/Workspace/WorkspaceImpl.pm b/lib/Bio/P3/Workspace/WorkspaceImpl.pm index 368a8d5..d785f35 100644 --- a/lib/Bio/P3/Workspace/WorkspaceImpl.pm +++ b/lib/Bio/P3/Workspace/WorkspaceImpl.pm @@ -435,7 +435,7 @@ sub _get_directory_contents { #Retrive objects from mongodb based on input query** sub _query_database { - my ($self,$query,$count) = @_; + my ($self,$query,$count,$update_shock) = @_; if (defined($query->{path})) { $query->{path} =~ s/^\///; $query->{path} =~ s/\/$//; @@ -449,7 +449,7 @@ sub _query_database { while (my $object = $cursor->next) { $object->{wsobj} = $self->_wscache("_uuid",$object->{workspace_uuid}); if ($object->{shock} == 1 && $object->{size} == 0) { - $self->_update_shock_node($object); + $self->_update_shock_node($object,$update_shock); } if (defined($hash->{$object->{workspace_uuid}}->{$object->{path}}->{$object->{name}})) { for (my $i=0; $i < @{$output}; $i++) { @@ -568,7 +568,9 @@ sub _create_shock_node { sub _update_shock_node { my ($self,$object,$force) = @_; - if ($force == 1 || !defined($self->{_shockupdate}->{$object->{uuid}}) || (time() - $self->{_shockupdate}->{$object->{uuid}}) > $self->{_params}->{"update-interval"}) { + if ($force == 1 || + !defined($self->{_shockupdate}->{$object->{uuid}}) || + (time() - $self->{_shockupdate}->{$object->{uuid}}) > $self->{_params}->{"update-interval"}) { my $ua = LWP::UserAgent->new(); my $res = $ua->get($object->{shocknode},Authorization => "OAuth ".$self->_wsauth()); my $json = JSON::XS->new; @@ -993,7 +995,7 @@ sub _list_objects { } else { $query->{path} = $path; } - return $self->_query_database($query,0); + return $self->_query_database($query,0, 1); } #Formating queries to support direct mongo queries - this will need to get far more sophisticated** From fffc6e13fd012e61ee5047a2131c406d1980f513 Mon Sep 17 00:00:00 2001 From: non Date: Tue, 28 Jul 2015 23:50:27 -0500 Subject: [PATCH 02/21] Rolling back makefile changes as they break deploy. --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 806887f..b0f72fb 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ TPAGE_ARGS = --define kb_top=$(TARGET) \ TESTS = $(wildcard t/client-tests/*.t) -all: bin service +all: bin compile-typespec service jarfile: gen_java_client $(SERVER_SPEC) org.patricbrc.Workspace java @@ -84,7 +84,7 @@ bin: $(BIN_PERL) $(BIN_SERVICE_PERL) deploy: deploy-client deploy-service deploy-all: deploy-client deploy-service -deploy-client: deploy-libs deploy-scripts +deploy-client: compile-typespec deploy-docs deploy-libs deploy-scripts deploy-service: deploy-dir deploy-monit deploy-libs deploy-service-scripts $(TPAGE) $(TPAGE_ARGS) service/start_service.tt > $(TARGET)/services/$(SERVICE)/start_service From adfe706f1059e6828a4b69cce265769433025f2b Mon Sep 17 00:00:00 2001 From: India Gordon Date: Mon, 3 Aug 2015 15:20:15 -0500 Subject: [PATCH 03/21] Update and rename LICENSE to LICENSE.md --- LICENSE => LICENSE.md | 1 - 1 file changed, 1 deletion(-) rename LICENSE => LICENSE.md (99%) diff --git a/LICENSE b/LICENSE.md similarity index 99% rename from LICENSE rename to LICENSE.md index f04cee8..69c19dd 100644 --- a/LICENSE +++ b/LICENSE.md @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - From 2db22868ec54a4ad6912ee3795e4fd5e832fd884 Mon Sep 17 00:00:00 2001 From: non Date: Fri, 7 Aug 2015 22:48:48 -0500 Subject: [PATCH 04/21] Minor tweaks to tests and script helper. --- lib/Bio/P3/Workspace/ScriptHelpers.pm | 22 +++++++++++++++++++++- lib/Bio/P3/Workspace/WorkspaceTests.pm | 23 +++++++++++++++-------- t/client-tests/tests.t | 2 +- t/server-tests/tests.t | 2 +- 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/lib/Bio/P3/Workspace/ScriptHelpers.pm b/lib/Bio/P3/Workspace/ScriptHelpers.pm index b5be6e4..ecb03f9 100644 --- a/lib/Bio/P3/Workspace/ScriptHelpers.pm +++ b/lib/Bio/P3/Workspace/ScriptHelpers.pm @@ -321,7 +321,6 @@ sub msClient { } if ($url eq "impl") { require "Bio/ModelSEED/ProbModelSEED/ProbModelSEEDImpl.pm"; - $ENV{KB_DEPLOYMENT_CONFIG} = "/Users/chenry/code/ProbModelSEED/configs/test.cfg"; $Bio::ModelSEED::ProbModelSEED::Service::CallContext = Bio::ModelSEED::ProbModelSEED::Service::CallContext->new(Bio::P3::Workspace::ScriptHelpers::token(),"unknown",Bio::P3::Workspace::ScriptHelpers::user()); my $client = Bio::ModelSEED::ProbModelSEED::ProbModelSEEDImpl->new(); return $client; @@ -329,6 +328,27 @@ sub msClient { return Bio::ModelSEED::ProbModelSEED::ProbModelSEEDClient->new($url,token => Bio::P3::Workspace::ScriptHelpers::token()); } +sub get_workspace_object { + my $ref = shift; + my $options = shift; + my $input = {objects => [$ref]}; + if ($options->{adminmode}) { + $input->{adminmode} = $options->{adminmode}; + } + if ($options->{metadata_only}) { + $input->{metadata_only} = $options->{metadata_only}; + } + my $wc = wsClient(); + my $output = $wc->get($input); + if (defined($output->[0]->[11])) { + my $ua = LWP::UserAgent->new(); + $ua->default_header( "Authorization" => $options->{token} ); + my $res = $ua->get($options->{url}); + $output->[1] = $res->{content}; + } + return $output; +} + sub wsClient { my $url = shift; if (!defined($url)) { diff --git a/lib/Bio/P3/Workspace/WorkspaceTests.pm b/lib/Bio/P3/Workspace/WorkspaceTests.pm index 1cd4a41..9996694 100644 --- a/lib/Bio/P3/Workspace/WorkspaceTests.pm +++ b/lib/Bio/P3/Workspace/WorkspaceTests.pm @@ -7,6 +7,9 @@ use Data::Dumper; use Config::Simple; + my $serverclass = "Bio::P3::Workspace::WorkspaceImpl"; + my $clientclass = "Bio::P3::Workspace::WorkspaceClient"; + sub new { my($class,$bin) = @_; my $c = Config::Simple->new(); @@ -36,12 +39,16 @@ } if (!defined($self->{url}) || $self->{url} eq "impl") { print "Loading server with this config: ".$ENV{KB_DEPLOYMENT_CONFIG}."\n"; - require "Bio/P3/Workspace/WorkspaceImpl.pm"; - $self->{obj} = Bio::P3::Workspace::WorkspaceImpl->new(); + my $classpath = $serverclass; + $classpath =~ s/::/\//g; + require $classpath.".pm"; + $self->{obj} = $serverclass->new(); } else { - require "Bio/P3/Workspace/WorkspaceClient.pm"; - $self->{clientobj} = Bio::P3::Workspace::WorkspaceClient->new($self->{url},token => $self->{token}); - $self->{clientobjtwo} = Bio::P3::Workspace::WorkspaceClient->new($self->{url},token => $self->{tokentwo}); + my $classpath = $clientclass; + $classpath =~ s/::/\//g; + require $classpath.".pm"; + $self->{clientobj} = $clientclass->new($self->{url},token => $self->{token}); + $self->{clientobjtwo} = $clientclass->new($self->{url},token => $self->{tokentwo}); } return bless $self, $class; } @@ -50,9 +57,9 @@ my($self,$user) = @_; if (!defined($self->{url}) || $self->{url} eq "impl") { if ($user == 2) { - $Bio::P3::Workspace::WorkspaceImpl::CallContext = Bio::P3::Workspace::WorkspaceImpl::CallContext->new($self->{tokentwo},"test",$self->{usertwo}); + $Bio::P3::Workspace::WorkspaceImpl::CallContext = CallContext->new($self->{tokentwo},"test",$self->{usertwo}); } else { - $Bio::P3::Workspace::WorkspaceImpl::CallContext = Bio::P3::Workspace::WorkspaceImpl::CallContext->new($self->{token},"test",$self->{user}); + $Bio::P3::Workspace::WorkspaceImpl::CallContext = CallContext->new($self->{token},"test",$self->{user}); } } else { if ($user == 2) { @@ -478,7 +485,7 @@ } { - package Bio::P3::Workspace::WorkspaceImpl::CallContext; + package CallContext; use strict; diff --git a/t/client-tests/tests.t b/t/client-tests/tests.t index 1bbcdb1..f309c2b 100644 --- a/t/client-tests/tests.t +++ b/t/client-tests/tests.t @@ -1,5 +1,5 @@ use FindBin qw($Bin); use Bio::P3::Workspace::WorkspaceTests; -my $tester = Bio::P3::Workspace::WorkspaceTests->new($bin); +my $tester = Bio::P3::Workspace::WorkspaceTests->new($Bin); $tester->run_tests(); \ No newline at end of file diff --git a/t/server-tests/tests.t b/t/server-tests/tests.t index 1bbcdb1..f309c2b 100644 --- a/t/server-tests/tests.t +++ b/t/server-tests/tests.t @@ -1,5 +1,5 @@ use FindBin qw($Bin); use Bio::P3::Workspace::WorkspaceTests; -my $tester = Bio::P3::Workspace::WorkspaceTests->new($bin); +my $tester = Bio::P3::Workspace::WorkspaceTests->new($Bin); $tester->run_tests(); \ No newline at end of file From 4d00719c4cd5c1059b425f6ab59b8ef87cc4452d Mon Sep 17 00:00:00 2001 From: Christopher Henry Date: Tue, 1 Dec 2015 23:16:20 -0600 Subject: [PATCH 05/21] Implementing workspace publication --- lib/Bio/P3/Workspace/ScriptHelpers.pm | 3 ++ lib/Bio/P3/Workspace/WorkspaceClient.pm | 18 +++++---- lib/Bio/P3/Workspace/WorkspaceImpl.pm | 49 ++++++++++++++++++------- lib/Bio/P3/Workspace/WorkspaceTests.pm | 31 ++++++++++++++-- scripts/ws-create.pl | 1 + scripts/ws-ls.pl | 3 ++ 6 files changed, 79 insertions(+), 26 deletions(-) diff --git a/lib/Bio/P3/Workspace/ScriptHelpers.pm b/lib/Bio/P3/Workspace/ScriptHelpers.pm index ecb03f9..a5daab1 100644 --- a/lib/Bio/P3/Workspace/ScriptHelpers.pm +++ b/lib/Bio/P3/Workspace/ScriptHelpers.pm @@ -230,6 +230,9 @@ sub process_paths { if ($paths->[$i] !~ /^\// && $paths->[$i] !~ /^PATRICSOLR/) { $paths->[$i] = Bio::P3::Workspace::ScriptHelpers::directory().$paths->[$i]; } + while ($paths->[$i] =~ m/[^\/]+\/\.\.\/*/) { + $paths->[$i] =~ s/[^\/]+\/\.\.\/*//g; + } } return $paths; } diff --git a/lib/Bio/P3/Workspace/WorkspaceClient.pm b/lib/Bio/P3/Workspace/WorkspaceClient.pm index b9d7c87..1541348 100644 --- a/lib/Bio/P3/Workspace/WorkspaceClient.pm +++ b/lib/Bio/P3/Workspace/WorkspaceClient.pm @@ -84,15 +84,17 @@ sub new # # We create an auth token, passing through the arguments that we were (hopefully) given. - { - my $token = Bio::KBase::AuthToken->new(@args); + #{ + #my $token = Bio::KBase::AuthToken->new(@args); - if (!$token->error_message) - { - $self->{token} = $token->token; - $self->{client}->{token} = $token->token; - } - } + #if (!$token->error_message) + #{ + # $self->{token} = $token->token; + # $self->{client}->{token} = $token->token; + #} + #} + $self->{token} = $args[1]; + $self->{client}->{token} = $args[1]; my $ua = $self->{client}->ua; my $timeout = $ENV{CDMI_TIMEOUT} || (30 * 60); diff --git a/lib/Bio/P3/Workspace/WorkspaceImpl.pm b/lib/Bio/P3/Workspace/WorkspaceImpl.pm index e13c852..0a30d02 100644 --- a/lib/Bio/P3/Workspace/WorkspaceImpl.pm +++ b/lib/Bio/P3/Workspace/WorkspaceImpl.pm @@ -134,7 +134,7 @@ sub _url { sub _error { my($self,$msg) = @_; $msg = "_ERROR_".$msg."_ERROR_"; - Bio::KBase::Exceptions::ArgumentValidationError->throw(error => $msg,method_name => $self->_current_method()); + Bio::KBase::Exceptions::ArgumentValidationError->throw(error => $msg,method_name => "");#$self->_current_method()); } sub _db_path { @@ -165,14 +165,7 @@ sub _user_is_admin { sub _updateDB { my ($self,$name,$query,$update) = @_; - my $data = $self->_mongodb()->run_command({ - findAndModify => $name, - query => $query, - update => $update - }); - if (ref($data) ne "HASH" || !defined($data->{value})) { - return 0; - } + $self->_mongodb()->get_collection($name)->update($query,$update); return 1; } @@ -257,7 +250,7 @@ sub _retrieve_object_data { #Validating that the input permissions have a recognizable value** sub _validate_workspace_permission { my ($self,$input) = @_; - if ($input !~ m/^[awron]$/) { + if ($input !~ m/^[awronp]$/) { $self->_error("Input permissions ".$input." invalid!"); } return $input; @@ -308,12 +301,16 @@ sub _validate_object_type { sub _get_ws_permission { my ($self,$wsobj) = @_; + if ($wsobj->{global_permission} eq "p") { + return "p"; + } my $curruser = $self->_getUsername(); if ($wsobj->{owner} eq $curruser) { return "o"; } my $values = { n => 0, + p => 1, r => 1, w => 2, a => 3, @@ -336,6 +333,7 @@ sub _check_ws_permissions { my $perm = $self->_get_ws_permission($wsobj); my $values = { n => 0, + p => 1, r => 1, w => 2, a => 3, @@ -561,9 +559,7 @@ sub _create_shock_node { my $res = $ua->post($self->_shockurl()."/node",Authorization => "OAuth ".$self->_wsauth()); my $json = JSON::XS->new; my $data = $json->decode($res->content); - #print "create shock node output:\n".Data::Dumper->Dump([$data])."\n\n"; my $res = $ua->put($self->_shockurl()."/node/".$data->{data}->{id}."/acl/all?users=".$self->_getUsername(),Authorization => "OAuth ".$self->_wsauth()); - #print "authorizing shock node output:\n".Data::Dumper->Dump([$res])."\n\n"; return $data->{data}->{id}; } @@ -574,7 +570,6 @@ sub _update_shock_node { my $res = $ua->get($object->{shocknode},Authorization => "OAuth ".$self->_wsauth()); my $json = JSON::XS->new; my $data = $json->decode($res->content); - print Data::Dumper->Dump([$data])."\n"; if (length($data->{data}->{file}->{name}) == 0) { $self->{_shockupdate}->{$object->{uuid}} = time(); } else { @@ -807,6 +802,10 @@ sub _create_workspace { my ($self,$specs) = @_; if (!defined($specs->{user}) || length($specs->{user}) == 0) {$self->_error("Owner not specified in creation!");} if (!defined($specs->{workspace}) || length($specs->{workspace}) == 0) {$self->_error("Top directory not specified in creation!");} + if ($specs->{user} ne $self->_getUsername() && $self->_adminmode() == 0) { + $self->_error("User does not have permission to create workspace!"); + } + #Creating workspace directory on disk File::Path::mkpath ($self->_db_path()."/".$specs->{user}."/".$specs->{workspace}); #Creating workspace object in mongodb @@ -845,6 +844,7 @@ sub _create_object { $specs->{creation_date} = DateTime->now()->datetime(); } my $wsobj = $self->_wscache($specs->{user},$specs->{workspace}); + $self->_check_ws_permissions($wsobj,"w",1); my $object = { wsobj => $wsobj, size => 0, @@ -2833,12 +2833,30 @@ sub set_permissions new_global_permission => undef }); my ($user,$ws,$path,$name) = $self->_parse_ws_path($input->{path}); + #Checking that workspace exists and a top lever directory is being adjusted my $wsobj = $self->_wscache($user,$ws,1); if (length($path) + length($name) > 0) { $self->_error("Can only set permissions on top-level folders!"); } - $self->_check_ws_permissions($wsobj,"a",1); + #Checking that user has permissions to change permissions + if ($wsobj->{global_permission} eq "p") { + if ($wsobj->{owner} ne $self->_getUsername() && $self->_adminmode() == 0) { + $self->_error("Only owner and administrators can change permissions on a published workspace!"); + } + } else { + $self->_check_ws_permissions($wsobj,"a",1); + } + #Checking that none of the user-permissions are "p" + for (my $i=0; $i < @{$input->{permissions}}; $i++) { + if ($input->{permissions}->[$i]->[1] eq "p") { + $self->_error("Cannot set user-specific permissions to publish!"); + } + } if (defined($input->{new_global_permission})) { + #Only workspace owner or administrator can set global permissions to "p" + if ($input->{new_global_permission} eq "p") { + $self->_check_ws_permissions($wsobj,"o",1); + } $input->{new_global_permission} = $self->_validate_workspace_permission($input->{new_global_permission}); $self->_updateDB("workspaces",{uuid => $wsobj->{uuid}},{'$set' => {global_permission => $input->{new_global_permission}}}); $wsobj->{global_permission} = $input->{new_global_permission}; @@ -2847,8 +2865,10 @@ sub set_permissions $input->{permissions}->[$i]->[1] = $self->_validate_workspace_permission($input->{permissions}->[$i]->[1]); if ($input->{permissions}->[$i]->[1] eq "n" && defined($wsobj->{permissions}->{$input->{permissions}->[$i]->[0]})) { $self->_updateDB("workspaces",{uuid => $wsobj->{uuid}},{'$unset' => {'permissions.'.$input->{permissions}->[$i]->[0] => $wsobj->{permissions}->{$input->{permissions}->[$i]->[0]}}}); + delete $wsobj->{permissions}->{$input->{permissions}->[$i]->[0]}; } else { $self->_updateDB("workspaces",{uuid => $wsobj->{uuid}},{'$set' => {'permissions.'.$input->{permissions}->[$i]->[0] => $input->{permissions}->[$i]->[1]}}); + $wsobj->{permissions}->{$input->{permissions}->[$i]->[0]} = $input->{permissions}->[$i]->[1]; } } $output = $self->_generate_object_meta($wsobj); @@ -2937,6 +2957,7 @@ sub list_permissions my($output); #BEGIN list_permissions $input = $self->_validateargs($input,["objects"],{}); + $output = {}; for (my $i=0; $i < @{$input->{objects}}; $i++) { my ($user,$ws,$path,$name) = $self->_parse_ws_path($input->{objects}->[$i]); my $wsobj = $self->_wscache($user,$ws,1); diff --git a/lib/Bio/P3/Workspace/WorkspaceTests.pm b/lib/Bio/P3/Workspace/WorkspaceTests.pm index 9996694..bdd3dcb 100644 --- a/lib/Bio/P3/Workspace/WorkspaceTests.pm +++ b/lib/Bio/P3/Workspace/WorkspaceTests.pm @@ -13,7 +13,7 @@ sub new { my($class,$bin) = @_; my $c = Config::Simple->new(); - $c->read($bin."test.cfg"); + $c->read($bin."/test.cfg"); my $self = { testcount => 0, dumpoutput => $c->param("WorkspaceTest.dumpoutput"), @@ -35,14 +35,19 @@ }); $ENV{KB_INTERACTIVE} = 1; if (defined($c->param("WorkspaceTest.serverconfig"))) { - $ENV{KB_DEPLOYMENT_CONFIG} = $bin.$c->param("WorkspaceTest.serverconfig"); + $ENV{KB_DEPLOYMENT_CONFIG} = $bin."/".$c->param("WorkspaceTest.serverconfig"); } if (!defined($self->{url}) || $self->{url} eq "impl") { print "Loading server with this config: ".$ENV{KB_DEPLOYMENT_CONFIG}."\n"; my $classpath = $serverclass; $classpath =~ s/::/\//g; require $classpath.".pm"; - $self->{obj} = $serverclass->new(); + $self->{obj} = $serverclass->new({ + "db-path" => $c->param("WorkspaceTest.db-path"), + "wsuser" => $c->param("WorkspaceTest.wsuser"), + "wspassword" => $c->param("WorkspaceTest.wspassword"), + "types-file" => $c->param("WorkspaceTest.types-file") + }); } else { my $classpath = $clientclass; $classpath =~ s/::/\//g; @@ -57,8 +62,10 @@ my($self,$user) = @_; if (!defined($self->{url}) || $self->{url} eq "impl") { if ($user == 2) { + $Bio::P3::Workspace::WorkspaceImpl::CallContext = undef; $Bio::P3::Workspace::WorkspaceImpl::CallContext = CallContext->new($self->{tokentwo},"test",$self->{usertwo}); } else { + $Bio::P3::Workspace::WorkspaceImpl::CallContext = undef; $Bio::P3::Workspace::WorkspaceImpl::CallContext = CallContext->new($self->{token},"test",$self->{user}); } } else { @@ -309,7 +316,6 @@ ],0,undef,1); #Uploading file to newly created shock node - print "Filename:".$self->{bin}."testdata.txt\n"; my $req = HTTP::Request::Common::POST($output->[0]->[11],Authorization => "OAuth ".$self->{token},Content_Type => 'multipart/form-data',Content => [upload => [$self->{bin}."testdata.txt"]]); $req->method('PUT'); my $ua = LWP::UserAgent->new(); @@ -467,6 +473,23 @@ ["defined(\$output->[0]->[1])","Object retrieved with all data"] ],0,undef,1); + #Publishing workspace + $output = $self->test_harness("set_permissions",{ + path => "/".$self->{usertwo}."/TestWorkspace", + new_global_permission => "p" + },"Publishing workspace",[],0,undef,2); + + #Attempting to write to published workspace + $output = $self->test_harness("create",{ + objects => [["/".$self->{usertwo}."/TestWorkspace/test_write_published_workspace","folder",{},undef]] + },"Cannot write to published workspace",[],1,undef,2); + + #Unpublishing workspace + $output = $self->test_harness("set_permissions",{ + path => "/".$self->{usertwo}."/TestWorkspace", + new_global_permission => "r" + },"Unpublishing workspace",[],0,undef,2); + #Deleting workspaces $output = $self->test_harness("delete",{ objects => ["/".$self->{user}."/TestWorkspace"], diff --git a/scripts/ws-create.pl b/scripts/ws-create.pl index 706ca04..56b38f6 100644 --- a/scripts/ws-create.pl +++ b/scripts/ws-create.pl @@ -57,6 +57,7 @@ =head1 COMMAND-LINE OPTIONS Content => [upload => [$filename]]); $req->method('PUT'); my $sres = $ua->request($req); + print Data::Dumper->Dump([$sres]); } print "File created:\n"; diff --git a/scripts/ws-ls.pl b/scripts/ws-ls.pl index 9cda031..7a0fc75 100644 --- a/scripts/ws-ls.pl +++ b/scripts/ws-ls.pl @@ -27,6 +27,9 @@ =head1 COMMAND-LINE OPTIONS ["recursive|r", "Recursively list subdirectory contents"], ["shock|s", "Include shock URLs"], ]); +if (!defined($ARGV[0])) { + $ARGV[0] = ""; +} my $paths = Bio::P3::Workspace::ScriptHelpers::process_paths([@ARGV]); my $res = Bio::P3::Workspace::ScriptHelpers::wscall("ls",{ paths => $paths, From c611a7aa11ce9429aeefd45d3198d72d019995a0 Mon Sep 17 00:00:00 2001 From: Christopher Henry Date: Wed, 2 Dec 2015 15:14:26 -0600 Subject: [PATCH 06/21] Fixing output for permission commands --- Workspace.spec | 2 +- lib/Bio/P3/Workspace/WorkspaceImpl.pm | 7 +++- scripts/ws-create.pl | 2 +- scripts/ws-perms.pl | 47 +++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 scripts/ws-perms.pl diff --git a/Workspace.spec b/Workspace.spec index 3260769..8fa1ee0 100644 --- a/Workspace.spec +++ b/Workspace.spec @@ -244,7 +244,7 @@ typedef structure { WorkspacePerm new_global_permission; bool adminmode; } set_permissions_params; -funcdef set_permissions(set_permissions_params input) returns (ObjectMeta output) authentication required; +funcdef set_permissions(set_permissions_params input) returns (list > output) authentication required; /* "list_permissions" command Description: diff --git a/lib/Bio/P3/Workspace/WorkspaceImpl.pm b/lib/Bio/P3/Workspace/WorkspaceImpl.pm index 0a30d02..2982f2b 100644 --- a/lib/Bio/P3/Workspace/WorkspaceImpl.pm +++ b/lib/Bio/P3/Workspace/WorkspaceImpl.pm @@ -2871,7 +2871,11 @@ sub set_permissions $wsobj->{permissions}->{$input->{permissions}->[$i]->[0]} = $input->{permissions}->[$i]->[1]; } } - $output = $self->_generate_object_meta($wsobj); + $output = []; + foreach my $puser (keys(%{$wsobj->{permissions}})) { + push(@{$output},[$puser,$wsobj->{permissions}->{$puser}]); + } + push(@{$output},["global_permission",$wsobj->{global_permission}]); #END set_permissions my @_bad_returns; (ref($output) eq 'ARRAY') or push(@_bad_returns, "Invalid type for return variable \"output\" (value was \"$output\")"); @@ -2965,6 +2969,7 @@ sub list_permissions foreach my $puser (keys(%{$wsobj->{permissions}})) { push(@{$output->{$input->{objects}->[$i]}},[$puser,$wsobj->{permissions}->{$puser}]); } + push(@{$output->{$input->{objects}->[$i]}},["global_permission",$wsobj->{global_permission}]); } #END list_permissions my @_bad_returns; diff --git a/scripts/ws-create.pl b/scripts/ws-create.pl index 56b38f6..56d3033 100644 --- a/scripts/ws-create.pl +++ b/scripts/ws-create.pl @@ -22,7 +22,7 @@ =head1 COMMAND-LINE OPTIONS =cut my($opt, $usage) = Bio::P3::Workspace::ScriptHelpers::options("%c %o ",[ - ["permission|p", "Permissions for folders created"], + ["permission|p=s", "Permissions for folders created"], ["useshock|u", "Upload file to shock and store link in workspace"], ["overwrite|o", "Overwirte existing destination object"], ]); diff --git a/scripts/ws-perms.pl b/scripts/ws-perms.pl new file mode 100644 index 0000000..c3623ae --- /dev/null +++ b/scripts/ws-perms.pl @@ -0,0 +1,47 @@ + +use strict; +use Bio::P3::Workspace::ScriptHelpers; +=head1 NAME + +ws-create + +=head1 SYNOPSIS + +ws-create ws-name + +=head1 DESCRIPTION + +Create a workspace + +=head1 COMMAND-LINE OPTIONS + +ws-create workspace [long options...] + --url URL to use for workspace service + --help print usage message and exit + +=cut + +my($opt, $usage) = Bio::P3::Workspace::ScriptHelpers::options("%c %o ",[ + ["perm|p=s", "permission to reset globally or for specific users"], + ["users|u=s", "; delimited list of users to set permissions for"], +]); +my $paths = Bio::P3::Workspace::ScriptHelpers::process_paths([$ARGV[0]]); +if (defined($opt->{perm})) { + my $perms = $opt->{perm}; + my $input = { + path => $paths->[0] + }; + if (defined($opt->{users})) { + my $array = [split(/;/,$opt->{users})]; + for (my $i=0; $i < @{$array}; $i++) { + push(@{$input->{permissions}},[$array->[$i],$perms]); + } + } else { + $input->{new_global_permission} = $perms; + } + my $res = Bio::P3::Workspace::ScriptHelpers::wscall("set_permissions",$input); + print Data::Dumper->Dump([$res]); +} else { + my $res = Bio::P3::Workspace::ScriptHelpers::wscall("list_permissions",{objects => $paths}); + print Data::Dumper->Dump([$res]); +} \ No newline at end of file From 83724b27eed131813985879de48a8e1553a1773f Mon Sep 17 00:00:00 2001 From: Christopher Henry Date: Wed, 2 Dec 2015 16:34:22 -0600 Subject: [PATCH 07/21] Fixing query formatting --- lib/Bio/P3/Workspace/WorkspaceImpl.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Bio/P3/Workspace/WorkspaceImpl.pm b/lib/Bio/P3/Workspace/WorkspaceImpl.pm index 2982f2b..d3ecc39 100644 --- a/lib/Bio/P3/Workspace/WorkspaceImpl.pm +++ b/lib/Bio/P3/Workspace/WorkspaceImpl.pm @@ -1032,7 +1032,7 @@ sub _formatQuery { } } foreach my $term (keys(%{$inquery})) { - if (ref($inquery->{$term}) eq "ARRAY") { + if (ref($inquery->{$term}) eq "ARRAY" && $term ne '$or') { $inquery->{$term} = {'$in' => $inquery->{$term}}; } } From c5c9c676bd340e5458300ca494c23dadf3fe75ba Mon Sep 17 00:00:00 2001 From: Christopher Henry Date: Wed, 2 Dec 2015 16:34:42 -0600 Subject: [PATCH 08/21] Fixing permission script --- scripts/ws-perms.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ws-perms.pl b/scripts/ws-perms.pl index c3623ae..0e55bd4 100644 --- a/scripts/ws-perms.pl +++ b/scripts/ws-perms.pl @@ -43,5 +43,5 @@ =head1 COMMAND-LINE OPTIONS print Data::Dumper->Dump([$res]); } else { my $res = Bio::P3::Workspace::ScriptHelpers::wscall("list_permissions",{objects => $paths}); - print Data::Dumper->Dump([$res]); + print Data::Dumper->Dump([$res->{$paths->[0]}]); } \ No newline at end of file From 14d33190496882bf40f2aece7f1611fd8fe03b01 Mon Sep 17 00:00:00 2001 From: Christopher Henry Date: Wed, 2 Dec 2015 17:20:57 -0600 Subject: [PATCH 09/21] Fixing query implementation on workspaces --- lib/Bio/P3/Workspace/WorkspaceImpl.pm | 37 +++++++++++++++++++-------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/lib/Bio/P3/Workspace/WorkspaceImpl.pm b/lib/Bio/P3/Workspace/WorkspaceImpl.pm index d3ecc39..eee9702 100644 --- a/lib/Bio/P3/Workspace/WorkspaceImpl.pm +++ b/lib/Bio/P3/Workspace/WorkspaceImpl.pm @@ -950,19 +950,34 @@ sub _wscache { #List all workspaces matching input query** sub _list_workspaces { - my ($self,$user) = @_; - my $query = { '$or' => [ {owner => $self->_getUsername()},{global_permission => {'$ne' => "n"} },{"permissions.".$self->_getUsername() => {'$exists' => 1 } } ] }; - if ($self->_adminmode() == 1) { - $query = {}; - } + my ($self,$user,$query) = @_; if (defined($user)) { - if ($user eq $self->_getUsername()) { - $query = {owner => $self->_getUsername()}; - } else { - $query = { '$and' => [ {owner => $user },{ '$or' => [ {global_permission => {'$ne' => "n"} },{"permissions.".$self->_getUsername() => {'$exists' => 1 } } ] } ] }; - if ($self->_adminmode() == 1) { - $query = {owner => $user}; + $query->{owner} = $user; + } + if ($self->_adminmode() != 1) { + if (defined($query->{'$or'})) { + my $oldarray = $query->{'$or'}; + $query->{'$or'} = []; + for (my $i=0; $i < @{$oldarray}; $i++) { + my $hash = {}; + foreach my $key (keys(%{$oldarray->[$i]})) { + $hash->{$key} = $oldarray->[$i]->{$key}; + } + if (!defined($oldarray->[$i]->{owner})) { + $hash->{owner} = $self->_getUsername(); + push(@{$query->{'$or'}},$hash); + } + if (!defined($oldarray->[$i]->{global_permission})) { + $hash->{global_permission} = {'$ne' => "n"}; + push(@{$query->{'$or'}},$hash); + } + if (!defined($oldarray->[$i]->{"permissions.".$self->_getUsername()})) { + $hash->{"permissions.".$self->_getUsername()} = {'$exists' => 1 }; + push(@{$query->{'$or'}},$hash); + } } + } else { + $query->{'$or'} = [ {owner => $self->_getUsername()},{global_permission => {'$ne' => "n"}},{"permissions.".$self->_getUsername() => {'$exists' => 1 }} ] } } my $objs = []; From 22c41784bd97588ea0c897dfbd84c07d3cd4b782 Mon Sep 17 00:00:00 2001 From: Christopher Henry Date: Wed, 2 Dec 2015 17:25:35 -0600 Subject: [PATCH 10/21] Debugging workspace query --- lib/Bio/P3/Workspace/WorkspaceImpl.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Bio/P3/Workspace/WorkspaceImpl.pm b/lib/Bio/P3/Workspace/WorkspaceImpl.pm index eee9702..baf83ed 100644 --- a/lib/Bio/P3/Workspace/WorkspaceImpl.pm +++ b/lib/Bio/P3/Workspace/WorkspaceImpl.pm @@ -980,6 +980,7 @@ sub _list_workspaces { $query->{'$or'} = [ {owner => $self->_getUsername()},{global_permission => {'$ne' => "n"}},{"permissions.".$self->_getUsername() => {'$exists' => 1 }} ] } } + print STDERR Data::Dumper->Dump([$query])."\n"; my $objs = []; my $cursor = $self->_mongodb()->get_collection('workspaces')->find($query); while (my $object = $cursor->next) { From 2cd951c6bc75ce8230bb673f0a5424b268a57dc0 Mon Sep 17 00:00:00 2001 From: Christopher Henry Date: Wed, 2 Dec 2015 17:29:38 -0600 Subject: [PATCH 11/21] Fixing query of workspaces --- lib/Bio/P3/Workspace/WorkspaceImpl.pm | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/Bio/P3/Workspace/WorkspaceImpl.pm b/lib/Bio/P3/Workspace/WorkspaceImpl.pm index baf83ed..32ecc2c 100644 --- a/lib/Bio/P3/Workspace/WorkspaceImpl.pm +++ b/lib/Bio/P3/Workspace/WorkspaceImpl.pm @@ -959,19 +959,27 @@ sub _list_workspaces { my $oldarray = $query->{'$or'}; $query->{'$or'} = []; for (my $i=0; $i < @{$oldarray}; $i++) { - my $hash = {}; - foreach my $key (keys(%{$oldarray->[$i]})) { - $hash->{$key} = $oldarray->[$i]->{$key}; - } if (!defined($oldarray->[$i]->{owner})) { + my $hash = {}; + foreach my $key (keys(%{$oldarray->[$i]})) { + $hash->{$key} = $oldarray->[$i]->{$key}; + } $hash->{owner} = $self->_getUsername(); push(@{$query->{'$or'}},$hash); } if (!defined($oldarray->[$i]->{global_permission})) { + my $hash = {}; + foreach my $key (keys(%{$oldarray->[$i]})) { + $hash->{$key} = $oldarray->[$i]->{$key}; + } $hash->{global_permission} = {'$ne' => "n"}; push(@{$query->{'$or'}},$hash); } if (!defined($oldarray->[$i]->{"permissions.".$self->_getUsername()})) { + my $hash = {}; + foreach my $key (keys(%{$oldarray->[$i]})) { + $hash->{$key} = $oldarray->[$i]->{$key}; + } $hash->{"permissions.".$self->_getUsername()} = {'$exists' => 1 }; push(@{$query->{'$or'}},$hash); } From d247266c62002fc6fe76ce43e62c83c40c32476a Mon Sep 17 00:00:00 2001 From: Christopher Henry Date: Wed, 2 Dec 2015 17:41:52 -0600 Subject: [PATCH 12/21] Fixing bug in workspace queries --- lib/Bio/P3/Workspace/WorkspaceImpl.pm | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/Bio/P3/Workspace/WorkspaceImpl.pm b/lib/Bio/P3/Workspace/WorkspaceImpl.pm index 32ecc2c..18a4222 100644 --- a/lib/Bio/P3/Workspace/WorkspaceImpl.pm +++ b/lib/Bio/P3/Workspace/WorkspaceImpl.pm @@ -959,6 +959,7 @@ sub _list_workspaces { my $oldarray = $query->{'$or'}; $query->{'$or'} = []; for (my $i=0; $i < @{$oldarray}; $i++) { + my $included = 0; if (!defined($oldarray->[$i]->{owner})) { my $hash = {}; foreach my $key (keys(%{$oldarray->[$i]})) { @@ -966,6 +967,13 @@ sub _list_workspaces { } $hash->{owner} = $self->_getUsername(); push(@{$query->{'$or'}},$hash); + } elsif ($oldarray->[$i]->{owner} eq $self->_getUsername()) { + $included = 1; + my $hash = {}; + foreach my $key (keys(%{$oldarray->[$i]})) { + $hash->{$key} = $oldarray->[$i]->{$key}; + } + push(@{$query->{'$or'}},$hash); } if (!defined($oldarray->[$i]->{global_permission})) { my $hash = {}; @@ -974,6 +982,13 @@ sub _list_workspaces { } $hash->{global_permission} = {'$ne' => "n"}; push(@{$query->{'$or'}},$hash); + } elsif ($oldarray->[$i]->{global_permission} ne "n" && $included == 0) { + $included = 1; + my $hash = {}; + foreach my $key (keys(%{$oldarray->[$i]})) { + $hash->{$key} = $oldarray->[$i]->{$key}; + } + push(@{$query->{'$or'}},$hash); } if (!defined($oldarray->[$i]->{"permissions.".$self->_getUsername()})) { my $hash = {}; @@ -982,6 +997,12 @@ sub _list_workspaces { } $hash->{"permissions.".$self->_getUsername()} = {'$exists' => 1 }; push(@{$query->{'$or'}},$hash); + } elsif ($included == 0) { + my $hash = {}; + foreach my $key (keys(%{$oldarray->[$i]})) { + $hash->{$key} = $oldarray->[$i]->{$key}; + } + push(@{$query->{'$or'}},$hash); } } } else { From 49088842c4f20ed266eacd8a1962d9206227c5b6 Mon Sep 17 00:00:00 2001 From: Christopher Henry Date: Wed, 2 Dec 2015 17:45:17 -0600 Subject: [PATCH 13/21] Removing debug statement --- lib/Bio/P3/Workspace/WorkspaceImpl.pm | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Bio/P3/Workspace/WorkspaceImpl.pm b/lib/Bio/P3/Workspace/WorkspaceImpl.pm index 18a4222..f3d58bc 100644 --- a/lib/Bio/P3/Workspace/WorkspaceImpl.pm +++ b/lib/Bio/P3/Workspace/WorkspaceImpl.pm @@ -1009,7 +1009,6 @@ sub _list_workspaces { $query->{'$or'} = [ {owner => $self->_getUsername()},{global_permission => {'$ne' => "n"}},{"permissions.".$self->_getUsername() => {'$exists' => 1 }} ] } } - print STDERR Data::Dumper->Dump([$query])."\n"; my $objs = []; my $cursor = $self->_mongodb()->get_collection('workspaces')->find($query); while (my $object = $cursor->next) { From 3ecc6048cd7c77777143497f365de117d9cd937b Mon Sep 17 00:00:00 2001 From: Christopher Henry Date: Sat, 2 Jan 2016 01:01:07 -0600 Subject: [PATCH 14/21] Adding types, improving handling of folders, and removing probmodelseed dependency from workspace scripts --- lib/Bio/P3/Workspace/ScriptHelpers.pm | 5 +++-- lib/Bio/P3/Workspace/WorkspaceImpl.pm | 21 +++++++++++++++++---- lib/Bio/P3/Workspace/WorkspaceTests.pm | 14 ++++++++++++++ typeslist.txt | 1 + 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/lib/Bio/P3/Workspace/ScriptHelpers.pm b/lib/Bio/P3/Workspace/ScriptHelpers.pm index a5daab1..6e0467f 100644 --- a/lib/Bio/P3/Workspace/ScriptHelpers.pm +++ b/lib/Bio/P3/Workspace/ScriptHelpers.pm @@ -9,7 +9,7 @@ use HTTP::Request::Common; use LWP::UserAgent; use Bio::P3::Workspace::WorkspaceClient; use Bio::P3::Workspace::WorkspaceClientExt; -use Bio::ModelSEED::ProbModelSEED::ProbModelSEEDClient; +use ; our $defaultWSURL = "http://p3.theseed.org/services/Workspace"; our $defaultAPPURL = "http://p3.theseed.org/services/app_service"; @@ -227,7 +227,7 @@ sub appurl { sub process_paths { my $paths = shift; for (my $i=0; $i < @{$paths}; $i++) { - if ($paths->[$i] !~ /^\// && $paths->[$i] !~ /^PATRICSOLR/) { + if ($paths->[$i] !~ /^\// && $paths->[$i] !~ /^PATRIC:/ && $paths->[$i] !~ /^PUBSEED:/ && $paths->[$i] !~ /^RAST:/ && $paths->[$i] !~ /^REFSEQ:/) { $paths->[$i] = Bio::P3::Workspace::ScriptHelpers::directory().$paths->[$i]; } while ($paths->[$i] =~ m/[^\/]+\/\.\.\/*/) { @@ -328,6 +328,7 @@ sub msClient { my $client = Bio::ModelSEED::ProbModelSEED::ProbModelSEEDImpl->new(); return $client; } + require "Bio/ModelSEED/ProbModelSEED/ProbModelSEEDClient.pm"; return Bio::ModelSEED::ProbModelSEED::ProbModelSEEDClient->new($url,token => Bio::P3::Workspace::ScriptHelpers::token()); } diff --git a/lib/Bio/P3/Workspace/WorkspaceImpl.pm b/lib/Bio/P3/Workspace/WorkspaceImpl.pm index f3d58bc..5e44dcc 100644 --- a/lib/Bio/P3/Workspace/WorkspaceImpl.pm +++ b/lib/Bio/P3/Workspace/WorkspaceImpl.pm @@ -215,6 +215,7 @@ sub _generate_object_meta { if (defined($obj->{shocknode})) { $shock = $obj->{shocknode}; } + $obj->{autometadata}->{is_folder} = $self->is_folder($obj->{type}); return [$obj->{name},$obj->{type},$path,$obj->{creation_date},$obj->{uuid},$obj->{owner},$obj->{size},$obj->{metadata},$obj->{autometadata},$self->_get_ws_permission($obj->{wsobj}),$obj->{wsobj}->{global_permission},$shock]; } else { return [$obj->{name},"folder","/".$obj->{owner}."/",$obj->{creation_date},$obj->{uuid},$obj->{owner},0,$obj->{metadata},{},$self->_get_ws_permission($obj),$obj->{global_permission},""]; @@ -608,7 +609,7 @@ sub _validate_save_objects_before_saving { my $nocreate = 0; #We are creating a workspace if (defined($wsobj)) { - if ($objects->[$i]->[1] eq "folder") { + if ($self->is_folder($objects->[$i]->[1]) == 1) { #We ignore creation of folders that already exist $nocreate = 1; } else { @@ -618,7 +619,7 @@ sub _validate_save_objects_before_saving { } elsif ($user ne $self->_getUsername() && $self->_adminmode() == 0) { #Users can only create their own workspaces $self->_error("Insufficient permissions to create ".$objects->[$i]->[0]); - } elsif ($objects->[$i]->[1] ne "folder") { + } elsif ($self->is_folder($objects->[$i]->[1]) == 0) { #Workspace must be a folder $self->_error("Cannot create ".$objects->[$i]->[0]." because top level objects must be folders!"); } @@ -645,7 +646,7 @@ sub _validate_save_objects_before_saving { my $nocreate = 0; if (defined($obj)) { if ($obj->{folder} == 1) { - if ($objects->[$i]->[1] eq "folder") { + if ($self->is_folder($objects->[$i]->[1]) == 1) { #We ignore creation of folders that already exist $nocreate = 1; } else { @@ -866,7 +867,7 @@ sub _create_object { if (!defined($object->{wsobj}->{owner}) || length($object->{wsobj}->{owner}) == 0) {$self->_error("Owner not specified in creation!");} if (!defined($object->{wsobj}->{name}) || length($object->{wsobj}->{name}) == 0) {$self->_error("Top directory not specified in creation!");} if (!defined($object->{name}) || length($object->{name}) == 0) {$self->_error("Name not specified in creation!");} - if ($specs->{type} eq "folder") { + if ($self->is_folder($specs->{type}) == 1) { #Creating folder on file system $object->{autometadata} = {}; $object->{folder} = 1; @@ -1293,6 +1294,14 @@ sub _compute_autometadata { } }; +sub is_folder { + my($self, $type) = @_; + if (defined($self->{_foldertypes}->{lc($type)})) { + return 1; + } + return 0; +} + #END_HEADER sub new @@ -1384,6 +1393,10 @@ sub new $self->{_params} = $params; $self->{_params}->{"db-path"} =~ s/\/\//\//g; $self->{_params}->{"db-path"} =~ s/\/$//g; + $self->{_foldertypes} = { + folder => 1, + modelfolder => 1 + }; #END_CONSTRUCTOR if ($self->can('_init_instance')) diff --git a/lib/Bio/P3/Workspace/WorkspaceTests.pm b/lib/Bio/P3/Workspace/WorkspaceTests.pm index bdd3dcb..86b2794 100644 --- a/lib/Bio/P3/Workspace/WorkspaceTests.pm +++ b/lib/Bio/P3/Workspace/WorkspaceTests.pm @@ -459,6 +459,20 @@ objects => [["/".$self->{user}."/TestWorkspace/emptydir","folder",{},undef]] },"Successfully created a workspace directory!",[],0,undef,1); + #Creating a model folder + $output = $self->test_harness("create",{ + objects => [["/".$self->{user}."/TestWorkspace/emptydir/modelfolder","modelfolder",{},undef]] + },"Successfully created a folder with type other than folder!",[],0,undef,1); + + #Listing model folder + $output = $self->test_harness("ls",{ + paths => ["/".$self->{user}."/TestWorkspace/emptydir/"], + excludeDirectories => 0, + excludeObjects => 0, + recursive => 1 + },"Listing nonfolder directory",[ + ["\$output->{\"/".$self->{user}."/TestWorkspace/emptydir/\"}->[0]->[8]->{is_folder} == 1","ls indicates that object is a folder"] + ],0,undef,1); #Getting an object $output = $self->test_harness("get",{ objects => ["/".$self->{user}."/TestWorkspace/testdir/testdir2/testdir3/testobj"] diff --git a/typeslist.txt b/typeslist.txt index 5b2bb19..a72ac7a 100644 --- a/typeslist.txt +++ b/typeslist.txt @@ -33,6 +33,7 @@ json mapping media model +modelfolder model_edit modeltemplate pdf From aa5e9a0c50d5280719835b468bf0e13f84431dd4 Mon Sep 17 00:00:00 2001 From: Christopher Henry Date: Sat, 2 Jan 2016 01:06:47 -0600 Subject: [PATCH 15/21] Fixing small bug in script helper --- lib/Bio/P3/Workspace/ScriptHelpers.pm | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Bio/P3/Workspace/ScriptHelpers.pm b/lib/Bio/P3/Workspace/ScriptHelpers.pm index 6e0467f..cb067cc 100644 --- a/lib/Bio/P3/Workspace/ScriptHelpers.pm +++ b/lib/Bio/P3/Workspace/ScriptHelpers.pm @@ -9,7 +9,6 @@ use HTTP::Request::Common; use LWP::UserAgent; use Bio::P3::Workspace::WorkspaceClient; use Bio::P3::Workspace::WorkspaceClientExt; -use ; our $defaultWSURL = "http://p3.theseed.org/services/Workspace"; our $defaultAPPURL = "http://p3.theseed.org/services/app_service"; From 61ae2abc0c399aa44deae326e51dcb5aca5d7767 Mon Sep 17 00:00:00 2001 From: Christopher Henry Date: Fri, 8 Jan 2016 15:02:12 -0600 Subject: [PATCH 16/21] Adding type --- typeslist.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/typeslist.txt b/typeslist.txt index a72ac7a..90e6f2b 100644 --- a/typeslist.txt +++ b/typeslist.txt @@ -55,3 +55,4 @@ wig xls xlsx zip +contigset From 7ffbb343db7a193bc595946b88c41c663add62bb Mon Sep 17 00:00:00 2001 From: Robert Olson Date: Fri, 29 Jan 2016 12:27:09 -0600 Subject: [PATCH 17/21] Update .kbase_config when p3-login is run. --- lib/Bio/P3/Workspace/ScriptHelpers.pm | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/Bio/P3/Workspace/ScriptHelpers.pm b/lib/Bio/P3/Workspace/ScriptHelpers.pm index b5be6e4..f4485f8 100644 --- a/lib/Bio/P3/Workspace/ScriptHelpers.pm +++ b/lib/Bio/P3/Workspace/ScriptHelpers.pm @@ -11,6 +11,13 @@ use Bio::P3::Workspace::WorkspaceClient; use Bio::P3::Workspace::WorkspaceClientExt; use Bio::ModelSEED::ProbModelSEED::ProbModelSEEDClient; +our $have_kb_auth = 0; +eval +{ + require Bio::KBase::Auth; + $have_kb_auth = 1; +}; + our $defaultWSURL = "http://p3.theseed.org/services/Workspace"; our $defaultAPPURL = "http://p3.theseed.org/services/app_service"; our $defaultMSURL = "https://p3.theseed.org/services/ProbModelSEED"; @@ -303,6 +310,15 @@ sub login { user_id => $params->{user_id}, password => undef }); + # + # Update the KBase .kbase_config file as well. + # + if ($have_kb_auth) + { + Bio::KBase::Auth::SetConfigs(token => $token, + user_id => $params->{user_id}, + password => undef); + } } return $token; } From 378b679da62a33b3ef6be32fc31a0706544f3e12 Mon Sep 17 00:00:00 2001 From: Robert Olson Date: Fri, 29 Jan 2016 12:28:32 -0600 Subject: [PATCH 18/21] Also update .kbase_config on p3-logout. --- lib/Bio/P3/Workspace/ScriptHelpers.pm | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/Bio/P3/Workspace/ScriptHelpers.pm b/lib/Bio/P3/Workspace/ScriptHelpers.pm index f4485f8..1a9dd71 100644 --- a/lib/Bio/P3/Workspace/ScriptHelpers.pm +++ b/lib/Bio/P3/Workspace/ScriptHelpers.pm @@ -324,10 +324,19 @@ sub login { } sub logout { - Bio::P3::Workspace::ScriptHelpers::SetConfig({ - token => undef, - user_id => undef + Bio::P3::Workspace::ScriptHelpers::SetConfig({ + token => undef, + user_id => undef }); + # + # Update the KBase .kbase_config file as well. + # + if ($have_kb_auth) + { + Bio::KBase::Auth::SetConfigs(token => undef, + user_id => undef, + password => undef); + } } sub msClient { From a139a56cc20a061b4d7cd992e0892fdb6b98d7b0 Mon Sep 17 00:00:00 2001 From: Robert Olson Date: Wed, 9 Mar 2016 13:23:26 -0600 Subject: [PATCH 19/21] Remove debug --- lib/Bio/P3/Workspace/WorkspaceImpl.pm | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/Bio/P3/Workspace/WorkspaceImpl.pm b/lib/Bio/P3/Workspace/WorkspaceImpl.pm index fb6eb8b..7cf84e2 100644 --- a/lib/Bio/P3/Workspace/WorkspaceImpl.pm +++ b/lib/Bio/P3/Workspace/WorkspaceImpl.pm @@ -1144,7 +1144,6 @@ sub _download_request { $writer->write($data); my $len = length($data); - print STDERR "B $len\n"; return 1; } else @@ -1193,7 +1192,6 @@ sub _download_request if ($h->{rbuf}) { my $len = length($h->{rbuf}); - print "R $len\n"; $writer->write($h->{rbuf}); $h->rbuf = ''; } From d1d1895241ba9b9d712925274a0cf2d30ef9b946 Mon Sep 17 00:00:00 2001 From: Christopher Henry Date: Sat, 19 Mar 2016 16:24:30 -0500 Subject: [PATCH 20/21] Enabling access to public workspaces without auth --- Workspace.spec | 10 ++-- lib/Bio/P3/Workspace/Service.pm | 30 ++++++++-- lib/Bio/P3/Workspace/WorkspaceClient.pm | 80 ++++++------------------- lib/Bio/P3/Workspace/WorkspaceImpl.pm | 74 ++++++++--------------- lib/Bio/P3/Workspace/WorkspaceTests.pm | 44 +++++++++++--- lib/WorkspaceServer.py | 10 ++-- 6 files changed, 114 insertions(+), 134 deletions(-) diff --git a/Workspace.spec b/Workspace.spec index 8fa1ee0..1871369 100644 --- a/Workspace.spec +++ b/Workspace.spec @@ -110,7 +110,7 @@ typedef structure { bool metadata_only; bool adminmode; } get_params; -funcdef get(get_params input) returns (list> output) authentication required; +funcdef get(get_params input) returns (list> output) authentication optional; /* "update_shock_meta" command Description: @@ -138,7 +138,7 @@ funcdef update_auto_meta(update_auto_meta_params input) returns (list objects; } get_download_url_params; -funcdef get_download_url(get_download_url_params input) returns (list urls) authentication required; +funcdef get_download_url(get_download_url_params input) returns (list urls) authentication optional; /* "get_archive_url" command Description: @@ -158,7 +158,7 @@ typedef structure { string archive_name; string archive_type; } get_archive_url_params; -funcdef get_archive_url(get_archive_url_params input) returns (string url); +funcdef get_archive_url(get_archive_url_params input) returns (string url) authentication optional; /* "list" command Description: @@ -182,7 +182,7 @@ typedef structure { mapping> query; bool adminmode; } list_params; -funcdef ls(list_params input) returns (mapping> output) authentication required; +funcdef ls(list_params input) returns (mapping> output) authentication optional; /********** REORGANIZATION FUNCTIONS *******************/ @@ -258,6 +258,6 @@ typedef structure { list objects; bool adminmode; } list_permissions_params; -funcdef list_permissions(list_permissions_params input) returns (mapping > > output) authentication required; +funcdef list_permissions(list_permissions_params input) returns (mapping > > output) authentication optional; }; diff --git a/lib/Bio/P3/Workspace/Service.pm b/lib/Bio/P3/Workspace/Service.pm index 0cc9c30..c8796e4 100644 --- a/lib/Bio/P3/Workspace/Service.pm +++ b/lib/Bio/P3/Workspace/Service.pm @@ -6,6 +6,7 @@ use Moose; use POSIX; use JSON; use Bio::KBase::Log; +use Class::Load qw(); use Config::Simple; my $get_time = sub { time, 0 }; eval { @@ -44,15 +45,15 @@ our %return_counts = ( our %method_authentication = ( 'create' => 'required', 'update_metadata' => 'required', - 'get' => 'required', + 'get' => 'optional', 'update_auto_meta' => 'required', - 'get_download_url' => 'required', - 'get_archive_url' => 'none', - 'ls' => 'required', + 'get_download_url' => 'optional', + 'get_archive_url' => 'optional', + 'ls' => 'optional', 'copy' => 'required', 'delete' => 'required', 'set_permissions' => 'required', - 'list_permissions' => 'required', + 'list_permissions' => 'optional', ); @@ -149,6 +150,23 @@ sub _build_loggers return $loggers; } +# +# Override method from RPC::Any::Server::JSONRPC +# to eliminate the deprecation warning for Class::MOP::load_class. +# +sub _default_error { + my ($self, %params) = @_; + my $version = $self->default_version; + $version =~ s/\./_/g; + my $error_class = "JSON::RPC::Common::Procedure::Return::Version_${version}::Error"; + Class::Load::load_class($error_class); + my $error = $error_class->new(%params); + my $return_class = "JSON::RPC::Common::Procedure::Return::Version_$version"; + Class::Load::load_class($return_class); + return $return_class->new(error => $error); +} + + #override of RPC::Any::Server sub handle_error { my ($self, $error) = @_; @@ -396,7 +414,7 @@ sub get_method "There is no method package named '$package'."); } - Class::MOP::load_class($module); + Class::Load::load_class($module); } if (!$module->can($method)) { diff --git a/lib/Bio/P3/Workspace/WorkspaceClient.pm b/lib/Bio/P3/Workspace/WorkspaceClient.pm index 1541348..9ce19e7 100644 --- a/lib/Bio/P3/Workspace/WorkspaceClient.pm +++ b/lib/Bio/P3/Workspace/WorkspaceClient.pm @@ -35,10 +35,6 @@ sub new { my($class, $url, @args) = @_; - if (!defined($url)) - { - $url = 'http://p3.theseed.org/services/Workspace'; - } my $self = { client => Bio::P3::Workspace::WorkspaceClient::RpcClient->new, @@ -84,17 +80,15 @@ sub new # # We create an auth token, passing through the arguments that we were (hopefully) given. - #{ - #my $token = Bio::KBase::AuthToken->new(@args); + { + my $token = Bio::KBase::AuthToken->new(@args); - #if (!$token->error_message) - #{ - # $self->{token} = $token->token; - # $self->{client}->{token} = $token->token; - #} - #} - $self->{token} = $args[1]; - $self->{client}->{token} = $args[1]; + if (!$token->error_message) + { + $self->{token} = $token->token; + $self->{client}->{token} = $token->token; + } + } my $ua = $self->{client}->ua; my $timeout = $ENV{CDMI_TIMEOUT} || (30 * 60); @@ -513,7 +507,7 @@ sub get { my($self, @args) = @_; -# Authentication: required +# Authentication: optional if ((my $n = @args) != 1) { @@ -735,7 +729,7 @@ sub get_download_url { my($self, @args) = @_; -# Authentication: required +# Authentication: optional if ((my $n = @args) != 1) { @@ -830,7 +824,7 @@ sub get_archive_url { my($self, @args) = @_; -# Authentication: none +# Authentication: optional if ((my $n = @args) != 1) { @@ -975,7 +969,7 @@ sub ls { my($self, @args) = @_; -# Authentication: required +# Authentication: optional if ((my $n = @args) != 1) { @@ -1316,7 +1310,9 @@ sub delete
 $input is a set_permissions_params
-$output is an ObjectMeta
+$output is a reference to a list where each element is a reference to a list containing 2 items:
+	0: a Username
+	1: a WorkspacePerm
 set_permissions_params is a reference to a hash where the following keys are defined:
 	path has a value which is a FullObjectPath
 	permissions has a value which is a reference to a list where each element is a reference to a list containing 2 items:
@@ -1329,26 +1325,6 @@ FullObjectPath is a string
 Username is a string
 WorkspacePerm is a string
 bool is an int
-ObjectMeta is a reference to a list containing 12 items:
-	0: an ObjectName
-	1: an ObjectType
-	2: a FullObjectPath
-	3: (creation_time) a Timestamp
-	4: an ObjectID
-	5: (object_owner) a Username
-	6: an ObjectSize
-	7: a UserMetadata
-	8: an AutoMetadata
-	9: (user_permission) a WorkspacePerm
-	10: (global_permission) a WorkspacePerm
-	11: (shockurl) a string
-ObjectName is a string
-ObjectType is a string
-Timestamp is a string
-ObjectID is a string
-ObjectSize is an int
-UserMetadata is a reference to a hash where the key is a string and the value is a string
-AutoMetadata is a reference to a hash where the key is a string and the value is a string
 
 
@@ -1357,7 +1333,9 @@ AutoMetadata is a reference to a hash where the key is a string and the value is =begin text $input is a set_permissions_params -$output is an ObjectMeta +$output is a reference to a list where each element is a reference to a list containing 2 items: + 0: a Username + 1: a WorkspacePerm set_permissions_params is a reference to a hash where the following keys are defined: path has a value which is a FullObjectPath permissions has a value which is a reference to a list where each element is a reference to a list containing 2 items: @@ -1370,26 +1348,6 @@ FullObjectPath is a string Username is a string WorkspacePerm is a string bool is an int -ObjectMeta is a reference to a list containing 12 items: - 0: an ObjectName - 1: an ObjectType - 2: a FullObjectPath - 3: (creation_time) a Timestamp - 4: an ObjectID - 5: (object_owner) a Username - 6: an ObjectSize - 7: a UserMetadata - 8: an AutoMetadata - 9: (user_permission) a WorkspacePerm - 10: (global_permission) a WorkspacePerm - 11: (shockurl) a string -ObjectName is a string -ObjectType is a string -Timestamp is a string -ObjectID is a string -ObjectSize is an int -UserMetadata is a reference to a hash where the key is a string and the value is a string -AutoMetadata is a reference to a hash where the key is a string and the value is a string =end text @@ -1505,7 +1463,7 @@ sub list_permissions { my($self, @args) = @_; -# Authentication: required +# Authentication: optional if ((my $n = @args) != 1) { diff --git a/lib/Bio/P3/Workspace/WorkspaceImpl.pm b/lib/Bio/P3/Workspace/WorkspaceImpl.pm index 5e44dcc..bcda0fd 100644 --- a/lib/Bio/P3/Workspace/WorkspaceImpl.pm +++ b/lib/Bio/P3/Workspace/WorkspaceImpl.pm @@ -224,7 +224,7 @@ sub _generate_object_meta { #Retrieving object data from filesystem or giving permission to download shock node** sub _retrieve_object_data { - my ($self,$obj) = @_; + my ($self,$obj,$wsobj) = @_; if ($obj->{folder} == 1) { return ""; } @@ -238,8 +238,12 @@ sub _retrieve_object_data { } close($fh); } else { - my $ua = LWP::UserAgent->new(); - my $res = $ua->put($obj->{shocknode}."/acl/all?users=".$self->_getUsername(),Authorization => "OAuth ".$self->_wsauth()); + if ($wsobj->{global_permission} ne "n") { + $self->_make_shock_node_public($obj->{shocknode}); + } else { + my $ua = LWP::UserAgent->new(); + my $res = $ua->put($obj->{shocknode}."/acl/all?users=".$self->_getUsername(),Authorization => "OAuth ".$self->_wsauth()); + } $data = $obj->{shocknode}; } if (!defined($data)) { @@ -564,6 +568,15 @@ sub _create_shock_node { return $data->{data}->{id}; } +sub _make_shock_node_public { + my ($self,$url) = @_; + my $ua = LWP::UserAgent->new(); + my $res = $ua->get($url."/acl/",Authorization => "OAuth ".$self->_wsauth()); + my $json = JSON::XS->new; + my $data = $json->decode($res->content); + $res = $ua->delete($url."/acl/read?users=".join(",",@{$data->{data}->{read}}),Authorization => "OAuth ".$self->_wsauth()); +} + sub _update_shock_node { my ($self,$object,$force) = @_; if ($force == 1 || !defined($self->{_shockupdate}->{$object->{uuid}}) || (time() - $self->{_shockupdate}->{$object->{uuid}}) > $self->{_params}->{"update-interval"}) { @@ -1341,7 +1354,7 @@ sub new $c->read($e); for my $p (@{$paramlist}) { my $v = $c->param("$service.$p"); - if ($v && !defined($params->{$p})) { + if ($v && !defined($params->{$p})) { $params->{$p} = $v; if ($v eq "null") { $params->{$p} = undef; @@ -1349,7 +1362,7 @@ sub new } } } - } + } $params = $self->_validateargs($params,["db-path","wsuser","wspassword","types-file"],{ "script-path" => "/kb/deployment/plbin/", "job-directory" => "/tmp/wsjobs/", @@ -1906,7 +1919,7 @@ sub get } else { push(@{$output},[ $self->_generate_object_meta($obj), - $self->_retrieve_object_data($obj) + $self->_retrieve_object_data($obj,$wsobj) ]); } } @@ -2163,7 +2176,6 @@ sub get_download_url workspace_path => $ws_path, }; - print Dumper($obj); if (!defined($obj->{shock}) || $obj->{shock} == 0) { my $filename = $self->_db_path()."/".$obj->{wsobj}->{owner}."/".$obj->{wsobj}->{name}."/".$obj->{path}."/".$obj->{name}; $doc->{file_path} = $filename; @@ -2781,7 +2793,9 @@ sub delete
 $input is a set_permissions_params
-$output is an ObjectMeta
+$output is a reference to a list where each element is a reference to a list containing 2 items:
+	0: a Username
+	1: a WorkspacePerm
 set_permissions_params is a reference to a hash where the following keys are defined:
 	path has a value which is a FullObjectPath
 	permissions has a value which is a reference to a list where each element is a reference to a list containing 2 items:
@@ -2794,26 +2808,6 @@ FullObjectPath is a string
 Username is a string
 WorkspacePerm is a string
 bool is an int
-ObjectMeta is a reference to a list containing 12 items:
-	0: an ObjectName
-	1: an ObjectType
-	2: a FullObjectPath
-	3: (creation_time) a Timestamp
-	4: an ObjectID
-	5: (object_owner) a Username
-	6: an ObjectSize
-	7: a UserMetadata
-	8: an AutoMetadata
-	9: (user_permission) a WorkspacePerm
-	10: (global_permission) a WorkspacePerm
-	11: (shockurl) a string
-ObjectName is a string
-ObjectType is a string
-Timestamp is a string
-ObjectID is a string
-ObjectSize is an int
-UserMetadata is a reference to a hash where the key is a string and the value is a string
-AutoMetadata is a reference to a hash where the key is a string and the value is a string
 
 
@@ -2822,7 +2816,9 @@ AutoMetadata is a reference to a hash where the key is a string and the value is =begin text $input is a set_permissions_params -$output is an ObjectMeta +$output is a reference to a list where each element is a reference to a list containing 2 items: + 0: a Username + 1: a WorkspacePerm set_permissions_params is a reference to a hash where the following keys are defined: path has a value which is a FullObjectPath permissions has a value which is a reference to a list where each element is a reference to a list containing 2 items: @@ -2835,26 +2831,6 @@ FullObjectPath is a string Username is a string WorkspacePerm is a string bool is an int -ObjectMeta is a reference to a list containing 12 items: - 0: an ObjectName - 1: an ObjectType - 2: a FullObjectPath - 3: (creation_time) a Timestamp - 4: an ObjectID - 5: (object_owner) a Username - 6: an ObjectSize - 7: a UserMetadata - 8: an AutoMetadata - 9: (user_permission) a WorkspacePerm - 10: (global_permission) a WorkspacePerm - 11: (shockurl) a string -ObjectName is a string -ObjectType is a string -Timestamp is a string -ObjectID is a string -ObjectSize is an int -UserMetadata is a reference to a hash where the key is a string and the value is a string -AutoMetadata is a reference to a hash where the key is a string and the value is a string =end text diff --git a/lib/Bio/P3/Workspace/WorkspaceTests.pm b/lib/Bio/P3/Workspace/WorkspaceTests.pm index 86b2794..68714b4 100644 --- a/lib/Bio/P3/Workspace/WorkspaceTests.pm +++ b/lib/Bio/P3/Workspace/WorkspaceTests.pm @@ -42,18 +42,14 @@ my $classpath = $serverclass; $classpath =~ s/::/\//g; require $classpath.".pm"; - $self->{obj} = $serverclass->new({ - "db-path" => $c->param("WorkspaceTest.db-path"), - "wsuser" => $c->param("WorkspaceTest.wsuser"), - "wspassword" => $c->param("WorkspaceTest.wspassword"), - "types-file" => $c->param("WorkspaceTest.types-file") - }); + $self->{obj} = $serverclass->new({}); } else { my $classpath = $clientclass; $classpath =~ s/::/\//g; require $classpath.".pm"; $self->{clientobj} = $clientclass->new($self->{url},token => $self->{token}); $self->{clientobjtwo} = $clientclass->new($self->{url},token => $self->{tokentwo}); + $self->{clientobjthree} = $clientclass->new($self->{url},token => undef); } return bless $self, $class; } @@ -64,6 +60,9 @@ if ($user == 2) { $Bio::P3::Workspace::WorkspaceImpl::CallContext = undef; $Bio::P3::Workspace::WorkspaceImpl::CallContext = CallContext->new($self->{tokentwo},"test",$self->{usertwo}); + } elsif ($user == 3) { + $Bio::P3::Workspace::WorkspaceImpl::CallContext = undef; + $Bio::P3::Workspace::WorkspaceImpl::CallContext = CallContext->new(undef,"test",undef); } else { $Bio::P3::Workspace::WorkspaceImpl::CallContext = undef; $Bio::P3::Workspace::WorkspaceImpl::CallContext = CallContext->new($self->{token},"test",$self->{user}); @@ -71,6 +70,8 @@ } else { if ($user == 2) { $self->{obj} = $self->{clientobjtwo}; + } elsif ($user == 3) { + $self->{obj} = $self->{clientobjthree}; } else { $self->{obj} = $self->{clientobj}; } @@ -312,7 +313,6 @@ ["defined(\$output->[0])","Getting metadata for created object back"], ["\$output->[0]->[1] eq \"genome\"","Object has type genome"], ["defined(\$output->[0]->[11])","Shock URL is returned"] - ],0,undef,1); #Uploading file to newly created shock node @@ -429,9 +429,15 @@ new_global_permission => "w" },"Successfully changed global permissions!",[],0,undef,1); + #Copy objects + $output = $self->test_harness("copy",{ + objects => [["/".$self->{usertwo}."/TestWorkspace/copydir","/".$self->{usertwo}."/TestWorkspace/copydir_two"]], + recursive => 1 + },"Successfully ran copy to move objects!",[],0,undef,2); + #Moving objects $output = $self->test_harness("copy",{ - objects => [["/".$self->{usertwo}."/TestWorkspace/copydir","/".$self->{user}."/TestWorkspace/movedir"]], + objects => [["/".$self->{usertwo}."/TestWorkspace/copydir_two","/".$self->{user}."/TestWorkspace/movedir"]], recursive => 1, move => 1 },"Successfully ran copy to move objects!",[],0,undef,2); @@ -498,12 +504,34 @@ objects => [["/".$self->{usertwo}."/TestWorkspace/test_write_published_workspace","folder",{},undef]] },"Cannot write to published workspace",[],1,undef,2); + #Listing public workspace + $output = $self->test_harness("ls",{ + paths => ["/".$self->{usertwo}."/TestWorkspace"] + },"Using ls function on published workspace without auth",[],0,undef,3); + + #Getting object from public workspace + $output = $self->test_harness("get",{ + objects => ["/".$self->{usertwo}."/TestWorkspace/copydir/testdir2/testdir3/shockobj"] + },"Using get function to retrieve object from published workspace without auth",[],0,undef,3); + system("curl ".$output->[0]->[0]->[11]."?download"); + #Unpublishing workspace $output = $self->test_harness("set_permissions",{ path => "/".$self->{usertwo}."/TestWorkspace", new_global_permission => "r" },"Unpublishing workspace",[],0,undef,2); + #Listing public workspace + $output = $self->test_harness("ls",{ + paths => ["/".$self->{usertwo}."/TestWorkspace"] + },"Using ls function on public workspace without auth",[],0,undef,3); + + #Getting object from public workspace + $output = $self->test_harness("get",{ + objects => ["/".$self->{usertwo}."/TestWorkspace/copydir/testdir2/testdir3/shockobj"] + },"Using get function to retrieve object from public workspace without auth",[],0,undef,3); + system("curl ".$output->[0]->[0]->[11]."?download"); + #Deleting workspaces $output = $self->test_harness("delete",{ objects => ["/".$self->{user}."/TestWorkspace"], diff --git a/lib/WorkspaceServer.py b/lib/WorkspaceServer.py index 2fc0363..0949910 100644 --- a/lib/WorkspaceServer.py +++ b/lib/WorkspaceServer.py @@ -275,7 +275,7 @@ def __init__(self): self.rpc_service.add(impl_Workspace.get, name='Workspace.get', types=[dict]) - self.method_authentication['Workspace.get'] = 'required' + self.method_authentication['Workspace.get'] = 'optional' self.rpc_service.add(impl_Workspace.update_auto_meta, name='Workspace.update_auto_meta', types=[dict]) @@ -283,15 +283,15 @@ def __init__(self): self.rpc_service.add(impl_Workspace.get_download_url, name='Workspace.get_download_url', types=[dict]) - self.method_authentication['Workspace.get_download_url'] = 'required' + self.method_authentication['Workspace.get_download_url'] = 'optional' self.rpc_service.add(impl_Workspace.get_archive_url, name='Workspace.get_archive_url', types=[dict]) - self.method_authentication['Workspace.get_archive_url'] = 'none' + self.method_authentication['Workspace.get_archive_url'] = 'optional' self.rpc_service.add(impl_Workspace.ls, name='Workspace.ls', types=[dict]) - self.method_authentication['Workspace.ls'] = 'required' + self.method_authentication['Workspace.ls'] = 'optional' self.rpc_service.add(impl_Workspace.copy, name='Workspace.copy', types=[dict]) @@ -307,7 +307,7 @@ def __init__(self): self.rpc_service.add(impl_Workspace.list_permissions, name='Workspace.list_permissions', types=[dict]) - self.method_authentication['Workspace.list_permissions'] = 'required' + self.method_authentication['Workspace.list_permissions'] = 'optional' self.auth_client = biokbase.nexus.Client( config={'server': 'nexus.api.globusonline.org', 'verify_ssl': True, From 736089fb4ac3646bb71f14b4ccc27e08eef431d5 Mon Sep 17 00:00:00 2001 From: Robert Olson Date: Mon, 28 Mar 2016 12:08:59 -0500 Subject: [PATCH 21/21] If we don't have a token, don't send auth header to shock. This looks like it may fix the public workspace download problem. --- lib/Bio/P3/Workspace/WorkspaceImpl.pm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Bio/P3/Workspace/WorkspaceImpl.pm b/lib/Bio/P3/Workspace/WorkspaceImpl.pm index 9682971..edd5a97 100644 --- a/lib/Bio/P3/Workspace/WorkspaceImpl.pm +++ b/lib/Bio/P3/Workspace/WorkspaceImpl.pm @@ -1193,8 +1193,13 @@ sub _download_request my $url = $res->{shock_node} . "?download"; print STDERR "retrieve $url\n"; + my @headers; + if ($res->{user_token}) + { + @headers = (headers => {Authorization => "OAuth $res->{user_token}" }); + } http_request(GET => $url, - headers => {Authorization => "OAuth $res->{user_token}" }, + @headers, # handle_params => { max_read_size => 32768 }, on_body => sub { my($data, $hdr) = @_;