gitlab-fog-azure-rm 1.9.1 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +1 -1
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +19 -0
- data/gitlab-fog-azure-rm.gemspec +6 -2
- data/lib/azure/core/auth/authorizer.rb +36 -0
- data/lib/azure/core/auth/shared_key.rb +125 -0
- data/lib/azure/core/auth/shared_key_lite.rb +48 -0
- data/lib/azure/core/auth/signer.rb +51 -0
- data/lib/azure/core/default.rb +23 -0
- data/lib/azure/core/error.rb +21 -0
- data/lib/azure/core/filtered_service.rb +45 -0
- data/lib/azure/core/http/debug_filter.rb +36 -0
- data/lib/azure/core/http/http_error.rb +135 -0
- data/lib/azure/core/http/http_filter.rb +53 -0
- data/lib/azure/core/http/http_request.rb +195 -0
- data/lib/azure/core/http/http_response.rb +102 -0
- data/lib/azure/core/http/retry_policy.rb +84 -0
- data/lib/azure/core/http/signer_filter.rb +33 -0
- data/lib/azure/core/service.rb +46 -0
- data/lib/azure/core/signed_service.rb +45 -0
- data/lib/azure/core/utility.rb +244 -0
- data/lib/azure/core/version.rb +33 -0
- data/lib/azure/core.rb +48 -0
- data/lib/azure/http_response_helper.rb +38 -0
- data/lib/azure/storage/blob/append.rb +244 -0
- data/lib/azure/storage/blob/autoload.rb +47 -0
- data/lib/azure/storage/blob/blob.rb +932 -0
- data/lib/azure/storage/blob/blob_service.rb +720 -0
- data/lib/azure/storage/blob/block.rb +530 -0
- data/lib/azure/storage/blob/container.rb +634 -0
- data/lib/azure/storage/blob/default.rb +171 -0
- data/lib/azure/storage/blob/page.rb +566 -0
- data/lib/azure/storage/blob/serialization.rb +351 -0
- data/lib/azure/storage/blob/version.rb +49 -0
- data/lib/azure/storage/blob.rb +26 -0
- data/lib/azure/storage/common/autoload.rb +62 -0
- data/lib/azure/storage/common/client.rb +162 -0
- data/lib/azure/storage/common/client_options.rb +363 -0
- data/lib/azure/storage/common/client_options_error.rb +41 -0
- data/lib/azure/storage/common/configurable.rb +212 -0
- data/lib/azure/storage/common/core/auth/anonymous_signer.rb +43 -0
- data/lib/azure/storage/common/core/auth/shared_access_signature.rb +30 -0
- data/lib/azure/storage/common/core/auth/shared_access_signature_generator.rb +399 -0
- data/lib/azure/storage/common/core/auth/shared_access_signature_signer.rb +57 -0
- data/lib/azure/storage/common/core/auth/shared_key.rb +60 -0
- data/lib/azure/storage/common/core/auth/token_signer.rb +43 -0
- data/lib/azure/storage/common/core/autoload.rb +53 -0
- data/lib/azure/storage/common/core/error.rb +43 -0
- data/lib/azure/storage/common/core/filter/exponential_retry_filter.rb +64 -0
- data/lib/azure/storage/common/core/filter/linear_retry_filter.rb +55 -0
- data/lib/azure/storage/common/core/filter/retry_filter.rb +300 -0
- data/lib/azure/storage/common/core/http_client.rb +82 -0
- data/lib/azure/storage/common/core/sr.rb +85 -0
- data/lib/azure/storage/common/core/token_credential.rb +64 -0
- data/lib/azure/storage/common/core/utility.rb +261 -0
- data/lib/azure/storage/common/core.rb +35 -0
- data/lib/azure/storage/common/default.rb +868 -0
- data/lib/azure/storage/common/service/access_policy.rb +37 -0
- data/lib/azure/storage/common/service/cors.rb +38 -0
- data/lib/azure/storage/common/service/cors_rule.rb +48 -0
- data/lib/azure/storage/common/service/enumeration_results.rb +32 -0
- data/lib/azure/storage/common/service/geo_replication.rb +40 -0
- data/lib/azure/storage/common/service/logging.rb +47 -0
- data/lib/azure/storage/common/service/metrics.rb +45 -0
- data/lib/azure/storage/common/service/retention_policy.rb +37 -0
- data/lib/azure/storage/common/service/serialization.rb +335 -0
- data/lib/azure/storage/common/service/signed_identifier.rb +40 -0
- data/lib/azure/storage/common/service/storage_service.rb +322 -0
- data/lib/azure/storage/common/service/storage_service_properties.rb +48 -0
- data/lib/azure/storage/common/service/storage_service_stats.rb +39 -0
- data/lib/azure/storage/common/service/user_delegation_key.rb +50 -0
- data/lib/azure/storage/common/version.rb +49 -0
- data/lib/azure/storage/common.rb +26 -0
- data/lib/fog/azurerm/version.rb +1 -1
- metadata +122 -5
@@ -0,0 +1,244 @@
|
|
1
|
+
#-------------------------------------------------------------------------
|
2
|
+
# Copyright 2013 Microsoft Open Technologies, Inc.
|
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
|
+
|
16
|
+
require 'ipaddr'
|
17
|
+
|
18
|
+
if RUBY_VERSION.to_f < 2.0
|
19
|
+
begin
|
20
|
+
require 'Win32/Console/ANSI' if RUBY_PLATFORM =~ /win32|mingw32/
|
21
|
+
rescue LoadError
|
22
|
+
puts 'WARNING: Output will look weird on Windows unless'\
|
23
|
+
' you install the "win32console" gem.'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module Azure
|
28
|
+
module Error
|
29
|
+
# Azure Error
|
30
|
+
class Error < Azure::Core::Error
|
31
|
+
attr_reader :description
|
32
|
+
attr_reader :status_code
|
33
|
+
attr_reader :type
|
34
|
+
|
35
|
+
def initialize(type, status, description)
|
36
|
+
@type = type
|
37
|
+
@status_code = status
|
38
|
+
@description = description
|
39
|
+
super("#{type} (#{status_code}): #{description}")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
module Core
|
45
|
+
module Utility
|
46
|
+
def random_string(str = 'azure', no_of_char = 5)
|
47
|
+
str + (0...no_of_char).map { ('a'..'z').to_a[rand(26)] }.join
|
48
|
+
end
|
49
|
+
|
50
|
+
def xml_content(xml, key, default = '')
|
51
|
+
content = default
|
52
|
+
node = xml.at_css(key)
|
53
|
+
content = node.text if node
|
54
|
+
content
|
55
|
+
end
|
56
|
+
|
57
|
+
def locate_file(name)
|
58
|
+
if File.exist? name
|
59
|
+
name
|
60
|
+
elsif File.exist?(File.join(ENV['HOME'], name))
|
61
|
+
File.join(ENV['HOME'], name)
|
62
|
+
else
|
63
|
+
Azure::Loggerx.error_with_exit "Unable to find #{name} file "
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def export_der(cert, key, pass = nil, name = nil)
|
68
|
+
pkcs12 = OpenSSL::PKCS12.create(pass, name, key, cert)
|
69
|
+
Base64.encode64(pkcs12.to_der)
|
70
|
+
rescue Exception => e
|
71
|
+
puts e.message
|
72
|
+
abort
|
73
|
+
end
|
74
|
+
|
75
|
+
def export_fingerprint(certificate)
|
76
|
+
Digest::SHA1.hexdigest(certificate.to_der)
|
77
|
+
end
|
78
|
+
|
79
|
+
def enable_winrm?(winrm_transport)
|
80
|
+
(!winrm_transport.nil? && (winrm_transport.select { |x| x.downcase == 'http' || x.downcase == 'https' }.size > 0))
|
81
|
+
end
|
82
|
+
|
83
|
+
def get_certificate(private_key_file)
|
84
|
+
rsa = OpenSSL::PKey.read File.read(private_key_file)
|
85
|
+
cert = OpenSSL::X509::Certificate.new
|
86
|
+
cert.version = 2
|
87
|
+
cert.serial = 0
|
88
|
+
name = OpenSSL::X509::Name.new([['CN', 'Azure Management Certificate']])
|
89
|
+
cert.subject = cert.issuer = name
|
90
|
+
cert.not_before = Time.now
|
91
|
+
cert.not_after = cert.not_before + (60*60*24*365)
|
92
|
+
cert.public_key = rsa.public_key
|
93
|
+
cert.sign(rsa, OpenSSL::Digest::SHA1.new)
|
94
|
+
cert
|
95
|
+
end
|
96
|
+
|
97
|
+
def initialize_external_logger(logger)
|
98
|
+
Loggerx.initialize_external_logger(logger)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Logger
|
103
|
+
module Logger
|
104
|
+
class << self
|
105
|
+
attr_accessor :logger
|
106
|
+
|
107
|
+
def info(msg)
|
108
|
+
if logger.nil?
|
109
|
+
puts msg.bold.white
|
110
|
+
else
|
111
|
+
logger.info(msg)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def error_with_exit(msg)
|
116
|
+
if logger.nil?
|
117
|
+
puts msg.bold.red
|
118
|
+
else
|
119
|
+
logger.error(msg)
|
120
|
+
end
|
121
|
+
|
122
|
+
raise msg.bold.red
|
123
|
+
end
|
124
|
+
|
125
|
+
def warn(msg)
|
126
|
+
if logger.nil?
|
127
|
+
puts msg.yellow
|
128
|
+
else
|
129
|
+
logger.warn(msg)
|
130
|
+
end
|
131
|
+
|
132
|
+
msg
|
133
|
+
end
|
134
|
+
|
135
|
+
def error(msg)
|
136
|
+
if logger.nil?
|
137
|
+
puts msg.bold.red
|
138
|
+
else
|
139
|
+
logger.error(msg)
|
140
|
+
end
|
141
|
+
|
142
|
+
msg
|
143
|
+
end
|
144
|
+
|
145
|
+
def exception_message(msg)
|
146
|
+
if logger.nil?
|
147
|
+
puts msg.bold.red
|
148
|
+
else
|
149
|
+
logger.warn(msg)
|
150
|
+
end
|
151
|
+
|
152
|
+
raise msg.bold.red
|
153
|
+
end
|
154
|
+
|
155
|
+
def success(msg)
|
156
|
+
msg_with_new_line = msg + "\n"
|
157
|
+
if logger.nil?
|
158
|
+
print msg_with_new_line.green
|
159
|
+
else
|
160
|
+
logger.info(msg)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def initialize_external_logger(logger)
|
165
|
+
@logger = logger
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
class String
|
173
|
+
{ reset: 0,
|
174
|
+
bold: 1,
|
175
|
+
dark: 2,
|
176
|
+
underline: 4,
|
177
|
+
blink: 5,
|
178
|
+
orange: 6,
|
179
|
+
negative: 7,
|
180
|
+
black: 30,
|
181
|
+
red: 31,
|
182
|
+
green: 32,
|
183
|
+
yellow: 33,
|
184
|
+
blue: 34,
|
185
|
+
magenta: 35,
|
186
|
+
cyan: 36,
|
187
|
+
white: 37,
|
188
|
+
}.each do |key, value|
|
189
|
+
define_method key do
|
190
|
+
"\e[#{value}m" + self + "\e[0m"
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
# Code validate private/public IP acceptable ranges.
|
196
|
+
class IPAddr
|
197
|
+
PRIVATE_RANGES = [
|
198
|
+
IPAddr.new('10.0.0.0/8'),
|
199
|
+
IPAddr.new('172.16.0.0/12'),
|
200
|
+
IPAddr.new('192.168.0.0/16')
|
201
|
+
]
|
202
|
+
|
203
|
+
def private?
|
204
|
+
return false unless self.ipv4?
|
205
|
+
PRIVATE_RANGES.each do |ipr|
|
206
|
+
return true if ipr.include?(self)
|
207
|
+
end
|
208
|
+
false
|
209
|
+
end
|
210
|
+
|
211
|
+
def public?
|
212
|
+
!private?
|
213
|
+
end
|
214
|
+
|
215
|
+
class << self
|
216
|
+
def validate_ip_and_prefix(ip, cidr)
|
217
|
+
if cidr.to_s.empty?
|
218
|
+
raise "Cidr is missing for IP '#{ip}'."
|
219
|
+
elsif valid?(ip)
|
220
|
+
raise "Ip address '#{ip}' is invalid."
|
221
|
+
elsif !IPAddr.new(ip).private?
|
222
|
+
raise "Ip Address #{ip} must be private."
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
def validate_address_space(ip)
|
227
|
+
if ip.split('/').size != 2
|
228
|
+
raise "Cidr is invalid for IP #{ip}."
|
229
|
+
elsif valid?(ip)
|
230
|
+
raise "Address space '#{ip}' is invalid."
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
def address_prefix(ip, cidr)
|
235
|
+
ip + '/' + cidr.to_s
|
236
|
+
end
|
237
|
+
|
238
|
+
def valid?(ip)
|
239
|
+
(IPAddr.new(ip) rescue nil).nil?
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
Azure::Loggerx = Azure::Core::Logger
|
@@ -0,0 +1,33 @@
|
|
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
|
+
|
16
|
+
module Azure
|
17
|
+
module Core
|
18
|
+
class Version
|
19
|
+
MAJOR = 0 unless defined? MAJOR
|
20
|
+
MINOR = 2 unless defined? MINOR
|
21
|
+
UPDATE = 0 unless defined? UPDATE
|
22
|
+
PRE = nil unless defined? PRE
|
23
|
+
|
24
|
+
class << self
|
25
|
+
|
26
|
+
# @return [String]
|
27
|
+
def to_s
|
28
|
+
[MAJOR, MINOR, UPDATE].join('.') + (PRE.nil? ? '' : "-#{PRE}")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/azure/core.rb
ADDED
@@ -0,0 +1,48 @@
|
|
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
|
+
|
16
|
+
require 'rubygems'
|
17
|
+
require 'nokogiri'
|
18
|
+
require 'faraday'
|
19
|
+
require 'faraday/follow_redirects'
|
20
|
+
require 'faraday/net_http_persistent'
|
21
|
+
|
22
|
+
module Azure
|
23
|
+
module Core
|
24
|
+
autoload :Utility, 'azure/core/utility'
|
25
|
+
autoload :Logger, 'azure/core/utility'
|
26
|
+
autoload :Error, 'azure/core/error'
|
27
|
+
autoload :Service, 'azure/core/service'
|
28
|
+
autoload :FilteredService, 'azure/core/filtered_service'
|
29
|
+
autoload :SignedService, 'azure/core/signed_service'
|
30
|
+
autoload :Default, 'azure/core/default'
|
31
|
+
module Auth
|
32
|
+
autoload :SharedKey, 'azure/core/auth/shared_key'
|
33
|
+
autoload :Signer, 'azure/core/auth/signer'
|
34
|
+
autoload :Authorizer, 'azure/core/auth/authorizer'
|
35
|
+
autoload :SharedKeyLite, 'azure/core/auth/shared_key_lite'
|
36
|
+
end
|
37
|
+
module Http
|
38
|
+
autoload :DebugFilter, 'azure/core/http/debug_filter'
|
39
|
+
autoload :HTTPError, 'azure/core/http/http_error'
|
40
|
+
autoload :HttpFilter, 'azure/core/http/http_filter'
|
41
|
+
autoload :HttpRequest, 'azure/core/http/http_request'
|
42
|
+
autoload :HttpResponse, 'azure/core/http/http_response'
|
43
|
+
autoload :RetryPolicy, 'azure/core/http/retry_policy'
|
44
|
+
autoload :SignerFilter, 'azure/core/http/signer_filter'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,38 @@
|
|
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
|
+
|
16
|
+
module Azure
|
17
|
+
module HttpResponseHelper
|
18
|
+
|
19
|
+
# Sends request to HTTP server and returns a Faraday::Response
|
20
|
+
# @param method [Symbol] The HTTP method to use (:get, :post, :put, :del, etc...)
|
21
|
+
# @param url [URI] The URI of the HTTP endpoint to query
|
22
|
+
# @param conn [Net::HTTP] http agent for a given uri
|
23
|
+
# @param headers [String] The request headers
|
24
|
+
# @param body [String] The request body
|
25
|
+
#returns Faraday::Response
|
26
|
+
def set_up_response(method, url, conn, headers ,body)
|
27
|
+
conn.run_request(method, url, nil, nil) do |req|
|
28
|
+
req.body = body if body
|
29
|
+
req.headers = headers if headers
|
30
|
+
unless headers.nil?
|
31
|
+
keep_alive = headers['Keep-Alive'] || headers['keep-alive']
|
32
|
+
req.options[:timeout] = keep_alive.split('=').last.to_i unless keep_alive.nil?
|
33
|
+
end
|
34
|
+
req.options[:open_timeout] ||= 60
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,244 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#-------------------------------------------------------------------------
|
4
|
+
# # Copyright (c) Microsoft and contributors. All rights reserved.
|
5
|
+
#
|
6
|
+
# The MIT License(MIT)
|
7
|
+
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
# of this software and associated documentation files(the "Software"), to deal
|
10
|
+
# in the Software without restriction, including without limitation the rights
|
11
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
12
|
+
# copies of the Software, and to permit persons to whom the Software is
|
13
|
+
# furnished to do so, subject to the following conditions :
|
14
|
+
|
15
|
+
# The above copyright notice and this permission notice shall be included in
|
16
|
+
# all copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
# THE SOFTWARE.
|
25
|
+
#--------------------------------------------------------------------------
|
26
|
+
|
27
|
+
module Azure::Storage
|
28
|
+
module Blob
|
29
|
+
# Public: Creates a new append blob. Note that calling create_append_blob to create an append
|
30
|
+
# blob only initializes the blob. To add content to an append blob, call append_blob_blocks method.
|
31
|
+
#
|
32
|
+
# ==== Attributes
|
33
|
+
#
|
34
|
+
# * +container+ - String. The container name.
|
35
|
+
# * +blob+ - String. The blob name.
|
36
|
+
# * +options+ - Hash. Optional parameters.
|
37
|
+
#
|
38
|
+
# ==== Options
|
39
|
+
#
|
40
|
+
# Accepted key/value pairs in options parameter are:
|
41
|
+
# * +:content_type+ - String. Content type for the blob. Will be saved with blob.
|
42
|
+
# * +:content_encoding+ - String. Content encoding for the blob. Will be saved with blob.
|
43
|
+
# * +:content_language+ - String. Content language for the blob. Will be saved with blob.
|
44
|
+
# * +:content_md5+ - String. Content MD5 for the blob. Will be saved with blob.
|
45
|
+
# * +:cache_control+ - String. Cache control for the blob. Will be saved with blob.
|
46
|
+
# * +:content_disposition+ - String. Conveys additional information about how to process the response payload,
|
47
|
+
# and also can be used to attach additional metadata
|
48
|
+
# * +:metadata+ - Hash. Custom metadata values to store with the blob.
|
49
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
50
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
51
|
+
# in the analytics logs when storage analytics logging is enabled.
|
52
|
+
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
|
53
|
+
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
|
54
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
55
|
+
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
|
56
|
+
# only if the blob has not been modified since the specified date/time. If the blob has been modified,
|
57
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
58
|
+
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
|
59
|
+
# only if the blob's ETag value matches the value specified. If the values do not match,
|
60
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
61
|
+
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
|
62
|
+
# only if the blob's ETag value does not match the value specified. If the values are identical,
|
63
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
64
|
+
# * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an active lease,
|
65
|
+
# specify the valid lease ID for this header.
|
66
|
+
#
|
67
|
+
# See http://msdn.microsoft.com/en-us/library/azure/dd179451.aspx
|
68
|
+
#
|
69
|
+
# Returns a Blob
|
70
|
+
def create_append_blob(container, blob, options = {})
|
71
|
+
query = {}
|
72
|
+
StorageService.with_query query, "timeout", options[:timeout] if options[:timeout]
|
73
|
+
|
74
|
+
uri = blob_uri(container, blob, query)
|
75
|
+
|
76
|
+
headers = {}
|
77
|
+
|
78
|
+
# set x-ms-blob-type to AppendBlob
|
79
|
+
StorageService.with_header headers, "x-ms-blob-type", "AppendBlob"
|
80
|
+
|
81
|
+
# ensure content-length is 0
|
82
|
+
StorageService.with_header headers, "Content-Length", 0
|
83
|
+
|
84
|
+
# set the rest of the optional headers
|
85
|
+
StorageService.with_header headers, "x-ms-blob-content-type", options[:content_type]
|
86
|
+
StorageService.with_header headers, "x-ms-blob-content-encoding", options[:content_encoding]
|
87
|
+
StorageService.with_header headers, "x-ms-blob-content-language", options[:content_language]
|
88
|
+
StorageService.with_header headers, "x-ms-blob-content-md5", options[:content_md5]
|
89
|
+
StorageService.with_header headers, "x-ms-blob-cache-control", options[:cache_control]
|
90
|
+
StorageService.with_header headers, "x-ms-blob-content-disposition", options[:content_disposition]
|
91
|
+
|
92
|
+
StorageService.add_metadata_to_headers options[:metadata], headers
|
93
|
+
add_blob_conditional_headers options, headers
|
94
|
+
headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
|
95
|
+
headers["x-ms-blob-content-type"] = Default::CONTENT_TYPE_VALUE unless headers["x-ms-blob-content-type"]
|
96
|
+
|
97
|
+
# call PutBlob with empty body
|
98
|
+
response = call(:put, uri, nil, headers, options)
|
99
|
+
|
100
|
+
result = Serialization.blob_from_headers(response.headers)
|
101
|
+
result.name = blob
|
102
|
+
result.metadata = options[:metadata] if options[:metadata]
|
103
|
+
|
104
|
+
result
|
105
|
+
end
|
106
|
+
|
107
|
+
# Public: Commits a new block of data to the end of an existing append blob.
|
108
|
+
# This operation is permitted only on blobs created with the create_append_blob API.
|
109
|
+
#
|
110
|
+
# ==== Attributes
|
111
|
+
#
|
112
|
+
# * +container+ - String. The container name.
|
113
|
+
# * +blob+ - String. The blob name.
|
114
|
+
# * +content+ - IO or String. The content of the blob.
|
115
|
+
# * +options+ - Hash. Optional parameters.
|
116
|
+
#
|
117
|
+
# ==== Options
|
118
|
+
#
|
119
|
+
# Accepted key/value pairs in options parameter are:
|
120
|
+
# * +:content_md5+ - String. Content MD5 for the request contents.
|
121
|
+
# * +:max_size+ - Integer. The max length in bytes permitted for the append blob
|
122
|
+
# * +:append_position+ - Integer. A number indicating the byte offset to compare. It will succeed only if the append position is equal to this number
|
123
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
124
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
125
|
+
# in the analytics logs when storage analytics logging is enabled.
|
126
|
+
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to append a block only if
|
127
|
+
# the blob has been modified since the specified date/time. If the blob has not been modified,
|
128
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
129
|
+
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to append a block only if
|
130
|
+
# the blob has not been modified since the specified date/time. If the blob has been modified,
|
131
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
132
|
+
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to append a block only if
|
133
|
+
# the blob's ETag value matches the value specified. If the values do not match,
|
134
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
135
|
+
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to append a block only if
|
136
|
+
# the blob's ETag value does not match the value specified. If the values are identical,
|
137
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
138
|
+
# * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an
|
139
|
+
# active lease, specify the valid lease ID for this header.
|
140
|
+
#
|
141
|
+
# See http://msdn.microsoft.com/en-us/library/azure/mt427365.aspx
|
142
|
+
#
|
143
|
+
# Returns a Blob
|
144
|
+
def append_blob_block(container, blob, content, options = {})
|
145
|
+
query = { "comp" => "appendblock" }
|
146
|
+
StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
|
147
|
+
|
148
|
+
uri = blob_uri(container, blob, query)
|
149
|
+
|
150
|
+
headers = {}
|
151
|
+
StorageService.with_header headers, "Content-MD5", options[:content_md5]
|
152
|
+
StorageService.with_header headers, "x-ms-lease-id", options[:lease_id]
|
153
|
+
StorageService.with_header headers, "x-ms-blob-condition-maxsize", options[:max_size]
|
154
|
+
StorageService.with_header headers, "x-ms-blob-condition-appendpos", options[:append_position]
|
155
|
+
|
156
|
+
add_blob_conditional_headers options, headers
|
157
|
+
headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]
|
158
|
+
|
159
|
+
response = call(:put, uri, content, headers, options)
|
160
|
+
result = Serialization.blob_from_headers(response.headers)
|
161
|
+
result.name = blob
|
162
|
+
|
163
|
+
result
|
164
|
+
end
|
165
|
+
|
166
|
+
# Public: Creates a new append blob with given content
|
167
|
+
#
|
168
|
+
# ==== Attributes
|
169
|
+
#
|
170
|
+
# * +container+ - String. The container name.
|
171
|
+
# * +blob+ - String. The blob name.
|
172
|
+
# * +content+ - IO or String. Content to write.
|
173
|
+
# * +options+ - Hash. Optional parameters.
|
174
|
+
#
|
175
|
+
# ==== Options
|
176
|
+
#
|
177
|
+
# Accepted key/value pairs in options parameter are:
|
178
|
+
# * +:content_type+ - String. Content type for the blob. Will be saved with blob.
|
179
|
+
# * +:content_encoding+ - String. Content encoding for the blob. Will be saved with blob.
|
180
|
+
# * +:content_language+ - String. Content language for the blob. Will be saved with blob.
|
181
|
+
# * +:content_md5+ - String. Content MD5 for the blob. Will be saved with blob.
|
182
|
+
# * +:cache_control+ - String. Cache control for the blob. Will be saved with blob.
|
183
|
+
# * +:content_disposition+ - String. Conveys additional information about how to process the response payload,
|
184
|
+
# and also can be used to attach additional metadata
|
185
|
+
# * +:max_size+ - Integer. The max length in bytes permitted for the append blob.
|
186
|
+
# * +:metadata+ - Hash. Custom metadata values to store with the blob.
|
187
|
+
# * +:timeout+ - Integer. A timeout in seconds.
|
188
|
+
# * +:request_id+ - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
|
189
|
+
# in the analytics logs when storage analytics logging is enabled.
|
190
|
+
# * +:if_modified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
|
191
|
+
# only if the blob has been modified since the specified date/time. If the blob has not been modified,
|
192
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
193
|
+
# * +:if_unmodified_since+ - String. A DateTime value. Specify this conditional header to create a new blob
|
194
|
+
# only if the blob has not been modified since the specified date/time. If the blob has been modified,
|
195
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
196
|
+
# * +:if_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
|
197
|
+
# only if the blob's ETag value matches the value specified. If the values do not match,
|
198
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
199
|
+
# * +:if_none_match+ - String. An ETag value. Specify an ETag value for this conditional header to create a new blob
|
200
|
+
# only if the blob's ETag value does not match the value specified. If the values are identical,
|
201
|
+
# the Blob service returns status code 412 (Precondition Failed).
|
202
|
+
# * +:lease_id+ - String. Required if the blob has an active lease. To perform this operation on a blob with an active lease,
|
203
|
+
# specify the valid lease ID for this header.
|
204
|
+
#
|
205
|
+
# See http://msdn.microsoft.com/en-us/library/azure/dd179451.aspx
|
206
|
+
#
|
207
|
+
# Returns a Blob
|
208
|
+
def create_append_blob_from_content(container, blob, content, options = {})
|
209
|
+
# Fail fast if content has larger size than max_size
|
210
|
+
max_size = options.delete :max_size
|
211
|
+
if max_size
|
212
|
+
if content.respond_to?(:size) && max_size < content.size
|
213
|
+
raise Azure::Storage::Common::Core::StorageError.new("Given content has exceeded the specified maximum size for the blob.")
|
214
|
+
end
|
215
|
+
end
|
216
|
+
options[:content_type] = get_or_apply_content_type(content, options[:content_type])
|
217
|
+
create_append_blob(container, blob, options)
|
218
|
+
content = StringIO.new(content) if content.is_a? String
|
219
|
+
# initialize the append block options.
|
220
|
+
append_block_options = {}
|
221
|
+
append_block_options[:if_modified_since] = options[:if_modified_since] if options[:if_modified_since]
|
222
|
+
append_block_options[:if_unmodified_since] = options[:if_unmodified_since] if options[:if_unmodified_since]
|
223
|
+
append_block_options[:if_match] = options[:if_match] if options[:if_match]
|
224
|
+
append_block_options[:if_none_match] = options[:if_none_match] if options[:if_none_match]
|
225
|
+
append_block_options[:lease_id] = options[:lease_id] if options[:lease_id]
|
226
|
+
append_block_options[:max_size] = max_size if max_size
|
227
|
+
position = 0
|
228
|
+
while !content.eof?
|
229
|
+
payload = content.read(BlobConstants::DEFAULT_WRITE_BLOCK_SIZE_IN_BYTES)
|
230
|
+
# set the append position to make sure that each append is going to the correct offset.
|
231
|
+
append_block_options[:append_position] = position
|
232
|
+
append_blob_block(container, blob, payload, append_block_options)
|
233
|
+
# calculate the position after the append.
|
234
|
+
position += payload.size
|
235
|
+
end
|
236
|
+
|
237
|
+
get_properties_options = {}
|
238
|
+
get_properties_options[:lease_id] = options[:lease_id] if options[:lease_id]
|
239
|
+
|
240
|
+
# Get the blob properties
|
241
|
+
get_blob_properties(container, blob, get_properties_options)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#-------------------------------------------------------------------------
|
4
|
+
# # Copyright (c) Microsoft and contributors. All rights reserved.
|
5
|
+
#
|
6
|
+
# The MIT License(MIT)
|
7
|
+
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
# of this software and associated documentation files(the "Software"), to deal
|
10
|
+
# in the Software without restriction, including without limitation the rights
|
11
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
12
|
+
# copies of the Software, and to permit persons to whom the Software is
|
13
|
+
# furnished to do so, subject to the following conditions :
|
14
|
+
|
15
|
+
# The above copyright notice and this permission notice shall be included in
|
16
|
+
# all copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
# THE SOFTWARE.
|
25
|
+
#--------------------------------------------------------------------------
|
26
|
+
|
27
|
+
require "rubygems"
|
28
|
+
require "nokogiri"
|
29
|
+
require "base64"
|
30
|
+
|
31
|
+
require "azure/storage/common"
|
32
|
+
|
33
|
+
module Azure
|
34
|
+
module Storage
|
35
|
+
module Blob
|
36
|
+
autoload :Default, "azure/storage/blob/default"
|
37
|
+
autoload :Version, "azure/storage/blob/version"
|
38
|
+
autoload :Blob, "azure/storage/blob/blob"
|
39
|
+
autoload :Block, "azure/storage/blob/block"
|
40
|
+
autoload :Page, "azure/storage/blob/page"
|
41
|
+
autoload :Append, "azure/storage/blob/append"
|
42
|
+
autoload :Container, "azure/storage/blob/container"
|
43
|
+
autoload :Serialization, "azure/storage/blob/serialization"
|
44
|
+
autoload :BlobService, "azure/storage/blob/blob_service"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|