Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable use of project API key for default deployments #21

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions pkg/experiment/local/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,40 @@ type Client struct {

func Initialize(apiKey string, config *Config) *Client {
initMutex.Lock()
client := clients[apiKey]
var usedKey string
if config == nil || config.DeploymentKey == "" {
usedKey = apiKey
} else {
usedKey = config.DeploymentKey
}
client := clients[usedKey]
if client == nil {
if apiKey == "" {
panic("api key must be set")
if usedKey == "" {
panic("project api key or experiment deployment key must be set")
}
config = fillConfigDefaults(config)
log := logger.New(config.Debug)
var as *assignmentService
if config.AssignmentConfig != nil && config.AssignmentConfig.APIKey != "" {
if config.AssignmentConfig != nil && config.AssignmentConfig.APIKey != "" {
amplitudeClient := amplitude.NewClient(config.AssignmentConfig.Config)
as = &assignmentService{
amplitude: &amplitudeClient,
filter: newAssignmentFilter(config.AssignmentConfig.CacheCapacity),
filter: newAssignmentFilter(config.AssignmentConfig.CacheCapacity),
}
}
client = &Client{
log: log,
apiKey: apiKey,
config: config,
client: &http.Client{},
poller: newPoller(),
flags: make(map[string]*evaluation.Flag),
flagsMutex: &sync.RWMutex{},
engine: evaluation.NewEngine(log),
log: log,
apiKey: usedKey,
config: config,
client: &http.Client{},
poller: newPoller(),
flags: make(map[string]*evaluation.Flag),
flagsMutex: &sync.RWMutex{},
engine: evaluation.NewEngine(log),
assignmentService: as,
}
client.log.Debug("config: %v", *config)
clients[apiKey] = client
clients[usedKey] = client
}
initMutex.Unlock()
return client
Expand Down
1 change: 1 addition & 0 deletions pkg/experiment/local/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Config struct {
FlagConfigPollerInterval time.Duration
FlagConfigPollerRequestTimeout time.Duration
AssignmentConfig *AssignmentConfig
DeploymentKey string
}

type AssignmentConfig struct {
Expand Down
14 changes: 10 additions & 4 deletions pkg/experiment/remote/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,21 @@ type Client struct {

func Initialize(apiKey string, config *Config) *Client {
initMutex.Lock()
client := clients[apiKey]
var usedKey string
if config == nil || config.DeploymentKey == "" {
usedKey = apiKey
} else {
usedKey = config.DeploymentKey
}
client := clients[usedKey]
if client == nil {
if apiKey == "" {
panic("api key must be set")
if usedKey == "" {
panic("project api key or experiment deployment key must be set")
}
config = fillConfigDefaults(config)
client = &Client{
log: logger.New(config.Debug),
apiKey: apiKey,
apiKey: usedKey,
config: config,
client: &http.Client{},
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/experiment/remote/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package remote
import "time"

type Config struct {
Debug bool
ServerUrl string
FetchTimeout time.Duration
RetryBackoff *RetryBackoff
Debug bool
ServerUrl string
FetchTimeout time.Duration
RetryBackoff *RetryBackoff
DeploymentKey string
}

var DefaultConfig = &Config{
Expand Down
Loading