net-ssh-session 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -47,6 +47,7 @@ session.capture('cat /etc/lsb-release')
47
47
  # File helpers
48
48
  session.file_exists?('/path')
49
49
  session.directory_exists?('/path')
50
+ session.symlink_exists?('/path')
50
51
  session.read_file('/path')
51
52
 
52
53
  # Process helpers
@@ -1,7 +1,7 @@
1
1
  module Net
2
2
  module SSH
3
3
  class Session
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
5
5
  end
6
6
  end
7
7
  end
@@ -47,12 +47,19 @@ module Net
47
47
  end
48
48
 
49
49
  # Check if remote file exists
50
- # @param path [String] file path
50
+ # @param [String] file path
51
51
  # @return [Boolean] execution result
52
52
  def file_exists?(path)
53
53
  run("test -f #{path}").success?
54
54
  end
55
55
 
56
+ # Check if a symbilic link exists
57
+ # @param [String] file path
58
+ # @return [Boolean]
59
+ def symlink_exists?(path)
60
+ run("test -h #{path}").success?
61
+ end
62
+
56
63
  # Check if process with PID is running
57
64
  # @param pid [String] process id
58
65
  # @return [Boolean] execution result
@@ -69,6 +76,20 @@ module Net
69
76
  process_exists?(pid)
70
77
  end
71
78
 
79
+ # Check if user exists
80
+ # @param [String] username
81
+ # @return [Boolean]
82
+ def has_user?(name, options={})
83
+ run("id #{name}").success?
84
+ end
85
+
86
+ # Check if group exists
87
+ # @param [String] group name
88
+ # @return [Boolean]
89
+ def has_group?(name)
90
+ run("id -g #{name}").success?
91
+ end
92
+
72
93
  # Export an environment variable
73
94
  # @param key [String] variable name
74
95
  # @param value [String] variable value
@@ -144,4 +144,19 @@ describe Net::SSH::SessionHelpers do
144
144
  expect { session.with_timeout(2, &worker) }.not_to raise_error Timeout::Error
145
145
  end
146
146
  end
147
+
148
+ describe '#has_user?' do
149
+ before do
150
+ session.stub(:run).with('id foo').and_return(fake_run('id foo', "id: foo: No such user\n", 1))
151
+ session.stub(:run).with('id bar').and_return(fake_run('id bar', "uid=1000(bar) gid=1000(bar) groups=1000(bar)\n"))
152
+ end
153
+
154
+ it 'returns true if user exists' do
155
+ session.has_user?('foo').should be_false
156
+ end
157
+
158
+ it 'returns false if user does not exist' do
159
+ session.has_user?('bar').should be_true
160
+ end
161
+ end
147
162
  end
metadata CHANGED
@@ -1,71 +1,87 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: net-ssh-session
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
4
5
  prerelease:
5
- version: 0.1.3
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Dan Sosedoff
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2013-01-22 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2013-02-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: rake
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
24
22
  type: :development
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: rspec
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
30
33
  none: false
31
- requirements:
34
+ requirements:
32
35
  - - ~>
33
- - !ruby/object:Gem::Version
34
- version: "2.11"
36
+ - !ruby/object:Gem::Version
37
+ version: '2.11'
35
38
  type: :development
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: simplecov
39
39
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.11'
46
+ - !ruby/object:Gem::Dependency
47
+ name: simplecov
48
+ requirement: !ruby/object:Gem::Requirement
41
49
  none: false
42
- requirements:
50
+ requirements:
43
51
  - - ~>
44
- - !ruby/object:Gem::Version
45
- version: "0.4"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.4'
46
54
  type: :development
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
49
- name: net-ssh
50
55
  prerelease: false
51
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.4'
62
+ - !ruby/object:Gem::Dependency
63
+ name: net-ssh
64
+ requirement: !ruby/object:Gem::Requirement
52
65
  none: false
53
- requirements:
66
+ requirements:
54
67
  - - ~>
55
- - !ruby/object:Gem::Version
56
- version: "2.6"
68
+ - !ruby/object:Gem::Version
69
+ version: '2.6'
57
70
  type: :runtime
58
- version_requirements: *id004
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '2.6'
59
78
  description: Shell interface with helper methods to work with Net::SSH connections
60
- email:
79
+ email:
61
80
  - dan.sosedoff@gmail.com
62
81
  executables: []
63
-
64
82
  extensions: []
65
-
66
83
  extra_rdoc_files: []
67
-
68
- files:
84
+ files:
69
85
  - .gitignore
70
86
  - .rspec
71
87
  - .travis.yml
@@ -89,32 +105,29 @@ files:
89
105
  - spec/spec_helper.rb
90
106
  homepage: https://github.com/sosedoff/net-ssh-session
91
107
  licenses: []
92
-
93
108
  post_install_message:
94
109
  rdoc_options: []
95
-
96
- require_paths:
110
+ require_paths:
97
111
  - lib
98
- required_ruby_version: !ruby/object:Gem::Requirement
112
+ required_ruby_version: !ruby/object:Gem::Requirement
99
113
  none: false
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: "0"
104
- required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
119
  none: false
106
- requirements:
107
- - - ">="
108
- - !ruby/object:Gem::Version
109
- version: "0"
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
110
124
  requirements: []
111
-
112
125
  rubyforge_project:
113
126
  rubygems_version: 1.8.24
114
127
  signing_key:
115
128
  specification_version: 3
116
129
  summary: Shell session for Net::SSH connections
117
- test_files:
130
+ test_files:
118
131
  - spec/fixtures/.gitkeep
119
132
  - spec/session_command_spec.rb
120
133
  - spec/session_helpers_spec.rb