Sha256: c45a3140d79f3b31867d33198a9306219b92afec12923c8c12c7614e90085db9

Contents?: true

Size: 873 Bytes

Versions: 21

Compression:

Stored size: 873 Bytes

Contents

Execute.define_task do
desc "get-token", "Fetch current api token from rhoconnect"
  def get_token(save = true)
    require 'rest_client'
    url = config[:syncserver]
    password = ''
    begin
      system "stty -echo"
      password = ask "admin password: "
      system "stty echo"
    rescue NoMethodError, Interrupt
      system "stty echo"
      exit
    end
    puts ''
    begin
      token = RestClient.post("#{url}/rc/v1/system/login",
        { :login => 'rhoadmin', :password => password }.to_json, :content_type => :json)
    rescue Exception => e
      puts e.message
      puts "Rhoconnect server is not running or invalid credentials."
      exit
    end
    if save
      token_file = File.join(ENV['HOME'],'.rhoconnect_token')
      File.open(token_file,'w') {|f| f.write(token)}
      puts "Token is saved in: #{token_file}"
    end
    token
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
rhoconnect-7.6.0 commands/rhoconnect/get_token.rb
rhoconnect-7.5.1 commands/rhoconnect/get_token.rb
rhoconnect-7.4.1 commands/rhoconnect/get_token.rb
rhoconnect-7.1.17 commands/rhoconnect/get_token.rb
rhoconnect-6.2.0 commands/rhoconnect/get_token.rb
rhoconnect-6.0.11 commands/rhoconnect/get_token.rb
rhoconnect-5.5.18 commands/rhoconnect/get_token.rb
rhoconnect-5.5.17 commands/rhoconnect/get_token.rb
rhoconnect-5.5.15 commands/rhoconnect/get_token.rb
rhoconnect-5.5.0.22 commands/rhoconnect/get_token.rb
rhoconnect-5.5.2 commands/rhoconnect/get_token.rb
rhoconnect-5.5.0.7 commands/rhoconnect/get_token.rb
rhoconnect-5.5.0.3 commands/rhoconnect/get_token.rb
rhoconnect-5.5.0 commands/rhoconnect/get_token.rb
rhoconnect-5.1.1 commands/rhoconnect/get_token.rb
rhoconnect-4.0.4 commands/rhoconnect/get_token.rb
rhoconnect-4.0.3 commands/rhoconnect/get_token.rb
rhoconnect-4.0.2 commands/rhoconnect/get_token.rb
rhoconnect-4.0.1 commands/rhoconnect/get_token.rb
rhoconnect-4.0.0 commands/rhoconnect/get_token.rb