Class: DInstaller::Users

Inherits:
Object
  • Object
show all
Defined in:
lib/dinstaller/users.rb

Overview

Backend class using YaST code.

DBus::Users wraps it with a D-Bus interface and DBus::Clients::Users is a D-Bus client for that.

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ Users

Returns a new instance of Users.



33
34
35
# File 'lib/dinstaller/users.rb', line 33

def initialize(logger)
  @logger = logger
end

Instance Method Details

#assign_first_user(full_name, user_name, password, auto_login, _data) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# File 'lib/dinstaller/users.rb', line 73

def assign_first_user(full_name, user_name, password, , _data)
  remove_first_user

  user = Y2Users::User.new(user_name)
  user.gecos = [full_name]
  user.password = Y2Users::Password.create_plain(password)
  config.attach(user)
  config. ||= Y2Users::LoginConfig.new
  config..autologin_user =  ? user : nil
end

#assign_root_password(value, encrypted) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/dinstaller/users.rb', line 49

def assign_root_password(value, encrypted)
  pwd = if encrypted
    Y2Users::Password.create_encrypted(value)
  else
    Y2Users::Password.create_plain(value)
  end

  root_user.password = value.empty? ? nil : pwd
end

#first_userObject



59
60
61
62
63
64
65
66
# File 'lib/dinstaller/users.rb', line 59

def first_user
  user = config.users.reject(&:root?).first

  return ["", "", false, {}] unless user

  # TODO: not sure if backend should return structure of dbus?
  [user.full_name, user.name, config..autologin_user == user, {}]
end

#remove_first_userObject

Removes the first user



85
86
87
88
# File 'lib/dinstaller/users.rb', line 85

def remove_first_user
  old_users = config.users.reject(&:root?)
  config.detach(old_users) unless old_users.empty?
end

#remove_root_passwordObject

Clears the root password



69
70
71
# File 'lib/dinstaller/users.rb', line 69

def remove_root_password
  root_user.password = nil
end

#root_password?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/dinstaller/users.rb', line 45

def root_password?
  !!root_user.password_content
end

#root_ssh_keyObject



37
38
39
# File 'lib/dinstaller/users.rb', line 37

def root_ssh_key
  root_user.authorized_keys.first || ""
end

#root_ssh_key=(value) ⇒ Object



41
42
43
# File 'lib/dinstaller/users.rb', line 41

def root_ssh_key=(value)
  root_user.authorized_keys = [value] # just one supported for now
end

#writeObject



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/dinstaller/users.rb', line 90

def write
  without_run_mount do
    on_target do
      system_config = Y2Users::ConfigManager.instance.system(force_read: true)
      target_config = system_config.copy
      Y2Users::ConfigMerger.new(target_config, config).merge

      writer = Y2Users::Linux::Writer.new(target_config, system_config)
      issues = writer.write
      logger.error(issues.inspect) unless issues.empty?
    end
  end
end