itamae-mitsurin 0.50 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +5 -5
  2. data/lib/itamae-mitsurin/cli.rb +0 -2
  3. data/lib/itamae-mitsurin/logger.rb +74 -20
  4. data/lib/itamae-mitsurin/mitsurin/base.rb +109 -0
  5. data/lib/itamae-mitsurin/mitsurin/base_task.rb +147 -0
  6. data/lib/itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/recipes/default.rb +0 -11
  7. data/lib/itamae-mitsurin/mitsurin/itamae_task.rb +44 -130
  8. data/lib/itamae-mitsurin/mitsurin/itamae_with_target_task.rb +64 -157
  9. data/lib/itamae-mitsurin/mitsurin/local_task.rb +57 -131
  10. data/lib/itamae-mitsurin/mitsurin/serverspec_task.rb +56 -81
  11. data/lib/itamae-mitsurin/mitsurin/serverspec_with_target_task.rb +80 -143
  12. data/lib/itamae-mitsurin/node.rb +0 -1
  13. data/lib/itamae-mitsurin/notification.rb +0 -1
  14. data/lib/itamae-mitsurin/recipe.rb +2 -5
  15. data/lib/itamae-mitsurin/resource.rb +1 -1
  16. data/lib/itamae-mitsurin/resource/base.rb +0 -12
  17. data/lib/itamae-mitsurin/resource/http_request.rb +23 -8
  18. data/lib/itamae-mitsurin/resource/s3_file.rb +33 -0
  19. data/lib/itamae-mitsurin/runner.rb +4 -5
  20. data/lib/itamae-mitsurin/version.txt +1 -1
  21. metadata +6 -221
  22. data/lib/itamae-mitsurin/mitsurin/itamae_with_git_task.rb +0 -159
  23. data/lib/itamae-mitsurin/mitsurin/task_base.rb +0 -100
  24. data/test/test_itamae-mitsurin.rb +0 -18
  25. data/test/test_itamae-mitsurin/ext/test_specinfra.rb +0 -39
  26. data/test/test_itamae-mitsurin/handler/test_base.rb +0 -40
  27. data/test/test_itamae-mitsurin/handler/test_debug.rb +0 -10
  28. data/test/test_itamae-mitsurin/handler/test_fluentd.rb +0 -44
  29. data/test/test_itamae-mitsurin/handler/test_json.rb +0 -22
  30. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/.rspec +0 -2
  31. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/Gemfile +0 -3
  32. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/Rakefile +0 -2
  33. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/environments/.keep +0 -0
  34. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/environments/sample.json +0 -7
  35. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/keys/.keep +0 -0
  36. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/nodes/.keep +0 -0
  37. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/nodes/sample01.json +0 -9
  38. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/roles/.keep +0 -0
  39. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/attributes/.keep +0 -0
  40. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/files/.keep +0 -0
  41. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/recipes/default.rb +0 -1
  42. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/spec/default_spec.rb +0 -1
  43. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/templates/.keep +0 -0
  44. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/spec/spec_helper.rb +0 -33
  45. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/tmp-nodes/.keep +0 -0
  46. data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/attributes/.keep +0 -0
  47. data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/files/.keep +0 -0
  48. data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/recipes/default.rb +0 -0
  49. data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/spec/.keep +0 -0
  50. data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/templates/.keep +0 -0
  51. data/test/test_itamae-mitsurin/mitsurin/creators/test_cookbook.rb +0 -24
  52. data/test/test_itamae-mitsurin/mitsurin/creators/test_project.rb +0 -24
  53. data/test/test_itamae-mitsurin/mitsurin/test_cli.rb +0 -56
  54. data/test/test_itamae-mitsurin/mitsurin/test_creators.rb +0 -19
  55. data/test/test_itamae-mitsurin/mitsurin/test_itamae_task.rb +0 -197
  56. data/test/test_itamae-mitsurin/mitsurin/test_itamae_with_git_task.rb +0 -213
  57. data/test/test_itamae-mitsurin/mitsurin/test_serverspec_task.rb +0 -123
  58. data/test/test_itamae-mitsurin/resource/test_aws_ebs_volume.rb +0 -84
  59. data/test/test_itamae-mitsurin/resource/test_base.rb +0 -374
  60. data/test/test_itamae-mitsurin/resource/test_directory.rb +0 -63
  61. data/test/test_itamae-mitsurin/resource/test_execute.rb +0 -26
  62. data/test/test_itamae-mitsurin/resource/test_file.rb +0 -176
  63. data/test/test_itamae-mitsurin/resource/test_gem_package.rb +0 -81
  64. data/test/test_itamae-mitsurin/resource/test_git.rb +0 -94
  65. data/test/test_itamae-mitsurin/resource/test_group.rb +0 -42
  66. data/test/test_itamae-mitsurin/resource/test_http_request.rb +0 -71
  67. data/test/test_itamae-mitsurin/resource/test_link.rb +0 -33
  68. data/test/test_itamae-mitsurin/resource/test_local_ruby_block.rb +0 -15
  69. data/test/test_itamae-mitsurin/resource/test_package.rb +0 -44
  70. data/test/test_itamae-mitsurin/resource/test_remote_directory.rb +0 -84
  71. data/test/test_itamae-mitsurin/resource/test_remote_file.rb +0 -54
  72. data/test/test_itamae-mitsurin/resource/test_service.rb +0 -69
  73. data/test/test_itamae-mitsurin/resource/test_template.rb +0 -53
  74. data/test/test_itamae-mitsurin/resource/test_user.rb +0 -93
  75. data/test/test_itamae-mitsurin/test_backend.rb +0 -297
  76. data/test/test_itamae-mitsurin/test_cli.rb +0 -88
  77. data/test/test_itamae-mitsurin/test_definition.rb +0 -40
  78. data/test/test_itamae-mitsurin/test_ext.rb +0 -1
  79. data/test/test_itamae-mitsurin/test_handler.rb +0 -21
  80. data/test/test_itamae-mitsurin/test_handler_proxy.rb +0 -38
  81. data/test/test_itamae-mitsurin/test_logger.rb +0 -124
  82. data/test/test_itamae-mitsurin/test_mitsurin.rb +0 -14
  83. data/test/test_itamae-mitsurin/test_node.rb +0 -74
  84. data/test/test_itamae-mitsurin/test_notification.rb +0 -46
  85. data/test/test_itamae-mitsurin/test_recipe.rb +0 -171
  86. data/test/test_itamae-mitsurin/test_recipe_children.rb +0 -86
  87. data/test/test_itamae-mitsurin/test_resource.rb +0 -73
  88. data/test/test_itamae-mitsurin/test_runner.rb +0 -124
  89. data/test/test_itamae-mitsurin/test_version.rb +0 -3
  90. data/test/test_itamae-mitsurin/version.txt +0 -1
  91. data/test_project/.rspec +0 -2
  92. data/test_project/Gemfile +0 -4
  93. data/test_project/Rakefile +0 -3
  94. data/test_project/environments/.keep +0 -0
  95. data/test_project/keys/.keep +0 -0
  96. data/test_project/nodes/.keep +0 -0
  97. data/test_project/nodes/test.json +0 -9
  98. data/test_project/roles/.keep +0 -0
  99. data/test_project/roles/test.json +0 -14
  100. data/test_project/site-cookbooks/_base/_base/attributes/.keep +0 -0
  101. data/test_project/site-cookbooks/_base/_base/files/.keep +0 -0
  102. data/test_project/site-cookbooks/_base/_base/recipes/default.rb +0 -1
  103. data/test_project/site-cookbooks/_base/_base/spec/default_spec.rb +0 -1
  104. data/test_project/site-cookbooks/_base/_base/templates/.keep +0 -0
  105. data/test_project/site-cookbooks/a_test/directory/attributes/.keep +0 -0
  106. data/test_project/site-cookbooks/a_test/directory/files/.keep +0 -0
  107. data/test_project/site-cookbooks/a_test/directory/recipes/default.rb +0 -8
  108. data/test_project/site-cookbooks/a_test/directory/spec/.keep +0 -0
  109. data/test_project/site-cookbooks/a_test/directory/spec/default_spec.rb +0 -4
  110. data/test_project/site-cookbooks/a_test/directory/templates/.keep +0 -0
  111. data/test_project/site-cookbooks/a_test/package/attributes/.keep +0 -0
  112. data/test_project/site-cookbooks/a_test/package/files/.keep +0 -0
  113. data/test_project/site-cookbooks/a_test/package/recipes/default.rb +0 -2
  114. data/test_project/site-cookbooks/a_test/package/spec/.keep +0 -0
  115. data/test_project/site-cookbooks/a_test/package/spec/default_spec.rb +0 -4
  116. data/test_project/site-cookbooks/a_test/package/templates/.keep +0 -0
  117. data/test_project/site-cookbooks/a_test/service/attributes/.keep +0 -0
  118. data/test_project/site-cookbooks/a_test/service/files/.keep +0 -0
  119. data/test_project/site-cookbooks/a_test/service/recipes/default.rb +0 -5
  120. data/test_project/site-cookbooks/a_test/service/spec/.keep +0 -0
  121. data/test_project/site-cookbooks/a_test/service/spec/default_spec.rb +0 -6
  122. data/test_project/site-cookbooks/a_test/service/templates/.keep +0 -0
  123. data/test_project/site-cookbooks/b_test/git/attributes/.keep +0 -0
  124. data/test_project/site-cookbooks/b_test/git/files/.keep +0 -0
  125. data/test_project/site-cookbooks/b_test/git/recipes/default.rb +0 -5
  126. data/test_project/site-cookbooks/b_test/git/spec/.keep +0 -0
  127. data/test_project/site-cookbooks/b_test/git/spec/default_spec.rb +0 -5
  128. data/test_project/site-cookbooks/b_test/git/templates/.keep +0 -0
  129. data/test_project/site-cookbooks/b_test/link/attributes/.keep +0 -0
  130. data/test_project/site-cookbooks/b_test/link/files/.keep +0 -0
  131. data/test_project/site-cookbooks/b_test/link/recipes/default.rb +0 -5
  132. data/test_project/site-cookbooks/b_test/link/spec/.keep +0 -0
  133. data/test_project/site-cookbooks/b_test/link/spec/default_spec.rb +0 -5
  134. data/test_project/site-cookbooks/b_test/link/templates/.keep +0 -0
  135. data/test_project/site-cookbooks/b_test/remote_file/attributes/.keep +0 -0
  136. data/test_project/site-cookbooks/b_test/remote_file/files/.keep +0 -0
  137. data/test_project/site-cookbooks/b_test/remote_file/files/remote_file.sh +0 -1
  138. data/test_project/site-cookbooks/b_test/remote_file/recipes/default.rb +0 -9
  139. data/test_project/site-cookbooks/b_test/remote_file/spec/.keep +0 -0
  140. data/test_project/site-cookbooks/b_test/remote_file/spec/default_spec.rb +0 -7
  141. data/test_project/site-cookbooks/b_test/remote_file/templates/.keep +0 -0
  142. data/test_project/site-cookbooks/b_test/template/attributes/.keep +0 -0
  143. data/test_project/site-cookbooks/b_test/template/files/.keep +0 -0
  144. data/test_project/site-cookbooks/b_test/template/recipes/default.rb +0 -5
  145. data/test_project/site-cookbooks/b_test/template/spec/.keep +0 -0
  146. data/test_project/site-cookbooks/b_test/template/spec/default_spec.rb +0 -7
  147. data/test_project/site-cookbooks/b_test/template/templates/.keep +0 -0
  148. data/test_project/site-cookbooks/b_test/template/templates/template.erb +0 -2
  149. data/test_project/site-cookbooks/c_test/execute/attributes/.keep +0 -0
  150. data/test_project/site-cookbooks/c_test/execute/files/.keep +0 -0
  151. data/test_project/site-cookbooks/c_test/execute/recipes/default.rb +0 -6
  152. data/test_project/site-cookbooks/c_test/execute/spec/.keep +0 -0
  153. data/test_project/site-cookbooks/c_test/execute/spec/default_spec.rb +0 -6
  154. data/test_project/site-cookbooks/c_test/execute/templates/.keep +0 -0
  155. data/test_project/site-cookbooks/c_test/remote_directory/attributes/.keep +0 -0
  156. data/test_project/site-cookbooks/c_test/remote_directory/files/.keep +0 -0
  157. data/test_project/site-cookbooks/c_test/remote_directory/recipes/default.rb +0 -10
  158. data/test_project/site-cookbooks/c_test/remote_directory/spec/.keep +0 -0
  159. data/test_project/site-cookbooks/c_test/remote_directory/spec/default_spec.rb +0 -20
  160. data/test_project/site-cookbooks/c_test/remote_directory/templates/.keep +0 -0
  161. data/test_project/site-cookbooks/c_test/remote_directory/templates/remote_dir/a.txt +0 -0
  162. data/test_project/site-cookbooks/c_test/remote_directory/templates/remote_dir/b.txt +0 -0
  163. data/test_project/site-cookbooks/c_test/remote_directory/templates/remote_dir/c.txt +0 -0
  164. data/test_project/site-cookbooks/d_spec/air/attributes/.keep +0 -0
  165. data/test_project/site-cookbooks/d_spec/air/files/.keep +0 -0
  166. data/test_project/site-cookbooks/d_spec/air/recipes/default.rb +0 -0
  167. data/test_project/site-cookbooks/d_spec/air/spec/.keep +0 -0
  168. data/test_project/site-cookbooks/d_spec/air/spec/default_spec.rb +0 -0
  169. data/test_project/site-cookbooks/d_spec/air/templates/.keep +0 -0
  170. data/test_project/spec/spec_helper.rb +0 -33
  171. data/test_project/tmp-nodes/.keep +0 -0
  172. data/test_project/tmp-nodes/test.json +0 -12
