Module: Fog::Storage::Atmos::Utils

Included in:
Mock, Real
Defined in:
lib/fog/atmos/storage.rb

Constant Summary collapse

ENDPOINT_REGEX =
/(https*):\/\/([a-zA-Z0-9\.\-]+)(:[0-9]+)?(\/.*)?/

Instance Method Summary collapse

Instance Method Details

#api_pathObject



48
49
50
# File 'lib/fog/atmos/storage.rb', line 48

def api_path
  @endpoint.match(ENDPOINT_REGEX)[4]
end

#hostObject



44
45
46
# File 'lib/fog/atmos/storage.rb', line 44

def host
  @endpoint.match(ENDPOINT_REGEX)[2]
end

#portObject



38
39
40
41
42
# File 'lib/fog/atmos/storage.rb', line 38

def port
  port = @endpoint.match(ENDPOINT_REGEX)[3]
  return ssl? ? 443 : 80 if port.nil?
  port.split(':')[1].to_i
end

#setup_credentials(options) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/fog/atmos/storage.rb', line 52

def setup_credentials(options)
  @storage_token = options[:atmos_storage_token]
  @storage_secret = options[:atmos_storage_secret]
  @storage_secret_decoded = Base64.decode64(@storage_secret)
  @endpoint = options[:atmos_storage_endpoint]
  @prefix = self.ssl? ? 'https' : 'http'
  @storage_host = self.host
  @storage_port = self.port
  @api_path = self.api_path
end

#ssl?Boolean

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


28
29
30
31
32
33
34
35
36
# File 'lib/fog/atmos/storage.rb', line 28

def ssl?
  protocol = @endpoint.match(ENDPOINT_REGEX)[1]
  raise ArgumentError, 'Invalid endpoint URL' if protocol.nil?

  return true if protocol == 'https'
  return false if protocol == 'http'

  raise ArgumentError, "Unknown protocol #{protocol}"
end