Module: VagrantPlugins::GitCredentials::Util

Included in:
Action::AddKey, Action::RemoveKey
Defined in:
lib/vagrant-gitcredentials/Util.rb

Instance Method Summary collapse

Instance Method Details

#createKey ⇒ Object

generates new ssh key and calls github v3 api to add key to user account



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vagrant-gitcredentials/Util.rb', line 6

def createKey 
	  script = ["GITHUB_USERNAME=$1", "GITHUB_PASSWORD=$2"]
	  script.concat(["ssh-keygen -N '' -f ~/.ssh/github_rsa", "ssh-add ~/.ssh/github_rsa"])
	  script.concat(["set -- $(<~/.ssh/github_rsa.pub)", 'JSON=\'{"title":"vagrant provision key", "key": "ssh-rsa \'$2\'"}\''])
	  script.concat(['curl -u "$GITHUB_USERNAME:$GITHUB_PASSWORD" -d "$JSON" https://api.github.com/user/keys'])
	  @machine.communicate.execute("echo '' > ~/.ssh/github.sh")
	  # create script
	  script.each {
		|l|
		e = Shellwords.escape(l);
		@machine.communicate.execute("echo #{e} >> ~/.ssh/github.sh")
	  }
	  # set permissions for execution
	  @machine.communicate.execute("chmod 755 ~/.ssh/github.sh")
	  @machine.communicate.execute("cat ~/.ssh/github.sh")
	  # execute script w/ permissions
	  promptCredentials()				
	  @machine.communicate.execute("sh ~/.ssh/github.sh #@gitUsername #@gitPassword")

	@ui.info("created ssh key")
end

#deleteKey ⇒ Object

calls github v3 api to remove key from user account



29
30
31
# File 'lib/vagrant-gitcredentials/Util.rb', line 29

def deleteKey 
	@ui.info("not yet implemented")
end

#promptCredentials ⇒ Object

get (temporarily) git credentials from user



34
35
36
37
38
# File 'lib/vagrant-gitcredentials/Util.rb', line 34

def promptCredentials
	@ui.info("We will now generate an ssh key and add it to your github account.")
	@gitUsername = @ui.ask("What is your github account name? ")
	@gitPassword = @ui.ask("What is your github account password? (not stored) ")
end