daf4d4b94b
draft pr for the test demo harness for permit.io * harness working for permit.io demo * user is const * aws profile * permit import code for research * cleanup * create user tool poc * Merge branch 'main' of bitbucket.org:aarete/query-orchestration into feature/permit-io-demo * tests for user creation * add audit logs and dry-run * add tests sanity check the requested roles * update docs for delete * disable/enable users and test * more tests and make user name required only for create operations * clean up * add docs * aws tag tests * audit -> slog * attempt build fix devbox * edit * just devbox * remove lock change for merge * Merge branch 'main' of bitbucket.org:aarete/query-orchestration into feature/permit-io-demo
95 lines
1.9 KiB
Go
95 lines
1.9 KiB
Go
package config
|
|
|
|
import (
|
|
"go.uber.org/zap"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
type PermitBuilder struct {
|
|
PermitConfig
|
|
}
|
|
|
|
func NewConfigBuilder(token string) *PermitBuilder {
|
|
factsSyncTimeout := DefaultFactsSyncTimeout
|
|
return &PermitBuilder{
|
|
PermitConfig: PermitConfig{
|
|
apiUrl: DefaultApiUrl,
|
|
token: token,
|
|
pdpUrl: DefaultPdpUrl,
|
|
debug: DefaultDebugMode,
|
|
Context: nil,
|
|
Logger: nil,
|
|
proxyFactsViaPDP: false,
|
|
factsSyncTimeout: &factsSyncTimeout,
|
|
httpClient: &http.Client{Timeout: DefaultTimeout},
|
|
},
|
|
}
|
|
}
|
|
|
|
func (c *PermitConfig) WithProxyFactsViaPDP(proxyFactsViaPDP bool) *PermitConfig {
|
|
c.proxyFactsViaPDP = proxyFactsViaPDP
|
|
return c
|
|
}
|
|
|
|
func (c *PermitConfig) WithFactsSyncTimeout(timeout time.Duration) *PermitConfig {
|
|
c.factsSyncTimeout = &timeout
|
|
return c
|
|
}
|
|
func (c *PermitConfig) WithHTTPClient(client *http.Client) *PermitConfig {
|
|
c.httpClient = client
|
|
return c
|
|
}
|
|
|
|
func (c *PermitConfig) WithApiUrl(apiUrl string) *PermitConfig {
|
|
if apiUrl != "" {
|
|
c.apiUrl = apiUrl
|
|
}
|
|
|
|
return c
|
|
}
|
|
|
|
func (c *PermitConfig) WithPdpUrl(pdpUrl string) *PermitConfig {
|
|
if pdpUrl != "" {
|
|
c.pdpUrl = pdpUrl
|
|
}
|
|
|
|
return c
|
|
}
|
|
|
|
func (c *PermitConfig) WithOpaUrl(opaUrl string) *PermitConfig {
|
|
c.opaUrl = opaUrl
|
|
return c
|
|
}
|
|
|
|
func (c *PermitConfig) WithDebug(debug bool) *PermitConfig {
|
|
c.debug = debug
|
|
return c
|
|
}
|
|
|
|
func (c *PermitConfig) WithContext(context *PermitContext) *PermitConfig {
|
|
c.Context = context
|
|
return c
|
|
}
|
|
|
|
func (c *PermitConfig) WithTimeout(timeout time.Duration) *PermitConfig {
|
|
c.httpClient.Timeout = timeout
|
|
return c
|
|
}
|
|
|
|
func (c *PermitConfig) WithLogger(logger *zap.Logger) *PermitConfig {
|
|
c.Logger = logger
|
|
return c
|
|
}
|
|
|
|
func (c *PermitConfig) Build() PermitConfig {
|
|
if c.Logger == nil {
|
|
logger, err := zap.NewProduction()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
c.Logger = logger
|
|
}
|
|
return *c
|
|
}
|