forked from BenLangmead/crossbow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAWS.pm
66 lines (61 loc) · 1.83 KB
/
AWS.pm
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
#!/usr/bin/perl -w
##
# Author: Ben Langmead
# Date: 2/14/2010
#
# Routines for getting and expanding jars from
#
package AWS;
use strict;
use warnings;
our $accessKey = "";
our $secretKey = "";
##
# If either $accessKey or $secretKey are not already set, look some
# more places for them.
#
sub ensureKeys($$$) {
my ($hadoop, $hadoop_arg, $env) = @_;
my $hadoopHome = $env->{HADOOP_HOME};
if(!defined($hadoopHome)) {
$hadoop = $hadoop_arg if $hadoop_arg ne "";
if(-x $hadoop) {
$hadoopHome = `dirname $hadoop`;
chomp($hadoopHome);
$hadoopHome .= "/..";
}
}
if($accessKey eq "") {
if(defined($env->{AWS_ACCESS_KEY_ID})) {
$accessKey = $env->{AWS_ACCESS_KEY_ID};
} elsif(defined($hadoopHome)) {
$accessKey = `grep fs.s3n.awsAccessKeyId $hadoopHome/conf/*.xml | sed 's/.*<value>//' | sed 's/<\\/value>.*//'`;
$accessKey =~ s/\s.*$//; # In case we got multiple lines back
if($accessKey eq "") {
print STDERR "Couldn't get access key from $hadoopHome/conf/*.xml\n";
}
}
if($accessKey eq "") {
die "--accesskey was not specified, nor could the access ".
"key be retrived from an environment variable or from ".
"the \$HADOOP_HOME/conf directory\n";
}
}
if($secretKey eq "") {
if(defined($env->{AWS_SECRET_ACCESS_KEY})) {
$secretKey = $env->{AWS_SECRET_ACCESS_KEY};
} elsif(defined($hadoopHome)) {
$secretKey = `grep fs.s3n.awsSecretAccessKey $hadoopHome/conf/*.xml | sed 's/.*<value>//' | sed 's/<\\/value>.*//'`;
$secretKey =~ s/\s.*$//; # In case we got multiple lines back
if($secretKey eq "") {
print STDERR "Couldn't get secret key from $hadoopHome/conf/*.xml\n";
}
}
if($secretKey eq "") {
die "--secretkey was not specified, nor could the secret ".
"key be retrived from an environment variable or from ".
"the \$HADOOP_HOME/conf directory\n";
}
}
}
1;