From e68fae0d8cf43df76e95310171f3ad2fb31cb56f Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Mon, 30 Nov 2015 17:16:45 +0000 Subject: [PATCH 1/2] Adds spec to catch showing a private ip in list --- spec/cli/droplets_cli_spec.rb | 20 ++ spec/fixtures/show_droplets_private_ip.json | 258 ++++++++++++++++++++ 2 files changed, 278 insertions(+) create mode 100644 spec/fixtures/show_droplets_private_ip.json diff --git a/spec/cli/droplets_cli_spec.rb b/spec/cli/droplets_cli_spec.rb index 16af3d7..0e0e0ad 100644 --- a/spec/cli/droplets_cli_spec.rb +++ b/spec/cli/droplets_cli_spec.rb @@ -24,6 +24,26 @@ expect(a_request(:get, "https://api.digitalocean.com/v2/droplets?page=1&per_page=200")).to have_been_made end + it "shows a private IP if droplet in list has private IP" do + stub_request(:get, "https://api.digitalocean.com/v2/droplets?page=1&per_page=1"). + with(: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'}). + to_return(:status => 200, :body => fixture('show_droplets'), :headers => {}) + + stub_request(:get, "https://api.digitalocean.com/v2/droplets?page=1&per_page=200"). + with(: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'}). + to_return(:status => 200, :body => fixture("show_droplets_private_ip"), :headers => {'Content-Type' => 'application/json'},) + + @cli.droplets + + expect($stdout.string).to eq <<-eos +exampleprivate.com (ip: 104.236.32.182, private_ip: 10.131.99.89, status: \e[32mactive\e[0m, region: nyc3, id: 6918990) +example2.com (ip: 104.236.32.172, status: \e[32mactive\e[0m, region: nyc3, id: 3164956) +example3.com (ip: 104.236.32.173, status: \e[31moff\e[0m, region: nyc3, id: 3164444) + eos + + expect(a_request(:get, "https://api.digitalocean.com/v2/droplets?page=1&per_page=200")).to have_been_made + end + it "returns an error message when no droplets exist" do stub_request(:get, "https://api.digitalocean.com/v2/droplets?page=1&per_page=1"). with(: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'}). diff --git a/spec/fixtures/show_droplets_private_ip.json b/spec/fixtures/show_droplets_private_ip.json new file mode 100644 index 0000000..e9f3214 --- /dev/null +++ b/spec/fixtures/show_droplets_private_ip.json @@ -0,0 +1,258 @@ +{ + "droplets": [ + { + "id": 6918990, + "name": "exampleprivate.com", + "memory": 512, + "vcpus": 1, + "disk": 20, + "locked": false, + "status": "active", + "kernel": { + "id": 2233, + "name": "Ubuntu 14.04 x64 vmlinuz-3.13.0-37-generic", + "version": "3.13.0-37-generic" + }, + "created_at": "2014-11-14T16:29:21Z", + "features": [ + "backups", + "ipv6", + "virtio" + ], + "backup_ids": [ + 7938002 + ], + "snapshot_ids": [ + + ], + "image": { + "id": 6918990, + "name": "14.04 x64", + "distribution": "Ubuntu", + "slug": "ubuntu-14-04-x64", + "public": true, + "regions": [ + "nyc1", + "ams1", + "sfo1", + "nyc2", + "ams2", + "sgp1", + "lon1", + "nyc3", + "ams3", + "nyc3" + ], + "created_at": "2014-10-17T20:24:33Z", + "min_disk_size": 20 + }, + "size_slug": "512mb", + "networks": { + "v4": [ + { + "ip_address": "104.236.32.182", + "netmask": "255.255.192.0", + "gateway": "104.236.0.1", + "type": "public" + }, + { + "ip_address": "10.131.99.89", + "netmask": "255.255.0.0", + "gateway": "10.131.0.1", + "type": "private" + } + ], + "v6": [ + { + "ip_address": "2604:A880:0800:0010:0000:0000:02DD:4001", + "netmask": 64, + "gateway": "2604:A880:0800:0010:0000:0000:0000:0001", + "type": "public" + } + ] + }, + "region": { + "name": "New York 3", + "slug": "nyc3", + "sizes": [ + + ], + "features": [ + "virtio", + "private_networking", + "backups", + "ipv6", + "metadata" + ], + "available": null + } + }, + { + "id": 3164956, + "name": "example2.com", + "memory": 512, + "vcpus": 1, + "disk": 20, + "locked": false, + "status": "active", + "kernel": { + "id": 2233, + "name": "Ubuntu 14.04 x64 vmlinuz-3.13.0-37-generic", + "version": "3.13.0-37-generic" + }, + "created_at": "2014-08-14T16:29:21Z", + "features": [ + "backups", + "ipv6", + "virtio" + ], + "backup_ids": [ + 7938002 + ], + "snapshot_ids": [ + + ], + "image": { + "id": 6918990, + "name": "14.04 x64", + "distribution": "Ubuntu", + "slug": "ubuntu-14-04-x64", + "public": true, + "regions": [ + "nyc1", + "ams1", + "sfo1", + "nyc2", + "ams2", + "sgp1", + "lon1", + "nyc3", + "ams3", + "nyc3" + ], + "created_at": "2014-10-17T20:24:33Z", + "min_disk_size": 20 + }, + "size_slug": "512mb", + "networks": { + "v4": [ + { + "ip_address": "104.236.32.172", + "netmask": "255.255.192.0", + "gateway": "104.236.0.1", + "type": "public" + } + ], + "v6": [ + { + "ip_address": "2604:A880:0800:0010:0000:0000:02DD:4001", + "netmask": 64, + "gateway": "2604:A880:0800:0010:0000:0000:0000:0001", + "type": "public" + } + ] + }, + "region": { + "name": "New York 3", + "slug": "nyc3", + "sizes": [ + + ], + "features": [ + "virtio", + "private_networking", + "backups", + "ipv6", + "metadata" + ], + "available": null + } + }, + { + "id": 3164444, + "name": "example3.com", + "memory": 512, + "vcpus": 1, + "disk": 20, + "locked": false, + "status": "off", + "kernel": { + "id": 2233, + "name": "Ubuntu 14.04 x64 vmlinuz-3.13.0-37-generic", + "version": "3.13.0-37-generic" + }, + "created_at": "2014-08-14T16:29:21Z", + "features": [ + "backups", + "ipv6", + "virtio" + ], + "backup_ids": [ + 7938002 + ], + "snapshot_ids": [ + + ], + "image": { + "id": 6918990, + "name": "14.04 x64", + "distribution": "Ubuntu", + "slug": "ubuntu-14-04-x64", + "public": true, + "regions": [ + "nyc1", + "ams1", + "sfo1", + "nyc2", + "ams2", + "sgp1", + "lon1", + "nyc3", + "ams3", + "nyc3" + ], + "created_at": "2014-10-17T20:24:33Z", + "min_disk_size": 20 + }, + "size_slug": "512mb", + "networks": { + "v4": [ + { + "ip_address": "104.236.32.173", + "netmask": "255.255.192.0", + "gateway": "104.236.0.1", + "type": "public" + } + ], + "v6": [ + { + "ip_address": "2604:A880:0800:0010:0000:0000:02DD:4001", + "netmask": 64, + "gateway": "2604:A880:0800:0010:0000:0000:0000:0001", + "type": "public" + } + ] + }, + "region": { + "name": "New York 3", + "slug": "nyc3", + "sizes": [ + + ], + "features": [ + "virtio", + "private_networking", + "backups", + "ipv6", + "metadata" + ], + "available": null + } + } + ], + "links": { + }, + "meta": { + "total": 4 + } +} \ No newline at end of file From 5b1aaad1d8143bd507bb348a76b0a8c3d0e4548b Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Mon, 30 Nov 2015 17:17:15 +0000 Subject: [PATCH 2/2] Changes to private_ip Keeps in line with the name of the attribute from porcelain --- lib/tugboat/middleware/list_droplets.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tugboat/middleware/list_droplets.rb b/lib/tugboat/middleware/list_droplets.rb index b32c774..81d75ab 100644 --- a/lib/tugboat/middleware/list_droplets.rb +++ b/lib/tugboat/middleware/list_droplets.rb @@ -15,7 +15,7 @@ def call(env) private_addr = droplet.networks.v4.detect { |address| address.type == 'private' } if private_addr - private_ip = ", privateip: #{private_addr.ip_address}" + private_ip = ", private_ip: #{private_addr.ip_address}" end if droplet.status == "active"