serverkit 0.4.0 → 0.4.1

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: 174dabbbd261022d8472541f073f877df3e18d14
4
- data.tar.gz: 9a640c7f32fd916751f6d975852b6020f6c0a301
3
+ metadata.gz: a36fe579bf7780e6e75bb199039675897a356768
4
+ data.tar.gz: f3b1295d4b074e6350b4062e63cea098830f4340
5
5
  SHA512:
6
- metadata.gz: 39d435b1b256e029edb9019cc1496a03ff8480fb5edd2f0165757eb88313e8eb99251f76535144eaf54347bced62c1ebd57d431bee95a8fa40c25154b5f94abe
7
- data.tar.gz: d08d24dca2751a11a4a6bc3fec77f4086753a7108b7bea749ac34952388e25639300b8e3224e7c25e71868bc9e8a539f1ad5d6dee82c396228c1331b27d2d9bf
6
+ metadata.gz: 92942f4878c772f8fddfa275deaf9947212a315404538218d38a20d1e2230b0979336a190aafc76b6d3bbac5b59569d20617e7c0a8b568361bd613db84a9924b
7
+ data.tar.gz: fcde5f4a9b5643e16dc408280c8342f66ff4bb2d26bbc194691da5efabb85112470dc7af1f5848a1da2062349342f9b73bd0006818e1e9daa0244d1eea7d48e4
data/.gitignore CHANGED
@@ -1,9 +1,10 @@
1
+ /_yardoc/
1
2
  /.bundle/
3
+ /.vagrant
2
4
  /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
5
  /coverage/
6
6
  /doc/
7
+ /Gemfile.lock
7
8
  /pkg/
8
9
  /spec/reports/
9
10
  /tmp/
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.4.1
2
+ - Add user resource
3
+
1
4
  ## 0.4.0
2
5
  - Deprecate homebrew & homebrew_cask resources
3
6
  - Add check_script and recheck_script to all resources
