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,32 @@
|
|
1
|
+
module Azure
|
2
|
+
module ServiceRuntime
|
3
|
+
class RoleEnvironmentChange
|
4
|
+
end
|
5
|
+
|
6
|
+
class RoleEnvironmentConfigurationSettingChange < RoleEnvironmentChange
|
7
|
+
attr_reader :configuration_setting_name
|
8
|
+
alias :name :configuration_setting_name
|
9
|
+
|
10
|
+
def initialize(configuration_setting_name)
|
11
|
+
@configuration_setting_name = configuration_setting_name
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
@configuration_setting_name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class RoleEnvironmentTopologyChange < RoleEnvironmentChange
|
20
|
+
attr_reader :role_name
|
21
|
+
alias :name :role_name
|
22
|
+
|
23
|
+
def initialize(role_name)
|
24
|
+
@role_name = role_name
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
@role_name
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'azure/service_runtime/role_instance_endpoint'
|
2
|
+
require 'azure/service_runtime/local_resource'
|
3
|
+
|
4
|
+
module Azure
|
5
|
+
module ServiceRuntime
|
6
|
+
class RoleInstance
|
7
|
+
attr_accessor :id, :role_name, :fault_domain, :update_domain, :endpoints, :configuration_settings, :local_resources
|
8
|
+
alias :instance_endpoints :endpoints
|
9
|
+
|
10
|
+
def initialize(node)
|
11
|
+
self.id = node["id"]
|
12
|
+
self.fault_domain = node["faultDomain"].to_i
|
13
|
+
self.update_domain = node["updateDomain"].to_i
|
14
|
+
self.role_name = node["roleName"]
|
15
|
+
|
16
|
+
self.endpoints = node.css('Endpoints > Endpoint').inject({}) do |hash, endpoint_xml|
|
17
|
+
endpoint = RoleInstanceEndpoint.new(endpoint_xml)
|
18
|
+
hash[endpoint.name] = endpoint
|
19
|
+
hash
|
20
|
+
end
|
21
|
+
|
22
|
+
self.configuration_settings = node.css('ConfigurationSettings > ConfigurationSetting').inject({}) do |hash, setting_xml|
|
23
|
+
hash[setting_xml["name"]] = setting_xml["value"]
|
24
|
+
hash
|
25
|
+
end
|
26
|
+
|
27
|
+
self.local_resources = node.css('LocalResources > LocalResource').inject({}) do |hash, local_resource_xml|
|
28
|
+
local_resource = LocalResource.new(local_resource_xml)
|
29
|
+
hash[local_resource.name] = local_resource
|
30
|
+
hash
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Azure
|
2
|
+
module ServiceRuntime
|
3
|
+
class RoleInstanceEndpoint
|
4
|
+
attr_accessor :name, :address, :port, :protocol
|
5
|
+
|
6
|
+
def initialize(node)
|
7
|
+
self.name = node["name"]
|
8
|
+
self.address = node["address"]
|
9
|
+
self.port = node["port"].to_i
|
10
|
+
self.protocol = node["protocol"]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/azure/tables.rb
ADDED
@@ -0,0 +1,215 @@
|
|
1
|
+
require "azure/tables/service"
|
2
|
+
require "azure/tables/table"
|
3
|
+
require "azure/tables/entity"
|
4
|
+
require "azure/tables/entities_collection"
|
5
|
+
require "azure/tables/tables_collection"
|
6
|
+
require "azure/atom"
|
7
|
+
|
8
|
+
module Azure
|
9
|
+
module Tables
|
10
|
+
# Public: Get a list of Tables from the server.
|
11
|
+
#
|
12
|
+
# query - Options for this query.
|
13
|
+
# service - The backend service to implement this (optional).
|
14
|
+
#
|
15
|
+
# Returns an Array of Table elements.
|
16
|
+
def self.all(query = {}, service=Azure::Tables::Services::QueryTables.new)
|
17
|
+
response = service.call(query)
|
18
|
+
feed = Atom::Feed.load_feed(response.body)
|
19
|
+
collection = Azure::Tables::TablesCollection.from_entries(feed.entries, query)
|
20
|
+
|
21
|
+
collection.continuation_token(
|
22
|
+
response.headers["x-ms-continuation-nexttablename"]
|
23
|
+
)
|
24
|
+
|
25
|
+
collection
|
26
|
+
end
|
27
|
+
|
28
|
+
# Public: Get a single table by name. If the operation is unsuccessful, the
|
29
|
+
# resulting table is invalidated.
|
30
|
+
#
|
31
|
+
# name - The name of the table.
|
32
|
+
# service - The backend service to implement this (optional).
|
33
|
+
#
|
34
|
+
# Returns a Table.
|
35
|
+
def self.fetch(name, service=Azure::Tables::Services::FetchTable.new)
|
36
|
+
response = service.call(name)
|
37
|
+
|
38
|
+
if response.success?
|
39
|
+
Table.from_entry(Atom::Entry.load_entry(response.body))
|
40
|
+
else
|
41
|
+
Table.from_error(response.error)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Public: Attempt to create a new table. If the operation is unsuccessful,
|
46
|
+
# the resulting Table object will have the error accessible through the
|
47
|
+
# table.error method.
|
48
|
+
#
|
49
|
+
# name - The name of the table.
|
50
|
+
# service - The backend service to implement this (optional).
|
51
|
+
#
|
52
|
+
# Returns a Table.
|
53
|
+
def self.create(name, service=Azure::Tables::Services::CreateTable.new)
|
54
|
+
response = service.call(name)
|
55
|
+
|
56
|
+
if response.success?
|
57
|
+
Table.from_entry(Atom::Entry.load_entry(response.body))
|
58
|
+
else
|
59
|
+
Table.from_error(response.error)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Public: Delete a Table from the server.
|
64
|
+
#
|
65
|
+
# table - An Azure::Tables::Table.
|
66
|
+
# service - The backend service to implement this (optional).
|
67
|
+
#
|
68
|
+
# Returns true|false to indicate success.
|
69
|
+
def self.delete(table, service=Azure::Tables::Services::DeleteTable.new)
|
70
|
+
response = service.call(table.url)
|
71
|
+
table.error = response.error unless response.success?
|
72
|
+
response.success?
|
73
|
+
end
|
74
|
+
|
75
|
+
# Public: Inserts a new entity in the given table. If the operation fails an
|
76
|
+
# error will be added to the entity.
|
77
|
+
#
|
78
|
+
# table - An Azure::Tables::Table.
|
79
|
+
# entity - An Azure::Tables::Entity.
|
80
|
+
# service - The backend service to implement this (optional).
|
81
|
+
#
|
82
|
+
# Returns the entity.
|
83
|
+
def self.insert_entity(table, entity, service=Azure::Tables::Services::InsertEntity.new)
|
84
|
+
response = service.call(table.name, entity.attributes)
|
85
|
+
|
86
|
+
if response.success?
|
87
|
+
entity.reset(
|
88
|
+
Entity.from_entry(Azure::Atom::Entry.load_entry(response.body))
|
89
|
+
)
|
90
|
+
entity.etag = response.headers["etag"]
|
91
|
+
else
|
92
|
+
entity.error = response.error
|
93
|
+
end
|
94
|
+
|
95
|
+
entity
|
96
|
+
end
|
97
|
+
|
98
|
+
# Public: Replaces the attributes of an existing entity. In case of an
|
99
|
+
# error, the entity won't be changed and entity.error will be set.
|
100
|
+
#
|
101
|
+
# entity - The entity to update.
|
102
|
+
# attributes - A Hash of attributes. This hash must contain a "PartitionKey"
|
103
|
+
# and a "RowKey".
|
104
|
+
# force - Force this operation even if the object is stale (optional,
|
105
|
+
# defaults to false).
|
106
|
+
# service - The backend service to implement this (optional).
|
107
|
+
#
|
108
|
+
# Returns true|false to indicate success.
|
109
|
+
def self.update_entity(entity, attributes, force=false, service=Azure::Tables::Services::ReplaceEntity.new)
|
110
|
+
etag = force ? Entity::FORCE_UPDATE : entity.etag
|
111
|
+
response = service.call(entity.url, attributes, etag)
|
112
|
+
|
113
|
+
if response.success?
|
114
|
+
entity.attributes.replace(attributes)
|
115
|
+
entity.etag = response.headers["etag"]
|
116
|
+
else
|
117
|
+
entity.error = response.error
|
118
|
+
end
|
119
|
+
|
120
|
+
response.success?
|
121
|
+
end
|
122
|
+
|
123
|
+
# Public: Merge new attributes into an entity. If successful, the entity
|
124
|
+
# will have the new attributes. In case of an error, the entity won't be
|
125
|
+
# changed and entity.error will be set.
|
126
|
+
#
|
127
|
+
# entity - The entity to update.
|
128
|
+
# attributes - A Hash of attributes.
|
129
|
+
# force - Force this operation even if the object is stale (optional,
|
130
|
+
# defaults to false).
|
131
|
+
# service - The backend service to implement this (optional).
|
132
|
+
#
|
133
|
+
# Returns true|false to indicate success.
|
134
|
+
def self.merge_entity(entity, attributes, force=false, service=Azure::Tables::Services::MergeEntity.new)
|
135
|
+
etag = force ? Entity::FORCE_UPDATE : entity.etag
|
136
|
+
response = service.call(entity.url, attributes, etag)
|
137
|
+
|
138
|
+
if response.success?
|
139
|
+
entity.attributes.update(attributes)
|
140
|
+
entity.etag = response.headers["etag"]
|
141
|
+
else
|
142
|
+
entity.error = response.error
|
143
|
+
end
|
144
|
+
|
145
|
+
response.success?
|
146
|
+
end
|
147
|
+
|
148
|
+
# Public: Delete an Entity. If the entity can't be deleted, entity.error
|
149
|
+
# will be set.
|
150
|
+
#
|
151
|
+
# entity - The entity to delete.
|
152
|
+
# force - Force this operation even if the object is stale (optional,
|
153
|
+
# defaults to false).
|
154
|
+
# service - The backend service to implement this (optional).
|
155
|
+
#
|
156
|
+
# Returns true|false to indicate success.
|
157
|
+
def self.delete_entity(entity, force=false, service=Azure::Tables::Services::DeleteEntity.new)
|
158
|
+
etag = force ? Entity::FORCE_UPDATE : entity.etag
|
159
|
+
response = service.call(entity.url, etag)
|
160
|
+
|
161
|
+
if response.success?
|
162
|
+
entity.etag = response.headers["etag"]
|
163
|
+
entity.freeze
|
164
|
+
else
|
165
|
+
entity.error = response.error
|
166
|
+
end
|
167
|
+
|
168
|
+
response.success?
|
169
|
+
end
|
170
|
+
|
171
|
+
# Public: Query a table for a specific entity.
|
172
|
+
#
|
173
|
+
# table - An Azure::Tables::Table.
|
174
|
+
# partition_key - The PartitionKey of the desired entity.
|
175
|
+
# row_key - The RowKey of the desired entity.
|
176
|
+
# service - The backend service to implement this (optional).
|
177
|
+
#
|
178
|
+
# Returns an Entity, or nil if none is found.
|
179
|
+
def self.query_entity(table, partition_key, row_key, query={}, service=Azure::Tables::Services::QueryEntities.new)
|
180
|
+
query.update(partition_key: partition_key, row_key: row_key)
|
181
|
+
response = service.call(table.name, query)
|
182
|
+
|
183
|
+
if response.success?
|
184
|
+
Entity.from_entry(Azure::Atom::Entry.load_entry(response.body))
|
185
|
+
else
|
186
|
+
nil
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
# Public: Query a table for entities.
|
191
|
+
# Options Hash keys *should* be defined using :symbols.
|
192
|
+
#
|
193
|
+
# table - An Azure::Tables::Table.
|
194
|
+
# query - A hash of query options.
|
195
|
+
# service - The backend service to implement this (optional).
|
196
|
+
#
|
197
|
+
# Returns an array of entities.
|
198
|
+
def self.query_entities(table, query={}, service=Azure::Tables::Services::QueryEntities.new)
|
199
|
+
response = service.call(table.name, query)
|
200
|
+
|
201
|
+
if response.success?
|
202
|
+
feed = Atom::Feed.load_feed(response.body)
|
203
|
+
collection = Azure::Tables::EntitiesCollection.from_entries(table, feed.entries, query)
|
204
|
+
collection.continuation_token(
|
205
|
+
response.headers["x-ms-continuation-nextpartitionkey"],
|
206
|
+
response.headers["x-ms-continuation-nextrowkey"]
|
207
|
+
)
|
208
|
+
|
209
|
+
collection
|
210
|
+
else
|
211
|
+
Azure::Tables::EntitiesCollection.new(table, query)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "cgi"
|
2
|
+
require "azure/configuration"
|
3
|
+
require "azure/core/signer"
|
4
|
+
|
5
|
+
module Azure
|
6
|
+
module Tables
|
7
|
+
module Auth
|
8
|
+
class SharedKey < Core::Signer
|
9
|
+
# The Azure account's name.
|
10
|
+
attr :account_name
|
11
|
+
|
12
|
+
# Public: Initialize the Signer.
|
13
|
+
#
|
14
|
+
# account_name - The Azure account name. Defaults to the one in the
|
15
|
+
# global configuration.
|
16
|
+
# access_key - The Azure access_key encoded in Base64. Defaults to the
|
17
|
+
# one in the global configuration.
|
18
|
+
def initialize(account_name=Azure.config.account_name, access_key=Azure.config.access_key)
|
19
|
+
@account_name = account_name
|
20
|
+
super(access_key)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Public: The name of the strategy.
|
24
|
+
#
|
25
|
+
# Returns a String.
|
26
|
+
def name
|
27
|
+
"SharedKey"
|
28
|
+
end
|
29
|
+
|
30
|
+
# Public: Generate a request signature.
|
31
|
+
#
|
32
|
+
# verb - The HTTP request method.
|
33
|
+
# uri - The URI of the request we're signing.
|
34
|
+
# headers - A Hash of HTTP request headers.
|
35
|
+
#
|
36
|
+
# Returns a Base64 String signed with HMAC.
|
37
|
+
def sign(method, uri, headers)
|
38
|
+
super(signable_string(method, uri, headers))
|
39
|
+
end
|
40
|
+
|
41
|
+
# Generate the string to sign.
|
42
|
+
#
|
43
|
+
# verb - The HTTP request method.
|
44
|
+
# uri - The URI of the request we're signing.
|
45
|
+
# headers - A Hash of HTTP request headers.
|
46
|
+
#
|
47
|
+
# Returns a plain text string.
|
48
|
+
def signable_string(method, uri, headers)
|
49
|
+
[
|
50
|
+
method.to_s.upcase,
|
51
|
+
headers.fetch("Content-MD5", ""),
|
52
|
+
headers.fetch("Content-Type", ""),
|
53
|
+
headers.fetch("Date") { headers.fetch("x-ms-date") },
|
54
|
+
canonicalized_resource(uri)
|
55
|
+
].join("\n")
|
56
|
+
end
|
57
|
+
|
58
|
+
# Calculate the Canonicalized Resource string for a request.
|
59
|
+
#
|
60
|
+
# uri - The request's URI.
|
61
|
+
#
|
62
|
+
# Returns a String with the canonicalized resource.
|
63
|
+
def canonicalized_resource(uri)
|
64
|
+
path = "/%s%s" % [account_name, uri.path]
|
65
|
+
query = CGI.parse(uri.query.to_s).fetch("comp", nil)
|
66
|
+
[path, query].compact.join("?")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "azure/tables/auth/shared_key"
|
2
|
+
|
3
|
+
module Azure
|
4
|
+
module Tables
|
5
|
+
module Auth
|
6
|
+
class SharedKeyLite < SharedKey
|
7
|
+
# Public: The name of the strategy.
|
8
|
+
#
|
9
|
+
# Returns a String.
|
10
|
+
def name
|
11
|
+
"SharedKeyLite"
|
12
|
+
end
|
13
|
+
|
14
|
+
# Generate the string to sign.
|
15
|
+
#
|
16
|
+
# verb - The HTTP request method.
|
17
|
+
# uri - The URI of the request we're signing.
|
18
|
+
# headers - A Hash of HTTP request headers.
|
19
|
+
#
|
20
|
+
# Returns a plain text string.
|
21
|
+
def signable_string(method, uri, headers)
|
22
|
+
[
|
23
|
+
headers.fetch("Date") { headers.fetch("x-ms-date") },
|
24
|
+
canonicalized_resource(uri)
|
25
|
+
].join("\n")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require "azure/tables"
|
2
|
+
|
3
|
+
module Azure
|
4
|
+
module Tables
|
5
|
+
|
6
|
+
class EntitiesCollection < Array
|
7
|
+
|
8
|
+
# Public: Create a EntitiesCollection instance.
|
9
|
+
#
|
10
|
+
# table - Azure::Tables::Table instace where entities in this class belongs to.
|
11
|
+
# query - A Hash with the query options passed to the server to get the feed.
|
12
|
+
#
|
13
|
+
# Returns the instance.
|
14
|
+
def initialize(table, query = {}, service = Azure::Tables)
|
15
|
+
@service = service
|
16
|
+
@query = query
|
17
|
+
@table = table
|
18
|
+
end
|
19
|
+
|
20
|
+
# Public: Creates an Azure::Tables::EntitiesCollection from entries feed.
|
21
|
+
#
|
22
|
+
# table - An Azure::Tables::Table instance.
|
23
|
+
# entries - An array of xml entries.
|
24
|
+
# query - A Hash with the query options passed to the server to get the feed.
|
25
|
+
#
|
26
|
+
# Returns an instance of Azure::Tables::EntitiesCollection.
|
27
|
+
def self.from_entries(table, entries, query = {}, service = Azure::Tables)
|
28
|
+
collection = self.new(table, query, service)
|
29
|
+
|
30
|
+
entries.each do |entry|
|
31
|
+
collection << Entity.from_entry(entry)
|
32
|
+
end
|
33
|
+
|
34
|
+
collection
|
35
|
+
end
|
36
|
+
|
37
|
+
# Public: Set continuation tokens for this collection
|
38
|
+
def continuation_token(next_partition_key, next_row_key)
|
39
|
+
@next_partition_key = next_partition_key
|
40
|
+
@next_row_key = next_row_key
|
41
|
+
end
|
42
|
+
|
43
|
+
# Public: Indicates if the collection is a paginated result.
|
44
|
+
# http://msdn.microsoft.com/en-us/library/windowsazure/dd135718
|
45
|
+
#
|
46
|
+
# Returs boolean.
|
47
|
+
def paginated?
|
48
|
+
@next_partition_key ? true : false
|
49
|
+
end
|
50
|
+
|
51
|
+
# Public: Returns continuation results if exists.
|
52
|
+
#
|
53
|
+
# Returns an instance of Azure::Tables::EntitiesCollection
|
54
|
+
def next
|
55
|
+
return nil if !paginated?
|
56
|
+
|
57
|
+
query = @query.merge({
|
58
|
+
"NextPartitionKey" => @next_partition_key,
|
59
|
+
"NextRowKey" => @next_row_key
|
60
|
+
})
|
61
|
+
|
62
|
+
@service.query_entities(@table, query)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|