stuartpreston-azure-sdk-for-ruby 0.6.7 → 0.6.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 79011371187700f252d099c2dba1361b7f578111
4
- data.tar.gz: 46bcd38a6c7e472619b6d901e521439ae8a2268e
3
+ metadata.gz: 74ffefba6eece817b30916acf39b2bf18cc2170e
4
+ data.tar.gz: cdebe9e5766d715c901f05b26e611a219e365182
5
5
  SHA512:
6
- metadata.gz: 87a9c90eb7bc23b5b233472cb707c4feab18fdfff8e57dd2cbbed83f385e49b53ae1bd825b2a006d46e0dafc2a40da053df51544c484ac054520ff781c0a8b80
7
- data.tar.gz: cec3895e035c7313890b8cde60bcf55cc09cc7e564a20d09b5259ab6e349d66805c6697a0403eac29461bd9d6446c6d3dab63f4769df2770b401b61e105b51c2
6
+ metadata.gz: 52e659246d3574a55b42fa5e221530578f2f03ffb6ace5dd3760fabf1609a7fedac5c92f3b436d7ae0eb0835ef4d5aee03fb503ce2d9133b1703d0c436e1eade
7
+ data.tar.gz: de1968be02983c26defdfd3341765b4155d09282a6e6352a24133e26d640d0423e538aeb1d0ee3acf7eb80d9314b21b669f3316d478de96cd9549dfdfed558b2
data/ChangeLog.txt CHANGED
@@ -1,3 +1,9 @@
1
+ 2014.03.30 - version 0.6.9 (stuartpreston-azure-sdk-for-ruby)
2
+ * Implement fixes for regression issues with filename handling
3
+
4
+ 2014.03.29 - version 0.6.8 (stuartpreston-azure-sdk-for-ruby)
5
+ * Support for accepting certificates in memory (@jkeiser)
6
+
1
7
  2014.03.12 - version 0.6.7 (stuartpreston-azure-sdk-for-ruby)
2
8
  * Support for .pfx and .publishsettings as certificate sources
3
9
 
