Class: Snxvpn::Config
- Inherits:
-
Hash
- Object
- Hash
- Snxvpn::Config
- Defined in:
- lib/snxvpn/config.rb
Constant Summary collapse
- DEFAULTS =
{ 'realm' => 'ssl_vpn', 'login_type' => 'Standard', 'username' => 'anonymous', 'password' => 'secret', 'snx_path' => 'snx', 'entry_path' => '/SNX/Portal/Main', }.freeze
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(path, profile = nil) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(path, profile = nil) ⇒ Config
Returns a new instance of Config.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/snxvpn/config.rb', line 12 def initialize(path, profile = nil) stat = File.stat(path) raise ArgumentError, "#{path} is not owned by the current user" unless stat.owned? raise ArgumentError, "#{path} mode must be 600" if stat.world_readable? || stat.world_writable? raw = YAML.load_file(path) raise ArgumentError, "#{path} contains invalid config" unless raw.is_a?(Hash) update DEFAULTS if profile raise ArgumentError, "Unable to find configuration for profile '#{profile}'" unless raw.key?(profile) update raw[profile] elsif raw.size == 1 update raw.values.first else raise ArgumentError, 'No profile selected' end end |
Instance Method Details
#[](key) ⇒ Object
32 33 34 |
# File 'lib/snxvpn/config.rb', line 32 def [](key) super(key.to_s) end |