azure-plus 0.6.5

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.
Files changed (298) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.travis.yml +11 -0
  4. data/ChangeLog.txt +40 -0
  5. data/Gemfile +16 -0
  6. data/README.md +590 -0
  7. data/Rakefile +129 -0
  8. data/azure.gemspec +47 -0
  9. data/lib/azure.rb +52 -0
  10. data/lib/azure/base_management/affinity_group.rb +32 -0
  11. data/lib/azure/base_management/base_management_service.rb +238 -0
  12. data/lib/azure/base_management/location.rb +27 -0
  13. data/lib/azure/base_management/management_http_request.rb +244 -0
  14. data/lib/azure/base_management/serialization.rb +129 -0
  15. data/lib/azure/base_management/sql_management_http_request.rb +45 -0
  16. data/lib/azure/blob/blob.rb +32 -0
  17. data/lib/azure/blob/blob_service.rb +1424 -0
  18. data/lib/azure/blob/block.rb +31 -0
  19. data/lib/azure/blob/container.rb +32 -0
  20. data/lib/azure/blob/serialization.rb +285 -0
  21. data/lib/azure/cloud_service_management/cloud_service.rb +38 -0
  22. data/lib/azure/cloud_service_management/cloud_service_management_service.rb +361 -0
  23. data/lib/azure/cloud_service_management/configuration_set.rb +28 -0
  24. data/lib/azure/cloud_service_management/deployment.rb +64 -0
  25. data/lib/azure/cloud_service_management/input_endpoint.rb +29 -0
  26. data/lib/azure/cloud_service_management/instance_endpoint.rb +31 -0
  27. data/lib/azure/cloud_service_management/persistent_vm_downtime.rb +29 -0
  28. data/lib/azure/cloud_service_management/role.rb +30 -0
  29. data/lib/azure/cloud_service_management/role_instance.rb +40 -0
  30. data/lib/azure/cloud_service_management/serialization.rb +329 -0
  31. data/lib/azure/cloud_service_management/virtual_ip.rb +29 -0
  32. data/lib/azure/core.rb +39 -0
  33. data/lib/azure/core/auth/authorizer.rb +36 -0
  34. data/lib/azure/core/auth/shared_key.rb +110 -0
  35. data/lib/azure/core/auth/shared_key_lite.rb +48 -0
  36. data/lib/azure/core/auth/signer.rb +48 -0
  37. data/lib/azure/core/configuration.rb +211 -0
  38. data/lib/azure/core/error.rb +22 -0
  39. data/lib/azure/core/filtered_service.rb +44 -0
  40. data/lib/azure/core/http/debug_filter.rb +36 -0
  41. data/lib/azure/core/http/http_error.rb +88 -0
  42. data/lib/azure/core/http/http_filter.rb +53 -0
  43. data/lib/azure/core/http/http_request.rb +159 -0
  44. data/lib/azure/core/http/http_response.rb +140 -0
  45. data/lib/azure/core/http/retry_policy.rb +74 -0
  46. data/lib/azure/core/http/signer_filter.rb +34 -0
  47. data/lib/azure/core/service.rb +63 -0
  48. data/lib/azure/core/signed_service.rb +43 -0
  49. data/lib/azure/core/utility.rb +190 -0
  50. data/lib/azure/queue/message.rb +30 -0
  51. data/lib/azure/queue/queue.rb +29 -0
  52. data/lib/azure/queue/queue_service.rb +568 -0
  53. data/lib/azure/queue/serialization.rb +106 -0
  54. data/lib/azure/service/access_policy.rb +26 -0
  55. data/lib/azure/service/enumeration_results.rb +21 -0
  56. data/lib/azure/service/logging.rb +32 -0
  57. data/lib/azure/service/metrics.rb +31 -0
  58. data/lib/azure/service/retention_policy.rb +25 -0
  59. data/lib/azure/service/serialization.rb +240 -0
  60. data/lib/azure/service/signed_identifier.rb +30 -0
  61. data/lib/azure/service/storage_service.rb +79 -0
  62. data/lib/azure/service/storage_service_properties.rb +32 -0
  63. data/lib/azure/service_bus/action.rb +21 -0
  64. data/lib/azure/service_bus/auth/wrap_service.rb +89 -0
  65. data/lib/azure/service_bus/auth/wrap_signer.rb +69 -0
  66. data/lib/azure/service_bus/brokered_message.rb +124 -0
  67. data/lib/azure/service_bus/brokered_message_serializer.rb +159 -0
  68. data/lib/azure/service_bus/correlation_filter.rb +45 -0
  69. data/lib/azure/service_bus/empty_rule_action.rb +30 -0
  70. data/lib/azure/service_bus/false_filter.rb +38 -0
  71. data/lib/azure/service_bus/filter.rb +21 -0
  72. data/lib/azure/service_bus/interval.rb +104 -0
  73. data/lib/azure/service_bus/queue.rb +230 -0
  74. data/lib/azure/service_bus/resource.rb +109 -0
  75. data/lib/azure/service_bus/rule.rb +98 -0
  76. data/lib/azure/service_bus/rule_aspect.rb +34 -0
  77. data/lib/azure/service_bus/serialization.rb +160 -0
  78. data/lib/azure/service_bus/service_bus_service.rb +829 -0
  79. data/lib/azure/service_bus/sql_filter.rb +50 -0
  80. data/lib/azure/service_bus/sql_rule_action.rb +50 -0
  81. data/lib/azure/service_bus/subscription.rb +184 -0
  82. data/lib/azure/service_bus/topic.rb +187 -0
  83. data/lib/azure/service_bus/true_filter.rb +38 -0
  84. data/lib/azure/sql_database_management/serialization.rb +111 -0
  85. data/lib/azure/sql_database_management/sql_database.rb +31 -0
  86. data/lib/azure/sql_database_management/sql_database_management_service.rb +200 -0
  87. data/lib/azure/storage_management/serialization.rb +184 -0
  88. data/lib/azure/storage_management/storage_account.rb +40 -0
  89. data/lib/azure/storage_management/storage_management_service.rb +166 -0
  90. data/lib/azure/table/auth/shared_key.rb +92 -0
  91. data/lib/azure/table/auth/shared_key_lite.rb +44 -0
  92. data/lib/azure/table/batch.rb +330 -0
  93. data/lib/azure/table/batch_response.rb +118 -0
  94. data/lib/azure/table/edmtype.rb +127 -0
  95. data/lib/azure/table/entity.rb +31 -0
  96. data/lib/azure/table/guid.rb +24 -0
  97. data/lib/azure/table/query.rb +112 -0
  98. data/lib/azure/table/serialization.rb +108 -0
  99. data/lib/azure/table/table_service.rb +560 -0
  100. data/lib/azure/version.rb +31 -0
  101. data/lib/azure/virtual_machine_image_management/serialization.rb +51 -0
  102. data/lib/azure/virtual_machine_image_management/virtual_machine_disk.rb +25 -0
  103. data/lib/azure/virtual_machine_image_management/virtual_machine_image.rb +25 -0
  104. data/lib/azure/virtual_machine_image_management/virtual_machine_image_management_service.rb +66 -0
  105. data/lib/azure/virtual_machine_management/serialization.rb +436 -0
  106. data/lib/azure/virtual_machine_management/virtual_machine.rb +42 -0
  107. data/lib/azure/virtual_machine_management/virtual_machine_management_service.rb +549 -0
  108. data/lib/azure/virtual_network_management/serialization.rb +186 -0
  109. data/lib/azure/virtual_network_management/virtual_network.rb +36 -0
  110. data/lib/azure/virtual_network_management/virtual_network_management_service.rb +109 -0
  111. data/test/fixtures/32px-fulls-black.jpg +0 -0
  112. data/test/fixtures/affinity_group.xml +33 -0
  113. data/test/fixtures/all_containers.xml +20 -0
  114. data/test/fixtures/all_tables.xml +22 -0
  115. data/test/fixtures/certificate.pem +21 -0
  116. data/test/fixtures/container_acl.xml +11 -0
  117. data/test/fixtures/create_sql_database_server.xml +2 -0
  118. data/test/fixtures/create_storage_desc_error.xml +5 -0
  119. data/test/fixtures/create_storage_extendedprop_error.xml +8 -0
  120. data/test/fixtures/create_storage_extendedpropname_error.xml +6 -0
  121. data/test/fixtures/create_storage_full_error.xml +6 -0
  122. data/test/fixtures/create_storage_label_error.xml +5 -0
  123. data/test/fixtures/create_storage_location_error.xml +5 -0
  124. data/test/fixtures/create_storage_name_error.xml +6 -0
  125. data/test/fixtures/create_table_response_entry.xml +15 -0
  126. data/test/fixtures/delete_storage_container_error.xml +5 -0
  127. data/test/fixtures/delete_storage_error.xml +5 -0
  128. data/test/fixtures/deployment_error.xml +5 -0
  129. data/test/fixtures/empty_xml_file +0 -0
  130. data/test/fixtures/get_deployment.xml +94 -0
  131. data/test/fixtures/get_deployment_existing.xml +94 -0
  132. data/test/fixtures/get_deployment_missing.xml +5 -0
  133. data/test/fixtures/get_storage_account_error.xml +5 -0
  134. data/test/fixtures/get_storage_account_properties.xml +32 -0
  135. data/test/fixtures/get_storage_account_properties_new.xml +32 -0
  136. data/test/fixtures/http_error.xml +5 -0
  137. data/test/fixtures/insert_entity_response_entry.xml +25 -0
  138. data/test/fixtures/list_affinity_groups.xml +22 -0
  139. data/test/fixtures/list_blobs.xml +121 -0
  140. data/test/fixtures/list_block_all_with_none_committed.xml +22 -0
  141. data/test/fixtures/list_blocks_all.xml +23 -0
  142. data/test/fixtures/list_blocks_committed.xml +13 -0
  143. data/test/fixtures/list_cloud_services.xml +39 -0
  144. data/test/fixtures/list_containers.xml +38 -0
  145. data/test/fixtures/list_firewall_management_endpoint.xml +27 -0
  146. data/test/fixtures/list_images.xml +110 -0
  147. data/test/fixtures/list_locations.xml +62 -0
  148. data/test/fixtures/list_page_ranges.xml +11 -0
  149. data/test/fixtures/list_sql_database.xml +36 -0
  150. data/test/fixtures/list_sql_server_firewall.xml +23 -0
  151. data/test/fixtures/list_storage_account_single.xml +25 -0
  152. data/test/fixtures/list_storage_accounts.xml +46 -0
  153. data/test/fixtures/list_virtual_networks.xml +92 -0
  154. data/test/fixtures/logging.xml +11 -0
  155. data/test/fixtures/management_certificate.pem +55 -0
  156. data/test/fixtures/messages.xml +12 -0
  157. data/test/fixtures/metrics.xml +10 -0
  158. data/test/fixtures/privatekey.key +28 -0
  159. data/test/fixtures/query_entities_empty_response.xml +7 -0
  160. data/test/fixtures/query_entities_response.xml +45 -0
  161. data/test/fixtures/queue_service_properties.xml +22 -0
  162. data/test/fixtures/queue_service_properties_original.xml +19 -0
  163. data/test/fixtures/queues.xml +16 -0
  164. data/test/fixtures/retention_policy.xml +5 -0
  165. data/test/fixtures/sb_default_create_queue_response.xml +23 -0
  166. data/test/fixtures/sb_default_create_topic_response.xml +18 -0
  167. data/test/fixtures/sb_get_access_token_response.txt +1 -0
  168. data/test/fixtures/sb_queues_runtime_peek_message_response_headers.txt +9 -0
  169. data/test/fixtures/storage_service_properties.xml +23 -0
  170. data/test/fixtures/update_storage_account.xml +16 -0
  171. data/test/fixtures/update_storage_error.xml +5 -0
  172. data/test/fixtures/updated_storage_accounts.xml +53 -0
  173. data/test/fixtures/virtual_machine.xml +113 -0
  174. data/test/fixtures/windows_virtual_machine.xml +106 -0
  175. data/test/integration/affinity_group/Affinity_test.rb +55 -0
  176. data/test/integration/affinity_group/Create_Affinity_test.rb +63 -0
  177. data/test/integration/affinity_group/Delete_Affinity_test.rb +56 -0
  178. data/test/integration/affinity_group/List_Affinity_test.rb +41 -0
  179. data/test/integration/affinity_group/Update_Affinity_test.rb +82 -0
  180. data/test/integration/blob/blob_gb18030_test.rb +199 -0
  181. data/test/integration/blob/blob_metadata_test.rb +75 -0
  182. data/test/integration/blob/blob_pages_test.rb +119 -0
  183. data/test/integration/blob/blob_properties_test.rb +77 -0
  184. data/test/integration/blob/block_blob_test.rb +254 -0
  185. data/test/integration/blob/container/container_acl_test.rb +69 -0
  186. data/test/integration/blob/container/container_metadata_test.rb +50 -0
  187. data/test/integration/blob/container/create_container_test.rb +60 -0
  188. data/test/integration/blob/container/delete_container_test.rb +39 -0
  189. data/test/integration/blob/container/get_container_properties_test.rb +48 -0
  190. data/test/integration/blob/container/list_containers_test.rb +79 -0
  191. data/test/integration/blob/container/root_container_test.rb +54 -0
  192. data/test/integration/blob/copy_blob_test.rb +113 -0
  193. data/test/integration/blob/create_blob_snapshot_test.rb +80 -0
  194. data/test/integration/blob/create_page_blob_test.rb +83 -0
  195. data/test/integration/blob/delete_blob_test.rb +159 -0
  196. data/test/integration/blob/get_blob_test.rb +65 -0
  197. data/test/integration/blob/informative_errors_test.rb +39 -0
  198. data/test/integration/blob/lease/acquire_lease_test.rb +36 -0
  199. data/test/integration/blob/lease/break_lease_test.rb +40 -0
  200. data/test/integration/blob/lease/release_lease_test.rb +40 -0
  201. data/test/integration/blob/lease/renew_lease_test.rb +42 -0
  202. data/test/integration/blob/list_blobs_test.rb +113 -0
  203. data/test/integration/cloud_service/Cloud_Create_test.rb +44 -0
  204. data/test/integration/cloud_service/Cloud_Delete_test.rb +44 -0
  205. data/test/integration/database/create_sql_server_firewall_test.rb +86 -0
  206. data/test/integration/database/create_sql_server_test.rb +53 -0
  207. data/test/integration/database/delete_sql_server_firewall_test.rb +70 -0
  208. data/test/integration/database/delete_sql_server_test.rb +58 -0
  209. data/test/integration/database/list_sql_server_firewall_test.rb +45 -0
  210. data/test/integration/database/list_sql_servers_test.rb +44 -0
  211. data/test/integration/database/reset_password_sql_server_test.rb +55 -0
  212. data/test/integration/location/Location_List_test.rb +39 -0
  213. data/test/integration/queue/clear_messages_test.rb +42 -0
  214. data/test/integration/queue/create_message_test.rb +75 -0
  215. data/test/integration/queue/create_queue_test.rb +50 -0
  216. data/test/integration/queue/delete_message_test.rb +67 -0
  217. data/test/integration/queue/delete_queue_test.rb +45 -0
  218. data/test/integration/queue/informative_errors_test.rb +42 -0
  219. data/test/integration/queue/list_messages_encoded_test.rb +79 -0
  220. data/test/integration/queue/list_messages_test.rb +79 -0
  221. data/test/integration/queue/list_queues_test.rb +44 -0
  222. data/test/integration/queue/peek_messages_test.rb +59 -0
  223. data/test/integration/queue/queue_gb18030_test.rb +131 -0
  224. data/test/integration/queue/queue_metadata_test.rb +40 -0
  225. data/test/integration/queue/update_message_test.rb +74 -0
  226. data/test/integration/service_bus/informative_errors_test.rb +37 -0
  227. data/test/integration/service_bus/queues_scenario_test.rb +200 -0
  228. data/test/integration/service_bus/queues_test.rb +266 -0
  229. data/test/integration/service_bus/rules_test.rb +145 -0
  230. data/test/integration/service_bus/sb_queue_gb18030_test.rb +182 -0
  231. data/test/integration/service_bus/scenario_test.rb +101 -0
  232. data/test/integration/service_bus/subscriptions_test.rb +211 -0
  233. data/test/integration/service_bus/topics_scenario_test.rb +406 -0
  234. data/test/integration/service_bus/topics_test.rb +129 -0
  235. data/test/integration/storage_management/storage_management_test.rb +160 -0
  236. data/test/integration/table/create_table_test.rb +36 -0
  237. data/test/integration/table/delete_entity_batch_test.rb +107 -0
  238. data/test/integration/table/delete_entity_test.rb +94 -0
  239. data/test/integration/table/delete_table_test.rb +40 -0
  240. data/test/integration/table/get_table_test.rb +37 -0
  241. data/test/integration/table/informative_errors_test.rb +39 -0
  242. data/test/integration/table/insert_entity_batch_test.rb +100 -0
  243. data/test/integration/table/insert_entity_test.rb +88 -0
  244. data/test/integration/table/insert_or_merge_entity_batch_test.rb +159 -0
  245. data/test/integration/table/insert_or_merge_entity_test.rb +143 -0
  246. data/test/integration/table/insert_or_replace_entity_batch_test.rb +152 -0
  247. data/test/integration/table/insert_or_replace_entity_test.rb +137 -0
  248. data/test/integration/table/merge_entity_batch_test.rb +128 -0
  249. data/test/integration/table/merge_entity_test.rb +113 -0
  250. data/test/integration/table/query_entities_test.rb +195 -0
  251. data/test/integration/table/query_tables_test.rb +43 -0
  252. data/test/integration/table/query_test.rb +251 -0
  253. data/test/integration/table/table_acl_test.rb +52 -0
  254. data/test/integration/table/table_gb18030_test.rb +355 -0
  255. data/test/integration/table/update_entity_batch_test.rb +149 -0
  256. data/test/integration/table/update_entity_test.rb +131 -0
  257. data/test/integration/test_helper.rb +42 -0
  258. data/test/integration/vm/VM_Create_test.rb +260 -0
  259. data/test/integration/vm/VM_Delete_test.rb +55 -0
  260. data/test/integration/vm/VM_Operations_test.rb +173 -0
  261. data/test/integration/vm_image/virtual_machine_disk_test.rb +37 -0
  262. data/test/integration/vm_image/virtual_machine_image_test.rb +37 -0
  263. data/test/integration/vnet/Virtual_Network_Create_test.rb +122 -0
  264. data/test/integration/vnet/Virtual_Network_list_test.rb +53 -0
  265. data/test/support/env.rb +19 -0
  266. data/test/support/fixtures.rb +36 -0
  267. data/test/support/name_generator.rb +160 -0
  268. data/test/support/stubs.rb +42 -0
  269. data/test/support/virtual_machine_name_generator.rb +102 -0
  270. data/test/support/virtual_network_helper.rb +73 -0
  271. data/test/test_helper.rb +53 -0
  272. data/test/unit/affinity_group/affinity_group_test.rb +192 -0
  273. data/test/unit/affinity_group/serialization_test.rb +88 -0
  274. data/test/unit/base_management/location_test.rb +57 -0
  275. data/test/unit/blob/blob_service_test.rb +1947 -0
  276. data/test/unit/cloud_service_management/cloud_service_management_service_test.rb +276 -0
  277. data/test/unit/cloud_service_management/serialization_test.rb +169 -0
  278. data/test/unit/core/auth/shared_key_lite_test.rb +51 -0
  279. data/test/unit/core/auth/shared_key_test.rb +58 -0
  280. data/test/unit/core/auth/signer_test.rb +30 -0
  281. data/test/unit/core/http/http_error_test.rb +57 -0
  282. data/test/unit/core/http/http_request_test.rb +66 -0
  283. data/test/unit/core/http/http_response_test.rb +45 -0
  284. data/test/unit/core/http/retry_policy_test.rb +23 -0
  285. data/test/unit/database/serialization_test.rb +97 -0
  286. data/test/unit/database/sql_database_server_service_test.rb +288 -0
  287. data/test/unit/service/serialization_test.rb +502 -0
  288. data/test/unit/service/storage_service_test.rb +291 -0
  289. data/test/unit/storage_management/serialization_test.rb +232 -0
  290. data/test/unit/storage_management/storage_management_service_test.rb +261 -0
  291. data/test/unit/table/edmtype_test.rb +108 -0
  292. data/test/unit/virtual_machine_image_management/serialization_test.rb +35 -0
  293. data/test/unit/virtual_machine_image_management/virtual_machine_image_management_service_test.rb +65 -0
  294. data/test/unit/virtual_machine_management/serialization_test.rb +247 -0
  295. data/test/unit/virtual_machine_management/virtual_machine_management_service_test.rb +440 -0
  296. data/test/unit/vnet/serialization_test.rb +187 -0
  297. data/test/unit/vnet/virtual_network_management_service_test.rb +131 -0
  298. metadata +470 -0
