azure-storage 0.14.0.preview → 0.15.0.preview
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.
- checksums.yaml +4 -4
- data/lib/azure/storage/blob/append.rb +6 -0
- data/lib/azure/storage/blob/blob.rb +80 -3
- data/lib/azure/storage/blob/blob_service.rb +29 -8
- data/lib/azure/storage/blob/block.rb +22 -2
- data/lib/azure/storage/blob/container.rb +57 -6
- data/lib/azure/storage/blob/page.rb +25 -2
- data/lib/azure/storage/client.rb +10 -10
- data/lib/azure/storage/client_options.rb +6 -3
- data/lib/azure/storage/configurable.rb +50 -17
- data/lib/azure/storage/core/auth/anonymous_signer.rb +44 -0
- data/lib/azure/storage/core/filter/retry_filter.rb +123 -12
- data/lib/azure/storage/default.rb +10 -1
- data/lib/azure/storage/file/directory.rb +13 -3
- data/lib/azure/storage/file/file.rb +17 -4
- data/lib/azure/storage/file/file_service.rb +19 -12
- data/lib/azure/storage/file/share.rb +16 -4
- data/lib/azure/storage/queue/queue_service.rb +26 -13
- data/lib/azure/storage/service/geo_replication.rb +40 -0
- data/lib/azure/storage/service/serialization.rb +26 -0
- data/lib/azure/storage/service/storage_service.rb +144 -20
- data/lib/azure/storage/service/storage_service_stats.rb +39 -0
- data/lib/azure/storage/table/table_service.rb +33 -14
- data/lib/azure/storage/version.rb +1 -1
- metadata +5 -2
| @@ -39,7 +39,8 @@ module Azure::Storage | |
| 39 39 | 
             
                    client_config = options[:client] || Azure::Storage
         | 
| 40 40 | 
             
                    signer = options[:signer] || client_config.signer || Core::Auth::SharedKey.new(client_config.storage_account_name, client_config.storage_access_key)
         | 
| 41 41 | 
             
                    super(signer, client_config.storage_account_name, options, &block)
         | 
| 42 | 
            -
                    @ | 
| 42 | 
            +
                    @storage_service_host[:primary] = client.storage_file_host
         | 
| 43 | 
            +
                    @storage_service_host[:secondary] = client.storage_file_host true
         | 
| 43 44 | 
             
                  end
         | 
| 44 45 |  | 
| 45 46 | 
             
                  def call(method, uri, body = nil, headers = {}, options = {})
         | 
| @@ -98,6 +99,9 @@ module Azure::Storage | |
| 98 99 | 
             
                  # * +:request_id+              - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
         | 
| 99 100 | 
             
                  #                                in the analytics logs when storage analytics logging is enabled.
         | 
| 100 101 | 
             
                  #
         | 
| 102 | 
            +
                  # * +:location_mode+           - LocationMode. Specifies the location mode used to decide 
         | 
| 103 | 
            +
                  #                                which location the request should be sent to.
         | 
| 104 | 
            +
                  #
         | 
| 101 105 | 
             
                  # See: https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/list-shares
         | 
| 102 106 | 
             
                  #
         | 
| 103 107 | 
             
                  # Returns an Azure::Service::EnumerationResults
         | 
| @@ -112,7 +116,8 @@ module Azure::Storage | |
| 112 116 | 
             
                      StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
         | 
| 113 117 | 
             
                    end
         | 
| 114 118 |  | 
| 115 | 
            -
                     | 
| 119 | 
            +
                    options[:request_location_mode] = RequestLocationMode::PRIMARY_OR_SECONDARY
         | 
| 120 | 
            +
                    uri = shares_uri(query, options)
         | 
| 116 121 | 
             
                    response = call(:get, uri, nil, {}, options)
         | 
| 117 122 |  | 
| 118 123 | 
             
                    Serialization.share_enumeration_results_from_xml(response.body)
         | 
| @@ -127,9 +132,9 @@ module Azure::Storage | |
| 127 132 | 
             
                  # Returns a URI.
         | 
| 128 133 | 
             
                  #
         | 
| 129 134 | 
             
                  protected
         | 
| 130 | 
            -
                    def shares_uri(query = {})
         | 
| 135 | 
            +
                    def shares_uri(query = {}, options = {})
         | 
| 131 136 | 
             
                      query = { "comp" => "list" }.merge(query)
         | 
| 132 | 
            -
                      generate_uri("", query)
         | 
| 137 | 
            +
                      generate_uri("", query, options)
         | 
| 133 138 | 
             
                    end
         | 
| 134 139 |  | 
| 135 140 | 
             
                  # Protected: Generate the URI for a specific share.
         | 
| @@ -142,10 +147,10 @@ module Azure::Storage | |
| 142 147 | 
             
                  # Returns a URI.
         | 
| 143 148 | 
             
                  #
         | 
| 144 149 | 
             
                  protected
         | 
| 145 | 
            -
                    def share_uri(name, query = {})
         | 
| 150 | 
            +
                    def share_uri(name, query = {}, options = {})
         | 
| 146 151 | 
             
                      return name if name.kind_of? ::URI
         | 
