Class: BrocadeREST::VtmQuirksManager
- Inherits:
-
QuirksManager
- Object
- QuirksManager
- BrocadeREST::VtmQuirksManager
- Defined in:
- lib/brocade/vtmquirksmanager.rb
Instance Method Summary collapse
-
#hashPrivateKey(uri, json) ⇒ Object
Create a Base64 encoded SHA256 hash of the private key data for comparison with REST API Compare functions should accept a JSON string, and return a hash for comparison.
-
#initialize(restVersion) ⇒ VtmQuirksManager
constructor
A new instance of VtmQuirksManager.
-
#nodeAutoScaling(uri, json) ⇒ Object
Don’t check the nodes array if AutoScaling is in use.
-
#nodePriorities(json) ⇒ Object
Insert the node priority and weight values if they are missing.
-
#setEditableKeys(uri, json) ⇒ Object
Add expert_keys to monitor put requests so that they can be seen in the UI.
-
#stripHashValue(uri, json) ⇒ Object
we don’t want to hose the private key by overwriting it with its checksum.
Methods inherited from QuirksManager
Constructor Details
#initialize(restVersion) ⇒ VtmQuirksManager
Returns a new instance of VtmQuirksManager.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/brocade/vtmquirksmanager.rb', line 15 def initialize(restVersion) super(restVersion) @quirks = [ "ssl_server_keys", "ssl_client_keys" ] @quirkHash = {} @quirkHash["ssl_server_keys"] = { manifest: '{"properties":{"basic":{"note":"","public":"","private":"","request":""}}}', required: [{"name"=>"basic__public","example"=>""},{"name"=>"basic__private","example"=>""}], compareFunc: "hashPrivateKey", writeFunc: "stripHashValue" } @quirkHash["monitors"] = { writeFunc: "setEditableKeys" } @quirkHash["pools"] = { readFunc: "nodePriorities", compareFunc: "nodeAutoScaling" } # SSL Client and Server keys need the same additional processing @quirkHash["ssl_client_keys"] = @quirkHash["ssl_server_keys"] end |
Instance Method Details
#hashPrivateKey(uri, json) ⇒ Object
Create a Base64 encoded SHA256 hash of the private key data for comparison with REST API Compare functions should accept a JSON string, and return a hash for comparison
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/brocade/vtmquirksmanager.rb', line 38 def hashPrivateKey(uri, json) hash = JSON.parse(json) if ( ! hash["properties"]["basic"]["private"].start_with?("-----BEGIN") ) # private is not a private key, maybe we stored the hash? Do nothing. return hash end sha = Digest::SHA2.new(256) sha.update( hash["properties"]["basic"]["private"] ) hash["properties"]["basic"]["private"] = sha.base64digest() return hash end |
#nodeAutoScaling(uri, json) ⇒ Object
Don’t check the nodes array if AutoScaling is in use.
127 128 129 130 131 132 133 134 |
# File 'lib/brocade/vtmquirksmanager.rb', line 127 def nodeAutoScaling(uri, json) hash = JSON.parse(json) if hash["properties"]["dns_autoscale"]["enabled"] == true or hash["properties"]["auto_scaling"]["enabled"] == true hash["properties"]["basic"].delete("nodes_table") end return hash end |
#nodePriorities(json) ⇒ Object
Insert the node priority and weight values if they are missing.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/brocade/vtmquirksmanager.rb', line 106 def nodePriorities(json) hash = JSON.parse(json) modified = false hash["properties"]["basic"]["nodes_table"].each do |node| if (! node.include?("priority")) node["priority"] = 1 modified = true end if (! node.include?("weight")) node["weight"] = 1 modified = true end end if modified return JSON.generate(hash) else return json end end |
#setEditableKeys(uri, json) ⇒ Object
Add expert_keys to monitor put requests so that they can be seen in the UI.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/brocade/vtmquirksmanager.rb', line 63 def setEditableKeys(uri, json) # Editable keys not available prior to REST Version 3.5 (vTM 10.1) if Float(@restVersion) < 3.5 return json end # monitor types 'rtsp', 'sip', 'tcp_transaction' hash = JSON.parse(json) type = hash["properties"]["basic"]["type"] case type when "http" uri.query = "expert_keys=editable_keys,can_use_ssl" hash["properties"]["basic"]["editable_keys"] = ["authentication","body_regex","host_header","path","status_regex"] hash["properties"]["basic"]["can_use_ssl"] = true json = JSON.generate(hash) when "rtsp" uri.query = "expert_keys=editable_keys" hash["properties"]["basic"]["editable_keys"] = ["rtsp_body_regex","rtsp_path","rtsp_status_regex"] json = JSON.generate(hash) when "program" uri.query = "expert_keys=can_use_ssl" hash["properties"]["basic"]["can_use_ssl"] = true json = JSON.generate(hash) when "sip" uri.query = "expert_keys=editable_keys,can_use_ssl,can_edit_ssl" if hash["properties"]["sip"]["transport"] == "udp" hash["properties"]["basic"]["editable_keys"] = ["sip_status_regex","sip_body_regex","udp_accept_all"] else hash["properties"]["basic"]["editable_keys"] = ["sip_status_regex","sip_body_regex"] end hash["properties"]["basic"]["can_use_ssl"] = true json = JSON.generate(hash) when "tcp_transaction" uri.query = "expert_keys=editable_keys,can_use_ssl" hash["properties"]["basic"]["editable_keys"] = ["write_string","close_string","response_regex"] hash["properties"]["basic"]["can_use_ssl"] = true json = JSON.generate(hash) end return json end |
#stripHashValue(uri, json) ⇒ Object
we don’t want to hose the private key by overwriting it with its checksum
52 53 54 55 56 57 58 59 60 |
# File 'lib/brocade/vtmquirksmanager.rb', line 52 def stripHashValue(uri, json) hash = JSON.parse(json) if ( ! hash["properties"]["basic"]["private"].start_with?("-----BEGIN") ) hash["properties"]["basic"].delete("private") return JSON.generate(hash) else return json end end |