upstart-exporter 2.1.3 → 2.1.4

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: dee17e8ba6b4e4ab976d7ae3ecc16f171829c914
4
- data.tar.gz: 732bf68bdcaded54a5daa625f93ebb1af8fdc7cf
3
+ metadata.gz: 4fce4ef046663f8e1e24c0d055b8c6f44f28fa88
4
+ data.tar.gz: aae98fdaf485adaaa86bacd3ced81e96744860f9
5
5
  SHA512:
6
- metadata.gz: f13d22de2f4d5e595be058ffefc448bd30514813114676c60e3ff44277432014d969d0f4065b36860e0460270b4fe796e325bbf418edd6795197cdfb83753d54
7
- data.tar.gz: 708f2bab35e591f91697bd8512ab76a54c3cf9b8ccc878f81b68b6e4f15c81574cf756d345c9bcb655bb1481fd423ac3c0a45349c45141bf20dff976731a139c
6
+ metadata.gz: fca66cae4aaa262c3585a85d19bb3e852198758695b36c883061caa1b89386fd2644e02ffbb986596f4877c367c65cf2c3e37415ddefded6500888877560941c
7
+ data.tar.gz: 0c97df4a412222f422d212c27e75f568ea1894c0d95af395d3b49a7725a4c53575fe0a6b70efee9cb5a5e278d478a8a0d585779b42f7eab04b30579a5cbeb3c0
data/README.md CHANGED
@@ -35,7 +35,7 @@ which is a simple YAML file of the following format:
35
35
  upstart_dir: /var/upstart_dir # Directory where upstart scripts should be placed
36
36
  prefix: 'myupstartjobs-' # Prefix added to app's log folders and upstart scripts
37
37
  respawn: # Controls how often job can fail and be restarted, set to false to prohibit restart after failure
38
- limit: 10 # Number of allowed restarts in given interval
38
+ count: 10 # Number of allowed restarts in given interval
39
39
  interval: 10 # Interval in seconds
40
40
 
41
41
  The config is not installed by default. If this config is absent, the default values are the following:
@@ -45,7 +45,7 @@ The config is not installed by default. If this config is absent, the default va
45
45
  run_user: service
46
46
  prefix: 'fb-'
47
47
  respawn:
48
- limit: 5
48
+ count: 5
49
49
  interval: 10
50
50
 
51
51
  To give a certain user (i.e. `deployuser`) the ability to use this script, you can place the following lines into `sudoers` file:
@@ -21,7 +21,7 @@ module Upstart
21
21
  command_line_options = Options::CommandLine.new(command_line_args)
22
22
 
23
23
  @options = global_options.merge(command_line_options)
24
- Upstart::Exporter::Options::Validator.new(@options).validate!
24
+ @options = Upstart::Exporter::Options::Validator.new(@options).call
25
25
 
26
26
  ensure_dirs
27
27
  end
@@ -100,6 +100,7 @@ module Upstart
100
100
  :cmd_name => cmd_name,
101
101
  :helper_cmd_conf => helper_cmd_conf(cmd_name)
102
102
  )
103
+
103
104
  File.open(upstart_cmd_conf(cmd_name), 'w') do |f|
104
105
  f.write(cmd_upstart_conf_content)
105
106
  end
@@ -29,11 +29,11 @@ class Upstart::Exporter
29
29
  private
30
30
 
31
31
  def export_cmd(command, cmd_options)
32
- cmd_options = {
32
+ cmd_options = cmd_options.merge(
33
33
  :working_directory => working_directory(cmd_options),
34
34
  :log => log(cmd_options),
35
35
  :kill_timeout => kill_timeout(cmd_options)
36
- }.merge(cmd_options)
36
+ )
37
37
 
38
38
  script = cmd_options[:command]
39
39
  script = add_env_command(script, cmd_options)
@@ -9,44 +9,65 @@ module Upstart::Exporter::Options
9
9
  @options = options
10
10
  end
11
11
 
12
- def validate!
13
- validate_path(options[:helper_dir])
14
- validate_path(options[:upstart_dir])
15
-
16
- reject_special_symbols(options[:run_user])
17
- reject_special_symbols(options[:run_group])
18
- reject_special_symbols(options[:prefix])
19
-
20
- validate_runlevel(options[:start_on_runlevel])
21
- validate_runlevel(options[:stop_on_runlevel])
22
-
23
- validate_digits(options[:kill_timeout])
24
-
25
- validate_respawn(options[:respawn])
26
-
27
- if options[:procfile_commands][:version] == 2
28
- validate_procfile_v2(options[:procfile_commands])
29
- end
12
+ def call
13
+ clean_params = {
14
+ :app_name => reject_special_symbols(options[:app_name]),
15
+ :helper_dir => validate_path(options[:helper_dir]),
16
+ :upstart_dir => validate_path(options[:upstart_dir]),
17
+ :run_user => reject_special_symbols(options[:run_user]),
18
+ :run_group => reject_special_symbols(options[:run_group]),
19
+ :prefix => reject_special_symbols(options[:prefix]),
20
+ :start_on_runlevel => validate_runlevel(options[:start_on_runlevel]),
21
+ :stop_on_runlevel => validate_runlevel(options[:stop_on_runlevel]),
22
+ :kill_timeout => validate_digits(options[:kill_timeout]),
23
+ :respawn => validate_respawn(options[:respawn]),
24
+ :working_directory => validate_path(options[:working_directory]),
25
+ :procfile_commands => validate_procfile(options[:procfile_commands])
26
+ }
27
+
28
+ clean_params
30
29
  end
