module GoodData::Helpers::AuthHelper

Public Class Methods

credentials_file() click to toggle source

Get path of .gooddata config

# File lib/gooddata/helpers/auth_helpers.rb, line 17
def credentials_file
  "#{Helpers.home_directory}/.gooddata"
end
read_credentials(credentials_file_path = credentials_file) click to toggle source

Read credentials

# File lib/gooddata/helpers/auth_helpers.rb, line 22
def read_credentials(credentials_file_path = credentials_file)
  if File.exist?(credentials_file_path)
    config = File.read(credentials_file_path)
    MultiJson.load(config, :symbolize_keys => true)
  else
    {}
  end
end
read_environment(credentials_file_path = credentials_file) click to toggle source

Try read environemnt

Tries to read it from ~/.gooddata file or from environment variable GD_SERVER @param [String] credentials_file_path (credentials_file) Path to .gooddata file @return [String] server token from environment variable, .gooddata or nil

# File lib/gooddata/helpers/auth_helpers.rb, line 36
def read_environment(credentials_file_path = credentials_file)
  goodfile = read_credentials(credentials_file_path)
  [ENV['GD_ENVIRONMENT'], goodfile[:environment], GoodData::Project::DEFAULT_ENVIRONMENT].find { |x| !x.nil? && !x.empty? }
end
read_server(credentials_file_path = credentials_file) click to toggle source

Try read server

Tries to read it from ~/.gooddata file or from environment variable GD_SERVER @param [String] credentials_file_path (credentials_file) Path to .gooddata file @return [String] server token from environment variable, .gooddata or DEFAULT_URL

# File lib/gooddata/helpers/auth_helpers.rb, line 46
def read_server(credentials_file_path = credentials_file)
  goodfile = read_credentials(credentials_file_path)
  [ENV['GD_SERVER'], goodfile[:server], GoodData::Rest::Connection::DEFAULT_URL].find { |x| !x.nil? && !x.empty? }
end
read_token(credentials_file_path = credentials_file) click to toggle source

Try read token

Tries to read it from ~/.gooddata file or from environment variable GD_PROJECT_TOKEN @param [String] credentials_file_path (credentials_file) Path to .gooddata file @return [String] auth token from environment variable, .gooddata or nil

# File lib/gooddata/helpers/auth_helpers.rb, line 56
def read_token(credentials_file_path = credentials_file)
  goodfile = read_credentials(credentials_file_path)
  [ENV['GD_PROJECT_TOKEN'], goodfile[:auth_token], goodfile[:token]].find { |x| !x.nil? && !x.empty? }
end
remove_credentials_file(credentials_file_path = credentials_file) click to toggle source
# File lib/gooddata/helpers/auth_helpers.rb, line 69
def remove_credentials_file(credentials_file_path = credentials_file)
  FileUtils.rm_f(credentials_file_path)
end
write_credentials(credentials, credentials_file_path = credentials_file) click to toggle source

Writes credentials

# File lib/gooddata/helpers/auth_helpers.rb, line 62
def write_credentials(credentials, credentials_file_path = credentials_file)
  File.open(credentials_file_path, 'w', 0o600) do |f|
    f.puts JSON.pretty_generate(credentials)
  end
  credentials
end