@@ -0,0 +1,109 @@
1
+ #-------------------------------------------------------------------------
2
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #--------------------------------------------------------------------------
15
+ require 'azure/service_bus/resource'
16
+ require 'azure/service_bus/interval'
17
+
18
+ module Azure
19
+ module ServiceBus
20
+ class Resource
21
+ # Public: Initialize the resource (either queue, topic, rule or subscription).
22
+ #
23
+ # name - A String with the name of the resource.
24
+ # description - The resource description Hash
25
+ def initialize(name, description = {})
26
+ @name = name
27
+ @description = description
28
+ yield self if block_given?
29
+ end
30
+
31
+ # Get the Resource's ID.
32
+ #
33
+ # Returns a URI.
34
+ attr_accessor :id
35
+ alias_method :url, :id
36
+
37
+ # Get the Resource's name.
38
+ #
39
+ # Returns a String.
40
+ attr_accessor :name
41
+ alias_method :title, :name
42
+
43
+ # Public: Get the published time
44
+ #
45
+ # Returns a Time
46
+ attr_accessor :published
47
+
48
+ # Public: Get the updated time
49
+ #
50
+ # Returns a Time
51
+ attr_accessor :updated
52
+
53
+ # Public: Get the author name
54
+ #
55
+ # Returns a String
56
+ attr_accessor :author_name
57
+
58
+ # Public: Resource description
59
+ #
60
+ # Returns a Hash
61
+ attr_accessor :description
62
+
63
+ def get_props
64
+ desc = description.dup
65
+ props = []
66
+ ordered_props.each { |prop_name|
67
+ if desc[prop_name]
68
+ props.push [prop_name, desc[prop_name]]
69
+ desc.delete prop_name
70
+ end
71
+ }
72
+ desc.each { |k,v|
73
+ props.push [k, v]
74
+ }
75
+ props
76
+ end
77
+
78
+ private
79
+
80
+ def to_interval(s)
81
+ s ? Interval.parse(s) : s
82
+ end
83
+
84
+ def to_time(s)
85
+ s ? Time.parse(s) : s
86
+ end
87
+
88
+ def to_i(s)
89
+ s ? s.to_i : s
90
+ end
91
+
92
+ def to_bool(s)
93
+ s ? (s || "").downcase == 'true' : s
94
+ end
95
+
96
+ def _set(name, value)
97
+ if value
98
+ description[name] = value.to_s
99
+ else
100
+ description.delete name
101
+ end
102
+ end
103
+
104
+ def ordered_props
105
+ []
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,98 @@
1
+ #-------------------------------------------------------------------------
2
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #--------------------------------------------------------------------------
15
+ require 'azure/service_bus/resource'
16
+ require 'azure/service_bus/rule_aspect'
17
+
18
+ require 'azure/service_bus/sql_filter'
19
+ require 'azure/service_bus/true_filter'
20
+ require 'azure/service_bus/false_filter'
21
+ require 'azure/service_bus/correlation_filter'
22
+
23
+ require 'azure/service_bus/sql_rule_action'
24
+ require 'azure/service_bus/empty_rule_action'
25
+
26
+ module Azure
27
+ module ServiceBus
28
+ class Rule < Resource
29
+
30
+ attr_accessor :topic
31
+ attr_accessor :subscription
32
+
33
+ # Public: Initialize the rule.
34
+ #
35
+ # ==== Attributes
36
+ #
37
+ # * +name+ - A String with the name of the rule.
38
+ # * +options+ - The resource options Hash
39
+ #
40
+ # ==== Options
41
+ #
42
+ # Accepted key/value pairs in options parameter are:
43
+ # * +:filter+ - String. The rule filter.
44
+ # * +:action+ - String. The rule action.
45
+ #
46
+ def initialize(name, options = {})
47
+ normalized_options = {}
48
+ normalized_options["Filter"] = options[:filter] if options.has_key?(:filter)
49
+ normalized_options["Action"] = options[:action] if options.has_key?(:action)
50
+
51
+ super(name, normalized_options)
52
+ end
53
+
54
+ # Filter: SqlFilter, TrueFilter /FalseFiilter, CorrelationFilter
55
+ #
56
+ # The Filter property references an instance of Filter that is evaluated against a message. The following types of
57
+ # filters are provided:
58
+ #
59
+ # SqlFilter - A type of Filter that is represented by SQL expression. For detailed information about SqlFilter
60
+ # syntax, see SqlFilter.SqlExpression Property.
61
+ #
62
+ # TrueFilter/FalseFiilter - A handy shortcut for always returning true or false. They are a type of SqlFilter.
63
+ #
64
+ # CorrelationFilter: A type of Filter that matches CorrelationId property of BrokeredMessage.
65
+ def filter
66
+ RuleAspect.from_hash(description['Filter'])
67
+ end
68
+
69
+ def filter=(val)
70
+ description['Filter'] = val.to_hash
71
+ end
72
+
73
+ # Action: String
74
+ #
75
+ # The Action property references an instance of FilterAction. The following type of FilterAction are provided.
76
+ # Default is an instance of EmptyRuleAction.
77
+ #
78
+ # SqlFilterAction - A type of FilterAction that is represented by SQL expression. For detailed information about
79
+ # SqlFilterAction syntax, see SqlRuleAction.SqlExpression Property.
80
+ #
81
+ # EmptyRuleAction - A type of FilterAction that represents an empty action.
82
+ def action
83
+ RuleAspect.from_hash(description['Action'])
84
+ end
85
+
86
+ def action=(val)
87
+ description['Action'] = val.to_hash
88
+ end
89
+
90
+ def ordered_props
91
+ [
92
+ 'Filter',
93
+ 'Action'
94
+ ]
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,34 @@
1
+ #-------------------------------------------------------------------------
2
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #--------------------------------------------------------------------------
15
+ module Azure
16
+ module ServiceBus
17
+ class RuleAspect
18
+ def initialize()
19
+ yield self if block_given?
20
+ end
21
+
22
+ def to_hash(hash={})
23
+ hash[:type]=self.class.name.split('::').last
24
+ hash
25
+ end
26
+
27
+ def self.from_hash(hash)
28
+ hash = {} unless hash
29
+ type = hash[:type]
30
+ Azure::ServiceBus.const_get(type).new(hash) if type
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,160 @@
1
+ #-------------------------------------------------------------------------
2
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #--------------------------------------------------------------------------
15
+ require 'nokogiri'
16
+
17
+ require "azure/service_bus/queue"
18
+ require "azure/service_bus/topic"
19
+ require "azure/service_bus/subscription"
20
+ require "azure/service_bus/rule"
21
+
22
+ require "azure/service/enumeration_results"
23
+
24
+ module Azure
25
+ module ServiceBus
26
+ module Serialization
27
+ module ClassMethods
28
+
29
+ def rule_to_xml(xml, rule)
30
+ rule_aspect_to_xml xml, 'Filter', rule if rule.filter
31
+ rule_aspect_to_xml xml, 'Action', rule if rule.action
32
+ end
33
+
34
+ def rule_aspect_to_xml(xml, aspect_name, rule)
35
+ aspect = rule.description[aspect_name].dup
36
+ xml.send(aspect_name, "i:type" => aspect.delete(:type)) {
37
+ aspect.each { |k,v|
38
+ if k == :sql_expression
39
+ k = "SqlExpression"
40
+ elsif k == :compatibility_level
41
+ k = "CompatibilityLevel"
42
+ elsif k == :correlation_id
43
+ k = "CorrelationId"
44
+ end
45
+
46
+ xml.send(k, v)
47
+ }
48
+ }
49
+ end
50
+
51
+ def resource_to_xml(resource, entry)
52
+ doc = Nokogiri::XML::Builder.new(:encoding => "UTF-8") do |xml|
53
+ xml.entry(:xmlns => 'http://www.w3.org/2005/Atom') {
54
+ xml.content(:type => 'application/xml') {
55
+ xml.send("#{resource.to_s.capitalize}Description", 'xmlns' => 'http://schemas.microsoft.com/netservices/2010/10/servicebus/connect', 'xmlns:i' => 'http://www.w3.org/2001/XMLSchema-instance') {
56
+ if resource == :rule
57
+ rule_to_xml xml, entry
58
+ else
59
+ entry.get_props.each do |p|
60
+ xml.send(p[0], p[1].to_s)
61
+ end
62
+ end
63
+ }
64
+ }
65
+ }
66
+ end
67
+ doc.to_xml
68
+ end
69
+
70
+ def resource_from_xml(resource, node)
71
+ resource = resource.to_s.capitalize
72
+
73
+ name = (node % "title").text
74
+
75
+ Azure::ServiceBus.const_get(resource).new(name) do |r|
76
+ r.id = URI((node % "id").text) if (node % "id")
77
+ r.published = Time.parse((node % "published").text) if (node % "published")
78
+ r.updated = Time.parse((node % "updated").text) if (node % "updated")
79
+ r.author_name = (node % "author/name").text if (node % "author/name")
80
+
81
+ r.description = (node / "content/#{resource}Description *").each_with_object({}) do |element, description|
82
+ if resource == "Rule"
83
+ handle_rule_description_element element, description
84
+ else
85
+ description[element.name] = element.text
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ def handle_rule_description_element(element, description)
92
+ if element.name == "Filter" or element.name == "Action"
93
+ value = {}
94
+ value[:type] = element["type"]
95
+ element.children.each do |child|
96
+ if child.name == "SqlExpression"
97
+ value[:sql_expression] = child.content
98
+ elsif child.name == "CompatibilityLevel"
99
+ value[:compatibility_level] = child.content
100
+ elsif child.name == "CorrelationId"
101
+ value[:correlation_id] = child.content
102
+ end
103
+ end
104
+ description[element.name] = value
105
+ end
106
+ end
107
+
108
+ def resources_from_xml(resource, xml)
109
+ feed = Nokogiri::XML(xml).remove_namespaces!
110
+ values = (feed / 'entry').map {|node| resource_from_xml(resource, node) }
111
+ values.class.module_eval { attr_accessor :next_link}
112
+ values.next_link = feed.xpath("//link[@rel='next']/@href")
113
+ values
114
+ end
115
+
116
+ def resources_from_xml_with_next_link(resource, xml)
117
+ feed = Nokogiri::XML(xml).remove_namespaces!
118
+ values = Azure::Service::EnumerationResults.new((feed / 'entry').map {|node| resource_from_xml(resource, node) })
119
+
120
+ next_token = nil
121
+ next_uri = feed.xpath("//link[@rel='next']/@href")
122
+ if next_uri != nil && next_uri.length > 0
123
+ u = URI.parse(next_uri.to_s)
124
+ p = CGI.parse(u.query)
125
+
126
+ if p['skip'] || p['top']
127
+ next_token = { }
128
+ next_token[:top] = p['top'] if p['top']
129
+ next_token[:skip] = p['skip'] if p['skip']
130
+ end
131
+ end
132
+
133
+ values.continuation_token = next_token
134
+ values
135
+ end
136
+
137
+ def to_bool(s)
138
+ (s || "").downcase == 'true'
139
+ end
140
+
141
+ def slopify(xml)
142
+ node = (xml.is_a? String) ? Nokogiri.Slop(xml).root : xml
143
+ node.slop! if node.is_a? Nokogiri::XML::Document unless node.respond_to? :method_missing
144
+ node = node.root if node.is_a? Nokogiri::XML::Document
145
+ node
146
+ end
147
+
148
+ def expect_node(node_name, xml)
149
+ raise "Xml is not a #{node_name} node." unless xml.name == node_name
150
+ end
151
+ end
152
+
153
+ extend ClassMethods
154
+
155
+ def self.included( other )
156
+ other.extend( ClassMethods )
157
+ end
158
+ end
159
+ end
160
+ end
@@ -0,0 +1,829 @@
1
+ #-------------------------------------------------------------------------
2
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #--------------------------------------------------------------------------
15
+ require 'azure/core/signed_service'
16
+ require 'azure/service_bus/auth/wrap_signer'
17
+ require 'azure/service_bus/serialization'
18
+
19
+ require 'azure/service_bus/brokered_message_serializer'
20
+ require 'azure/core/http/http_response'
21
+
22
+ module Azure
23
+ module ServiceBus
24
+ class ServiceBusService < Azure::Core::SignedService
25
+
26
+ DEFAULT_TIMEOUT = 60
27
+
28
+ def initialize(host=Azure.config.service_bus_host)
29
+ super(Azure::ServiceBus::Auth::WrapSigner.new)
30
+ @host = host
31
+
32
+ with_filter do |req, res|
33
+ req.headers.delete "x-ms-date"
34
+ req.headers.delete "x-ms-version"
35
+ req.headers.delete "DataServiceVersion"
36
+ req.headers.delete "MaxDataServiceVersion"
37
+ res.call
38
+ end
39
+ end
40
+
41
+ # Creates a new queue. Once created, this queue's resource manifest is immutable.
42
+ #
43
+ # ==== Attributes
44
+ #
45
+ # * +queue+ - Azure::ServiceBus::Queue instance to create on server, or a string of the queue name
46
+ # * +options+ - Hash. The queue properties.
47
+ #
48
+ # ==== Options
49
+ #
50
+ # Accepted key/value pairs in options parameter are:
51
+ # * +:default_message_time_to_live+ - XML datetime. Determines how long a message lives in the associated subscriptions.
52
+ # * +:duplicate_detection_history_time_window+ - XML datetime. Specifies the time span during which the Service Bus will detect message duplication.
53
+ # * +:enable_batched_operations+ - Boolean. Enables or disables service side batching behavior when performing operations for the specific queue.
54
+ # * +:dead_lettering_on_message_expiration:+ - Boolean. This field controls how the Service Bus handles a message whose TTL has expired.
55
+ # * +:lock_duration+ - XML datetime. Determines the amount of time in seconds in which a message should be locked for processing by a receiver.
56
+ # * +:max_delivery_count+ - Number. A message is automatically deadlettered after this number of deliveries.
57
+ # * +:max_size_in_megabytes+ - Number. Specifies the maximum topic size in megabytes
58
+ # * +:message_count+ - Number. Displays the number of messages currently in the queue.
59
+ # * +:requires_duplicate_detection+ - Boolean. If enabled, the topic will detect duplicate messages within the time span specified by the DuplicateDetectionHistoryTimeWindow property
60
+ # * +:requires_session+ - Boolean. If set to true, the queue will be session-aware and only SessionReceiver will be supported.
61
+ # * +:size_in_bytes+ - Number. Reflects the actual bytes toward the topic quota that messages in the topic currently occupy.
62
+ #
63
+ def create_queue(queue, options={})
64
+ queue = _new_or_existing(Azure::ServiceBus::Queue, queue, options ? options : {})
65
+ create_resource_entry(:queue, queue, queue.name)
66
+ end
67
+
68
+ # Deletes an existing queue. This operation will also remove all associated state
69
+ # including messages in the queue.
70
+ #
71
+ # ==== Attributes
72
+ #
73
+ # * +queue+ - Azure::ServiceBus::Queue instance to delete or a string of the queue name
74
+ def delete_queue(queue)
75
+ delete_resource_entry(:queue, _name_for(queue))
76
+ end
77
+
78
+ # Retrieves an existing queue.
79
+ #
80
+ # ==== Attributes
81
+ #
82
+ # * +queue+ - Azure::ServiceBus::Queue instance to retrieve or a string of the queue name
83
+ def get_queue(queue)
84
+ resource_entry(:queue, _name_for(queue))
85
+ end
86
+
87
+ # Enumerates the queues in the service namespace.
88
+ #
89
+ # ==== Attributes
90
+ #
91
+ # * +options+ - Hash. Optional parameters.
92
+ #
93
+ # ==== Options
94
+ #
95
+ # Accepted key/value pairs in options parameter are:
96
+ # * +:skip+ - Integer. Number of queues to skip.
97
+ # * +:top+ - Integer. Number of queues to list.
98
+ def list_queues(options={})
99
+ query = {}
100
+ query["$skip"] = options[:skip].to_i.to_s if options[:skip]
101
+ query["$top"] = options[:top].to_i.to_s if options[:top]
102
+
103
+ resource_list(:queue, query)
104
+ end
105
+
106
+ # Creates a new topic. Once created, this topic resource manifest is immutable.
107
+ #
108
+ # ==== Attributes
109
+ #
110
+ # * +topic+ - Azure::ServiceBus::Topic instance to create on server, or a string of the topic name
111
+ # * +options+ - Hash. The topic properties.
112
+ #
113
+ # ==== Options
114
+ #
115
+ # Accepted key/value pairs in options parameter are:
116
+ # * +:default_message_time_to_tive+ - XML datetime. Determines how long a message lives in the associated subscriptions.
117
+ # * +:maximum_number_of_subscriptions+ - Number. Specifies the maximum number of subscriptions that can be associated with the topic.
118
+ # * +:max_size_in_megabytes+ - Number. Specifies the maximum topic size in megabytes
119
+ # * +:requires_duplicate_detection+ - Boolean. If enabled, the topic will detect duplicate messages within the time span specified by the DuplicateDetectionHistoryTimeWindow property
120
+ # * +:dead_lettering_on_filter_evaluation_exceptions+ - Boolean. Determines how the Service Bus handles a message that causes an exception during a subscription's filter evaluation.
121
+ # * +:duplicate_detection_history_time_window+ - XML datetime. Specifies the time span during which the Service Bus will detect message duplication.
122
+ # * +:enable_batched_operations+ - Boolean. Enables or disables service side batching behavior when performing operations for the specific queue.
123
+ #
124
+ def create_topic(topic, options={})
125
+ topic = _new_or_existing(Azure::ServiceBus::Topic, topic, options ? options : {})
126
+ create_resource_entry(:topic, topic, topic.name)
127
+ end
128
+
129
+ # Deletes an existing topic. This operation will also remove all associated state
130
+ # including associated subscriptions.
131
+ #
132
+ # ==== Attributes
133
+ #
134
+ # * +topic+ - Azure::ServiceBus::Topic instance to delete or a string of the topic name
135
+ def delete_topic(topic)
136
+ delete_resource_entry(:topic, _name_for(topic))
137
+ end
138
+
139
+ # Retrieves the description for the specified topic.
140
+ #
141
+ # ==== Attributes
142
+ #
143
+ # * +topic+ - Azure::ServiceBus::Topic instance to retrieve or a string of the topic name
144
+ def get_topic(topic)
145
+ resource_entry(:topic, _name_for(topic))
146
+ end
147
+
148
+ # Retrieves the topics in the service namespace.
149
+ #
150
+ # ==== Attributes
151
+ #
152
+ # * +options+ - Hash. Optional parameters.
153
+ #
154
+ # ==== Options
155
+ #
156
+ # Accepted key/value pairs in options parameter are:
157
+ # * +:skip+ - Integer. Number of topics to skip.
158
+ # * +:top+ - Integer. Number of topics to list.
159
+ def list_topics(options={})
160
+ query = {}
161
+ query["$skip"] = options[:skip].to_i.to_s if options[:skip]
162
+ query["$top"] = options[:top].to_i.to_s if options[:top]
163
+
164
+ resource_list(:topic, query)
165
+ end
166
+
167
+ # Creates a new rule. Once created, this rule's resource manifest is immutable.
168
+ #
169
+ # ==== Attributes
170
+ #
171
+ # Pass either (topic_name, subscription_name, rule_name) as strings, or (rule) a rule object.
172
+ # When using (topic_name, subscription_name, rule_name, options) overload, you may also pass the properties for the rule.
173
+ #
174
+ # ==== Options
175
+ #
176
+ # Accepted key/value pairs in options parameter are:
177
+ # * +:filter+ - String. The rule filter.
178
+ # * +:action+ - String. The rule action.
179
+ #
180
+ def create_rule(*p)
181
+ rule = _rule_from(*p)
182
+ result = create_resource_entry(:rule, rule, rule.topic, rule.subscription, rule.name)
183
+ result.topic = rule.topic
184
+ result.subscription = rule.subscription
185
+ result
186
+ end
187
+
188
+ # Deletes an existing rule.
189
+ #
190
+ # ==== Attributes
191
+ #
192
+ # Pass either (topic_name, subscription_name, rule_name) as strings, or (rule) a object with .name, .topic, and
193
+ # .subscription methods such as Azure::ServiceBus::Rule instance.
194
+ #
195
+ # Note: The default rule name is '$Default'. Use this name to delete the default rule for the subscription.
196
+ def delete_rule(*p)
197
+ topic_name, subscription_name, rule_name = _rule_args(*p)
198
+
199
+ delete_resource_entry(:rule, topic_name, subscription_name, rule_name)
200
+ end
201
+
202
+ # Retrieves the description for the specified rule.
203
+ #
204
+ # ==== Attributes
205
+ #
206
+ # Pass either (topic_name, subscription_name, rule_name) as strings, or (rule) a object with .name, .topic, and
207
+ # .subscription methods such as Azure::ServiceBus::Rule instance.
208
+ #
209
+ # Note: The default rule name is '$Default'. Use this name to retrieve the default rule for the subscription.
210
+ def get_rule(*p)
211
+ topic_name, subscription_name, rule_name = _rule_args(*p)
212
+
213
+ result = resource_entry(:rule, topic_name, subscription_name, rule_name)
214
+ result.topic = topic_name
215
+ result.subscription = subscription_name
216
+ result
217
+ end
218
+
219
+ # Retrieves the rules that exist under the specified subscription.
220
+ #
221
+ # ==== Attributes
222
+ #
223
+ # Pass either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods
224
+ # such as Azure::ServiceBus::Subscription instance.
225
+ #
226
+ # * +options+ - Hash. Optional parameters.
227
+ #
228
+ # ==== Options
229
+ #
230
+ # Accepted key/value pairs in options parameter are:
231
+ # * +:skip+ - Integer. Number of topics to skip.
232
+ # * +:top+ - Integer. Number of topics to list.
233
+ def list_rules(*p)
234
+ topic_name, subscription_name, options = _subscription_args(*p)
235
+
236
+ query = {}
237
+ query["$skip"] = options[:skip].to_i.to_s if options[:skip]
238
+ query["$top"] = options[:top].to_i.to_s if options[:top]
239
+
240
+ results = resource_list(:rule, topic_name, subscription_name, query)
241
+ results.each{|r| r.topic = topic_name; r.subscription=subscription_name}
242
+
243
+ return results
244
+ end
245
+
246
+ # Creates a new subscription. Once created, this subscription resource manifest is
247
+ # immutable.
248
+ #
249
+ # ==== Attributes
250
+ #
251
+ # Pass either (topic_name, subscription_name) as strings, or (subscription) a object.
252
+ # When using (topic_name, subscription_name) overload, you may also pass optional properties for the subscription.
253
+ #
254
+ # ==== Options
255
+ #
256
+ # Accepted key/value pairs in options parameter are:
257
+ # * +:lock_duration+ - XML datetime. Determines the amount of time in seconds in which a message should be locked for processing by a receiver.
258
+ # * +:requires_session+ - Boolean. If set to true, the queue will be session-aware and only SessionReceiver will be supported.
259
+ # * +:default_message_time_to_live+ - XML datetime. Determines how long a message lives in the associated subscriptions.
260
+ # * +:dead_lettering_on_message_expiration:+ - Boolean. This field controls how the Service Bus handles a message whose TTL has expired.
261
+ # * +:dead_lettering_on_filter_evaluation_exceptions+ - Boolean. Determines how the Service Bus handles a message that causes an exception during a subscription's filter evaluation.
262
+ # * +:enable_batched_operations+ - Boolean. Enables or disables service side batching behavior when performing operations for the specific queue.
263
+ # * +:max_delivery_count+ - Number. A message is automatically deadlettered after this number of deliveries.
264
+ # * +:message_count+ - Number. Displays the number of messages currently in the queue.
265
+ #
266
+ def create_subscription(*p)
267
+ subscription = _subscription_from(*p)
268
+
269
+ result = create_resource_entry(:subscription, subscription, subscription.topic, subscription.name)
270
+ result.topic = subscription.topic
271
+ result
272
+ end
273
+
274
+ #
275
+ # Deletes an existing subscription.
276
+ #
277
+ # ==== Attributes
278
+ #
279
+ # Pass either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods
280
+ # such as Azure::ServiceBus::Subscription instance.
281
+ def delete_subscription(*p)
282
+ topic_name, subscription_name = _subscription_args(*p)
283
+
284
+ delete_resource_entry(:subscription, topic_name, subscription_name)
285
+ end
286
+
287
+ # Gets an existing subscription.
288
+ #
289
+ # ==== Attributes
290
+ #
291
+ # Pass either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods
292
+ # such as Azure::ServiceBus::Subscription instance.
293
+ def get_subscription(*p)
294
+ topic_name, subscription_name = _subscription_args(*p)
295
+
296
+ result = resource_entry(:subscription, topic_name, subscription_name)
297
+ result.topic = topic_name
298
+ result
299
+ end
300
+
301
+ # Retrieves the subscriptions in the specified topic.
302
+ #
303
+ # ==== Attributes
304
+ #
305
+ # * +topic+ - Either a Azure::ServiceBus::Topic instance or a string of the topic name
306
+ # * +options+ - Hash. Optional parameters.
307
+ #
308
+ # ==== Options
309
+ #
310
+ # Accepted key/value pairs in options parameter are:
311
+ # * +:skip+ - Integer. Number of subscriptions to skip.
312
+ # * +:top+ - Integer. Number of subscriptions to list.
313
+ def list_subscriptions(topic, options={})
314
+ topic = _name_for(topic)
315
+ query = {}
316
+ query["$skip"] = options[:skip].to_i.to_s if options[:skip]
317
+ query["$top"] = options[:top].to_i.to_s if options[:top]
318
+
319
+ results = resource_list(:subscription, topic, query)
320
+ results.each { |s| s.topic = topic }
321
+
322
+ return results
323
+ end
324
+
325
+ # Enqueues a message into the specified topic. The limit to the number of messages
326
+ # which may be present in the topic is governed by the message size in MaxTopicSizeInBytes.
327
+ # If this message causes the topic to exceed its quota, a quota exceeded error is
328
+ # returned and the message will be rejected.
329
+ #
330
+ # ==== Attributes
331
+ #
332
+ # * +topic+ - Either a Azure::ServiceBus::Topic instance or a string of the topic name
333
+ # * +message+ - An Azure::ServiceBus::BrokeredMessage object containing message body and properties,
334
+ # or a string of the message body (a default BrokeredMessage will be created from the string).
335
+ def send_topic_message(topic, message)
336
+ _send_message(_name_for(topic), message)
337
+ end
338
+
339
+ # This operation is used to atomically retrieve and lock a message for processing.
340
+ # The message is guaranteed not to be delivered to other receivers during the lock
341
+ # duration period specified in buffer description. Once the lock expires, the
342
+ # message will be available to other receivers (on the same subscription only)
343
+ # during the lock duration period specified in the topic description. Once the lock
344
+ # expires, the message will be available to other receivers. In order to complete
345
+ # processing of the message, the receiver should issue a delete command with the
346
+ # lock ID received from this operation. To abandon processing of the message and
347
+ # unlock it for other receivers, an Unlock Message command should be issued, or
348
+ # the lock duration period can expire.
349
+ #
350
+ # ==== Attributes
351
+ #
352
+ # * +topic+ - String. The name of the topic or a Topic instance
353
+ # * +subscription+ - String. The name of the subscription or a Subscription instance
354
+ # * +options+ - Hash. Optional parameters.
355
+ #
356
+ # ==== Options
357
+ #
358
+ # Accepted key/value pairs in options parameter are:
359
+ # * +:timeout+ - Integer. Timeout for the REST call.
360
+ def peek_lock_subscription_message(topic, subscription, options={})
361
+ topic = _name_for(topic)
362
+ subscription = _name_for(subscription)
363
+
364
+ _peek_lock_message(subscriptions_path(topic, subscription), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
365
+ end
366
+
367
+ #
368
+ # Unlock a message for processing by other receivers on a given subscription.
369
+ # This operation deletes the lock object, causing the message to be unlocked.
370
+ # A message must have first been locked by a receiver before this operation
371
+ # is called.
372
+ #
373
+ # ==== Attributes
374
+ #
375
+ # * +message+ - String. Either the message location URL or a message object.
376
+ #
377
+ def unlock_subscription_message(message)
378
+ _unlock_message(message)
379
+ end
380
+
381
+ # Read and delete a message from a subscription as an atomic operation. This
382
+ # operation should be used when a best-effort guarantee is sufficient for an
383
+ # application; that is, using this operation it is possible for messages to
384
+ # be lost if processing fails.
385
+ #
386
+ # ==== Attributes
387
+ #
388
+ # * +topic+ - The name of the topic or a Topic instance
389
+ # * +subscription+ - The name of the subscription or a Subscription instance
390
+ # * +options+ - Hash. Optional parameters.
391
+ #
392
+ # ==== Options
393
+ #
394
+ # Accepted key/value pairs in options parameter are:
395
+ # * +:timeout+ - Integer. Timeout for the REST call.
396
+ #
397
+ def read_delete_subscription_message(topic, subscription, options={})
398
+ topic = _name_for(topic)
399
+ subscription = _name_for(subscription)
400
+
401
+ _read_delete_message(subscriptions_path(topic, subscription), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
402
+ end
403
+
404
+ # Completes processing on a locked message and delete it from the subscription.
405
+ # This operation should only be called after processing a previously locked
406
+ # message is successful to maintain At-Least-Once delivery assurances.
407
+ #
408
+ # ==== Attributes
409
+ #
410
+ # * +message+ - String. Either the message location URL or a message object.
411
+ #
412
+ def delete_subscription_message(message)
413
+ _delete_message(message)
414
+ end
415
+
416
+ # Sends a message into the specified queue. The limit to the number of messages
417
+ # which may be present in the topic is governed by the message size the
418
+ # MaxTopicSizeInMegaBytes. If this message will cause the queue to exceed its
419
+ # quota, a quota exceeded error is returned and the message will be rejected.
420
+ #
421
+ # ==== Attributes
422
+ #
423
+ # * +queue+ - Either a Azure::ServiceBus::Queue instance or a string of the queue name
424
+ # * +message+ - An Azure::ServiceBus::BrokeredMessage object containing message body and properties,
425
+ # or a string of the message body (a default BrokeredMessage will be created from the string).
426
+ def send_queue_message(queue, message)
427
+ _send_message(_name_for(queue), message)
428
+ end
429
+
430
+ #
431
+ # Automatically retrieves and locks a message from a queue for processing. The
432
+ # message is guaranteed not to be delivered to other receivers (on the same
433
+ # subscription only) during the lock duration period specified in the queue
434
+ # description. Once the lock expires, the message will be available to other
435
+ # receivers. In order to complete processing of the message, the receiver
436
+ # should issue a delete command with the lock ID received from this operation.
437
+ # To abandon processing of the message and unlock it for other receivers,
438
+ # an Unlock Message command should be issued, or the lock duration period
439
+ # can expire.
440
+ #
441
+ # ==== Attributes
442
+ #
443
+ # * +queue+ - String. Either a Azure::ServiceBus::Queue instance or a string of the queue name
444
+ # * +options+ - Hash. Optional parameters.
445
+ #
446
+ # ==== Options
447
+ #
448
+ # Accepted key/value pairs in options parameter are:
449
+ # * +:timeout+ - Integer. Timeout for the REST call.
450
+ #
451
+ def peek_lock_queue_message(queue, options={})
452
+ _peek_lock_message(_name_for(queue), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
453
+ end
454
+
455
+ # Unlocks a message for processing by other receivers on a given subscription.
456
+ # This operation deletes the lock object, causing the message to be unlocked.
457
+ # A message must have first been locked by a receiver before this operation is
458
+ # called.
459
+ #
460
+ # ==== Attributes
461
+ #
462
+ # * +message+ - String. Either the message location URL or a message object.
463
+ #
464
+ def unlock_queue_message(message)
465
+ _unlock_message(message)
466
+ end
467
+
468
+ # Reads and deletes a message from a queue as an atomic operation. This operation
469
+ # should be used when a best-effort guarantee is sufficient for an application;
470
+ # that is, using this operation it is possible for messages to be lost if
471
+ # processing fails.
472
+ #
473
+ # ==== Attributes
474
+ #
475
+ # * +queue+ - Either a Azure::ServiceBus::Queue instance or a string of the queue name
476
+ # * +options+ - Hash. Optional parameters.
477
+ #
478
+ # ==== Options
479
+ #
480
+ # Accepted key/value pairs in options parameter are:
481
+ # * +:timeout+ - Integer. Timeout for the REST call.
482
+ #
483
+ def read_delete_queue_message(queue, options={})
484
+ _read_delete_message(_name_for(queue), options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT)
485
+ end
486
+
487
+ # Completes processing on a locked message and delete it from the queue. This
488
+ # operation should only be called after processing a previously locked message
489
+ # is successful to maintain At-Least-Once delivery assurances.
490
+ #
491
+ # ==== Attributes
492
+ #
493
+ # * +message+ - String. Either the message location URL or a message object.
494
+ #
495
+ def delete_queue_message(message)
496
+ _delete_message(message)
497
+ end
498
+
499
+ # Public: Receives a queue message.
500
+ #
501
+ # ==== Attributes
502
+ #
503
+ # * +queue+ - String. The queue name.
504
+ # * +options+ - Hash. Optional parameters.
505
+ #
506
+ # ==== Options
507
+ #
508
+ # Accepted key/value pairs in options parameter are:
509
+ # * +:peek_lock+ - Boolean. Lock when peeking.
510
+ # * +:timeout+ - Integer. Timeout for the REST call.
511
+ #
512
+ def receive_queue_message(queue, options={})
513
+ peek_lock = true
514
+ peek_lock = options[:peek_lock] if options[:peek_lock]
515
+
516
+ options[:timeout] = options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT
517
+ if peek_lock
518
+ peek_lock_queue_message(queue, options)
519
+ else
520
+ read_delete_queue_message(queue, options)
521
+ end
522
+ end
523
+
524
+ # Public: Receives a subscription message.
525
+ #
526
+ # ==== Attributes
527
+ #
528
+ # * +topic+ - String. The topic name.
529
+ # * +options+ - Hash. Optional parameters.
530
+ #
531
+ # ==== Options
532
+ #
533
+ # Accepted key/value pairs in options parameter are:
534
+ # * +:peek_lock+ - Boolean. Lock when peeking.
535
+ # * +:timeout+ - Integer. Timeout for the REST call.
536
+ #
537
+ def receive_subscription_message(topic, subscription, options={})
538
+ peek_lock = true
539
+ peek_lock = options[:peek_lock] if options[:peek_lock]
540
+
541
+ options[:timeout] = options[:timeout] ? options[:timeout] : DEFAULT_TIMEOUT
542
+ if peek_lock
543
+ peek_lock_subscription_message(topic, subscription, options)
544
+ else
545
+ read_delete_subscription_message(topic, subscription, options)
546
+ end
547
+ end
548
+
549
+ private
550
+
551
+ def _unlock_message(message)
552
+ _modify_message(:put, message)
553
+ end
554
+
555
+ def _delete_message(message)
556
+ _modify_message(:delete, message)
557
+ end
558
+
559
+ def _modify_message(method, message)
560
+ uri = nil
561
+ if (message.respond_to? :location)
562
+ uri = message.location
563
+ else
564
+ uri = message
565
+ end
566
+
567
+ call(method, uri)
568
+ nil
569
+ end
570
+
571
+ def _send_message(path, message)
572
+ message = Azure::ServiceBus::BrokeredMessage.new(message.to_s) unless message.kind_of?(Azure::ServiceBus::BrokeredMessage)
573
+
574
+ serializer = BrokeredMessageSerializer.new(message)
575
+ broker_properties = serializer.to_json
576
+ message_properties = serializer.get_property_headers
577
+
578
+ content_type = message.content_type || 'text/plain'
579
+
580
+ headers = {
581
+ 'BrokerProperties'=> broker_properties
582
+ }
583
+
584
+ message_properties.each do |k,v|
585
+ headers[k.to_s.encode("UTF-8")] = v.encode("UTF-8")
586
+ end
587
+
588
+ headers["Content-Type"] = content_type
589
+
590
+ call(:post, messages_uri(path), message.body, headers)
591
+ nil
592
+ end
593
+
594
+ def _read_delete_message(path, timeout=DEFAULT_TIMEOUT)
595
+ _retrieve_message(:delete, path, timeout)
596
+ end
597
+
598
+ def _peek_lock_message(path, timeout=DEFAULT_TIMEOUT)
599
+ _retrieve_message(:post, path, timeout)
600
+ end
601
+
602
+ def _retrieve_message(method, path, timeout=DEFAULT_TIMEOUT)
603
+ uri = messages_head_uri(path, { "timeout"=> timeout.to_s })
604
+
605
+ response = call(method, uri)
606
+ (response.status_code == 204) ? nil : BrokeredMessageSerializer.get_from_http_response(response)
607
+ end
608
+
609
+ def _rule_from(*p)
610
+ rule = nil
611
+
612
+ if p.length == 3 or p.length == 4
613
+ rule = Azure::ServiceBus::Rule.new(p[2]) do |r|
614
+ r.topic = p[0]
615
+ r.subscription = p[1]
616
+ r.description = p[3] if p.length == 4
617
+ end
618
+ elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic and p[0].respond_to? :subscription and p[0].respond_to? :description
619
+ rule = p[0]
620
+ else
621
+ raise ArgumentError, "Must provide either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods such as Azure::ServiceBus::Subscription instance."
622
+ end
623
+
624
+ rule
625
+ end
626
+
627
+ def _rule_args(*p)
628
+ if p.length == 3
629
+ topic_name = p[0]
630
+ subscription_name = p[1]
631
+ rule_name = p[2]
632
+ elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic
633
+ topic_name = p[0].topic
634
+ subscription_name = p[0].subscription
635
+ rule_name = p[0].name
636
+ else
637
+ raise ArgumentError, "Must provide either (topic_name, subscription_name, rule_name) as strings, or (rule) a object with .name, .topic, and .subscription methods such as Azure::ServiceBus::Rule instance."
638
+ end
639
+
640
+ return topic_name, subscription_name, rule_name
641
+ end
642
+
643
+ def _subscription_from(*p)
644
+ subscription = nil
645
+
646
+ if p.length == 3
647
+ subscription = Azure::ServiceBus::Subscription.new(p[1], p[2]) do |sub|
648
+ sub.topic = p[0]
649
+ end
650
+ elsif p.length == 2
651
+ subscription = Azure::ServiceBus::Subscription.new(p[1]) do |sub|
652
+ sub.topic = p[0]
653
+ end
654
+ elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic and p[0].respond_to? :description
655
+ subscription = p[0]
656
+ else
657
+ raise ArgumentError, "Must provide either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods such as Azure::ServiceBus::Subscription instance."
658
+ end
659
+
660
+ subscription
661
+ end
662
+
663
+ def _subscription_args(*p)
664
+
665
+ raise ArgumentError, "Not enough args" if p.length < 1
666
+ topic_name = nil
667
+ subscription_name = nil
668
+ options = {}
669
+
670
+ if p.length == 3
671
+ # topic/sub/options
672
+ topic_name = _name_for(p[0])
673
+ subscription_name = _name_for(p[1])
674
+ options =p[2]
675
+ elsif p.length == 2
676
+ # either subscription/options or topic/sub
677
+ if p[0].respond_to? :name and p[0].respond_to? :topic
678
+ topic_name = p[0].topic
679
+ subscription_name = p[0].name
680
+ options =p[1]
681
+ else
682
+ topic_name = _name_for(p[0])
683
+ subscription_name = _name_for(p[1])
684
+ end
685
+ elsif p.length == 1 and p[0].respond_to? :name and p[0].respond_to? :topic
686
+ topic_name = p[0].topic
687
+ subscription_name = p[0].name
688
+ else
689
+ raise ArgumentError, "Must provide either (topic_name, subscription_name) as strings, or (subscription) a object with .name and .topic methods such as Azure::ServiceBus::Subscription instance."
690
+ end
691
+
692
+ return topic_name, subscription_name, options
693
+ end
694
+
695
+ def _name_for(val)
696
+ val.respond_to?(:name) ? val.name : val
697
+ end
698
+
699
+ def _new_or_existing(type, *p)
700
+ p[0].kind_of?(type) ? p[0] : type.new(*p)
701
+ end
702
+
703
+
704
+ def create_resource_entry(resource, entry, *p)
705
+ body = Serialization.resource_to_xml resource, entry
706
+ response = call(:put, self.send("#{resource.to_s}_uri", *p), body)
707
+ results = Serialization.resources_from_xml(resource, response.body)
708
+ results ? results.first : results
709
+ end
710
+
711
+ def delete_resource_entry(resource, *p)
712
+ call(:delete, self.send("#{resource.to_s}_uri", *p))
713
+ nil
714
+ end
715
+
716
+ def resource_entry(resource, *p)
717
+ uri = self.send("#{resource.to_s}_uri", *p)
718
+ response = call(:get, uri)
719
+ results = Serialization.resources_from_xml(resource, response.body)
720
+ result = results ? results.first : results
721
+ raise Azure::Core::Http::HTTPError.new(Azure::Core::Http::HttpResponse.new(Azure::Core::Http::HttpResponse::MockResponse.new(404, '<?xml version="1.0"?><error><code>ResourceNotFound</code><message xml:lang="en-US">The specified resource does not exist.</message></error>', {}), uri)) unless result
722
+ result
723
+ end
724
+
725
+ def resource_list(resource, *p)
726
+ response = call(:get, self.send("#{resource.to_s}_list_uri", *p))
727
+ Serialization.resources_from_xml_with_next_link(resource, response.body)
728
+ end
729
+
730
+ # paths
731
+
732
+ protected
733
+ def message_path(path, sequence_number, lock_token)
734
+ "#{messages_path(path)}/#{sequence_number}/#{lock_token}"
735
+ end
736
+
737
+ protected
738
+ def messages_head_path(path)
739
+ "#{messages_path(path)}/head"
740
+ end
741
+
742
+ protected
743
+ def messages_path(path)
744
+ "#{path}/messages"
745
+ end
746
+
747
+ protected
748
+ def rule_path(topic, subscription, rule)
749
+ "#{subscriptions_path(topic, subscription)}/rules/#{rule}"
750
+ end
751
+
752
+ protected
753
+ def subscriptions_path(topic, subscription)
754
+ "#{topic}/subscriptions/#{subscription}"
755
+ end
756
+
757
+ # messages uris
758
+
759
+ protected
760
+ def message_uri(path, sequence_number, lock_token, query={})
761
+ generate_uri(message_path(path, sequence_number, lock_token), query)
762
+ end
763
+
764
+ protected
765
+ def messages_head_uri(path, query={})
766
+ generate_uri(messages_head_path(path), query)
767
+ end
768
+
769
+ protected
770
+ def messages_uri(path, query={})
771
+ generate_uri(messages_path(path), query)
772
+ end
773
+
774
+ # entry uris
775
+ protected
776
+ def rule_uri(topic, subscription, rule, query={})
777
+ generate_uri(rule_path(topic, subscription, rule), query)
778
+ end
779
+
780
+ protected
781
+ def subscription_uri(topic, subscription, query={})
782
+ generate_uri(subscriptions_path(topic, subscription), query)
783
+ end
784
+
785
+ protected
786
+ def queue_uri(topic, query={})
787
+ generate_uri(topic, query)
788
+ end
789
+
790
+ protected
791
+ def topic_uri(topic, query={})
792
+ generate_uri(topic, query)
793
+ end
794
+
795
+ # list uris
796
+
797
+ protected
798
+ def rule_list_uri(topic, subscription, query={})
799
+ resource_list_uri(:rule, query, subscriptions_path(topic, subscription))
800
+ end
801
+
802
+ protected
803
+ def subscription_list_uri(topic, query={})
804
+ resource_list_uri(:subscription, query, topic)
805
+ end
806
+
807
+ protected
808
+ def queue_list_uri(query={})
809
+ resource_list_uri(:queue, query)
810
+ end
811
+
812
+ protected
813
+ def topic_list_uri(query={})
814
+ resource_list_uri(:topic, query)
815
+ end
816
+
817
+ protected
818
+ def resource_list_uri(resource, query={}, subpath='$Resources')
819
+ skip = query.delete ["$skip"]
820
+ top = query.delete ["$top"]
821
+
822
+ uri = generate_uri("#{subpath}/#{resource.to_s.capitalize}s", query)
823
+ uri.query = [uri.query, "$skip=" + skip].join('&') if skip
824
+ uri.query = [uri.query, "$top=" + top].join('&') if top
825
+ uri
826
+ end
827
+ end
828
+ end
829
+ end