Skip to content

Commit

Permalink
fix: set hosted secret as auth instead of workspace token (#5181)
Browse files Browse the repository at this point in the history
  • Loading branch information
BonapartePC authored Oct 14, 2024
1 parent ae9d984 commit 519f3c6
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func NewHandle(backendConfig backendconfig.BackendConfig) (DestinationDebugger,
var err error
url := fmt.Sprintf("%s/dataplane/v2/eventDeliveryStatus", h.configBackendURL)
eventUploader := NewEventDeliveryStatusUploader(h.log)
h.uploader = debugger.New[*DeliveryStatusT](url, eventUploader)
h.uploader = debugger.New[*DeliveryStatusT](url, backendConfig.Identity(), eventUploader)
h.uploader.Start()

cacheType := cache.CacheType(config.GetInt("DestinationDebugger.cacheType", int(cache.MemoryCacheType)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
mocksBackendConfig "github.com/rudderlabs/rudder-server/mocks/backend-config"
"github.com/rudderlabs/rudder-server/utils/misc"
"github.com/rudderlabs/rudder-server/utils/pubsub"
testutils "github.com/rudderlabs/rudder-server/utils/tests"
)

const (
Expand Down Expand Up @@ -169,6 +170,7 @@ type eventDeliveryStatusUploaderContext struct {
func (c *eventDeliveryStatusUploaderContext) Setup() {
c.mockCtrl = gomock.NewController(GinkgoT())
c.mockBackendConfig = mocksBackendConfig.NewMockBackendConfig(c.mockCtrl)
c.mockBackendConfig.EXPECT().Identity().AnyTimes().Return(&testutils.BasicAuthMock{})
}

func initEventDeliveryStatusUploader() {
Expand Down
2 changes: 1 addition & 1 deletion services/debugger/source/eventUploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func NewHandle(backendConfig backendconfig.BackendConfig) (SourceDebugger, error
h.disableEventUploads = config.GetReloadableBoolVar(false, "SourceDebugger.disableEventUploads")
url := fmt.Sprintf("%s/dataplane/v2/eventUploads", h.configBackendURL)
eventUploader := NewEventUploader(h.log)
h.uploader = debugger.New[*GatewayEventBatchT](url, eventUploader)
h.uploader = debugger.New[*GatewayEventBatchT](url, backendConfig.Identity(), eventUploader)
h.uploader.Start()

cacheType := cache.CacheType(config.GetInt("SourceDebugger.cacheType", int(cache.MemoryCacheType)))
Expand Down
2 changes: 2 additions & 0 deletions services/debugger/source/eventUploader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
mocksBackendConfig "github.com/rudderlabs/rudder-server/mocks/backend-config"
"github.com/rudderlabs/rudder-server/utils/misc"
"github.com/rudderlabs/rudder-server/utils/pubsub"
testutils "github.com/rudderlabs/rudder-server/utils/tests"
)

const (
Expand All @@ -38,6 +39,7 @@ type eventUploaderContext struct {
func (c *eventUploaderContext) Setup() {
c.mockCtrl = gomock.NewController(GinkgoT())
c.mockBackendConfig = mocksBackendConfig.NewMockBackendConfig(c.mockCtrl)
c.mockBackendConfig.EXPECT().Identity().AnyTimes().Return(&testutils.BasicAuthMock{})
}

func (c *eventUploaderContext) Finish() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func NewHandle(backendConfig backendconfig.BackendConfig) (TransformationDebugge
return nil, err
}

h.uploader = debugger.New[*TransformStatusT](url, transformationStatusUploader)
h.uploader = debugger.New[*TransformStatusT](url, backendConfig.Identity(), transformationStatusUploader)
h.uploader.Start()

h.start(backendConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
mocksBackendConfig "github.com/rudderlabs/rudder-server/mocks/backend-config"
"github.com/rudderlabs/rudder-server/processor/transformer"
"github.com/rudderlabs/rudder-server/utils/pubsub"
testutils "github.com/rudderlabs/rudder-server/utils/tests"
"github.com/rudderlabs/rudder-server/utils/types"
)

Expand Down Expand Up @@ -165,6 +166,7 @@ type eventDeliveryStatusUploaderContext struct {
func (c *eventDeliveryStatusUploaderContext) Setup() {
c.mockCtrl = gomock.NewController(GinkgoT())
c.mockBackendConfig = mocksBackendConfig.NewMockBackendConfig(c.mockCtrl)
c.mockBackendConfig.EXPECT().Identity().AnyTimes().Return(&testutils.BasicAuthMock{})
c.mockBackendConfig.EXPECT().Subscribe(gomock.Any(), backendconfig.TopicProcessConfig).
DoAndReturn(func(ctx context.Context, topic backendconfig.Topic) pubsub.DataChannel {
// on Subscribe, emulate a backend configuration event
Expand Down
8 changes: 5 additions & 3 deletions services/debugger/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/rudderlabs/rudder-go-kit/stats"

"github.com/rudderlabs/rudder-server/rruntime"
"github.com/rudderlabs/rudder-server/services/controlplane/identity"
"github.com/rudderlabs/rudder-server/utils/httputil"
"github.com/rudderlabs/rudder-server/utils/sysUtils"
)
Expand Down Expand Up @@ -48,6 +49,7 @@ type uploaderImpl[E any] struct {
maxBatchSize, maxRetry, maxESQueueSize config.ValueLoader[int]
batchTimeout, retrySleep config.ValueLoader[time.Duration]
region string
authorizer identity.Authorizer

bgWaitGroup sync.WaitGroup
}
Expand All @@ -66,12 +68,12 @@ func (uploader *uploaderImpl[E]) Setup() {
uploader.region = config.GetString("region", "")
}

func New[E any](url string, transformer Transformer[E]) Uploader[E] {
func New[E any](url string, authorizer identity.Authorizer, transformer Transformer[E]) Uploader[E] {
eventBatchChannel := make(chan E)
eventBuffer := make([]E, 0)
client := &http.Client{Timeout: config.GetDuration("HttpClient.debugger.timeout", 30, time.Second)}

uploader := &uploaderImpl[E]{url: url, transformer: transformer, eventBatchChannel: eventBatchChannel, eventBuffer: eventBuffer, Client: client, bgWaitGroup: sync.WaitGroup{}}
uploader := &uploaderImpl[E]{url: url, transformer: transformer, eventBatchChannel: eventBatchChannel, eventBuffer: eventBuffer, Client: client, bgWaitGroup: sync.WaitGroup{}, authorizer: authorizer}
uploader.Setup()
return uploader
}
Expand Down Expand Up @@ -128,7 +130,7 @@ func (uploader *uploaderImpl[E]) uploadEvents(eventBuffer []E) {
req.URL.RawQuery = q.Encode()
}
req.Header.Set("Content-Type", "application/json;charset=UTF-8")
req.SetBasicAuth(config.GetWorkspaceToken(), "")
req.SetBasicAuth(uploader.authorizer.BasicAuth())

resp, err = uploader.Client.Do(req)
if err != nil {
Expand Down
28 changes: 16 additions & 12 deletions services/debugger/uploader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

mocksDebugger "github.com/rudderlabs/rudder-server/mocks/services/debugger"
mocksSysUtils "github.com/rudderlabs/rudder-server/mocks/utils/sysUtils"
testutils "github.com/rudderlabs/rudder-server/utils/tests"
)

type uploaderContext struct {
Expand Down Expand Up @@ -69,7 +70,7 @@ var _ = Describe("Uploader", func() {
mockHTTPClient = mocksSysUtils.NewMockHTTPClientI(c.mockCtrl)
mockHTTP = mocksSysUtils.NewMockHttpI(c.mockCtrl)
mockTransformer = mocksDebugger.NewMockTransformerAny(c.mockCtrl)
uploader = New[any]("http://test", mockTransformer)
uploader = New[any]("http://test", &testutils.BasicAuthMock{}, mockTransformer)
uploader.Start()
})

Expand Down Expand Up @@ -99,8 +100,7 @@ var _ = Describe("Uploader", func() {

mockHTTPClient.EXPECT().Do(gomock.Any()).Do(func(req *http.Request) {
// asserting http request
req.Method = "POST"
req.URL.Host = "test"
assertRequest(req)
}).Return(&http.Response{
StatusCode: 200,
Body: r,
Expand Down Expand Up @@ -129,8 +129,7 @@ var _ = Describe("Uploader", func() {

mockHTTPClient.EXPECT().Do(gomock.Any()).Do(func(req *http.Request) {
// asserting http request
req.Method = "POST"
req.URL.Host = "test"
assertRequest(req)
}).Return(&http.Response{
StatusCode: 400,
Body: r,
Expand Down Expand Up @@ -199,9 +198,7 @@ var _ = Describe("Uploader", func() {

mockHTTPClient.EXPECT().Do(gomock.Any()).Do(func(req *http.Request) {
// asserting http request
req.Method = "POST"
req.URL.Host = "test"

assertRequest(req)
wg.Done()
}).Return(&http.Response{
StatusCode: 200,
Expand Down Expand Up @@ -236,8 +233,7 @@ var _ = Describe("Uploader", func() {

mockHTTPClient.EXPECT().Do(gomock.Any()).Do(func(req *http.Request) {
// asserting http request
req.Method = "POST"
req.URL.Host = "test"
assertRequest(req)
}).Return(&http.Response{
StatusCode: 200,
Body: r,
Expand Down Expand Up @@ -283,8 +279,7 @@ var _ = Describe("Uploader", func() {

mockHTTPClient.EXPECT().Do(gomock.Any()).Do(func(req *http.Request) {
// asserting http request
req.Method = "POST"
req.URL.Host = "test"
assertRequest(req)
wg.Done()
}).Return(&http.Response{
StatusCode: 200,
Expand All @@ -298,3 +293,12 @@ var _ = Describe("Uploader", func() {
})
})
})

func assertRequest(req *http.Request) {
username, password, ok := req.BasicAuth()
Expect(ok).To(BeTrue())
Expect(username).To(Equal("test"))
Expect(password).To(Equal("test"))
Expect(req.Method).To(Equal("POST"))
Expect(req.URL.Host).To(Equal("test"))
}

0 comments on commit 519f3c6

Please sign in to comment.