31
30
 
32
31
  private
33
32
 
33
+ def validate_procfile(config)
34
+ if config[:version] == 2
35
+ validate_procfile_v2(config)
36
+ else
37
+ config
38
+ end
39
+ end
40
+
34
41
  def validate_procfile_v2(config)
35
- validate_command_params(config)
36
- config[:commands].values.each {|cmd| validate_command_params(cmd)}
42
+ clean_params = validate_command_params(config)
43
+ clean_params[:version] = config[:version]
44
+
45
+ if config[:commands]
46
+ clean_params[:commands] = Hash[config[:commands].map {|name, cmd| [name, validate_command_params(cmd)]}]
47
+ end
48
+
49
+ clean_params
37
50
  end
38
51
 
39
52
  def validate_command_params(cmd)
40
- validate_runlevel(cmd[:start_on_runlevel])
41
- validate_runlevel(cmd[:stop_on_runlevel])
42
- validate_path(cmd[:working_directory])
43
- validate_respawn(cmd[:respawn])
53
+ {
54
+ :command => cmd[:command],
55
+ :start_on_runlevel => validate_runlevel(cmd[:start_on_runlevel]),
56
+ :stop_on_runlevel => validate_runlevel(cmd[:stop_on_runlevel]),
57
+ :working_directory => validate_path(cmd[:working_directory]),
58
+ :respawn => validate_respawn(cmd[:respawn]),
59
+ :count => validate_digits(cmd[:count]),
60
+ :kill_timeout => validate_digits(cmd[:kill_timeout])
61
+ }
44
62
  end
45
63
 
46
64
  def validate_respawn(options)
47
- return unless options
48
- validate_digits(options[:kill_timeout])
49
- validate_digits(options[:interval])
65
+ return options unless options.is_a?(Hash)
66
+
67
+ {
68
+ :count => validate_digits(options[:count]),
69
+ :interval => validate_digits(options[:interval])
70
+ }
50
71
  end
51
72
 
52
73
  def validate_path(val)
@@ -66,12 +87,14 @@ module Upstart::Exporter::Options
66
87
  end
67
88
 
68
89
  def validate(val, regexp)
69
- val = val.to_s
70
- return if val == ""
90
+ str_val = val.to_s
91
+ return if str_val == ""
71
92
 
72
- unless val =~ regexp
93
+ unless str_val =~ regexp
73
94
  error("value #{val} is insecure and can't be accepted")
74
95
  end
96
+
97
+ val
75
98
  end
76
99
 
77
100
  end
@@ -1,5 +1,5 @@
1
1
  module Upstart
2
2
  class Exporter
3
- VERSION = "2.1.3"
3
+ VERSION = "2.1.4"
4
4
  end
5
5
  end
@@ -4,24 +4,24 @@ describe Upstart::Exporter::Options::Validator do
4
4
 
5
5
  it "validates paths" do
6
6
  validator = described_class.new(:helper_dir => "/some/dir;")
7
- expect {validator.validate!}.to raise_error(Upstart::Exporter::Error)
7
+ expect {validator.call}.to raise_error(Upstart::Exporter::Error)
8
8
  end
9
9
 
10
10
  it "validates user names" do
11
11
  validator = described_class.new(:run_user => "bad_user_name!")
12
- expect {validator.validate!}.to raise_error(Upstart::Exporter::Error)
12
+ expect {validator.call}.to raise_error(Upstart::Exporter::Error)
13
13
  end
14
14
 
15
15
  it "validates runlevels" do
16
16
  validator = described_class.new(:start_on_runlevel => "[not_a_digit]")
17
- expect {validator.validate!}.to raise_error(Upstart::Exporter::Error)
17
+ expect {validator.call}.to raise_error(Upstart::Exporter::Error)
18
18
  end
19
19
 
20
20
  describe "procfile v2" do
21
21
  it "validates respawn" do
22
- options = {:procfile_commands => {:version => 2, :respawn => {:kill_timeout => "10;"}}}
22
+ options = {:procfile_commands => {:version => 2, :respawn => {:count => "10;"}}}
23
23
  validator = described_class.new(options)
24
- expect {validator.validate!}.to raise_error(Upstart::Exporter::Error)
24
+ expect {validator.call}.to raise_error(Upstart::Exporter::Error)
25
25
  end
26
26
 
27
27
  it "validates options for individual commands" do
@@ -35,7 +35,7 @@ describe Upstart::Exporter::Options::Validator do
35
35
  }
36
36
  }
37
37
  validator = described_class.new(options)
38
- expect {validator.validate!}.to raise_error(Upstart::Exporter::Error)
38
+ expect {validator.call}.to raise_error(Upstart::Exporter::Error)
39
39
  end
40
40
  end
41
41
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upstart-exporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Averyanov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-02-04 00:00:00.000000000 Z
12
+ date: 2016-02-05 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Gem for converting extended Procfile-like files to upstart scripts
15
15
  email: