Class: Vagrant::PowerDNS::Config
- Inherits:
-
Object
- Object
- Vagrant::PowerDNS::Config
- Defined in:
- lib/vagrant-powerdns/config.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_url ⇒ Object
Returns the value of attribute api_url.
-
#default_zone ⇒ Object
Returns the value of attribute default_zone.
-
#disable ⇒ Object
Returns the value of attribute disable.
Instance Method Summary collapse
- #enabled? ⇒ Boolean
- #finalize! ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #validate(machine) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
10 11 12 13 14 15 |
# File 'lib/vagrant-powerdns/config.rb', line 10 def initialize @api_url = UNSET_VALUE @api_key = UNSET_VALUE @default_zone = UNSET_VALUE @disable = UNSET_VALUE end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
6 7 8 |
# File 'lib/vagrant-powerdns/config.rb', line 6 def api_key @api_key end |
#api_url ⇒ Object
Returns the value of attribute api_url.
5 6 7 |
# File 'lib/vagrant-powerdns/config.rb', line 5 def api_url @api_url end |
#default_zone ⇒ Object
Returns the value of attribute default_zone.
7 8 9 |
# File 'lib/vagrant-powerdns/config.rb', line 7 def default_zone @default_zone end |
#disable ⇒ Object
Returns the value of attribute disable.
8 9 10 |
# File 'lib/vagrant-powerdns/config.rb', line 8 def disable @disable end |
Instance Method Details
#enabled? ⇒ Boolean
33 34 35 |
# File 'lib/vagrant-powerdns/config.rb', line 33 def enabled? @api_url.is_a?(String) and @api_key.is_a?(String) and @default_zone.is_a?(Zone) end |
#finalize! ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/vagrant-powerdns/config.rb', line 17 def finalize! if @default_zone == UNSET_VALUE @default_zone = nil elsif @default_zone.nil? # Completely disable if no default zone @disable = true elsif !@default_zone.is_a?(Zone) @default_zone = Zone.new @default_zone; end @api_url = nil if @api_url == UNSET_VALUE @api_key = nil if @api_key == UNSET_VALUE @disable = false if @disable == UNSET_VALUE end |
#validate(machine) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/vagrant-powerdns/config.rb', line 37 def validate(machine) if enabled? #return if not @api_url.nil? and not @api_key.nil? and not @default_zone.nil? errors = [] # verify @disable if @disable != true and @disable != false then errors << 'invalid disable setting' end # verify zone begin @default_zone = Zone.new @default_zone; rescue => e; errors << e. end # verify api_url begin @api_url = String.new @api_url; rescue => e; errors << "powerdns.api_url: Invalid URL. It should be like `http://ns.example.com:8081'" end # verify api_key begin @api_key = String.new @api_key; rescue => e; errors << "powerdns.api_key: Invalid API Key. It should be like `api_key_of_powerdns'" end # verify zone #begin @default_zone = Zone.new @default_zone; rescue => e; errors << "config.powerdns.default_zone: Invalid Zone #{@default_zone}. It should be like: `dev.example.com'" end return { 'PowerDNS configuration' => errors } end end |