Skip to content

Commit

Permalink
Allow specifying the public_key_path
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Mar 12, 2013
1 parent a991fb3 commit d92a2ad
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ This provider exposes quite a few provider-specific configuration options:
exact ID or name of the image, or this can be a regular expression to
partially match some image.
* `endpoint` - The endpoint to hit. By default this is DFW.
* `public_key_path` - The path to a public key to initialize with the remote
server. This should be the matching pair for the private key configured
with `config.ssh.private_key_path` on Vagrant.
* `username` - The username with which to access Rackspace.

These can be set like typical provider-specific configuration:
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-rackspace/action/create_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def call(env)
:personality => [
{
:path => "/root/.ssh/authorized_keys",
:contents => Base64.encode64(Vagrant.source_root.join("keys/vagrant.pub").read)
:contents => Base64.encode64(File.read(config.public_key_path))
}
]
}
Expand Down
11 changes: 11 additions & 0 deletions lib/vagrant-rackspace/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class Config < Vagrant.plugin("2", :config)
# expression to partially match a name.
attr_accessor :image

# The path to the public key to set up on the remote server for SSH.
# This should match the private key configured with `config.ssh.private_key_path`.
#
# @return [String]
attr_accessor :public_key_path

# The username to access RackSpace.
#
# @return [String]
Expand All @@ -32,6 +38,7 @@ def initialize
@endpoint = UNSET_VALUE
@flavor = UNSET_VALUE
@image = UNSET_VALUE
@public_key_path = UNSET_VALUE
@username = UNSET_VALUE
end

Expand All @@ -41,6 +48,10 @@ def finalize!
@flavor = nil if @flavor == UNSET_VALUE
@image = nil if @image == UNSET_VALUE
@username = nil if @username == UNSET_VALUE

if @public_key_path == UNSET_VALUE
@public_key_path = Vagrant.source_root.join("keys/vagrant.pub")
end
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/vagrant-rackspace/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

describe VagrantPlugins::Rackspace::Config do
describe "defaults" do
let(:vagrant_public_key) { Vagrant.source_root.join("keys/vagrant.pub") }

subject do
super().tap do |o|
o.finalize!
Expand All @@ -12,6 +14,7 @@
its(:endpoint) { should be_nil }
its(:flavor) { should be_nil }
its(:image) { should be_nil }
its(:public_key_path) { should eql(vagrant_public_key) }
its(:username) { should be_nil }
end

Expand All @@ -20,6 +23,7 @@
:endpoint,
:flavor,
:image,
:public_key_path,
:username].each do |attribute|
it "should not default #{attribute} if overridden" do
subject.send("#{attribute}=".to_sym, "foo")
Expand Down

0 comments on commit d92a2ad

Please sign in to comment.