awful 0.0.148 → 0.0.149

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d420f25ad52c2ef47831260ad3877200ce63db51
4
- data.tar.gz: 5cb75305af243c48deb0fe2883345a77759063a6
3
+ metadata.gz: 0e57d00ae8d82a5f9567358f877adfe11f42c2b2
4
+ data.tar.gz: 709fade131b43199128f2f0983a46860344bfcce
5
5
  SHA512:
6
- metadata.gz: 7026740cf81eff9e4cc493b37d18d0ef50b673c3a6f1016bf3d126f7c7e9ddd767cf67ae9e7572ee2bbf624066ec876176e8ca8749e9d58c625e1a2a11edb7da
7
- data.tar.gz: 0df95ff8ef59e626b459b854f3482fbf93b5fb8f48db16e55eeb91ed6ba8aba00cdfa752f8bd7a46a683639146f8158bfc5a9869f50b61e10e640a484aa88709
6
+ metadata.gz: 93972b5343ab4e2ef2201f6b0ffa1b78627ca0f139d532e7fa4a0646299e003f30a127deb340d305c3c2525769c1d5ef07502d36475ccc1b9022597c024be186
7
+ data.tar.gz: 73fdb3e8539f4c76ab8e3b926da72bad42a50f94a055286f63bcb401864bbc53994cad0ab03c6df55f4b55916061499ba31d7ffddee30a03465ef40d5309a111
data/bin/kms ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby
2
+ #-*- mode: ruby; -*-
3
+
4
+ require 'awful'
5
+ require 'awful/kms'
6
+
7
+ Awful::Kms.start(ARGV)
@@ -0,0 +1,96 @@
1
+ module Awful
2
+ module Short
3
+ def kms(*args)
4
+ Awful::Kms.new.invoke(*args)
5
+ end
6
+ end
7
+
8
+ class Kms < Cli
9
+ COLORS = {
10
+ Enabled: :green,
11
+ PendingDeletion: :red,
12
+ }
13
+
14
+ no_commands do
15
+ def kms
16
+ @_kms ||= Aws::KMS::Client.new
17
+ end
18
+
19
+ def color(string)
20
+ set_color(string, COLORS.fetch(string.to_sym, :yellow))
21
+ end
22
+
23
+ def paginate(thing)
24
+ next_marker = nil
25
+ things = []
26
+ loop do
27
+ response = yield(next_marker)
28
+ things += response.send(thing)
29
+ next_marker = response.next_marker
30
+ break unless next_marker
31
+ end
32
+ things
33
+ end
34
+
35
+ def aliases
36
+ paginate(:aliases) do |marker|
37
+ kms.list_aliases(marker: marker)
38
+ end
39
+ end
40
+
41
+ def aliases_hash
42
+ @_aliases_hash ||= aliases.each_with_object({}) do |a, h|
43
+ h[a.target_key_id] = a.alias_name.gsub(/^alias\//, '')
44
+ end
45
+ end
46
+
47
+ ## return target id for alias
48
+ def alias_by_name(name)
49
+ aliases.find do |a|
50
+ a.alias_name == "alias/#{name}"
51
+ end.target_key_id
52
+ end
53
+
54
+ def is_uuid?(id)
55
+ id.match(/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i)
56
+ end
57
+
58
+ def id_or_alias(id)
59
+ is_uuid?(id) ? id : alias_by_name(id)
60
+ end
61
+ end
62
+
63
+ desc 'ls', 'list keys'
64
+ method_option :long, aliases: '-l', type: :boolean, default: false, desc: 'long listing'
65
+ def ls
66
+ paginate(:keys) do |marker|
67
+ kms.list_keys(marker: marker)
68
+ end.output do |keys|
69
+ if options[:long]
70
+ print_table keys.map { |k|
71
+ key = kms.describe_key(key_id: k.key_id).key_metadata
72
+ [ aliases_hash.fetch(k.key_id, '-'), k.key_id, color(key.key_state), key.creation_date ]
73
+ }.sort
74
+ else
75
+ puts keys.map(&:key_id)
76
+ end
77
+ end
78
+ end
79
+
80
+ desc 'get ID', 'describe KMS key with ID'
81
+ def get(id)
82
+ kms.describe_key(key_id: id_or_alias(id)).key_metadata.output do |key|
83
+ puts YAML.dump(stringify_keys(key.to_hash))
84
+ end
85
+ end
86
+
87
+ desc 'policy ID', 'get key policy'
88
+ method_option :name, aliases: '-n', type: :string, default: :default, desc: 'policy name'
89
+ def policy(id)
90
+ kms.get_key_policy(key_id: id_or_alias(id), policy_name: options[:name]).policy.output do |policy|
91
+ puts policy
92
+ end
93
+ end
94
+
95
+ end
96
+ end
@@ -102,12 +102,29 @@ module Awful
102
102
  end
103
103
  end
104
104
 
105
+ ## deprecated in favour of put below
105
106
  desc 'upload FILE BUCKET/OBJECT', 'upload FILE to given object'
106
107
  def upload(file, s3path)
107
108
  bucket, key = s3path.split('/', 2)
108
109
  s3_resource.bucket(bucket).object(key).upload_file(file)
109
110
  end
110
111
 
112
+ ## this is the new version of upload
113
+ desc 'put BUCKET/OBJECT [FILE]', 'put object in bucket from file/stdin/string'
114
+ method_option :string, aliases: '-s', type: :string, default: nil, desc: 'send string instead of reading a file'
115
+ method_option :kms, aliases: '-k', type: :string, default: nil, desc: 'KMS key ID for encryption'
116
+ def put(s3path, filename = nil)
117
+ bucket, key = s3path.split('/', 2)
118
+ body = options.fetch('string', file_or_stdin(filename))
119
+ s3.put_object(
120
+ bucket: bucket,
121
+ key: key,
122
+ body: body,
123
+ server_side_encryption: options[:kms] ? 'aws:kms' : nil,
124
+ ssekms_key_id: options[:kms],
125
+ )
126
+ end
127
+
111
128
  desc 'remove_bucket NAME', 'delete a bucket, which must be empty'
112
129
  def remove_bucket(name)
113
130
  if yes? "Really delete bucket #{name}?", :yellow
@@ -1,3 +1,3 @@
1
1
  module Awful
2
- VERSION = '0.0.148'
2
+ VERSION = '0.0.149'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.148
4
+ version: 0.0.149
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ric Lister
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-18 00:00:00.000000000 Z
11
+ date: 2016-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -102,6 +102,7 @@ executables:
102
102
  - elasticache
103
103
  - elb
104
104
  - iam
105
+ - kms
105
106
  - lambda
106
107
  - lc
107
108
  - r53
@@ -143,6 +144,7 @@ files:
143
144
  - bin/elasticache
144
145
  - bin/elb
145
146
  - bin/iam
147
+ - bin/kms
146
148
  - bin/lambda
147
149
  - bin/lc
148
150
  - bin/r53
@@ -182,6 +184,7 @@ files:
182
184
  - lib/awful/elasticache.rb
183
185
  - lib/awful/elb.rb
184
186
  - lib/awful/iam.rb
187
+ - lib/awful/kms.rb
185
188
  - lib/awful/lambda.rb
186
189
  - lib/awful/lambda_events.rb
187
190
  - lib/awful/launch_config.rb