shelter 0.0.4 → 0.0.5

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: a4af3e0a261fda7eac0a113a58b69e2584709775
4
- data.tar.gz: 231b3b5e68efab28aced80863dde26ce4325f8ed
3
+ metadata.gz: 0e6809cf1cc3418ab086795b255461754ce0be7a
4
+ data.tar.gz: 40bd1fd16a6f62e754a840f0941a7acfe8d653f1
5
5
  SHA512:
6
- metadata.gz: 3b202c423bd81af7ea1a143d7ee790b3c615809ff1b1a159f28a2bf1cacc9e319ac7da0a404952e7d87934607ccbad5bae80866594a6c9c762b556dfd58dc281
7
- data.tar.gz: d680464d08151bb0e0c8c6d2f65d45cdf5b438a6925b5cce6971212712557f8ded5d6e63ff63980b92c521f8958f4a9a22d43afe670f91be627a1e724447ba2b
6
+ metadata.gz: f1637a566b08c10a54ff2253af02e047decdfa67a4c0a3582c4c91b34b57aa70f6de04357b32e0e5e90d884e9f39d5f1f0a3c6a7d4a81d8b2267f2bbf5581cb4
7
+ data.tar.gz: 27ec4c6ed3bc358586bd60ad66c5c00d9a7380024aa1277dafb2beb00ae4a819f3e92b9bc79ab7574aea144725130a73f88057d4302fa0862f0ff0a1000a097a
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
+ [![Gem Version](https://badge.fury.io/rb/shelter.svg)](https://badge.fury.io/rb/shelter)
2
+ [![Build Status](https://travis-ci.org/Yitsushi/shelter.svg?branch=master)](https://travis-ci.org/Yitsushi/shelter)
3
+
1
4
  # Configuration
2
5
 
3
6
  Create `Shelterfile.rb`:
4
7
 
5
- ```
8
+ ```ruby
6
9
  Shelter::CLI::App.config do |c|
7
10
  c.ansible_directory = 'ansible'
8
11
  c.stack_directory = 'stack'
@@ -16,7 +19,7 @@ end
16
19
 
17
20
  Create a ruby file under your inventory directory:
18
21
 
19
- ```
22
+ ```ruby
20
23
  # inventory/my_inventory.rb
21
24
  module Inventory
22
25
  class MyInventory
@@ -33,7 +36,7 @@ end
33
36
  Create a directory under your `stack` directory (eg: `random`)
34
37
  and create your template there. `cli.rb` will be loaded.
35
38
 
36
- ```
39
+ ```ruby
37
40
  # stack/random_stack/cli.rb:
38
41
  module Stack
39
42
  class RandomStack < Shelter::CLI::Stack::CloudFormation
@@ -55,7 +58,7 @@ Create a directory under your `plugin` directory and place your code there.
55
58
 
56
59
  ### Example #1: extra command
57
60
 
58
- ```
61
+ ```ruby
59
62
  # plugin/check/main.rb
60
63
  require 'thor'
61
64
 
@@ -73,7 +76,7 @@ Shelter::CLI::App.register(Plugin::Check, 'check', 'check [COMMAND]', 'check plu
73
76
 
74
77
  ### Example #2: extra command under a specific namespace
75
78
 
76
- ```
79
+ ```ruby
77
80
  # plugin/ansible_scanner/main.rb
78
81
  require 'thor'
79
82
 
@@ -26,22 +26,25 @@ module Shelter
26
26
  command
27
27
  end
28
28
 
29
- def optional_params(tags: [], skip: [], limit: nil)
29
+ def optional_params(opts)
30
30
  command = []
31
- command << "--tags '#{tags.join(',')}'" unless tags.empty?
32
- command << "--skip-tags '#{skip.join(',')}'" unless skip.empty?
33
- command << "--limit '#{limit}'" unless limit.nil?
31
+ command << "--tags '#{opts[:tags].join(',')}'" unless opts[:tags].empty?
32
+ command << "--skip-tags '#{opts[:skip].join(',')}'" unless
33
+ opts[:skip].empty?
34
+ command << "--limit '#{opts[:limit]}'" unless opts[:limit].nil?
34
35
  command
35
36
  end
36
37
 
37
- def ansible_execute(
38
- playbook,
39
- server_user: nil, inventory: nil,
40
- tags: [], skip: [], limit: nil
41
- )
42
- command = [command_bin, inventory_file(inventory), vault_password_file]
43
- command += new_server_params(server_user)
44
- command += optional_params(tags: tags, skip: skip, limit: limit)
38
+ # server_user: nil, inventory: nil,
39
+ # tags: [], skip: [], limit: nil
40
+ def ansible_execute(playbook, options = {})
41
+ params = {
42
+ inventory: nil, server_user: nil, tags: [], skip: [], limit: nil
43
+ }.merge(options)
44
+ command = [command_bin, inventory_file(params[:inventory]),
45
+ vault_password_file]
46
+ command += new_server_params(params[:server_user])
47
+ command += optional_params(params)
45
48
  command << "#{App.config.ansible_directory}/#{playbook}.yaml"
46
49
 
47
50
  full_command = command.join(' ')
@@ -10,24 +10,15 @@ module Shelter
10
10
  class CloudFormation < Thor
11
11
  desc 'status', 'Stack status'
12
12
  def status
13
- target_stack = cf_client.describe_stacks(
13
+ stack = cf_client.describe_stacks(
14
14
  stack_name: get_attr(:stack_name)
15
15
  ).stacks.first
16
16
 
17
- puts "#{target_stack.stack_name} exists..."
18
- puts "Created: #{target_stack.creation_time}"
17
+ puts "#{stack.stack_name} exists | #{stack.creation_time}"
19
18
 
20
- resources = cf_client.describe_stack_resources(
21
- stack_name: target_stack.stack_name
22
- )
23
- resources.stack_resources.each do |r|
24
- puts "Stack Name: #{r.stack_name}"
25
- puts "Resource ID: #{r.physical_resource_id}"
26
- puts "Resource Type: #{r.resource_type}"
27
- puts "Resource Status: #{r.resource_status}"
28
- end
29
- rescue Exception => e
30
- raise Thor::Error, e.message
19
+ cf_client.describe_stack_resources(
20
+ stack_name: stack.stack_name
21
+ ).stack_resources.each { |r| display_stack_resource(r) }
31
22
  end
32
23
 
33
24
  desc 'create', 'Create stack'
@@ -36,24 +27,12 @@ module Shelter
36
27
  stack_name: get_attr(:stack_name),
37
28
  template_body: File.open(get_attr(:template_file)).read,
38
29
  capabilities: ['CAPABILITY_IAM'],
39
- tags: [
40
- { key: 'client', value: get_attr(:meta)[:client] },
41
- { key: 'type', value: get_attr(:meta)[:type] },
42
- { key: 'application', value: get_attr(:meta)[:application] }
43
- ]
30
+ tags: stack_meta
44
31
  )
45
- i = 0
46
32
  cf_client.wait_until(
47
33
  :stack_create_complete,
48
34
  stack_name: get_attr(:stack_name)
49
- ) do |w|
50
- w.before_attempt do
51
- i = (i + 1) % SPINNER.size
52
- print "\r#{SPINNER[i]}"
53
- end
54
- end
55
- rescue Exception => e
56
- raise Thor::Error, e.message
35
+ )
57
36
  end
58
37
 
59
38
  desc 'update', 'Update stack'
@@ -63,32 +42,29 @@ module Shelter
63
42
  template_body: File.open(get_attr(:template_file)).read,
64
43
  capabilities: ['CAPABILITY_IAM']
65
44
  )
66
- i = 0
67
45
  cf_client.wait_until(
68
46
  :stack_update_complete,
69
47
  stack_name: get_attr(:stack_name)
70
- ) do |w|
71
- w.before_attempt do
72
- i = (i + 1) % SPINNER.size
73
- print "\r#{SPINNER[i]}"
74
- end
75
- end
76
- rescue Exception => e
77
- raise Thor::Error, e.message
48
+ )
78
49
  end
79
50
 
51
+ # Attribute helpers
80
52
  no_commands do
81
53
  class << self
54
+ attr_accessor :_attr
82
55
  def set_attr(name, value)
83
- @@_attr ||= {}
84
- @@_attr[name] = value
56
+ self._attr ||= {}
57
+ self._attr[name] = value
85
58
  end
86
59
  end
87
60
 
88
61
  def get_attr(name)
89
- @@_attr[name] if @@_attr.key? name
62
+ self.class._attr[name] if self.class._attr.key? name
90
63
  end
64
+ end
91
65
 
66
+ # AWS helpers
67
+ no_commands do
92
68
  def cf_client
93
69
  @cf_client ||= Aws::CloudFormation::Client.new(
94
70
  credentials: Aws::Credentials.new(
@@ -98,20 +74,19 @@ module Shelter
98
74
  )
99
75
  end
100
76
 
101
- def public_ip
102
- target_stack = cf_client.describe_stacks(
103
- stack_name: get_attr(:stack_name)
104
- ).stacks.first
105
-
106
- resources = cf_client.describe_stack_resources(
107
- stack_name: target_stack.stack_name
108
- )
109
-
110
- eip = resources.stack_resources.select do |r|
111
- r.resource_type == 'AWS::EC2::EIP'
112
- end.first
77
+ def display_stack_resource(r)
78
+ puts "Stack Name: #{r.stack_name}"
79
+ puts "Resource ID: #{r.physical_resource_id}"
80
+ puts "Resource Type: #{r.resource_type}"
81
+ puts "Resource Status: #{r.resource_status}"
82
+ end
113
83
 
114
- eip.physical_resource_id
84
+ def stack_meta
85
+ [
86
+ { key: 'client', value: get_attr(:meta)[:client] },
87
+ { key: 'type', value: get_attr(:meta)[:type] },
88
+ { key: 'application', value: get_attr(:meta)[:application] }
89
+ ]
115
90
  end
116
91
  end
117
92
  end
data/lib/shelter.rb CHANGED
@@ -17,7 +17,9 @@ class String
17
17
  else
18
18
  string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase }
19
19
  end
20
- string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" }.gsub('/', '::')
20
+ string.gsub(%r{(?:_|(/))([a-z\d]*)}) do
21
+ "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}"
22
+ end.gsub('/', '::')
21
23
  end
22
24
  end
23
25
 
data/lib/version.rb CHANGED
@@ -3,5 +3,5 @@
3
3
  module Shelter
4
4
  # Current version to publish
5
5
  # Gemspec also uses this constant
6
- VERSION = '0.0.4'
6
+ VERSION = '0.0.5'
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shelter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Balazs Nadasdi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-16 00:00:00.000000000 Z
11
+ date: 2017-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk