Added Guang's suggestion
1. Renamed config value disable_sql_endpoint to sql_database_authentication_mode 2. sql_database_authenticaton will accept two values :sql_server or :management_certificate 3. Renamed config valuesql_management_endpoint to sql_management_endpoint 4. Removed RDFE from comment.
This commit is contained in:
Родитель
f2f32b6562
Коммит
4f1f5e715a
16
README.md
16
README.md
|
@ -108,10 +108,10 @@ There are two ways you can set up the connections:
|
|||
config.management_certificate = "<path to your *.pem or *.pfx>"
|
||||
config.subscription_id = "<your Subscriptionid>"
|
||||
config.management_endpoint = "https://management.core.windows.net"
|
||||
# This property enables/disables SQL API RDFE endpoint. By default RDFE is enabled. RDFE will also be enabled if you do not set this property
|
||||
config.disable_sql_endpoint = true
|
||||
# Configure the non-RDFE SQL API endpoint here
|
||||
config.sql_management_endpoint = "http://management.database.windows.net:8443"
|
||||
# This property enables/disables SQL Server authentication. By default SQL Server authentication is enabled. SQL Server authentication will also be enabled if you do not set this property
|
||||
config.sql_database_authentication_mode = <:management_certificate or :sql_server>
|
||||
# Configure SQL Server authentication API endpoint here
|
||||
config.sql_database_management_endpoint = "http://management.database.windows.net:8443"
|
||||
end
|
||||
```
|
||||
* Against local Emulator (Windows Only)
|
||||
|
@ -147,11 +147,11 @@ There are two ways you can set up the connections:
|
|||
* Service Management
|
||||
|
||||
```bash
|
||||
AZURE_MANAGEMENT_CERTIFICATE = <path to *.pem or *.pfx>
|
||||
AZURE_MANAGEMENT_CERTIFICATE = <path to *.pem or *.pfx>
|
||||
AZURE_SUBSCRIPTION_ID = <your subscription ID>
|
||||
AZURE_MANAGEMENT_ENDPOINT = <The endpoint URL of Windows Azure management service>
|
||||
AZURE_SQL_MANAGEMENT_ENDPOINT = <Non-RDFE SQL Management Endpoint>
|
||||
AZURE_DISABLE_SQL_ENDPOINT = <true_or_false>
|
||||
AZURE_MANAGEMENT_ENDPOINT = <The endpoint URL of Windows Azure management service>
|
||||
AZURE_SQL_DATABASE_MANAGEMENT_ENDPOINT = <SQL Database Management Endpoint>
|
||||
AZURE_SQL_DATABASE_AUTHENTICATION_MODE = <:management_certificate or :sql_server>
|
||||
```
|
||||
* Against local Emulator (Windows Only)
|
||||
* Storage
|
||||
|
|
2
Rakefile
2
Rakefile
|
@ -118,7 +118,7 @@ namespace :test do
|
|||
# config.sb_issuer = ENV.fetch("AZURE_SERVICEBUS_ISSUER")
|
||||
config.management_certificate = ENV.fetch('AZURE_MANAGEMENT_CERTIFICATE')
|
||||
config.management_endpoint = ENV.fetch("AZURE_MANAGEMENT_ENDPOINT")
|
||||
config.sql_management_endpoint = ENV.fetch("AZURE_SQL_MANAGEMENT_ENDPOINT")
|
||||
config.sql_database_management_endpoint = ENV.fetch("AZURE_SQL_DATABASE_MANAGEMENT_ENDPOINT")
|
||||
config.subscription_id = ENV.fetch("AZURE_SUBSCRIPTION_ID")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
# an HTTP server, returning a HttpResponse
|
||||
module Azure
|
||||
module BaseManagement
|
||||
# This class is used for communicating with the non-RDFE SQL API endpoint
|
||||
# This class is used for communicating with the Management certificate authentication API endpoint
|
||||
class SqlManagementHttpRequest < ManagementHttpRequest
|
||||
attr_accessor :uri
|
||||
# Public: Creates the ManagementHttpRequest
|
||||
|
@ -28,7 +28,7 @@ module Azure
|
|||
# cert - String. The request certificate
|
||||
def initialize(method, path, body=nil)
|
||||
super(method, path, body)
|
||||
@uri = URI.parse(Azure.config.sql_management_endpoint + Azure.config.subscription_id + path)
|
||||
@uri = URI.parse(Azure.config.sql_database_management_endpoint + Azure.config.subscription_id + path)
|
||||
@key = Azure.config.http_private_key
|
||||
@cert = Azure.config.http_certificate_key
|
||||
end
|
||||
|
|
|
@ -34,7 +34,6 @@ Azure.configure do |config|
|
|||
config.management_certificate = ENV["AZURE_MANAGEMENT_CERTIFICATE"]
|
||||
config.subscription_id = ENV["AZURE_SUBSCRIPTION_ID"]
|
||||
config.management_endpoint = ENV["AZURE_MANAGEMENT_ENDPOINT"]
|
||||
config.sql_management_endpoint = ENV["AZURE_SQL_MANAGEMENT_ENDPOINT"]
|
||||
|
||||
config.disable_sql_endpoint = ENV['AZURE_DISABLE_SQL_ENDPOINT'] || 'false'
|
||||
config.sql_database_management_endpoint = ENV["AZURE_SQL_DATABASE_MANAGEMENT_ENDPOINT"]
|
||||
config.sql_database_authentication_mode = ENV["AZURE_SQL_DATABASE_AUTHENTICATION_MODE"]
|
||||
end
|
||||
|
|
|
@ -167,8 +167,8 @@ module Azure
|
|||
#Public: Set the certificate key for SSL/HTTPS request with PEM certificate
|
||||
attr_accessor :http_certificate_key
|
||||
|
||||
# Public: Set the host for SQL Management API (non-RDFE SQL Endpoint)
|
||||
attr_accessor :sql_management_endpoint
|
||||
# Public: Set the host for SQL Management API (SQL Server authentication Endpoint)
|
||||
attr_accessor :sql_database_management_endpoint
|
||||
|
||||
def management_endpoint
|
||||
if @management_endpoint.nil? or @management_endpoint.empty?
|
||||
|
@ -182,25 +182,25 @@ module Azure
|
|||
end
|
||||
end
|
||||
|
||||
def sql_management_endpoint
|
||||
if @sql_management_endpoint.nil? or @sql_management_endpoint.empty?
|
||||
def sql_database_management_endpoint
|
||||
if @sql_database_management_endpoint.nil? or @sql_database_management_endpoint.empty?
|
||||
"https://management.database.windows.net:8443/"
|
||||
elsif !@sql_management_endpoint.end_with?('/')
|
||||
@sql_management_endpoint += '/'
|
||||
elsif URI(@sql_management_endpoint).scheme.nil?
|
||||
"https://#{@sql_management_endpoint}"
|
||||
elsif !@sql_database_management_endpoint.end_with?('/')
|
||||
@sql_database_management_endpoint += '/'
|
||||
elsif URI(@sql_database_management_endpoint).scheme.nil?
|
||||
"https://#{@sql_database_management_endpoint}"
|
||||
else
|
||||
@management_endpoint
|
||||
end
|
||||
end
|
||||
|
||||
# Public: Set this true to use non-RDFE SQL API Endpoint
|
||||
attr_accessor :disable_sql_endpoint
|
||||
# Public: Set this to enable Management certificate authentication or SQL Server authentication
|
||||
attr_accessor :sql_database_authentication_mode
|
||||
|
||||
def disable_sql_endpoint
|
||||
return false if @disable_sql_endpoint.nil? or @disable_sql_endpoint.empty?
|
||||
@disable_sql_endpoint.downcase == 'true'
|
||||
def sql_database_authentication_mode
|
||||
@sql_database_authentication_mode || :sql_server
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -77,7 +77,7 @@ module Azure
|
|||
|
||||
def self.database_firewall_from_xml(response_xml)
|
||||
firewalls = []
|
||||
if Azure.config.disable_sql_endpoint
|
||||
if Azure.config.sql_database_authentication_mode == :sql_server
|
||||
database_firewallXML = response_xml.css('FirewallRules FirewallRule')
|
||||
database_firewallXML.each do |firewall_xml|
|
||||
firewall = {
|
||||
|
|
|
@ -31,15 +31,13 @@ module Azure
|
|||
# Returns an array of Azure::SqlDatabaseManagement::SqlDatabase objects
|
||||
def list_servers
|
||||
request_path = "/servers"
|
||||
|
||||
if Azure.config.disable_sql_endpoint
|
||||
if sql_endpoint?
|
||||
request = SqlManagementHttpRequest.new(:get, request_path, nil)
|
||||
request.headers["x-ms-version"] = @x_ms_version
|
||||
else
|
||||
request_path = "/services/sqlservers#{request_path}"
|
||||
request = ManagementHttpRequest.new(:get, request_path, nil)
|
||||
end
|
||||
|
||||
response = request.call
|
||||
Serialization.databases_from_xml(response)
|
||||
end
|
||||
|
@ -58,15 +56,13 @@ module Azure
|
|||
def create_server(login, password, location)
|
||||
body = Serialization.database_to_xml(login, password, location)
|
||||
request_path = "/servers"
|
||||
|
||||
if Azure.config.disable_sql_endpoint
|
||||
if sql_endpoint?
|
||||
request = SqlManagementHttpRequest.new(:post, request_path, body)
|
||||
request.headers["x-ms-version"] = @x_ms_version
|
||||
else
|
||||
request_path = "/services/sqlservers#{request_path}"
|
||||
request = ManagementHttpRequest.new(:post, request_path, body)
|
||||
end
|
||||
|
||||
response = request.call
|
||||
sql_server = Serialization.server_name_from_xml(response, login, location)
|
||||
Loggerx.info "SQL database server #{sql_server.name} is created." if sql_server
|
||||
|
@ -86,8 +82,7 @@ module Azure
|
|||
def delete_server(name)
|
||||
if get_sql_server(name)
|
||||
request_path = "/servers/#{name}"
|
||||
|
||||
if Azure.config.disable_sql_endpoint
|
||||
if sql_endpoint?
|
||||
request = SqlManagementHttpRequest.new(:delete, request_path)
|
||||
request.headers["x-ms-version"] = @x_ms_version
|
||||
else
|
||||
|
@ -113,10 +108,9 @@ module Azure
|
|||
# Returns: None
|
||||
def reset_password(name, password)
|
||||
if get_sql_server(name)
|
||||
request_path = "/servers/#{name}?op=ResetPassword"
|
||||
body = Serialization.reset_password_to_xml(password)
|
||||
|
||||
if Azure.config.disable_sql_endpoint
|
||||
request_path = "/servers/#{name}?op=ResetPassword"
|
||||
if sql_endpoint?
|
||||
request = SqlManagementHttpRequest.new(:post, request_path, body)
|
||||
request.headers["x-ms-version"] = @x_ms_version
|
||||
else
|
||||
|
@ -163,7 +157,7 @@ module Azure
|
|||
request = SqlManagementHttpRequest.new(method, request_path, body)
|
||||
request.headers["x-ms-version"] = @x_ms_version
|
||||
|
||||
# RDFE Endpoint throws errors for this operation. Need to re-visit
|
||||
# SQL Server authentication Endpoint throws errors for this operation. Need to re-visit
|
||||
# this once the Azure API is working.
|
||||
|
||||
request.call
|
||||
|
@ -184,15 +178,13 @@ module Azure
|
|||
def list_sql_server_firewall_rules(server_name)
|
||||
if get_sql_server(server_name)
|
||||
request_path = "/servers/#{server_name}/firewallrules"
|
||||
|
||||
if Azure.config.disable_sql_endpoint
|
||||
if sql_endpoint?
|
||||
request = SqlManagementHttpRequest.new(:get, request_path)
|
||||
request.headers["x-ms-version"] = @x_ms_version
|
||||
else
|
||||
request_path = "/services/sqlservers#{request_path}"
|
||||
request = ManagementHttpRequest.new(:get, request_path)
|
||||
end
|
||||
|
||||
response = request.call
|
||||
Serialization.database_firewall_from_xml(response)
|
||||
end
|
||||
|
@ -214,21 +206,23 @@ module Azure
|
|||
raise error
|
||||
elsif get_sql_server(server_name)
|
||||
request_path = "/servers/#{server_name}/firewallrules/#{rule_name}"
|
||||
|
||||
if Azure.config.disable_sql_endpoint
|
||||
if sql_endpoint?
|
||||
request = SqlManagementHttpRequest.new(:delete, request_path)
|
||||
request.headers["x-ms-version"] = @x_ms_version
|
||||
else
|
||||
request_path = "/services/sqlservers#{request_path}"
|
||||
request = ManagementHttpRequest.new(:delete, request_path)
|
||||
end
|
||||
|
||||
request.call
|
||||
Loggerx.info "Deleted server-level firewall rule #{rule_name}."
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def sql_endpoint?
|
||||
Azure.config.sql_database_authentication_mode == :sql_server
|
||||
end
|
||||
|
||||
def get_sql_server(server_name)
|
||||
if server_name.empty?
|
||||
error = Azure::Error::Error.new("DatabaseServerNotFound", 40645, "Servername cannot be empty or null.")
|
||||
|
|
|
@ -29,7 +29,6 @@ describe Azure::SqlDatabaseManagementService do
|
|||
sql_server.name.wont_be_nil
|
||||
sql_server.location.must_equal WindowsImageLocation
|
||||
sql_server.administrator_login.must_equal login_name
|
||||
|
||||
subject.delete_server sql_server.name
|
||||
end
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ describe Azure::SqlDatabaseManagementService do
|
|||
|
||||
let(:login_name) {'ms_open_tech'}
|
||||
let(:sql_server) { subject.create_server(login_name, 'User1@123', WindowsImageLocation) }
|
||||
subject { Azure::SqlDatabaseManagementService.new }
|
||||
subject { Azure::SqlDatabaseManagementService.new }
|
||||
|
||||
before {
|
||||
Loggerx.expects(:puts).returns(nil).at_least(0)
|
||||
|
|
|
@ -19,15 +19,6 @@ describe Azure::SqlDatabaseManagement::Serialization do
|
|||
|
||||
let(:sql_servers_xml) { Fixtures['list_sql_database'] }
|
||||
|
||||
before {
|
||||
@rdfe = Azure.config.disable_sql_endpoint
|
||||
Azure.config.disable_sql_endpoint = 'true'
|
||||
}
|
||||
|
||||
after {
|
||||
Azure.config.disable_sql_endpoint = "#{@rdfe}"
|
||||
}
|
||||
|
||||
describe '#databases_from_xml' do
|
||||
|
||||
it 'accepts an XML string' do
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#--------------------------------------------------------------------------
|
||||
require 'test_helper'
|
||||
|
||||
describe 'Azure::SqlDatabaseManagementService - non-RDFE Endpoint' do
|
||||
describe 'Azure::SqlDatabaseManagementService - SQL Server authentication Endpoint' do
|
||||
subject { Azure::SqlDatabaseManagementService.new }
|
||||
|
||||
let(:response_headers) { {} }
|
||||
|
@ -26,12 +26,7 @@ describe 'Azure::SqlDatabaseManagementService - non-RDFE Endpoint' do
|
|||
Loggerx.expects(:puts).returns(nil).at_least(0)
|
||||
mock_request.stubs(:headers).returns(response_headers)
|
||||
mock_request.expects(:call).returns(Nokogiri::XML response_xml).at_least(0)
|
||||
@rdfe_off = Azure.config.disable_sql_endpoint
|
||||
Azure.config.disable_sql_endpoint = 'true'
|
||||
end
|
||||
|
||||
after do
|
||||
Azure.config.disable_sql_endpoint = "#{@rdfe_off}"
|
||||
Azure.config.sql_database_authentication_mode = :sql_server
|
||||
end
|
||||
|
||||
describe '#list_servers' do
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#--------------------------------------------------------------------------
|
||||
require 'test_helper'
|
||||
|
||||
describe 'Azure::SqlDatabaseManagementService - RDFE Endpoint' do
|
||||
describe 'Azure::SqlDatabaseManagementService - Management certificate authentication Endpoint' do
|
||||
subject { Azure::SqlDatabaseManagementService.new }
|
||||
|
||||
let(:response_headers) { {} }
|
||||
|
@ -26,12 +26,7 @@ describe 'Azure::SqlDatabaseManagementService - RDFE Endpoint' do
|
|||
Loggerx.expects(:puts).returns(nil).at_least(0)
|
||||
mock_request.stubs(:headers).returns(response_headers)
|
||||
mock_request.expects(:call).returns(Nokogiri::XML response_xml).at_least(0)
|
||||
@rdfe_off = Azure.config.disable_sql_endpoint
|
||||
Azure.config.disable_sql_endpoint = nil
|
||||
end
|
||||
|
||||
after do
|
||||
Azure.config.disable_sql_endpoint = "#{@rdfe_off}"
|
||||
Azure.config.sql_database_authentication_mode = :management_certificate
|
||||
end
|
||||
|
||||
describe '#list_servers' do
|
||||
|
@ -40,11 +35,11 @@ describe 'Azure::SqlDatabaseManagementService - RDFE Endpoint' do
|
|||
let(:request_path) { '/services/sqlservers/servers' }
|
||||
|
||||
before do
|
||||
ManagementHttpRequest.stubs(:new).with(
|
||||
method,
|
||||
request_path,
|
||||
nil
|
||||
).returns(mock_request)
|
||||
ManagementHttpRequest.stubs(:new).with(
|
||||
method,
|
||||
request_path,
|
||||
nil
|
||||
).returns(mock_request)
|
||||
end
|
||||
|
||||
it 'assembles a URI for the request' do
|
||||
|
@ -71,7 +66,7 @@ describe 'Azure::SqlDatabaseManagementService - RDFE Endpoint' do
|
|||
:list_servers
|
||||
).returns([])
|
||||
end
|
||||
|
||||
|
||||
it 'error if sql server does not exists' do
|
||||
s_name = 'unknown-server'
|
||||
exception = assert_raises(Azure::Error::Error) do
|
||||
|
@ -79,17 +74,16 @@ describe 'Azure::SqlDatabaseManagementService - RDFE Endpoint' do
|
|||
end
|
||||
s_id = Azure.config.subscription_id
|
||||
assert_match(/Subscription #{s_id} does not have server #{s_name}./i,
|
||||
exception.message)
|
||||
exception.message)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe '#list_sql_server_firewall_rules' do
|
||||
let(:response_xml) { Fixtures['list_sql_server_firewall_rdfe'] }
|
||||
let(:response_xml) { Fixtures['sql_authentication_list_firewall'] }
|
||||
let(:method) { :get }
|
||||
let(:sql_server_name) { 'server1' }
|
||||
let(:request_path) { "/services/sqlservers/servers/#{sql_server_name}/firewallrules" }
|
||||
|
||||
|
||||
before do
|
||||
sql_server = Azure::SqlDatabaseManagement::SqlDatabase.new do |server|
|
||||
server.name = sql_server_name
|
||||
|
@ -97,18 +91,18 @@ describe 'Azure::SqlDatabaseManagementService - RDFE Endpoint' do
|
|||
Azure::SqlDatabaseManagementService.any_instance.stubs(
|
||||
:list_servers
|
||||
).returns([sql_server])
|
||||
|
||||
|
||||
ManagementHttpRequest.stubs(:new).with(
|
||||
method,
|
||||
request_path,
|
||||
nil
|
||||
).returns(mock_request)
|
||||
end
|
||||
|
||||
|
||||
it 'assembles a URI for the sql server firewall request' do
|
||||
subject.list_sql_server_firewall_rules sql_server_name
|
||||
end
|
||||
|
||||
|
||||
it 'returns a list of firewall of given sql servers' do
|
||||
results = subject.list_sql_server_firewall_rules sql_server_name
|
||||
results.must_be_kind_of Array
|
||||
|
@ -153,7 +147,8 @@ describe 'Azure::SqlDatabaseManagementService - RDFE Endpoint' do
|
|||
subject.set_sql_server_firewall_rule('zv2nfoah2t1', ip_range)
|
||||
end
|
||||
assert_match(/Missing parameter server_name or rule_name/i,
|
||||
exception.message)
|
||||
exception.message)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче