Sha256: 8313b1a7ec409e3861230f7941f15777731c9dfa786974e5b2aa11ab437a7cea

Contents?: true

Size: 1.75 KB

Versions: 5

Compression:

Stored size: 1.75 KB

Contents

module AptlyCli
  class AptlyCommand
    include HTTMultiParty

    attr_accessor :config
    def initialize(config, options = nil)
      @config = config
      options ||= Options.new

      if options.server
        @config[:server] = options.server
      end

      if options.port
        @config[:port] = options.port
      end

      if options.username
        @config[:username] = options.username
      end

      if options.password
        @config[:password] = options.password
      end

      if options.debug
        @config[:debug] = options.debug
      end

      @config.each do |k, v|
        if v == '${PROMPT}'
          @config[k.to_sym] = ask("Enter a value for #{k}:")
        elsif v == '${PROMPT_PASSWORD}'
          @config[k.to_sym] = password("Enter a value for #{k}:")
        elsif v == '${KEYRING}'
          require 'keyring'

          keyring = Keyring.new
          keychain_item_name = 'Aptly API server at ' + \
                               @config[:server] + ':' + @config[:port].to_s
          value = keyring.get_password(keychain_item_name, @config[:username])

          unless value
            # Prompt for password...
            value = password("Enter a value for #{k}:")

            # ... and store in keyring
            keyring.set_password(keychain_item_name, @config[:username], value)
          end

          @config[k.to_sym] = value
        end
      end

      base_uri = "#{@config[:proto]}://#{@config[:server]}:#{@config[:port]}" \
                 '/api'
      self.class.base_uri base_uri

      if @config[:username]
        if @config[:password]
          self.class.basic_auth @config[:username].to_s, @config[:password].to_s
        end
      end

      self.class.debug_output @config[:debug] ? $stdout : nil
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
aptly_cli-0.4.2 lib/aptly_command.rb
aptly_cli-0.4.0 lib/aptly_command.rb
aptly_cli-0.3.10 lib/aptly_command.rb
aptly_cli-0.3.8 lib/aptly_command.rb
aptly_cli-0.3.7 lib/aptly_command.rb