itamae 1.0.0.beta24 → 1.0.0.beta25

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: ea6fc052b822e3cde537f8c2f7b78116d5ed5875
4
- data.tar.gz: c291f27cb784245988bc80b6eb5b41afef44704f
3
+ metadata.gz: f605498020d0aeec34bafecc46b026c60d686034
4
+ data.tar.gz: 404ca611835437710e7bd838f3489fa1f9fe6385
5
5
  SHA512:
6
- metadata.gz: 5e7c82107830eca10417bd2bc4c2f2e1312420fcee1852015862ab2c992939e12d282a834213b492783b1639d6472f9c1c175822b0931b7e700e05d7e2bf8104
7
- data.tar.gz: 7a54dda4b3e814ec755ea74f3fee019236579ba0343cc2339a9cdbe1d64590d312bcb6f63eee0032aa76fcbef67f98a0f4b82ca07c28b4028a91f43f748c56a9
6
+ metadata.gz: 04a4ba33724549eb5f5bb80808bf3f0b05abe669d5c474387f69dd705b73ecb4151ad81267c2f7e5be3a1402e724780483ffa6ea65c645f991a382447e8eedc2
7
+ data.tar.gz: 7ca95a00ff582c363a78afbfeae79cc60f03ddb40951af7b6ab6948abf08735be08ed9331adb04c3454da5b16058d46345bc30ccf19364bb9a9d8f53dfdfd988
@@ -11,9 +11,32 @@ module Itamae
11
11
  define_attribute :system_user, type: [TrueClass, FalseClass]
12
12
  define_attribute :uid, type: [String, Integer]
13
13
 
14
+ def set_current_attributes
15
+ @current_attributes[:exist?] = exist?
16
+
17
+ if @current_attributes[:exist?]
18
+ @current_attributes[:uid] = run_command(["id", "-u", username]).stdout.strip
19
+ @current_attributes[:gid] = run_command(["id", "-g", username]).stdout.strip
20
+ @current_attributes[:home] = run_command("echo ~#{shell_escape(username)}").stdout.strip
21
+ end
22
+ end
23
+
14
24
  def create_action
15
25
  if run_specinfra(:check_user_exists, username)
16
- Logger.warn "User already exists. Currently, user resources do not support to modify attributes."
26
+ if uid && uid.to_s != @current_attributes[:uid]
27
+ run_command(["usermod", "-u", uid, username])
28
+ updated!
29
+ end
30
+
31
+ if gid && gid.to_s != @current_attributes[:gid]
32
+ run_command(["usermod", "-g", gid, username])
33
+ updated!
34
+ end
35
+
36
+ if password && password != current_password
37
+ run_command("echo #{shell_escape("#{username}:#{password}")} | chpasswd -e")
38
+ updated!
39
+ end
17
40
  else
18
41
  args = ["useradd"]
19
42
  args << "-g" << gid if gid
@@ -23,8 +46,19 @@ module Itamae
23
46
  args << "-u" << uid.to_s if uid
24
47
  args << username
25
48
  run_command(args)
49
+
50
+ updated!
26
51
  end
27
52
  end
53
+
54
+ private
55
+ def exist?
56
+ run_specinfra(:check_user_exists, username)
57
+ end
58
+
59
+ def current_password
60
+ run_command("cat /etc/shadow | grep -E ^itamae:").stdout.split(":")[1]
61
+ end
28
62
  end
29
63
  end
30
64
  end
@@ -1 +1 @@
1
- 1.0.0.beta24
1
+ 1.0.0.beta25
@@ -1,10 +1,15 @@
1
1
  include_recipe "./included.rb"
2
2
 
3
- # TODO: replace with user resource
4
- #execute 'id itamae || useradd itamae'
3
+ user "create itamae user" do
4
+ uid 123
5
+ username "itamae"
6
+ password "$1$ltOY8bZv$iZ57f1KAp8jwKViNm3pze."
7
+ end
5
8
 
6
- user "itamae" do
9
+ user "update itamae user" do
7
10
  uid 1234
11
+ username "itamae"
12
+ password "$1$TQz9gPMl$nHYrsA5W2ZdZ0Yn021BQH1"
8
13
  end
9
14
 
10
15
  ######
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itamae
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta24
4
+ version: 1.0.0.beta25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Arai