@@ -1,71 +0,0 @@
1
- require 'itamae-mitsurin'
2
- require 'uri'
3
- require 'net/https'
4
-
5
- module ItamaeMitsurin
6
- module Resource
7
- class HttpRequest < File
8
- RedirectLimitExceeded = Class.new(StandardError)
9
-
10
- define_attribute :action, default: :get
11
- define_attribute :headers, type: Hash, default: {}
12
- define_attribute :message, type: String, default: ""
13
- define_attribute :redirect_limit, type: Integer, default: 10
14
- define_attribute :url, type: String, required: true
15
-
16
- def pre_action
17
- uri = URI.parse(attributes.url)
18
- response = nil
19
- redirects_followed = 0
20
-
21
- loop do
22
- http = Net::HTTP.new(uri.host, uri.port)
23
- http.use_ssl = true if uri.scheme == "https"
24
-
25
- case attributes.action
26
- when :delete, :get, :options
27
- response = http.method(attributes.action).call(uri.request_uri, attributes.headers)
28
- when :post, :put
29
- response = http.method(attributes.action).call(uri.request_uri, attributes.message, attributes.headers)
30
- end
31
-
32
- if response.kind_of?(Net::HTTPRedirection)
33
- if redirects_followed < attributes.redirect_limit
34
- uri = URI.parse(response["location"])
35
- redirects_followed += 1
36
- ItamaeMitsurin.logger.debug "Following redirect #{redirects_followed}/#{attributes.redirect_limit}"
37
- else
38
- raise RedirectLimitExceeded
39
- end
40
- else
41
- break
42
- end
43
- end
44
-
45
- attributes.content = response.body
46
-
47
- super
48
- end
49
-
50
- def action_delete(options)
51
- action_create(options)
52
- end
53
-
54
- def action_get(options)
55
- action_create(options)
56
- end
57
-
58
- def action_options(options)
59
- action_create(options)
60
- end
61
-
62
- def action_post(options)
63
- action_create(options)
64
- end
65
-
66
- def action_put(options)
67
- action_create(options)
68
- end
69
- end
70
- end
71
- end
@@ -1,33 +0,0 @@
1
- require 'itamae-mitsurin'
2
-
3
- module ItamaeMitsurin
4
- module Resource
5
- class Link < Base
6
- define_attribute :action, default: :create
7
- define_attribute :link, type: String, default_name: true
8
- define_attribute :to, type: String, required: true
9
- define_attribute :force, type: [TrueClass, FalseClass], default: false
10
-
11
- def pre_action
12
- case @current_action
13
- when :create
14
- attributes.exist = true
15
- end
16
- end
17
-
18
- def set_current_attributes
19
- current.exist = run_specinfra(:check_file_is_link, attributes.link)
20
-
21
- if current.exist
22
- current.to = run_specinfra(:get_file_link_target, attributes.link).stdout.strip
23
- end
24
- end
25
-
26
- def action_create(options)
27
- unless run_specinfra(:check_file_is_linked_to, attributes.link, attributes.to)
28
- run_specinfra(:link_file_to, attributes.link, attributes.to, force: attributes.force)
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,15 +0,0 @@
1
- require 'itamae-mitsurin'
2
-
3
- module ItamaeMitsurin
4
- module Resource
5
- class LocalRubyBlock < Base
6
- define_attribute :action, default: :run
7
- define_attribute :block, type: Proc
8
-
9
- def action_run(options)
10
- attributes.block.call
11
- end
12
- end
13
- end
14
- end
15
-
@@ -1,44 +0,0 @@
1
- require 'itamae-mitsurin'
2
-
3
- module ItamaeMitsurin
4
- module Resource
5
- class Package < Base
6
- define_attribute :action, default: :install
7
- define_attribute :name, type: String, default_name: true
8
- define_attribute :version, type: String
9
- define_attribute :options, type: String
10
-
11
- def pre_action
12
- case @current_action
13
- when :install
14
- attributes.installed = true
15
- when :remove
16
- attributes.installed = false
17
- end
18
- end
19
-
20
- def set_current_attributes
21
- current.installed = run_specinfra(:check_package_is_installed, attributes.name)
22
-
23
- if current.installed
24
- current.version = run_specinfra(:get_package_version, attributes.name).stdout.strip
25
- end
26
- end
27
-
28
- def action_install(action_options)
29
- unless run_specinfra(:check_package_is_installed, attributes.name, attributes.version)
30
- run_specinfra(:install_package, attributes.name, attributes.version, attributes.options)
31
- updated!
32
- end
33
- end
34
-
35
- def action_remove(action_options)
36
- if run_specinfra(:check_package_is_installed, attributes.name, nil)
37
- run_specinfra(:remove_package, attributes.name, attributes.options)
38
- updated!
39
- end
40
- end
41
- end
42
- end
43
- end
44
-
@@ -1,84 +0,0 @@
1
- require 'itamae-mitsurin'
2
-
3
- module ItamaeMitsurin
4
- module Resource
5
- class RemoteDirectory < Base
6
- define_attribute :action, default: :create
7
- define_attribute :path, type: String, default_name: true
8
- define_attribute :source, type: String, required: true
9
- define_attribute :mode, type: String
10
- define_attribute :owner, type: String
11
- define_attribute :group, type: String
12
-
13
- def pre_action
14
- directory = ::File.expand_path(attributes.source, ::File.dirname(@recipe.path))
15
- src = ::File.expand_path(directory, ::File.dirname(@recipe.path))
16
-
17
- @temppath = ::File.join(runner.tmpdir, Time.now.to_f.to_s)
18
- backend.send_directory(src, @temppath)
19
-
20
- case @current_action
21
- when :create
22
- attributes.exist = true
23
- end
24
- end
25
-
26
- def set_current_attributes
27
- current.exist = run_specinfra(:check_file_is_directory, attributes.path)
28
-
29
- if current.exist
30
- current.mode = run_specinfra(:get_file_mode, attributes.path).stdout.chomp
31
- current.owner = run_specinfra(:get_file_owner_user, attributes.path).stdout.chomp
32
- current.group = run_specinfra(:get_file_owner_group, attributes.path).stdout.chomp
33
- else
34
- current.mode = nil
35
- current.owner = nil
36
- current.group = nil
37
- end
38
- end
39
-
40
- def show_differences
41
- super
42
-
43
- if current.exist
44
- diff = run_command(["diff", "-u", attributes.path, @temppath], error: false)
45
- if diff.exit_status == 0
46
- # no change
47
- ItamaeMitsurin.logger.debug "directory content will not change"
48
- else
49
- ItamaeMitsurin.logger.info "diff:"
50
- diff.stdout.each_line do |line|
51
- ItamaeMitsurin.logger.info "#{line.strip}"
52
- end
53
- end
54
- end
55
- end
56
-
57
- def action_create(options)
58
- if attributes.mode
59
- run_specinfra(:change_file_mode, @temppath, attributes.mode)
60
- end
61
- if attributes.owner || attributes.group
62
- run_specinfra(:change_file_owner, @temppath, attributes.owner, attributes.group)
63
- end
64
-
65
- if run_specinfra(:check_file_is_file, attributes.path)
66
- unless check_command(["diff", "-q", @temppath, attributes.path])
67
- updated!
68
- end
69
- else
70
- updated!
71
- end
72
-
73
- run_specinfra(:remove_file, attributes.path)
74
- run_specinfra(:move_file, @temppath, attributes.path)
75
- end
76
-
77
- def action_delete(options)
78
- if run_specinfra(:check_file_is_directory, attributes.path)
79
- run_specinfra(:remove_file, attributes.path)
80
- end
81
- end
82
- end
83
- end
84
- end
@@ -1,54 +0,0 @@
1
- require 'itamae-mitsurin'
2
-
3
- module ItamaeMitsurin
4
- module Resource
5
- class RemoteFile < File
6
- SourceNotFoundError = Class.new(StandardError)
7
-
8
- define_attribute :source, type: [String, Symbol], default: :auto
9
-
10
- private
11
-
12
- def content_file
13
- source_file
14
- end
15
-
16
- def source_file
17
- @source_file ||= find_source_file
18
- end
19
-
20
- def find_source_file
21
- if attributes.source == :auto
22
- dirs = attributes.path.split(::File::SEPARATOR)
23
- dirs.shift if dirs.first == ""
24
-
25
- searched_paths = []
26
- dirs.size.times do |i|
27
- source_file_exts.each do |ext|
28
- path = ::File.join(@recipe.dir, source_file_dir, "#{dirs[i..-1].join("/")}#{ext}")
29
- if ::File.exist?(path)
30
- ItamaeMitsurin.logger.debug "#{path} is used as a source file."
31
- return path
32
- else
33
- searched_paths << path
34
- end
35
- end
36
- end
37
-
38
- raise SourceNotFoundError, "source file is not found (searched paths: #{searched_paths.join(', ')})"
39
- else
40
- ::File.expand_path(attributes.source, @recipe.dir)
41
- end
42
- end
43
-
44
- def source_file_dir
45
- "files"
46
- end
47
-
48
- def source_file_exts
49
- [""]
50
- end
51
- end
52
- end
53
- end
54
-
@@ -1,69 +0,0 @@
1
- require 'itamae-mitsurin'
2
-
3
- module ItamaeMitsurin
4
- module Resource
5
- class Service < Base
6
- define_attribute :action, default: :nothing
7
- define_attribute :name, type: String, default_name: true
8
- define_attribute :provider, type: Symbol, default: nil
9
-
10
- def initialize(*args)
11
- super
12
- @under = attributes.provider ? "_under_#{attributes.provider}" : ""
13
- end
14
-
15
- def pre_action
16
- case @current_action
17
- when :start, :restart
18
- attributes.running = true
19
- when :stop
20
- attributes.running = false
21
- when :enable
22
- attributes.enabled = true
23
- when :disable
24
- attributes.enabled = false
25
- end
26
- end
27
-
28
- def set_current_attributes
29
- current.running = run_specinfra(:"check_service_is_running#{@under}", attributes.name)
30
- current.enabled = run_specinfra(:"check_service_is_enabled#{@under}", attributes.name)
31
- end
32
-
33
- def action_start(options)
34
- unless current.running
35
- run_specinfra(:"start_service#{@under}", attributes.name)
36
- end
37
- end
38
-
39
- def action_stop(options)
40
- if current.running
41
- run_specinfra(:"stop_service#{@under}", attributes.name)
42
- end
43
- end
44
-
45
- def action_restart(options)
46
- run_specinfra(:"restart_service#{@under}", attributes.name)
47
- end
48
-
49
- def action_reload(options)
50
- if current.running
51
- run_specinfra(:"reload_service#{@under}", attributes.name)
52
- end
53
- end
54
-
55
- def action_enable(options)
56
- unless current.enabled
57
- run_specinfra(:"enable_service#{@under}", attributes.name)
58
- end
59
- end
60
-
61
- def action_disable(options)
62
- if current.enabled
63
- run_specinfra(:"disable_service#{@under}", attributes.name)
64
- end
65
- end
66
- end
67
- end
68
- end
69
-
@@ -1,53 +0,0 @@
1
- require 'itamae-mitsurin'
2
- require 'erb'
3
- require 'tempfile'
4
-
5
- module ItamaeMitsurin
6
- module Resource
7
- class Template < RemoteFile
8
- define_attribute :variables, type: Hash, default: {}
9
-
10
- def pre_action
11
- attributes.content = RenderContext.new(self).render_file(source_file)
12
-
13
- super
14
- end
15
-
16
- private
17
-
18
- def content_file
19
- nil
20
- end
21
-
22
- def source_file_dir
23
- "templates"
24
- end
25
-
26
- def source_file_exts
27
- [".erb", ""]
28
- end
29
-
30
- class RenderContext
31
- def initialize(resource)
32
- @resource = resource
33
-
34
- @resource.attributes.variables.each_pair do |key, value|
35
- instance_variable_set("@#{key}".to_sym, value)
36
- end
37
- end
38
-
39
- def render_file(src)
40
- template = ::File.read(src)
41
- ERB.new(template, nil, '-').tap do |erb|
42
- erb.filename = src
43
- end.result(binding)
44
- end
45
-
46
- def node
47
- @resource.recipe.runner.node
48
- end
49
- end
50
- end
51
- end
52
- end
53
-
@@ -1,93 +0,0 @@
1
- require 'itamae-mitsurin'
2
-
3
- module ItamaeMitsurin
4
- module Resource
5
- class User < Base
6
- define_attribute :action, default: :create
7
- define_attribute :username, type: String, default_name: true
8
- define_attribute :gid, type: [Integer, String]
9
- define_attribute :home, type: String
10
- define_attribute :password, type: String
11
- define_attribute :system_user, type: [TrueClass, FalseClass]
12
- define_attribute :uid, type: Integer
13
- define_attribute :shell, type: String
14
- define_attribute :create_home, type: [TrueClass, FalseClass], default: false
15
-
16
- def pre_action
17
- case @current_action
18
- when :create
19
- attributes.exist = true
20
- end
21
- end
22
-
23
- def set_current_attributes
24
- current.exist = exist?
25
-
26
- if current.exist
27
- current.uid = run_specinfra(:get_user_uid, attributes.username).stdout.strip.to_i
28
- current.gid = run_specinfra(:get_user_gid, attributes.username).stdout.strip.to_i
29
- current.home = run_specinfra(:get_user_home_directory, attributes.username).stdout.strip
30
- current.shell = run_specinfra(:get_user_login_shell, attributes.username).stdout.strip
31
- current.password = current_password
32
- end
33
- end
34
-
35
- def action_create(options)
36
- if run_specinfra(:check_user_exists, attributes.username)
37
- if attributes.uid && attributes.uid != current.uid
38
- run_specinfra(:update_user_uid, attributes.username, attributes.uid)
39
- updated!
40
- end
41
-
42
- if attributes.gid && attributes.gid != current.gid
43
- run_specinfra(:update_user_gid, attributes.username, attributes.gid)
44
- updated!
45
- end
46
-
47
- if attributes.password && attributes.password != current.password
48
- run_specinfra(:update_user_encrypted_password, attributes.username, attributes.password)
49
- updated!
50
- end
51
-
52
- if attributes.home && attributes.home != current.home
53
- run_specinfra(:update_user_home_directory, attributes.username, attributes.home)
54
- updated!
55
- end
56
-
57
- if attributes.shell && attributes.shell != current.shell
58
- run_specinfra(:update_user_login_shell, attributes.username, attributes.shell)
59
- updated!
60
- end
61
- else
62
- options = {
63
- gid: attributes.gid,
64
- home_directory: attributes.home,
65
- password: attributes.password,
66
- system_user: attributes.system_user,
67
- uid: attributes.uid,
68
- shell: attributes.shell,
69
- create_home: attributes.create_home,
70
- }
71
-
72
- run_specinfra(:add_user, attributes.username, options)
73
-
74
- updated!
75
- end
76
- end
77
-
78
- private
79
- def exist?
80
- run_specinfra(:check_user_exists, attributes.username)
81
- end
82
-
83
- def current_password
84
- result = run_specinfra(:get_user_encrypted_password, attributes.username)
85
- if result.success?
86
- result.stdout.strip
87
- else
88
- nil
89
- end
90
- end
91
- end
92
- end
93
- end