Repository navigation
Expand file tree
/
Copy pathtemplate
More file actions
112 lines (92 loc) · 2.18 KB
/
Copy pathtemplate
File metadata and controls
112 lines (92 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
use LWP::UserAgent;
use JSON;
use Bio::KBase::IDServer::Client;
sub help {
my $text = qq~
NAME
##resource## -- ##description##
VERSION
##version##
SYNOPSIS
##resource## [ ##optionlist default####optionlist##]
DESCRIPTION
##long description##
Options
##options detailed default##
##options detailed##
Output
##outputs##
EXAMPLES
##example##
SEE ALSO
##related##
AUTHORS
##authors##
~;
system "echo '$text' | more";
}
my $HOST = '##host##/##item##/';
my $user = '';
my $pass = '';
my $token = '';
my $verbosity = 'full';
my $help = '';
my $webkey = '';
my $offset = '0';
my $limit = '10';
my $id = undef;
GetOptions ( 'user=s' => \$user,
'pass=s' => \$pass,
'token=s' => \$token,
'verbosity=s' => \$verbosity,
'help' => \$help,
'webkey=s' => \$webkey,
'limit=s' => \$limit,
'offset' => \$offset,
'id=s' => \$id );
if ($help) {
&help();
exit 0;
}
if ($user || $pass) {
if ($user && $pass) {
my $exec = 'curl -s -u '.$user.':'.$pass.' -X POST "https://nexus.api.globusonline.org/goauth/token?grant_type=client_credentials"';
my $result = `$exec`;
my $ustruct = "";
eval {
my $json = new JSON;
$ustruct = $json->decode($result);
};
if ($@) {
die "could not reach auth server";
} else {
if ($ustruct->{access_token}) {
$token = $ustruct->{access_token};
} else {
die "authentication failed";
}
}
} else {
die "you must supply both username and password";
}
}
if ($id && $id =~/^kb\|/) {
my $id_server_url = "http://www.kbase.us/services/idserver";
my $idserver = Bio::KBase::IDServer::Client->new($id_server_url);
my $return = $idserver->kbase_ids_to_external_ids( [ $id ]);
$id = $return->{$id}->[1] ;
$HOST .= "$id/";
}
my $url = $HOST."?verbosity=$verbosity&limit=$limit&offset=$offset";
if ($webkey) {
$url .= "&webkey=".$webkey;
}
my $ua = LWP::UserAgent->new;
if ($token) {
$ua->default_header('user_auth' => $token);
}
print $ua->get($url)->content;