Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prompt for vCentre password so it doesn't need to be saved in config file #36

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

robinbowes
Copy link

No description provided.

@tomeon
Copy link

tomeon commented Feb 11, 2016

Would really appreciate this feature! 👍

@robinbowes
Copy link
Author

@BaxterStockman I worked around this as follows:

Put your credentials in a file in the root of your home dir named .vcenter_login.yaml like this:

---
username: "your_username"
password: "your_password"

Add code to Vagrantfile, something like this:

provider = 'vcenter'
creds_file = YAML.load_file(File.expand_path("~/.#{provider}_login.yaml"))
username = creds_file['username']
password = creds_file['password']

Then you can use the username and password variables like this:

config.vm.provider :vcenter do |vcenter|
     vcenter.username = username
     vcenter.password = password
...

@tomeon
Copy link

tomeon commented Feb 11, 2016

@robinbowes -- thanks for sharing your setup! I had hoped to do something similar, but I've gotten pushback from colleagues who aren't enthusiastic about storing their credentials in a file (even with restrictive permissions). I have a workaround, but it makes me feel bad about myself 😢:

# This is a simplified version of the logic that's followed in `bin/vagrant`;
# see https://github.com/mitchellh/vagrant/blob/master/bin/vagrant.          
class UI                                                                     
  extend SingleForwardable                                                   

  class << self                                                              
    attr_accessor :ui                                                        

    def init(argv = ARGV)                                                    
      self.ui = ui_class(argv).new                                           
    end                                                                      

    def ui_class(argv)                                                       
      if argv.include?("--machine-readable")                                 
        Vagrant::UI::MachineReadable                                         
      elsif argv.include?("--no-color") || ENV["VAGRANT_NO_COLOR"]           
        Vagrant::UI::Basic                                                   
      elsif argv.include?("--color")                                         
        Vagrant::UI::Colored                                                 
      elsif !Vagrant::Util::Platform.terminal_supports_colors?               
        Vagrant::UI::Basic                                                   
      elsif !$stdout.tty? && !Vagrant::Util::Platform.cygwin?                
        Vagrant::UI::Basic                                                   
      else                                                                   
        Vagrant::UI::Colored                                                 
      end                                                                    
    end                                                                      

    private :ui_class                                                        
  end                                                                        

  def_single_delegators :ui, :ask, :detail, :warn, :error, :info, :output,   
                        :success                                             
end

UI.init                                                                             

Vagrant.configure('2') do |config|                                                  
  config.vm.provider :vcenter do |vcenter|                                                                  
    vcenter.password = UI.ask('vSphere password (will be hidden): ', :echo => false)                                                                          
   end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants