Class: K8sflow::Utils::HerokuClient

Inherits:
Object
  • Object
show all
Defined in:
lib/k8sflow/utils/heroku.rb

Constant Summary collapse

HEROKU_API_HOST =
"api.heroku.com"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#api_tokenObject

Returns the value of attribute api_token.



10
11
12
# File 'lib/k8sflow/utils/heroku.rb', line 10

def api_token
  @api_token
end

#herokuObject

Returns the value of attribute heroku.



10
11
12
# File 'lib/k8sflow/utils/heroku.rb', line 10

def heroku
  @heroku
end

Class Method Details

.clientObject



12
13
14
15
16
17
18
# File 'lib/k8sflow/utils/heroku.rb', line 12

def client
  if @client.nil?
    user, token = netrc[HEROKU_API_HOST]
    @client = Heroku::API.new(:api_key => token)
  end
  return @client
end

.envs(app, db_only = true) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/k8sflow/utils/heroku.rb', line 39

def envs(app, db_only=true)
  envs = client.get_config_vars(app).body
  #      pp "overrided vars: #{@options.envvars}"
  db_vars = ["DATABASE_URL",
             "MEMCACHIER_PASSWORD",
             "MEMCACHIER_SERVERS",
             "MEMCACHIER_USERNAME",
             "REDISTOGO_URL",
             "REDIS_PROVIDER"]
  if db_only == true
    envs.select!{|k,v| db_vars.index(k) != nil}
  end
  pp envs
  return envs
end

.netrcObject

:nodoc:



20
21
22
23
24
25
26
27
# File 'lib/k8sflow/utils/heroku.rb', line 20

def netrc # :nodoc:
  @netrc ||= begin
               File.exists?(netrc_path) ? Netrc.read(netrc_path) : raise(StandardError)
             rescue => error
               puts netrc_path
               raise ".netrc missing or no entry found. Try `heroku auth:login`"
             end
end

.netrc_pathObject

:nodoc:



29
30
31
32
33
34
35
36
37
# File 'lib/k8sflow/utils/heroku.rb', line 29

def netrc_path # :nodoc:
  default = Netrc.default_path
  encrypted = default + ".gpg"
  if File.exists?(encrypted)
    encrypted
  else
    default
  end
end