Skip to content

Commit

Permalink
Populate email in events field
Browse files Browse the repository at this point in the history
Signed-off-by: Burak Sekili <buraksekili@gmail.com>
  • Loading branch information
buraksekili committed Mar 6, 2024
1 parent 345a47e commit 2b8131b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 28 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ setting up an organization and an admin user. Additionally, it generates Kuberne
| TYK_K8SBOOTSTRAP_TYK_ORG_NAME | corresponds to the name for your organization that is going to be bootstrapped in Tyk. |
| TYK_K8SBOOTSTRAP_TYK_ORG_CNAME | corresponds to the Organisation CNAME which is going to bind the Portal to. |
| TYK_K8SBOOTSTRAP_TYK_ORG_ID | corresponds to the organisation ID that is being created. |
| TYK_K8SBOOTSTRAP_TYK_ORG_HYBRID_ENABLED | specifies if the Hybrid organisation for MDCB Control Plane is enabled or not |
| TYK_K8SBOOTSTRAP_TYK_ORG_HYBRID_KEYEVENT | corresponds to `key_event` of the event options (optional). |
| TYK_K8SBOOTSTRAP_TYK_ORG_HYBRID_HASHEDKEYEVENT | corresponds to `hashed_key_event` of the event options (optional). |
| TYK_K8SBOOTSTRAP_TYK_DASHBOARDLICENSE | corresponds to the license key of Tyk Dashboard. |
| TYK_K8SBOOTSTRAP_TYK_HYBRID_ENABLED | specifies if the Hybrid organisation for MDCB Control Plane is enabled or not |
| TYK_K8SBOOTSTRAP_TYK_HYBRID_KEYEVENT | corresponds to `key_event` of the event options (optional). |
| TYK_K8SBOOTSTRAP_TYK_HYBRID_HASHEDKEYEVENT | corresponds to `hashed_key_event` of the event options (optional). |

## Bootstrapped Environments

Expand Down
10 changes: 3 additions & 7 deletions hack/load_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

make build-all

docker build -t tykio/tyk-k8s-bootstrap-pre-install:testing -f ./.container/image/bootstrap-pre-install/Dockerfile ./bin &&
kind load docker-image tykio/tyk-k8s-bootstrap-pre-install:testing
docker build -t tykio/tyk-k8s-bootstrap-pre-install:testing -f ./.container/image/bootstrap-pre-install/Dockerfile ./bin
docker build -t tykio/tyk-k8s-bootstrap-post:testing -f ./.container/image/bootstrap-post/Dockerfile ./bin
docker build -t tykio/tyk-k8s-bootstrap-pre-delete:testing -f ./.container/image/bootstrap-pre-delete/Dockerfile ./bin

docker build -t tykio/tyk-k8s-bootstrap-post:testing -f ./.container/image/bootstrap-post/Dockerfile ./bin &&
kind load docker-image tykio/tyk-k8s-bootstrap-post:testing

docker build -t tykio/tyk-k8s-bootstrap-pre-delete:testing -f ./.container/image/bootstrap-pre-delete/Dockerfile ./bin &&
kind load docker-image tykio/tyk-k8s-bootstrap-pre-delete:testing
8 changes: 4 additions & 4 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ type TykOrg struct {

// ID corresponds to the organisation ID that is being created.
ID string

// Hybrid includes details of hybrid organisation while using MDCB Control Plane
Hybrid *HybridConf
}

type TykConf struct {
Expand All @@ -86,9 +89,6 @@ type TykConf struct {

// DashboardLicense corresponds to the license key of Tyk Dashboard.
DashboardLicense string

// Hybrid includes details of hybrid organisation while using MDCB Control Plane
Hybrid HybridConf
}

type HybridConf struct {
Expand All @@ -99,7 +99,7 @@ type HybridConf struct {
KeyEvent *api.EventConfig
// HashedKeyEvent corresponds to `hashed_key_event` of the event options which enables key events such as updates
// and deletes, to be propagated to the various instance zones.
HashedKeyEvent *api.EventConfig
HashedKeyEvent *api.EventConfig `json:",omitempty"`
}

func NewConfig() (*Config, error) {
Expand Down
8 changes: 4 additions & 4 deletions tyk/api/request.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package api

type EventConfig struct {
Webhook string `json:"webhook"`
Email string `json:"email"`
Redis bool `json:"redis"`
Webhook string `json:"webhook,omitempty"`
Email string `json:"email,omitempty"`
Redis bool `json:"redis,omitempty"`
}

type CreateOrgReq struct {
OwnerName string `json:"owner_name"`
CnameEnabled bool `json:"cname_enabled"`
Cname string `json:"cname"`
HybridEnabled bool `json:"hybrid_enabled"`
EventOptions map[string]EventConfig `json:"event_options"`
EventOptions map[string]EventConfig `json:"event_options,omitempty"`
}

type ResetPasswordReq struct {
Expand Down
34 changes: 24 additions & 10 deletions tyk/organisation.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ func (s *Service) CreateOrganisation() error {

// Enable hybrid in the organisation while setting up the MDCB Control Plane.
// For reference: https://tyk.io/docs/tyk-multi-data-centre/setup-controller-data-centre/
if s.appArgs.Tyk.Hybrid.Enabled {
if s.appArgs.Tyk.Org.Hybrid != nil && s.appArgs.Tyk.Org.Hybrid.Enabled {
createOrgData.HybridEnabled = true
createOrgData.EventOptions = eventOptions(s.appArgs.Tyk.Hybrid, s.appArgs.Tyk.Admin.EmailAddress)
createOrgData.EventOptions = eventOptions(s.appArgs.Tyk.Org.Hybrid, s.appArgs.Tyk.Admin.EmailAddress)
}

reqBodyBytes, err := json.Marshal(createOrgData)
Expand Down Expand Up @@ -130,25 +130,39 @@ func (s *Service) CreateOrganisation() error {
return nil
}

func eventOptions(hconf config.HybridConf, defaultEmail string) map[string]api.EventConfig {
func eventOptions(hconf *config.HybridConf, defaultEmail string) map[string]api.EventConfig {
if hconf == nil {
return nil
}

m := make(map[string]api.EventConfig)

const (
keyEventKey = "key_event"
hashedKeyEventKey = "hashed_key_event"
keyEventKey = "key_event"
)

hashedKeyEventConf := api.EventConfig{
Email: defaultEmail,
Webhook: hconf.HashedKeyEvent.Webhook,
Redis: hconf.HashedKeyEvent.Redis,
}
keyEventConf := hashedKeyEventConf

if hconf.HashedKeyEvent != nil {
m[hashedKeyEventKey] = *hconf.HashedKeyEvent
} else {
m[hashedKeyEventKey] = api.EventConfig{Email: defaultEmail}
if hconf.HashedKeyEvent.Email != "" {
hashedKeyEventConf.Email = hconf.HashedKeyEvent.Email
}
}

if hconf.KeyEvent != nil {
m[keyEventKey] = *hconf.KeyEvent
} else {
m[keyEventKey] = api.EventConfig{Email: defaultEmail}
if hconf.KeyEvent.Email != "" {
keyEventConf.Email = hconf.KeyEvent.Email
}
}

m[hashedKeyEventKey] = hashedKeyEventConf
m[keyEventKey] = keyEventConf

return m
}

0 comments on commit 2b8131b

Please sign in to comment.