Class: Emasser::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/emasser/configuration.rb

Class Method Summary collapse

Class Method Details

.raise_unless_present(env) ⇒ Object

rubocop: disable Style/RaiseArgs



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/emasser/configuration.rb', line 8

def self.raise_unless_present(env)
  ENV.fetch(env) { raise Emasser::ConfigurationMissingError.new(env) }
rescue Emasser::ConfigurationMissingError => e
  if (ARGV[0].to_s.include? '-v') || (ARGV[0].to_s.include? '-V')
    puts "emasser version: #{Emasser::VERSION}".green
  else
    puts "\n", e.message.red
    puts 'Create a .env file containing required variables, place it in the root directory where the emasser command is executed'.yellow
    puts 'Required environment variables are:'.yellow
    puts '  export EMASSER_API_KEY_API_KEY=<API key>'.green
    puts '  export EMASSER_API_KEY_USER_UID=<unique identifier of the eMASS user EMASSER_API_KEY_API_KEY belongs to>'.green
    puts '  export EMASSER_HOST=<FQDN of the eMASS server>'.green
    puts '  export EMASSER_KEY_FILE_PATH=<path to your emass key in PEM format>'.green
    puts '  export EMASSER_CERT_FILE_PATH=<path to your emass certficate in PEM format>'.green
    puts '  export EMASSER_KEY_PASSWORD=<password for the key given in EMASSER_KEY_FILE_PATH>'.green, "\n"
    puts 'See emasser environment variables requirements in emasser CLI Features for more information (https://mitre.github.io/emasser/docs/features.html).', "\n"
  end
  exit
end