Class: Frontend
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Frontend
- Defined in:
- lib/mkit/app/model/frontend.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.create(yaml) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mkit/app/model/frontend.rb', line 10 def self.create(yaml) validate(yaml) frontend = Frontend.new frontend.name = yaml["name"] frontend.port = yaml["bind"]["port"] if yaml["bind"]["port"] frontend.mode = yaml["bind"]["mode"] if yaml["bind"]["mode"] frontend. = yaml["bind"]["options"] if yaml["bind"]["options"] frontend. = yaml["options"] if yaml["options"] frontend.default_backend = yaml["default_backend"] has_ssl = !yaml["bind"]["ssl"].nil? && yaml["bind"]["ssl"].to_s.start_with?('true') frontend.ssl = has_ssl ? 'true' : 'false' if has_ssl frontend.crt = yaml["bind"]["cert"].nil? ? MKIt::Utils.proxy_cert : yaml["bind"]["cert"] end frontend end |
.validate(yaml) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/mkit/app/model/frontend.rb', line 30 def self.validate(yaml) raise_bad_configuration "name is mandatory" unless yaml["name"] raise_bad_configuration "default_backend is mandatory" unless yaml["default_backend"] raise_bad_configuration "bind is mandatory" unless yaml["bind"] raise_bad_configuration "mode is mandatory" unless yaml["bind"]["mode"] raise_bad_configuration "frontend port is mandatory" unless yaml["bind"]["port"] raise_bad_configuration "mode must match tcp|http" unless yaml["bind"]["mode"] =~ /^(tcp|http)$/ end |
Instance Method Details
#ssl? ⇒ Boolean
39 40 41 |
# File 'lib/mkit/app/model/frontend.rb', line 39 def ssl? self.ssl == 'true' end |
#to_h(options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/mkit/app/model/frontend.rb', line 43 def to_h( = {}) hash = { name: self.name, options: self., bind: { port: self.port, mode: self.mode, ssl: self.ssl, cert: self.ssl? ? self.crt : nil, options: self. }, default_backend: self.default_backend } unless self.ssl? hash[:bind].delete(:ssl) hash[:bind].delete(:cert) end hash.remove_symbols_from_keys end |