azure-janmg-common 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/lib/azure/core/auth/authorizer.rb +36 -0
  3. data/lib/azure/core/auth/shared_key.rb +125 -0
  4. data/lib/azure/core/auth/shared_key_lite.rb +48 -0
  5. data/lib/azure/core/auth/signer.rb +51 -0
  6. data/lib/azure/core/default.rb +23 -0
  7. data/lib/azure/core/error.rb +21 -0
  8. data/lib/azure/core/filtered_service.rb +45 -0
  9. data/lib/azure/core/http/debug_filter.rb +36 -0
  10. data/lib/azure/core/http/http_error.rb +135 -0
  11. data/lib/azure/core/http/http_filter.rb +53 -0
  12. data/lib/azure/core/http/http_request.rb +195 -0
  13. data/lib/azure/core/http/http_response.rb +102 -0
  14. data/lib/azure/core/http/retry_policy.rb +84 -0
  15. data/lib/azure/core/http/signer_filter.rb +33 -0
  16. data/lib/azure/core/service.rb +46 -0
  17. data/lib/azure/core/signed_service.rb +45 -0
  18. data/lib/azure/core/utility.rb +244 -0
  19. data/lib/azure/core/version.rb +33 -0
  20. data/lib/azure/core.rb +47 -0
  21. data/lib/azure/http_response_helper.rb +38 -0
  22. data/lib/azure/storage/common/autoload.rb +63 -0
  23. data/lib/azure/storage/common/client.rb +162 -0
  24. data/lib/azure/storage/common/client_options.rb +363 -0
  25. data/lib/azure/storage/common/client_options_error.rb +41 -0
  26. data/lib/azure/storage/common/configurable.rb +212 -0
  27. data/lib/azure/storage/common/core/auth/anonymous_signer.rb +43 -0
  28. data/lib/azure/storage/common/core/auth/shared_access_signature.rb +30 -0
  29. data/lib/azure/storage/common/core/auth/shared_access_signature_generator.rb +399 -0
  30. data/lib/azure/storage/common/core/auth/shared_access_signature_signer.rb +57 -0
  31. data/lib/azure/storage/common/core/auth/shared_key.rb +60 -0
  32. data/lib/azure/storage/common/core/auth/token_signer.rb +43 -0
  33. data/lib/azure/storage/common/core/autoload.rb +53 -0
  34. data/lib/azure/storage/common/core/error.rb +43 -0
  35. data/lib/azure/storage/common/core/filter/exponential_retry_filter.rb +64 -0
  36. data/lib/azure/storage/common/core/filter/linear_retry_filter.rb +55 -0
  37. data/lib/azure/storage/common/core/filter/retry_filter.rb +300 -0
  38. data/lib/azure/storage/common/core/http_client.rb +82 -0
  39. data/lib/azure/storage/common/core/sr.rb +85 -0
  40. data/lib/azure/storage/common/core/token_credential.rb +64 -0
  41. data/lib/azure/storage/common/core/utility.rb +261 -0
  42. data/lib/azure/storage/common/core.rb +35 -0
  43. data/lib/azure/storage/common/default.rb +868 -0
  44. data/lib/azure/storage/common/service/access_policy.rb +37 -0
  45. data/lib/azure/storage/common/service/cors.rb +38 -0
  46. data/lib/azure/storage/common/service/cors_rule.rb +48 -0
  47. data/lib/azure/storage/common/service/enumeration_results.rb +32 -0
  48. data/lib/azure/storage/common/service/geo_replication.rb +40 -0
  49. data/lib/azure/storage/common/service/logging.rb +47 -0
  50. data/lib/azure/storage/common/service/metrics.rb +45 -0
  51. data/lib/azure/storage/common/service/retention_policy.rb +37 -0
  52. data/lib/azure/storage/common/service/serialization.rb +335 -0
  53. data/lib/azure/storage/common/service/signed_identifier.rb +40 -0
  54. data/lib/azure/storage/common/service/storage_service.rb +322 -0
  55. data/lib/azure/storage/common/service/storage_service_properties.rb +48 -0
  56. data/lib/azure/storage/common/service/storage_service_stats.rb +39 -0
  57. data/lib/azure/storage/common/service/user_delegation_key.rb +50 -0
  58. data/lib/azure/storage/common/version.rb +49 -0
  59. data/lib/azure/storage/common.rb +26 -0
  60. metadata +280 -0
