Sha256: 2a2b9cf8a6613a24afff4f44f1545e482cb35b6a2e9d42ff0b5464a5ab008f73

Contents?: true

Size: 811 Bytes

Versions: 2

Compression:

Stored size: 811 Bytes

Contents

Execute.define_task do
desc "get-token", "Fetch current api token from rhoconnect"
  def get_token(save = true)
    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
      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

2 entries across 2 versions & 1 rubygems

Version Path
rhoconnect-4.0.0.beta.10 commands/rhoconnect/get_token.rb
rhoconnect-4.0.0.beta.12 commands/rhoconnect/get_token.rb