knife-s3 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/chef/knife/s3_base.rb +89 -0
- data/lib/chef/knife/s3_list.rb +60 -0
- data/lib/knife-s3/version.rb +3 -0
- metadata +79 -0
@@ -0,0 +1,89 @@
|
|
1
|
+
#
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
3
|
+
# you may not use this file except in compliance with the License.
|
4
|
+
# You may obtain a copy of the License at
|
5
|
+
#
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
7
|
+
#
|
8
|
+
# Unless required by applicable law or agreed to in writing, software
|
9
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
# See the License for the specific language governing permissions and
|
12
|
+
# limitations under the License.
|
13
|
+
#
|
14
|
+
|
15
|
+
# s3_base.rb based on cfn_base.rb by Neil Turner, which can be found at https://github.com/neillturner/knife-cfn
|
16
|
+
|
17
|
+
require 'chef/knife'
|
18
|
+
|
19
|
+
class Chef
|
20
|
+
class Knife
|
21
|
+
class S3Base < Knife
|
22
|
+
def self.included(includer)
|
23
|
+
includer.class_eval do
|
24
|
+
|
25
|
+
deps do
|
26
|
+
require 'fog'
|
27
|
+
require 'readline'
|
28
|
+
require 'chef/json_compat'
|
29
|
+
end
|
30
|
+
|
31
|
+
option :aws_access_key_id,
|
32
|
+
:short => "-A ID",
|
33
|
+
:long => "--aws-access-key-id KEY",
|
34
|
+
:description => "AWS Access Key ID",
|
35
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:aws_access_key_id] = key }
|
36
|
+
|
37
|
+
option :aws_secret_access_key,
|
38
|
+
:short => "-K SECRET",
|
39
|
+
:long => "--aws-secret-access-key SECRET",
|
40
|
+
:description => "Your AWS API Secret Access Key",
|
41
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:aws_secret_access_key] = key }
|
42
|
+
|
43
|
+
option :region,
|
44
|
+
:long => "--region REGION",
|
45
|
+
:description => "Your AWS region",
|
46
|
+
:default => "us-west-1",
|
47
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:region] = key }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
def connection
|
51
|
+
@connection ||= begin
|
52
|
+
connection = Fog::Storage.new(
|
53
|
+
:provider => 'AWS',
|
54
|
+
:aws_access_key_id => Chef::Config[:knife][:aws_access_key_id],
|
55
|
+
:aws_secret_access_key => Chef::Config[:knife][:aws_secret_access_key],
|
56
|
+
:region => locate_config_value(:region)
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def locate_config_value(key)
|
62
|
+
key = key.to_sym
|
63
|
+
Chef::Config[:knife][key] || config[key]
|
64
|
+
end
|
65
|
+
|
66
|
+
def msg_pair(label, value, color=:cyan)
|
67
|
+
if value && @value.to_s.empty?
|
68
|
+
puts "#{ui.color(label, color)}: #{value}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def validate!(keys=[:aws_access_key_id, :aws_secret_access_key])
|
73
|
+
errors = []
|
74
|
+
|
75
|
+
keys.each do |k|
|
76
|
+
pretty_key = k.to_s.gsub(/_/, ' ').gsub(/\w+/){ |w| (w =~ /(ssh)|(aws)/i) ? w.upcase : w.capitalize }
|
77
|
+
if Chef::Config[:knife][k].nil?
|
78
|
+
errors << "You did not provide a valid '#{pretty_key}' value."
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
if errors.each{|e| ui.error(e)}.any?
|
83
|
+
exit 1
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'chef/knife'
|
2
|
+
require 'chef/knife/s3_base'
|
3
|
+
|
4
|
+
class Chef
|
5
|
+
class Knife
|
6
|
+
class S3List < Chef::Knife::S3Base
|
7
|
+
|
8
|
+
deps do
|
9
|
+
require 'fog'
|
10
|
+
require 'readline'
|
11
|
+
require 'chef/json_compat'
|
12
|
+
require 'chef/knife/bootstrap'
|
13
|
+
Chef::Knife::Bootstrap.load_deps
|
14
|
+
end
|
15
|
+
|
16
|
+
banner "knife s3 list <bucket name>"
|
17
|
+
|
18
|
+
option :bucket_name,
|
19
|
+
:short => "-b BUCKET",
|
20
|
+
:long => "--bucket BUCKET",
|
21
|
+
:description => "Sets bucket name"
|
22
|
+
|
23
|
+
option :prefix,
|
24
|
+
:short => "-p PREFIX",
|
25
|
+
:long => "--prefix PREFIX",
|
26
|
+
:description => "A prefix to search within (path)"
|
27
|
+
|
28
|
+
def run
|
29
|
+
$stdout.sync = true
|
30
|
+
|
31
|
+
validate!
|
32
|
+
|
33
|
+
if config[:bucket_name]
|
34
|
+
puts "Listing bucket " + config[:bucket_name]
|
35
|
+
else
|
36
|
+
puts "Please supply a bucket name"
|
37
|
+
exit 1
|
38
|
+
end
|
39
|
+
|
40
|
+
if config[:prefix]
|
41
|
+
puts "Filtering by prefix " + config[:prefix]
|
42
|
+
end
|
43
|
+
|
44
|
+
begin
|
45
|
+
if config[:prefix].nil?
|
46
|
+
connection.directories.get(config[:bucket_name]).files.map do |file|
|
47
|
+
puts file.key
|
48
|
+
end
|
49
|
+
else
|
50
|
+
connection.directories.get(config[:bucket_name], prefix: config[:prefix]).files.map do |file|
|
51
|
+
puts file.key
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knife-s3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brett Cave
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: fog
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: chef
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '11'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '11'
|
46
|
+
description: S3 Support for Chef's Knife Command
|
47
|
+
email: brett@cave.za.net
|
48
|
+
executables: []
|
49
|
+
extensions: []
|
50
|
+
extra_rdoc_files: []
|
51
|
+
files:
|
52
|
+
- lib/chef/knife/s3_list.rb
|
53
|
+
- lib/chef/knife/s3_base.rb
|
54
|
+
- lib/knife-s3/version.rb
|
55
|
+
homepage: https://github.com/brettcave/knife-s3
|
56
|
+
licenses: []
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.8.25
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: S3 Support for Knife
|
79
|
+
test_files: []
|