Sha256: 507b11880145cc4a1a251169e1255c69231e10c50e493a34dc4bcf0354ff4a39

Contents?: true

Size: 1.45 KB

Versions: 20

Compression:

Stored size: 1.45 KB

Contents

module Fog
  module Storage
    class GoogleXML
      class Mock
        def put_bucket_acl(_bucket_name, _acl)
          Fog::Mock.not_implemented
        end
      end

      class Real
        # Change access control list for an Google Storage bucket
        def put_bucket_acl(bucket_name, acl)
          data = <<-DATA
<AccessControlList>
  <Owner>
    #{tag('ID', acl['Owner']['ID'])}
  </Owner>
  <Entries>
    #{entries_list(acl['AccessControlList'])}
  </Entries>
</AccessControlList>
DATA

          request(:body     => data,
                  :expects  => 200,
                  :headers  => {},
                  :host     => "#{bucket_name}.#{@host}",
                  :method   => "PUT",
                  :query    => { "acl" => nil })
        end

        private

        def tag(name, value)
          "<#{name}>#{value}</#{name}>"
        end

        def scope_tag(scope)
          if %w(AllUsers AllAuthenticatedUsers).include?(scope["type"])
            "<Scope type='#{scope['type']}'/>"
          else
            "<Scope type='#{scope['type']}'>" +
              scope.to_a.reject { |pair| pair[0] == "type" }.map { |pair| tag(pair[0], pair[1]) }.join("\n") +
              "</Scope>"
          end
        end

        def entries_list(access_control_list)
          access_control_list.map do |entry|
            tag("Entry", scope_tag(entry["Scope"]) + tag("Permission", entry["Permission"]))
          end.join("\n")
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
fog-google-1.9.1 lib/fog/storage/google_xml/requests/put_bucket_acl.rb
fog-google-1.9.0 lib/fog/storage/google_xml/requests/put_bucket_acl.rb
fog-google-1.8.2 lib/fog/storage/google_xml/requests/put_bucket_acl.rb
fog-google-1.8.1 lib/fog/storage/google_xml/requests/put_bucket_acl.rb
fog-google-1.8.0 lib/fog/storage/google_xml/requests/put_bucket_acl.rb
fog-google-1.7.1 lib/fog/storage/google_xml/requests/put_bucket_acl.rb
fog-google-1.7.0 lib/fog/storage/google_xml/requests/put_bucket_acl.rb
fog-google-1.6.0 lib/fog/storage/google_xml/requests/put_bucket_acl.rb
fog-google-1.5.0 lib/fog/storage/google_xml/requests/put_bucket_acl.rb
fog-google-1.4.0 lib/fog/storage/google_xml/requests/put_bucket_acl.rb
fog-google-1.3.3 lib/fog/storage/google_xml/requests/put_bucket_acl.rb
fog-google-1.3.2 lib/fog/storage/google_xml/requests/put_bucket_acl.rb
fog-google-1.3.1 lib/fog/storage/google_xml/requests/put_bucket_acl.rb
fog-google-1.3.0 lib/fog/storage/google_xml/requests/put_bucket_acl.rb
fog-google-1.2.2 lib/fog/storage/google_xml/requests/put_bucket_acl.rb
fog-google-1.2.1 lib/fog/storage/google_xml/requests/put_bucket_acl.rb
fog-google-1.2.0 lib/fog/storage/google_xml/requests/put_bucket_acl.rb
fog-google-1.1.0 lib/fog/storage/google_xml/requests/put_bucket_acl.rb
fog-google-1.0.1 lib/fog/storage/google_xml/requests/put_bucket_acl.rb
fog-google-1.0.0 lib/fog/storage/google_xml/requests/put_bucket_acl.rb