serverkit 0.2.7 → 0.2.8

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: d88e5f03bf3c76a8195af458f1a596074db889a6
4
- data.tar.gz: 35387a924e18aa5a1653d83d36793eb2817a8faf
3
+ metadata.gz: 65f599078706665a41712a95fac9fceb098ab617
4
+ data.tar.gz: c83b4d7ca7377f8029300646eb11f5ea9f105a95
5
5
  SHA512:
6
- metadata.gz: 62499c66973b3de08fec3836eb0079fcffa6a5050c2fb44cd939abf615821da02fed7512a4aef64048a0d6786fefb52245a1dac0a04960a93c1a6de5ed1a072d
7
- data.tar.gz: e341d3fb9c9c1de9dafe79a3fd6c4deb96b330ddb171f95da4cd246edce08e833168648f78259c5d2d02161b0060f2aad01534947266459da054bd12ea30d970
6
+ metadata.gz: f6ab8e2a496800ee62a5fcd8676e5d82fa8cd2b96c07a03462fc535d8f489e3f1e1d1731e042bfdff1c0d1bdb231733b23bfbb2f825179c80deaeec0f0b034de
7
+ data.tar.gz: 36bfe26ca78820a08f6049237fb74793de3a711db6d03059f3b8140a0851f8d33c5f5c681881e369b1fe682158293decf62671416e1c9c4d6653f886c7265faf
data/.rubocop.yml CHANGED
@@ -1,3 +1,6 @@
1
+ Lint/HandleExceptions:
2
+ Enabled: false
3
+
1
4
  Lint/UnusedBlockArgument:
2
5
  Enabled: false
3
6
 
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.2.8
2
+ - Support SSH options injection on action class
3
+
1
4
  ## 0.2.7
2
5
  - Ignore missing Gemfile error
3
6
 
@@ -1,7 +1,6 @@
1
1
  require "bundler"
2
2
  require "etc"
3
3
  require "net/ssh"
4
- require "serverkit/errors/missing_recipe_path_argument_error"
5
4
  require "serverkit/loaders/recipe_loader"
6
5
  require "serverkit/recipe"
7
6
  require "slop"
@@ -10,9 +9,15 @@ require "specinfra"
10
9
  module Serverkit
11
10
  module Actions
12
11
  class Base
13
- # @param [Array] argv Command-line arguments given to serverkit executable
14
- def initialize(argv)
15
- @argv = argv
12
+ # @param [String, nil] hosts
13
+ # @param [String] recipe_path
14
+ # @param [Hash, nil] ssh_options For override default ssh options
15
+ # @param [Stirng, nil] variables_path
16
+ def initialize(hosts: nil, recipe_path: nil, ssh_options: nil, variables_path: nil)
17
+ @hosts = hosts
18
+ @recipe_path = recipe_path
19
+ @ssh_options = ssh_options
20
+ @variables_path = variables_path
16
21
  end
17
22
 
18
23
  def call
@@ -28,14 +33,14 @@ module Serverkit
28
33
 
29
34
  # @return [Array<Specinfra::Backend::Base>]
30
35
  def backends
31
- if options[:hosts]
36
+ if has_hosts?
32
37
  hosts.map do |host|
33
38
  backend_class.new(
34
39
  disable_sudo: true,
35
40
  host: host,
36
41
  ssh_options: {
37
42
  user: ssh_user_for(host),
38
- },
43
+ }.merge(ssh_options),
39
44
  )
40
45
  end
41
46
  else
@@ -44,7 +49,7 @@ module Serverkit
44
49
  end
45
50
 
46
51
  def backend_class
47
- if options[:hosts]
52
+ if has_hosts?
48
53
  Specinfra::Backend::Ssh
49
54
  else
50
55
  Specinfra::Backend::Exec
@@ -56,16 +61,14 @@ module Serverkit
56
61
  rescue Bundler::GemfileNotFound
57
62
  end
58
63
 
59
- def hosts
60
- options[:hosts].split(",")
64
+ def has_hosts?
65
+ !@hosts.nil?
61
66
  end
62
67
 
