swa 0.4.0 → 0.4.1

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: 857543d35465a009440daac9909f96f0e4c67f06
4
- data.tar.gz: b0d79ccc8a742c1e31813646b1949d565b74d84d
3
+ metadata.gz: 4dc9fcd21e4fbd399ce0a2437fe6a054d4c41495
4
+ data.tar.gz: 00ac4e5e34e55def411589f177db392db456e22c
5
5
  SHA512:
6
- metadata.gz: 9a3839446038c98f7de200cfc06a390ce6c556c2d5a3aa59d2a96b53a736172a48cb7912bb1a231a08d314944564f4c78e4a8adf86493fba509c9cfa667b5752
7
- data.tar.gz: 3dec6acb79cda9077a2e02e0736b360c5de968fe0edd761eba2dbe9e4d6235b3fb3a85a0024daeb2810c3214c8e55a79ea6424cb6c8f775ecf66c7a1ce360c21
6
+ metadata.gz: dba4cb585a4e6761c1dc9cdfb34ed8b229d0cef5b0eb693285efde74cf92758f06d95febe86ef836a5584a598c85e3be35e561ce9004f34f1d45a86809c80649
7
+ data.tar.gz: bf783e3b8ec3aa1c66a5a4722d2dede644e2d4292b27eefb5de2d39cad26ce17094b0cf094f1934e857634ab631e163a05d243d499fe4e58d1bb3c5a59ff1011
data/README.md CHANGED
@@ -50,6 +50,17 @@ But you can ask for **all** the data, if you wish:
50
50
 
51
51
  Specify `-J` if you like JSON better than YAML.
52
52
 
