Sha256: dca00f1446f4b2625f042e939f5609c92b00e88ad8388df979f6949a8ab8d5c5

Contents?: true

Size: 1.63 KB

Versions: 42

Compression:

Stored size: 1.63 KB

Contents

#
# Copyright (c) 2010-2017 GoodData Corporation. All rights reserved.
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

require 'gli'

require_relative '../helpers/auth_helpers'

GoodData::CLI.module_eval do
  pre do |global, _command, _options, _args|
    require 'logger'
    GoodData.logger = Logger.new(STDERR)
    GoodData.logger.level = Logger::Severity::ERROR
    username = global[:username]
    password = global[:password]
    token = global[:token]

    creds = GoodData::Helpers::AuthHelper.read_credentials

    username = creds[:username] if username.nil?
    password = creds[:password] if password.nil?
    token = creds[:auth_token] || creds[:token] if token.nil?
    GoodData.logger.error 'SSL verification is turned off. I hope you are not in production!' unless global[:verify_ssl]

    global[:token] = token if global[:token].nil?
    if global[:login].nil?
      global[:login] = username
      global['login'] = username
    end
    if global[:password].nil?
      global[:password] = password
      global['password'] = password
    end
    # Pre logic here
    # Return true to proceed; false to abort and not call the
    # chosen command
    # Use skips_pre before a command to skip this block
    # on that command only
    true
  end

  post do |_global, _command, _options, _args|
    # Post logic here
    # Use skips_post before a command to skip this
    # block on that command only
  end

  on_error do |_exception|
    # Error logic here
    # return false to skip default error handling
    # pp exception.backtrace
    # pp exception
    true
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
gooddata-2.1.0-java lib/gooddata/cli/hooks.rb
gooddata-2.1.0 lib/gooddata/cli/hooks.rb