2017-04-04 00:24:53 +02:00
|
|
|
package opc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-04-06 19:59:16 +02:00
|
|
|
"log"
|
2017-04-04 00:24:53 +02:00
|
|
|
"net/url"
|
2017-04-06 19:59:16 +02:00
|
|
|
"strings"
|
2017-04-04 00:24:53 +02:00
|
|
|
|
2017-04-06 19:59:16 +02:00
|
|
|
"github.com/fsouza/go-dockerclient/external/github.com/hashicorp/go-cleanhttp"
|
2017-04-04 00:24:53 +02:00
|
|
|
"github.com/hashicorp/go-oracle-terraform/compute"
|
|
|
|
"github.com/hashicorp/go-oracle-terraform/opc"
|
2017-04-06 19:59:16 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/logging"
|
2017-04-04 00:24:53 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
User string
|
|
|
|
Password string
|
|
|
|
IdentityDomain string
|
|
|
|
Endpoint string
|
|
|
|
MaxRetryTimeout int
|
|
|
|
}
|
|
|
|
|
|
|
|
type OPCClient struct {
|
|
|
|
Client *compute.Client
|
|
|
|
MaxRetryTimeout int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) Client() (*compute.Client, error) {
|
|
|
|
u, err := url.ParseRequestURI(c.Endpoint)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Invalid endpoint URI: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
config := opc.Config{
|
|
|
|
IdentityDomain: &c.IdentityDomain,
|
|
|
|
Username: &c.User,
|
|
|
|
Password: &c.Password,
|
|
|
|
APIEndpoint: u,
|
2017-04-06 19:59:16 +02:00
|
|
|
HTTPClient: cleanhttp.DefaultClient(),
|
|
|
|
}
|
|
|
|
|
|
|
|
if logging.IsDebugOrHigher() {
|
|
|
|
config.LogLevel = opc.LogDebug
|
|
|
|
config.Logger = opcLogger{}
|
2017-04-04 00:24:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return compute.NewComputeClient(&config)
|
|
|
|
}
|
2017-04-06 19:59:16 +02:00
|
|
|
|
|
|
|
type opcLogger struct{}
|
|
|
|
|
|
|
|
func (l opcLogger) Log(args ...interface{}) {
|
|
|
|
tokens := make([]string, 0, len(args))
|
|
|
|
for _, arg := range args {
|
|
|
|
if token, ok := arg.(string); ok {
|
|
|
|
tokens = append(tokens, token)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Printf("[DEBUG] [go-oracle-terraform]: %s", strings.Join(tokens, " "))
|
|
|
|
}
|