| 147 | 
            -
                      query = {  | 
| 148 | 
            -
                      generate_uri(name, query)
         | 
| 152 | 
            +
                      query = { restype: "share" }.merge(query)
         | 
| 153 | 
            +
                      generate_uri(name, query, options)
         | 
| 149 154 | 
             
                    end
         | 
| 150 155 |  | 
| 151 156 | 
             
                  # Protected: Generate the URI for a specific directory.
         | 
| @@ -160,10 +165,11 @@ module Azure::Storage | |
| 160 165 | 
             
                  # Returns a URI.
         | 
| 161 166 | 
             
                  #
         | 
| 162 167 | 
             
                  protected
         | 
| 163 | 
            -
                    def directory_uri(share, directory_path, query = {})
         | 
| 168 | 
            +
                    def directory_uri(share, directory_path, query = {}, options = {})
         | 
| 164 169 | 
             
                      path = directory_path.nil? ? share : ::File.join(share, directory_path)
         | 
| 165 | 
            -
                      query = {  | 
| 166 | 
            -
                       | 
| 170 | 
            +
                      query = { restype: "directory" }.merge(query)
         | 
| 171 | 
            +
                      options = { encode: true }.merge(options)
         | 
| 172 | 
            +
                      generate_uri(path, query, options)
         | 
| 167 173 | 
             
                    end
         | 
| 168 174 |  | 
| 169 175 | 
             
                  # Protected: Generate the URI for a specific file.
         | 
| @@ -178,13 +184,14 @@ module Azure::Storage | |
| 178 184 | 
             
                  # Returns a URI.
         | 
| 179 185 | 
             
                  #
         | 
| 180 186 | 
             
                  protected
         | 
| 181 | 
            -
                    def file_uri(share, directory_path, file, query = {})
         | 
| 187 | 
            +
                    def file_uri(share, directory_path, file, query = {}, options = {})
         | 
| 182 188 | 
             
                      if directory_path.nil?
         | 
| 183 189 | 
             
                        path = ::File.join(share, file)
         | 
| 184 190 | 
             
                      else
         | 
| 185 191 | 
             
                        path = ::File.join(share, directory_path, file)
         | 
| 186 192 | 
             
                      end
         | 
| 187 | 
            -
                       | 
| 193 | 
            +
                      options = { encode: true }.merge(options)
         | 
| 194 | 
            +
                      generate_uri(path, query, options)
         | 
| 188 195 | 
             
                    end
         | 
| 189 196 | 
             
                end
         | 
| 190 197 | 
             
              end
         | 
| @@ -100,6 +100,8 @@ module Azure::Storage::File | |
| 100 100 | 
             
                # * +:timeout+                  - Integer. A timeout in seconds.
         | 
| 101 101 | 
             
                # * +:request_id+               - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
         | 
| 102 102 | 
             
                #                                 in the analytics logs when storage analytics logging is enabled.
         | 
| 103 | 
            +
                # * +:location_mode+            - LocationMode. Specifies the location mode used to decide 
         | 
| 104 | 
            +
                #                                 which location the request should be sent to.
         | 
| 103 105 | 
             
                #
         | 
| 104 106 | 
             
                # See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/get-share-properties
         | 
| 105 107 | 
             
                #
         | 
| @@ -110,7 +112,8 @@ module Azure::Storage::File | |
| 110 112 | 
             
                  query["timeout"] = options[:timeout].to_s if options[:timeout]
         | 
| 111 113 |  | 
| 112 114 | 
             
                  # Call
         | 
| 113 | 
            -
                   | 
| 115 | 
            +
                  options[:request_location_mode] = Azure::Storage::RequestLocationMode::PRIMARY_OR_SECONDARY
         | 
| 116 | 
            +
                  response = call(:get, share_uri(name, query, options), nil, {}, options)
         | 
| 114 117 |  | 
| 115 118 | 
             
                  # result
         | 
| 116 119 | 
             
                  share = Serialization.share_from_headers(response.headers)
         | 
| @@ -166,6 +169,8 @@ module Azure::Storage::File | |
| 166 169 | 
             
                # * +:timeout+                  - Integer. A timeout in seconds.
         | 
| 167 170 | 
             
                # * +:request_id+               - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
         | 
| 168 171 | 
             
                #                                 in the analytics logs when storage analytics logging is enabled.
         | 
| 172 | 
            +
                # * +:location_mode+            - LocationMode. Specifies the location mode used to decide 
         | 
| 173 | 
            +
                #                                 which location the request should be sent to.
         | 
| 169 174 | 
             
                #
         | 
| 170 175 | 
             
                # See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/get-share-metadata
         | 
| 171 176 | 
             
                #
         | 
| @@ -176,7 +181,8 @@ module Azure::Storage::File | |
| 176 181 | 
             
                  query["timeout"] = options[:timeout].to_s if options[:timeout]
         | 
| 177 182 |  | 
| 178 183 | 
             
                  # Call
         | 
| 179 | 
            -
                   | 
| 184 | 
            +
                  options[:request_location_mode] = Azure::Storage::RequestLocationMode::PRIMARY_OR_SECONDARY
         | 
| 185 | 
            +
                  response = call(:get, share_uri(name, query, options), nil, {}, options)
         | 
| 180 186 |  | 
| 181 187 | 
             
                  # result
         | 
| 182 188 | 
             
                  share = Serialization.share_from_headers(response.headers)
         | 
| @@ -260,6 +266,8 @@ module Azure::Storage::File | |
| 260 266 | 
             
                # * +:timeout+                  - Integer. A timeout in seconds.
         | 
| 261 267 | 
             
                # * +:request_id+               - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
         | 
| 262 268 | 
             
                #                                 in the analytics logs when storage analytics logging is enabled.
         | 
| 269 | 
            +
                # * +:location_mode+            - LocationMode. Specifies the location mode used to decide 
         | 
| 270 | 
            +
                #                                 which location the request should be sent to.
         | 
| 263 271 | 
             
                #
         | 
| 264 272 | 
             
                # See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/get-share-acl
         | 
| 265 273 | 
             
                #
         | 
| @@ -273,7 +281,8 @@ module Azure::Storage::File | |
| 273 281 | 
             
                  query["timeout"] = options[:timeout].to_s if options[:timeout]
         | 
| 274 282 |  | 
| 275 283 | 
             
                  # Call
         | 
| 276 | 
            -
                   | 
| 284 | 
            +
                  options[:request_location_mode] = Azure::Storage::RequestLocationMode::PRIMARY_OR_SECONDARY
         | 
| 285 | 
            +
                  response = call(:get, share_uri(name, query, options), nil, {}, options)
         | 
| 277 286 |  | 
| 278 287 | 
             
                  # Result
         | 
| 279 288 | 
             
                  share = Serialization.share_from_headers(response.headers)
         | 
| @@ -343,6 +352,8 @@ module Azure::Storage::File | |
| 343 352 | 
             
                # * +:timeout+                  - Integer. A timeout in seconds.
         | 
| 344 353 | 
             
                # * +:request_id+               - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
         | 
| 345 354 | 
             
                #                                 in the analytics logs when storage analytics logging is enabled.
         | 
| 355 | 
            +
                # * +:location_mode+            - LocationMode. Specifies the location mode used to decide 
         | 
| 356 | 
            +
                #                                 which location the request should be sent to.
         | 
| 346 357 | 
             
                #
         | 
| 347 358 | 
             
                # See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/get-share-stats
         | 
| 348 359 | 
             
                #
         | 
| @@ -353,7 +364,8 @@ module Azure::Storage::File | |
| 353 364 | 
             
                  query["timeout"] = options[:timeout].to_s if options[:timeout]
         | 
| 354 365 |  | 
| 355 366 | 
             
                  # Call
         | 
| 356 | 
            -
                   | 
| 367 | 
            +
                  options[:request_location_mode] = Azure::Storage::RequestLocationMode::PRIMARY_OR_SECONDARY
         | 
| 368 | 
            +
                  response = call(:get, share_uri(name, query, options), nil, {}, options)
         | 
| 357 369 |  | 
| 358 370 | 
             
                  # result
         | 
| 359 371 | 
             
                  share = Serialization.share_from_headers(response.headers)
         | 
| @@ -35,7 +35,8 @@ module Azure::Storage | |
| 35 35 | 
             
                    client_config = options[:client] || Azure::Storage
         | 
| 36 36 | 
             
                    signer = options[:signer] || client_config.signer || Azure::Storage::Core::Auth::SharedKey.new(client_config.storage_account_name, client_config.storage_access_key)
         | 
| 37 37 | 
             
                    super(signer, client_config.storage_account_name, options, &block)
         | 
| 38 | 
            -
                    @ | 
| 38 | 
            +
                    @storage_service_host[:primary] = client.storage_queue_host
         | 
| 39 | 
            +
                    @storage_service_host[:secondary] = client.storage_queue_host true
         | 
| 39 40 | 
             
                  end
         | 
| 40 41 |  | 
| 41 42 | 
             
                  # Public: Get a list of Queues from the server
         | 
| @@ -65,6 +66,8 @@ module Azure::Storage | |
| 65 66 | 
             
                  # * +:timeout+                   - Integer. A timeout in seconds.
         | 
| 66 67 | 
             
                  # * +:request_id+                - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
         | 
| 67 68 | 
             
                  #                                  in the analytics logs when storage analytics logging is enabled.
         | 
| 69 | 
            +
                  # * +:location_mode+             - LocationMode. Specifies the location mode used to decide 
         | 
| 70 | 
            +
                  #                                  which location the request should be sent to.
         | 
| 68 71 | 
             
                  #
         | 
| 69 72 | 
             
                  # NOTE: Metadata requested with the :metadata parameter must have been stored in
         | 
| 70 73 | 
             
                  # accordance with the naming restrictions imposed by the 2009-09-19 version of the queue
         | 
| @@ -86,7 +89,8 @@ module Azure::Storage | |
| 86 89 | 
             
                    query["include"] = "metadata" if options[:metadata] == true
         | 
| 87 90 | 
             
                    query["timeout"] = options[:timeout].to_s if options[:timeout]
         | 
| 88 91 |  | 
| 89 | 
            -
                     | 
| 92 | 
            +
                    options[:request_location_mode] = RequestLocationMode::PRIMARY_OR_SECONDARY
         | 
| 93 | 
            +
                    uri = collection_uri(query, options)
         | 
| 90 94 | 
             
                    response = call(:get, uri, nil, {}, options)
         | 
| 91 95 |  | 
| 92 96 | 
             
                    Serialization.queue_enumeration_results_from_xml(response.body)
         | 
| @@ -195,6 +199,8 @@ module Azure::Storage | |
| 195 199 | 
             
                  # * +:timeout+                   - Integer. A timeout in seconds.
         | 
| 196 200 | 
             
                  # * +:request_id+                - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
         | 
| 197 201 | 
             
                  #                                  in the analytics logs when storage analytics logging is enabled.
         | 
| 202 | 
            +
                  # * +:location_mode+             - LocationMode. Specifies the location mode used to decide 
         | 
| 203 | 
            +
                  #                                  which location the request should be sent to.
         | 
| 198 204 | 
             
                  #
         | 
| 199 205 | 
             
                  # See http://msdn.microsoft.com/en-us/library/azure/dd179384
         | 
| 200 206 | 
             
                  #
         | 
| @@ -207,7 +213,8 @@ module Azure::Storage | |
| 207 213 | 
             
                    query = { "comp" => "metadata" }
         | 
| 208 214 | 
             
                    query["timeout"] = options[:timeout].to_s if options[:timeout]
         | 
| 209 215 |  | 
| 210 | 
            -
                     | 
| 216 | 
            +
                    options[:request_location_mode] = RequestLocationMode::PRIMARY_OR_SECONDARY
         | 
| 217 | 
            +
                    uri = queue_uri(queue_name, query, options)
         | 
| 211 218 |  | 
| 212 219 | 
             
                    response = call(:get, uri, nil, {}, options)
         | 
| 213 220 |  | 
| @@ -262,6 +269,8 @@ module Azure::Storage | |
| 262 269 | 
             
                  # * +:timeout+                   - Integer. A timeout in seconds.
         | 
| 263 270 | 
             
                  # * +:request_id+                - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
         | 
| 264 271 | 
             
                  #                                  in the analytics logs when storage analytics logging is enabled.
         | 
| 272 | 
            +
                  # * +:location_mode+             - LocationMode. Specifies the location mode used to decide 
         | 
| 273 | 
            +
                  #                                  which location the request should be sent to.
         | 
| 265 274 | 
             
                  #
         | 
| 266 275 | 
             
                  # See http://msdn.microsoft.com/en-us/library/azure/jj159101
         | 
| 267 276 | 
             
                  #
         | 
| @@ -270,7 +279,8 @@ module Azure::Storage | |
| 270 279 | 
             
                    query = { "comp" => "acl" }
         | 
| 271 280 | 
             
                    query["timeout"] = options[:timeout].to_s if options[:timeout]
         | 
| 272 281 |  | 
| 273 | 
            -
                     | 
| 282 | 
            +
                    options[:request_location_mode] = RequestLocationMode::PRIMARY_OR_SECONDARY
         | 
| 283 | 
            +
                    response = call(:get, queue_uri(queue_name, query, options), nil, {}, options)
         | 
| 274 284 |  | 
| 275 285 | 
             
                    signed_identifiers = []
         | 
| 276 286 | 
             
                    signed_identifiers = Serialization.signed_identifiers_from_xml(response.body) unless response.body == (nil) || response.body.length < (1)
         | 
| @@ -432,6 +442,8 @@ module Azure::Storage | |
| 432 442 | 
             
                  # * +:timeout+                   - Integer. A timeout in seconds.
         | 
| 433 443 | 
             
                  # * +:request_id+                - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
         | 
| 434 444 | 
             
                  #                                  in the analytics logs when storage analytics logging is enabled.
         | 
| 445 | 
            +
                  # * +:location_mode+             - LocationMode. Specifies the location mode used to decide 
         | 
| 446 | 
            +
                  #                                  which location the request should be sent to.
         | 
| 435 447 | 
             
                  #
         | 
| 436 448 | 
             
                  # See http://msdn.microsoft.com/en-us/library/azure/dd179472
         | 
| 437 449 | 
             
                  #
         | 
| @@ -443,7 +455,8 @@ module Azure::Storage | |
| 443 455 | 
             
                    query = { "peekonly" => "true", "numofmessages" => number_of_messages.to_s }
         | 
| 444 456 | 
             
                    query["timeout"] = options[:timeout].to_s if options[:timeout]
         | 
| 445 457 |  | 
| 446 | 
            -
                     | 
| 458 | 
            +
                    options[:request_location_mode] = RequestLocationMode::PRIMARY_OR_SECONDARY
         | 
| 459 | 
            +
                    uri = messages_uri(queue_name, query, options)
         | 
| 447 460 | 
             
                    response = call(:get, uri, nil, {}, options)
         | 
| 448 461 |  | 
| 449 462 | 
             
                    messages = Serialization.queue_messages_from_xml(response.body, options[:decode])
         | 
| @@ -558,9 +571,9 @@ module Azure::Storage | |
| 558 571 | 
             
                  #
         | 
| 559 572 | 
             
                  # Returns a URI.
         | 
| 560 573 | 
             
                  protected
         | 
| 561 | 
            -
                    def collection_uri(query = {})
         | 
| 574 | 
            +
                    def collection_uri(query = {}, options = {})
         | 
| 562 575 | 
             
                      query.update(comp: "list", include: "metadata")
         | 
| 563 | 
            -
                      generate_uri("", query)
         | 
| 576 | 
            +
                      generate_uri("", query, options)
         | 
| 564 577 | 
             
                    end
         | 
| 565 578 |  | 
| 566 579 | 
             
                  # Protected: Generate the URI for a given queue.
         | 
| @@ -572,9 +585,9 @@ module Azure::Storage | |
| 572 585 | 
             
                  #
         | 
| 573 586 | 
             
                  # Returns a URI.
         | 
| 574 587 | 
             
                  protected
         | 
| 575 | 
            -
                    def queue_uri(queue_name, query = {})
         | 
| 588 | 
            +
                    def queue_uri(queue_name, query = {}, options = {})
         | 
| 576 589 | 
             
                      return queue_name if queue_name.kind_of? ::URI
         | 
| 577 | 
            -
                      generate_uri(queue_name, query)
         | 
| 590 | 
            +
                      generate_uri(queue_name, query, options)
         | 
| 578 591 | 
             
                    end
         | 
| 579 592 |  | 
| 580 593 | 
             
                  # Protected: Generate the messages URI for the given queue.
         | 
| @@ -586,8 +599,8 @@ module Azure::Storage | |
| 586 599 | 
             
                  #
         | 
| 587 600 | 
             
                  # Returns a URI.
         | 
| 588 601 | 
             
                  protected
         | 
| 589 | 
            -
                    def messages_uri(queue_name, query = {})
         | 
| 590 | 
            -
                      generate_uri("#{queue_name}/messages", query)
         | 
| 602 | 
            +
                    def messages_uri(queue_name, query = {}, options = {})
         | 
| 603 | 
            +
                      generate_uri("#{queue_name}/messages", query, options)
         | 
| 591 604 | 
             
                    end
         | 
| 592 605 |  | 
| 593 606 | 
             
                  # Protected: Generate the URI for a given message
         | 
| @@ -600,8 +613,8 @@ module Azure::Storage | |
| 600 613 | 
             
                  #
         | 
| 601 614 | 
             
                  # Returns a URI.
         | 
| 602 615 | 
             
                  protected
         | 
| 603 | 
            -
                    def message_uri(queue_name, message_id, query = {})
         | 
| 604 | 
            -
                      generate_uri("#{queue_name}/messages/#{message_id}", query)
         | 
| 616 | 
            +
                    def message_uri(queue_name, message_id, query = {}, options = {})
         | 
| 617 | 
            +
                      generate_uri("#{queue_name}/messages/#{message_id}", query, options)
         | 
| 605 618 | 
             
                    end
         | 
| 606 619 | 
             
                end
         | 
| 607 620 | 
             
              end
         | 
| @@ -0,0 +1,40 @@ | |
| 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 Service
         | 
| 29 | 
            +
                class GeoReplication
         | 
| 30 | 
            +
                  def initialize
         | 
| 31 | 
            +
                    @status = nil
         | 
| 32 | 
            +
                    @last_sync_time = nil
         | 
| 33 | 
            +
                    yield self if block_given?
         | 
| 34 | 
            +
                  end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                  attr_accessor :status
         | 
| 37 | 
            +
                  attr_accessor :last_sync_time
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
            end
         | 
| @@ -24,6 +24,7 @@ | |
| 24 24 | 
             
            # THE SOFTWARE.
         | 
| 25 25 | 
             
            #--------------------------------------------------------------------------
         | 
| 26 26 | 
             
            require "nokogiri"
         | 
| 27 | 
            +
            require "time"
         | 
| 27 28 |  | 
| 28 29 | 
             
            require "azure/storage/service/enumeration_results"
         | 
| 29 30 | 
             
            require "azure/storage/service/signed_identifier"
         | 
| @@ -34,6 +35,7 @@ require "azure/storage/service/metrics" | |
| 34 35 | 
             
            require "azure/storage/service/retention_policy"
         | 
| 35 36 | 
             
            require "azure/storage/service/cors"
         | 
| 36 37 | 
             
            require "azure/storage/service/cors_rule"
         | 
| 38 | 
            +
            require "azure/storage/service/storage_service_stats"
         | 
| 37 39 |  | 
| 38 40 | 
             
            module Azure::Storage
         | 
| 39 41 | 
             
              module Service
         | 
| @@ -253,6 +255,21 @@ module Azure::Storage | |
| 253 255 | 
             
                      end
         | 
| 254 256 | 
             
                    end
         | 
| 255 257 |  | 
| 258 | 
            +
                    def geo_replication_from_xml(xml)
         | 
| 259 | 
            +
                      xml = slopify(xml)
         | 
| 260 | 
            +
                      expect_node("GeoReplication", xml)
         | 
| 261 | 
            +
             | 
| 262 | 
            +
                      GeoReplication.new do |geo_replication|
         | 
| 263 | 
            +
                        geo_replication.status = xml.Status.text if (xml > "Status").any?
         | 
| 264 | 
            +
                        geo_replication.last_sync_time =
         | 
| 265 | 
            +
                          begin
         | 
| 266 | 
            +
                            Time.parse(xml.LastSyncTime.text) if (xml > "LastSyncTime").any?
         | 
| 267 | 
            +
                          rescue
         | 
| 268 | 
            +
                            nil
         | 
| 269 | 
            +
                          end
         | 
| 270 | 
            +
                      end
         | 
| 271 | 
            +
                    end
         | 
| 272 | 
            +
             | 
| 256 273 | 
             
                    def ary_from_node(node)
         | 
| 257 274 | 
             
                      node.text.split(",").map { |s| s.strip }
         | 
| 258 275 | 
             
                    end
         | 
| @@ -283,6 +300,15 @@ module Azure::Storage | |
| 283 300 | 
             
                      end
         | 
| 284 301 | 
             
                    end
         | 
| 285 302 |  | 
| 303 | 
            +
                    def service_stats_from_xml(xml)
         | 
| 304 | 
            +
                      xml = slopify(xml)
         | 
| 305 | 
            +
                      expect_node("StorageServiceStats", xml)
         | 
| 306 | 
            +
                      
         | 
| 307 | 
            +
                      StorageServiceStats.new do |stats|
         | 
| 308 | 
            +
                        stats.geo_replication = geo_replication_from_xml(xml.GeoReplication)
         | 
| 309 | 
            +
                      end
         | 
| 310 | 
            +
                    end
         | 
| 311 | 
            +
             | 
| 286 312 | 
             
                    def to_bool(s)
         | 
| 287 313 | 
             
                      (s || "").downcase == "true"
         | 
| 288 314 | 
             
                    end
         | 
| @@ -27,11 +27,17 @@ | |
| 27 27 | 
             
            require "azure/core/signed_service"
         | 
| 28 28 | 
             
            require "azure/storage/core"
         | 
| 29 29 | 
             
            require "azure/storage/service/storage_service_properties"
         | 
| 30 | 
            +
            require "azure/storage/service/storage_service_stats"
         | 
| 30 31 |  | 
| 31 32 | 
             
            module Azure::Storage
         | 
| 32 33 | 
             
              module Service
         | 
| 33 34 | 
             
                # A base class for StorageService implementations
         | 
| 34 35 | 
             
                class StorageService < Azure::Core::SignedService
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  # @!attribute storage_service_host
         | 
| 38 | 
            +
                  # @return [Hash] Get or set the storage service host
         | 
| 39 | 
            +
                  attr_accessor :storage_service_host
         | 
| 40 | 
            +
             | 
| 35 41 | 
             
                  # Create a new instance of the StorageService
         | 
| 36 42 | 
             
                  #
         | 
| 37 43 | 
             
                  # @param signer         [Azure::Core::Auth::Signer] An implementation of Signer used for signing requests.
         | 
| @@ -39,7 +45,7 @@ module Azure::Storage | |
| 39 45 | 
             
                  # @param account_name   [String] The account name (optional, Default=Azure::Storage.storage_account_name)
         | 
| 40 46 | 
             
                  # @param options        [Azure::Storage::Configurable] the client configuration context
         | 
| 41 47 | 
             
                  def initialize(signer = nil, account_name = nil, options = {}, &block)
         | 
| 42 | 
            -
                    StorageService.register_request_callback | 
| 48 | 
            +
                    StorageService.register_request_callback(&block) if block_given?
         | 
| 43 49 | 
             
                    options[:client] = Azure::Storage if options[:client] == nil
         | 
| 44 50 | 
             
                    client_config = options[:client]
         | 
| 45 51 | 
             
                    signer = signer || Azure::Storage::Core::Auth::SharedKey.new(
         | 
| @@ -48,11 +54,12 @@ module Azure::Storage | |
| 48 54 | 
             
                    signer = signer || Azure::Storage::Core::Auth::SharedAccessSignatureSigner.new(
         | 
| 49 55 | 
             
                      client_config.storage_account_name,
         | 
| 50 56 | 
             
                      client_config.storage_sas_token)
         | 
| 57 | 
            +
                    @storage_service_host = { primary: "", secondary: "" };
         | 
| 51 58 | 
             
                    super(signer, account_name, options)
         | 
| 52 59 | 
             
                  end
         | 
| 53 60 |  | 
| 54 61 | 
             
                  def call(method, uri, body = nil, headers = {}, options = {})
         | 
| 55 | 
            -
                    super(method, uri, body, StorageService.common_headers(options).merge(headers))
         | 
| 62 | 
            +
                    super(method, uri, body, StorageService.common_headers(options).merge(headers), options)
         | 
| 56 63 | 
             
                  end
         | 
| 57 64 |  | 
| 58 65 | 
             
                  # Public: Get Storage Service properties
         | 
| @@ -98,9 +105,35 @@ module Azure::Storage | |
| 98 105 | 
             
                    nil
         | 
| 99 106 | 
             
                  end
         | 
| 100 107 |  | 
| 108 | 
            +
                  # Public: Retrieves statistics related to replication for the service. 
         | 
| 109 | 
            +
                  # It is only available on the secondary location endpoint when read-access geo-redundant 
         | 
| 110 | 
            +
                  # replication is enabled for the storage account. 
         | 
| 111 | 
            +
                  #
         | 
| 112 | 
            +
                  # See https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-service-stats
         | 
| 113 | 
            +
                  # See https://docs.microsoft.com/en-us/rest/api/storageservices/get-queue-service-stats
         | 
| 114 | 
            +
                  # See https://docs.microsoft.com/en-us/rest/api/storageservices/get-table-service-stats
         | 
| 115 | 
            +
                  #
         | 
| 116 | 
            +
                  # ==== Options
         | 
| 117 | 
            +
                  #
         | 
| 118 | 
            +
                  # * +:timeout+                   - Integer. A timeout in seconds.
         | 
| 119 | 
            +
                  # * +:request_id+                - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded
         | 
| 120 | 
            +
                  #                                  in the analytics logs when storage analytics logging is enabled.
         | 
| 121 | 
            +
                  #
         | 
| 122 | 
            +
                  # Returns a Hash with the service statistics or nil if the operation failed
         | 
| 123 | 
            +
                  def get_service_stats(options = {})
         | 
| 124 | 
            +
                    query = {}
         | 
| 125 | 
            +
                    StorageService.with_query query, "timeout", options[:timeout].to_s if options[:timeout]
         | 
| 126 | 
            +
             | 
| 127 | 
            +
                    options.update(
         | 
| 128 | 
            +
                      location_mode: LocationMode::SECONDARY_ONLY,
         | 
| 129 | 
            +
                      request_location_mode: RequestLocationMode::SECONDARY_ONLY)
         | 
| 130 | 
            +
                    response = call(:get, service_stats_uri(query, options), nil, {}, options)
         | 
| 131 | 
            +
                    Serialization.service_stats_from_xml response.body
         | 
| 132 | 
            +
                  end
         | 
| 133 | 
            +
             | 
| 101 134 | 
             
                  # Public: Generate the URI for the service properties
         | 
| 102 135 | 
             
                  #
         | 
| 103 | 
            -
                  # query - see Azure::Storage::Services::GetServiceProperties#call documentation.
         | 
| 136 | 
            +
                  # * +:query+ - see Azure::Storage::Services::GetServiceProperties#call documentation.
         | 
| 104 137 | 
             
                  #
         | 
| 105 138 | 
             
                  # Returns a URI.
         | 
| 106 139 | 
             
                  def service_properties_uri(query = {})
         | 
| @@ -108,21 +141,56 @@ module Azure::Storage | |
| 108 141 | 
             
                    generate_uri("", query)
         | 
| 109 142 | 
             
                  end
         | 
| 110 143 |  | 
| 144 | 
            +
                  # Public: Generate the URI for the service statistics
         | 
| 145 | 
            +
                  #
         | 
| 146 | 
            +
                  # * +:query+ - see Azure::Storage::Services::GetServiceStats#call documentation.
         | 
| 147 | 
            +
                  #
         | 
| 148 | 
            +
                  # Returns a URI.
         | 
| 149 | 
            +
                  def service_stats_uri(query = {}, options = {})
         | 
| 150 | 
            +
                    query.update(restype: "service", comp: "stats")
         | 
| 151 | 
            +
                    generate_uri("", query, options)
         | 
| 152 | 
            +
                  end
         | 
| 153 | 
            +
             | 
| 111 154 | 
             
                  # Overrides the base class implementation to determine the request uri
         | 
| 112 155 | 
             
                  #
         | 
| 113 156 | 
             
                  # path    - String. the request path
         | 
| 114 157 | 
             
                  # query   - Hash. the query parameters
         | 
| 115 158 | 
             
                  #
         | 
| 159 | 
            +
                  # ==== Options
         | 
| 160 | 
            +
                  #
         | 
| 161 | 
            +
                  # * +:encode+                    - bool. Specifies whether to encode the path.
         | 
| 162 | 
            +
                  # * +:location_mode+             - LocationMode. Specifies the location mode used to decide 
         | 
| 163 | 
            +
                  #                                  which location the request should be sent to. 
         | 
| 164 | 
            +
                  # * +:request_location_mode+     - RequestLocationMode. Specifies the location used to indicate 
         | 
| 165 | 
            +
                  #                                  which location the operation (REST API) can be performed against.
         | 
| 166 | 
            +
                  #                                  This is determined by the API and cannot be specified by the users. 
         | 
| 167 | 
            +
                  #
         | 
| 116 168 | 
             
                  # Returns the uri hash
         | 
| 117 | 
            -
                  def generate_uri(path = "", query = {},  | 
| 118 | 
            -
                     | 
| 119 | 
            -
                      if  | 
| 120 | 
            -
                         | 
| 169 | 
            +
                  def generate_uri(path = "", query = {}, options = {})
         | 
| 170 | 
            +
                    location_mode =
         | 
| 171 | 
            +
                      if options[:location_mode].nil?
         | 
| 172 | 
            +
                        LocationMode::PRIMARY_ONLY
         | 
| 173 | 
            +
                      else
         | 
| 174 | 
            +
                        options[:location_mode]
         | 
| 175 | 
            +
                      end
         | 
| 176 | 
            +
             | 
| 177 | 
            +
                    request_location_mode = 
         | 
| 178 | 
            +
                      if options[:request_location_mode].nil?
         | 
| 179 | 
            +
                        RequestLocationMode::PRIMARY_ONLY
         | 
| 121 180 | 
             
                      else
         | 
| 122 | 
            -
                         | 
| 181 | 
            +
                        request_location_mode = options[:request_location_mode]
         | 
| 123 182 | 
             
                      end
         | 
| 183 | 
            +
             | 
| 184 | 
            +
                    location = StorageService.get_location location_mode, request_location_mode
         | 
| 185 | 
            +
             | 
| 186 | 
            +
                    if self.client.is_a?(Azure::Storage::Client) && self.client.options[:use_path_style_uri]
         | 
| 187 | 
            +
                      account_path = get_account_path location
         | 
| 188 | 
            +
                      path = path.length > 0 ? account_path + "/" + path : account_path
         | 
| 124 189 | 
             
                    end
         | 
| 125 190 |  | 
| 191 | 
            +
                    @host = location == StorageLocation::PRIMARY ? @storage_service_host[:primary] : @storage_service_host[:secondary]
         | 
| 192 | 
            +
             | 
| 193 | 
            +
                    encode = options[:encode].nil? ? false : options[:encode]
         | 
| 126 194 | 
             
                    if encode
         | 
| 127 195 | 
             
                      path = CGI.escape(path.encode("UTF-8"))
         | 
| 128 196 |  | 
| @@ -134,7 +202,32 @@ module Azure::Storage | |
| 134 202 | 
             
                      path = path.gsub(/\+/, "%20")
         | 
| 135 203 | 
             
                    end
         | 
| 136 204 |  | 
| 137 | 
            -
                     | 
| 205 | 
            +
                    @host = storage_service_host[:primary]
         | 
| 206 | 
            +
                    options[:primary_uri] = super path, query
         | 
| 207 | 
            +
             | 
| 208 | 
            +
                    @host = storage_service_host[:secondary]
         | 
| 209 | 
            +
                    options[:secondary_uri] = super path, query
         | 
| 210 | 
            +
             | 
| 211 | 
            +
                    if location == StorageLocation::PRIMARY
         | 
| 212 | 
            +
                      @host = @storage_service_host[:primary]
         | 
| 213 | 
            +
                      return options[:primary_uri]
         | 
| 214 | 
            +
                    else
         | 
| 215 | 
            +
                      @host = @storage_service_host[:secondary]
         | 
| 216 | 
            +
                      return options[:secondary_uri]
         | 
| 217 | 
            +
                    end
         | 
| 218 | 
            +
                  end
         | 
| 219 | 
            +
             | 
| 220 | 
            +
                  # Get account path according to the location settings.
         | 
| 221 | 
            +
                  #
         | 
| 222 | 
            +
                  # * +:location+                      - StorageLocation. Specifies the request location.
         | 
| 223 | 
            +
                  #
         | 
| 224 | 
            +
                  # Returns the account path
         | 
| 225 | 
            +
                  def get_account_path(location)
         | 
| 226 | 
            +
                    if location == StorageLocation::PRIMARY
         | 
| 227 | 
            +
                      self.client.options[:storage_account_name]
         | 
| 228 | 
            +
                    else
         | 
| 229 | 
            +
                      self.client.options[:storage_account_name] + "-secondary"
         | 
| 230 | 
            +
                    end
         | 
| 138 231 | 
             
                  end
         | 
| 139 232 |  | 
| 140 233 | 
             
                  class << self
         | 
| @@ -152,10 +245,41 @@ module Azure::Storage | |
| 152 245 | 
             
                      @request_callback = Proc.new
         | 
| 153 246 | 
             
                    end
         | 
| 154 247 |  | 
| 248 | 
            +
                    # Get the request location.
         | 
| 249 | 
            +
                    #
         | 
| 250 | 
            +
                    # * +:location_mode+             - LocationMode. Specifies the location mode used to decide 
         | 
| 251 | 
            +
                    #                                  which location the request should be sent to.
         | 
| 252 | 
            +
                    # * +:request_location_mode+     - RequestLocationMode. Specifies the location used to indicate 
         | 
| 253 | 
            +
                    #                                  which location the operation (REST API) can be performed against.
         | 
| 254 | 
            +
                    #                                  This is determined by the API and cannot be specified by the users. 
         | 
| 255 | 
            +
                    #
         | 
| 256 | 
            +
                    # Returns the reqeust location
         | 
| 257 | 
            +
                    def get_location(location_mode, request_location_mode)
         | 
| 258 | 
            +
                      if request_location_mode == RequestLocationMode::PRIMARY_ONLY && location_mode == LocationMode::SECONDARY_ONLY
         | 
| 259 | 
            +
                        raise InvalidOptionsError, "This operation can only be executed against the primary storage location."
         | 
| 260 | 
            +
                      end
         | 
| 261 | 
            +
             | 
| 262 | 
            +
                      if request_location_mode == RequestLocationMode::SECONDARY_ONLY && location_mode == LocationMode::PRIMARY_ONLY
         | 
| 263 | 
            +
                        raise InvalidOptionsError, "This operation can only be executed against the secondary storage location."
         | 
| 264 | 
            +
                      end
         | 
| 265 | 
            +
             | 
| 266 | 
            +
                      if request_location_mode == RequestLocationMode::PRIMARY_ONLY
         | 
| 267 | 
            +
                        return StorageLocation::PRIMARY
         | 
| 268 | 
            +
                      elsif request_location_mode == RequestLocationMode::SECONDARY_ONLY
         | 
| 269 | 
            +
                        return StorageLocation::SECONDARY
         | 
| 270 | 
            +
                      end
         | 
| 271 | 
            +
             | 
| 272 | 
            +
                      if location_mode == LocationMode::PRIMARY_ONLY || location_mode == LocationMode::PRIMARY_THEN_SECONDARY
         | 
| 273 | 
            +
                        StorageLocation::PRIMARY
         | 
| 274 | 
            +
                      elsif location_mode == LocationMode::SECONDARY_ONLY || location_mode == LocationMode::SECONDARY_THEN_PRIMARY
         | 
| 275 | 
            +
                        StorageLocation::SECONDARY
         | 
| 276 | 
            +
                      end
         | 
| 277 | 
            +
                    end
         | 
| 278 | 
            +
             | 
| 155 279 | 
             
                    # Adds metadata properties to header hash with required prefix
         | 
| 156 280 | 
             
                    #
         | 
| 157 | 
            -
                    # metadata  - A Hash of metadata name/value pairs
         | 
| 158 | 
            -
                    # headers   - A Hash of HTTP headers
         | 
| 281 | 
            +
                    # * +:metadata+  - A Hash of metadata name/value pairs
         | 
| 282 | 
            +
                    # * +:headers+   - A Hash of HTTP headers
         | 
| 159 283 | 
             
                    def add_metadata_to_headers(metadata, headers)
         | 
| 160 284 | 
             
                      if metadata
         | 
| 161 285 | 
             
                        metadata.each do |key, value|
         | 
| @@ -166,25 +290,25 @@ module Azure::Storage | |
| 166 290 |  | 
| 167 291 | 
             
                    # Adds a value to the Hash object
         | 
| 168 292 | 
             
                    #
         | 
| 169 | 
            -
                    # object     - A Hash object
         | 
| 170 | 
            -
                    # key        - The key name
         | 
| 171 | 
            -
                    # value      - The value
         | 
| 293 | 
            +
                    # * +:object+     - A Hash object
         | 
| 294 | 
            +
                    # * +:key+        - The key name
         | 
| 295 | 
            +
                    # * +:value+      - The value
         | 
| 172 296 | 
             
                    def with_value(object, key, value)
         | 
| 173 297 | 
             
                      object[key] = value if value
         | 
| 174 298 | 
             
                    end
         | 
| 175 299 |  | 
| 176 300 | 
             
                    # Adds a header with the value
         | 
| 177 301 | 
             
                    #
         | 
| 178 | 
            -
                    # headers    - A Hash of HTTP headers
         | 
| 179 | 
            -
                    # name       - The header name
         | 
| 180 | 
            -
                    # value      - The value
         | 
| 302 | 
            +
                    # * +:headers+    - A Hash of HTTP headers
         | 
| 303 | 
            +
                    # * +:name+       - The header name
         | 
| 304 | 
            +
                    # * +:value+      - The value
         | 
| 181 305 | 
             
                    alias with_header with_value
         | 
| 182 306 |  | 
| 183 307 | 
             
                    # Adds a query parameter
         | 
| 184 308 | 
             
                    #
         | 
| 185 | 
            -
                    # query      - A Hash of HTTP query
         | 
| 186 | 
            -
                    # name       - The parameter name
         | 
| 187 | 
            -
                    # value      - The value
         | 
| 309 | 
            +
                    # * +:query+      - A Hash of HTTP query
         | 
| 310 | 
            +
                    # * +:name+       - The parameter name
         | 
| 311 | 
            +
                    # * +:value+      - The value
         | 
| 188 312 | 
             
                    alias with_query with_value
         | 
| 189 313 |  | 
| 190 314 | 
             
                    # Declares a default hash object for request headers
         |