opentofu/builtin/providers/rancher/config.go
John Engelman 243ecf3b4f [Provider] Rancher (#9173)
* Vendor Rancher Go library.

* Implement Rancher Provider.

Starting implementation taken from
https://github.com/platanus/terraform-provider-rancher

Commits from jidonoso@gmail.com and raphael.pinson@camptocamp.com
2016-12-05 15:29:41 +00:00

77 lines
1.6 KiB
Go

package rancher
import (
"log"
rancherClient "github.com/rancher/go-rancher/client"
"github.com/raphink/go-rancher/catalog"
)
type Config struct {
*rancherClient.RancherClient
APIURL string
AccessKey string
SecretKey string
}
// Create creates a generic Rancher client
func (c *Config) CreateClient() error {
client, err := rancherClient.NewRancherClient(&rancherClient.ClientOpts{
Url: c.APIURL,
AccessKey: c.AccessKey,
SecretKey: c.SecretKey,
})
if err != nil {
return err
}
log.Printf("[INFO] Rancher Client configured for url: %s", c.APIURL)
c.RancherClient = client
return nil
}
func (c *Config) EnvironmentClient(env string) (*rancherClient.RancherClient, error) {
url := c.APIURL + "/projects/" + env + "/schemas"
client, err := rancherClient.NewRancherClient(&rancherClient.ClientOpts{
Url: url,
AccessKey: c.AccessKey,
SecretKey: c.SecretKey,
})
if err != nil {
return nil, err
}
log.Printf("[INFO] Rancher Client configured for url: %s", url)
return client, nil
}
func (c *Config) RegistryClient(id string) (*rancherClient.RancherClient, error) {
reg, err := c.Registry.ById(id)
if err != nil {
return nil, err
}
return c.EnvironmentClient(reg.AccountId)
}
func (c *Config) CatalogClient() (*catalog.RancherClient, error) {
url := c.APIURL + "-catalog/schemas"
client, err := catalog.NewRancherClient(&catalog.ClientOpts{
Url: url,
AccessKey: c.AccessKey,
SecretKey: c.SecretKey,
})
if err != nil {
return nil, err
}
log.Printf("[INFO] Rancher Catalog Client configured for url: %s", url)
return client, nil
}