Parent

Class/Module Index [+]

Quicksearch

Fog::Storage::HP::Directory

Public Instance Methods

acl=(new_acl) click to toggle source
# File lib/fog/hp/models/storage/directory.rb, line 15
def acl=(new_acl)
  if new_acl.nil?
    new_acl = "private"
  end
  valid_acls = ['private', 'public-read', 'public-write', 'public-read-write']
  unless valid_acls.include?(new_acl)
    raise ArgumentError.new("acl must be one of [#{valid_acls.join(', ')}]")
  end
  @acl = new_acl
end
cdn_enable=(new_cdn_enable) click to toggle source
# File lib/fog/hp/models/storage/directory.rb, line 80
def cdn_enable=(new_cdn_enable)
  @cdn_enable ||= false
  if (!service.cdn.nil? && service.cdn.enabled?)
    @cdn_enable = new_cdn_enable
  else
    # since cdn service is not activated, container cannot be cdn-enabled
    @cdn_enable = false
  end
end
cdn_enabled?() click to toggle source
# File lib/fog/hp/models/storage/directory.rb, line 90
def cdn_enabled?
  if (!service.cdn.nil? && service.cdn.enabled?)
    begin response = service.cdn.head_container(key)
      cdn_header = response.headers.fetch('X-Cdn-Enabled', nil)
      if (!cdn_header.nil? && cdn_header == 'True')
        @cdn_enable = true
      else
        @cdn_enable = false
      end
    rescue Fog::CDN::HP::NotFound => err
      @cdn_enable = false
    end
  else
    @cdn_enable = false
  end
end
cdn_public_url() click to toggle source
# File lib/fog/hp/models/storage/directory.rb, line 107
def cdn_public_url
  requires :key
  @cdn_public_url ||= begin
    # return the CDN public url from the appropriate uri from the header
    begin response = service.cdn.head_container(key)
      if response.headers['X-Cdn-Enabled'] == 'True'
        if service.hp_cdn_ssl == true
          response.headers.fetch('X-Cdn-Ssl-Uri', nil)
        else
          response.headers.fetch('X-Cdn-Uri', nil)
        end
      end
    rescue Fog::CDN::HP::NotFound => err
      nil
    end
  end
end
destroy() click to toggle source
# File lib/fog/hp/models/storage/directory.rb, line 26
def destroy
  requires :key
  service.delete_container(key)
  # If CDN service is available, try to delete the container if it was CDN-enabled
  if cdn_enabled?
    begin
      service.cdn.delete_container(key)
    rescue Fog::CDN::HP::NotFound
      # ignore if cdn container not found
    end
  end
  true
rescue Excon::Errors::NotFound, Fog::Storage::HP::NotFound
  false
end
files() click to toggle source
# File lib/fog/hp/models/storage/directory.rb, line 42
def files
  @files ||= begin
    Fog::Storage::HP::Files.new(
      :directory    => self,
      :service   => service
    )
  end
end
public=(new_public) click to toggle source
# File lib/fog/hp/models/storage/directory.rb, line 51
def public=(new_public)
  if new_public
    @acl = 'public-read'
  else
    @acl = 'private'
  end
  @public = new_public
end
public?() click to toggle source
# File lib/fog/hp/models/storage/directory.rb, line 60
def public?
  if @acl.nil?
    false
  else
    @acl == 'public-read'
  end
end
public_url() click to toggle source
# File lib/fog/hp/models/storage/directory.rb, line 68
def public_url
  requires :key
  @public_url ||= begin
    begin response = service.head_container(key)
      # escape the key to cover for special char. in container names
      url = "#{service.url}/#{Fog::HP.escape(key)}"
    rescue Fog::Storage::HP::NotFound => err
      nil
    end
  end
end
save() click to toggle source
# File lib/fog/hp/models/storage/directory.rb, line 125
def save
  requires :key
  options = {}
  if @acl
    options.merge!(service.acl_to_header(@acl))
  end
  service.put_container(key, options)
  # Added an extra check to see if CDN is enabled for the container
  if (!service.cdn.nil? && service.cdn.enabled?)
    # If CDN available, set the container to be CDN-enabled or not based on if it is marked as cdn_enable.
    if @cdn_enable
      # check to make sure that the container exists. If yes, cdn enable it.
      begin response = service.cdn.head_container(key)
        ### Deleting a container from CDN is much more expensive than flipping the bit to disable it
        service.cdn.post_container(key, {'X-CDN-Enabled' => 'True'})
      rescue Fog::CDN::HP::NotFound => err
        service.cdn.put_container(key)
      end
    else
      # check to make sure that the container exists. If yes, cdn disable it.
      begin response = service.cdn.head_container(key)
        ### Deleting a container from CDN is much more expensive than flipping the bit to disable it
        service.cdn.post_container(key, {'X-CDN-Enabled' => 'False'})
      rescue Fog::CDN::HP::NotFound => err
        # just continue, as container is not cdn-enabled.
      end
    end
  end
  true
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.