Skip to content

Commit 61b2e3a

Browse files
committed
Merge pull request #233 from pearkes/ip6_config_setup_rebase
Configuration support for IPv6
2 parents 88a055c + cb8d4d7 commit 61b2e3a

File tree

7 files changed

+33
-9
lines changed

7 files changed

+33
-9
lines changed

lib/tugboat/config.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def reload!
106106
end
107107

108108
# Writes a config file
109-
def create_config_file(access_token, ssh_key_path, ssh_user, ssh_port, region, image, size, ssh_key, private_networking, backups_enabled)
109+
def create_config_file(access_token, ssh_key_path, ssh_user, ssh_port, region, image, size, ssh_key, private_networking, backups_enabled, ip6)
110110
# Default SSH Key path
111111
if ssh_key_path.empty?
112112
ssh_key_path = File.join("~", DEFAULT_SSH_KEY_PATH)
@@ -144,6 +144,10 @@ def create_config_file(access_token, ssh_key_path, ssh_user, ssh_port, region, i
144144
backups_enabled = DEFAULT_BACKUPS_ENABLED
145145
end
146146

147+
if ip6.empty?
148+
ip6 = DEFAULT_IP6
149+
end
150+
147151
require 'yaml'
148152
File.open(@path, File::RDWR|File::TRUNC|File::CREAT, 0600) do |file|
149153
data = {
@@ -160,7 +164,8 @@ def create_config_file(access_token, ssh_key_path, ssh_user, ssh_port, region, i
160164
"size" => size,
161165
"ssh_key" => ssh_key,
162166
"private_networking" => private_networking,
163-
"backups_enabled" => backups_enabled
167+
"backups_enabled" => backups_enabled,
168+
"ip6" => ip6,
164169
}
165170
}
166171
file.write data.to_yaml

lib/tugboat/middleware/ask_for_credentials.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ def call(env)
2020
ssh_key = ask "Enter your default ssh key IDs (optional, defaults to none, comma separated string):"
2121
private_networking = ask "Enter your default for private networking (optional, defaults to false):"
2222
backups_enabled = ask "Enter your default for enabling backups (optional, defaults to false):"
23+
ip6 = ask "Enter your default for IPv6 (optional, defaults to false):"
2324

2425
# Write the config file.
25-
env['config'].create_config_file(access_token, ssh_key_path, ssh_user, ssh_port, region, image, size, ssh_key, private_networking, backups_enabled)
26+
env['config'].create_config_file(access_token, ssh_key_path, ssh_user, ssh_port, region, image, size, ssh_key, private_networking, backups_enabled, ip6)
2627
env['config'].reload!
2728

2829
@app.call(env)

spec/cli/authorize_cli_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
expect($stdin).to receive(:gets).and_return(private_networking)
3737
expect($stdout).to receive(:print).with("Enter your default for enabling backups (optional, defaults to false): ")
3838
expect($stdin).to receive(:gets).and_return(backups_enabled)
39+
expect($stdout).to receive(:print).with("Enter your default for IPv6 (optional, defaults to false): ")
40+
expect($stdin).to receive(:gets).and_return(ip6)
3941

4042
@cli.authorize
4143

@@ -54,6 +56,7 @@
5456
expect(config["defaults"]["ssh_key"]).to eq ssh_key_id
5557
expect(config["defaults"]["private_networking"]).to eq private_networking
5658
expect(config["defaults"]["backups_enabled"]).to eq backups_enabled
59+
expect(config["defaults"]["ip6"]).to eq ip6
5760
end
5861

5962
it "sets defaults if no input given" do
@@ -82,6 +85,8 @@
8285
expect($stdin).to receive(:gets).and_return('')
8386
expect($stdout).to receive(:print).with("Enter your default for enabling backups (optional, defaults to false): ")
8487
expect($stdin).to receive(:gets).and_return('')
88+
expect($stdout).to receive(:print).with("Enter your default for IPv6 (optional, defaults to false): ")
89+
expect($stdin).to receive(:gets).and_return('')
8590

8691
@cli.authorize
8792

@@ -98,6 +103,9 @@
98103
expect(config["ssh"]["ssh_key_path"]).to eq "~/.ssh/id_rsa"
99104
expect(config["ssh"]["ssh_port"]).to eq "22"
100105
expect(config["defaults"]["ssh_key"]).to eq ""
106+
expect(config["defaults"]["private_networking"]).to eq 'false'
107+
expect(config["defaults"]["backups_enabled"]).to eq 'false'
108+
expect(config["defaults"]["ip6"]).to eq 'false'
101109
end
102110
end
103111

spec/cli/config_cli_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
ssh_key: '1234'
2626
private_networking: 'false'
2727
backups_enabled: 'false'
28+
ip6: 'false'
2829
eos
2930
end
3031

@@ -50,6 +51,7 @@
5051
ssh_key: '1234'
5152
private_networking: 'false'
5253
backups_enabled: 'false'
54+
ip6: 'false'
5355
eos
5456
end
5557
end

spec/cli/create_cli_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
describe "create a droplet" do
77
it "with a name, uses defaults from configuration" do
88
stub_request(:post, "https://api.digitalocean.com/v2/droplets").
9-
with(:body => "{\"name\":\"foo\",\"size\":\"512mb\",\"image\":\"ubuntu-14-04-x64\",\"region\":\"nyc2\",\"ssh_keys\":[\"1234\"],\"private_networking\":\"false\",\"backups_enabled\":\"false\",\"ipv6\":null,\"user_data\":null}",
9+
with(:body => "{\"name\":\"foo\",\"size\":\"512mb\",\"image\":\"ubuntu-14-04-x64\",\"region\":\"nyc2\",\"ssh_keys\":[\"1234\"],\"private_networking\":\"false\",\"backups_enabled\":\"false\",\"ipv6\":\"false\",\"user_data\":null}",
1010
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer foo', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.2'}).
1111
to_return(:status => 200, :body => fixture('create_droplet'), :headers => {})
1212

@@ -19,7 +19,7 @@
1919

2020
it "with args does not use defaults from configuration" do
2121
stub_request(:post, "https://api.digitalocean.com/v2/droplets").
22-
with(:body => "{\"name\":\"example.com\",\"size\":\"1gb\",\"image\":\"ubuntu-12-04-x64\",\"region\":\"nyc3\",\"ssh_keys\":[\"foo_bar_key\"],\"private_networking\":\"false\",\"backups_enabled\":\"false\",\"ipv6\":null,\"user_data\":null}",
22+
with(:body => "{\"name\":\"example.com\",\"size\":\"1gb\",\"image\":\"ubuntu-12-04-x64\",\"region\":\"nyc3\",\"ssh_keys\":[\"foo_bar_key\"],\"private_networking\":\"false\",\"backups_enabled\":\"false\",\"ipv6\":\"false\",\"user_data\":null}",
2323
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer foo', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.2'}).
2424
to_return(:status => 200, :body => fixture('create_droplet'), :headers => {})
2525

@@ -49,7 +49,7 @@
4949

5050
it "with user data args" do
5151
stub_request(:post, "https://api.digitalocean.com/v2/droplets").
52-
with(:body => "{\"name\":\"example.com\",\"size\":\"512mb\",\"image\":\"ubuntu-14-04-x64\",\"region\":\"nyc2\",\"ssh_keys\":[\"1234\"],\"private_networking\":\"false\",\"backups_enabled\":\"false\",\"ipv6\":null,\"user_data\":\"#!/bin/bash\\n\\necho \\\"Hello world\\\"\"}",
52+
with(:body => "{\"name\":\"example.com\",\"size\":\"512mb\",\"image\":\"ubuntu-14-04-x64\",\"region\":\"nyc2\",\"ssh_keys\":[\"1234\"],\"private_networking\":\"false\",\"backups_enabled\":\"false\",\"ipv6\":\"false\",\"user_data\":\"#!/bin/bash\\n\\necho \\\"Hello world\\\"\"}",
5353
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer foo', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.2'}).
5454
to_return(:status => 200, :body => fixture('create_droplet'), :headers => {})
5555

@@ -103,7 +103,7 @@
103103

104104
it "does not clobber named droplets that contain the word help" do
105105
stub_request(:post, "https://api.digitalocean.com/v2/droplets").
106-
with(:body => "{\"name\":\"somethingblahblah--help\",\"size\":\"512mb\",\"image\":\"ubuntu-14-04-x64\",\"region\":\"nyc2\",\"ssh_keys\":[\"1234\"],\"private_networking\":\"false\",\"backups_enabled\":\"false\",\"ipv6\":null,\"user_data\":null}",
106+
with(:body => "{\"name\":\"somethingblahblah--help\",\"size\":\"512mb\",\"image\":\"ubuntu-14-04-x64\",\"region\":\"nyc2\",\"ssh_keys\":[\"1234\"],\"private_networking\":\"false\",\"backups_enabled\":\"false\",\"ipv6\":\"false\",\"user_data\":null}",
107107
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer foo', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.2'}).
108108
to_return(:status => 200, :body => fixture('create_droplet'), :headers => {})
109109

spec/config_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@
3333
let(:ssh_key_id) { '1234' }
3434
let(:private_networking) { 'false' }
3535
let(:backups_enabled) { 'false' }
36+
let(:ip6) { 'false' }
3637

3738
let(:config) { config = Tugboat::Configuration.instance }
3839

3940
before :each do
4041
# Create a temporary file
41-
config.create_config_file(access_token, ssh_key_path, ssh_user, ssh_port, region, image, size, ssh_key_id, private_networking, backups_enabled)
42+
config.create_config_file(access_token, ssh_key_path, ssh_user, ssh_port, region, image, size, ssh_key_id, private_networking, backups_enabled, ip6)
4243
end
4344

4445
it "can be created" do
@@ -105,6 +106,7 @@
105106
let(:config_default_ssh_key) { Tugboat::Configuration::DEFAULT_SSH_KEY }
106107
let(:config_default_networking) { Tugboat::Configuration::DEFAULT_PRIVATE_NETWORKING }
107108
let(:config_default_backups) { Tugboat::Configuration::DEFAULT_BACKUPS_ENABLED }
109+
let(:config_default_ip6) { Tugboat::Configuration::DEFAULT_IP6 }
108110
let(:backwards_config) {
109111
{
110112
'authentication' => { 'client_key' => client_key, 'api_key' => api_key },
@@ -151,5 +153,10 @@
151153
expect(backups_enabled).to eql config_default_backups
152154
end
153155

156+
it "should use default ip6 if not in the configuration" do
157+
ip6 = config.default_ip6
158+
expect(ip6).to eql config_default_ip6
159+
end
160+
154161
end
155162
end

spec/shared/environment.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
let(:ssh_public_key) { 'ssh-dss A123= user@host' }
2020
let(:private_networking) { 'false'}
2121
let(:backups_enabled) { 'false'}
22+
let(:ip6) { 'false' }
2223
let(:ocean) { Barge::Client.new(:access_token => access_token) }
2324
let(:app) { lambda { |env| } }
2425
let(:env) { {} }
@@ -30,7 +31,7 @@
3031
@cli = Tugboat::CLI.new
3132

3233
# Set a temprary project path and create fake config.
33-
config.create_config_file(access_token, ssh_key_path, ssh_user, ssh_port, region, image, size, ssh_key_id, private_networking, backups_enabled)
34+
config.create_config_file(access_token, ssh_key_path, ssh_user, ssh_port, region, image, size, ssh_key_id, private_networking, backups_enabled, ip6)
3435
config.reload!
3536

3637
# Keep track of the old stderr / out

0 commit comments

Comments
 (0)