azure 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,152 @@
|
|
|
1
|
+
require "azure/queues"
|
|
2
|
+
require "azure/queues/uri"
|
|
3
|
+
require "azure/error"
|
|
4
|
+
require "uri"
|
|
5
|
+
require "nokogiri"
|
|
6
|
+
|
|
7
|
+
module Azure
|
|
8
|
+
module Queues
|
|
9
|
+
# Public: Representation of the Service Properties in a message queue.
|
|
10
|
+
class ServiceProperties
|
|
11
|
+
include Azure::ErrorHandler
|
|
12
|
+
|
|
13
|
+
# Public: Instantiate a ServiceProperties from an XML entry.
|
|
14
|
+
#
|
|
15
|
+
# entry - An XML::Node element.
|
|
16
|
+
#
|
|
17
|
+
# Returns a Serviceproperties.
|
|
18
|
+
def self.from_node(node)
|
|
19
|
+
new() do |s|
|
|
20
|
+
s.logging = Logging.from_node(node % "Logging")
|
|
21
|
+
s.metrics = Metrics.from_node(node % "Metrics")
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Public: Instantiate a message from an error object.
|
|
26
|
+
#
|
|
27
|
+
# error - An Azure::Error.
|
|
28
|
+
#
|
|
29
|
+
# Returns a Message.
|
|
30
|
+
def self.from_error(error)
|
|
31
|
+
message = new(nil)
|
|
32
|
+
message.error = error
|
|
33
|
+
message
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
attr_accessor :logging, :metrics
|
|
37
|
+
|
|
38
|
+
# Public: Constructor.
|
|
39
|
+
#
|
|
40
|
+
# queue - The message queue
|
|
41
|
+
# service - The Queue service to perform external calls.
|
|
42
|
+
def initialize(service=Azure::Queues)
|
|
43
|
+
@service = service
|
|
44
|
+
@logging = Logging.new
|
|
45
|
+
@metrics = Metrics.new
|
|
46
|
+
yield self if block_given?
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
class Logging
|
|
50
|
+
attr_accessor :version, :delete, :read, :write, :retention_policy
|
|
51
|
+
|
|
52
|
+
def initialize
|
|
53
|
+
@version = "1.0"
|
|
54
|
+
@read = false
|
|
55
|
+
@write = false
|
|
56
|
+
@delete = false
|
|
57
|
+
@retention_policy = RetentionPolicy.new
|
|
58
|
+
yield self if block_given?
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Public: Instantiate a Logging from an XML entry.
|
|
62
|
+
#
|
|
63
|
+
# entry - An XML::Node element.
|
|
64
|
+
#
|
|
65
|
+
# Returns a Logging.
|
|
66
|
+
def self.from_node(node)
|
|
67
|
+
new() do |l|
|
|
68
|
+
l.version = (node % "Version").text
|
|
69
|
+
l.read = (node % "Read").text == "true"
|
|
70
|
+
l.write = (node % "Write").text == "true"
|
|
71
|
+
l.delete = (node % "Delete").text == "true"
|
|
72
|
+
l.retention_policy = RetentionPolicy.from_node(node % "RetentionPolicy")
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
class Metrics
|
|
78
|
+
attr_accessor :version, :enabled, :include_apis, :retention_policy
|
|
79
|
+
|
|
80
|
+
def initialize
|
|
81
|
+
@version = "1.0"
|
|
82
|
+
@enabled = false
|
|
83
|
+
@include_apis = false
|
|
84
|
+
@retention_policy = RetentionPolicy.new
|
|
85
|
+
yield self if block_given?
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Public: Instantiate a Metrics from an XML entry.
|
|
89
|
+
#
|
|
90
|
+
# entry - An XML::Node element.
|
|
91
|
+
#
|
|
92
|
+
# Returns a Metrics.
|
|
93
|
+
def self.from_node(node)
|
|
94
|
+
new() do |m|
|
|
95
|
+
m.version = (node % "Version").text
|
|
96
|
+
m.enabled = (node % "Enabled").text == "true"
|
|
97
|
+
m.include_apis = (node % "IncludeAPIs").text == "true" unless (node % "IncludeAPIs").nil?
|
|
98
|
+
m.retention_policy = RetentionPolicy.from_node(node % "RetentionPolicy")
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
class RetentionPolicy
|
|
104
|
+
attr_accessor :enabled, :days
|
|
105
|
+
|
|
106
|
+
def initialize
|
|
107
|
+
@enabled = false
|
|
108
|
+
yield self if block_given?
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Public: Instantiate a RetentionPolicy from an XML entry.
|
|
112
|
+
#
|
|
113
|
+
# entry - An XML::Node element.
|
|
114
|
+
#
|
|
115
|
+
# Returns a RetentionPolicy.
|
|
116
|
+
def self.from_node(node)
|
|
117
|
+
new() do |m|
|
|
118
|
+
m.enabled = (node % "Enabled").text == "true"
|
|
119
|
+
m.days = (node % "Days").text unless (node % "Days").nil?
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def to_xml
|
|
125
|
+
body = Nokogiri::XML::Builder.new do |xml|
|
|
126
|
+
xml.StorageServiceProperties {
|
|
127
|
+
xml.Logging {
|
|
128
|
+
xml.Version logging.version
|
|
129
|
+
xml.Delete logging.delete
|
|
130
|
+
xml.Read logging.read
|
|
131
|
+
xml.Write logging.write
|
|
132
|
+
xml.RetentionPolicy {
|
|
133
|
+
xml.Enabled logging.retention_policy.enabled
|
|
134
|
+
xml.Days logging.retention_policy.days if logging.retention_policy.enabled
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
xml.Metrics {
|
|
138
|
+
xml.Version metrics.version
|
|
139
|
+
xml.Enabled metrics.enabled
|
|
140
|
+
xml.IncludeAPIs metrics.include_apis unless metrics.include_apis.nil?
|
|
141
|
+
xml.RetentionPolicy {
|
|
142
|
+
xml.Enabled metrics.retention_policy.enabled
|
|
143
|
+
xml.Days metrics.retention_policy.days if metrics.retention_policy.enabled
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
end
|
|
148
|
+
body.to_xml
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
require "azure/configuration"
|
|
2
|
+
require "uri"
|
|
3
|
+
|
|
4
|
+
module Azure
|
|
5
|
+
module Queues
|
|
6
|
+
module URI
|
|
7
|
+
# Public: generate the URI for the service properties
|
|
8
|
+
#
|
|
9
|
+
# query - see Azure::Services::GetServiceProperties#call documentation.
|
|
10
|
+
# host - The host of the API.
|
|
11
|
+
#
|
|
12
|
+
# Returns a URI.
|
|
13
|
+
def self.service_properties(query={}, host=Azure.config.queue_host)
|
|
14
|
+
query.update(restype: 'service', comp: 'properties')
|
|
15
|
+
generate(host, "", query)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Public: generate the URI for the collection of queues.
|
|
19
|
+
#
|
|
20
|
+
# query - see Azure::Services::ListQueues#call documentation.
|
|
21
|
+
# host - The host of the API.
|
|
22
|
+
#
|
|
23
|
+
# Returns a URI.
|
|
24
|
+
def self.collection(query={}, host=Azure.config.queue_host)
|
|
25
|
+
query.update(comp: 'list', include: 'metadata')
|
|
26
|
+
generate(host, "", query)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Public: Generate the URI for a given queue.
|
|
30
|
+
#
|
|
31
|
+
# queue_name - The name of the queue.
|
|
32
|
+
# query - A Hash of query parameters (default: {}).
|
|
33
|
+
# host - The host of the API.
|
|
34
|
+
#
|
|
35
|
+
# Returns a URI.
|
|
36
|
+
def self.queue(queue_name, query={}, host=Azure.config.queue_host)
|
|
37
|
+
return queue_name if name.kind_of? ::URI
|
|
38
|
+
generate(host, queue_name, query)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Public: Generate the messages URI for the given queue.
|
|
42
|
+
#
|
|
43
|
+
# queue_name - The name of the queue.
|
|
44
|
+
# query - A Hash of query parameters (default: {}).
|
|
45
|
+
# host - The host of the API.
|
|
46
|
+
#
|
|
47
|
+
# Returns a URI.
|
|
48
|
+
def self.messages(queue_name, query={}, host=Azure.config.queue_host)
|
|
49
|
+
generate(host, "#{queue_name}/messages", query)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Public: generate the URI for a given message
|
|
53
|
+
#
|
|
54
|
+
# queue_name - The name of the queue.
|
|
55
|
+
# message_id - The id of the message.
|
|
56
|
+
# query - A Hash of query parameters (default: {}).
|
|
57
|
+
# host - The host of the API.
|
|
58
|
+
#
|
|
59
|
+
# Returns a URI.
|
|
60
|
+
def self.message(queue_name, message_id, query={}, host=Azure.config.queue_host)
|
|
61
|
+
generate(host, "#{queue_name}/messages/#{message_id}", query)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Utility method to generate the URI.
|
|
65
|
+
#
|
|
66
|
+
# host - A String with the URI's host.
|
|
67
|
+
# path - A String with the URI's path.
|
|
68
|
+
# query - A simple Hash with query parameters (default: {}).
|
|
69
|
+
#
|
|
70
|
+
# Returns a URI.
|
|
71
|
+
def self.generate(host, path, query={})
|
|
72
|
+
uri = ::URI.parse(File.join(host, path))
|
|
73
|
+
uri.query = ::URI.encode_www_form(query) unless query.empty?
|
|
74
|
+
uri
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
require "digest/md5"
|
|
2
|
+
require "base64"
|
|
3
|
+
require "net/http"
|
|
4
|
+
require "time"
|
|
5
|
+
require "azure/response"
|
|
6
|
+
|
|
7
|
+
module Azure
|
|
8
|
+
class Request
|
|
9
|
+
# Public: The URI we're requesting.
|
|
10
|
+
attr :uri
|
|
11
|
+
|
|
12
|
+
# Public: A Hash of request headers.
|
|
13
|
+
attr :headers
|
|
14
|
+
|
|
15
|
+
# Public: The HTTP method of the request.
|
|
16
|
+
attr :method
|
|
17
|
+
|
|
18
|
+
# Public: The request body (in Atom) or nil.
|
|
19
|
+
attr :body
|
|
20
|
+
|
|
21
|
+
# Public: Build the HTTP Request.
|
|
22
|
+
#
|
|
23
|
+
# method - The HTTP request method.
|
|
24
|
+
# uri - The URI we'll hit.
|
|
25
|
+
# body - The request body, or nil.
|
|
26
|
+
# clock - An object that responds to .now and returns a Time.
|
|
27
|
+
def initialize(method, uri, body=nil, clock=Clock.new)
|
|
28
|
+
@method = method
|
|
29
|
+
@uri = uri
|
|
30
|
+
@body = body
|
|
31
|
+
@headers = {}
|
|
32
|
+
@clock = clock
|
|
33
|
+
|
|
34
|
+
calculate_headers
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Public: Make the request.
|
|
38
|
+
#
|
|
39
|
+
# ssl - Use SSL (default: false)
|
|
40
|
+
#
|
|
41
|
+
# Returns an Azure::Response.
|
|
42
|
+
def request!(ssl=false)
|
|
43
|
+
req = http_requester.new(uri.request_uri, headers)
|
|
44
|
+
req.body = body if body
|
|
45
|
+
|
|
46
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
47
|
+
if uri.scheme == 'https' || ssl
|
|
48
|
+
# require 'net/https'
|
|
49
|
+
http.use_ssl = true
|
|
50
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
Response.new(http.request(req))
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Build the headers Hash.
|
|
57
|
+
#
|
|
58
|
+
# Returns nothing.
|
|
59
|
+
def calculate_headers
|
|
60
|
+
headers["x-ms-date"] = @clock.now
|
|
61
|
+
headers["x-ms-version"] = "2011-08-18"
|
|
62
|
+
headers["DataServiceVersion"] = "1.0;NetFx"
|
|
63
|
+
headers["MaxDataServiceVersion"] = "2.0;NetFx"
|
|
64
|
+
|
|
65
|
+
if body
|
|
66
|
+
headers["Content-Type"] = "application/atom+xml; charset=utf-8"
|
|
67
|
+
headers["Content-Length"] = body.bytesize.to_s
|
|
68
|
+
headers["Content-MD5"] = Base64.strict_encode64(Digest::MD5.digest(body))
|
|
69
|
+
else
|
|
70
|
+
headers["Content-Length"] = "0"
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Obtain the Net::HTTP class that will handle this request.
|
|
75
|
+
#
|
|
76
|
+
# Returns a subclass of Net::HTTPRequest
|
|
77
|
+
def http_requester
|
|
78
|
+
Net::HTTP.const_get(method.to_s.capitalize)
|
|
79
|
+
rescue NameError => e
|
|
80
|
+
e.message = "#{method} is an invalid HTTP method"
|
|
81
|
+
raise
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Utility class to generate timestamps in a format the Azure platform likes.
|
|
85
|
+
class Clock
|
|
86
|
+
# Initialize the clock.
|
|
87
|
+
#
|
|
88
|
+
# source - Injectable dependency on the Time class.
|
|
89
|
+
def initialize(source=Time)
|
|
90
|
+
@source = source
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Calculate the time of "now", converted into something the Azure backend
|
|
94
|
+
# likes.
|
|
95
|
+
#
|
|
96
|
+
# Returns a String with the time formatted in accordance to RFC 2616.
|
|
97
|
+
def now
|
|
98
|
+
@source.now.httpdate
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
require "azure/error"
|
|
2
|
+
|
|
3
|
+
module Azure
|
|
4
|
+
# A small proxy to clean up the API of Net::HTTPResponse.
|
|
5
|
+
class Response
|
|
6
|
+
|
|
7
|
+
# Public: Initialize a new response.
|
|
8
|
+
#
|
|
9
|
+
# http_response - A Net::HTTPResponse.
|
|
10
|
+
def initialize(http_response)
|
|
11
|
+
@http_response = http_response
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Public: Get the response body.
|
|
15
|
+
#
|
|
16
|
+
# Returns a String.
|
|
17
|
+
def body
|
|
18
|
+
@http_response.body
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Public: Get the response status code.
|
|
22
|
+
#
|
|
23
|
+
# Returns a Fixnum.
|
|
24
|
+
def code
|
|
25
|
+
@http_response.code.to_i
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Public: Check if this response was successful. A request is considered
|
|
29
|
+
# successful if the response is in the 200 - 399 range.
|
|
30
|
+
#
|
|
31
|
+
# Returns true|false.
|
|
32
|
+
def success?
|
|
33
|
+
(200..399).include? code
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Public: Get all the response headers as a Hash.
|
|
37
|
+
#
|
|
38
|
+
# Returns a Hash.
|
|
39
|
+
def headers
|
|
40
|
+
@headers ||= HeaderHash.new(@http_response.to_hash)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Public: Get an error that wraps this HTTP response, as long as this
|
|
44
|
+
# response was unsuccessful. This method _should not_ be called if the
|
|
45
|
+
# response was successful.
|
|
46
|
+
#
|
|
47
|
+
# Returns an Azure::HTTPError.
|
|
48
|
+
def exception
|
|
49
|
+
Azure::HTTPError.new(self)
|
|
50
|
+
end
|
|
51
|
+
alias_method :error, :exception
|
|
52
|
+
|
|
53
|
+
# HTTP Headers are case insensitive, and the Azure APIs seem to like this a
|
|
54
|
+
# lot (documenting headers in one case and sending them in another). Also
|
|
55
|
+
# this wraps Net::HTTPResponse headers by returning their values as strings,
|
|
56
|
+
# not arrays.
|
|
57
|
+
class HeaderHash < Hash
|
|
58
|
+
# Public: Initialize the header hash.
|
|
59
|
+
#
|
|
60
|
+
# headers - A Hash of headers as returned from Net::HTTPResponse#to_hash.
|
|
61
|
+
def initialize(headers)
|
|
62
|
+
super
|
|
63
|
+
headers = Hash[headers.map { |k,v| [k.downcase.freeze, v.first.freeze] }]
|
|
64
|
+
replace(headers)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Public: Get a header's value or nil if it's not present.
|
|
68
|
+
#
|
|
69
|
+
# header - A string with the header's name.
|
|
70
|
+
#
|
|
71
|
+
# Returns a String or nil.
|
|
72
|
+
def [](header)
|
|
73
|
+
super(header.downcase)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Public: Get a header's value or a specified default.
|
|
77
|
+
#
|
|
78
|
+
# header - A string with the header's name.
|
|
79
|
+
# default - A default value.
|
|
80
|
+
#
|
|
81
|
+
# Yields a block where you can specify the default value.
|
|
82
|
+
#
|
|
83
|
+
# Returns a String, or the specified default.
|
|
84
|
+
def fetch(header, *default, &block)
|
|
85
|
+
if (args = default.size) > 1
|
|
86
|
+
raise ArgumentError, "wrong number of arguments(#{args + 1} for 2)"
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
super(header.downcase, *default, &block)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require "azure/configuration"
|
|
2
|
+
|
|
3
|
+
module Azure
|
|
4
|
+
module ServiceBus
|
|
5
|
+
module Auth
|
|
6
|
+
class Authorizer
|
|
7
|
+
# Public: Signs an HTTP request before it's made, by adding the
|
|
8
|
+
# Authorization header.
|
|
9
|
+
#
|
|
10
|
+
# request - An Azure::Request that hasn't been signed.
|
|
11
|
+
# signer - A signing strategy, such as Azure::ServiceBus::Auth::Wrap.
|
|
12
|
+
#
|
|
13
|
+
# Returns the modified request.
|
|
14
|
+
def sign(request, signer)
|
|
15
|
+
signature = signer.sign(request)
|
|
16
|
+
request.headers["Authorization"] = "#{signature}"
|
|
17
|
+
request
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|