diff --git a/README.rdoc b/README.rdoc index 74e7154..e603b10 100644 --- a/README.rdoc +++ b/README.rdoc @@ -19,14 +19,14 @@ OR The management certificate is required for secure communication with the Windows Azure Platform via the REST APIs. These can be obtained from the publishsettings file. You need to download the .publishsettings file from the link given below. You can either provide the path to the .publishsettings file OR you can generate the management certificate yourself from the .publishsettings file. ===Management Certificate using the .publishsettings file -Download the .publishsettings file from http://go.microsoft.com/fwlink/?LinkId=254432 +Download the .publishsettings file from https://manage.windowsazure.com/publishsettings/index?client=xplat Set the option :azure_publish_settings_file by specifying the path to the downloaded .publishsettings file. The plugin provides this easy option and will save you the complexity of the second approach listed next. ===Management Certificate in the PEM format Follow these steps to generate the certificate in the PEM format -1. Download the settings file from http://go.microsoft.com/fwlink/?LinkId=254432 +1. Download the settings file from https://manage.windowsazure.com/publishsettings/index?client=xplat 2. Extract the data from the ManagementCertificate field into a separate file named - cert.pfx 3. Decode the certificate file : diff --git a/azureValidSchemaVersion-2.0.publishsettings b/azureValidSchemaVersion-2.0.publishsettings new file mode 100644 index 0000000..8815b9f --- /dev/null +++ b/azureValidSchemaVersion-2.0.publishsettings @@ -0,0 +1,12 @@ + + + + + + diff --git a/lib/chef/knife/azure_base.rb b/lib/chef/knife/azure_base.rb index 5ebb510..5889b42 100755 --- a/lib/chef/knife/azure_base.rb +++ b/lib/chef/knife/azure_base.rb @@ -125,9 +125,18 @@ class Chef begin doc = Nokogiri::XML(File.open(find_file(filename))) profile = doc.at_css("PublishProfile") - management_cert = OpenSSL::PKCS12.new(Base64.decode64(profile.attribute("ManagementCertificate").value)) + subscription = profile.at_css("Subscription") + #check given PublishSettings XML file format.Currently PublishSettings file have two different XML format + if profile.attribute("SchemaVersion").nil? + management_cert = OpenSSL::PKCS12.new(Base64.decode64(profile.attribute("ManagementCertificate").value)) + Chef::Config[:knife][:azure_api_host_name] = URI(profile.attribute("Url").value).host + elsif profile.attribute("SchemaVersion").value == "2.0" + management_cert = OpenSSL::PKCS12.new(Base64.decode64(subscription.attribute("ManagementCertificate").value)) + Chef::Config[:knife][:azure_api_host_name] = URI(subscription.attribute("ServiceManagementUrl").value).host + else + ui.error("Publish settings file Schema not supported - " + filename) + end Chef::Config[:knife][:azure_mgmt_cert] = management_cert.certificate.to_pem + management_cert.key.to_pem - Chef::Config[:knife][:azure_api_host_name] = URI(profile.attribute("Url").value).host Chef::Config[:knife][:azure_subscription_id] = doc.at_css("Subscription").attribute("Id").value rescue ui.error("Incorrect publish settings file - " + filename) diff --git a/spec/unit/azure_base_spec.rb b/spec/unit/azure_base_spec.rb index 46c4372..a62ff5b 100644 --- a/spec/unit/azure_base_spec.rb +++ b/spec/unit/azure_base_spec.rb @@ -55,6 +55,13 @@ describe Chef::Knife::AzureBase do validate_cert() end + it "- should validate parse method for SchemaVersion2-0 publishsettings file" do + @dummy.parse_publish_settings_file("azureValidSchemaVersion-2.0.publishsettings") + Chef::Config[:knife][:azure_api_host_name].should == 'management.core.windows.net' + Chef::Config[:knife][:azure_subscription_id].should == 'id1' + validate_cert() + end + it "- should validate settings file and subscrition id" do @dummy.config[:azure_subscription_id] = "azure_subscription_id" Chef::Config[:knife][:azure_publish_settings_file] = "azureValid.publishsettings"