class Cloudkeeper::Aws::CLI

Class defining CLI of cloudkeeper-aws

Constants

SIGINT
SIGNALS
SIGTERM

Public Instance Methods

sync() click to toggle source
# File lib/cloudkeeper/aws/cli.rb, line 71
def sync
  initialize_config
  initialize_logger
  logger.debug { "Running with config: #{Cloudkeeper::Aws::Settings.to_hash.inspect}" }
  initialize_grpc
rescue Cloudkeeper::Aws::Errors::InvalidConfigurationError => ex
  abort ex.message
rescue StandardError => ex
  logger.error "Unexpected error: #{ex.message}"
  raise ex
end
version() click to toggle source
# File lib/cloudkeeper/aws/cli.rb, line 84
def version
  $stdout.puts Cloudkeeper::Aws::VERSION
end

Private Instance Methods

all_options_available(required_options) click to toggle source
# File lib/cloudkeeper/aws/cli.rb, line 133
def all_options_available(required_options)
  required_options.reduce(true) { |acc, elem| Cloudkeeper::Aws::Settings[elem] && acc }
end
credentials() click to toggle source
# File lib/cloudkeeper/aws/cli.rb, line 110
def credentials
  return :this_port_is_insecure unless Cloudkeeper::Aws::Settings[:authentication]

  GRPC::Core::ServerCredentials.new(
    File.read(Cloudkeeper::Aws::Settings[:'core-certificate']),
    [private_key: File.read(Cloudkeeper::Aws::Settings[:key]),
     cert_chain: File.read(Cloudkeeper::Aws::Settings[:certificate])],
    true
  )
end
initialize_config() click to toggle source
# File lib/cloudkeeper/aws/cli.rb, line 103
def initialize_config
  aws_config = Cloudkeeper::Aws::Settings[:aws]
  Cloudkeeper::Aws::Settings.clear
  Cloudkeeper::Aws::Settings.merge! options.to_hash
  Cloudkeeper::Aws::Settings[:aws] = aws_config
end
initialize_grpc() click to toggle source
# File lib/cloudkeeper/aws/cli.rb, line 92
def initialize_grpc
  grpc_server = GRPC::RpcServer.new
  grpc_server.add_http2_port Cloudkeeper::Aws::Settings[:'listen-address'], credentials
  grpc_server.handle Cloudkeeper::Aws::CoreConnector.new(Cloudkeeper::Aws::Cloud.new)
  grpc_server.run_till_terminated
rescue SignalException => ex
  raise ex unless SIGNALS.include? ex.signo

  grpc_server.stop
end
initialize_logger() click to toggle source
# File lib/cloudkeeper/aws/cli.rb, line 137
def initialize_logger
  logging_level = options['logging-level']
  logging_level = 'debug' if options['debug']

  Yell.new :stdout, name: Object, level: logging_level.downcase, format: Yell::DefaultFormat
  Object.send :include, Yell::Loggable

  setup_file_logger if options['logging-file']

  logger.debug { 'Running in debug mode...' }
end
setup_file_logger() click to toggle source
# File lib/cloudkeeper/aws/cli.rb, line 149
def setup_file_logger
  logging_file = options['logging-file']
  unless (File.exist?(logging_file) && File.writable?(logging_file)) || File.writable?(File.dirname(logging_file))
    logger.error "File #{logging_file} isn't writable"
    return
  end
  logger.adapter :file, logging_file
end
validate_configuration!() click to toggle source
# File lib/cloudkeeper/aws/cli.rb, line 121
def validate_configuration!
  validate_configuration_group! :authentication,
                                %i[certificate key core-certificate],
                                'Authentication configuration missing'
end
validate_configuration_group!(flag, required_options, error_message) click to toggle source
# File lib/cloudkeeper/aws/cli.rb, line 127
def validate_configuration_group!(flag, required_options, error_message)
  return unless Cloudkeeper::Aws::Settings[flag]

  raise Cloudkeeper::Aws::Errors::InvalidConfigurationError, error_message unless all_options_available(required_options)
end