53
+ You can specify a [JMESPath](http://jmespath.org) to extract a subset of the data:
54
+
55
+ $ swa ec2 instances data '[].{Id:InstanceId,Profile:IamInstanceProfile.Id}'
56
+ ---
57
+ - Id: i-7f5495ae
58
+ Profile: AIPAIDOQKT66MFXRO5BPS
59
+ - Id: i-9c539e4d
60
+ Profile: AIPAIRT5GOEJ2ZMVPGGD6
61
+ - Id: i-fbeda3be
62
+ Profile: AIPAIZXZFLTUW6L456LFU
63
+
53
64
  ## Inspecting things
54
65
 
55
66
  Each "collection" operation has a corresponding "item" operation, e.g.
@@ -17,40 +17,6 @@ module Swa
17
17
 
18
18
  class Ec2Command < BaseCommand
19
19
 
20
- subcommand ["key-pair", "kp"], "Show key-pair" do
21
-
22
- parameter "NAME", "key-pair name"
23
-
24
- include ItemBehaviour
25
-
26
- private
27
-
28
- def key_pair
29
- Swa::EC2::KeyPair.new(ec2.key_pair(name))
30
- end
31
-
32
- alias_method :item, :key_pair
33
-
34
- end
35
-
36
- subcommand ["key-pairs", "kps"], "List key-pairs" do
37
-
38
- self.description = <<-EOF
39
- List key-pairs.
40
- EOF
41
-
42
- include CollectionBehaviour
43
-
44
- private
45
-
46
- def key_pairs
47
- query_for(:key_pairs, Swa::EC2::KeyPair)
48
- end
49
-
50
- alias_method :collection, :key_pairs
51
-
52
- end
53
-
54
20
  subcommand ["image", "ami"], "Show image" do
55
21
 
56
22
  parameter "IMAGE-ID", "image id"
@@ -219,6 +185,40 @@ module Swa
219
185
 
220
186
  end
221
187
 
188
+ subcommand ["key-pair", "kp"], "Show key-pair" do
189
+
190
+ parameter "NAME", "key-pair name"
191
+
192
+ include ItemBehaviour
193
+
194
+ private
195
+
196
+ def key_pair
197
+ Swa::EC2::KeyPair.new(ec2.key_pair(name))
198
+ end
199
+
200
+ alias_method :item, :key_pair
201
+
202
+ end
203
+
204
+ subcommand ["key-pairs", "kps"], "List key-pairs" do
205
+
206
+ self.description = <<-EOF
207
+ List key-pairs.
208
+ EOF
209
+
210
+ include CollectionBehaviour
211
+
212
+ private
213
+
214
+ def key_pairs
215
+ query_for(:key_pairs, Swa::EC2::KeyPair)
216
+ end
217
+
218
+ alias_method :collection, :key_pairs
219
+
220
+ end
221
+
222
222
  subcommand ["security-group", "sg"], "Show security-group" do
223
223
 
224
224
  parameter "GROUP-ID", "security-group id"
@@ -0,0 +1,157 @@
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/iam/group"
6
+ require "swa/iam/policy"
7
+ require "swa/iam/role"
8
+ require "swa/iam/user"
9
+
10
+ module Swa
11
+ module CLI
12
+
13
+ class IamCommand < BaseCommand
14
+
15
+ subcommand ["group"], "Show group" do
16
+
17
+ parameter "NAME", "group name/ARN"
18
+
19
+ include ItemBehaviour
20
+
21
+ private
22
+
23
+ def item
24
+ Swa::IAM::Group.new(iam.group(File.basename(name)))
25
+ end
26
+
27
+ end
28
+
29
+ subcommand ["groups"], "Show groups" do
30
+
31
+ self.description = <<-EOF
32
+ List groups.
33
+ EOF
34
+
35
+ include CollectionBehaviour
36
+
37
+ private
38
+
39
+ def collection
40
+ query_for(:groups, Swa::IAM::Group)
41
+ end
42
+
43
+ end
44
+
45
+ subcommand ["policy"], "Show policy" do
46
+
47
+ parameter "ARN", "policy ARN"
48
+
49
+ include ItemBehaviour
50
+
51
+ private
52
+
53
+ def item
54
+ Swa::IAM::Policy.new(iam.policy(arn))
55
+ end
56
+
57
+ subcommand "document", "print current policy document" do
58
+
59
+ def execute
60
+ puts item.document
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+
67
+ subcommand ["policies"], "Show policies" do
68
+
69
+ self.description = <<-EOF
70
+ List policies.
71
+ EOF
72
+
73
+ include CollectionBehaviour
74
+
75
+ private
76
+
77
+ def collection
78
+ query_for(:policies, Swa::IAM::Policy)
79
+ end
80
+
81
+ end
82
+
83
+ subcommand ["role"], "Show role" do
84
+
85
+ parameter "NAME", "role name/ARN"
86
+
87
+ include ItemBehaviour
88
+
89
+ private
90
+
91
+ def item
92
+ Swa::IAM::Role.new(iam.role(File.basename(name)))
93
+ end
94
+
95
+ end
96
+
97
+ subcommand ["roles"], "Show roles" do
98
+
99
+ self.description = <<-EOF
100
+ List roles.
101
+ EOF
102
+
103
+ include CollectionBehaviour
104
+
105
+ private
106
+
107
+ def collection
108
+ query_for(:roles, Swa::IAM::Role)
109
+ end
110
+
111
+ end
112
+
113
+ subcommand ["user"], "Show user" do
114
+
115
+ parameter "NAME", "user name/ARN"
116
+
117
+ include ItemBehaviour
118
+
119
+ private
120
+
121
+ def item
122
+ Swa::IAM::User.new(iam.user(File.basename(name)))
123
+ end
124
+
125
+ end
126
+
127
+ subcommand ["users"], "Show users" do
128
+
129
+ self.description = <<-EOF
130
+ List users.
131
+ EOF
132
+
133
+ include CollectionBehaviour
134
+
135
+ private
136
+
137
+ def collection
138
+ query_for(:users, Swa::IAM::User)
139
+ end
140
+
141
+ end
142
+
143
+ protected
144
+
145
+ def iam
146
+ ::Aws::IAM::Resource.new(aws_config)
147
+ end
148
+
149
+ def query_for(query_method, resource_model)
150
+ aws_resources = iam.public_send(query_method)
151
+ wrapped_resources = resource_model.list(aws_resources)
152
+ end
153
+
154
+ end
155
+
156
+ end
157
+ end
@@ -1,5 +1,6 @@
1
1
  require "swa/cli/base_command"
2
2
  require "swa/cli/ec2_command"
3
+ require "swa/cli/iam_command"
3
4
 
4
5
  module Swa
5
6
  module CLI
@@ -7,6 +8,7 @@ module Swa
7
8
  class MainCommand < BaseCommand
8
9
 
9
10
  subcommand "ec2", "EC2 stuff", Ec2Command
11
+ subcommand "iam", "IAM stuff", IamCommand
10
12
 
11
13
  end
12
14
 
@@ -0,0 +1,19 @@
1
+ require "swa/resource"
2
+
3
+ module Swa
4
+ module IAM
5
+
6
+ class Group < Resource
7
+
8
+ def summary
9
+ group.arn
10
+ end
11
+
12
+ private
13
+
14
+ alias_method :group, :aws_resource
15
+
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ require "cgi"
2
+ require "swa/resource"
3
+
4
+ module Swa
5
+ module IAM
6
+
7
+ class Policy < Resource
8
+
9
+ def summary
10
+ [
11
+ pad(policy.arn, 60),
12
+ quoted(policy.description)
13
+ ].join(" ")
14
+ end
15
+
16
+ def document
17
+ CGI.unescape(policy.default_version.document)
18
+ end
19
+
20
+ private
21
+
22
+ alias_method :policy, :aws_resource
23
+
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,19 @@
1
+ require "swa/resource"
2
+
3
+ module Swa
4
+ module IAM
5
+
6
+ class Role < Resource
7
+
8
+ def summary
9
+ role.arn
10
+ end
11
+
12
+ private
13
+
14
+ alias_method :role, :aws_resource
15
+
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "swa/resource"
2
+
3
+ module Swa
4
+ module IAM
5
+
6
+ class User < Resource
7
+
8
+ def summary
9
+ user.arn
10
+ end
11
+
12
+ private
13
+
14
+ alias_method :user, :aws_resource
15
+
16
+ end
17
+
18
+ end
19
+ end
data/lib/swa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Swa
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
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.0
4
+ version: 0.4.1
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-07-11 00:00:00.000000000 Z
11
+ date: 2016-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -146,6 +146,7 @@ files:
146
146
  - lib/swa/cli/data_output.rb
147
147
  - lib/swa/cli/ec2_command.rb
148
148
  - lib/swa/cli/filter_options.rb
149
+ - lib/swa/cli/iam_command.rb
149
150
  - lib/swa/cli/item_behaviour.rb
150
151
  - lib/swa/cli/main_command.rb
151
152
  - lib/swa/cli/selector.rb
@@ -160,6 +161,10 @@ files:
160
161
  - lib/swa/ec2/tagged_resource.rb
161
162
  - lib/swa/ec2/volume.rb
162
163
  - lib/swa/ec2/vpc.rb
164
+ - lib/swa/iam/group.rb
165
+ - lib/swa/iam/policy.rb
166
+ - lib/swa/iam/role.rb
167
+ - lib/swa/iam/user.rb
163
168
  - lib/swa/resource.rb
164
169
  - lib/swa/version.rb
165
170
  - swa.gemspec