Class: Fog::Storage::Akamai::Real

Inherits:
Object
  • Object
show all
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

Methods included from Initializer

included, #init

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(options = {})
  init(options)
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_dataObject



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.

Parameters:

  • path (String)

    the path for the file that will be downloaded

Returns:

  • (Excon::Response)

    response



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

Returns:

  • (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]



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

Parameters:

  • path (String)

    the path for the file that will be downloaded

Returns:

  • (Excon::Response)

    response:

    • body [binary]



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.

Parameters:

  • path (String)

    the path for the file that will be downloaded

Returns:

  • (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



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

Parameters:

  • path (String)

    the path to create, it will create directories recursively

Returns:

  • (Excon::Response)

    response



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”).

Parameters:

  • path (String)

    the path for he file that will be downloaded

  • mtime (int) (defaults to: DateTime.now.to_time.to_i)

    the desired modification time for the target content (i.e., in UNIX epoch time).

Returns:

  • (Excon::Response)

    response



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.

Parameters:

  • source (String)

    the path to check

  • destination (String)

    the path to check

Returns:

  • (Excon::Response)

    response



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.

Parameters:

  • path (String)

    the path to the directory

Returns:

  • (Excon::Response)

    response



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

Parameters:

  • path (String)

    the path to check

Returns:

  • (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]



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

Use this action to rename a file or symbolic link.

Parameters:

  • source (String)

    the path to check

  • target (String)

    the path to check

Returns:

  • (Excon::Response)

    response



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

Parameters:

  • path (String)

    the path to where to upload

  • body (File)

    the file to upload, can be file or a byte array

Returns:

  • (Excon::Response)

    response



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