package provider import ( "context" "fmt" "github.com/pulumi/pulumi-go-provider/infer" "git.sr.ht/~rbdr/pulumi-porkbun/internal/porkbun" ) type Config struct { APIKey string `pulumi:"apiKey,optional" provider:"secret"` SecretAPIKey string `pulumi:"secretApiKey,optional" provider:"secret"` BaseURL string `pulumi:"baseUrl,optional"` client *porkbun.Client } func (c *Config) Annotate(a infer.Annotator) { a.Describe(&c, "Configuration for the Porkbun provider.") a.Describe(&c.APIKey, "The Porkbun API key. May also be set via the `PORKBUN_API_KEY` environment variable.") a.Describe(&c.SecretAPIKey, "The Porkbun secret API key. May also be set via the `PORKBUN_SECRET_API_KEY` environment variable.") a.Describe(&c.BaseURL, "The base URL of the Porkbun API. Provided for testing purpouses; defaults to the public endpoint.") a.SetDefault(&c.APIKey, "", "PORKBUN_API_KEY") a.SetDefault(&c.SecretAPIKey, "", "PORKBUN_SECRET_API_KEY") a.SetDefault(&c.BaseURL, porkbun.DefaultBaseURL) } func (c *Config) Configure(ctx context.Context) error { if c.APIKey == "" || c.SecretAPIKey == "" { return fmt.Errorf("porkbun API credentials are missing: set the porkbun:apiKey and porkbun:secretApiKey " + "config values (e.g. `pulumi config set porkbun:apiKey --secret`) or the PORKBUN_API_KEY and " + "PORKBUN_SECRET_API_KEY environment variables") } opts := []porkbun.Option{} if c.BaseURL != "" { opts = append(opts, porkbun.WithBaseURL(c.BaseURL)) } c.client = porkbun.NewClient(c.APIKey, c.SecretAPIKey, opts...) return nil } func (c Config) Client() *porkbun.Client { return c.client }