serverkit 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +7 -0
- data/README.md +5 -3
- data/example/recipe.yml +11 -3
- data/lib/serverkit/backends/base_backend.rb +5 -0
- data/lib/serverkit/resource_builder.rb +2 -0
- data/lib/serverkit/resources/directory.rb +69 -0
- data/lib/serverkit/resources/file.rb +52 -27
- data/lib/serverkit/resources/remote_file.rb +69 -0
- data/lib/serverkit/resources/user.rb +26 -13
- data/lib/serverkit/version.rb +1 -1
- data/serverkit.gemspec +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c63fd1655ae7424f508d32cdaefa5c0e83090117
|
4
|
+
data.tar.gz: b4c5a55c88bb2e2031dd3321f26443c32bdf79a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66c44fa0c113ccbde06013a4eab9d63ec42175572e8c6dd3848e764531d404d665f8668a5367df74d8186a80522e7dac8a13e3072a36cb0d633947ac8e55f6c1
|
7
|
+
data.tar.gz: 28ae2520dc1e0805e070cff7cc4ebb7d5f4e5725d5ec27f7e4948314a38ead1442a16f7079ff0f4758296c7a5d14a129e5203815c3e963c53c0f5ef2c2ee8fc4
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 0.4.3
|
2
|
+
- Add directory resource
|
3
|
+
- Add file resource
|
4
|
+
- Rename the previous file resource with remote_file
|
5
|
+
- Support shell attribute on user resource
|
6
|
+
- Change some attribue names on user resource
|
7
|
+
|
1
8
|
## 0.4.2
|
2
9
|
- Fix bug on apply action exit code
|
3
10
|
- Support case-insensitive or number log-level
|
data/README.md
CHANGED
@@ -25,12 +25,12 @@ Write a recipe, then run `serverkit` executable to validate, inspect, check, and
|
|
25
25
|
|
26
26
|
### serverkit validate
|
27
27
|
Validates recipe schema, resources, and attributes.
|
28
|
-
For instance, it shows validation error if `source` attributes is missing in `
|
28
|
+
For instance, it shows validation error if `source` attributes is missing in `remote_file` resource.
|
29
29
|
If any validation error is detected, it returns exit status 1.
|
30
30
|
|
31
31
|
```
|
32
32
|
$ serverkit validate recipe.yml
|
33
|
-
Error: source attribute is required in
|
33
|
+
Error: source attribute is required in remote_file resource
|
34
34
|
Error: path attribute can't be unreadable path in recipe resource
|
35
35
|
```
|
36
36
|
|
@@ -192,14 +192,16 @@ By default, all types of resource can or must have the following attributes:
|
|
192
192
|
- notify - specify an Array of handler ids that should be applied after changed
|
193
193
|
|
194
194
|
### Type
|
195
|
-
A resource must have a type attribute
|
195
|
+
A resource must have a valid type attribute like:
|
196
196
|
|
197
197
|
- command
|
198
|
+
- directory
|
198
199
|
- file
|
199
200
|
- git
|
200
201
|
- nothing
|
201
202
|
- package
|
202
203
|
- recipe
|
204
|
+
- remote_file
|
203
205
|
- service
|
204
206
|
- symlink
|
205
207
|
- user
|
data/example/recipe.yml
CHANGED
@@ -1,7 +1,15 @@
|
|
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
|
2
8
|
- type: user
|
3
9
|
name: test
|
4
10
|
password: test
|
5
|
-
|
6
|
-
|
7
|
-
|
11
|
+
home: /Users/test
|
12
|
+
shell: /bin/bash
|
13
|
+
- type: directory
|
14
|
+
path: /Users/test
|
15
|
+
owner: test
|
@@ -1,11 +1,13 @@
|
|
1
1
|
require "active_support/core_ext/string/inflections"
|
2
2
|
require "serverkit/resources/command"
|
3
|
+
require "serverkit/resources/directory"
|
3
4
|
require "serverkit/resources/file"
|
4
5
|
require "serverkit/resources/git"
|
5
6
|
require "serverkit/resources/missing"
|
6
7
|
require "serverkit/resources/nothing"
|
7
8
|
require "serverkit/resources/package"
|
8
9
|
require "serverkit/resources/recipe"
|
10
|
+
require "serverkit/resources/remote_file"
|
9
11
|
require "serverkit/resources/service"
|
10
12
|
require "serverkit/resources/symlink"
|
11
13
|
require "serverkit/resources/unknown"
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require "serverkit/resources/base"
|
2
|
+
|
3
|
+
module Serverkit
|
4
|
+
module Resources
|
5
|
+
class Directory < Base
|
6
|
+
attribute :group, type: String
|
7
|
+
attribute :mode, type: [Integer, String]
|
8
|
+
attribute :owner, type: String
|
9
|
+
attribute :path, required: true, type: String
|
10
|
+
|
11
|
+
# @note Override
|
12
|
+
def apply
|
13
|
+
create_directory unless has_correct_directory?
|
14
|
+
update_group unless has_correct_group?
|
15
|
+
update_mode unless has_correct_mode?
|
16
|
+
update_owner unless has_correct_owner?
|
17
|
+
end
|
18
|
+
|
19
|
+
# @note Override
|
20
|
+
def check
|
21
|
+
has_correct_directory? && has_correct_group? && has_correct_mode? && has_correct_owner?
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def create_directory
|
27
|
+
run_command_from_identifier(:create_file_as_directory, path)
|
28
|
+
end
|
29
|
+
|
30
|
+
def has_correct_directory?
|
31
|
+
check_command_from_identifier(:check_file_is_directory, path)
|
32
|
+
end
|
33
|
+
|
34
|
+
def has_correct_group?
|
35
|
+
group.nil? || check_command_from_identifier(:check_file_is_grouped, path, group)
|
36
|
+
end
|
37
|
+
|
38
|
+
def has_correct_mode?
|
39
|
+
mode.nil? || check_command_from_identifier(:check_file_has_mode, path, mode_in_octal_notation)
|
40
|
+
end
|
41
|
+
|
42
|
+
def has_correct_owner?
|
43
|
+
owner.nil? || check_command_from_identifier(:check_file_is_owned_by, path, owner)
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [String]
|
47
|
+
# @example "755" # for 0755
|
48
|
+
def mode_in_octal_notation
|
49
|
+
if mode.is_a?(Integer)
|
50
|
+
mode.to_s(8)
|
51
|
+
else
|
52
|
+
mode
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def update_group
|
57
|
+
run_command_from_identifier(:change_file_group, path, group)
|
58
|
+
end
|
59
|
+
|
60
|
+
def update_mode
|
61
|
+
run_command_from_identifier(:change_file_mode, path, mode_in_octal_notation)
|
62
|
+
end
|
63
|
+
|
64
|
+
def update_owner
|
65
|
+
run_command_from_identifier(:change_file_owner, path, owner)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -1,68 +1,93 @@
|
|
1
1
|
require "digest"
|
2
2
|
require "serverkit/resources/base"
|
3
|
+
require "tempfile"
|
3
4
|
|
4
5
|
module Serverkit
|
5
6
|
module Resources
|
6
7
|
class File < Base
|
7
|
-
attribute :
|
8
|
+
attribute :content, type: String
|
8
9
|
attribute :group, type: String
|
10
|
+
attribute :mode, type: [Integer, String]
|
9
11
|
attribute :owner, type: String
|
10
|
-
attribute :
|
12
|
+
attribute :path, required: true, type: String
|
11
13
|
|
12
14
|
# @note Override
|
13
15
|
def apply
|
14
|
-
|
15
|
-
|
16
|
-
|
16
|
+
update_file unless has_correct_file?
|
17
|
+
update_group unless has_correct_group?
|
18
|
+
update_mode unless has_correct_mode?
|
19
|
+
update_owner unless has_correct_owner?
|
17
20
|
end
|
18
21
|
|
19
22
|
# @note Override
|
20
23
|
def check
|
21
|
-
|
24
|
+
has_correct_file? && has_correct_group? && has_correct_mode? && has_correct_owner?
|
22
25
|
end
|
23
26
|
|
24
27
|
private
|
25
28
|
|
26
|
-
|
27
|
-
|
29
|
+
# @return [String]
|
30
|
+
def content_sha256sum
|
31
|
+
::Digest::SHA256.hexdigest(content)
|
28
32
|
end
|
29
33
|
|
30
|
-
|
31
|
-
|
34
|
+
# @return [String]
|
35
|
+
def file_sha256sum
|
36
|
+
run_command_from_identifier(:get_file_sha256sum, path).stdout.rstrip
|
32
37
|
end
|
33
38
|
|
34
|
-
def
|
35
|
-
|
39
|
+
def has_file?
|
40
|
+
check_command_from_identifier(:check_file_is_file, path)
|
36
41
|
end
|
37
42
|
|
38
|
-
def
|
39
|
-
|
43
|
+
def has_correct_content?
|
44
|
+
content.nil? || file_sha256sum == content_sha256sum
|
40
45
|
end
|
41
46
|
|
42
|
-
def
|
43
|
-
|
47
|
+
def has_correct_file?
|
48
|
+
has_file? && has_correct_content?
|
44
49
|
end
|
45
50
|
|
46
|
-
def
|
47
|
-
group.nil? || check_command_from_identifier(:check_file_is_grouped,
|
51
|
+
def has_correct_group?
|
52
|
+
group.nil? || check_command_from_identifier(:check_file_is_grouped, path, group)
|
48
53
|
end
|
49
54
|
|
50
|
-
def
|
51
|
-
|
55
|
+
def has_correct_mode?
|
56
|
+
mode.nil? || check_command_from_identifier(:check_file_has_mode, path, mode_in_octal_notation)
|
52
57
|
end
|
53
58
|
|
54
|
-
|
55
|
-
|
56
|
-
::Digest::SHA256.hexdigest(::File.read(source))
|
59
|
+
def has_correct_owner?
|
60
|
+
owner.nil? || check_command_from_identifier(:check_file_is_owned_by, path, owner)
|
57
61
|
end
|
58
62
|
|
59
63
|
# @return [String]
|
60
|
-
|
61
|
-
|
64
|
+
# @example "755" # for 0755
|
65
|
+
def mode_in_octal_notation
|
66
|
+
if mode.is_a?(Integer)
|
67
|
+
mode.to_s(8)
|
68
|
+
else
|
69
|
+
mode
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def update_file
|
74
|
+
::Tempfile.open("") do |file|
|
75
|
+
file.write(content || "")
|
76
|
+
file.close
|
77
|
+
backend.send_file(file.path, path)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def update_group
|
82
|
+
run_command_from_identifier(:change_file_group, path, group)
|
83
|
+
end
|
84
|
+
|
85
|
+
def update_mode
|
86
|
+
run_command_from_identifier(:change_file_mode, path, mode_in_octal_notation)
|
62
87
|
end
|
63
88
|
|
64
|
-
def
|
65
|
-
run_command_from_identifier(:
|
89
|
+
def update_owner
|
90
|
+
run_command_from_identifier(:change_file_owner, path, owner)
|
66
91
|
end
|
67
92
|
end
|
68
93
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require "digest"
|
2
|
+
require "serverkit/resources/base"
|
3
|
+
|
4
|
+
module Serverkit
|
5
|
+
module Resources
|
6
|
+
class RemoteFile < Base
|
7
|
+
attribute :destination, required: true, type: String
|
8
|
+
attribute :group, type: String
|
9
|
+
attribute :owner, type: String
|
10
|
+
attribute :source, readable: true, required: true, type: String
|
11
|
+
|
12
|
+
# @note Override
|
13
|
+
def apply
|
14
|
+
send_file_from_source_to_destination if file_sendable?
|
15
|
+
change_group unless has_valid_group?
|
16
|
+
change_owner unless has_valid_owner?
|
17
|
+
end
|
18
|
+
|
19
|
+
# @note Override
|
20
|
+
def check
|
21
|
+
has_file? && has_same_content? && has_valid_group? && has_valid_owner?
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def change_group
|
27
|
+
run_command_from_identifier(:change_file_group, destination, group)
|
28
|
+
end
|
29
|
+
|
30
|
+
def change_owner
|
31
|
+
run_command_from_identifier(:change_file_owner, destination, owner)
|
32
|
+
end
|
33
|
+
|
34
|
+
def file_sendable?
|
35
|
+
!has_file? || !has_same_content?
|
36
|
+
end
|
37
|
+
|
38
|
+
def has_file?
|
39
|
+
check_command_from_identifier(:check_file_is_file, destination)
|
40
|
+
end
|
41
|
+
|
42
|
+
def has_same_content?
|
43
|
+
remote_file_sha256sum == local_file_sha256sum
|
44
|
+
end
|
45
|
+
|
46
|
+
def has_valid_group?
|
47
|
+
group.nil? || check_command_from_identifier(:check_file_is_grouped, destination, group)
|
48
|
+
end
|
49
|
+
|
50
|
+
def has_valid_owner?
|
51
|
+
owner.nil? || check_command_from_identifier(:check_file_is_owned_by, destination, owner)
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [String]
|
55
|
+
def local_file_sha256sum
|
56
|
+
::Digest::SHA256.hexdigest(::File.read(source))
|
57
|
+
end
|
58
|
+
|
59
|
+
# @return [String]
|
60
|
+
def remote_file_sha256sum
|
61
|
+
run_command_from_identifier(:get_file_sha256sum, destination).stdout.rstrip
|
62
|
+
end
|
63
|
+
|
64
|
+
def send_file_from_source_to_destination
|
65
|
+
send_file(source, destination)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -5,10 +5,11 @@ module Serverkit
|
|
5
5
|
module Resources
|
6
6
|
class User < Base
|
7
7
|
attribute :gid, type: [Integer, String]
|
8
|
-
attribute :
|
8
|
+
attribute :home, type: String
|
9
9
|
attribute :name, type: String, required: true
|
10
10
|
attribute :password, type: String
|
11
|
-
attribute :
|
11
|
+
attribute :shell, type: String
|
12
|
+
attribute :system, type: [FalseClass, TrueClass]
|
12
13
|
attribute :uid, type: Integer
|
13
14
|
|
14
15
|
# @note Override
|
@@ -17,6 +18,7 @@ module Serverkit
|
|
17
18
|
update_user_encrypted_password unless has_correct_password?
|
18
19
|
update_user_gid unless has_correct_gid?
|
19
20
|
update_user_home_directory unless has_correct_home_directory?
|
21
|
+
update_user_login_shell unless has_correct_login_shell?
|
20
22
|
update_user_uid unless has_correct_uid?
|
21
23
|
else
|
22
24
|
add_user
|
@@ -28,13 +30,15 @@ module Serverkit
|
|
28
30
|
case
|
29
31
|
when !has_correct_user?
|
30
32
|
false
|
31
|
-
when
|
33
|
+
when !has_correct_gid?
|
32
34
|
false
|
33
|
-
when
|
35
|
+
when !has_correct_home_directory?
|
34
36
|
false
|
35
|
-
when
|
37
|
+
when !has_correct_password?
|
36
38
|
false
|
37
|
-
when
|
39
|
+
when !has_correct_login_shell?
|
40
|
+
false
|
41
|
+
when !has_correct_uid?
|
38
42
|
false
|
39
43
|
else
|
40
44
|
true
|
@@ -48,9 +52,10 @@ module Serverkit
|
|
48
52
|
:add_user,
|
49
53
|
name,
|
50
54
|
gid: gid,
|
51
|
-
home_directory:
|
55
|
+
home_directory: home,
|
52
56
|
password: encrypted_password,
|
53
|
-
|
57
|
+
shell: shell,
|
58
|
+
system_user: system,
|
54
59
|
uid: uid,
|
55
60
|
)
|
56
61
|
end
|
@@ -64,19 +69,23 @@ module Serverkit
|
|
64
69
|
end
|
65
70
|
|
66
71
|
def has_correct_gid?
|
67
|
-
check_command_from_identifier(:check_user_belongs_to_group, name, gid)
|
72
|
+
gid.nil? || check_command_from_identifier(:check_user_belongs_to_group, name, gid)
|
68
73
|
end
|
69
74
|
|
70
75
|
def has_correct_home_directory?
|
71
|
-
check_command_from_identifier(:check_user_has_home_directory, name,
|
76
|
+
home.nil? || check_command_from_identifier(:check_user_has_home_directory, name, home)
|
77
|
+
end
|
78
|
+
|
79
|
+
def has_correct_login_shell?
|
80
|
+
shell.nil? || check_command_from_identifier(:check_user_has_login_shell, name, shell)
|
72
81
|
end
|
73
82
|
|
74
83
|
def has_correct_password?
|
75
|
-
::UnixCrypt.valid?(password, get_remote_encrypted_password)
|
84
|
+
password.nil? || ::UnixCrypt.valid?(password, get_remote_encrypted_password)
|
76
85
|
end
|
77
86
|
|
78
87
|
def has_correct_uid?
|
79
|
-
check_command_from_identifier(:check_user_has_uid, name, uid)
|
88
|
+
uid.nil? || check_command_from_identifier(:check_user_has_uid, name, uid)
|
80
89
|
end
|
81
90
|
|
82
91
|
def has_correct_user?
|
@@ -92,7 +101,11 @@ module Serverkit
|
|
92
101
|
end
|
93
102
|
|
94
103
|
def update_user_home_directory
|
95
|
-
run_command_from_identifier(:update_user_home_directory, name,
|
104
|
+
run_command_from_identifier(:update_user_home_directory, name, home)
|
105
|
+
end
|
106
|
+
|
107
|
+
def update_user_login_shell
|
108
|
+
run_command_from_identifier(:update_user_login_shell, name, shell)
|
96
109
|
end
|
97
110
|
|
98
111
|
def update_user_uid
|
data/lib/serverkit/version.rb
CHANGED
data/serverkit.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_runtime_dependency "highline"
|
24
24
|
spec.add_runtime_dependency "rainbow"
|
25
25
|
spec.add_runtime_dependency "slop", "~> 3.4"
|
26
|
-
spec.add_runtime_dependency "specinfra"
|
26
|
+
spec.add_runtime_dependency "specinfra", ">= 2.29.0"
|
27
27
|
spec.add_runtime_dependency "unix-crypt"
|
28
28
|
spec.add_development_dependency "pry", "0.10.1"
|
29
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
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.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: 2.29.0
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
124
|
+
version: 2.29.0
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: unix-crypt
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -242,12 +242,14 @@ files:
|
|
242
242
|
- lib/serverkit/resource_builder.rb
|
243
243
|
- lib/serverkit/resources/base.rb
|
244
244
|
- lib/serverkit/resources/command.rb
|
245
|
+
- lib/serverkit/resources/directory.rb
|
245
246
|
- lib/serverkit/resources/file.rb
|
246
247
|
- lib/serverkit/resources/git.rb
|
247
248
|
- lib/serverkit/resources/missing.rb
|
248
249
|
- lib/serverkit/resources/nothing.rb
|
249
250
|
- lib/serverkit/resources/package.rb
|
250
251
|
- lib/serverkit/resources/recipe.rb
|
252
|
+
- lib/serverkit/resources/remote_file.rb
|
251
253
|
- lib/serverkit/resources/service.rb
|
252
254
|
- lib/serverkit/resources/symlink.rb
|
253
255
|
- lib/serverkit/resources/unknown.rb
|