github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/builtin/providers/rancher/config.go (about) 1 package rancher 2 3 import ( 4 "log" 5 6 rancherClient "github.com/rancher/go-rancher/client" 7 "github.com/raphink/go-rancher/catalog" 8 ) 9 10 type Config struct { 11 *rancherClient.RancherClient 12 APIURL string 13 AccessKey string 14 SecretKey string 15 } 16 17 // Create creates a generic Rancher client 18 func (c *Config) CreateClient() error { 19 client, err := rancherClient.NewRancherClient(&rancherClient.ClientOpts{ 20 Url: c.APIURL, 21 AccessKey: c.AccessKey, 22 SecretKey: c.SecretKey, 23 }) 24 if err != nil { 25 return err 26 } 27 28 log.Printf("[INFO] Rancher Client configured for url: %s", c.APIURL) 29 30 c.RancherClient = client 31 32 return nil 33 } 34 35 func (c *Config) EnvironmentClient(env string) (*rancherClient.RancherClient, error) { 36 37 url := c.APIURL + "/projects/" + env + "/schemas" 38 client, err := rancherClient.NewRancherClient(&rancherClient.ClientOpts{ 39 Url: url, 40 AccessKey: c.AccessKey, 41 SecretKey: c.SecretKey, 42 }) 43 if err != nil { 44 return nil, err 45 } 46 47 log.Printf("[INFO] Rancher Client configured for url: %s", url) 48 49 return client, nil 50 } 51 52 func (c *Config) RegistryClient(id string) (*rancherClient.RancherClient, error) { 53 reg, err := c.Registry.ById(id) 54 if err != nil { 55 return nil, err 56 } 57 58 return c.EnvironmentClient(reg.AccountId) 59 } 60 61 func (c *Config) CatalogClient() (*catalog.RancherClient, error) { 62 63 url := c.APIURL + "-catalog/schemas" 64 client, err := catalog.NewRancherClient(&catalog.ClientOpts{ 65 Url: url, 66 AccessKey: c.AccessKey, 67 SecretKey: c.SecretKey, 68 }) 69 if err != nil { 70 return nil, err 71 } 72 73 log.Printf("[INFO] Rancher Catalog Client configured for url: %s", url) 74 75 return client, nil 76 }