Module: SauceWhisk

Defined in:
lib/sauce_whisk.rb,
lib/sauce_whisk/info.rb,
lib/sauce_whisk/jobs.rb,
lib/sauce_whisk/assets.rb,
lib/sauce_whisk/storage.rb,
lib/sauce_whisk/tunnels.rb,
lib/sauce_whisk/version.rb,
lib/sauce_whisk/accounts.rb,
lib/sauce_whisk/rest_request_builder.rb

Defined Under Namespace

Modules: RestRequestBuilder Classes: Account, AccountError, Accounts, Asset, Assets, InvalidAccountError, Job, JobNotComplete, Jobs, Sauce, Storage, SubAccount, SubAccountCreationError, Tunnel, Tunnels

Constant Summary collapse

VERSION =
"0.3.2"

Class Method Summary collapse

Class Method Details

.access_key=(access_key) ⇒ Object



35
36
37
# File 'lib/sauce_whisk.rb', line 35

def self.access_key= access_key
  @access_key = access_key
end

.asset_fetch_retriesObject



55
56
57
58
59
60
61
62
63
64
# File 'lib/sauce_whisk.rb', line 55

def self.asset_fetch_retries
  if @asset_fetch_retries
    return @asset_fetch_retries
  end

  retries = self.load_first_found(:asset_fetch_retries)

  return retries.to_i if retries
  return 1
end

.asset_fetch_retries=(retries) ⇒ Object



51
52
53
# File 'lib/sauce_whisk.rb', line 51

def self.asset_fetch_retries=(retries)
  @asset_fetch_retries = retries
end

.base_urlObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sauce_whisk.rb', line 16

def self.base_url
  case data_center
  when :US_WEST
    "https://saucelabs.com/rest/v1"
  when :US_EAST
    "https://us-east-1.saucelabs.com/rest/v1"
  when :EU_VDC
    "https://eu-central-1.saucelabs.com/rest/v1"
  when :APAC
    "https://apac-southeast-1.saucelabs.com/rest/v1"
  else
    raise ::ArgumentError.new "No Data Center Selected (Which should not happen?)"
  end
end

.data_centerObject



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/sauce_whisk.rb', line 81

def self.data_center
  configured_dc = self.load_first_found(:data_center)
  
  if configured_dc.nil?
    logger.warn "[DEPRECATED] You have not selected a REST API Endpoint - using US by default. This behaviour is deprecated and will be removed in an upcoming version. Please select a data center as described here: https://github.com/saucelabs/sauce_whisk#data-center"
    configured_dc = :US_WEST
  end

  validated_dc = validate_dc configured_dc
  validated_dc
end

.data_center=(dc) ⇒ Object



93
94
95
# File 'lib/sauce_whisk.rb', line 93

def self.data_center= dc
  @data_center = validate_dc dc
end

.from_yml(key) ⇒ Object



130
131
132
133
# File 'lib/sauce_whisk.rb', line 130

def self.from_yml(key)
  @hash_from_yaml ||= self.load_options_from_yaml
  return @hash_from_yaml[key]
end

.load_first_found(key) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/sauce_whisk.rb', line 153

def self.load_first_found(key)
  value = self.instance_variable_get "@#{key}".to_sym

  unless value
    value = ::Sauce::Config.new[key] if defined? ::Sauce
  end

  value = self.from_yml(key) unless value
  
  unless value
    env_key = "SAUCE_#{key.to_s.upcase}" 
    value = ENV[env_key]
  end
  
  return value
end

.load_options_from_yamlObject



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/sauce_whisk.rb', line 135

def self.load_options_from_yaml
  paths = [
    "ondemand.yml",
    File.join("config", "ondemand.yml"),
    File.expand_path("../../ondemand.yml", __FILE__),
    File.join(File.expand_path("~"), ".sauce", "ondemand.yml")
  ]

  paths.each do |path|
    if File.exists? path
      conf = YAML.load_file(path)
      return conf.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
    end
  end

  return {}
end

.loggerObject



119
120
121
# File 'lib/sauce_whisk.rb', line 119

def self.logger
  @logger||= default_logger
end

.logger=(logger) ⇒ Object



115
116
117
# File 'lib/sauce_whisk.rb', line 115

def self.logger=(logger)
  @logger = logger
end

.pass_job(job_id) ⇒ Object



111
112
113
# File 'lib/sauce_whisk.rb', line 111

def self.pass_job(job_id)
  Jobs.pass_job job_id
end

.passwordObject



45
46
47
48
49
# File 'lib/sauce_whisk.rb', line 45

def self.password
  configured_key = self.load_first_found(:access_key)
  return configured_key unless configured_key.nil? || configured_key.empty?
  raise ::ArgumentError.new "Couldn't find Access Key in Sauce::Config, yaml file or Environment Variables"
end


123
124
125
126
127
128
# File 'lib/sauce_whisk.rb', line 123

def self.public_link(job_id)
  key        = "#{self.username}:#{self.password}"
  auth_token = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('md5'), key, job_id)

  "https://saucelabs.com/jobs/#{job_id}?auth=#{auth_token}"
end

.rest_retriesObject



70
71
72
73
74
75
76
77
78
79
# File 'lib/sauce_whisk.rb', line 70

def self.rest_retries
  if @rest_retries
    return @rest_retries
  end

  retries = self.load_first_found(:rest_retries)

  return retries.to_i if retries
  return 1
end

.rest_retries=(retries) ⇒ Object



66
67
68
# File 'lib/sauce_whisk.rb', line 66

def self.rest_retries=(retries)
  @rest_retries = retries
end

.usernameObject



39
40
41
42
43
# File 'lib/sauce_whisk.rb', line 39

def self.username
  configured_username = self.load_first_found(:username)
  return configured_username unless configured_username.nil? || configured_username.empty?
  raise ::ArgumentError.new "Couldn't find Username in Sauce::Config, yaml file or Environment Variables"
end

.username=(username) ⇒ Object



31
32
33
# File 'lib/sauce_whisk.rb', line 31

def self.username= username
  @username = username
end

.validate_dc(dc) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/sauce_whisk.rb', line 97

def self.validate_dc dc
  dc = :eu_vdc if dc.to_s.upcase.to_sym == :EU
  dc = :us_west if dc.to_s.upcase.to_sym == :US
  dc = :us_west if dc.to_s.upcase.to_sym == :US_VDC

  ucdc = dc.to_s.upcase.to_sym

  if ![:EU_VDC, :US_EAST, :US_WEST, :APAC].include? ucdc
    raise ::ArgumentError.new("Invalid data center requested: #{ucdc}.  Value values are :EU_VDC, :US_EAST and :US_WEST.")
  end

  @data_center = ucdc
end