swa 0.4.3 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6aaa1176986a7480f4aeba71a8864ce133083c20
4
- data.tar.gz: 03b8bd838b24a235a1c1bb499b06ce0e761b6fad
3
+ metadata.gz: 83e548dcd3489014b39e2abeaa629f2d992abb3a
4
+ data.tar.gz: 8631da8f320f0c4f836679cbb8051271a39e423b
5
5
  SHA512:
6
- metadata.gz: f4d039e776472e25cdf8028ea81e420957ecc97416ee0e2ac571d4f5a3261c2bce52196cec049874e9a04a6d3d5afd4d58f9a6ddf554899d4d4a4e1aad2efe89
7
- data.tar.gz: da52ab84256340a1b71b287831f3b5cb9153e7ff301c942a3c43ebd556a41cc0260b2e305a67a71f8546f4943160d2ed0804ccb88dbf3fc8be7d140caaf56c50
6
+ metadata.gz: 05538c822b54162fa9e46ea392dc78d35d23b1f52f0113bc42191888dfef9bdedd6a3a78613ee5f6c86e9efb7a86281d7c983436829dedeb1b5906cc70859d35
7
+ data.tar.gz: f6bf15581d16ec77d4133a3a22401e0218b6ce10e0fa384f5fb15e45f325370da59cd97026762706b370682855ae478d081feed465dc1b6541c69bb5fec06d45
@@ -0,0 +1,38 @@
1
+ require "aws-sdk-resources"
2
+ require "swa/cli/base_command"
3
+ require "swa/cli/collection_behaviour"
4
+ require "swa/cli/item_behaviour"
5
+ require "swa/cloud_formation/stack"
6
+
7
+ module Swa
8
+ module CLI
9
+
10
+ class CloudFormationCommand < BaseCommand
11
+
12
+ subcommand ["stacks"], "Show stacks" do
13
+
14
+ include CollectionBehaviour
15
+
16
+ private
17
+
18
+ def collection
19
+ query_for(:stacks, Swa::CloudFormation::Stack)
20
+ end
21
+
22
+ end
23
+
24
+ protected
25
+
26
+ def cloud_formation
27
+ ::Aws::CloudFormation::Resource.new(aws_config)
28
+ end
29
+
30
+ def query_for(query_method, model)
31
+ aws_resources = cloud_formation.public_send(query_method, query_options)
32
+ model.list(aws_resources)
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+ end
@@ -1,16 +1,20 @@
1
1
  require "swa/cli/base_command"
2
+ require "swa/cli/cloud_formation_command"
2
3
  require "swa/cli/ec2_command"
3
4
  require "swa/cli/iam_command"
4
5
  require "swa/cli/kms_command"
6
+ require "swa/cli/s3_command"
5
7
 
6
8
  module Swa
7
9
  module CLI
8
10
 
9
11
  class MainCommand < BaseCommand
10
12
 
13
+ subcommand ["cf", "cloudformation"], "CloudFormation stuff", CloudFormationCommand
11
14
  subcommand "ec2", "EC2 stuff", Ec2Command
12
15
  subcommand "iam", "IAM stuff", IamCommand
13
16
  subcommand "kms", "KMS stuff", KmsCommand
17
+ subcommand "s3", "S3 stuff", S3Command
14
18
 
15
19
  protected
16
20
 
