Permalink
Browse files

remove annoying prompts and key uploads from github ssh recipes

  • Loading branch information...
1 parent 3e6f51b commit 11fcfd67481bd626acf98d43bb77f2efb9c51b23 Doc Ritezel and Matthew Kocher committed Dec 1, 2012
Showing with 3 additions and 38 deletions.
  1. +3 −38 recipes/github_ssh_keys.rb
View
@@ -12,23 +12,6 @@
mode "0644"
end
-if !File.exist?("#{WS_HOME}/.ssh/known_hosts") || !File.read("#{WS_HOME}/.ssh/known_hosts").include?("github.com")
- if node["github_username"].nil? || node["github_password"].nil?
- require "tempfile"
- credentials_script = Tempfile.new("github_credentials")
- credentials_script << <<-RUBY
- value = gets
- puts value
- RUBY
- credentials_script.rewind
- print "Github Username: "
- node["github_username"] = `ruby #{credentials_script.path}`.strip
- print "Github Password: "
- node["github_password"] = `ruby #{credentials_script.path}`.strip
- credentials_script.close
- end
-end
-
# If there is no github_project defined, we will use the name of the machine as the SSH key,
# therefore make sure we have a name first.
include_recipe "pivotal_workstation::rename_machine" unless node["github_project"]
@@ -43,8 +26,8 @@
end
execute "make sure .ssh/config is owned by the user" do
- only_if "test -e #{WS_HOME}/.ssh/config"
command "chown #{WS_USER} #{WS_HOME}/.ssh/config"
+ only_if "test -e #{WS_HOME}/.ssh/config"
end
execute "create SSH key pair for Github" do
@@ -56,11 +39,13 @@
execute "symlink Github key for git-project" do
command "ln -nfs #{WS_HOME}/.ssh/id_github_{#{node["github_project"] || node['fqdn']},current}"
user WS_USER
+ only_if { node.has_key?("github_project") }
end
execute "symlink Github public key for git-project" do
command "ln -nfs #{WS_HOME}/.ssh/id_github_{#{node["github_project"] || node['fqdn']},current}.pub"
user WS_USER
+ only_if { node.has_key?("github_project") }
end
execute "add Github configuration to .ssh/config" do
@@ -69,23 +54,3 @@
not_if "grep 'id_github_current' #{WS_HOME}/.ssh/config"
user WS_USER
end
-
-# add ssh keys to github account if possible
-if node["github_username"].to_s != "" && node["github_password"].to_s != ""
- github_name="#{WS_USER}@#{node['fqdn']}"
- curl_options = %[--retry 3 --retry-delay 5 --retry-max-time 30 --connect-timeout 5 --max-time 30 -u "#{node["github_username"]}:#{node["github_password"]}"]
- execute "upload ssh key to github if it does not already exist there" do
- not_if <<-SH
- curl #{curl_options} https://api.github.com/user/keys | grep "`cat #{WS_HOME}/.ssh/id_github_#{node["github_project"] || node["fqdn"]}.pub` | cut -f 2 -d ' '`"
- SH
- command <<-SH
- curl -X POST --verbose #{curl_options} \
- --data "{ \\"key\\": \\"`cat #{WS_HOME}/.ssh/id_github_#{node["github_project"] || node["fqdn"]}.pub`\\", \\"title\\": \\"#{github_name}\\" }" \
- https://api.github.com/user/keys
- SH
- end
- user WS_USER
-else
- log "No GITHUB_USERNAME or GITHUB_PASSWORD provided, skipping steps to upload ssh keys to github.com"
-end
-

0 comments on commit 11fcfd6

Please sign in to comment.