crossing 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 +8 -8
- data/bin/crossing +41 -38
- data/lib/crossing.rb +23 -3
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NGQxM2NmNTU1ODNkNTI2N2ExMTk5M2MyNTQ1MGRkMDI3MjgxYWE4MQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZGY4YjFjNzBhMDVhZjdkYmE5OTAxZjdiODNhOTE5YzdiODdmZmVmYg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NGI0Yjc1YWRmZDJiYjYwOTkyMGI5NmZhM2E3MDVhNjJlZTU2MTQ0MzkxMzEx
|
10
|
+
YTZiYWEzNTI3NGQ3ZmE3MjYyMTUxYjY3MWIwMzc2ZmI5YWUwNGExYTYyYjU3
|
11
|
+
NjVlYmVkZTcxMDkxZmNmZmJkMTk0ZTQ5NGMwM2VmNzA2OWY5MjA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NmJmY2NiMTQ0ZDg5YmE2Y2U5ODhhZDJmYmE4NGFjOGM4MGMzOTg2OTIyMTEx
|
14
|
+
YmMxZjdjNDgzNjQ5NjVlZGU5NzNmMjk2MWRhMWI5ZjcyZmMxYzQzYmRkNDk3
|
15
|
+
NzE0NmNlYjQwOWJlY2E2NjM0YjAwMGE3MTA3ZjdhZTI0NmM2OGU=
|
data/bin/crossing
CHANGED
@@ -1,51 +1,54 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require 'optparse'
|
3
|
-
require 'crossing'
|
4
|
-
|
5
|
-
options = { bucket: nil, file: nil, key: nil }
|
6
|
-
arguments = OptionParser.new do |opts|
|
7
|
-
opts.banner = 'Usage: crossing [options]'
|
8
2
|
|
9
|
-
|
10
|
-
|
11
|
-
# Read in arguments
|
12
|
-
opts.on('-b', '--bucket bucket', 'Bucket') do |bucket|
|
13
|
-
options[:bucket] = bucket
|
14
|
-
end
|
3
|
+
require 'trollop'
|
4
|
+
require 'crossing'
|
15
5
|
|
16
|
-
|
17
|
-
|
18
|
-
|
6
|
+
SUB_COMMANDS = %w(get put).freeze
|
7
|
+
global_opts = Trollop.options do
|
8
|
+
opt :region, 'The region to look for the KMS Key in', default: 'us-east-1'
|
9
|
+
banner 'utility for storing and retrieving files in S3 in a secure manner
|
10
|
+
available commands:
|
19
11
|
|
20
|
-
|
21
|
-
|
22
|
-
end
|
12
|
+
put -- store a file in S3
|
13
|
+
get -- retrieve a file from S3
|
23
14
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
opts.on('-h', '--help', 'Displays Help') do
|
29
|
-
puts opts
|
30
|
-
exit
|
31
|
-
end
|
15
|
+
use --help with either command for more information.
|
16
|
+
'
|
17
|
+
stop_on SUB_COMMANDS
|
32
18
|
end
|
33
19
|
|
34
|
-
|
20
|
+
cmd = ARGV.shift
|
21
|
+
cmd_opts =
|
22
|
+
case cmd
|
23
|
+
when 'put'
|
24
|
+
Trollop.options do
|
25
|
+
opt :file, 'the path to the file to store', required: true, type: String
|
26
|
+
opt :bucket, 'the bucket to store the file in', required: true, type: String
|
27
|
+
opt :kmskeyid, 'the kms key id of the master KMS key', required: true, type: String
|
28
|
+
end
|
29
|
+
when 'get'
|
30
|
+
Trollop.options do
|
31
|
+
opt :file, 'the name of the file to retrieve', required: true, type: String
|
32
|
+
opt :bucket, 'the bucket the file is stored in', required: true, type: String
|
33
|
+
opt :kmskeyid, 'the kms key id of the master KMS key', required: true, type: String
|
34
|
+
end
|
35
|
+
else
|
36
|
+
Trollop.die 'usage: crossing [get|put] [parameters]'
|
37
|
+
end
|
35
38
|
|
36
|
-
|
37
|
-
# if options[key].nil?
|
38
|
-
# raise "#{key} is required...aborting"
|
39
|
-
# end
|
40
|
-
# end
|
41
|
-
kms = Aws::KMS::Client.new
|
39
|
+
kms = Aws::KMS::Client.new region: global_opts[:region]
|
42
40
|
s3 = Aws::S3::Encryption::Client.new(
|
43
|
-
kms_key_id:
|
41
|
+
kms_key_id: cmd_opts[:kmskeyid],
|
44
42
|
kms_client: kms
|
45
43
|
)
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
|
45
|
+
crossing = Crossing.new(s3)
|
46
|
+
|
47
|
+
case cmd
|
48
|
+
when 'put'
|
49
|
+
crossing.put(cmd_opts[:bucket], cmd_opts[:file])
|
50
|
+
when 'get'
|
51
|
+
crossing.get(File, cmd_opts[:bucket], cmd_opts[:file])
|
49
52
|
else
|
50
|
-
|
53
|
+
raise "unknown subcommand #{cmd}"
|
51
54
|
end
|
data/lib/crossing.rb
CHANGED
@@ -8,10 +8,30 @@ class Crossing
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def put(bucket, filename)
|
11
|
-
|
12
|
-
|
11
|
+
begin
|
12
|
+
file = File.new(filename, 'r')
|
13
|
+
rescue
|
14
|
+
raise CrossingFileNotFoundException, "File not found: #{filename}"
|
15
|
+
end
|
16
|
+
|
17
|
+
@s3_client.put_object(bucket: bucket, key: filename.split('/').last, body: file.read)
|
13
18
|
end
|
14
19
|
|
15
|
-
def get(bucket, file)
|
20
|
+
def get(filesystem, bucket, file)
|
21
|
+
if filesystem.exist?(file)
|
22
|
+
raise CrossingFileExistsException, "File #{file} already exists, will not overwrite."
|
23
|
+
end
|
24
|
+
|
25
|
+
content = @s3_client.get_object(bucket: bucket, key: file).body.read
|
26
|
+
filesystem.write(file, content)
|
16
27
|
end
|
17
28
|
end
|
29
|
+
|
30
|
+
class CrossingError < StandardError
|
31
|
+
end
|
32
|
+
|
33
|
+
class CrossingFileNotFoundException < CrossingError
|
34
|
+
end
|
35
|
+
|
36
|
+
class CrossingFileExistsException < CrossingError
|
37
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crossing
|
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
|
- John Ulick
|
8
|
+
- Jonny Sywulak
|
8
9
|
- Stelligent
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2017-02-
|
13
|
+
date: 2017-02-03 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: aws-sdk
|
@@ -25,11 +26,25 @@ dependencies:
|
|
25
26
|
- - ~>
|
26
27
|
- !ruby/object:Gem::Version
|
27
28
|
version: '2'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: trollop
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - '='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 2.1.2
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 2.1.2
|
28
43
|
description: The native AWS command line does not have an easy way to upload encrypted
|
29
44
|
files to S3. The Ruby SDK has a way to do this, but not everyone wants to use it.
|
30
45
|
This utility allows you to do client side encrypted uploads to S3 from the command
|
31
46
|
line, which is useful for uploads from your CI system to docker containers.
|
32
|
-
email:
|
47
|
+
email: info@stelligent.com
|
33
48
|
executables:
|
34
49
|
- crossing
|
35
50
|
extensions: []
|