azure 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/Gemfile.lock +36 -0
- data/README.md +3 -0
- data/Rakefile +81 -0
- data/azure.gemspec +20 -9
- data/lib/azure.rb +4 -0
- data/lib/azure/atom.rb +170 -0
- data/lib/azure/auth.rb +29 -0
- data/lib/azure/blobs.rb +620 -0
- data/lib/azure/blobs/blob.rb +360 -0
- data/lib/azure/blobs/container.rb +209 -0
- data/lib/azure/blobs/service.rb +396 -0
- data/lib/azure/blobs/shared_access_signature.rb +84 -0
- data/lib/azure/blobs/uri.rb +60 -0
- data/lib/azure/configuration.rb +121 -0
- data/lib/azure/core/auth/shared_key.rb +95 -0
- data/lib/azure/core/auth/shared_key_lite.rb +34 -0
- data/lib/azure/core/collection.rb +118 -0
- data/lib/azure/core/service.rb +43 -0
- data/lib/azure/core/signer.rb +32 -0
- data/lib/azure/core/utils/interval.rb +97 -0
- data/lib/azure/core/utils/queryable.rb +74 -0
- data/lib/azure/core/utils/storage_service_properties.rb +83 -0
- data/lib/azure/core/utils/string.rb +59 -0
- data/lib/azure/error.rb +72 -0
- data/lib/azure/queues.rb +272 -0
- data/lib/azure/queues/message.rb +174 -0
- data/lib/azure/queues/queue.rb +187 -0
- data/lib/azure/queues/service.rb +263 -0
- data/lib/azure/queues/service_properties.rb +152 -0
- data/lib/azure/queues/uri.rb +78 -0
- data/lib/azure/request.rb +102 -0
- data/lib/azure/response.rb +93 -0
- data/lib/azure/service_bus.rb +4 -0
- data/lib/azure/service_bus/auth/authorizer.rb +22 -0
- data/lib/azure/service_bus/auth/uri.rb +52 -0
- data/lib/azure/service_bus/auth/wrap.rb +37 -0
- data/lib/azure/service_bus/auth/wrap_service.rb +76 -0
- data/lib/azure/service_bus/auth/wrap_token.rb +45 -0
- data/lib/azure/service_bus/auth/wrap_token_manager.rb +46 -0
- data/lib/azure/service_bus/brokered_message.rb +139 -0
- data/lib/azure/service_bus/brokered_message_serializer.rb +113 -0
- data/lib/azure/service_bus/queues.rb +194 -0
- data/lib/azure/service_bus/queues/queue.rb +100 -0
- data/lib/azure/service_bus/queues/queue_serializer.rb +51 -0
- data/lib/azure/service_bus/queues/service.rb +154 -0
- data/lib/azure/service_bus/queues/uri.rb +80 -0
- data/lib/azure/service_bus/rules.rb +110 -0
- data/lib/azure/service_bus/rules/rule.rb +97 -0
- data/lib/azure/service_bus/rules/service.rb +122 -0
- data/lib/azure/service_bus/rules/uri.rb +39 -0
- data/lib/azure/service_bus/service_bus_service.rb +22 -0
- data/lib/azure/service_bus/subscriptions.rb +170 -0
- data/lib/azure/service_bus/subscriptions/service.rb +133 -0
- data/lib/azure/service_bus/subscriptions/subscription.rb +164 -0
- data/lib/azure/service_bus/subscriptions/subscription_serializer.rb +74 -0
- data/lib/azure/service_bus/subscriptions/uri.rb +71 -0
- data/lib/azure/service_bus/topics.rb +120 -0
- data/lib/azure/service_bus/topics/service.rb +98 -0
- data/lib/azure/service_bus/topics/topic.rb +122 -0
- data/lib/azure/service_bus/topics/topic_serializer.rb +44 -0
- data/lib/azure/service_bus/topics/uri.rb +58 -0
- data/lib/azure/service_runtime/client/goal_state_pipe_monitor.rb +21 -0
- data/lib/azure/service_runtime/client/goal_state_protocol.rb +18 -0
- data/lib/azure/service_runtime/client/runtime_client.rb +135 -0
- data/lib/azure/service_runtime/deployment.rb +24 -0
- data/lib/azure/service_runtime/local_resource.rb +15 -0
- data/lib/azure/service_runtime/role.rb +17 -0
- data/lib/azure/service_runtime/role_environment.rb +206 -0
- data/lib/azure/service_runtime/role_environment_change.rb +32 -0
- data/lib/azure/service_runtime/role_instance.rb +35 -0
- data/lib/azure/service_runtime/role_instance_endpoint.rb +14 -0
- data/lib/azure/tables.rb +215 -0
- data/lib/azure/tables/auth/shared_key.rb +71 -0
- data/lib/azure/tables/auth/shared_key_lite.rb +30 -0
- data/lib/azure/tables/entities_collection.rb +66 -0
- data/lib/azure/tables/entity.rb +127 -0
- data/lib/azure/tables/service.rb +211 -0
- data/lib/azure/tables/table.rb +129 -0
- data/lib/azure/tables/tables_collection.rb +62 -0
- data/lib/azure/tables/types.rb +65 -0
- data/lib/azure/tables/uri.rb +62 -0
- data/test/fixtures/32px-fulls-black.jpg +0 -0
- data/test/fixtures/all_containers.xml +20 -0
- data/test/fixtures/all_tables.xml +22 -0
- data/test/fixtures/create_table_response_entry.xml +15 -0
- data/test/fixtures/error.xml +5 -0
- data/test/fixtures/insert_entity_response_entry.xml +25 -0
- data/test/fixtures/messages.xml +12 -0
- data/test/fixtures/query_entities_empty_response.xml +7 -0
- data/test/fixtures/query_entities_response.xml +45 -0
- data/test/fixtures/queue_service_properties.xml +22 -0
- data/test/fixtures/queue_service_properties_original.xml +19 -0
- data/test/fixtures/queues.xml +16 -0
- data/test/fixtures/sb_default_create_queue_response.xml +23 -0
- data/test/fixtures/sb_default_create_topic_response.xml +18 -0
- data/test/fixtures/sb_get_access_token_response.txt +1 -0
- data/test/fixtures/sb_queues_runtime_peek_message_response_headers.txt +9 -0
- data/test/integration/blobs/auth_test.rb +19 -0
- data/test/integration/blobs/blob_test.rb +61 -0
- data/test/integration/blobs/clear_page_range_test.rb +19 -0
- data/test/integration/blobs/copy_test.rb +33 -0
- data/test/integration/blobs/create_blobs_test.rb +51 -0
- data/test/integration/blobs/create_container_test.rb +13 -0
- data/test/integration/blobs/create_snapshot_test.rb +17 -0
- data/test/integration/blobs/delete_blob_snapshots_test.rb +19 -0
- data/test/integration/blobs/delete_blobs_test.rb +25 -0
- data/test/integration/blobs/delete_container_test.rb +24 -0
- data/test/integration/blobs/delete_snapshot_test.rb +17 -0
- data/test/integration/blobs/get_blob_snapshot_test.rb +18 -0
- data/test/integration/blobs/get_blobs_test.rb +31 -0
- data/test/integration/blobs/get_page_range_test.rb +19 -0
- data/test/integration/blobs/list_blobs_test.rb +39 -0
- data/test/integration/blobs/list_containers_test.rb +28 -0
- data/test/integration/blobs/manage_blob_leases_test.rb +45 -0
- data/test/integration/blobs/manage_blob_metadata_test.rb +51 -0
- data/test/integration/blobs/manage_blob_properties_test.rb +25 -0
- data/test/integration/blobs/manage_blob_service_properties_test.rb +38 -0
- data/test/integration/blobs/manage_container_metadata_test.rb +46 -0
- data/test/integration/blobs/manage_container_permissions_test.rb +17 -0
- data/test/integration/blobs/update_page_range_test.rb +20 -0
- data/test/integration/queues/clear_messages_test.rb +22 -0
- data/test/integration/queues/create_queue_test.rb +13 -0
- data/test/integration/queues/delete_message_test.rb +42 -0
- data/test/integration/queues/delete_queue_test.rb +24 -0
- data/test/integration/queues/get_messages_test.rb +39 -0
- data/test/integration/queues/list_queues_test.rb +43 -0
- data/test/integration/queues/manage_queue_metadata_test.rb +45 -0
- data/test/integration/queues/manage_queue_service_properties_test.rb +27 -0
- data/test/integration/queues/peek_messages_test.rb +55 -0
- data/test/integration/queues/put_message_test.rb +31 -0
- data/test/integration/queues/update_message_test.rb +46 -0
- data/test/integration/service_bus/auth_test.rb +18 -0
- data/test/integration/service_bus/queues/create_queue_test.rb +25 -0
- data/test/integration/service_bus/queues/delete_message_from_queue_test.rb +29 -0
- data/test/integration/service_bus/queues/delete_queue_test.rb +25 -0
- data/test/integration/service_bus/queues/get_queue_test.rb +23 -0
- data/test/integration/service_bus/queues/list_queues_test.rb +39 -0
- data/test/integration/service_bus/queues/peek_message_from_queue_test.rb +34 -0
- data/test/integration/service_bus/queues/read_and_delete_message_from_queue_test.rb +31 -0
- data/test/integration/service_bus/queues/send_message_to_queue_test.rb +22 -0
- data/test/integration/service_bus/queues/unlock_message_from_queue_test.rb +36 -0
- data/test/integration/service_bus/rules/create_rule_test.rb +19 -0
- data/test/integration/service_bus/rules/delete_rule_test.rb +17 -0
- data/test/integration/service_bus/rules/get_rule_test.rb +21 -0
- data/test/integration/service_bus/rules/list_rules_test.rb +24 -0
- data/test/integration/service_bus/rules/rule_test.rb +16 -0
- data/test/integration/service_bus/subscriptions/create_subscription_test.rb +25 -0
- data/test/integration/service_bus/subscriptions/delete_message_from_subscription_test.rb +31 -0
- data/test/integration/service_bus/subscriptions/delete_subscription_test.rb +30 -0
- data/test/integration/service_bus/subscriptions/fetch_subscription_test.rb +28 -0
- data/test/integration/service_bus/subscriptions/list_subscriptions_test.rb +23 -0
- data/test/integration/service_bus/subscriptions/peek_lock_message_from_subscription_test.rb +42 -0
- data/test/integration/service_bus/subscriptions/read_delete_message_from_subscription_test.rb +36 -0
- data/test/integration/service_bus/subscriptions/subscription_test.rb +31 -0
- data/test/integration/service_bus/subscriptions/unlock_message_from_subscription_test.rb +43 -0
- data/test/integration/service_bus/topics/create_topic_test.rb +25 -0
- data/test/integration/service_bus/topics/delete_topic_test.rb +25 -0
- data/test/integration/service_bus/topics/get_topic_test.rb +23 -0
- data/test/integration/service_bus/topics/list_topics_test.rb +39 -0
- data/test/integration/service_bus/topics/send_message_to_topic_test.rb +23 -0
- data/test/integration/tables/auth_test.rb +29 -0
- data/test/integration/tables/creating_tables_test.rb +16 -0
- data/test/integration/tables/delete_entity_test.rb +39 -0
- data/test/integration/tables/deleting_table_test.rb +22 -0
- data/test/integration/tables/insert_entity_test.rb +23 -0
- data/test/integration/tables/merge_entity_test.rb +28 -0
- data/test/integration/tables/query_entities_test.rb +131 -0
- data/test/integration/tables/query_tables_test.rb +63 -0
- data/test/integration/tables/update_entity_test.rb +54 -0
- data/test/integration/test_helper.rb +14 -0
- data/test/support/blobs.rb +12 -0
- data/test/support/env.rb +5 -0
- data/test/support/fixtures.rb +22 -0
- data/test/support/stubs.rb +28 -0
- data/test/support/table_names.rb +44 -0
- data/test/test_helper.rb +10 -0
- data/test/unit/atom_test.rb +58 -0
- data/test/unit/auth_test.rb +24 -0
- data/test/unit/blobs/blob_test.rb +5 -0
- data/test/unit/blobs/container_test.rb +67 -0
- data/test/unit/blobs/service_test.rb +17 -0
- data/test/unit/blobs/shared_access_signature_test.rb +66 -0
- data/test/unit/blobs_test.rb +156 -0
- data/test/unit/core/service_test.rb +57 -0
- data/test/unit/core/utils/interval_test.rb +70 -0
- data/test/unit/core/utils/queryable_test.rb +69 -0
- data/test/unit/core/utils/storage_service_properties_test.rb +66 -0
- data/test/unit/error_test.rb +39 -0
- data/test/unit/queues/message_test.rb +40 -0
- data/test/unit/queues/queue_test.rb +64 -0
- data/test/unit/queues/service_properties.rb +35 -0
- data/test/unit/request_test.rb +38 -0
- data/test/unit/response_test.rb +43 -0
- data/test/unit/service_bus/auth/authorizer_test.rb +27 -0
- data/test/unit/service_bus/auth/wrap_token_test.rb +28 -0
- data/test/unit/service_bus/queues/queue_test.rb +38 -0
- data/test/unit/service_bus/topics/topic_test.rb +33 -0
- data/test/unit/service_runtime/data/goalstate.xml +9 -0
- data/test/unit/service_runtime/data/roleenvironmentdata.xml +29 -0
- data/test/unit/service_runtime/data/runtime.xml +6 -0
- data/test/unit/service_runtime/role_environment_test.rb +144 -0
- data/test/unit/tables/auth/shared_key_lite_test.rb +39 -0
- data/test/unit/tables/auth/shared_key_test.rb +45 -0
- data/test/unit/tables/entities_collection_test.rb +39 -0
- data/test/unit/tables/entity_test.rb +72 -0
- data/test/unit/tables/table_test.rb +57 -0
- data/test/unit/tables_test.rb +302 -0
- data/test/unit/types_test.rb +67 -0
- metadata +310 -47
- data/LICENSE +0 -0
- data/README +0 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
require "azure/configuration"
|
2
|
+
require "uri"
|
3
|
+
|
4
|
+
module Azure
|
5
|
+
module ServiceBus
|
6
|
+
module Auth
|
7
|
+
module URI
|
8
|
+
# Public: generate the URI for the ACS Wrap service
|
9
|
+
#
|
10
|
+
# options - see Azure::ServiceBus::Auth::WrapService.get_access_token documentation.
|
11
|
+
# host - The host of the API.
|
12
|
+
#
|
13
|
+
# Returns a URI.
|
14
|
+
def self.wrap(options={}, host=Azure.config.acs_host)
|
15
|
+
generate(host, "WRAPv0.9", options)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Utility method to generate the URI.
|
19
|
+
#
|
20
|
+
# host - A String with the URI's host.
|
21
|
+
# path - A String with the URI's path.
|
22
|
+
# params - A simple Hash with query parameters (default: {}).
|
23
|
+
#
|
24
|
+
# Returns a URI.
|
25
|
+
def self.generate(host, path, params = {})
|
26
|
+
uri = join(host, path)
|
27
|
+
uri.query = to_query(params) unless params.empty?
|
28
|
+
uri
|
29
|
+
end
|
30
|
+
|
31
|
+
# Utility method to URL encode form data from a given hash
|
32
|
+
#
|
33
|
+
# hash - A Hash with params
|
34
|
+
#
|
35
|
+
# Returns a String (application/x-www-form-urlencoded data)
|
36
|
+
def self.to_query(hash)
|
37
|
+
::URI.encode_www_form(hash)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Utility method to generate the URI.
|
41
|
+
#
|
42
|
+
# host - A String with the URI's host.
|
43
|
+
# path - A String with the URI's path.
|
44
|
+
#
|
45
|
+
# Returns a URI.
|
46
|
+
def self.join(host, path)
|
47
|
+
::URI.parse(File.join(host, path))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "azure/configuration"
|
2
|
+
require "azure/service_bus/auth/wrap_token_manager"
|
3
|
+
|
4
|
+
module Azure
|
5
|
+
module ServiceBus
|
6
|
+
module Auth
|
7
|
+
# Signing strategy for WRAP
|
8
|
+
#
|
9
|
+
class Wrap
|
10
|
+
# Public: Initialize the Signer.
|
11
|
+
#
|
12
|
+
# issuer -
|
13
|
+
# access_key - The Azure ServiceBus access_key encoded in Base64.
|
14
|
+
def initialize(issuer=Azure.config.sb_issuer, access_key=Azure.config.sb_access_key, token_manager=nil)
|
15
|
+
@wrap_token_manager = token_manager || WrapTokenManager.new(issuer, access_key)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Public: The name of the strategy.
|
19
|
+
#
|
20
|
+
# Returns a String.
|
21
|
+
def name
|
22
|
+
"Wrap"
|
23
|
+
end
|
24
|
+
|
25
|
+
# Public: Generate a request signature.
|
26
|
+
#
|
27
|
+
# request - The HTTP request
|
28
|
+
#
|
29
|
+
# Returns a String
|
30
|
+
def sign(request)
|
31
|
+
access_token = @wrap_token_manager.get_access_token(request.uri)
|
32
|
+
'WRAP access_token="%s"' % access_token
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require "azure/service_bus/auth/wrap_token"
|
2
|
+
require "azure/service_bus/auth/uri"
|
3
|
+
require 'net/https'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
module Azure
|
7
|
+
module ServiceBus
|
8
|
+
module Auth
|
9
|
+
class WrapService
|
10
|
+
attr :issuer
|
11
|
+
attr :access_key
|
12
|
+
|
13
|
+
# Constructor
|
14
|
+
#
|
15
|
+
# issuer -
|
16
|
+
# access_key -
|
17
|
+
def initialize(issuer, access_key)
|
18
|
+
@issuer = issuer
|
19
|
+
@access_key = access_key
|
20
|
+
end
|
21
|
+
|
22
|
+
# Public: Get a valid access token for a given uri
|
23
|
+
#
|
24
|
+
# resource_uri - URI for the resource target
|
25
|
+
#
|
26
|
+
# Returns a valid Azure::ServiceBus::Auth:WrapToken
|
27
|
+
def get_access_token(resource_uri)
|
28
|
+
uri = URI.wrap
|
29
|
+
body = get_body(resource_uri)
|
30
|
+
response = do_request(:post, uri, body)
|
31
|
+
|
32
|
+
if response.code == "200"
|
33
|
+
WrapToken.parse(response.body)
|
34
|
+
else
|
35
|
+
#FIXME: handle errors
|
36
|
+
raise "Couldn't get an access_token from ACS, response was: %s" % response.body
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def do_request(method, uri, body)
|
43
|
+
headers = {
|
44
|
+
"Content-Type" => "application/x-www-form-urlencoded",
|
45
|
+
"Content-Length" => "0"
|
46
|
+
}
|
47
|
+
request = Net::HTTP::Post.new(uri.request_uri, headers)
|
48
|
+
request.body = body
|
49
|
+
|
50
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
51
|
+
http.use_ssl = true
|
52
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
53
|
+
|
54
|
+
response = http.request(request)
|
55
|
+
response
|
56
|
+
end
|
57
|
+
|
58
|
+
# Private: Generate the wrap ACS body for the given uri as a String
|
59
|
+
#
|
60
|
+
# resource_uri - The resource URI
|
61
|
+
#
|
62
|
+
# Returns a url-encoded String
|
63
|
+
def get_body(resource_uri)
|
64
|
+
non_ssl_uri = resource_uri.dup
|
65
|
+
non_ssl_uri.scheme = 'http'
|
66
|
+
params = {
|
67
|
+
:wrap_scope => non_ssl_uri.to_s,
|
68
|
+
:wrap_name => @issuer,
|
69
|
+
:wrap_password => @access_key
|
70
|
+
}
|
71
|
+
::URI.encode_www_form(params)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module Azure
|
4
|
+
module ServiceBus
|
5
|
+
module Auth
|
6
|
+
class WrapToken
|
7
|
+
attr_accessor :access_token
|
8
|
+
attr_accessor :expire_time
|
9
|
+
|
10
|
+
def initialize(token, expire_time)
|
11
|
+
@access_token = token
|
12
|
+
@expire_time = expire_time
|
13
|
+
end
|
14
|
+
|
15
|
+
# Public: Instantiate a WrapToken from the HTTP response body.
|
16
|
+
#
|
17
|
+
# boddy - a String as returned by the ACS in the response body.
|
18
|
+
#
|
19
|
+
# Returns a WrapToken.
|
20
|
+
def self.parse(body)
|
21
|
+
begin
|
22
|
+
decoded = ::URI.decode_www_form(body.strip)
|
23
|
+
token = decoded.assoc("wrap_access_token").last
|
24
|
+
expiration = decoded.assoc("wrap_access_token_expires_in").last
|
25
|
+
new(token, expiration)
|
26
|
+
rescue => e
|
27
|
+
# TODO: hanlde errors
|
28
|
+
raise "Cannot get the access token from returned string: %s" % body
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Public: Instantiate a queue from an error object.
|
33
|
+
#
|
34
|
+
# error - An Azure::Error.
|
35
|
+
#
|
36
|
+
# Returns a Queue.
|
37
|
+
def self.from_error(error)
|
38
|
+
queue = new(nil)
|
39
|
+
queue.error = error
|
40
|
+
queue
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "azure/service_bus/auth/wrap_service"
|
2
|
+
require "azure/service_bus/auth/wrap_token"
|
3
|
+
|
4
|
+
module Azure
|
5
|
+
module ServiceBus
|
6
|
+
module Auth
|
7
|
+
class WrapTokenManager
|
8
|
+
|
9
|
+
# The service used to get new tokens from the ACS
|
10
|
+
#
|
11
|
+
# Returns an Azure::ServiceBus::Auth::WrapService
|
12
|
+
attr :wrap_service
|
13
|
+
|
14
|
+
# A list of active WrapTokens
|
15
|
+
#
|
16
|
+
# Returns an Array of Azure::ServiceBus::Auth::WrapToken
|
17
|
+
attr :active_tokens
|
18
|
+
|
19
|
+
# Constructor
|
20
|
+
#
|
21
|
+
# issuer -
|
22
|
+
# access_key -
|
23
|
+
# host -
|
24
|
+
def initialize(issuer, access_key)
|
25
|
+
@active_tokens = {}
|
26
|
+
@wrap_service = WrapService.new(issuer, access_key)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Gets a valid (not expired) access token for the given uri
|
30
|
+
#
|
31
|
+
# uri - URI for the resource target
|
32
|
+
#
|
33
|
+
# Returns a String
|
34
|
+
def get_access_token(uri)
|
35
|
+
token = @active_tokens[uri.path]
|
36
|
+
now = Time.now.utc
|
37
|
+
unless token && token.expire_time > now
|
38
|
+
@active_tokens[uri.path] = @wrap_service.get_access_token(uri)
|
39
|
+
token = @active_tokens[uri.path]
|
40
|
+
end
|
41
|
+
token.access_token
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require "azure/error"
|
2
|
+
|
3
|
+
module Azure
|
4
|
+
module ServiceBus
|
5
|
+
class BrokeredMessage
|
6
|
+
include Azure::ErrorHandler
|
7
|
+
|
8
|
+
# Please read http://msdn.microsoft.com/en-us/library/windowsazure/hh780742
|
9
|
+
# for more information on brokered message properties
|
10
|
+
|
11
|
+
# Public: Get/Set the message's ContentType
|
12
|
+
#
|
13
|
+
# Returns a String
|
14
|
+
attr_accessor :content_type
|
15
|
+
|
16
|
+
# Public: Get/Set the message's CorrelationID
|
17
|
+
#
|
18
|
+
# Returns a String
|
19
|
+
attr_accessor :correlation_id
|
20
|
+
|
21
|
+
# Public: Get/Set the message's SessionID
|
22
|
+
#
|
23
|
+
# Returns a String
|
24
|
+
attr_accessor :session_id
|
25
|
+
|
26
|
+
# Public: Get/Set the message's DeliveryCount
|
27
|
+
#
|
28
|
+
# Returns an Integer
|
29
|
+
attr_accessor :delivery_count
|
30
|
+
|
31
|
+
# Public: Get/Set the message's LockedUntilUtc
|
32
|
+
#
|
33
|
+
# Returns a DateTime
|
34
|
+
attr_accessor :locked_until_utc
|
35
|
+
|
36
|
+
# Public: Get/Set the message's LockToken
|
37
|
+
#
|
38
|
+
# Returns a String (GUID)
|
39
|
+
attr_accessor :lock_token
|
40
|
+
|
41
|
+
# Public: Get/Set the message's MessageID
|
42
|
+
#
|
43
|
+
# Returns a String
|
44
|
+
attr_accessor :message_id
|
45
|
+
alias_method :id, :message_id
|
46
|
+
|
47
|
+
# Public: Get/Set the message's Label
|
48
|
+
#
|
49
|
+
# Returns a String
|
50
|
+
attr_accessor :label
|
51
|
+
|
52
|
+
# Public: Get/Set the message's ReplyTo
|
53
|
+
#
|
54
|
+
# Returns a String
|
55
|
+
attr_accessor :reply_to
|
56
|
+
|
57
|
+
# Public: Get/Set the message's EnqueuedTimeUtc
|
58
|
+
#
|
59
|
+
# Returns a DateTime
|
60
|
+
attr_accessor :enqueued_time_utc
|
61
|
+
|
62
|
+
# Public: Get/Set the message's SequenceNumber
|
63
|
+
#
|
64
|
+
# Returns an Integer
|
65
|
+
attr_accessor :sequence_number
|
66
|
+
|
67
|
+
# Public: Get/Set the message's TimeToLive
|
68
|
+
#
|
69
|
+
# Returns an Integer
|
70
|
+
attr_accessor :time_to_live
|
71
|
+
|
72
|
+
# Public: Get/Set the message's To
|
73
|
+
#
|
74
|
+
# Returns a String
|
75
|
+
attr_accessor :to
|
76
|
+
|
77
|
+
# Public: Get/Set the message's ScheduledEnqueueTimeUtc
|
78
|
+
#
|
79
|
+
# Returns a DateTime
|
80
|
+
attr_accessor :scheduled_enqueue_time_utc
|
81
|
+
|
82
|
+
# Public: Get/Set the message's ReplyToSessionId
|
83
|
+
#
|
84
|
+
# Returns a String
|
85
|
+
attr_accessor :reply_to_session_id
|
86
|
+
|
87
|
+
# Public: Get/Set custom key-value properties for the message
|
88
|
+
#
|
89
|
+
# Returns a Hash
|
90
|
+
attr_accessor :properties
|
91
|
+
|
92
|
+
# Public: Get/Set the message's Body
|
93
|
+
#
|
94
|
+
# Returns a String
|
95
|
+
attr_accessor :body
|
96
|
+
|
97
|
+
# Public: Get/Set the URI of the locked message. This URI is needed to unlock or delete the message.
|
98
|
+
#
|
99
|
+
# Returns an URI
|
100
|
+
attr_accessor :location
|
101
|
+
|
102
|
+
# Public: Instantiate a message from an error object.
|
103
|
+
#
|
104
|
+
# error - An Azure::Error.
|
105
|
+
#
|
106
|
+
# Returns a BrokeredMessage.
|
107
|
+
def self.from_error(error)
|
108
|
+
queue = new(nil)
|
109
|
+
queue.error = error
|
110
|
+
queue
|
111
|
+
end
|
112
|
+
|
113
|
+
# Public: Constructor.
|
114
|
+
#
|
115
|
+
# name - A String with the name of the queue.
|
116
|
+
# description - The queue description Hash
|
117
|
+
# service - The Queue service to perform external calls.
|
118
|
+
def initialize(body, properties={}, service=Azure::ServiceBus::Queues)
|
119
|
+
@body = body
|
120
|
+
@properties = properties
|
121
|
+
@service = service
|
122
|
+
yield self if block_given?
|
123
|
+
end
|
124
|
+
|
125
|
+
def delete
|
126
|
+
@service.delete(self)
|
127
|
+
end
|
128
|
+
|
129
|
+
# Public: Compare two messages to see if they are the same.
|
130
|
+
#
|
131
|
+
# other - A BrokeredMessage.
|
132
|
+
#
|
133
|
+
# Returns true|false.
|
134
|
+
def ==(other)
|
135
|
+
id == other.id
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require "azure/core/utils/string"
|
2
|
+
require "json"
|
3
|
+
require "time"
|
4
|
+
require "uri"
|
5
|
+
|
6
|
+
module Azure
|
7
|
+
module ServiceBus
|
8
|
+
class BrokeredMessageSerializer
|
9
|
+
include Azure::Core::Utils::String
|
10
|
+
|
11
|
+
PROPERTIES = [
|
12
|
+
'ContentType',
|
13
|
+
'CorrelationId',
|
14
|
+
'SessionID',
|
15
|
+
'DeliveryCount',
|
16
|
+
'LockedUntilUtc',
|
17
|
+
'LockToken',
|
18
|
+
'MessageId',
|
19
|
+
'Label',
|
20
|
+
'ReplyTo',
|
21
|
+
'EnqueuedTimeUtc',
|
22
|
+
'SequenceNumber',
|
23
|
+
'TimeToLive',
|
24
|
+
'To',
|
25
|
+
'ScheduledEnqueueTimeUtc',
|
26
|
+
'ReplyToSessionId'
|
27
|
+
].freeze
|
28
|
+
|
29
|
+
attr :message
|
30
|
+
|
31
|
+
def initialize(msg)
|
32
|
+
@message = msg
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.get_from_http_response(response)
|
36
|
+
props = JSON.parse(response.headers['brokerproperties'])
|
37
|
+
BrokeredMessage.new(response.body) do |m|
|
38
|
+
m.location = URI(response.headers['location']) unless response.headers['location'].nil?
|
39
|
+
m.content_type = response.headers['content-type']
|
40
|
+
|
41
|
+
# String based properties
|
42
|
+
m.lock_token = props['LockToken']
|
43
|
+
m.message_id = props['MessageId']
|
44
|
+
m.label = props['Label']
|
45
|
+
m.to = props['To']
|
46
|
+
m.session_id = props['SessionID']
|
47
|
+
m.correlation_id = props['CorrelationId']
|
48
|
+
m.reply_to = props['ReplyTo']
|
49
|
+
m.reply_to = props['ReplyTo']
|
50
|
+
m.reply_to_session_id = props['ReplyToSessionId']
|
51
|
+
|
52
|
+
# Time based properties
|
53
|
+
m.locked_until_utc = Time.parse(props['LockedUntilUtc']) unless props['LockedUntilUtc'].nil?
|
54
|
+
m.enqueued_time_utc = Time.parse(props['EnqueuedTimeUtc']) unless props['EnqueuedTimeUtc'].nil?
|
55
|
+
m.scheduled_enqueue_time_utc = Time.parse(props['ScheduledEnqueueTimeUtc']) unless props['ScheduledEnqueueTimeUtc'].nil?
|
56
|
+
|
57
|
+
# Numeric based properties
|
58
|
+
m.delivery_count = props['DeliveryCount'].to_i
|
59
|
+
m.sequence_number = props['SequenceNumber'].to_i
|
60
|
+
m.time_to_live = props['TimeToLive'].to_f
|
61
|
+
|
62
|
+
# Custom Properties
|
63
|
+
header_names_black_list = [
|
64
|
+
'brokerproperties',
|
65
|
+
'date',
|
66
|
+
'transfer-encoding',
|
67
|
+
'location',
|
68
|
+
'server',
|
69
|
+
'connection',
|
70
|
+
'content-type'
|
71
|
+
]
|
72
|
+
props = response.headers.reject {|k,_| header_names_black_list.include?(k.downcase) }
|
73
|
+
props.each do |prop_name, value|
|
74
|
+
m.properties[prop_name] = value.gsub(/"/, '')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Serialize the message's attributes to JSON
|
80
|
+
#
|
81
|
+
# Returns a JSON String
|
82
|
+
def to_json
|
83
|
+
hash = {}
|
84
|
+
PROPERTIES.each do |p|
|
85
|
+
attr_name = underscore(p)
|
86
|
+
value = @message.send(attr_name)
|
87
|
+
hash[p] = value unless value.nil?
|
88
|
+
end
|
89
|
+
hash.to_json
|
90
|
+
end
|
91
|
+
|
92
|
+
# Build a hash based on message properties and make it
|
93
|
+
# compliant with Azure policy for Message Property values
|
94
|
+
# in HTTP headers
|
95
|
+
#
|
96
|
+
# Returns a Hash
|
97
|
+
def get_property_headers
|
98
|
+
hash = {}
|
99
|
+
@message.properties.each do |name, value|
|
100
|
+
val = value
|
101
|
+
# Check for an RFC2626 Date
|
102
|
+
begin
|
103
|
+
val = '"' + Time.parse(value).httpdate + '"'
|
104
|
+
rescue ArgumentError
|
105
|
+
val = '"' + value + '"' if value.is_a? String
|
106
|
+
end
|
107
|
+
hash[name] = val
|
108
|
+
end
|
109
|
+
hash
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|