heirloom 0.2.0 → 0.3.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +10 -0
- data/README.md +17 -15
- data/lib/heirloom/acl/s3.rb +3 -2
- data/lib/heirloom/archive/authorizer.rb +8 -4
- data/lib/heirloom/archive/builder.rb +8 -8
- data/lib/heirloom/archive/destroyer.rb +4 -2
- data/lib/heirloom/archive/reader.rb +15 -3
- data/lib/heirloom/archive/uploader.rb +2 -1
- data/lib/heirloom/archive/verifier.rb +2 -1
- data/lib/heirloom/archive.rb +18 -13
- data/lib/heirloom/cli/authorize.rb +52 -0
- data/lib/heirloom/cli/build.rb +25 -17
- data/lib/heirloom/cli/destroy.rb +6 -3
- data/lib/heirloom/cli/download.rb +8 -4
- data/lib/heirloom/cli/list.rb +6 -3
- data/lib/heirloom/cli/shared.rb +31 -0
- data/lib/heirloom/cli/show.rb +10 -7
- data/lib/heirloom/cli/update.rb +12 -7
- data/lib/heirloom/cli.rb +9 -2
- data/lib/heirloom/config.rb +4 -10
- data/lib/heirloom/directory/git_directory.rb +2 -2
- data/lib/heirloom/logger.rb +18 -30
- data/lib/heirloom/version.rb +1 -1
- data/script/ci_setup +4 -4
- data/spec/acl/s3_spec.rb +2 -3
- data/spec/{heirloom → archive}/authorizer_spec.rb +5 -5
- data/spec/{heirloom → archive}/builder_spec.rb +0 -0
- data/spec/{heirloom → archive}/destroyer_spec.rb +1 -2
- data/spec/{heirloom → archive}/downloader_spec.rb +0 -0
- data/spec/{heirloom → archive}/lister_spec.rb +0 -0
- data/spec/{heirloom → archive}/reader_spec.rb +20 -4
- data/spec/archive/updater_spec.rb +26 -0
- data/spec/archive/uploader_spec.rb +40 -0
- data/spec/{heirloom → archive}/verifier_spec.rb +6 -6
- data/spec/archive_spec.rb +195 -0
- data/spec/cli/shared_spec.rb +45 -0
- data/spec/config_spec.rb +11 -22
- data/spec/logger_spec.rb +3 -9
- metadata +42 -41
- data/spec/heirloom/updater_spec.rb +0 -16
- data/spec/heirloom/uploader_spec.rb +0 -16
- data/spec/heirloom_spec.rb +0 -74
data/CHANGELOG
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## v0.3.0:
|
2
|
+
|
3
|
+
* Move account authorization out of config to cli
|
4
|
+
* Move region select out of config to cli
|
5
|
+
* Updated obtions for update to use -u (not -v) for update
|
6
|
+
* Cleaned up archive specs
|
7
|
+
* Added authorize cli class
|
8
|
+
* Changed output of show / list to JSON
|
9
|
+
* Updated readme & cli help
|
10
|
+
|
1
11
|
## v0.2.0:
|
2
12
|
|
3
13
|
* Command line options updates for each sub command.
|
data/README.md
CHANGED
@@ -1,31 +1,33 @@
|
|
1
1
|
Heirloom
|
2
2
|
========
|
3
3
|
|
4
|
-
|
4
|
+
Heirloom is packages and distributes files to cloud storage services. Heirloom tracks metadata about those deployments, both about the file locations, as well as arbitrary metadata which can be set by an engineer or build process.
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
Installation
|
7
|
+
------------
|
8
8
|
|
9
|
-
|
9
|
+
First things first, install heirloom:
|
10
|
+
|
11
|
+
```
|
12
|
+
gem install heirloom
|
13
|
+
```
|
14
|
+
|
15
|
+
To get started copy the sample below into ~/.heirloom.yml and update the specified fields.
|
10
16
|
|
11
17
|
```
|
12
18
|
aws:
|
13
19
|
access_key: UPDATE_ME
|
14
20
|
secret_key: UPDATE_ME
|
15
|
-
regions:
|
16
|
-
- us-west-1
|
17
|
-
- us-west-2
|
18
|
-
- us-east-1
|
19
|
-
authorized_aws_accounts:
|
20
|
-
- UPDATE@ME
|
21
|
-
- UPDATE@ME
|
22
21
|
```
|
23
22
|
|
24
|
-
* **access_key / secret_key**:
|
25
|
-
* **regions**: AWS regions where the Heirlooms should be uploaded
|
26
|
-
* **authorized_aws_accounts**: Heirloom expects you to deploy to seperate accounts from where the Heirloom is stored. authorized_aws_accounts specifices the **email** address of other accounts to be authorized to access private Heirlooms.
|
23
|
+
* **access_key / secret_key**: AWS account credentials where you would like the archives stored.
|
27
24
|
|
28
25
|
Platforms
|
29
26
|
---------
|
30
27
|
|
31
|
-
Currently I support
|
28
|
+
Currently I support AWS S3 for object storage and AWS SimpleDB for metadata management. One day I'd like to expand to other providers.
|
29
|
+
|
30
|
+
Documentation
|
31
|
+
-------------
|
32
|
+
|
33
|
+
For more information, please view the [Heirloom Wiki](https://github.com/live-community/heirloom/wiki).
|
data/lib/heirloom/acl/s3.rb
CHANGED
@@ -8,13 +8,13 @@ module Heirloom
|
|
8
8
|
self.config = args[:config]
|
9
9
|
self.region = args[:region]
|
10
10
|
self.logger = config.logger
|
11
|
-
self.accounts = config.authorized_aws_accounts
|
12
11
|
end
|
13
12
|
|
14
13
|
def allow_read_access_from_accounts(args)
|
15
14
|
bucket = args[:bucket]
|
16
15
|
key_name = args[:key_name]
|
17
16
|
key_folder = args[:key_folder]
|
17
|
+
accounts = args[:accounts]
|
18
18
|
|
19
19
|
key = "#{key_folder}/#{key_name}.tar.gz"
|
20
20
|
|
@@ -38,11 +38,12 @@ module Heirloom
|
|
38
38
|
def build_bucket_grants(args)
|
39
39
|
id = args[:id]
|
40
40
|
name = args[:name]
|
41
|
+
accounts = args[:accounts]
|
41
42
|
|
42
43
|
a = Array.new
|
43
44
|
|
44
45
|
# Add each account email as read access
|
45
|
-
|
46
|
+
accounts.each do |g|
|
46
47
|
a << {
|
47
48
|
'Grantee' => { 'EmailAddress' => g } ,
|
48
49
|
'Permission' => 'READ'
|
@@ -9,18 +9,22 @@ module Heirloom
|
|
9
9
|
@logger = @config.logger
|
10
10
|
end
|
11
11
|
|
12
|
-
def authorize
|
12
|
+
def authorize(args)
|
13
|
+
regions = args[:regions]
|
14
|
+
accounts = args[:accounts]
|
15
|
+
|
13
16
|
@logger.info "Authorizing access to artifact."
|
14
17
|
|
15
|
-
|
18
|
+
regions.each do |region|
|
16
19
|
bucket = reader.get_bucket :region => region
|
17
20
|
|
18
21
|
s3_acl = ACL::S3.new :config => @config,
|
19
22
|
:region => region
|
20
23
|
|
21
|
-
s3_acl.allow_read_access_from_accounts :key_name
|
24
|
+
s3_acl.allow_read_access_from_accounts :key_name => @id,
|
22
25
|
:key_folder => @name,
|
23
|
-
:bucket
|
26
|
+
:bucket => bucket,
|
27
|
+
:accounts => accounts
|
24
28
|
end
|
25
29
|
|
26
30
|
@logger.info "Authorization complete."
|
@@ -47,14 +47,6 @@ module Heirloom
|
|
47
47
|
add_git_commit_to_artifact_record git_commit
|
48
48
|
end
|
49
49
|
|
50
|
-
def create_artifact_record
|
51
|
-
attributes = { 'built_by' => "#{user}@#{hostname}",
|
52
|
-
'built_at' => Time.now.utc.iso8601,
|
53
|
-
'id' => id }
|
54
|
-
logger.info "Create artifact record #{id}."
|
55
|
-
sdb.put_attributes name, id, attributes
|
56
|
-
end
|
57
|
-
|
58
50
|
def add_git_commit_to_artifact_record(commit)
|
59
51
|
attributes = { 'sha' => id,
|
60
52
|
'abbreviated_sha' => commit.id_abbrev,
|
@@ -69,6 +61,14 @@ module Heirloom
|
|
69
61
|
sdb.put_attributes name, id, attributes
|
70
62
|
end
|
71
63
|
|
64
|
+
def create_artifact_record
|
65
|
+
attributes = { 'built_by' => "#{user}@#{hostname}",
|
66
|
+
'built_at' => Time.now.utc.iso8601,
|
67
|
+
'id' => id }
|
68
|
+
logger.info "Create artifact record #{id}."
|
69
|
+
sdb.put_attributes name, id, attributes
|
70
|
+
end
|
71
|
+
|
72
72
|
def sdb
|
73
73
|
@sdb ||= AWS::SimpleDB.new :config => config
|
74
74
|
end
|
@@ -11,10 +11,12 @@ module Heirloom
|
|
11
11
|
self.logger = config.logger
|
12
12
|
end
|
13
13
|
|
14
|
-
def destroy
|
14
|
+
def destroy(args)
|
15
|
+
regions = args[:regions]
|
16
|
+
|
15
17
|
logger.info "Destroying #{@name} - #{@id}"
|
16
18
|
|
17
|
-
|
19
|
+
regions.each do |region|
|
18
20
|
bucket = reader.get_bucket :region => region
|
19
21
|
|
20
22
|
key = "#{id}.tar.gz"
|
@@ -21,6 +21,13 @@ module Heirloom
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
def regions
|
25
|
+
data = show.keys.map do |key|
|
26
|
+
key.gsub('-s3-url', '') if key =~ /-s3-url$/
|
27
|
+
end
|
28
|
+
data.compact
|
29
|
+
end
|
30
|
+
|
24
31
|
def get_bucket(args)
|
25
32
|
@logger.debug "Looking for bucket in #{args[:region]} for #{id}"
|
26
33
|
url = get_url(args)
|
@@ -47,8 +54,13 @@ module Heirloom
|
|
47
54
|
end
|
48
55
|
|
49
56
|
def show
|
50
|
-
|
51
|
-
items[id] ?
|
57
|
+
query = sdb.select "select * from #{name} where itemName() = '#{id}'"
|
58
|
+
items = query[id] ? query[id] : {}
|
59
|
+
r = {}
|
60
|
+
items.each_pair.map do |key,value|
|
61
|
+
r[key] = value.first
|
62
|
+
end
|
63
|
+
r
|
52
64
|
end
|
53
65
|
|
54
66
|
private
|
@@ -59,7 +71,7 @@ module Heirloom
|
|
59
71
|
url = "#{args[:region]}-s3-url"
|
60
72
|
if show[url]
|
61
73
|
@logger.debug "Found #{url} for #{id}."
|
62
|
-
show[url]
|
74
|
+
show[url]
|
63
75
|
else
|
64
76
|
@logger.debug "#{args[:region]} endpoint for #{id} not found."
|
65
77
|
nil
|
@@ -12,9 +12,10 @@ module Heirloom
|
|
12
12
|
def upload(args)
|
13
13
|
heirloom_file = args[:file]
|
14
14
|
bucket_prefix = args[:bucket_prefix]
|
15
|
+
regions = args[:regions]
|
15
16
|
public_readable = args[:public_readable]
|
16
17
|
|
17
|
-
|
18
|
+
regions.each do |region|
|
18
19
|
bucket = "#{bucket_prefix}-#{region}"
|
19
20
|
|
20
21
|
s3_uploader = Uploader::S3.new :config => @config,
|
@@ -10,9 +10,10 @@ module Heirloom
|
|
10
10
|
|
11
11
|
def buckets_exist?(args)
|
12
12
|
bucket_prefix = args[:bucket_prefix]
|
13
|
+
regions = args[:regions]
|
13
14
|
result = true
|
14
15
|
|
15
|
-
|
16
|
+
regions.each do |region|
|
16
17
|
bucket = "#{bucket_prefix}-#{region}"
|
17
18
|
|
18
19
|
s3 ||= AWS::S3.new :config => @config,
|
data/lib/heirloom/archive.rb
CHANGED
@@ -19,8 +19,9 @@ module Heirloom
|
|
19
19
|
@id = args[:id]
|
20
20
|
end
|
21
21
|
|
22
|
-
def authorize
|
23
|
-
authorizer.authorize
|
22
|
+
def authorize(accounts)
|
23
|
+
authorizer.authorize :accounts => accounts,
|
24
|
+
:regions => regions
|
24
25
|
end
|
25
26
|
|
26
27
|
def build(args)
|
@@ -36,7 +37,7 @@ module Heirloom
|
|
36
37
|
end
|
37
38
|
|
38
39
|
def upload(args)
|
39
|
-
uploader.upload args
|
40
|
+
uploader.upload({ :regions => regions }.merge(args))
|
40
41
|
end
|
41
42
|
|
42
43
|
def exists?
|
@@ -48,7 +49,7 @@ module Heirloom
|
|
48
49
|
end
|
49
50
|
|
50
51
|
def destroy
|
51
|
-
destroyer.destroy
|
52
|
+
destroyer.destroy :regions => regions
|
52
53
|
end
|
53
54
|
|
54
55
|
def show
|
@@ -63,6 +64,10 @@ module Heirloom
|
|
63
64
|
builder.cleanup
|
64
65
|
end
|
65
66
|
|
67
|
+
def regions
|
68
|
+
reader.regions
|
69
|
+
end
|
70
|
+
|
66
71
|
private
|
67
72
|
|
68
73
|
def lister
|
@@ -89,9 +94,9 @@ module Heirloom
|
|
89
94
|
end
|
90
95
|
|
91
96
|
def uploader
|
92
|
-
@uploader ||= Uploader.new :config
|
93
|
-
:name
|
94
|
-
:id
|
97
|
+
@uploader ||= Uploader.new :config => @config,
|
98
|
+
:name => @name,
|
99
|
+
:id => @id
|
95
100
|
end
|
96
101
|
|
97
102
|
def downloader
|
@@ -101,15 +106,15 @@ module Heirloom
|
|
101
106
|
end
|
102
107
|
|
103
108
|
def authorizer
|
104
|
-
@authorizer ||= Authorizer.new :config
|
105
|
-
:name
|
106
|
-
:id
|
109
|
+
@authorizer ||= Authorizer.new :config => @config,
|
110
|
+
:name => @name,
|
111
|
+
:id => @id
|
107
112
|
end
|
108
113
|
|
109
114
|
def destroyer
|
110
|
-
@destroyer ||= Destroyer.new :config
|
111
|
-
:name
|
112
|
-
:id
|
115
|
+
@destroyer ||= Destroyer.new :config => @config,
|
116
|
+
:name => @name,
|
117
|
+
:id => @id
|
113
118
|
end
|
114
119
|
|
115
120
|
def verifier
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Heirloom
|
4
|
+
module CLI
|
5
|
+
class Authorize
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@opts = read_options
|
9
|
+
@logger = HeirloomLogger.new :log_level => @opts[:level]
|
10
|
+
|
11
|
+
exit 1 unless CLI::Shared.valid_options? :provided => @opts,
|
12
|
+
:required => [:accounts,
|
13
|
+
:name, :id],
|
14
|
+
:logger => @logger
|
15
|
+
@archive = Archive.new :name => @opts[:name],
|
16
|
+
:id => @opts[:id],
|
17
|
+
:logger => @logger
|
18
|
+
end
|
19
|
+
|
20
|
+
def authorize
|
21
|
+
@archive.authorize @opts[:accounts]
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def read_options
|
27
|
+
Trollop::options do
|
28
|
+
version Heirloom::VERSION
|
29
|
+
banner <<-EOS
|
30
|
+
|
31
|
+
Authorize access from another AWS account to an archive.
|
32
|
+
|
33
|
+
Usage:
|
34
|
+
|
35
|
+
heirloom authorize -n NAME -i ID -a AWS_ACCOUNT1-a AWS_ACCOUNT2
|
36
|
+
|
37
|
+
Note: This will replace all current authorizations with those specified and make the archive private.
|
38
|
+
|
39
|
+
EOS
|
40
|
+
opt :accounts, "AWS Account(s) email to authorize. Can be specified multiple times.", :type => :string,
|
41
|
+
:multi => true
|
42
|
+
opt :help, "Display Help"
|
43
|
+
opt :id, "id of the archive to authorize.", :type => :string
|
44
|
+
opt :level, "Log level [debug|info|warn|error].", :type => :string,
|
45
|
+
:default => 'info'
|
46
|
+
opt :name, "Name of archive.", :type => :string
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/heirloom/cli/build.rb
CHANGED
@@ -7,29 +7,34 @@ module Heirloom
|
|
7
7
|
def initialize
|
8
8
|
@opts = read_options
|
9
9
|
@logger = HeirloomLogger.new :log_level => @opts[:level]
|
10
|
+
exit 1 unless CLI::Shared.valid_options? :provided => @opts,
|
11
|
+
:required => [:name, :id, :regions,
|
12
|
+
:bucket_prefix,
|
13
|
+
:directory],
|
14
|
+
:logger => @logger
|
10
15
|
@archive = Archive.new :name => @opts[:name],
|
11
16
|
:id => @opts[:id],
|
12
17
|
:logger => @logger
|
13
18
|
end
|
14
19
|
|
15
20
|
def build
|
16
|
-
unless @archive.buckets_exist? :bucket_prefix => @opts[:bucket_prefix]
|
21
|
+
unless @archive.buckets_exist? :bucket_prefix => @opts[:bucket_prefix],
|
22
|
+
:regions => @opts[:regions]
|
17
23
|
@logger.error "Buckets do no exist in required regions."
|
18
24
|
exit 1
|
19
25
|
end
|
20
26
|
|
21
27
|
@archive.destroy if @archive.exists?
|
22
28
|
|
23
|
-
archive_file = @archive.build :bucket_prefix
|
24
|
-
:directory
|
25
|
-
:exclude
|
26
|
-
:
|
27
|
-
:git => @opts[:git]
|
29
|
+
archive_file = @archive.build :bucket_prefix => @opts[:bucket_prefix],
|
30
|
+
:directory => @opts[:directory],
|
31
|
+
:exclude => @opts[:exclude].split(','),
|
32
|
+
:git => @opts[:git]
|
28
33
|
|
29
|
-
@archive.upload :bucket_prefix
|
30
|
-
:
|
31
|
-
|
32
|
-
|
34
|
+
@archive.upload :bucket_prefix => @opts[:bucket_prefix],
|
35
|
+
:regions => @opts[:regions],
|
36
|
+
:public_readable => @opts[:public],
|
37
|
+
:file => archive_file
|
33
38
|
|
34
39
|
@archive.cleanup
|
35
40
|
end
|
@@ -45,21 +50,24 @@ Build and upload a new archive.
|
|
45
50
|
|
46
51
|
Usage:
|
47
52
|
|
48
|
-
heirloom build -n NAME -i ID -b BUCKET_PREFIX [-d
|
53
|
+
heirloom build -n NAME -i ID -b BUCKET_PREFIX -r REGION [-d DIRECTORY_TO_BUILD] [-p] [-g] [-e DIRECTORIES_TO_EXCLUDE] [-l LOG_LEVEL]
|
49
54
|
|
50
55
|
EOS
|
51
|
-
opt :bucket_prefix, "Bucket prefix which will be combined with region
|
56
|
+
opt :bucket_prefix, "Bucket prefix which will be combined with region.\
|
57
|
+
For example: -b 'test' -r 'us-west-1' will expect bucket 'test-us-west-1' to be present", :type => :string
|
52
58
|
opt :directory, "Source directory of build.", :type => :string,
|
53
59
|
:default => '.'
|
54
|
-
opt :exclude, "Comma spereate list of files or directories to exclude.", :type
|
60
|
+
opt :exclude, "Comma spereate list of files or directories to exclude.", :type => :string,
|
55
61
|
:default => '.git'
|
56
|
-
opt :git, "Read git commit information from directory."
|
62
|
+
opt :git, "Read git commit information from directory and set as archive attributes."
|
57
63
|
opt :help, "Display Help"
|
58
|
-
opt :id, "
|
59
|
-
opt :level, "Log level.", :type => :string,
|
60
|
-
|
64
|
+
opt :id, "id for archive (when -g specified, assumed to be GIT sha).", :type => :string
|
65
|
+
opt :level, "Log level [debug|info|warn|error].", :type => :string,
|
66
|
+
:default => 'info'
|
61
67
|
opt :name, "Name of archive.", :type => :string
|
62
68
|
opt :public, "Set this archive as public readable?"
|
69
|
+
opt :regions, "Region(s) to upload archive. Can be set multiple times.", :type => :string,
|
70
|
+
:multi => true
|
63
71
|
end
|
64
72
|
end
|
65
73
|
|
data/lib/heirloom/cli/destroy.rb
CHANGED
@@ -4,9 +4,12 @@ module Heirloom
|
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
@opts = read_options
|
7
|
+
@logger = HeirloomLogger.new :log_level => @opts[:level]
|
8
|
+
exit 1 unless CLI::Shared.valid_options? :provided => @opts,
|
9
|
+
:required => [:name, :id],
|
10
|
+
:logger => @logger
|
7
11
|
@name = @opts[:name]
|
8
12
|
@id = @opts[:id]
|
9
|
-
@logger = HeirloomLogger.new :log_level => @opts[:level]
|
10
13
|
@archive = Archive.new :name => @name,
|
11
14
|
:id => @id,
|
12
15
|
:logger => @logger
|
@@ -32,8 +35,8 @@ heirloom destroy -n NAME -i ID [-l LOG_LEVEL]
|
|
32
35
|
EOS
|
33
36
|
opt :help, "Display Help"
|
34
37
|
opt :id, "ID of the archive to display.", :type => :string
|
35
|
-
opt :level, "Log level.", :type => :string,
|
36
|
-
|
38
|
+
opt :level, "Log level [debug|info|warn|error].", :type => :string,
|
39
|
+
:default => 'info'
|
37
40
|
opt :name, "Name of archive.", :type => :string
|
38
41
|
end
|
39
42
|
end
|
@@ -5,6 +5,10 @@ module Heirloom
|
|
5
5
|
def initialize
|
6
6
|
@opts = read_options
|
7
7
|
@logger = HeirloomLogger.new :log_level => @opts[:level]
|
8
|
+
exit 1 unless CLI::Shared.valid_options? :provided => @opts,
|
9
|
+
:required => [:name, :id, :output],
|
10
|
+
:logger => @logger
|
11
|
+
|
8
12
|
@archive = Archive.new :name => @opts[:name],
|
9
13
|
:id => @opts[:id],
|
10
14
|
:logger => @logger
|
@@ -30,13 +34,13 @@ heirloom download -n NAME -i ID -r REGION -o OUTPUT_FILE
|
|
30
34
|
|
31
35
|
EOS
|
32
36
|
opt :help, "Display Help"
|
33
|
-
opt :id, "
|
34
|
-
opt :level, "Log level.", :type => :string,
|
35
|
-
:default => 'info'
|
37
|
+
opt :id, "id of the archive to download.", :type => :string
|
36
38
|
opt :name, "Name of archive.", :type => :string
|
39
|
+
opt :level, "Log level [debug|info|warn|error].", :type => :string,
|
40
|
+
:default => 'info'
|
37
41
|
opt :output, "Location to download archive.", :type => :string
|
38
42
|
opt :region, "Region to download archive.", :type => :string,
|
39
|
-
|
43
|
+
:default => 'us-west-1'
|
40
44
|
end
|
41
45
|
end
|
42
46
|
end
|
data/lib/heirloom/cli/list.rb
CHANGED
@@ -5,12 +5,15 @@ module Heirloom
|
|
5
5
|
def initialize
|
6
6
|
@opts = read_options
|
7
7
|
@logger = HeirloomLogger.new :log_level => @opts[:level]
|
8
|
+
exit 1 unless CLI::Shared.valid_options? :provided => @opts,
|
9
|
+
:required => [:name],
|
10
|
+
:logger => @logger
|
8
11
|
@archive = Archive.new :name => @opts[:name],
|
9
12
|
:logger => @logger
|
10
13
|
end
|
11
14
|
|
12
15
|
def list(count = @opts[:count])
|
13
|
-
|
16
|
+
jj @archive.list(count)
|
14
17
|
end
|
15
18
|
|
16
19
|
private
|
@@ -28,8 +31,8 @@ heirloom list -n NAME
|
|
28
31
|
|
29
32
|
EOS
|
30
33
|
opt :help, "Display Help"
|
31
|
-
opt :level, "Log level.", :type => :string,
|
32
|
-
|
34
|
+
opt :level, "Log level [debug|info|warn|error].", :type => :string,
|
35
|
+
:default => 'info'
|
33
36
|
opt :name, "Name of archive.", :type => :string
|
34
37
|
opt :count, "Number of versions to return.", :type => :integer,
|
35
38
|
:default => 10
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Heirloom
|
2
|
+
module CLI
|
3
|
+
module Shared
|
4
|
+
|
5
|
+
def self.valid_options?(args)
|
6
|
+
provided = args[:provided]
|
7
|
+
required = args[:required]
|
8
|
+
logger = args[:logger]
|
9
|
+
|
10
|
+
missing_opts = required.map do |opt|
|
11
|
+
case provided[opt]
|
12
|
+
when nil
|
13
|
+
"Option '#{opt} (-#{opt[0]})' required but not specified."
|
14
|
+
when []
|
15
|
+
"Option '#{opt} (-#{opt[0]})' required but not specified."
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
missing_opts.compact!
|
20
|
+
|
21
|
+
if missing_opts.any?
|
22
|
+
missing_opts.each {|missing_opt| logger.error missing_opt}
|
23
|
+
end
|
24
|
+
|
25
|
+
missing_opts.any? ? false : true
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/heirloom/cli/show.rb
CHANGED
@@ -4,15 +4,18 @@ module Heirloom
|
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
@opts = read_options
|
7
|
-
id = @opts[:id] ? @opts[:id] : latest_id
|
8
7
|
@logger = HeirloomLogger.new :log_level => @opts[:level]
|
8
|
+
exit 1 unless CLI::Shared.valid_options? :provided => @opts,
|
9
|
+
:required => [:name],
|
10
|
+
:logger => @logger
|
11
|
+
id = @opts[:id] ? @opts[:id] : latest_id
|
9
12
|
@archive = Archive.new :name => @opts[:name],
|
10
|
-
:
|
11
|
-
:
|
13
|
+
:logger => @logger,
|
14
|
+
:id => id
|
12
15
|
end
|
13
16
|
|
14
17
|
def show
|
15
|
-
|
18
|
+
jj @archive.show
|
16
19
|
end
|
17
20
|
|
18
21
|
private
|
@@ -37,10 +40,10 @@ If -i is ommited, latest version is displayed.
|
|
37
40
|
|
38
41
|
EOS
|
39
42
|
opt :help, "Display Help"
|
40
|
-
opt :level, "Log level.", :type => :string,
|
41
|
-
|
43
|
+
opt :level, "Log level [debug|info|warn|error].", :type => :string,
|
44
|
+
:default => 'info'
|
42
45
|
opt :name, "Name of archive.", :type => :string
|
43
|
-
opt :id, "
|
46
|
+
opt :id, "id of the archive to display.", :type => :string
|
44
47
|
end
|
45
48
|
end
|
46
49
|
|
data/lib/heirloom/cli/update.rb
CHANGED
@@ -1,18 +1,23 @@
|
|
1
|
-
module Heirloom
|
1
|
+
module Heirloom
|
2
2
|
module CLI
|
3
3
|
class Update
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
@opts = read_options
|
7
7
|
@logger = HeirloomLogger.new :log_level => @opts[:level]
|
8
|
+
exit 1 unless CLI::Shared.valid_options? :provided => @opts,
|
9
|
+
:required => [:name, :id,
|
10
|
+
:attribute,
|
11
|
+
:updated_value],
|
12
|
+
:logger => @logger
|
8
13
|
@archive = Archive.new :name => @opts[:name],
|
9
14
|
:id => @opts[:id],
|
10
15
|
:logger => @logger
|
11
16
|
end
|
12
17
|
|
13
18
|
def update
|
14
|
-
@archive.update :attribute
|
15
|
-
:value
|
19
|
+
@archive.update :attribute => @opts[:attribute],
|
20
|
+
:value => @opts[:updated_value]
|
16
21
|
end
|
17
22
|
|
18
23
|
private
|
@@ -26,16 +31,16 @@ Update an archive's attribute.
|
|
26
31
|
|
27
32
|
Usage:
|
28
33
|
|
29
|
-
heirloom update -n NAME -i ID -a ATTRIBUTE_TO_UPDATE -
|
34
|
+
heirloom update -n NAME -i ID -a ATTRIBUTE_TO_UPDATE -u UPDATED_VALUE
|
30
35
|
|
31
36
|
EOS
|
32
37
|
opt :attribute, "Attribute to update.", :type => :string
|
33
38
|
opt :help, "Display Help"
|
34
39
|
opt :id, "ID of the archive to display.", :type => :string
|
35
|
-
opt :level, "Log level.", :type => :string,
|
36
|
-
|
40
|
+
opt :level, "Log level [debug|info|warn|error].", :type => :string,
|
41
|
+
:default => 'info'
|
37
42
|
opt :name, "Name of archive.", :type => :string
|
38
|
-
opt :
|
43
|
+
opt :updated_value, "Updated value of attribute.", :type => :string
|
39
44
|
end
|
40
45
|
end
|
41
46
|
end
|