@@ -0,0 +1,62 @@
1
+ require "aws-sdk-resources"
2
+ require "swa/cli/base_command"
3
+ require "swa/cli/collection_behaviour"
4
+ require "swa/cli/item_behaviour"
5
+ require "swa/cli/tag_filter_options"
6
+ require "swa/s3/bucket"
7
+
8
+ module Swa
9
+ module CLI
10
+
11
+ class S3Command < BaseCommand
12
+
13
+ subcommand ["bucket"], "Show bucket" do
14
+
15
+ parameter "NAME", "bucket name"
16
+
17
+ include ItemBehaviour
18
+
19
+ private
20
+
21
+ def item
22
+ Swa::S3::Bucket.new(s3.bucket(name))
23
+ end
24
+
25
+ subcommand "policy", "print bucket policy" do
26
+
27
+ def execute
28
+ puts item.policy
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+
35
+ subcommand ["buckets"], "List buckets" do
36
+
37
+ include TagFilterOptions
38
+ include CollectionBehaviour
39
+
40
+ private
41
+
42
+ def collection
43
+ query_for(:buckets, Swa::S3::Bucket)
44
+ end
45
+
46
+ end
47
+
48
+ protected
49
+
50
+ def s3
51
+ ::Aws::S3::Resource.new(aws_config)
52
+ end
53
+
54
+ def query_for(query_method, resource_model)
55
+ aws_resources = s3.public_send(query_method)
56
+ wrapped_resources = resource_model.list(aws_resources)
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,30 @@
1
+ require "swa/resource"
2
+
3
+ module Swa
4
+ module CloudFormation
5
+
6
+ class Stack < Resource
7
+
8
+ def summary
9
+ [
10
+ name,
11
+ # pad(subnet.subnet_id, 15),
12
+ # pad(subnet.vpc_id, 12),
13
+ # pad(subnet.availability_zone, 15),
14
+ # pad(subnet.cidr_block, 18),
15
+ # quoted(name)
16
+ ].join(" ")
17
+ end
18
+
19
+ def name
20
+ stack.name
21
+ end
22
+
23
+ private
24
+
25
+ alias_method :stack, :aws_resource
26
+
27
+ end
28
+
29
+ end
30
+ end
@@ -18,6 +18,28 @@ module Swa
18
18
  s.rjust(width)
19
19
  end
20
20
 
21
+ WIDTH_BY_TYPE = {
22
+ :availability_zone => 15,
23
+ :cidr_block => 18,
24
+ :group_id => 11,
25
+ :image_id => 12,
26
+ :instance_id => 19,
27
+ :instance_type => 10,
28
+ :private_ip_address => 14,
29
+ :public_ip_address => 14,
30
+ :snapshot_id => 22,
31
+ :subnet_id => 15,
32
+ :volume_id => 21,
33
+ :volume_type => 9,
34
+ :vpc_id => 12
35
+ }
36
+
37
+ def field(resource, field_name, type = field_name)
38
+ width = WIDTH_BY_TYPE.fetch(type.to_sym)
39
+ value = resource.public_send(field_name)
40
+ pad(value, width)
41
+ end
42
+
21
43
  def camelize_keys(data)
22
44
  case data
23
45
  when Hash
@@ -10,7 +10,7 @@ module Swa
10
10
 
11
11
  def summary
12
12
  [
13
- pad(ami.image_id, 12),
13
+ field(ami, :image_id),
14
14
  ami.creation_date.sub(".000Z", "Z"),
15
15
  quoted(name)
16
16
  ].join(" ")
@@ -11,12 +11,12 @@ module Swa
11
11
 
12
12
  def summary
13
13
  [
14
- pad(i.instance_id, 10),
15
- pad(i.image_id, 12),
16
- pad(i.instance_type, 10),
14
+ field(i, :instance_id),
15
+ field(i, :image_id),
16
+ field(i, :instance_type),
17
17
  pad(i.state.name, 10),
18
- pad(i.private_ip_address, 14),
19
- pad(i.public_ip_address, 14),
18
+ field(i, :private_ip_address),
19
+ field(i, :public_ip_address),
20
20
  quoted(name)
21
21
  ].join(" ")
22
22
  end
@@ -8,8 +8,8 @@ module Swa
8
8
 
9
9
  def summary
10
10
  [
11
- pad(sg.group_id, 11),
12
- pad(sg.vpc_id, 12),
11
+ field(sg, :group_id),
12
+ field(sg, :vpc_id),
13
13
  quoted(sg.group_name)
14
14
  ].join(" ")
15
15
  end
@@ -10,8 +10,8 @@ module Swa
10
10
 
11
11
  def summary
