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

chore: raw workspace configs #18

Merged
merged 2 commits into from
Feb 9, 2024
Merged
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
6 changes: 5 additions & 1 deletion internal/clients/base/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"io"
"net/http"
"net/url"

"github.com/rudderlabs/rudder-go-kit/httputil"
)

type Client struct {
Expand Down Expand Up @@ -36,7 +38,9 @@ func (c *Client) Send(req *http.Request) ([]byte, error) {
if err != nil {
return nil, err
}
defer res.Body.Close()
defer func() {
httputil.CloseResponse(res)
}()

if res.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status code: %d", res.StatusCode)
Expand Down
11 changes: 10 additions & 1 deletion internal/clients/namespace/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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) GetRawWorkspaceConfigs(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 @@ -39,6 +39,15 @@ func (c *Client) GetWorkspaceConfigs(ctx context.Context) (*modelv2.WorkspaceCon
return nil, err
}

return data, nil
}

func (c *Client) GetWorkspaceConfigs(ctx context.Context) (*modelv2.WorkspaceConfigs, error) {
data, err := c.GetRawWorkspaceConfigs(ctx)
if err != nil {
return nil, err
}

wcs, err := parser.Parse(data)
if err != nil {
return nil, err
Expand Down
11 changes: 10 additions & 1 deletion internal/clients/workspace/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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) GetRawWorkspaceConfigs(ctx context.Context) ([]byte, error) {
req, err := c.Get(ctx, "/data-plane/v2/workspaceConfig")
if err != nil {
return nil, err
Expand All @@ -39,6 +39,15 @@ func (c *Client) GetWorkspaceConfigs(ctx context.Context) (*modelv2.WorkspaceCon
return nil, err
}

return data, nil
}

func (c *Client) GetWorkspaceConfigs(ctx context.Context) (*modelv2.WorkspaceConfigs, error) {
data, err := c.GetRawWorkspaceConfigs(ctx)
if err != nil {
return nil, err
}

wcs, err := parser.Parse(data)
if err != nil {
return nil, err
Expand Down
6 changes: 6 additions & 0 deletions sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type ControlPlane struct {

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

Expand Down Expand Up @@ -154,6 +155,11 @@ func (cp *ControlPlane) GetWorkspaceConfigs() (*modelv2.WorkspaceConfigs, error)
}
}

// GetRawWorkspaceConfigs returns the raw workspace configs. It does not support for incremental updates.
func (cp *ControlPlane) GetRawWorkspaceConfigs() ([]byte, error) {
return cp.Client.GetRawWorkspaceConfigs(context.Background())
}

type Subscriber interface {
Notifications() chan notifications.WorkspaceConfigNotification
}
Expand Down
Loading