data/README.md CHANGED
@@ -13,6 +13,7 @@ Configuration management toolkit for IT automation.
13
13
  - [Variables](#variables)
14
14
  - [Example](#example)
15
15
  - [Resource](#resource)
16
+ - [Attributes](#attributes)
16
17
  - [Type](#type)
17
18
  - [Example](#example-1)
18
19
  - [Handler](#handler)
@@ -180,6 +181,16 @@ resources:
180
181
  ## Resource
181
182
  A resource is a statement of configuration policy that describes the desired state for an item.
182
183
 
184
+ ### Attributes
185
+ Each resource has different attributes along with its type.
186
+ By default, all types of resource can or must have the following attributes:
187
+
188
+ - type - what type this resource represents (required)
189
+ - check_script - pass shell script to override the `#check` phase
190
+ - recheck_script - pass shell script to override the `#recheck` phase (runned after `#apply`)
191
+ - id - change resource identifier used in log, and also used for `notify`
192
+ - notify - specify an Array of handler ids that should be applied after changed
193
+
183
194
  ### Type
184
195
  A resource must have a type attribute. Currently the following types are available:
185
196
 
@@ -191,6 +202,7 @@ A resource must have a type attribute. Currently the following types are availab
191
202
  - recipe
192
203
  - service
193
204
  - symlink
205
+ - user
194
206
 
195
207
  ### Example
196
208
  An example package resource that has type and name attributes.
data/Vagrantfile ADDED
@@ -0,0 +1,12 @@
1
+ Vagrant.configure("2") do |config|
2
+ config.vm.box = "ubuntu/trusty64"
3
+
4
+ config.plugin.add_dependency "vagrant-multiplug"
5
+ config.plugin.add_dependency "vagrant-serverkit", "0.0.5"
6
+
7
+ config.vm.provision :serverkit do |serverkit_config|
8
+ serverkit_config.log_level = "DEBUG"
9
+ serverkit_config.recipe_path = "example/recipes/recipe.yml"
10
+ serverkit_config.variables_path = "example/variables"
11
+ end
12
+ end
@@ -1,20 +1,7 @@
1
1
  resources:
2
- - type: recipe
3
- path: example/recipes/homebrew.yml
4
- - type: recipe
5
- path: example/recipes/homebrew_cask.yml
6
- - type: recipe
7
- path: example/recipes/dotfiles.yml.erb
8
- - type: nothing
9
- notify:
10
- - handler_test
11
- - type: nothing
12
- notify:
13
- - handler_test
14
- - type: command
15
- check_script: foo
16
- script: echo test
17
- recheck_script: "true"
2
+ - type: user
3
+ name: test
4
+ password: test
18
5
  handlers:
19
6
  - id: handler_test
20
7
  type: nothing
@@ -9,6 +9,7 @@ require "serverkit/resources/recipe"
9
9
  require "serverkit/resources/service"
10
10
  require "serverkit/resources/symlink"
11
11
  require "serverkit/resources/unknown"
12
+ require "serverkit/resources/user"
12
13
 
13
14
  module Serverkit
14
15
  class ResourceBuilder
@@ -0,0 +1,103 @@
1
+ require "serverkit/resources/base"
2
+ require "unix_crypt"
3
+
4
+ module Serverkit
5
+ module Resources
6
+ class User < Base
7
+ attribute :gid, type: [Integer, String]
8
+ attribute :home_directory, type: String
9
+ attribute :name, type: String, required: true
10
+ attribute :password, type: String
11
+ attribute :system_user, type: [FalseClass, TrueClass]
12
+ attribute :uid, type: Integer
13
+
14
+ # @note Override
15
+ def apply
16
+ if has_correct_user?
17
+ update_user_encrypted_password unless has_correct_password?
18
+ update_user_gid unless has_correct_gid?
19
+ update_user_home_directory unless has_correct_home_directory?
20
+ update_user_uid unless has_correct_uid?
21
+ else
22
+ add_user
23
+ end
24
+ end
25
+
26
+ # @note Override
27
+ def check
28
+ case
29
+ when !has_correct_user?
30
+ false
31
+ when gid && !has_correct_gid?
32
+ false
33
+ when home_directory && !has_correct_home_directory?
34
+ false
35
+ when password && !has_correct_password?
36
+ false
37
+ when uid && !has_correct_uid?
38
+ false
39
+ else
40
+ true
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def add_user
47
+ run_command_from_identifier(
48
+ :add_user,
49
+ name,
50
+ gid: gid,
51
+ home_directory: home_directory,
52
+ password: encrypted_password,
53
+ system_user: system_user,
54
+ uid: uid,
55
+ )
56
+ end
57
+
58
+ def encrypted_password
59
+ @encrypted_password ||= UnixCrypt::SHA512.build(password)
60
+ end
61
+
62
+ def get_remote_encrypted_password
63
+ run_command_from_identifier(:get_user_encrypted_password, name).stdout
64
+ end
65
+
66
+ def has_correct_gid?
67
+ check_command_from_identifier(:check_user_belongs_to_group, name, gid)
68
+ end
69
+
70
+ def has_correct_home_directory?
71
+ check_command_from_identifier(:check_user_has_home_directory, name, home_directory)
72
+ end
73
+
74
+ def has_correct_password?
75
+ ::UnixCrypt.valid?(password, get_remote_encrypted_password)
76
+ end
77
+
78
+ def has_correct_uid?
79
+ check_command_from_identifier(:check_user_has_uid, name, uid)
80
+ end
81
+
82
+ def has_correct_user?
83
+ check_command_from_identifier(:check_user_exists, name)
84
+ end
85
+
86
+ def update_user_encrypted_password
87
+ run_command_from_identifier(:update_user_encrypted_password, name, encrypted_password)
88
+ end
89
+
90
+ def update_user_gid
91
+ run_command_from_identifier(:update_user_gid, name, gid)
92
+ end
93
+
94
+ def update_user_home_directory
95
+ run_command_from_identifier(:update_user_home_directory, name, home_directory)
96
+ end
97
+
98
+ def update_user_uid
99
+ run_command_from_identifier(:update_user_uid, name, uid)
100
+ end
101
+ end
102
+ end
103
+ end
@@ -1,3 +1,3 @@
1
1
  module Serverkit
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
data/serverkit.gemspec CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_runtime_dependency "rainbow"
25
25
  spec.add_runtime_dependency "slop", "~> 3.4"
26
26
  spec.add_runtime_dependency "specinfra"
27
+ spec.add_runtime_dependency "unix-crypt"
27
28
  spec.add_development_dependency "pry", "0.10.1"
28
29
  spec.add_development_dependency "rake", "~> 10.0"
29
30
  spec.add_development_dependency "rspec", "3.2.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.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: unix-crypt
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: pry
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -195,12 +209,9 @@ files:
195
209
  - LICENSE.txt
196
210
  - README.md
197
211
  - Rakefile
212
+ - Vagrantfile
198
213
  - bin/serverkit
199
214
  - example/recipes/dotfiles.yml.erb
200
- - example/recipes/homebrew.yml
201
- - example/recipes/homebrew_cask.yml
202
- - example/recipes/recipe.json
203
- - example/recipes/recipe.rb
204
215
  - example/recipes/recipe.yml
205
216
  - example/variables/variables.yml
206
217
  - lib/readable_validator.rb
@@ -242,6 +253,7 @@ files:
242
253
  - lib/serverkit/resources/service.rb
243
254
  - lib/serverkit/resources/symlink.rb
244
255
  - lib/serverkit/resources/unknown.rb
256
+ - lib/serverkit/resources/user.rb
245
257
  - lib/serverkit/variables.rb
246
258
  - lib/serverkit/version.rb
247
259
  - lib/type_validator.rb
@@ -1,5 +0,0 @@
1
- resources:
2
- - type: homebrew
3
- name: mysql
4
- - type: homebrew
5
- name: redis
@@ -1,5 +0,0 @@
1
- resources:
2
- - type: homebrew_cask
3
- name: licecap
4
- - type: homebrew_cask
5
- name: alfred
@@ -1,16 +0,0 @@
1
- {
2
- "resources": [
3
- {
4
- "type": "recipe",
5
- "path": "example/recipes/homebrew.yml"
6
- },
7
- {
8
- "type": "recipe",
9
- "path": "example/recipes/homebrew_cask.yml"
10
- },
11
- {
12
- "type": "recipe",
13
- "path": "example/recipes/dotfiles.yml.erb"
14
- }
15
- ]
16
- }
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require "json"
3
- require "yaml"
4
-
5
- puts YAML.load_file(File.expand_path("../recipe.yml", __FILE__)).to_json