Sha256: 87a72689ad16f7769656735475b161607d66636e8bd9eb51b1bf2c6e07ed563f

Contents?: true

Size: 1.38 KB

Versions: 34

Compression:

Stored size: 1.38 KB

Contents

module Fog
  module Storage
    class Google
      class Real
        # TODO: move this methods to helper to use them with put_bucket_acl request
        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.select {|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

        def put_object_acl(bucket_name, object_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},
            :path     => CGI.escape(object_name)
          })
        end
      end
    end
  end
end

Version data entries

34 entries across 32 versions & 6 rubygems

Version Path
fog-1.25.0 lib/fog/google/requests/storage/put_object_acl.rb
nsidc-fog-1.24.1 lib/fog/google/requests/storage/put_object_acl.rb
fog-1.24.0 lib/fog/google/requests/storage/put_object_acl.rb
ns-fog-1.22.11 lib/fog/google/requests/storage/put_object_acl.rb
ns-fog-1.22.10 lib/fog/google/requests/storage/put_object_acl.rb
ns-fog-1.22.9 lib/fog/google/requests/storage/put_object_acl.rb
ns-fog-1.22.8 lib/fog/google/requests/storage/put_object_acl.rb
ns-fog-1.22.7 lib/fog/google/requests/storage/put_object_acl.rb
ns-fog-1.22.6 lib/fog/google/requests/storage/put_object_acl.rb
fog-1.23.0 lib/fog/google/requests/storage/put_object_acl.rb
ns-fog-1.22.4 lib/fog/google/requests/storage/put_object_acl.rb
ns-fog-1.22.3 lib/fog/google/requests/storage/put_object_acl.rb
ns-fog-1.22.2 lib/fog/google/requests/storage/put_object_acl.rb
fog-1.22.1 lib/fog/google/requests/storage/put_object_acl.rb