specinfra 2.0.0.beta41 → 2.0.0.beta42

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: 30b73b82ccf55b2f7047d78b079e9ae2fadbe0e7
4
- data.tar.gz: 47df260b0df6d2185fdd0513ecb1bcd8fdde4fc8
3
+ metadata.gz: 4ce10ce518d56b4792e183aaba73a154413af76b
4
+ data.tar.gz: 434a2c4affa297c0cc0e44a9a800922d7c48599c
5
5
  SHA512:
6
- metadata.gz: 1d496d2017cf292f64f487765f81e69b8a64954522d31aea4d2ab90e62e1e8903bb8b5421e0233c93097e59614d880c5c2e76e947c1173928c56040c60b5ecf0
7
- data.tar.gz: 3ee92a0a6782fccdb59ad4151a661df3fe4b059c01352b61fe03437d82b5dc387b825819c9c1ac6789bb482b2ba401ba1c39d6f47efb5e7690cb272029a57b11
6
+ metadata.gz: 9447f91943ff1390a4a947d2459c921c0ab1705f2328da3152cf0ef9757512d339f5c4080ac9144220373ead8e68d98be4ba4f2b7c6208135ca58e6238ff29f5
7
+ data.tar.gz: bacc3ae0e859cfb985845866fd7d28a4766358550d3d7f074c0397e65724e2d96883550d2f36d8f7c23505ab2d70213127ab1989b55585c5f0656284c37fda4b
@@ -129,11 +129,9 @@ class Specinfra::Command::Base::File < Specinfra::Command::Base
129
129
  def link_to(link, target)
130
130
  "ln -s #{escape(target)} #{escape(link)}"
131
131
  end
132
+
133
+ def remove(file)
134
+ "rm -rf #{escape(file)}"
135
+ end
132
136
  end
133
137
  end
134
-
135
-
136
-
137
-
138
-
139
-
@@ -29,5 +29,44 @@ class Specinfra::Command::Base::User < Specinfra::Command::Base
29
29
  key.sub!(/\s+\S*$/, '') if key.match(/^\S+\s+\S+\s+\S*$/)
30
30
  "grep -w -- #{escape(key)} ~#{escape(user)}/.ssh/authorized_keys"
31
31
  end
32
+
33
+ def get_uid(user)
34
+ "id -u #{escape(user)}"
35
+ end
36
+
37
+ def get_gid(user)
38
+ "id -g #{escape(user)}"
39
+ end
40
+
41
+ def get_home_directory(user)
42
+ "getent passwd #{escape(user)} | awk -F: '{ print $6 }'"
43
+ end
44
+
45
+ def update_uid(user, uid)
46
+ "usermod -u #{escape(uid)} #{escape(user)}"
47
+ end
48
+
49
+ def update_gid(user, gid)
50
+ "usermod -g #{escape(gid)} #{escape(user)}"
51
+ end
52
+
53
+ def add(user, options)
54
+ command = ['useradd']
55
+ command << '-g' << options[:gid] if options[:gid]
56
+ command << '-d' << options[:home_directory] if options[:home_directory]
57
+ command << '-p' << options[:password] if options[:password]
58
+ command << '-r' if options[:system_user]
59
+ command << '-u' << options[:uid] if options[:uid]
60
+ command << user
61
+ command.join(' ')
62
+ end
63
+
64
+ def update_encrypted_password(user, encrypted_password)
65
+ %Q!echo #{escape("#{user}:#{encrypted_password}")} | chpasswd -e!
66
+ end
67
+
68
+ def get_encrypted_password(user)
69
+ "getent shadow #{escape(user)} | awk -F: '{ print $2 }'"
70
+ end
32
71
  end
33
72
  end
@@ -1,3 +1,3 @@
1
1
  module Specinfra
2
- VERSION = "2.0.0.beta41"
2
+ VERSION = "2.0.0.beta42"
3
3
  end
@@ -46,4 +46,8 @@ describe 'File related commands' do
46
46
  context get_command(:link_file_to, '/link', '/target') do
47
47
  it { should eq 'ln -s /target /link' }
48
48
  end
49
+
50
+ context get_command(:remove_file, '/tmp') do
51
+ it { should eq 'rm -rf /tmp' }
52
+ end
49
53
  end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe get_command(:get_user_uid, 'foo') do
4
+ it { should eq 'id -u foo' }
5
+ end
6
+
7
+ describe get_command(:get_user_gid, 'foo') do
8
+ it { should eq 'id -g foo' }
9
+ end
10
+
11
+ describe get_command(:get_user_home_directory, 'foo') do
12
+ it { should eq "getent passwd foo | awk -F: '{ print $6 }'" }
13
+ end
14
+
15
+ describe get_command(:update_user_uid, 'foo', 100) do
16
+ it { should eq 'usermod -u 100 foo' }
17
+ end
18
+
19
+ describe get_command(:update_user_gid, 'foo', 100) do
20
+ it { should eq 'usermod -g 100 foo' }
21
+ end
22
+
23
+ describe get_command(:add_user, 'foo', :home_directory => '/home/foo') do
24
+ it { should eq 'useradd -d /home/foo foo' }
25
+ end
26
+
27
+ describe get_command(:update_user_encrypted_password, 'foo', 'xxxxxxxx') do
28
+ it { should eq 'echo foo:xxxxxxxx | chpasswd -e' }
29
+ end
30
+
31
+ describe get_command(:get_user_encrypted_password, 'foo') do
32
+ it { should eq "getent shadow foo | awk -F: '{ print $2 }'" }
33
+ end
34
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: specinfra
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta41
4
+ version: 2.0.0.beta42
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gosuke Miyashita
@@ -324,6 +324,7 @@ files:
324
324
  - spec/backend/exec/env_spec.rb
325
325
  - spec/backend/ssh/build_command_spec.rb
326
326
  - spec/command/base/file_spec.rb
327
+ - spec/command/base/user_spec.rb
327
328
  - spec/command/debian/service_spec.rb
328
329
  - spec/command/factory_spec.rb
329
330
  - spec/command/module/systemd_spec.rb
@@ -367,6 +368,7 @@ test_files:
367
368
  - spec/backend/exec/env_spec.rb
368
369
  - spec/backend/ssh/build_command_spec.rb
369
370
  - spec/command/base/file_spec.rb
371
+ - spec/command/base/user_spec.rb
370
372
  - spec/command/debian/service_spec.rb
371
373
  - spec/command/factory_spec.rb
372
374
  - spec/command/module/systemd_spec.rb