Class: Emasser::Configuration
- Inherits:
-
Object
- Object
- Emasser::Configuration
- Defined in:
- lib/emasser/configuration.rb
Class Method Summary collapse
- .check_folder_exists(env) ⇒ Object
-
.raise_unless_present(env) ⇒ Object
rubocop: disable Style/GuardClause, Lint/NonAtomicFileOperation rubocop: disable Style/RescueStandardError, Lint/DuplicateBranch, Style/RedundantReturn rubocop: disable Style/RaiseArgs, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.
Instance Method Summary collapse
-
#emasser_env_msg ⇒ Object
rubocop: enable Style/GuardClause, Lint/NonAtomicFileOperation rubocop: enable Style/RescueStandardError, Lint/DuplicateBranch, Style/RedundantReturn rubocop: enable Style/RaiseArgs, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.
- #emasser_pki_help ⇒ Object
Class Method Details
.check_folder_exists(env) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/emasser/configuration.rb', line 34 def self.check_folder_exists(env) folder_path = ENV.fetch(env) # raises error if EMASSER_DOWNLOAD_DIR is missing if folder_path.empty? # Create a default downloads folder raise CreateDefaultDownloadDirectory else # Create the folder if does not exist unless Dir.exist?(folder_path) FileUtils.mkdir_p('eMASSerDownloads') end return folder_path end rescue # CreateDefaultDownloadDirectory # Create the default folder if does not exist unless Dir.exist?('eMASSerDownloads') FileUtils.mkdir_p('eMASSerDownloads') end return 'eMASSerDownloads' end |
.raise_unless_present(env) ⇒ Object
rubocop: disable Style/GuardClause, Lint/NonAtomicFileOperation rubocop: disable Style/RescueStandardError, Lint/DuplicateBranch, Style/RedundantReturn rubocop: disable Style/RaiseArgs, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/emasser/configuration.rb', line 11 def self.raise_unless_present(env) env_value = ENV.fetch(env) { raise Emasser::ConfigurationMissingError.new(env) } if env_value.empty? raise Emasser::ConfigurationEmptyValueError.new(env) end return env_value rescue Emasser::ConfigurationEmptyValueError => e unless (ARGV[0].to_s.include? 'post') && (ARGV[1].to_s.include? 'register') && (env.include? 'EMASSER_API_KEY') puts "\n", e..red show = Configuration.new show.emasser_env_msg exit end rescue Emasser::ConfigurationMissingError => e unless (ARGV[0].to_s.include? 'post') && (ARGV[1].to_s.include? 'register') && (env.include? 'EMASSER_API_KEY') puts "\n", e..red show = Configuration.new show.emasser_env_msg exit end end |
Instance Method Details
#emasser_env_msg ⇒ Object
rubocop: enable Style/GuardClause, Lint/NonAtomicFileOperation rubocop: enable Style/RescueStandardError, Lint/DuplicateBranch, Style/RedundantReturn rubocop: enable Style/RaiseArgs, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/emasser/configuration.rb', line 57 def emasser_env_msg puts 'Create (or update) the configuration (.env) file and place it in the root directory where the emasser command is executed'.yellow puts 'Required environment variables:'.yellow puts ' export EMASSER_API_KEY=<API key>'.green puts ' export EMASSER_HOST_URL=<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_FILE_PASSWORD=<password for the key given in EMASSER_KEY_FILE_PATH>'.green puts 'Note: '.yellow + 'EMASSER_API_KEY is acquired by invoking the "emasser post register cert" API command'.cyan, "\n" puts 'Actionable (POST,PUT,DELETE) variable required by some eMASS instances:'.yellow puts ' export EMASSER_USER_UID=<unique identifier of the eMASS user EMASSER_API_KEY belongs to>'.green puts "\n" puts 'See eMASSer environment variables requirements in eMASSer CLI Features for more information (https://mitre.github.io/emasser/docs/features.html).'.yellow end |
#emasser_pki_help ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/emasser/configuration.rb', line 72 def emasser_pki_help puts 'eMASSer PKI Certificate Requirements:'.yellow puts 'eMASSer uses a client (signed certificate) and key (private key to the certificate) certificate for authenticating to eMASS.'.cyan puts 'Both files are pem (Privacy-Enhanced Mail) text-based containers using base-64 encoding. The key file requires a passphrase.'.cyan puts "\n" puts 'The following variables must be provided on the .env (configuration) file:'.yellow puts ' EMASSER_HOST_URL - The eMASS host URL'.cyan puts ' EMASSER_CERT_FILE_PATH - The client certificate (.pem) file (full path is required)'.cyan puts ' EMASSER_KEY_FILE_PATH - The private key for the certificate (.pem) file (full path is required)'.cyan puts ' EMASSER_KEY_FILE_PASSWORD - The key file passphrase value if the key file password has been set'.cyan puts 'IMPORTANT: If using a self signed certificate in the certificate chain the optional "EMASSER_VERIFY_SSL" variable must be set to false.'.red end |