12
12
  [
13
- pad(s.snapshot_id, 13),
14
- pad(s.volume_id, 12),
13
+ field(s, :snapshot_id),
14
+ field(s, :volume_id),
15
15
  sprintf("%5d", s.volume_size),
16
16
  s.start_time.iso8601,
17
17
  rpad(s.progress, 4),
@@ -10,10 +10,10 @@ module Swa
10
10
 
11
11
  def summary
12
12
  [
13
- pad(subnet.subnet_id, 15),
14
- pad(subnet.vpc_id, 12),
15
- pad(subnet.availability_zone, 15),
16
- pad(subnet.cidr_block, 18),
13
+ field(subnet, :subnet_id),
14
+ field(subnet, :vpc_id),
15
+ field(subnet, :availability_zone),
16
+ field(subnet, :cidr_block),
17
17
  quoted(name)
18
18
  ].join(" ")
19
19
  end
@@ -10,11 +10,11 @@ module Swa
10
10
 
11
11
  def summary
12
12
  [
13
- pad(v.volume_id, 12),
14
- pad(v.snapshot_id, 13),
13
+ field(v, :volume_id),
14
+ field(v, :snapshot_id),
15
15
  sprintf("%5d", v.size),
16
- pad(v.volume_type, 9),
17
- pad(attachment.instance_id, 10),
16
+ field(v, :volume_type),
17
+ field(attachment, :instance_id),
18
18
  pad(attachment.device, 9),
19
19
  quoted(name)
20
20
  ].join(" ")
@@ -10,9 +10,9 @@ module Swa
10
10
 
11
11
  def summary
12
12
  [
13
- pad(vpc.vpc_id, 12),
13
+ field(vpc, :vpc_id),
14
14
  pad(default_marker, 1),
15
- pad(vpc.cidr_block, 18),
15
+ field(vpc, :cidr_block),
16
16
  quoted(name)
17
17
  ].join(" ")
18
18
  end
@@ -0,0 +1,24 @@
1
+ require "base64"
2
+ require "swa/resource"
3
+
4
+ module Swa
5
+ module S3
6
+
7
+ class Bucket < Resource
8
+
9
+ def summary
10
+ bucket.name
11
+ end
12
+
13
+ def policy
14
+ bucket.policy.policy.read
15
+ end
16
+
17
+ private
18
+
19
+ alias_method :bucket, :aws_resource
20
+
21
+ end
22
+
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module Swa
2
- VERSION = "0.4.3"
2
+ VERSION = "0.4.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Williams
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-27 00:00:00.000000000 Z
11
+ date: 2016-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -142,6 +142,7 @@ files:
142
142
  - exe/swa
143
143
  - lib/swa.rb
144
144
  - lib/swa/cli/base_command.rb
145
+ - lib/swa/cli/cloud_formation_command.rb
145
146
  - lib/swa/cli/collection_behaviour.rb
146
147
  - lib/swa/cli/data_output.rb
147
148
  - lib/swa/cli/ec2_command.rb
@@ -150,8 +151,10 @@ files:
150
151
  - lib/swa/cli/item_behaviour.rb
151
152
  - lib/swa/cli/kms_command.rb
152
153
  - lib/swa/cli/main_command.rb
154
+ - lib/swa/cli/s3_command.rb
153
155
  - lib/swa/cli/selector.rb
154
156
  - lib/swa/cli/tag_filter_options.rb
157
+ - lib/swa/cloud_formation/stack.rb
155
158
  - lib/swa/data_presentation.rb
156
159
  - lib/swa/ec2/image.rb
157
160
  - lib/swa/ec2/instance.rb
@@ -170,6 +173,7 @@ files:
170
173
  - lib/swa/kms/key.rb
171
174
  - lib/swa/record.rb
172
175
  - lib/swa/resource.rb
176
+ - lib/swa/s3/bucket.rb
173
177
  - lib/swa/version.rb
174
178
  - swa.gemspec
175
179
  homepage: https://github.com/mdub/swa