class Fog::Storage::Akamai::Real
Public Class Methods
Initialize connection to Akamai
Notes¶ ↑
options parameter must include values for :akamai_host, :akamai_key_name, :akamai_key and :akamai_cp_code in order to create a connection
Examples¶ ↑
akamai_storage = Storage.new( :akamai_host => your_akamai_host_name, :akamai_key_name => you_akamai_key_name, :akamai_key => you_akamai_key, :akamai_cp_code => your_cp_code )
Parameters¶ ↑
-
options<~Hash> - config arguments for connection. Defaults to {}.
Returns¶ ↑
-
Storage
object for akamai.
# File lib/fog/akamai/storage.rb, line 107 def initialize(options = {}) init(options) end
Public Instance Methods
# File lib/fog/akamai/storage.rb, line 120 def acs_action(action) action = { action: action } if action.is_a?(Symbol) fail(ArgumentError, "Invalid action #{action} valid actions are: #{VALID_ACTIONS}") unless VALID_ACTIONS.include?(action[:action]) "version=1&#{action.map { |v, k| "#{v}=#{k}" }.join('&')}&format=xml" end
# File lib/fog/akamai/storage.rb, line 111 def acs_auth_data version = '5' reserved_field1 = '0.0.0.0' reserved_field2 = '0.0.0.0' time = Time.now.to_i.to_s unique_id = SecureRandom.uuid [version, reserved_field1, reserved_field2, time, unique_id, akamai_key_name].join(', ') end
# File lib/fog/akamai/storage.rb, line 128 def acs_auth_sign(auth_data, path, action) data = auth_data + sign_string(path, action) digest = OpenSSL::Digest::Digest::SHA256.new Base64.encode64(OpenSSL::HMAC.digest(digest, akamai_key, data)).strip end
Use this action to delete an individual file or symbolic link. @param path [String] the path for the file that will be downloaded @return [Excon::Response] response
# File lib/fog/akamai/requests/storage/delete.rb, line 11 def delete(path) path_guard(path) request(:delete, path: format_path(path), method: 'PUT', expects: 200) end
Use this action to return the structure for a selected directory @return [Excon::Response] response:
* body [Hash]: * directory [String] - Path to directory * files [Array]: * type [String] * name [String] * mtime [String] * size [String] * md5 [String] * directories [Array]: * type [String] * name [String] * mtime [String]
# File lib/fog/akamai/requests/storage/dir.rb, line 22 def dir(path = '') request(:dir, path: format_path(path), method: 'GET', expects: 200, parser: Fog::Parsers::Storage::Akamai::Dir.new) end
Use this action to download a file @param path [String] the path for the file that will be downloaded @return [Excon::Response] response:
* body [binary]
# File lib/fog/akamai/requests/storage/download.rb, line 10 def download(path) path_guard(path) request(:download, path: format_path(path), method: 'GET', expects: 200) end
Use this action to return disk usage information for the directory specified by the @path, including all files stored in any sub-directories that may exist. @param path [String] the path for the file that will be downloaded @return [Excon::Response] response:
* body [Hash]: * directory [String] - The path to the directory * files [String] - The size of the files in bytes * bytes [String] - The size of the directory in bytes
# File lib/fog/akamai/requests/storage/du.rb, line 16 def du(path) path_guard(path) request(:du, path: format_path(path), method: 'GET', expects: 200, parser: Fog::Parsers::Storage::Akamai::Du.new) end
Use this action to create a dir @param path [String] the path to create, it will create directories recursively @return [Excon::Response] response
# File lib/fog/akamai/requests/storage/mkdir.rb, line 11 def mkdir(path) path_guard(path) request(:mkdir, path: format_path(path), method: 'PUT', expects: 200 ) end
Use this action to change a file’s modification time (“touch”). @param path [String] the path for he file that will be downloaded @param mtime [int] the desired modification time for the target content (i.e., in UNIX epoch time). @return [Excon::Response] response
# File lib/fog/akamai/requests/storage/mtime.rb, line 12 def mtime(path, mtime = DateTime.now.to_time.to_i) path_guard(path) request({ action: :mtime, mtime: mtime }, path: format_path(path), method: 'POST', expects: 200) end
Use this action to rename a file or symbolic link. @param source [String] the path to check @param destination [String] the path to check @return [Excon::Response] response
# File lib/fog/akamai/requests/storage/rename.rb, line 12 def rename(source, destination) path_guard(source) path_guard(destination) request({ action: :rename, destination: CGI.escape(format_path(destination)) }, path: format_path(source), method: 'POST', expects: 200) end
Use this action to delete an empty directory. @param path [String] the path to the directory @return [Excon::Response] response
# File lib/fog/akamai/requests/storage/rmdir.rb, line 9 def rmdir(path) path_guard(path) request(:rmdir, method: 'POST', path: format_path(path), expects: 200) end
Use this action to check if a file or directory existis @param path [String] the path to check @return [Excon::Response] response:
* body [Hash]: * directory [String] - Path of the parnt directory * files [Array]: - In case the stat was for a file * type [String] * name [String] * mtime [String] * size [String] * md5 [String] * directories [Array]: - In case the stat was for a directory * type [String] * name [String] * mtime [String]
# File lib/fog/akamai/requests/storage/stat.rb, line 25 def stat(path) path_guard(path) request(:stat, path: format_path(path), method: 'GET', expects: 200, parser: Fog::Parsers::Storage::Akamai::Dir.new) end
Use this action to rename a file or symbolic link. @param source [String] the path to check @param target [String] the path to check @return [Excon::Response] response
# File lib/fog/akamai/requests/storage/symlink.rb, line 10 def symlink(source, target) path_guard(source) path_guard(target) request({ action: :symlink, target: CGI.escape(format_path(target)) }, path: format_path(source), method: 'POST', expects: 200) end
Use this action to upload a file @param path [String] the path to where to upload @param body [File] the file to upload, can be file or a byte array @return [Excon::Response] response
# File lib/fog/akamai/requests/storage/upload.rb, line 12 def upload(path, body) path_and_body_guard(path, body) data = Fog::Storage.parse_data(body) request(:upload, path: format_path(path), method: 'PUT', headers: data[:headers], body: data[:body], expects: 200) end
Private Instance Methods
# File lib/fog/akamai/storage.rb, line 136 def request(action, params) url = "#{scheme}://#{akamai_host}:#{port}" path = params[:path] auth_data = acs_auth_data headers = { ACS_AUTH_DATA_HEADER => auth_data, ACS_AUTH_SIGN_HEADER => acs_auth_sign(auth_data, path, action), ACS_AUTH_ACTION_HEADER => acs_action(action) }.merge(params[:headers] || {}) params = params.merge(headers: headers) Fog::XML::Connection.new(url).request(params) end
# File lib/fog/akamai/storage.rb, line 152 def sign_string(path, action) action = "x-akamai-acs-action:#{acs_action(action)}\n" "#{path}\n#{action}" end