Class: Netsoul::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/netsoul/config.rb

Constant Summary collapse

AUTH_METHODS =
[:std, :krb5].freeze
USER_STATES =
[:actif, :away, :connection, :idle, :lock, :server, :none].freeze
VALID_USER_CONNECTION_INFO =
[:md5_hash, :client_ip, :client_port].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Config

Supported environment variables:

NETSOUL_SERVER_HOST: Netsoul server host, default ‘ns-server.epita.fr’ NETSOUL_SERVER_PORT: Netsoul server port, default 4242 NETSOUL_LOGIN: IONIS account name NETSOUL_SOCKS_PASSWORD: IONIS socks password NETSOUL_UNIX_PASSWORD: IONIS unix password NETSOUL_AUTH_METHOD: Authentication method, default :std. Valid options are => @see Config::AUTH_METHODS NETSOUL_STATE: User status, default is :none. Valid options are => @see Config::USER_STATES NETSOUL_LOCATION: User location is free text of your position. If you ar in IONIS network an automatic mapping is proceed to detect your location NETSOUL_USER_GROUP: Free text specifying your promo or whatever else NETSOUL_CLIENT_NAME: Redefine the client name exposed to the Netsoul server

rubocop:disable all



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/netsoul/config.rb', line 36

def initialize(opts = {})
  @server_host = ENV['NETSOUL_SERVER_HOST'] || opts.fetch(:server_host, 'ns-server.epita.fr')
  @server_port = Integer(ENV['NETSOUL_SERVER_PORT'] || opts.fetch(:server_port, 4242))
  @login = ENV['NETSOUL_LOGIN'] || opts.fetch(:login, 'ionis')
  @socks_password = ENV['NETSOUL_SOCKS_PASSWORD'] || opts.fetch(:socks_password, 'socks_password')
  @unix_password = ENV['NETSOUL_UNIX_PASSWORD'] || opts.fetch(:unix_password, 'unix_password')
  @auth_method = (ENV['NETSOUL_AUTH_METHOD'] || (AUTH_METHODS.include?(opts[:auth_method]) ? opts[:auth_method] : :std)).to_sym
  @state = (ENV['NETSOUL_STATE'] || (USER_STATES.include?(opts[:state]) ? opts[:state] : :none)).to_sym
  @location = ENV['NETSOUL_LOCATION'] || opts.fetch(:location, 'Home')
  @user_group = ENV['NETSOUL_USER_GROUP'] || opts.fetch(:user_group, 'ETNA_2008')
  @user_connection_info = {}

  @client_name = ENV['NETSOUL_CLIENT_NAME'] || opts.fetch(:client_name, "(Netsoul-Ruby v#{Netsoul::VERSION}) -> { Christian Kakesa, since 2009}")
end

Instance Attribute Details

#auth_methodObject

Returns the value of attribute auth_method.



9
10
11
# File 'lib/netsoul/config.rb', line 9

def auth_method
  @auth_method
end

#client_nameObject (readonly)

Returns the value of attribute client_name.



20
21
22
# File 'lib/netsoul/config.rb', line 20

def client_name
  @client_name
end

#locationObject

Returns the value of attribute location.



9
10
11
# File 'lib/netsoul/config.rb', line 9

def location
  @location
end

#loginObject

Returns the value of attribute login.



9
10
11
# File 'lib/netsoul/config.rb', line 9

def 
  @login
end

#server_hostObject

Returns the value of attribute server_host.



9
10
11
# File 'lib/netsoul/config.rb', line 9

def server_host
  @server_host
end

#server_portObject

Returns the value of attribute server_port.



9
10
11
# File 'lib/netsoul/config.rb', line 9

def server_port
  @server_port
end

#socks_passwordObject

Returns the value of attribute socks_password.



9
10
11
# File 'lib/netsoul/config.rb', line 9

def socks_password
  @socks_password
end

#stateObject

Returns the value of attribute state.



9
10
11
# File 'lib/netsoul/config.rb', line 9

def state
  @state
end

#unix_passwordObject

Returns the value of attribute unix_password.



9
10
11
# File 'lib/netsoul/config.rb', line 9

def unix_password
  @unix_password
end

#user_connection_infoObject

Returns the value of attribute user_connection_info.



9
10
11
# File 'lib/netsoul/config.rb', line 9

def user_connection_info
  @user_connection_info
end

#user_groupObject

Returns the value of attribute user_group.



9
10
11
# File 'lib/netsoul/config.rb', line 9

def user_group
  @user_group
end

Instance Method Details

#build_user_connection_info(opts = {}) ⇒ Object

rubocop:enable all



52
53
54
55
# File 'lib/netsoul/config.rb', line 52

def build_user_connection_info(opts = {})
  return unless opts.is_a?(Hash)
  opts.each { |k, v| @user_connection_info[k] = v if VALID_USER_CONNECTION_INFO.include?(k) }
end