Class: Fog::Storage::Akamai::Real
- Inherits:
-
Object
- Object
- Fog::Storage::Akamai::Real
- Includes:
- Helpers, Initializer
- Defined in:
- lib/fog/akamai/storage.rb,
lib/fog/akamai/requests/storage/du.rb,
lib/fog/akamai/requests/storage/dir.rb,
lib/fog/akamai/requests/storage/stat.rb,
lib/fog/akamai/requests/storage/mkdir.rb,
lib/fog/akamai/requests/storage/mtime.rb,
lib/fog/akamai/requests/storage/rmdir.rb,
lib/fog/akamai/requests/storage/delete.rb,
lib/fog/akamai/requests/storage/rename.rb,
lib/fog/akamai/requests/storage/upload.rb,
lib/fog/akamai/requests/storage/symlink.rb,
lib/fog/akamai/requests/storage/download.rb
Instance Method Summary collapse
- #acs_action(action) ⇒ Object
- #acs_auth_data ⇒ Object
- #acs_auth_sign(auth_data, path, action) ⇒ Object
-
#delete(path) ⇒ Excon::Response
Use this action to delete an individual file or symbolic link.
-
#dir(path = '') ⇒ Excon::Response
Use this action to return the structure for a selected directory.
-
#download(path) ⇒ Excon::Response
Use this action to download a file.
-
#du(path) ⇒ Excon::Response
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.
-
#initialize(options = {}) ⇒ Real
constructor
Initialize connection to Akamai.
-
#mkdir(path) ⇒ Excon::Response
Use this action to create a dir.
-
#mtime(path, mtime = DateTime.now.to_time.to_i) ⇒ Excon::Response
Use this action to change a file’s modification time (“touch”).
-
#rename(source, destination) ⇒ Excon::Response
Use this action to rename a file or symbolic link.
-
#rmdir(path) ⇒ Excon::Response
Use this action to delete an empty directory.
-
#stat(path) ⇒ Excon::Response
Use this action to check if a file or directory existis.
-
#symlink(source, target) ⇒ Excon::Response
Use this action to rename a file or symbolic link.
-
#upload(path, body) ⇒ Excon::Response
Use this action to upload a file.
Methods included from Initializer
Methods included from Helpers
#format_path, #path_and_body_guard, #path_guard
Constructor Details
#initialize(options = {}) ⇒ Real
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.
107 108 109 |
# File 'lib/fog/akamai/storage.rb', line 107 def initialize( = {}) init() end |
Instance Method Details
#acs_action(action) ⇒ Object
120 121 122 123 124 125 126 |
# 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 |
#acs_auth_data ⇒ Object
111 112 113 114 115 116 117 118 |
# 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 |
#acs_auth_sign(auth_data, path, action) ⇒ Object
128 129 130 131 132 |
# 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 |
#delete(path) ⇒ Excon::Response
Use this action to delete an individual file or symbolic link.
11 12 13 14 15 16 17 |
# 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 |
#dir(path = '') ⇒ Excon::Response
Use this action to return the structure for a selected directory
22 23 24 25 26 27 28 |
# 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 |
#download(path) ⇒ Excon::Response
Use this action to download a file
10 11 12 13 14 15 16 |
# 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 |
#du(path) ⇒ Excon::Response
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.
16 17 18 19 20 21 22 23 |
# 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 |
#mkdir(path) ⇒ Excon::Response
Use this action to create a dir
11 12 13 14 15 16 17 18 |
# 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 |
#mtime(path, mtime = DateTime.now.to_time.to_i) ⇒ Excon::Response
Use this action to change a file’s modification time (“touch”).
12 13 14 15 16 17 18 |
# 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 |
#rename(source, destination) ⇒ Excon::Response
Use this action to rename a file or symbolic link.
12 13 14 15 16 17 18 19 20 |
# 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 |
#rmdir(path) ⇒ Excon::Response
Use this action to delete an empty directory.
9 10 11 12 13 14 15 |
# 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 |
#stat(path) ⇒ Excon::Response
Use this action to check if a file or directory existis
25 26 27 28 29 30 31 32 |
# 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 |
#symlink(source, target) ⇒ Excon::Response
Use this action to rename a file or symbolic link.
10 11 12 13 14 15 16 17 18 |
# 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 |
#upload(path, body) ⇒ Excon::Response
Use this action to upload a file
12 13 14 15 16 17 18 19 20 21 22 |
# 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 |