datasource: use opaque object instead of string

Rather than serializing the network config into a string and then later
deserializing it, just pass the object through directly.
This commit is contained in:
Alex Crawford
2015-05-15 12:40:23 -07:00
parent 81ffa056bd
commit 9ba25550a1
8 changed files with 56 additions and 68 deletions

View File

@@ -100,7 +100,7 @@ func (ms *metadataService) FetchMetadata() (metadata datasource.Metadata, err er
for i, key := range m.PublicKeys {
metadata.SSHPublicKeys[strconv.Itoa(i)] = key
}
metadata.NetworkConfig = data
metadata.NetworkConfig = m
return
}

View File

@@ -90,34 +90,27 @@ func TestFetchMetadata(t *testing.T) {
"0": "publickey1",
"1": "publickey2",
},
NetworkConfig: []byte(`{
"droplet_id": 1,
"user_data": "hello",
"vendor_data": "hello",
"public_keys": [
"publickey1",
"publickey2"
],
"region": "nyc2",
"interfaces": {
"public": [
{
"ipv4": {
"ip_address": "192.168.1.2",
"netmask": "255.255.255.0",
"gateway": "192.168.1.1"
},
"ipv6": {
"ip_address": "fe00::",
"cidr": 126,
"gateway": "fe00::"
},
"mac": "ab:cd:ef:gh:ij",
"type": "public"
}
]
}
}`),
NetworkConfig: Metadata{
Interfaces: Interfaces{
Public: []Interface{
Interface{
IPv4: &Address{
IPAddress: "192.168.1.2",
Netmask: "255.255.255.0",
Gateway: "192.168.1.1",
},
IPv6: &Address{
IPAddress: "fe00::",
Cidr: 126,
Gateway: "fe00::",
},
MAC: "ab:cd:ef:gh:ij",
Type: "public",
},
},
},
PublicKeys: []string{"publickey1", "publickey2"},
},
},
},
{