63
- # @return [Slop] Command-line options
64
- def options
65
- @options ||= Slop.parse!(@argv, help: true) do
66
- banner "Usage: serverkit ACTION [options]"
67
- on "--hosts=", "Pass hostname to execute command over SSH"
68
- on "--variables=", "Path to variables file for ERB recipe"
68
+ # @return [Array<String>, nil]
69
+ def hosts
70
+ if has_hosts?
71
+ @hosts.split(",")
69
72
  end
70
73
  end
71
74
 
@@ -74,14 +77,14 @@ module Serverkit
74
77
  abort_with_errors unless recipe.valid?
75
78
  end
76
79
 
77
- # @return [Serverkit::Recipe]
78
- def recipe
79
- @recipe ||= Loaders::RecipeLoader.new(recipe_path, variables_path: options[:variables]).load
80
+ # @return [Hash]
81
+ def ssh_options
82
+ @ssh_options || {}
80
83
  end
81
84
 
82
- # @return [String, nil]
83
- def recipe_path
84
- @argv[1] or raise Errors::MissingRecipePathArgumentError
85
+ # @return [Serverkit::Recipe]
86
+ def recipe
87
+ @recipe ||= Loaders::RecipeLoader.new(@recipe_path, variables_path: @variables_path).load
85
88
  end
86
89
 
87
90
  # @param [String] host
@@ -7,6 +7,8 @@ require "serverkit/errors/missing_recipe_path_argument_error"
7
7
  require "serverkit/errors/unknown_action_name_error"
8
8
 
9
9
  module Serverkit
10
+ # Command clsas takes care of command line interface.
11
+ # It builds and runs an Action object from given command line arguements.
10
12
  class Command
11
13
  # @param [Array<String>] argv
12
14
  def initialize(argv)
@@ -34,26 +36,62 @@ module Serverkit
34
36
 
35
37
  private
36
38
 
39
+ # @note #inspect is reserved ;(
40
+ def _inspect
41
+ Actions::Inspect.new(action_options).call
42
+ end
43
+
37
44
  # @return [String, nil]
38
45
  def action_name
39
46
  @argv.first
40
47
  end
41
48
 
49
+ # @return [Hash<Symbol => String>]
50
+ def action_options
51
+ {
52
+ hosts: hosts,
53
+ recipe_path: recipe_path,
54
+ variables_path: variables_path,
55
+ }.reject do |key, value|
56
+ value.nil?
57
+ end
58
+ end
59
+
42
60
  def apply
43
- Actions::Apply.new(@argv).call
61
+ Actions::Apply.new(action_options).call
44
62
  end
45
63
 
46
64
  def check
47
- Actions::Check.new(@argv).call
65
+ Actions::Check.new(action_options).call
48
66
  end
49
67
 
50
- # @note #inspect is reserved ;(
51
- def _inspect
52
- Actions::Inspect.new(@argv).call
68
+ # @note This options are commonly used from all actions for now, however,
69
+ # someday a new action that requires options might appear.
70
+ # @return [Slop]
71
+ def command_line_options
72
+ @command_line_options ||= Slop.parse!(@argv, help: true) do
73
+ banner "Usage: serverkit ACTION [options]"
74
+ on "--hosts=", "Pass hostname to execute command over SSH"
75
+ on "--variables=", "Path to variables file for ERB recipe"
76
+ end
77
+ end
78
+
79
+ # @return [String, nil]
80
+ def hosts
81
+ command_line_options[:hosts]
82
+ end
83
+
84
+ # @return [String]
85
+ def recipe_path
86
+ @argv[1] or raise Errors::MissingRecipePathArgumentError
53
87
  end
54
88
 
55
89
  def validate
56
- Actions::Validate.new(@argv).call
90
+ Actions::Validate.new(action_options).call
91
+ end
92
+
93
+ def variables_path
94
+ command_line_options[:variables]
57
95
  end
58
96
  end
59
97
  end
@@ -1,3 +1,3 @@
1
1
  module Serverkit
2
- VERSION = "0.2.7"
2
+ VERSION = "0.2.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serverkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-10 00:00:00.000000000 Z
11
+ date: 2015-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel