serverkit 0.4.7 → 0.4.8

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: 4ecbe14e1d8535b375c1b36fded6812e78b6f9ae
4
- data.tar.gz: f3f6e8e044a4f14147d11a81d6dd7768714c33b7
3
+ metadata.gz: 8940c786379f55b05d9416d30a0b80488db1bbc4
4
+ data.tar.gz: c59b253fec99e0a5b4bdccfe30fa205fe5d25c50
5
5
  SHA512:
6
- metadata.gz: dcced11db20e463973e4a497478063a8341a6dc9072048bf4c78d90062216b634e6b0355488fdabfa3b18d061691351cac565a03d2ced85abf150b68a331900c
7
- data.tar.gz: 5e28e75b6aba016381790d62143033fac0bfe17df3ee3290a2621afad8aec00ba964edb73264cab35a9b1408a5e828cf7fdb48d51bfc984cea339589f0b0fe6b
6
+ metadata.gz: 7121acccc709d1e5dff3d4d69bcfb43eb405f1e4408548e4f73a3b28907b963ec1d5659076891c3f8687fc516570952aa9d7c8f2ac7d5ad9e72ff8de65736144
7
+ data.tar.gz: b3a2456a7c2b784330900408b0667da7a048e832d89dd2b422727d1b54aaa4671989fa10a34eb2e43a3f2bd353c49accbc2043e36e42c742d02055c59be6580b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.4.8
2
+ - Add line resource
3
+
1
4
  ## 0.4.7
2
5
  - Add a patch for vagrant-serverkit
3
6
 
data/README.md CHANGED
@@ -199,6 +199,7 @@ A resource must have a valid type attribute like:
199
199
  - [file](https://github.com/r7kamura/serverkit/blob/master/lib/serverkit/resources/file.rb)
200
200
  - [git](https://github.com/r7kamura/serverkit/blob/master/lib/serverkit/resources/git.rb)
201
201
  - [group](https://github.com/r7kamura/serverkit/blob/master/lib/serverkit/resources/group.rb)
202
+ - [line](https://github.com/r7kamura/serverkit/blob/master/lib/serverkit/resources/line.rb)
202
203
  - [nothing](https://github.com/r7kamura/serverkit/blob/master/lib/serverkit/resources/nothing.rb)
203
204
  - [package](https://github.com/r7kamura/serverkit/blob/master/lib/serverkit/resources/package.rb)
204
205
  - [recipe](https://github.com/r7kamura/serverkit/blob/master/lib/serverkit/resources/recipe.rb)
data/example/recipe.yml CHANGED
@@ -1,21 +1,17 @@
1
1
  resources:
2
- - type: remote_file
3
- source: README.md
4
- destination: /tmp/README.md
5
- - type: file
6
- path: /tmp/README.md
7
- content: foo
8
2
  - type: user
9
- name: test
10
- password: test
11
- home: /Users/test
3
+ name: kit
4
+ password: kit
5
+ home: /home/kit
12
6
  shell: /bin/bash
13
- - type: directory
14
- path: /Users/test
15
- owner: test
16
- - type: template
17
- source: example/template.erb
18
- destination: /tmp/template_test
19
7
  - type: group
20
8
  name: wheel
21
- gid: 10000
9
+ - type: user
10
+ name: kit
11
+ group: wheel
12
+ - type: directory
13
+ path: /home/kit/.ssh
14
+ mode: 0700
15
+ - type: line
16
+ path: /etc/sudoers
17
+ line: "#includedir /etc/sudoers.d"
@@ -4,6 +4,7 @@ require "serverkit/resources/directory"
4
4
  require "serverkit/resources/file"
5
5
  require "serverkit/resources/git"
6
6
  require "serverkit/resources/group"
7
+ require "serverkit/resources/line"
7
8
  require "serverkit/resources/missing"
8
9
  require "serverkit/resources/nothing"
9
10
  require "serverkit/resources/package"
@@ -0,0 +1,70 @@
1
+ require "serverkit/resources/base"
2
+
3
+ module Serverkit
4
+ module Resources
5
+ # Ensure a particular line is in a file, or replace an existing line using regexp.
6
+ # @example Example line resource that ensures a line is in /etc/sudoers
7
+ # - type: line
8
+ # path: /etc/sudoers
9
+ # line: "#includedir /etc/sudoers.d"
10
+ class Line < Base
11
+ DEFAULT_STATE = "present"
12
+
13
+ attribute :path, required: true, type: String
14
+ attribute :line, required: true, type: String
15
+ attribute :state, default: DEFAULT_STATE, inclusion: %w[absent present], type: String
16
+
17
+ # @note Override
18
+ def apply
19
+ if has_correct_file?
20
+ send_applied_remote_file_content_to_path
21
+ end
22
+ end
23
+
24
+ # @note Override
25
+ def check
26
+ has_correct_file? && has_correct_line?
27
+ end
28
+
29
+ private
30
+
31
+ # @return [String]
32
+ def applied_remote_file_content
33
+ if present?
34
+ remote_file_content << line_with_break
35
+ else
36
+ (remote_file_content.each_line.to_a - [line_with_break]).join
37
+ end
38
+ end
39
+
40
+ def has_correct_file?
41
+ check_command_from_identifier(:check_file_is_file, path)
42
+ end
43
+
44
+ def has_correct_line?
45
+ !(present? ^ remote_file_content.each_line.include?(line_with_break))
46
+ end
47
+
48
+ def line_with_break
49
+ "#{line}\n"
50
+ end
51
+
52
+ def present?
53
+ state == "present"
54
+ end
55
+
56
+ # @return [String]
57
+ def remote_file_content
58
+ run_command_from_identifier(:get_file_content, path).stdout
59
+ end
60
+
61
+ def send_applied_remote_file_content_to_path
62
+ ::Tempfile.open("") do |file|
63
+ file.write(applied_remote_file_content)
64
+ file.close
65
+ backend.send_file(file.path, path)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -1,3 +1,3 @@
1
1
  module Serverkit
2
- VERSION = "0.4.7"
2
+ VERSION = "0.4.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serverkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.7
4
+ version: 0.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
@@ -249,6 +249,7 @@ files:
249
249
  - lib/serverkit/resources/file.rb
250
250
  - lib/serverkit/resources/git.rb
251
251
  - lib/serverkit/resources/group.rb
252
+ - lib/serverkit/resources/line.rb
252
253
  - lib/serverkit/resources/missing.rb
253
254
  - lib/serverkit/resources/nothing.rb
254
255
  - lib/serverkit/resources/package.rb
@@ -288,3 +289,4 @@ signing_key:
288
289
  specification_version: 4
289
290
  summary: Configuration management toolkit for IT automation.
290
291
  test_files: []
292
+ has_rdoc: