Sha256: 717273271518c8d35d92e495c5f95fd43f166b7c5401ae593c0507b604a8f827

Contents?: true

Size: 753 Bytes

Versions: 154

Compression:

Stored size: 753 Bytes

Contents

module Unix::User
  include Beaker::CommandFactory

  def user_list(&block)
    execute("getent passwd") do |result|
      users = []
      result.stdout.each_line do |line|
        users << (line.match( /^([^:]+)/) or next)[1]
      end

      yield result if block_given?

      users
    end
  end

  def user_get(name, &block)
    execute("getent passwd #{name}") do |result|
      fail_test "failed to get user #{name}" unless result.stdout =~  /^#{name}:/

      yield result if block_given?
    end
  end

  def user_present(name, &block)
    execute("if ! getent passwd #{name}; then useradd #{name}; fi", {}, &block)
  end

  def user_absent(name, &block)
    execute("if getent passwd #{name}; then userdel #{name}; fi", {}, &block)
  end
end

Version data entries

154 entries across 154 versions & 1 rubygems

Version Path
beaker-3.37.0 lib/beaker/host/unix/user.rb
beaker-3.36.0 lib/beaker/host/unix/user.rb
beaker-3.35.0 lib/beaker/host/unix/user.rb
beaker-3.34.0 lib/beaker/host/unix/user.rb
beaker-3.33.0 lib/beaker/host/unix/user.rb
beaker-3.32.0 lib/beaker/host/unix/user.rb
beaker-3.31.0 lib/beaker/host/unix/user.rb
beaker-3.30.0 lib/beaker/host/unix/user.rb
beaker-3.29.0 lib/beaker/host/unix/user.rb
beaker-3.28.0 lib/beaker/host/unix/user.rb
beaker-3.27.0 lib/beaker/host/unix/user.rb
beaker-3.26.0 lib/beaker/host/unix/user.rb
beaker-3.25.0 lib/beaker/host/unix/user.rb
beaker-3.24.0 lib/beaker/host/unix/user.rb
beaker-3.23.0 lib/beaker/host/unix/user.rb
beaker-3.22.0 lib/beaker/host/unix/user.rb
beaker-3.21.1 lib/beaker/host/unix/user.rb
beaker-3.21.0 lib/beaker/host/unix/user.rb
beaker-3.20.0 lib/beaker/host/unix/user.rb
beaker-3.19.0 lib/beaker/host/unix/user.rb