Module: VagrantPlugins::GitCredentials::Util

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

Instance Method Summary collapse

Instance Method Details

#createKeyObject

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
27
28
29
30
31
32
33
# 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 > ~/.ssh/git.response'])
	
	  # if we have a successful response, skip generating key
	  unless @machine.communicate.test('grep '"id"' ~/.ssh/git.response')
			
	    @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")
	  end
	
	  @machine.communicate.execute("sh /vagrant_shared/build/scripts/recipies/github.sh")

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

#deleteKeyObject

calls github v3 api to remove key from user account



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

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

#promptCredentialsObject

get (temporarily) git credentials from user



41
42
43
44
45
# File 'lib/vagrant-gitcredentials/Util.rb', line 41

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