Project

General

Profile

Download (1.69 KB) Statistics
| Branch: | Tag: | Revision:

hammer-cli-csv / lib / hammer_cli_csv / utils / config.rb @ f5d21adb

1
module HammerCLICsv
2
  module Utils
3
    module Config
4
      def credentials
5
        @credentials ||= HammerCLIForeman::BasicCredentials.new(
6
          :username => (HammerCLI::Settings.get(:_params, :username) || ENV['FOREMAN_USERNAME'] || HammerCLI::Settings.get(:foreman, :username)),
7
          :password => (HammerCLI::Settings.get(:_params, :password) || ENV['FOREMAN_PASSWORD'] || HammerCLI::Settings.get(:foreman, :password))
8
        )
9
        @credentials
10
      end
11

    
12
      def resource_config
13
        config = {}
14
        config[:uri] = HammerCLI::Settings.get(:_params, :host) || HammerCLI::Settings.get(:foreman, :host)
15
        config[:credentials] = credentials
16
        config[:logger] = Logging.logger['API']
17
        config[:api_version] = 2
18
        config[:follow_redirects] = HammerCLI::Settings.get(:foreman, :follow_redirects) || :never
19
        config[:aggressive_cache_checking] = HammerCLI::Settings.get(:foreman, :refresh_cache) || false
20
        config[:headers] = { "Accept-Language" => HammerCLI::I18n.locale }
21
        config[:language] = HammerCLI::I18n.locale
22
        config[:timeout] = HammerCLI::Settings.get(:foreman, :request_timeout)
23
        config[:timeout] = -1 if config[:timeout] && config[:timeout].to_i < 0
24
        config[:apidoc_authenticated] = false
25

    
26
        @username = config[:credentials].username
27
        @password = config[:credentials].password
28
        @server = config[:uri]
29
        config
30
      end
31

    
32
      def api_connection
33
        connection = HammerCLI::Connection.create(
34
          'csv',
35
          HammerCLI::Apipie::Command.resource_config.merge(resource_config),
36
          HammerCLI::Apipie::Command.connection_options
37
        )
38
        connection.api
39
      end
40
    end
41
  end
42
end