<commit_before># encoding: UTF-8
#
# Copyright (c) 2010-2015 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 'highline/import'

require_relative '../cli/terminal'
require_relative '../helpers/helpers'

module GoodData
  module Command
    class Auth
      class << self
        # Ask for credentials
        # @param [String] credentials_file_path (credentials_file) Path to .gooddata file
        # @return [Hash]
        #   * :username [String] Username (email address)
        #   * :password [String] Password
        #   * :auth_token [String] Authorization token
        #   * :environment [String] Environment - DEVELOPMENT, TEST, PRODUCTION
        #   * :server => [String] Server - https://secure.gooddata.com
        def ask_for_credentials(credentials_file_path = Helpers::AuthHelper.credentials_file)
          puts 'Enter your GoodData credentials.'

          old_credentials = Helpers::AuthHelper.read_credentials(credentials_file_path)

          # Ask for user email
          user = GoodData::CLI.terminal.ask('Email') do |q|
            set_default_value(q, old_credentials[:username])
          end

          # Ask for password
          password = GoodData::CLI.terminal.ask('Password') do |q|
            # set_default_value(q, old_credentials[:password])
            q.echo = '*'
          end

          # Ask for token
          auth_token = GoodData::CLI.terminal.ask('Authorization Token') do |q|
            set_default_value(q, old_credentials[:auth_token])
          end

          # Read environment
          environment = GoodData::CLI.terminal.ask('Environment') do |q|
            set_default_value(q, old_credentials[:environment], GoodData::Project::DEFAULT_ENVIRONMENT)
          end

          # Read server
          server = GoodData::CLI.terminal.ask('Server') do |q|
            set_default_value(q, old_credentials[:server], 'https://secure.gooddata.com')
          end

          # Return as struct
          {
            :username => user,
            :password => password,
            :auth_token => auth_token,
            :environment => environment,
            :server => server
          }
        end

        # Ask for credentials and store them
        def store(credentials_file_path = Helpers::AuthHelper.credentials_file)
          credentials = ask_for_credentials
<commit_msg>[BIA-244] Add explicit note about non encrypted storage of data in auth:store command in CLI<commit_after># encoding: UTF-8
#
# Copyright (c) 2010-2015 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 'highline/import'

require_relative '../cli/terminal'
require_relative '../helpers/helpers'

module GoodData
  module Command
    class Auth
      class << self
        # Ask for credentials
        # @param [String] credentials_file_path (credentials_file) Path to .gooddata file
        # @return [Hash]
        #   * :username [String] Username (email address)
        #   * :password [String] Password
        #   * :auth_token [String] Authorization token
        #   * :environment [String] Environment - DEVELOPMENT, TEST, PRODUCTION
        #   * :server => [String] Server - https://secure.gooddata.com
        def ask_for_credentials(credentials_file_path = Helpers::AuthHelper.credentials_file)
          puts 'Enter your GoodData credentials.'

          old_credentials = Helpers::AuthHelper.read_credentials(credentials_file_path)

          # Ask for user email
          user = GoodData::CLI.terminal.ask('Email') do |q|
            set_default_value(q, old_credentials[:username])
          end

          # Ask for password
          password = GoodData::CLI.terminal.ask('Password') do |q|
            # set_default_value(q, old_credentials[:password])
            q.echo = '*'
          end

          # Ask for token
          auth_token = GoodData::CLI.terminal.ask('Authorization Token') do |q|
            set_default_value(q, old_credentials[:auth_token])
          end

          # Read environment
          environment = GoodData::CLI.terminal.ask('Environment') do |q|
            set_default_value(q, old_credentials[:environment], GoodData::Project::DEFAULT_ENVIRONMENT)
          end

          # Read server
          server = GoodData::CLI.terminal.ask('Server') do |q|
            set_default_value(q, old_credentials[:server], 'https://secure.gooddata.com')
          end

          # Return as struct
          {
            :username => user,
            :password => password,
            :auth_token => auth_token,
            :environment => environment,
            :server => server
          }
        end

        # Ask for credentials and store them
        def store(credentials_file_path = Helpers::AuthHelper.credentials_file)
          puts 'This will store credntials to GoodData in an enencrypted form to your harddrive to file ~/.gooddata.'
          overwrite = GoodData::CLI.terminal.ask('Do you want to continue? (y/n)')
          return if overwrite != 'y'

          credentials = ask_for_credentials

{'fraction_non_alphanumeric': 0.0954821564160972, 'fraction_numerical': 0.003986332574031891, 'mean_word_length': 2.419208306294614, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4866027', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1407, 'n_words': 382}