File: get_bucket_location.rb

package info (click to toggle)
ruby-fog-aliyun 0.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 720 kB
  • sloc: ruby: 5,804; makefile: 6; sh: 3
file content (33 lines) | stat: -rw-r--r-- 894 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'nokogiri'
module Fog
  module Aliyun
    class Storage
      class Real

        # Get location constraint for an OSS bucket
        #
        # @param bucket_name [String] name of bucket to get location constraint for
        #
        # @see https://help.aliyun.com/document_detail/31967.html
        #
        # note: The OSS Ruby sdk does not support get_bucket_location and there needs to parse response

        def get_bucket_location(bucket_name)
          data = @oss_http.get({:bucket => bucket_name, :sub_res => { 'location' => nil} }, {})
          doc = parse_xml(data.body)
          doc.at_css("LocationConstraint").text
        end

        private

        def parse_xml(content)
          doc = Nokogiri::XML(content) do |config|
            config.options |= Nokogiri::XML::ParseOptions::NOBLANKS
          end

          doc
        end
      end
    end
  end
end