Module: Kelbim::PolicyTypes
- Defined in:
- lib/kelbim/policy-types.rb
Constant Summary collapse
- POLICIES =
{ :ssl_negotiation => 'SSLNegotiationPolicyType', :app_cookie_stickiness => 'AppCookieStickinessPolicyType', :lb_cookie_stickiness => 'LBCookieStickinessPolicyType', #:proxy_protocol => 'ProxyProtocolPolicyType', #:backend_server_authentication => 'BackendServerAuthenticationPolicyType', #:public_key => 'PublicKeyPolicyType', }
- EXPANDERS =
{ :ssl_negotiation => proc {|attrs| if attrs.key?('Reference-Security-Policy') { reference: attrs['Reference-Security-Policy'] } else attrs.select {|name, value| value[0] =~ /\Atrue\Z/i }.map {|n, v| n } end }, :app_cookie_stickiness => proc {|attrs| h = {}; attrs.map {|k, v| h[k] = [v].flatten[0] }; h }, :lb_cookie_stickiness => proc {|attrs| h = {}; attrs.map {|k, v| h[k] = [v].flatten[0] }; h }, }
- UNEXPANDERS =
{ :ssl_negotiation => proc {|attrs| if attrs.kind_of?(Hash) if attrs.key?(:reference) reference = attrs[:reference].is_a?(Array) ? attrs[:reference] : [attrs[:reference]] { 'Reference-Security-Policy' => reference } end else = {} attrs.each do |name| [name] = ['true'] end end }, :app_cookie_stickiness => proc {|attrs| h = {}; attrs.map {|k, v| h[k] = [v].flatten }; h }, :lb_cookie_stickiness => proc {|attrs| h = {}; attrs.map {|k, v| h[k] = [v].flatten }; h }, }
Class Method Summary collapse
- .convert_to_dsl(policy) ⇒ Object
- .expand(sym_or_str, policy_attrs) ⇒ Object
- .name?(name_or_attrs) ⇒ Boolean
- .string_to_symbol(str) ⇒ Object
- .symbol_to_string(sym) ⇒ Object
- .unexpand(sym_or_str, expanded_attrs) ⇒ Object
Class Method Details
.convert_to_dsl(policy) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/kelbim/policy-types.rb', line 60 def convert_to_dsl(policy) policy_name = policy[:name] policy_type = policy[:type] policy_attrs = policy[:attributes] sym = string_to_symbol(policy_type) if ( = EXPANDERS[sym]) policy_attrs = .call(policy_attrs) if policy_attrs.kind_of?(Hash) new_policy_attrs = {} policy_attrs.each do |name, value| value = value[0] if value.length < 2 new_policy_attrs[name] = value end args = new_policy_attrs.inspect.gsub(/\A\s*\{/, '').gsub(/\}\s*\Z/, '') else args = policy_attrs.inspect end else args = policy_name.inspect end "#{sym} #{args}" end |
.expand(sym_or_str, policy_attrs) ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/kelbim/policy-types.rb', line 92 def (sym_or_str, policy_attrs) if sym_or_str.kind_of?(String) sym_or_str = string_to_symbol(sym_or_str) end = EXPANDERS[sym_or_str] ? .call(policy_attrs) : policy_attrs end |
.name?(name_or_attrs) ⇒ Boolean
88 89 90 |
# File 'lib/kelbim/policy-types.rb', line 88 def name?(name_or_attrs) name_or_attrs.kind_of?(String) end |
.string_to_symbol(str) ⇒ Object
54 55 56 57 58 |
# File 'lib/kelbim/policy-types.rb', line 54 def string_to_symbol(str) sym = POLICIES.key(str) raise "PolicyTypes `#{str}` is not supported" unless sym return sym end |
.symbol_to_string(sym) ⇒ Object
48 49 50 51 52 |
# File 'lib/kelbim/policy-types.rb', line 48 def symbol_to_string(sym) str = POLICIES[sym] raise "PolicyTypes `#{sym}` is not supported" unless str return str end |
.unexpand(sym_or_str, expanded_attrs) ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'lib/kelbim/policy-types.rb', line 101 def (sym_or_str, ) if sym_or_str.kind_of?(String) sym_or_str = string_to_symbol(sym_or_str) end = UNEXPANDERS[sym_or_str] ? .call() : end |