Module: WithEtnaClients

Instance Method Summary collapse

Instance Method Details

#environmentObject



5
6
7
# File 'lib/helpers.rb', line 5

def environment
  EtnaApp.instance.environment
end

#janus_clientObject



52
53
54
55
56
57
# File 'lib/helpers.rb', line 52

def janus_client
  @janus_client ||= Etna::Clients::Janus.new(
      token: token,
      ignore_ssl: EtnaApp.instance.config(:ignore_ssl),
      **EtnaApp.instance.config(:janus, environment) || {})
end

#magma_clientObject



35
36
37
38
39
40
41
42
43
# File 'lib/helpers.rb', line 35

def magma_client
  @magma_client ||= Etna::Clients::Magma.new(
      token: token,
      ignore_ssl: EtnaApp.instance.config(:ignore_ssl),
      # Persistent connections cause problem with magma restarts, until we can fix that we should force them
      # to close + reopen each request.
      persistent: false,
      **EtnaApp.instance.config(:magma, environment) || {})
end

#metis_clientObject



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

def metis_client
  @metis_client ||= Etna::Clients::Metis.new(
      token: token,
      ignore_ssl: EtnaApp.instance.config(:ignore_ssl),
      **EtnaApp.instance.config(:metis, environment) || {})
end

#polyphemus_clientObject



59
60
61
62
63
64
# File 'lib/helpers.rb', line 59

def polyphemus_client
  @polyphemus_client ||= Etna::Clients::Polyphemus.new(
      token: token,
      ignore_ssl: EtnaApp.instance.config(:ignore_ssl),
      **EtnaApp.instance.config(:polyphemus, environment) || {})
end

#tokenObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/helpers.rb', line 9

def token
  if environment == :many
    raise "You have multiple environments configured, please specify your environment by adding --environment #{@config.keys.join("|")}"
  elsif environment == :none
    raise "You do not have a successfully configured environment, please run #{program_name} config set https://polyphemus.ucsf.edu"
  end

  env_token = ENV['TOKEN']
  if !env_token
    puts "No environment variable TOKEN is set.  You should set your token with `export TOKEN=<your.janus.token>` before running."
    redirect = EtnaApp.instance.config(:auth_redirect)

    if redirect.nil? && EtnaApp.instance.environment == :production
      redirect = 'https://janus.ucsf.edu/'
    end

    unless redirect.nil?
      puts "Open your browser to #{redirect} to complete login and copy your token."
    end

    exit
  end

  env_token
end