@@ -0,0 +1,64 @@
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
+ require "azure/core"
27
+
28
+ module Azure::Storage::Common::Core
29
+ class TokenCredential
30
+
31
+ # Public: Initializes an instance of [Azure::Storage::Common::Core::TokenCredential]
32
+ #
33
+ # ==== Attributes
34
+ #
35
+ # * +token+ - String. The initial access token.
36
+ #
37
+ def initialize(token)
38
+ @token = token
39
+ @mutex = Mutex.new
40
+ end
41
+
42
+ # Public: Gets the access token
43
+ #
44
+ # Note: Providing this getter under the protect of a mutex
45
+ #
46
+ def token
47
+ @mutex.synchronize do
48
+ @token
49
+ end
50
+ end
51
+
52
+ # Public: Renews the access token
53
+ #
54
+ # ==== Attributes
55
+ #
56
+ # * +new_token+ - String. The new access token.
57
+ #
58
+ def renew_token(new_token)
59
+ @mutex.synchronize do
60
+ @token = new_token
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,261 @@
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 "ipaddr"
28
+ require "azure/storage/common/core/error"
29
+
30
+ if RUBY_VERSION.to_f < 2.0
31
+ begin
32
+ require "Win32/Console/ANSI" if RUBY_PLATFORM =~ /win32|mingw32/
33
+ rescue LoadError
34
+ puts "WARNING: Output will look weird on Windows unless"\
35
+ ' you install the "win32console" gem.'
36
+ end
37
+ end
38
+
39
+ module Azure::Storage::Common
40
+ module Error
41
+ # Azure Error
42
+ class Error < Azure::Core::Error
43
+ attr_reader :description
44
+ attr_reader :status_code
45
+ attr_reader :type
46
+
47
+ def initialize(type, status, description)
48
+ @type = type
49
+ @status_code = status
50
+ @description = description
51
+ super("#{type} (#{status_code}): #{description}")
52
+ end
53
+ end
54
+ end
55
+
56
+ module Core
57
+ module Utility
58
+ def random_string(str = "azure", no_of_char = 5)
59
+ str + (0...no_of_char).map { ("a".."z").to_a[rand(26)] }.join
60
+ end
61
+
62
+ def xml_content(xml, key, default = "")
63
+ content = default
64
+ node = xml.at_css(key)
65
+ content = node.text if node
66
+ content
67
+ end
68
+
69
+ def locate_file(name)
70
+ if File.exist? name
71
+ name
72
+ elsif File.exist?(File.join(ENV["HOME"], name))
73
+ File.join(ENV["HOME"], name)
74
+ else
75
+ Azure::Loggerx.error_with_exit "Unable to find #{name} file "
76
+ end
77
+ end
78
+
79
+ def export_der(cert, key, pass = nil, name = nil)
80
+ pkcs12 = OpenSSL::PKCS12.create(pass, name, key, cert)
81
+ Base64.encode64(pkcs12.to_der)
82
+ rescue Exception => e
83
+ puts e.message
84
+ abort
85
+ end
86
+
87
+ def export_fingerprint(certificate)
88
+ Digest::SHA1.hexdigest(certificate.to_der)
89
+ end
90
+
91
+ def enable_winrm?(winrm_transport)
92
+ (!winrm_transport.nil? && (winrm_transport.select { |x| x.downcase == "http" || x.downcase == "https" }.size > 0))
93
+ end
94
+
95
+ def get_certificate(private_key_file)
96
+ rsa = OpenSSL::PKey.read File.read(private_key_file)
97
+ cert = OpenSSL::X509::Certificate.new
98
+ cert.version = 2
99
+ cert.serial = 0
100
+ name = OpenSSL::X509::Name.new([["CN", "Azure Management Certificate"]])
101
+ cert.subject = cert.issuer = name
102
+ cert.not_before = Time.now
103
+ cert.not_after = cert.not_before + (60 * 60 * 24 * 365)
104
+ cert.public_key = rsa.public_key
105
+ cert.sign(rsa, OpenSSL::Digest::SHA1.new)
106
+ cert
107
+ end
108
+
109
+ def initialize_external_logger(logger)
110
+ Loggerx.initialize_external_logger(logger)
111
+ end
112
+
113
+ def parse_charset_from_content_type(content_type)
114
+ if (content_type && content_type.length > 0)
115
+ charset = content_type.split(";").delete_if { |attribute| !attribute.lstrip.start_with?("charset=") }.map { |x| x.lstrip }[0]
116
+ charset["charset=".length...charset.length] if charset
117
+ end
118
+ end
119
+ end
120
+
121
+ # Logger
122
+ module Logger
123
+ class << self
124
+ attr_accessor :logger
125
+
126
+ def info(msg)
127
+ if logger.nil?
128
+ puts msg.bold.white
129
+ else
130
+ logger.info(msg)
131
+ end
132
+ end
133
+
134
+ def error_with_exit(msg)
135
+ if logger.nil?
136
+ puts msg.bold.red
137
+ else
138
+ logger.error(msg)
139
+ end
140
+
141
+ raise msg.bold.red
142
+ end
143
+
144
+ def warn(msg)
145
+ if logger.nil?
146
+ puts msg.yellow
147
+ else
148
+ logger.warn(msg)
149
+ end
150
+
151
+ msg
152
+ end
153
+
154
+ def error(msg)
155
+ if logger.nil?
156
+ puts msg.bold.red
157
+ else
158
+ logger.error(msg)
159
+ end
160
+
161
+ msg
162
+ end
163
+
164
+ def exception_message(msg)
165
+ if logger.nil?
166
+ puts msg.bold.red
167
+ else
168
+ logger.warn(msg)
169
+ end
170
+
171
+ raise msg.bold.red
172
+ end
173
+
174
+ def success(msg)
175
+ msg_with_new_line = msg + "\n"
176
+ if logger.nil?
177
+ print msg_with_new_line.green
178
+ else
179
+ logger.info(msg)
180
+ end
181
+ end
182
+
183
+ def initialize_external_logger(logger)
184
+ @logger = logger
185
+ end
186
+ end
187
+ end
188
+ end
189
+ end
190
+
191
+ class String
192
+ { reset: 0,
193
+ bold: 1,
194
+ dark: 2,
195
+ underline: 4,
196
+ blink: 5,
197
+ orange: 6,
198
+ negative: 7,
199
+ black: 30,
200
+ red: 31,
201
+ green: 32,
202
+ yellow: 33,
203
+ blue: 34,
204
+ magenta: 35,
205
+ cyan: 36,
206
+ white: 37,
207
+ }.each do |key, value|
208
+ define_method key do
209
+ "\e[#{value}m" + self + "\e[0m"
210
+ end
211
+ end
212
+ end
213
+
214
+ # Code validate private/public IP acceptable ranges.
215
+ class IPAddr
216
+ PRIVATE_RANGES = [
217
+ IPAddr.new('10.0.0.0/8'),
218
+ IPAddr.new('172.16.0.0/12'),
219
+ IPAddr.new('192.168.0.0/16')
220
+ ]
221
+
222
+ def private?
223
+ return false unless self.ipv4?
224
+ PRIVATE_RANGES.each do |ipr|
225
+ return true if ipr.include?(self)
226
+ end
227
+ false
228
+ end
229
+
230
+ def public?
231
+ !private?
232
+ end
233
+
234
+ class << self
235
+ def validate_ip_and_prefix(ip, cidr)
236
+ if cidr.to_s.empty?
237
+ raise "Cidr is missing for IP '#{ip}'."
238
+ elsif valid?(ip)
239
+ raise "Ip address '#{ip}' is invalid."
240
+ elsif !IPAddr.new(ip).private?
241
+ raise "Ip Address #{ip} must be private."
242
+ end
243
+ end
244
+
245
+ def validate_address_space(ip)
246
+ if ip.split("/").size != 2
247
+ raise "Cidr is invalid for IP #{ip}."
248
+ elsif valid?(ip)
249
+ raise "Address space '#{ip}' is invalid."
250
+ end
251
+ end
252
+
253
+ def address_prefix(ip, cidr)
254
+ ip + "/" + cidr.to_s
255
+ end
256
+
257
+ def valid?(ip)
258
+ (IPAddr.new(ip) rescue nil).nil?
259
+ end
260
+ end
261
+ end
@@ -0,0 +1,35 @@
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
28
+ module Storage
29
+ end
30
+ end
31
+
32
+ require "azure/storage/common/core/error"
33
+ require "azure/storage/common/default"
34
+ require "azure/storage/common/core/sr"
35
+ require "azure/storage/common/core/utility"