vman 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.vman.example.json +4 -0
- data/CONTRIBUTING.md +31 -0
- data/Gemfile +4 -0
- data/LICENSE.md +13 -0
- data/README.md +121 -0
- data/Rakefile +18 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bin/vman +32 -0
- data/interactive_menu.png +0 -0
- data/lib/vman.rb +105 -0
- data/lib/vman/help.rb +27 -0
- data/lib/vman/menu.rb +150 -0
- data/lib/vman/s3.rb +37 -0
- data/lib/vman/version.rb +3 -0
- data/vman.gemspec +30 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 65c9ed8c0ea649bf2e5860e42891de530d243d53
|
4
|
+
data.tar.gz: f00e98ad6611192c42eedeaeb05cdcef74c66642
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c325cbbbc947a7b7187f74f8b07b18eff008a92d1d5397f6721427bf51c0c6cbd9f21512f22c0d527dfd05225f5ffd88cd8531fc6c3f466a0e1d1d77b2ec9015
|
7
|
+
data.tar.gz: 489b35692691e3a7296f7ebba2b9dbdc0ba9ca9d45eb765d1904e00c3a313535f8951142fdda1bbbfa0865721e5b3f421aae3252a4f2e405b3ace79b9e59c8e4
|
data/.gitignore
ADDED
data/.vman.example.json
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
We welcome contributions to this repository. Feel free to submit issues for bugs you encounter and pull requests for code and documentation contributions.
|
4
|
+
|
5
|
+
In order to prevent licensing issues, we require all contributors to sign an individual contributor license agreement, which is reproduced below:
|
6
|
+
|
7
|
+
## Individual Contributor License Agreement
|
8
|
+
|
9
|
+
In order to clarify the intellectual property license granted with Contributions from any person or entity, Doximity, Inc. ("Doximity") must have a Contributor License Agreement ("CLA") on file that has been signed by each Contributor, indicating agreement to the license terms below. This license is for your protection as a Contributor as well as the protection of Doximity; it does not change your rights to use your own Contributions for any other purpose.
|
10
|
+
|
11
|
+
You accept and agree to the following terms and conditions for Your present and future Contributions submitted to Doximity. Except for the license granted herein to Doximity and recipients of software distributed by Doximity, You reserve all right, title, and interest in and to Your Contributions.
|
12
|
+
|
13
|
+
### Definitions
|
14
|
+
|
15
|
+
"You" (or "Your") shall mean the copyright owner or legal entity authorized by the copyright owner that is making this Agreement with Doximity. For legal entities, the entity making a Contribution and all other entities that control, are controlled by, or are under common control with that entity are considered to be a single Contributor. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
16
|
+
|
17
|
+
1. "Contribution" shall mean any original work of authorship, including any modifications or additions to an existing work, that is intentionally submitted by You to Doximity for inclusion in, or documentation of, any of the products owned or managed by Doximity (the "Work"). For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to Doximity or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, Doximity for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by You as "Not a Contribution."
|
18
|
+
|
19
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this Agreement, You hereby grant to Doximity and to recipients of software distributed by Doximity a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute Your Contributions and such derivative works.
|
20
|
+
|
21
|
+
3. Grant of Patent License. Subject to the terms and conditions of this Agreement, You hereby grant to Doximity and to recipients of software distributed by Doximity a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by You that are necessarily infringed by Your Contribution(s) alone or by combination of Your Contribution(s) with the Work to which such Contribution(s) was submitted. If any entity institutes patent litigation against You or any other entity (including a cross-claim or counterclaim in a lawsuit) alleging that your Contribution, or the Work to which you have contributed, constitutes direct or contributory patent infringement, then any patent licenses granted to that entity under this Agreement for that Contribution or Work shall terminate as of the date such litigation is filed.
|
22
|
+
|
23
|
+
4. You represent that you are legally entitled to grant the above license. If your employer(s) has rights to intellectual property that you create that includes your Contributions, you represent that you have received permission to make Contributions on behalf of that employer, that your employer has waived such rights for your Contributions to Doximity, or that your employer has executed a separate Corporate CLA with Doximity.
|
24
|
+
|
25
|
+
5. You represent that each of Your Contributions is Your original creation (see section 7 for submissions on behalf of others). You represent that Your Contribution submissions include complete details of any third-party license or other restriction (including, but not limited to, related patents and trademarks) of which you are personally aware and which are associated with any part of Your Contributions.
|
26
|
+
|
27
|
+
6. You are not expected to provide support for Your Contributions, except to the extent You desire to provide support. You may provide support for free, for a fee, or not at all. Unless required by applicable law or agreed to in writing, You provide Your Contributions on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON- INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
|
28
|
+
|
29
|
+
7. Should You wish to submit work that is not Your original creation, You may submit it to Doximity separately from any Contribution, identifying the complete details of its source and of any license or other restriction (including, but not limited to, related patents, trademarks, and license agreements) of which you are personally aware, and conspicuously marking the work as "Submitted on behalf of a third-party: [[]named here]".
|
30
|
+
|
31
|
+
8. You agree to notify Doximity of any facts or circumstances of which you become aware that would make these representations inaccurate in any respect.
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Copyright 2015 Doximity, Inc.
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
# Vman
|
2
|
+
|
3
|
+
Like superman but not at all.
|
4
|
+
|
5
|
+
A ruby gem to help manage (push/pull/delete/promote/etc) your objects and
|
6
|
+
directories in a [versioned S3 bucket](http://docs.aws.amazon.com/AmazonS3/latest/dev/Versioning.html).
|
7
|
+
|
8
|
+
## Prerequisites
|
9
|
+
|
10
|
+
Ensure you have the AWS cli [installed](http://docs.aws.amazon.com/cli/latest/userguide/installing.html) and [configured](http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html) properly.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Install with:
|
15
|
+
|
16
|
+
$ gem install vman
|
17
|
+
|
18
|
+
Create a configuration file with:
|
19
|
+
|
20
|
+
$ vman configure
|
21
|
+
|
22
|
+
Then edit the new `~/.vman.json` file with your correct values.
|
23
|
+
- `bucket_uri` is your `s3://`-prefixed S3 bucket URL to which you have permissions.
|
24
|
+
- `local_dir` (optional) value that tells `vman` which directory to work in. If not supplied, defaults to `Dir.pwd`.
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
Run without arguments to access help documentation:
|
29
|
+
|
30
|
+
$ vman
|
31
|
+
|
32
|
+
Show local file diff (differences on your local machine that are not on S3):
|
33
|
+
|
34
|
+
```bash
|
35
|
+
$ echo "Hello world" > newfile.txt
|
36
|
+
$ vman diff
|
37
|
+
Showing file diff for a push from '/Users/chl/Desktop/test' to 's3://my-bucket'
|
38
|
+
|
39
|
+
(dryrun) upload: ./newfile.txt to s3://my-bucket/newfile.txt
|
40
|
+
```
|
41
|
+
|
42
|
+
Show remote file diff (differences on remote S3 that are not on your local machine):
|
43
|
+
|
44
|
+
```bash
|
45
|
+
$ vman diff -r
|
46
|
+
Showing file diff for a pull from 's3://my-bucket' to '/Users/chl/Desktop/test'
|
47
|
+
|
48
|
+
(dryrun) download: s3://my-bucket/Gemfile to ./Gemfile
|
49
|
+
(dryrun) download: s3://my-bucket/Gemfile.lock to ./Gemfile.lock
|
50
|
+
(dryrun) download: s3://my-bucket/test.txt to ./test.txt
|
51
|
+
```
|
52
|
+
|
53
|
+
Push local changes to remote:
|
54
|
+
```bash
|
55
|
+
$ vman push -f
|
56
|
+
Pushing changes from /Users/chl/Desktop/test to remote bucket 's3://my-bucket'
|
57
|
+
upload: ./newfile.txt to s3://my-bucket/newfile.txt
|
58
|
+
```
|
59
|
+
|
60
|
+
Pull remote changes to local:
|
61
|
+
```bash
|
62
|
+
$ vman pull -f
|
63
|
+
Pulling changes from remote bucket 's3://my-bucket' to /Users/chl/Desktop/test.
|
64
|
+
This will overwrite local changes!
|
65
|
+
download: s3://my-bucket/Gemfile to ./Gemfile
|
66
|
+
download: s3://my-bucket/tete.txt to ./tete.txt
|
67
|
+
download: s3://my-bucket/test.txt to ./test.txt
|
68
|
+
download: s3://my-bucket/Gemfile.lock to ./Gemfile.lock
|
69
|
+
```
|
70
|
+
|
71
|
+
## Interactive Usage
|
72
|
+
|
73
|
+
Vman also comes with a fully interactive tty menu system for finer-grained over
|
74
|
+
single files or versions. This can be accessed with:
|
75
|
+
|
76
|
+
$ vman -i
|
77
|
+
|
78
|
+
![Image of interactive menu](interactive_menu.png)
|
79
|
+
|
80
|
+
## Integration With Git
|
81
|
+
|
82
|
+
You can easily hook into the git workflow with Vman by doing the following:
|
83
|
+
|
84
|
+
1. Add the directory or sub-directory in your local repo that you wish to sync to S3 to your `.gitignore` file.
|
85
|
+
2. To have Vman automatically push changes in your selected (sub)directory to S3, create a git hook in `.git/hooks/pre-push`. For example:
|
86
|
+
```bash
|
87
|
+
#!/bin/bash
|
88
|
+
|
89
|
+
exec < /dev/tty
|
90
|
+
|
91
|
+
cd ./path/to/synced/direcotry
|
92
|
+
|
93
|
+
vman push
|
94
|
+
|
95
|
+
while true; do
|
96
|
+
read -p "Do you wish to push these files to S3?" yn
|
97
|
+
case $yn in
|
98
|
+
[Yy]* ) vman push -f; break;;
|
99
|
+
[Nn]* ) printf "Nothing pushed to S3.\n\n"; exit;;
|
100
|
+
* ) echo "Please answer yes or no.";;
|
101
|
+
esac
|
102
|
+
done
|
103
|
+
|
104
|
+
printf "Continuing with 'git push'...\n"
|
105
|
+
```
|
106
|
+
|
107
|
+
This will first do a dry-run of `vman push` and show you the files that it plans to push to your S3 bucket. It will then prompt for
|
108
|
+
confirmation to execute the push. Regardless of your selection, your normal git flow will not be interrupted.
|
109
|
+
|
110
|
+
**N.B.** githooks execute in the root of your repo directory. Keep this in mind when entering the path to the (sub)directory
|
111
|
+
you wish to sync.
|
112
|
+
|
113
|
+
## Testing
|
114
|
+
|
115
|
+
Note that AWS cli must be installed. Then simply:
|
116
|
+
|
117
|
+
$ rake test
|
118
|
+
|
119
|
+
## Contributing
|
120
|
+
|
121
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/doximity/vman.
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.libs << "test"
|
6
|
+
t.libs << "lib"
|
7
|
+
t.test_files = FileList['test/**/*_test.rb']
|
8
|
+
end
|
9
|
+
|
10
|
+
task :console do
|
11
|
+
exec "irb -r vman -I ./lib"
|
12
|
+
end
|
13
|
+
|
14
|
+
task :run do
|
15
|
+
exec "ruby -Ilib ./bin/vman"
|
16
|
+
end
|
17
|
+
|
18
|
+
task :default => :test
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "vman"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/bin/vman
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'vman'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'tty-prompt'
|
6
|
+
|
7
|
+
@stty_save = `stty -g`.chomp
|
8
|
+
|
9
|
+
def save_and_exit
|
10
|
+
puts
|
11
|
+
system('stty', @stty_save)
|
12
|
+
exit
|
13
|
+
end
|
14
|
+
|
15
|
+
trap('INT') { save_and_exit }
|
16
|
+
|
17
|
+
begin
|
18
|
+
if ARGV[0] == 'configure'
|
19
|
+
prompt = TTY::Prompt.new
|
20
|
+
config_path = Vman::Client.const_get(:DEFAULT_CONFIG_PATH)
|
21
|
+
if File.exist?(config_path)
|
22
|
+
prompt.warn("Configuration file already exists at #{config_path}. No changes have been made.")
|
23
|
+
else
|
24
|
+
FileUtils.copy('.vman.example.json', config_path)
|
25
|
+
prompt.ok("Vman configuration file created at #{config_path}. Edit this file with your correct values")
|
26
|
+
end
|
27
|
+
else
|
28
|
+
Vman::Client.new(ARGV)
|
29
|
+
end
|
30
|
+
rescue TTY::Prompt::Reader::InputInterrupt
|
31
|
+
save_and_exit
|
32
|
+
end
|
Binary file
|
data/lib/vman.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'vman/version'
|
2
|
+
require 'vman/help'
|
3
|
+
require 'vman/menu'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Vman
|
7
|
+
class ValidationError < StandardError; end
|
8
|
+
class Client
|
9
|
+
|
10
|
+
DEFAULT_CONFIG_PATH = File.expand_path('~/.vman.json')
|
11
|
+
ATTRS = [:bucket_uri, :local_dir]
|
12
|
+
attr_reader(*ATTRS)
|
13
|
+
|
14
|
+
def initialize(args = ARGV)
|
15
|
+
@prompt = TTY::Prompt.new
|
16
|
+
@config = validate_config
|
17
|
+
@bucket_uri = @config['bucket_uri']
|
18
|
+
@local_dir = @config['local_dir'] || Dir.pwd
|
19
|
+
parse_args(args)
|
20
|
+
end
|
21
|
+
|
22
|
+
def push(args)
|
23
|
+
cmd = "aws s3 sync #{@local_dir} #{@bucket_uri}"
|
24
|
+
sub_cmd = args.shift
|
25
|
+
cmd += ' --dryrun' unless sub_cmd == '-f'
|
26
|
+
|
27
|
+
@prompt.warn("Pushing changes from #{@local_dir} to remote bucket \'#{@bucket_uri}\'")
|
28
|
+
sub_cmd == '-f' ? @prompt.ok(`#{cmd}`) : @prompt.warn(`#{cmd}`)
|
29
|
+
end
|
30
|
+
|
31
|
+
def diff(args)
|
32
|
+
from, to = @local_dir, @bucket_uri
|
33
|
+
action = 'push'
|
34
|
+
|
35
|
+
if args.shift == '-r'
|
36
|
+
to, from, action = from, to, 'pull'
|
37
|
+
end
|
38
|
+
|
39
|
+
cmd = "aws s3 sync #{from} #{to} --dryrun"
|
40
|
+
|
41
|
+
@prompt.warn("Showing file diff for a #{action} from \'#{from}\' to \'#{to}\'\n")
|
42
|
+
@prompt.warn(`#{cmd}`)
|
43
|
+
end
|
44
|
+
|
45
|
+
def pull(args)
|
46
|
+
cmd = "aws s3 sync #{@bucket_uri} #{@local_dir}"
|
47
|
+
sub_cmd = args.shift
|
48
|
+
cmd += ' --dryrun' unless sub_cmd == '-f'
|
49
|
+
|
50
|
+
@prompt.warn("Pulling changes from remote bucket \'#{@bucket_uri}\' to #{@local_dir}.")
|
51
|
+
@prompt.warn("This will overwrite local changes!")
|
52
|
+
sub_cmd == '-f' ? @prompt.ok(`#{cmd}`) : @prompt.warn(`#{cmd}`)
|
53
|
+
end
|
54
|
+
|
55
|
+
#######
|
56
|
+
private
|
57
|
+
#######
|
58
|
+
|
59
|
+
def delegate!(args)
|
60
|
+
available_methods = (self.public_methods(false) - ATTRS)
|
61
|
+
cmd = args.shift.to_sym
|
62
|
+
|
63
|
+
if available_methods.include?(cmd)
|
64
|
+
send(cmd, args)
|
65
|
+
else
|
66
|
+
raise ArgumentError, "No matching method for #{cmd}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def parse_args(args)
|
71
|
+
arg = ( args[0] ? args[0].downcase : nil)
|
72
|
+
|
73
|
+
case arg
|
74
|
+
when '-v', '--version'
|
75
|
+
@prompt.say(Vman::VERSION)
|
76
|
+
when '-h', '--help', NilClass
|
77
|
+
@prompt.say(Vman::Help.docs)
|
78
|
+
when '-i', '--interactive'
|
79
|
+
Vman::Menu.new(@config).show
|
80
|
+
else
|
81
|
+
delegate!(args)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def validate_config(args = nil)
|
86
|
+
unless File.exist?(DEFAULT_CONFIG_PATH)
|
87
|
+
@prompt.error("No configuration file found at #{DEFAULT_CONFIG_PATH}. Run 'vman configure' to generate one")
|
88
|
+
raise ValidationError
|
89
|
+
end
|
90
|
+
|
91
|
+
@config = JSON.parse(File.read(DEFAULT_CONFIG_PATH))
|
92
|
+
unless @config['bucket_uri']
|
93
|
+
@prompt.error("No key found under 'bucket_uri' in #{DEFAULT_CONFIG_PATH}")
|
94
|
+
raise ValidationError
|
95
|
+
end
|
96
|
+
|
97
|
+
unless @config['bucket_uri'] =~ /s3:\/\//
|
98
|
+
@prompt.error("Value 'bucket_uri' must be a valid S3 URI beginning with 's3://'")
|
99
|
+
raise ValidationError
|
100
|
+
end
|
101
|
+
@config
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
end
|
data/lib/vman/help.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Vman
|
2
|
+
module Help
|
3
|
+
|
4
|
+
def self.docs
|
5
|
+
docs = <<-EOF
|
6
|
+
|
7
|
+
Vman - the object version manager!
|
8
|
+
|
9
|
+
Usage:
|
10
|
+
vman configure Generate a Vman config file at ~/.vman.json
|
11
|
+
vman pull [-f] (Dry run) Pull changes from remote S3 bucket to local directory
|
12
|
+
vman push [-f] (Dry run) Push changes from local directory to remote S3 bucket
|
13
|
+
vman diff [-r] Show file differences for pushing from local to remote
|
14
|
+
vman -i Open the Vman interactive menu for finer-grained actions
|
15
|
+
vman -v Show current installed gem version
|
16
|
+
|
17
|
+
Options:
|
18
|
+
-f Force the action and apply changes, instead of dry-run
|
19
|
+
-r Reverse the diff. Show file differences for pulling from remote to local
|
20
|
+
|
21
|
+
EOF
|
22
|
+
|
23
|
+
docs
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/lib/vman/menu.rb
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
require 'tty-prompt'
|
2
|
+
require 'vman/s3'
|
3
|
+
require 'readline'
|
4
|
+
|
5
|
+
module Vman
|
6
|
+
class Menu
|
7
|
+
|
8
|
+
def initialize(config)
|
9
|
+
@prompt = TTY::Prompt.new
|
10
|
+
@s3 = S3.new(config['bucket_uri'])
|
11
|
+
end
|
12
|
+
|
13
|
+
def show
|
14
|
+
@prompt.select('Select an action') do |p|
|
15
|
+
p.choice "Retrieve an object", -> { retrieve }
|
16
|
+
p.choice "Store an object", -> { store }
|
17
|
+
p.choice "List all versions of an object", -> { versions }
|
18
|
+
p.choice "Show current version of an object", -> { version }
|
19
|
+
p.choice "List all objects", -> { list }
|
20
|
+
p.choice "Delete a version of an object", -> { delete }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def retrieve
|
25
|
+
obj_versions = get_versions
|
26
|
+
|
27
|
+
@prompt.select("Select a version to retrieve") do |prompt|
|
28
|
+
obj_versions.each do |v|
|
29
|
+
prompt.choice "#{v.id} (#{v.get.last_modified})", -> {
|
30
|
+
name = v.object_key + '_' + v.id
|
31
|
+
download(v, name)
|
32
|
+
@prompt.ok("#{name} downloaded to working directory")
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def store
|
39
|
+
file = prompt_file
|
40
|
+
key = File.basename(file)
|
41
|
+
stored_file = @s3.store(file, key)
|
42
|
+
|
43
|
+
if stored_file && stored_file.class == Aws::S3::Object
|
44
|
+
@prompt.ok("Successfully uploaded \"#{key}\" to S3")
|
45
|
+
else
|
46
|
+
@prompt.error("Error uploading \"#{key}\" to S3")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def versions
|
51
|
+
obj_versions = get_versions
|
52
|
+
|
53
|
+
@prompt.ok("Total number of versions: #{obj_versions.count}")
|
54
|
+
obj_versions.each do |v|
|
55
|
+
msg = " " + v.id + " (#{v.last_modified})"
|
56
|
+
msg[0] = "•" if v.is_latest
|
57
|
+
@prompt.say("#{msg}")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def version
|
62
|
+
obj_version = get_version
|
63
|
+
|
64
|
+
@prompt.ok("Current version for #{obj_version.object_key}:")
|
65
|
+
@prompt.say("#{obj_version.get.version_id} (#{obj_version.get.last_modified})")
|
66
|
+
end
|
67
|
+
|
68
|
+
def list
|
69
|
+
objects = @s3.list
|
70
|
+
|
71
|
+
@prompt.ok("All current objects in bucket:")
|
72
|
+
objects.each_with_index do |obj, i|
|
73
|
+
@prompt.say("#{i+1}. #{obj.key}")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def delete
|
78
|
+
obj_versions = get_versions
|
79
|
+
|
80
|
+
@prompt.select("Select a version to delete") do |prompt|
|
81
|
+
obj_versions.each do |v|
|
82
|
+
prompt.choice "#{v.id} (#{v.get.last_modified})", -> { prompt_delete(v) }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
#######
|
88
|
+
private
|
89
|
+
#######
|
90
|
+
|
91
|
+
def get_version
|
92
|
+
obj = get!
|
93
|
+
v_id = obj.get.version_id
|
94
|
+
obj.version(v_id)
|
95
|
+
end
|
96
|
+
|
97
|
+
def get_versions
|
98
|
+
obj = get!
|
99
|
+
_versions = @s3.versions(obj.key)
|
100
|
+
end
|
101
|
+
|
102
|
+
def download(object, name)
|
103
|
+
object.get({ response_target: File.open(name, 'w') })
|
104
|
+
end
|
105
|
+
|
106
|
+
def prompt_file
|
107
|
+
path = Readline.readline('Enter path to local file for upload: ')
|
108
|
+
abs_path = File.expand_path(path).strip!
|
109
|
+
|
110
|
+
if !File.exist?(abs_path)
|
111
|
+
@prompt.warn("Could not find \"#{abs_path}\". Did you mispell it?")
|
112
|
+
return store
|
113
|
+
end
|
114
|
+
|
115
|
+
abs_path
|
116
|
+
end
|
117
|
+
|
118
|
+
def prompt_delete(v)
|
119
|
+
@prompt.warn("WARNING: This will remove the selected version from the S3 bucket!")
|
120
|
+
@prompt.warn("Ensure you are deleting the correct version of this object:\n\n #{v.object_key} - #{v.id} - #{v.get.last_modified}\n")
|
121
|
+
|
122
|
+
if @prompt.yes?("Are you sure you want to delete this version?")
|
123
|
+
v.delete({ version_id: v.id })
|
124
|
+
@prompt.ok("Version id \"#{v.id}\" for object \"#{v.object_key}\" successfully deleted")
|
125
|
+
return true
|
126
|
+
end
|
127
|
+
|
128
|
+
@prompt.warn("No version deleted. Exiting.")
|
129
|
+
false
|
130
|
+
end
|
131
|
+
|
132
|
+
def get!
|
133
|
+
key = @prompt.ask("Enter object key to retrieve: ")
|
134
|
+
objs = @s3.find(key)
|
135
|
+
|
136
|
+
if objs.count == 0
|
137
|
+
@prompt.warn("No object found under key '#{key}'. Did you mispell it?")
|
138
|
+
return get!
|
139
|
+
elsif objs.count == 1
|
140
|
+
objs.first
|
141
|
+
else
|
142
|
+
@prompt.warn("Found multiple objects")
|
143
|
+
selection = @prompt.select("Which one do you want") do |prompt|
|
144
|
+
objs.each { |obj| prompt.choice "#{obj.key}", -> { obj } }
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
end
|
data/lib/vman/s3.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
|
3
|
+
module Vman
|
4
|
+
class S3
|
5
|
+
|
6
|
+
def initialize(bucket_uri)
|
7
|
+
@bucket ||= Aws::S3::Resource.new.bucket(bucket_uri[5..-1])
|
8
|
+
end
|
9
|
+
|
10
|
+
def list
|
11
|
+
@bucket.objects
|
12
|
+
end
|
13
|
+
|
14
|
+
def find(key)
|
15
|
+
@bucket.objects({ prefix: key })
|
16
|
+
end
|
17
|
+
|
18
|
+
def store(file_path, key)
|
19
|
+
@bucket.put_object({
|
20
|
+
body: File.open(file_path),
|
21
|
+
key: key
|
22
|
+
})
|
23
|
+
end
|
24
|
+
|
25
|
+
# TODO custom, more descriptive error class
|
26
|
+
def versions(key)
|
27
|
+
_versions = @bucket.object_versions({ prefix: key })
|
28
|
+
|
29
|
+
if _versions.count == 0
|
30
|
+
raise "No object exists for supplied key: #{key}"
|
31
|
+
end
|
32
|
+
|
33
|
+
_versions
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
data/lib/vman/version.rb
ADDED
data/vman.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vman/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "vman"
|
8
|
+
spec.version = Vman::VERSION
|
9
|
+
spec.authors = ["strong-code"]
|
10
|
+
spec.email = ["colin@strongco.de"]
|
11
|
+
spec.license = "Apache-2.0"
|
12
|
+
|
13
|
+
spec.summary = "Object version manager for AWS S3 buckets"
|
14
|
+
spec.description = "Command line and interactive menu interfaces for managing versioned S3 objects"
|
15
|
+
spec.homepage = "https://github.com/doximity/vman"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "bin"
|
21
|
+
spec.executables << 'vman'
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_runtime_dependency "aws-sdk", "~> 2.0"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
29
|
+
spec.add_development_dependency "minitest-reporters", "~> 1.1"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- strong-code
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.13'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest-reporters
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.1'
|
83
|
+
description: Command line and interactive menu interfaces for managing versioned S3
|
84
|
+
objects
|
85
|
+
email:
|
86
|
+
- colin@strongco.de
|
87
|
+
executables:
|
88
|
+
- vman
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- ".vman.example.json"
|
94
|
+
- CONTRIBUTING.md
|
95
|
+
- Gemfile
|
96
|
+
- LICENSE.md
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- bin/console
|
100
|
+
- bin/setup
|
101
|
+
- bin/vman
|
102
|
+
- interactive_menu.png
|
103
|
+
- lib/vman.rb
|
104
|
+
- lib/vman/help.rb
|
105
|
+
- lib/vman/menu.rb
|
106
|
+
- lib/vman/s3.rb
|
107
|
+
- lib/vman/version.rb
|
108
|
+
- vman.gemspec
|
109
|
+
homepage: https://github.com/doximity/vman
|
110
|
+
licenses:
|
111
|
+
- Apache-2.0
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.4.5.1
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: Object version manager for AWS S3 buckets
|
133
|
+
test_files: []
|