diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 010732836..63e7fb5de 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -839,183 +839,183 @@ }, { "ImportPath": "github.com/rackspace/gophercloud", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/bootfromvolume", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/floatingip", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/keypairs", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/schedulerhints", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/secgroups", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/servergroups", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/tenantnetworks", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/volumeattach", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/compute/v2/flavors", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/compute/v2/images", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/compute/v2/servers", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/identity/v2/tenants", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/identity/v2/tokens", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/identity/v3/tokens", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/networking/v2/extensions/fwaas/policies", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/networking/v2/extensions/fwaas/rules", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/networking/v2/extensions/layer3/floatingips", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/networking/v2/extensions/layer3/routers", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas/members", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas/monitors", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas/pools", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas/vips", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/networking/v2/networks", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/networking/v2/ports", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/networking/v2/subnets", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/objectstorage/v1/accounts", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/objectstorage/v1/containers", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/objectstorage/v1/objects", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/openstack/utils", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/pagination", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/testhelper", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/rackspace/gophercloud/testhelper/client", - "Comment": "v1.0.0-803-g6769c3b", - "Rev": "6769c3b3e54a5cf1b0bdb10ea5b25f5cff0a3134" + "Comment": "v1.0.0-831-gf3d0534", + "Rev": "f3d053460f7c37970af6733bf370a3256e3648fb" }, { "ImportPath": "github.com/satori/go.uuid", diff --git a/builtin/providers/openstack/resource_openstack_compute_secgroup_v2_test.go b/builtin/providers/openstack/resource_openstack_compute_secgroup_v2_test.go index 28223fa1b..34d1c8489 100644 --- a/builtin/providers/openstack/resource_openstack_compute_secgroup_v2_test.go +++ b/builtin/providers/openstack/resource_openstack_compute_secgroup_v2_test.go @@ -106,6 +106,24 @@ func TestAccComputeV2SecGroup_self(t *testing.T) { }) } +func TestAccComputeV2SecGroup_icmpZero(t *testing.T) { + var secgroup secgroups.SecurityGroup + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeV2SecGroupDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccComputeV2SecGroup_icmpZero, + Check: resource.ComposeTestCheckFunc( + testAccCheckComputeV2SecGroupExists(t, "openstack_compute_secgroup_v2.test_group_1", &secgroup), + ), + }, + }, + }) +} + func testAccCheckComputeV2SecGroupDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) computeClient, err := config.computeV2Client(OS_REGION_NAME) @@ -304,3 +322,15 @@ var testAccComputeV2SecGroup_self = fmt.Sprintf(` self = true } }`) + +var testAccComputeV2SecGroup_icmpZero = fmt.Sprintf(` + resource "openstack_compute_secgroup_v2" "test_group_1" { + name = "test_group_1" + description = "first test security group" + rule { + from_port = 0 + to_port = 0 + ip_protocol = "icmp" + cidr = "0.0.0.0/0" + } + }`) diff --git a/vendor/github.com/rackspace/gophercloud/.travis.yml b/vendor/github.com/rackspace/gophercloud/.travis.yml index 325b90ac8..42c095de0 100644 --- a/vendor/github.com/rackspace/gophercloud/.travis.yml +++ b/vendor/github.com/rackspace/gophercloud/.travis.yml @@ -1,16 +1,20 @@ language: go +sudo: false install: + - go get golang.org/x/crypto/ssh - go get -v -tags 'fixtures acceptance' ./... go: - - 1.2 - - 1.3 - 1.4 - 1.5 -script: script/cibuild -after_success: - - go get golang.org/x/tools/cmd/cover + - tip +env: + - COVERALLS_TOKEN=2k7PTU3xa474Hymwgdj6XjqenNfGTNkO8 +before_install: - go get github.com/axw/gocov/gocov - go get github.com/mattn/goveralls - - export PATH=$PATH:$HOME/gopath/bin/ - - goveralls 2k7PTU3xa474Hymwgdj6XjqenNfGTNkO8 -sudo: false + - go get github.com/pierrre/gotestcover + - if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi +script: + - $HOME/gopath/bin/gotestcover -v -tags=fixtures -coverprofile=cover.out ./... +after_success: + - $HOME/gopath/bin/goveralls -service=travis-ci -coverprofile=cover.out diff --git a/vendor/github.com/rackspace/gophercloud/CONTRIBUTING.md b/vendor/github.com/rackspace/gophercloud/CONTRIBUTING.md index 6ba5beb85..73c95bd82 100644 --- a/vendor/github.com/rackspace/gophercloud/CONTRIBUTING.md +++ b/vendor/github.com/rackspace/gophercloud/CONTRIBUTING.md @@ -11,7 +11,8 @@ As a contributor you will need to setup your workspace in a slightly different way than just downloading it. Here are the basic installation instructions: 1. Configure your `$GOPATH` and run `go get` as described in the main -[README](/README.md#how-to-install). +[README](/README.md#how-to-install) but add `-tags "fixtures acceptance"` to +get dependencies for unit and acceptance tests. 2. Move into the directory that houses your local repository: @@ -158,25 +159,25 @@ deleted after the test suite finishes. To run all tests: ```bash -go test ./... +go test -tags fixtures ./... ``` To run all tests with verbose output: ```bash -go test -v ./... +go test -v -tags fixtures ./... ``` To run tests that match certain [build tags](): ```bash -go test -tags "foo bar" ./... +go test -tags "fixtures foo bar" ./... ``` To run tests for a particular sub-package: ```bash -cd ./path/to/package && go test . +cd ./path/to/package && go test -tags fixtures . ``` ## Basic style guide diff --git a/vendor/github.com/rackspace/gophercloud/README.md b/vendor/github.com/rackspace/gophercloud/README.md index 0a0da59f6..4b0042b3b 100644 --- a/vendor/github.com/rackspace/gophercloud/README.md +++ b/vendor/github.com/rackspace/gophercloud/README.md @@ -1,5 +1,5 @@ # Gophercloud: an OpenStack SDK for Go -[![Build Status](https://travis-ci.org/rackspace/gophercloud.svg?branch=master)](https://travis-ci.org/rackspace/gophercloud) +[![Build Status](https://travis-ci.org/rackspace/gophercloud.svg?branch=master)](https://travis-ci.org/rackspace/gophercloud) [![Coverage Status](https://coveralls.io/repos/rackspace/gophercloud/badge.png)](https://coveralls.io/r/rackspace/gophercloud) Gophercloud is a flexible SDK that allows you to consume and work with OpenStack clouds in a simple and idiomatic way using golang. Many services are supported, diff --git a/vendor/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/secgroups/fixtures.go b/vendor/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/secgroups/fixtures.go index 8c42e48e4..28b1c0644 100644 --- a/vendor/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/secgroups/fixtures.go +++ b/vendor/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/secgroups/fixtures.go @@ -216,6 +216,42 @@ func mockAddRuleResponse(t *testing.T) { }) } +func mockAddRuleResponseICMPZero(t *testing.T) { + th.Mux.HandleFunc("/os-security-group-rules", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "POST") + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) + + th.TestJSONRequest(t, r, ` +{ + "security_group_rule": { + "from_port": 0, + "ip_protocol": "ICMP", + "to_port": 0, + "parent_group_id": "{groupID}", + "cidr": "0.0.0.0/0" + } +} `) + + w.Header().Add("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + + fmt.Fprintf(w, ` +{ + "security_group_rule": { + "from_port": 0, + "group": {}, + "ip_protocol": "ICMP", + "to_port": 0, + "parent_group_id": "{groupID}", + "ip_range": { + "cidr": "0.0.0.0/0" + }, + "id": "{ruleID}" + } +}`) + }) +} + func mockDeleteRuleResponse(t *testing.T, ruleID string) { url := fmt.Sprintf("/os-security-group-rules/%s", ruleID) th.Mux.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/secgroups/requests.go b/vendor/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/secgroups/requests.go index 4cef48022..120dcae3c 100644 --- a/vendor/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/secgroups/requests.go +++ b/vendor/github.com/rackspace/gophercloud/openstack/compute/v2/extensions/secgroups/requests.go @@ -2,6 +2,7 @@ package secgroups import ( "errors" + "strings" "github.com/rackspace/gophercloud" "github.com/rackspace/gophercloud/pagination" @@ -181,10 +182,10 @@ func (opts CreateRuleOpts) ToRuleCreateMap() (map[string]interface{}, error) { if opts.ParentGroupID == "" { return rule, errors.New("A ParentGroupID must be set") } - if opts.FromPort == 0 { + if opts.FromPort == 0 && strings.ToUpper(opts.IPProtocol) != "ICMP" { return rule, errors.New("A FromPort must be set") } - if opts.ToPort == 0 { + if opts.ToPort == 0 && strings.ToUpper(opts.IPProtocol) != "ICMP" { return rule, errors.New("A ToPort must be set") } if opts.IPProtocol == "" { diff --git a/vendor/github.com/rackspace/gophercloud/openstack/compute/v2/servers/fixtures.go b/vendor/github.com/rackspace/gophercloud/openstack/compute/v2/servers/fixtures.go index 151fea27b..85cea70a8 100644 --- a/vendor/github.com/rackspace/gophercloud/openstack/compute/v2/servers/fixtures.go +++ b/vendor/github.com/rackspace/gophercloud/openstack/compute/v2/servers/fixtures.go @@ -235,6 +235,12 @@ const SingleServerBody = ` } ` +const ServerPasswordBody = ` +{ + "password": "xlozO3wLCBRWAa2yDjCCVx8vwNPypxnypmRYDa/zErlQ+EzPe1S/Gz6nfmC52mOlOSCRuUOmG7kqqgejPof6M7bOezS387zjq4LSvvwp28zUknzy4YzfFGhnHAdai3TxUJ26pfQCYrq8UTzmKF2Bq8ioSEtVVzM0A96pDh8W2i7BOz6MdoiVyiev/I1K2LsuipfxSJR7Wdke4zNXJjHHP2RfYsVbZ/k9ANu+Nz4iIH8/7Cacud/pphH7EjrY6a4RZNrjQskrhKYed0YERpotyjYk1eDtRe72GrSiXteqCM4biaQ5w3ruS+AcX//PXk3uJ5kC7d67fPXaVz4WaQRYMg==" +} +` + var ( // ServerHerp is a Server struct that should correspond to the first result in ServerListBody. ServerHerp = Server{ @@ -399,8 +405,8 @@ func HandleServerDeletionSuccessfully(t *testing.T) { }) } -// HandleAdminPasswordChangeSuccessfully sets up the test server to respond to a server password -// change request. +// HandleServerForceDeletionSuccessfully sets up the test server to respond to a server force deletion +// request. func HandleServerForceDeletionSuccessfully(t *testing.T) { th.Mux.HandleFunc("/servers/asdfasdfasdf/action", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "POST") @@ -674,3 +680,13 @@ func HandleCreateServerImageSuccessfully(t *testing.T) { }) } +// HandlePasswordGetSuccessfully sets up the test server to respond to a password Get request. +func HandlePasswordGetSuccessfully(t *testing.T) { + th.Mux.HandleFunc("/servers/1234asdf/os-server-password", func(w http.ResponseWriter, r *http.Request) { + th.TestMethod(t, r, "GET") + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) + th.TestHeader(t, r, "Accept", "application/json") + + fmt.Fprintf(w, ServerPasswordBody) + }) +} diff --git a/vendor/github.com/rackspace/gophercloud/openstack/compute/v2/servers/requests.go b/vendor/github.com/rackspace/gophercloud/openstack/compute/v2/servers/requests.go index 8e60daa69..e6490539c 100644 --- a/vendor/github.com/rackspace/gophercloud/openstack/compute/v2/servers/requests.go +++ b/vendor/github.com/rackspace/gophercloud/openstack/compute/v2/servers/requests.go @@ -861,3 +861,12 @@ func IDFromName(client *gophercloud.ServiceClient, name string) (string, error) return "", fmt.Errorf("Found %d servers matching %s", serverCount, name) } } + +// GetPassword makes a request against the nova API to get the encrypted administrative password. +func GetPassword(client *gophercloud.ServiceClient, serverId string) GetPasswordResult { + var res GetPasswordResult + _, res.Err = client.Request("GET", passwordURL(client, serverId), gophercloud.RequestOpts{ + JSONResponse: &res.Body, + }) + return res +} diff --git a/vendor/github.com/rackspace/gophercloud/openstack/compute/v2/servers/results.go b/vendor/github.com/rackspace/gophercloud/openstack/compute/v2/servers/results.go index f27870984..406f68935 100644 --- a/vendor/github.com/rackspace/gophercloud/openstack/compute/v2/servers/results.go +++ b/vendor/github.com/rackspace/gophercloud/openstack/compute/v2/servers/results.go @@ -1,10 +1,12 @@ package servers import ( - "reflect" + "crypto/rsa" + "encoding/base64" "fmt" - "path" "net/url" + "path" + "reflect" "github.com/mitchellh/mapstructure" "github.com/rackspace/gophercloud" @@ -82,6 +84,47 @@ type CreateImageResult struct { gophercloud.Result } +// GetPasswordResult represent the result of a get os-server-password operation. +type GetPasswordResult struct { + gophercloud.Result +} + +// ExtractPassword gets the encrypted password. +// If privateKey != nil the password is decrypted with the private key. +// If privateKey == nil the encrypted password is returned and can be decrypted with: +// echo '' | base64 -D | openssl rsautl -decrypt -inkey +func (r GetPasswordResult) ExtractPassword(privateKey *rsa.PrivateKey) (string, error) { + + if r.Err != nil { + return "", r.Err + } + + var response struct { + Password string `mapstructure:"password"` + } + + err := mapstructure.Decode(r.Body, &response) + if err == nil && privateKey != nil && response.Password != "" { + return decryptPassword(response.Password, privateKey) + } + return response.Password, err +} + +func decryptPassword(encryptedPassword string, privateKey *rsa.PrivateKey) (string, error) { + b64EncryptedPassword := make([]byte, base64.StdEncoding.DecodedLen(len(encryptedPassword))) + + n, err := base64.StdEncoding.Decode(b64EncryptedPassword, []byte(encryptedPassword)) + if err != nil { + return "", fmt.Errorf("Failed to base64 decode encrypted password: %s", err) + } + password, err := rsa.DecryptPKCS1v15(nil, privateKey, b64EncryptedPassword[0:n]) + if err != nil { + return "", fmt.Errorf("Failed to decrypt password: %s", err) + } + + return string(password), nil +} + // ExtractImageID gets the ID of the newly created server image from the header func (res CreateImageResult) ExtractImageID() (string, error) { if res.Err != nil { diff --git a/vendor/github.com/rackspace/gophercloud/openstack/compute/v2/servers/urls.go b/vendor/github.com/rackspace/gophercloud/openstack/compute/v2/servers/urls.go index 899835493..d51fcbe6c 100644 --- a/vendor/github.com/rackspace/gophercloud/openstack/compute/v2/servers/urls.go +++ b/vendor/github.com/rackspace/gophercloud/openstack/compute/v2/servers/urls.go @@ -45,3 +45,7 @@ func listAddressesURL(client *gophercloud.ServiceClient, id string) string { func listAddressesByNetworkURL(client *gophercloud.ServiceClient, id, network string) string { return client.ServiceURL("servers", id, "ips", network) } + +func passwordURL(client *gophercloud.ServiceClient, id string) string { + return client.ServiceURL("servers", id, "os-server-password") +}