Skip to content

Commit

Permalink
commented non required stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
achettyiitr committed Feb 5, 2024
1 parent 6f3bbd5 commit 235d8de
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 66 deletions.
5 changes: 4 additions & 1 deletion internal/cache/cache.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cache

import (
"github.com/rudderlabs/rudder-cp-sdk/modelv2/parser"
"sync"

"github.com/rudderlabs/rudder-cp-sdk/modelv2"
Expand Down Expand Up @@ -35,7 +36,9 @@ func (c *WorkspaceConfigCache) Get() *modelv2.WorkspaceConfigs {
// If a workspace config is nil in input, it will not be updated.
// Source and destination definitions are merged without removing any missing definitions.
// It notifies all subscribers of the update.
func (c *WorkspaceConfigCache) Set(configs *modelv2.WorkspaceConfigs) {
func (c *WorkspaceConfigCache) Set(data []byte) {
configs, _ := parser.Parse(data)

c.updateLock.Lock()
c.merge(configs)
c.updateLock.Unlock()
Expand Down
14 changes: 3 additions & 11 deletions internal/clients/namespace/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (

"github.com/rudderlabs/rudder-cp-sdk/identity"
"github.com/rudderlabs/rudder-cp-sdk/internal/clients/base"
"github.com/rudderlabs/rudder-cp-sdk/modelv2"
"github.com/rudderlabs/rudder-cp-sdk/modelv2/parser"
)

type Client struct {
Expand All @@ -28,7 +26,7 @@ func (c *Client) Get(ctx context.Context, path string) (*http.Request, error) {
return req, nil
}

func (c *Client) GetWorkspaceConfigs(ctx context.Context) (*modelv2.WorkspaceConfigs, error) {
func (c *Client) GetWorkspaceConfigs(ctx context.Context) ([]byte, error) {
req, err := c.Get(ctx, "/data-plane/v2/namespaces/"+c.Identity.Namespace+"/config")
if err != nil {
return nil, err
Expand All @@ -38,15 +36,9 @@ func (c *Client) GetWorkspaceConfigs(ctx context.Context) (*modelv2.WorkspaceCon
if err != nil {
return nil, err
}

wcs, err := parser.Parse(data)
if err != nil {
return nil, err
}

return wcs, nil
return data, nil
}

func (c *Client) GetUpdatedWorkspaceConfigs(ctx context.Context, updatedAfter time.Time) (*modelv2.WorkspaceConfigs, error) {
func (c *Client) GetUpdatedWorkspaceConfigs(ctx context.Context, updatedAfter time.Time) ([]byte, error) {
return nil, errors.New("not implemented")
}
13 changes: 3 additions & 10 deletions internal/clients/workspace/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (

"github.com/rudderlabs/rudder-cp-sdk/identity"
"github.com/rudderlabs/rudder-cp-sdk/internal/clients/base"
"github.com/rudderlabs/rudder-cp-sdk/modelv2"
"github.com/rudderlabs/rudder-cp-sdk/modelv2/parser"
)

type Client struct {
Expand All @@ -28,7 +26,7 @@ func (c *Client) Get(ctx context.Context, path string) (*http.Request, error) {
return req, nil
}

func (c *Client) GetWorkspaceConfigs(ctx context.Context) (*modelv2.WorkspaceConfigs, error) {
func (c *Client) GetWorkspaceConfigs(ctx context.Context) ([]byte, error) {
req, err := c.Get(ctx, "/data-plane/v2/workspaceConfig")
if err != nil {
return nil, err
Expand All @@ -39,14 +37,9 @@ func (c *Client) GetWorkspaceConfigs(ctx context.Context) (*modelv2.WorkspaceCon
return nil, err
}

wcs, err := parser.Parse(data)
if err != nil {
return nil, err
}

return wcs, nil
return data, nil
}

func (c *Client) GetUpdatedWorkspaceConfigs(ctx context.Context, updatedAfter time.Time) (*modelv2.WorkspaceConfigs, error) {
func (c *Client) GetUpdatedWorkspaceConfigs(ctx context.Context, updatedAfter time.Time) ([]byte, error) {
return nil, errors.New("not implemented")
}
9 changes: 4 additions & 5 deletions internal/poller/mocks/poller.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions internal/poller/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"time"

"github.com/rudderlabs/rudder-cp-sdk/modelv2"
"github.com/rudderlabs/rudder-go-kit/logger"
)

Expand All @@ -19,11 +18,11 @@ type Poller struct {
log logger.Logger
}

type WorkspaceConfigHandler func(*modelv2.WorkspaceConfigs) error
type WorkspaceConfigHandler func([]byte) error

type Client interface {
GetWorkspaceConfigs(ctx context.Context) (*modelv2.WorkspaceConfigs, error)
GetUpdatedWorkspaceConfigs(ctx context.Context, updatedAt time.Time) (*modelv2.WorkspaceConfigs, error)
GetWorkspaceConfigs(ctx context.Context) ([]byte, error)
GetUpdatedWorkspaceConfigs(ctx context.Context, updatedAt time.Time) ([]byte, error)
}

func New(handler WorkspaceConfigHandler, opts ...Option) (*Poller, error) {
Expand Down Expand Up @@ -66,7 +65,7 @@ func (p *Poller) Start(ctx context.Context) {
}

func (p *Poller) poll(ctx context.Context) error {
var response *modelv2.WorkspaceConfigs
var response []byte
if p.updatedAt.IsZero() {
p.log.Debug("polling for workspace configs")
wcs, err := p.client.GetWorkspaceConfigs(ctx)
Expand Down
20 changes: 10 additions & 10 deletions modelv2/sources.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package modelv2

type Source struct {
Name string `json:"name"`
WriteKey string `json:"writeKey"`
Enabled bool `json:"enabled"`
//Deleted bool `json:"deleted"`
//Config any `json:"config"`
//Transient bool `json:"transient"`
DefinitionName string `json:"sourceDefinitionName"`
//SecretVersion int `json:"secretVersion"`
//AccountID string `json:"accountId"`
//TrackingPlanConfig *DGSourceTrackingPlan `json:"dgSourceTrackingPlanConfig"`
Name string `json:"name"`
WriteKey string `json:"writeKey"`
Enabled bool `json:"enabled"`
Deleted bool `json:"deleted"`
Config any `json:"config"`
Transient bool `json:"transient"`
DefinitionName string `json:"sourceDefinitionName"`
SecretVersion int `json:"secretVersion"`
AccountID string `json:"accountId"`
TrackingPlanConfig *DGSourceTrackingPlan `json:"dgSourceTrackingPlanConfig"`
// TODO: consider adding the following fields
// CreatedBy string `json:"createdBy"`
// CreatedAt time.Time `json:"createdAt"`
Expand Down
28 changes: 14 additions & 14 deletions modelv2/workspaceconfigs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ type WorkspaceConfigs struct {
}

type WorkspaceConfig struct {
//Settings *Settings `json:"settings"`
Sources map[string]*Source `json:"sources"`
//Destinations map[string]*Destination `json:"destinations"`
//Connections map[string]*Connection `json:"connections"`
//Libraries []*Library `json:"libraries"`
//WHTProjects map[string]*WHTProject `json:"whtProjects"`
//Accounts map[string]*Account `json:"accounts"`
//Transformations map[string]*Transformation `json:"transformations"`
//TrackingPlans map[string]*TrackingPlan `json:"trackingPlans"`
//Resources map[string]*Resource `json:"resources"`
//AudienceSources []*AudienceSource `json:"audienceSources"`
//SQLModelVersions map[string]*SQLModelVersion `json:"sqlModelVersions"`
//SQLModelVersionSourceConnections []*SQLModelVersionSourceConnection `json:"sqlModelVersionSourceConnections"`
UpdatedAt time.Time `json:"updatedAt"`
Settings *Settings `json:"settings"`
Sources map[string]*Source `json:"sources"`
Destinations map[string]*Destination `json:"destinations"`
Connections map[string]*Connection `json:"connections"`
Libraries []*Library `json:"libraries"`
WHTProjects map[string]*WHTProject `json:"whtProjects"`
Accounts map[string]*Account `json:"accounts"`
Transformations map[string]*Transformation `json:"transformations"`
TrackingPlans map[string]*TrackingPlan `json:"trackingPlans"`
Resources map[string]*Resource `json:"resources"`
AudienceSources []*AudienceSource `json:"audienceSources"`
SQLModelVersions map[string]*SQLModelVersion `json:"sqlModelVersions"`
SQLModelVersionSourceConnections []*SQLModelVersionSourceConnection `json:"sqlModelVersionSourceConnections"`
UpdatedAt time.Time `json:"updatedAt"`
}

// UpdatedAt returns the maximum UpdatedAt value of all included workspace configs.
Expand Down
15 changes: 5 additions & 10 deletions sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/rudderlabs/rudder-cp-sdk/internal/clients/namespace"
"github.com/rudderlabs/rudder-cp-sdk/internal/clients/workspace"
"github.com/rudderlabs/rudder-cp-sdk/internal/poller"
"github.com/rudderlabs/rudder-cp-sdk/modelv2"
"github.com/rudderlabs/rudder-cp-sdk/notifications"
"github.com/rudderlabs/rudder-go-kit/logger"
)
Expand Down Expand Up @@ -42,8 +41,8 @@ type ControlPlane struct {
}

type Client interface {
GetWorkspaceConfigs(ctx context.Context) (*modelv2.WorkspaceConfigs, error)
GetUpdatedWorkspaceConfigs(ctx context.Context, updatedAfter time.Time) (*modelv2.WorkspaceConfigs, error)
GetWorkspaceConfigs(ctx context.Context) ([]byte, error)
GetUpdatedWorkspaceConfigs(ctx context.Context, updatedAfter time.Time) ([]byte, error)
}

type RequestDoer interface {
Expand Down Expand Up @@ -115,7 +114,7 @@ func (cp *ControlPlane) setupPoller() error {
return nil
}

handle := func(wc *modelv2.WorkspaceConfigs) error {
handle := func(wc []byte) error {
cp.configsCache.Set(wc)
return nil
}
Expand Down Expand Up @@ -146,12 +145,8 @@ func (cp *ControlPlane) Close() {
// GetWorkspaceConfigs returns the latest workspace configs.
// If polling is enabled, this will return the cached configs, if they have been retrieved at least once.
// Otherwise, it will make a request to the control plane to get the latest configs.
func (cp *ControlPlane) GetWorkspaceConfigs() (*modelv2.WorkspaceConfigs, error) {
if cp.poller != nil {
return cp.configsCache.Get(), nil
} else {
return cp.Client.GetWorkspaceConfigs(context.Background())
}
func (cp *ControlPlane) GetWorkspaceConfigs() ([]byte, error) {
return cp.Client.GetWorkspaceConfigs(context.Background())
}

type Subscriber interface {
Expand Down

0 comments on commit 235d8de

Please sign in to comment.