stack72 b04796c2cc Bump Joyent/triton-go to modern version of the SDK
This brings packer into the same version of triton-go as that in Terraform, where we rewrote the package from a library with everything in 1 place to individual packages

I was able to successfully provision a machine on triton using this new change, you can find the output in the attached gist

https://gist.github.com/stack72/a64d745459107c5a16bcb156965597ce
2017-10-31 18:08:53 +02:00

65 lines
1.2 KiB
Go

package compute
import (
"context"
"encoding/json"
"fmt"
"net/http"
"sort"
"github.com/hashicorp/errwrap"
"github.com/joyent/triton-go/client"
)
type ServicesClient struct {
client *client.Client
}
type Service struct {
Name string
Endpoint string
}
type ListServicesInput struct{}
func (c *ServicesClient) List(ctx context.Context, _ *ListServicesInput) ([]*Service, error) {
path := fmt.Sprintf("/%s/services", c.client.AccountName)
reqInputs := client.RequestInput{
Method: http.MethodGet,
Path: path,
}
respReader, err := c.client.ExecuteRequest(ctx, reqInputs)
if respReader != nil {
defer respReader.Close()
}
if err != nil {
return nil, errwrap.Wrapf("Error executing List request: {{err}}", err)
}
var intermediate map[string]string
decoder := json.NewDecoder(respReader)
if err = decoder.Decode(&intermediate); err != nil {
return nil, errwrap.Wrapf("Error decoding List response: {{err}}", err)
}
keys := make([]string, len(intermediate))
i := 0
for k := range intermediate {
keys[i] = k
i++
}
sort.Strings(keys)
result := make([]*Service, len(intermediate))
i = 0
for _, key := range keys {
result[i] = &Service{
Name: key,
Endpoint: intermediate[key],
}
i++
}
return result, nil
}