Module: Azure::SqlDatabaseManagement::Serialization
- Defined in:
- lib/azure/sql_database_management/serialization.rb
Class Method Summary collapse
- .database_firewall_from_xml(response_xml) ⇒ Object
- .database_to_xml(login, password, location) ⇒ Object
- .databases_from_xml(databasesXML) ⇒ Object
- .firewall_rule_to_xml(options) ⇒ Object
- .reset_password_to_xml(password) ⇒ Object
- .server_name_from_xml(response_xml, login, location) ⇒ Object
Class Method Details
.database_firewall_from_xml(response_xml) ⇒ Object
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 104 105 106 107 |
# File 'lib/azure/sql_database_management/serialization.rb', line 78 def self.database_firewall_from_xml(response_xml) firewalls = [] if Azure.config.sql_database_authentication_mode == :sql_server database_firewallXML = response_xml.css('FirewallRules FirewallRule') database_firewallXML.each do |firewall_xml| firewall = { :rule => xml_content(firewall_xml, 'Name'), :start_ip_address => xml_content(firewall_xml, 'StartIpAddress'), :end_ip_address => xml_content(firewall_xml, 'EndIpAddress') } firewalls << firewall end else service_resources = response_xml.css( 'ServiceResources ServiceResource' ) service_resources.each do |resource| type = xml_content(resource, 'Type') if type == 'Microsoft.SqlAzure.FirewallRule' firewall = { rule: xml_content(resource, 'Name'), start_ip_address: xml_content(resource, 'StartIPAddress'), end_ip_address: xml_content(resource, 'EndIPAddress') } firewalls << firewall end end end firewalls.compact end |
.database_to_xml(login, password, location) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/azure/sql_database_management/serialization.rb', line 21 def self.database_to_xml(login, password, location) builder = Nokogiri::XML::Builder.new do |xml| xml.Server('xmlns'=>'http://schemas.microsoft.com/sqlazure/2010/12/') { xml.AdministratorLogin login xml.AdministratorLoginPassword password xml.Location location } end builder.doc.to_xml end |
.databases_from_xml(databasesXML) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/azure/sql_database_management/serialization.rb', line 32 def self.databases_from_xml(databasesXML) databases = [] databases_servicesXML = databasesXML.css('Servers Server') databases_servicesXML.each do |database_xml| database = SqlDatabase.new database.name = xml_content(database_xml, 'Name') database.administrator_login = xml_content(database_xml, 'AdministratorLogin') database.location = xml_content(database_xml, 'Location') database.feature_name = xml_content(database_xml, 'Features Feature Name') database.feature_value = xml_content(database_xml, 'Features Feature Value') databases << database end databases.compact end |
.firewall_rule_to_xml(options) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/azure/sql_database_management/serialization.rb', line 63 def self.firewall_rule_to_xml() # Need to revisit and implement RDFE request XML. # Currently Azure is throwing Internal Server Error when executing the # API builder = Nokogiri::XML::Builder.new do |xml| xml.FirewallRule('xmlns'=>'http://schemas.microsoft.com/sqlazure/2010/12/', 'xmlns:xsi'=>'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation'=>'http://schemas.microsoft.com/sqlazure/2010/12/ FirewallRule.xsd') { xml.StartIpAddress [:start_ip_address] xml.EndIpAddress [:end_ip_address] } end builder.doc.to_xml end |
.reset_password_to_xml(password) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/azure/sql_database_management/serialization.rb', line 56 def self.reset_password_to_xml(password) builder = Nokogiri::XML::Builder.new do |xml| xml.AdministratorLoginPassword(password, {'xmlns'=>'http://schemas.microsoft.com/sqlazure/2010/12/'}) end builder.doc.to_xml end |
.server_name_from_xml(response_xml, login, location) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/azure/sql_database_management/serialization.rb', line 47 def self.server_name_from_xml(response_xml, login, location) server_name = xml_content(response_xml, 'ServerName') SqlDatabase.new do |db| db.name = server_name db.location = location db.administrator_login = login end end |