presigner 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/bin/presigner +16 -0
- data/lib/presigner.rb +13 -6
- data/lib/presigner/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02cd85a3175bbb93c9ee386eea94baa8e8395c45
|
4
|
+
data.tar.gz: c087b0160933cbca516fc35c44c2dfedcffc8f4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c54525782582f34096da95dd28388412a728be49f2fe053e54ff44360b1c0faa09d2b2d3c953caeabf615ac8d1c4984648aa6479050ce238ae46d9ed63135d7
|
7
|
+
data.tar.gz: 1a0268130c725d049fa6ec82d130ada5bf486a331ac2220398924f594ee06b54be55dfae51e140aa0a7016823b9c99d908d71fd6149da9cef84077bb8674734d
|
data/README.md
CHANGED
@@ -21,7 +21,7 @@ Or install it yourself as:
|
|
21
21
|
## Usage
|
22
22
|
|
23
23
|
```bash
|
24
|
-
$ presigner --bucket foobucket --key bar.txt --duration 3600 --profile default
|
24
|
+
$ presigner generate --bucket foobucket --key bar.txt --duration 3600 --profile default
|
25
25
|
```
|
26
26
|
|
27
27
|
- Currently, You can provide duration only in seconds.
|
data/bin/presigner
CHANGED
@@ -7,10 +7,26 @@ class PresignerCLI < Thor
|
|
7
7
|
option :bucket, :required => true
|
8
8
|
option :key, :required => true
|
9
9
|
option :profile
|
10
|
+
option :access_key
|
11
|
+
option :secret_key
|
10
12
|
option :duration
|
13
|
+
option :region
|
11
14
|
desc "generate", "generate S3 presigned URL"
|
12
15
|
|
13
16
|
def generate
|
17
|
+
aws_opts = {}
|
18
|
+
if options[:access_key] and options[:secret_key]
|
19
|
+
aws_opts[:access_key] = options[:access_key]
|
20
|
+
aws_opts[:secret_key] = options[:secret_key]
|
21
|
+
elsif options[:profile]
|
22
|
+
prov = AWS::Core::CredentialProviders::
|
23
|
+
SharedCredentialFileProvider.new(profile_name: options[:profile])
|
24
|
+
aws_opts[:credential_provider] = prov
|
25
|
+
end
|
26
|
+
|
27
|
+
aws_opts[:region] = options[:region] if options[:region]
|
28
|
+
AWS.config(aws_opts)
|
29
|
+
|
14
30
|
presigner= Presigner.new(options)
|
15
31
|
url = presigner.generate
|
16
32
|
$stdout.puts url
|
data/lib/presigner.rb
CHANGED
@@ -8,9 +8,6 @@ class Presigner
|
|
8
8
|
DEFAULT_DURATION = 60 * 30
|
9
9
|
|
10
10
|
def initialize(options)
|
11
|
-
prov = AWS::Core::CredentialProviders::
|
12
|
-
SharedCredentialFileProvider.new(profile_name: options[:profile])
|
13
|
-
AWS.config(credential_provider: prov)
|
14
11
|
@bucket = options[:bucket]
|
15
12
|
@key = options[:key]
|
16
13
|
@duration = options[:duration].nil? ? DEFAULT_DURATION : options[:duration].to_i
|
@@ -23,7 +20,17 @@ class Presigner
|
|
23
20
|
|
24
21
|
s3 = AWS::S3.new
|
25
22
|
# check if specified bucket and key exist.
|
26
|
-
|
23
|
+
begin
|
24
|
+
target_obj = s3.buckets[bucket].objects[key]
|
25
|
+
if !target_obj.exists?
|
26
|
+
$stderr.puts "Specified bucket or key does not exist."
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
rescue AWS::S3::Errors::Forbidden
|
30
|
+
$stderr.puts "Access to the S3 object is denied. Credential or target name might be wrong"
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
|
27
34
|
if !target_obj.exists?
|
28
35
|
$stderr.puts "Specified bucket or key does not exist."
|
29
36
|
exit 1
|
@@ -32,11 +39,11 @@ class Presigner
|
|
32
39
|
presigner = AWS::S3::PresignV4.new(target_obj)
|
33
40
|
expires = calc_duration
|
34
41
|
|
35
|
-
url = presigner.presign(:get, expires:
|
42
|
+
url = presigner.presign(:get, expires: base + duration, secure: true)
|
36
43
|
url
|
37
44
|
end
|
38
45
|
|
39
46
|
def calc_duration
|
40
|
-
|
47
|
+
duration
|
41
48
|
end
|
42
49
|
end
|
data/lib/presigner/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: presigner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masao Mochizuki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|