github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/builtin/providers/opc/config.go (about)

     1  package opc
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  	"net/url"
     7  	"strings"
     8  
     9  	"github.com/hashicorp/go-cleanhttp"
    10  	"github.com/hashicorp/go-oracle-terraform/compute"
    11  	"github.com/hashicorp/go-oracle-terraform/opc"
    12  	"github.com/hashicorp/terraform/helper/logging"
    13  )
    14  
    15  type Config struct {
    16  	User            string
    17  	Password        string
    18  	IdentityDomain  string
    19  	Endpoint        string
    20  	MaxRetryTimeout int
    21  }
    22  
    23  type OPCClient struct {
    24  	Client          *compute.Client
    25  	MaxRetryTimeout int
    26  }
    27  
    28  func (c *Config) Client() (*compute.Client, error) {
    29  	u, err := url.ParseRequestURI(c.Endpoint)
    30  	if err != nil {
    31  		return nil, fmt.Errorf("Invalid endpoint URI: %s", err)
    32  	}
    33  
    34  	config := opc.Config{
    35  		IdentityDomain: &c.IdentityDomain,
    36  		Username:       &c.User,
    37  		Password:       &c.Password,
    38  		APIEndpoint:    u,
    39  		HTTPClient:     cleanhttp.DefaultClient(),
    40  	}
    41  
    42  	if logging.IsDebugOrHigher() {
    43  		config.LogLevel = opc.LogDebug
    44  		config.Logger = opcLogger{}
    45  	}
    46  
    47  	return compute.NewComputeClient(&config)
    48  }
    49  
    50  type opcLogger struct{}
    51  
    52  func (l opcLogger) Log(args ...interface{}) {
    53  	tokens := make([]string, 0, len(args))
    54  	for _, arg := range args {
    55  		if token, ok := arg.(string); ok {
    56  			tokens = append(tokens, token)
    57  		}
    58  	}
    59  	log.Printf("[DEBUG] [go-oracle-terraform]: %s", strings.Join(tokens, " "))
    60  }