data/README.md CHANGED
@@ -1,10 +1,15 @@
1
- # Microsoft Azure SDK for Ruby
2
- ## Fork taken February 2015 as no official release since May 2014.
1
+ # Microsoft Azure SDK for Ruby (gem: stuartpreston-azure-sdk-for-ruby)
2
+ This is a fork of the 'official' Azure SDK for Ruby which was taken in February 2015 due to there being no official releases since May 2014.
3
+
3
4
  [![Build Status](https://travis-ci.org/stuartpreston/azure-sdk-for-ruby.png?branch=master)](https://travis-ci.org/stuartpreston/azure-sdk-for-ruby)
4
5
 
6
+ Please view the [changelog](changelog.txt) for an up to date list of what is supported.
5
7
 
8
+ ###
6
9
  This project provides a Ruby package that makes it easy to access and manage Microsoft Azure Services like Storage, Service Bus and Virtual Machines.
7
10
 
11
+ This package accesses the Microsoft Azure Service Management API, and ***not*** the Microsoft Azure Resource Management API.
12
+
8
13
  # Library Features
9
14
  * Storage
10
15
  * Blobs
@@ -51,11 +56,8 @@ This project provides a Ruby package that makes it easy to access and manage Mic
51
56
 
52
57
  # Supported Ruby Versions
53
58
 
54
- * Ruby 1.9.3
55
59
  * Ruby 2.0
56
60
 
57
- **Notice** that Ruby 2.0 x64 on Windows is not supported due to the [lack of nokogiri](https://github.com/sparklemotion/nokogiri/issues/864).
58
-
59
61
  # Getting Started
60
62
 
61
63
  ## Install the rubygem package
@@ -71,7 +73,7 @@ gem install azure
71
73
  To get the source code of the SDK via **git** just type:
72
74
 
73
75
  ```bash
74
- git clone https://github.com/Azure/azure-sdk-for-ruby.git
76
+ git clone https://github.com/stuartpreston/azure-sdk-for-ruby.git
75
77
  cd ./azure-sdk-for-ruby
76
78
  ```
77
79
  Then, run bundler to install all the gem dependencies:
@@ -519,7 +521,7 @@ base_management_service.get_affinity_group('affinity-group-name')
519
521
  require 'azure'
520
522
 
521
523
  Azure.configure do |config|
522
- config.management_certificate = "path to *.pem or *.pfx file"
524
+ config.management_certificate = "path to .pem, .pfx or .publishsettings file"
523
525
  config.subscription_id = "your subscription id"
524
526
  config.management_endpoint = "https://management.database.windows.net:8443/"
525
527
  #To access other service management apis use "https://management.core.windows.net".
@@ -589,7 +591,7 @@ vnet.set_network_configuration(vnetxml)
589
591
 
590
592
  # Useful commands for certificate operations
591
593
 
592
- Currently the sdk supports *.pem or *.pfx (passwordless pfx) for service management operations. Following are the steps discussed on various cert operations.
594
+ Currently the sdk supports .pem, .pfx or .publishsettings for service management operations. Following are the steps discussed on various cert operations.
593
595
 
594
596
  * To create pfx, simply download the publishsettings file for your subscription, copy the contents of Management Certificate from the publishsettings and save it in a file and name the file as your cert.pfx. This pfx will be a passwordless pfx which can be supplied as a cert parameter for Service Management Commands
595
597
  * Using the following openssl commands to extract the pem file and pass the pem file as management cert parameter.
@@ -607,7 +609,7 @@ Be sure to check out the Microsoft Azure [Developer Forums on Stack Overflow and
607
609
  # Contribute Code or Provide Feedback
608
610
 
609
611
  If you would like to become an active contributor to this project please follow the instructions provided in [Microsoft Azure Projects Contribution Guidelines](http://windowsazure.github.com/guidelines.html).
610
- If you encounter any bugs with the library please file an issue in the [Issues](https://github.com/Azure/azure-sdk-for-ruby/issues) section of the project.
612
+ If you encounter any bugs with the library please file an issue in the [Issues](https://github.com/stuartpreston/azure-sdk-for-ruby/issues) section of the project.
611
613
 
612
614
  # Learn More
613
615
 
@@ -31,38 +31,7 @@ module Azure
31
31
  class BaseManagementService
32
32
  def initialize
33
33
  validate_configuration
34
- cert_file = nil
35
- begin
36
- if Azure.config.management_certificate =~ /(pem)$/
37
- cert_file = File.read(Azure.config.management_certificate)
38
- certificate_key = OpenSSL::X509::Certificate.new(cert_file)
39
- private_key = OpenSSL::PKey::RSA.new(cert_file)
40
- elsif Azure.config.management_certificate =~ /(pfx)$/
41
- # Parse pfx content
42
- File.open(Azure.config.management_certificate, "rb") do |f|
43
- cert_file = f.read
44
- end
45
- cert_content = OpenSSL::PKCS12.new(Base64.decode64(cert_file))
46
- certificate_key = OpenSSL::X509::Certificate.new(
47
- cert_content.certificate.to_pem
48
- )
49
- private_key = OpenSSL::PKey::RSA.new(cert_content.key.to_pem)
50
- elsif Azure.config.management_certificate =~ /(publishsettings)$/
51
- # Parse publishsettings content
52
- publish_settings = Nokogiri::XML(File.open(Azure.config.management_certificate, "r"))
53
- subscription_id = Azure.config.subscription_id
54
- xpath = "//PublishData/PublishProfile/Subscription[@Id='#{subscription_id}']/@ManagementCertificate"
55
- cert_file = publish_settings.xpath(xpath).text
56
- cert_content = OpenSSL::PKCS12.new(Base64.decode64(cert_file))
57
- certificate_key = OpenSSL::X509::Certificate.new(
58
- cert_content.certificate.to_pem
59
- )
60
- private_key = OpenSSL::PKey::RSA.new(cert_content.key.to_pem)
61
- end
62
- rescue Exception => e
63
- raise "Management certificate not valid. Error: #{e.message}"
64
- end
65
-
34
+ certificate_key, private_key = read_management_certificate(Azure.config.management_certificate)
66
35
  Azure.configure do |config|
67
36
  config.http_certificate_key = certificate_key
68
37
  config.http_private_key = private_key
@@ -79,12 +48,43 @@ module Azure
79
48
  raise error_message if m_ep.nil? || m_ep.empty?
80
49
 
81
50
  m_cert = Azure.config.management_certificate
82
- error_message = "Could not read from file '#{m_cert}'."
83
- raise error_message unless test('r', m_cert)
51
+ if m_cert.is_a?(Hash)
52
+ error_message = "Management certificate hash #{m_cert} does not have key :type! If specifying a hash, you must specify :type => <:pem, :pfx or :publishsettings>!"
53
+ raise error_message unless m_cert.has_key?(:type) && %w(pem pfx publishsettings).include?(m_cert[:type].to_s)
54
+
55
+ error_message = "Management certificate hash #{m_cert} does not have the certificate data! If specifying a hash, you must specify either :data => String, :io => <IO object> or :path => <path>!"
56
+ raise error_message unless [ :data, :io, :path ].any? { |k| m_cert.has_key?(k) }
57
+
58
+ unexpected_keys = m_cert.keys - [ :type, :data, :io, :path ]
59
+ error_message = "Management certificate hash #{m_cert} has unexpected keys #{unexpected_keys.join(", ")}! Only :type, :data, :io and :path are accepted values when specifying a hash."
60
+ raise error_message unless unexpected_keys.empty?
61
+
62
+ if m_cert[:data]
63
+ error_message= "Management certificate :data in #{m_cert} is not a String! Must be a String."
64
+ raise error_message unless m_cert[:data].is_a?(String)
65
+ end
66
+ if m_cert[:io]
67
+ error_message= "Management certificate :io in #{m_cert} is not an IO object! Must be an IO object."
68
+ raise error_message unless m_cert[:io].is_a?(IO)
69
+ end
70
+ if m_cert[:path]
71
+ error_message= "Management certificate :path in #{m_cert} is not a String! Must be a String."
72
+ raise error_message unless m_cert[:path].is_a?(String)
73
+ unless m_cert[:data] || m_cert[:io] # :path is only used to print information out if data or IO is there
74
+ error_message = "Could not read from file '#{m_cert[:path]}'."
75
+ raise error_message unless test('r', m_cert[:data])
76
+ end
77
+ end
78
+
79
+ else
80
+ m_cert_ext = File.extname(m_cert)
81
+ error_message = "Management certificate path '#{m_cert}' must have extension .pem, .pfx or .publishsettings"
82
+ raise error_message unless %w(.pem .pfx .publishsettings).include?(m_cert_ext)
83
+
84
+ error_message = "Could not read from file '#{m_cert}'."
85
+ raise error_message unless test('r', m_cert)
86
+ end
84
87
 
85
- m_cert = Azure.config.management_certificate
86
- error_message = 'Management certificate expects a .pem, .pfx or .publishsettings file.'
87
- raise error_message unless m_cert =~ /(pem|pfx|publishsettings)$/
88
88
  end
89
89
 
90
90
  # Public: Gets a list of regional data center locations from the server
@@ -244,6 +244,61 @@ module Azure
244
244
  raise error
245
245
  end
246
246
  end
247
+
248
+ def read_management_certificate(cert)
249
+ cert_file = nil
250
+ begin
251
+ # If it's a String, the type is the extension (.pem, .pfx, .publishsettings)
252
+ if cert.is_a?(String)
253
+ cert = {
254
+ type: File.extname(cert).split('.').last,
255
+ path: cert
256
+ }
257
+ end
258
+
259
+ case cert[:type].to_sym
260
+ when :pem
261
+ read_pem(cert)
262
+ when :pfx
263
+ read_pfx(cert)
264
+ when :publishsettings
265
+ read_publishsettings(cert)
266
+ else
267
+ raise ArgumentError, "Unknown type #{type} on Azure.config.management_certificate #{cert}"
268
+ end
269
+ end
270
+ end
271
+
272
+ def read_pem(cert)
273
+ cert[:data] ||= cert[:io] ? cert[:io].read : File.open(cert[:path], "r") { |f| f.read }
274
+
275
+ certificate_key = OpenSSL::X509::Certificate.new(cert[:data])
276
+ private_key = OpenSSL::PKey::RSA.new(cert[:data])
277
+ [ certificate_key, private_key ]
278
+ end
279
+
280
+ def read_pfx(cert)
281
+ cert[:data] ||= cert[:io] ? cert[:io].read : File.open(cert[:path], "rb") { |f| f.read }
282
+
283
+ cert_content = OpenSSL::PKCS12.new(Base64.decode64(cert[:data]))
284
+ certificate_key = OpenSSL::X509::Certificate.new(
285
+ cert_content.certificate.to_pem
286
+ )
287
+ private_key = OpenSSL::PKey::RSA.new(cert_content.key.to_pem)
288
+ [ certificate_key, private_key ]
289
+ end
290
+
291
+ def read_publishsettings(cert)
292
+ cert[:io] ||= cert[:data] ? StringIO.new(cert[:data]) : File.open(cert[:path], "r")
293
+
294
+ # Parse publishsettings content
295
+ publish_settings = Nokogiri::XML(cert[:io])
296
+ subscription_id = Azure.config.subscription_id
297
+ xpath = "//PublishData/PublishProfile/Subscription[@Id='#{subscription_id}']/@ManagementCertificate"
298
+ cert_file = publish_settings.xpath(xpath).text
299
+
300
+ read_pfx(data: cert_file, path: cert[:path])
301
+ end
247
302
  end
248
303
  end
249
- end
304
+ end
data/lib/azure/version.rb CHANGED
@@ -17,7 +17,7 @@ module Azure
17
17
  class Version
18
18
  MAJOR = 0 unless defined? MAJOR
19
19
  MINOR = 6 unless defined? MINOR
20
- UPDATE = 7 unless defined? UPDATE
20
+ UPDATE = 9 unless defined? UPDATE
21
21
  PRE = nil unless defined? PRE
22
22
 
23
23
  class << self
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stuartpreston-azure-sdk-for-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.7
4
+ version: 0.6.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Microsoft Corporation
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-03-12 00:00:00.000000000 Z
13
+ date: 2015-03-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri