diff options
| author | Ruben Beltran del Rio <jj@r.bdr.sh> | 2026-07-03 15:21:56 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <jj@r.bdr.sh> | 2026-07-03 15:21:58 +0200 |
| commit | 95dc66cb108a311065917362a00b86c08767303d (patch) | |
| tree | 46ca65be6548224be0dd5a42bb86f2ecede14da8 /provider/config.go | |
Diffstat (limited to 'provider/config.go')
| -rw-r--r-- | provider/config.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/provider/config.go b/provider/config.go new file mode 100644 index 0000000..956cbef --- /dev/null +++ b/provider/config.go @@ -0,0 +1,46 @@ +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 +} |