Skip to content

Commit

Permalink
Merge pull request #30 from TykTechnologies/feat/TT-11468/hybrid-dash…
Browse files Browse the repository at this point in the history
…board

[TT-11468] Allow bootstrapping hybrid organisation while bootstrapping tyk dashb…
  • Loading branch information
singhpr committed Mar 11, 2024
2 parents d8bed73 + 4e68dca commit 6cde43b
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ 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. |

## Bootstrapped Environments
Expand Down
16 changes: 16 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

import (
"tyk/tyk/bootstrap/tyk/api"

"github.com/kelseyhightower/envconfig"
)

Expand Down Expand Up @@ -74,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,6 +91,17 @@ type TykConf struct {
DashboardLicense string
}

type HybridConf struct {
// Enabled specified if the Hybrid organisation is enabled or not
Enabled bool
// KeyEvent corresponds to `key_event` of the event options which enables key events such as updates and deletes,
// to be propagated to the various instance zones.
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 `json:",omitempty"`
}

func NewConfig() (*Config, error) {
conf := &Config{}
if err := envconfig.Process(prefix, conf); err != nil {
Expand Down
14 changes: 11 additions & 3 deletions tyk/api/request.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package api

type EventConfig struct {
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"`
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,omitempty"`
}

type ResetPasswordReq struct {
Expand Down
45 changes: 45 additions & 0 deletions tyk/organisation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"io"
"net/http"
"tyk/tyk/bootstrap/pkg/config"
"tyk/tyk/bootstrap/tyk/api"
"tyk/tyk/bootstrap/tyk/internal/constants"

Expand Down Expand Up @@ -79,6 +80,13 @@ func (s *Service) CreateOrganisation() error {
Cname: s.appArgs.Tyk.Org.Cname,
}

// 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.Org.Hybrid != nil && s.appArgs.Tyk.Org.Hybrid.Enabled {
createOrgData.HybridEnabled = true
createOrgData.EventOptions = eventOptions(s.appArgs.Tyk.Org.Hybrid, s.appArgs.Tyk.Admin.EmailAddress)
}

reqBodyBytes, err := json.Marshal(createOrgData)
if err != nil {
return err
Expand Down Expand Up @@ -121,3 +129,40 @@ func (s *Service) CreateOrganisation() error {

return nil
}

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

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

const (
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 {
if hconf.HashedKeyEvent.Email != "" {
hashedKeyEventConf.Email = hconf.HashedKeyEvent.Email
}
}

if hconf.KeyEvent != nil {
if hconf.KeyEvent.Email != "" {
keyEventConf.Email = hconf.KeyEvent.Email
}
}

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

return m
}

0 comments on commit 6cde43b

Please sign in to comment.