-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: onboard Yandex Metrica Offline Events destination (#4534)
* chore: initial commit for ymoe * feat: onboard yandex metrica offline events destination, initial draft commit * chore: address comments, update csv generation updation logic * feat: add oauthv2 support into yandex * fix: add missing manager.go changes * fix: oauthv2 panic & add success response * chore: update request with destinationInfo in context * fix: update csvfilepath and refactor code * chore: add unit tests * chore: refactore code * chore: fix test case * chore: fix upload config * chore: address all formatting comments * chore: address all formatting commentsx2 * chore: update to use strconv for Price * chore: update error messages * fix: error test-case * chore: address comment, move id switch logic to function * chore: address review comments * chore: fix lint issue --------- Co-authored-by: Sai Sankeerth <sanpj2292@github.com> Co-authored-by: ItsSudip <sudip.paul1997@gmail.com> Co-authored-by: Sudip Paul <67197965+ItsSudip@users.noreply.github.com>
- Loading branch information
1 parent
e550a11
commit 904d8fb
Showing
11 changed files
with
595 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
router/batchrouter/asyncdestinationmanager/yandexmetrica/augmenter/augmenter.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package augmenter | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/samber/lo" | ||
"github.com/tidwall/gjson" | ||
|
||
"github.com/rudderlabs/rudder-server/services/oauth/v2/common" | ||
) | ||
|
||
type yandexAugmenter struct{} | ||
|
||
var YandexReqAugmenter = &yandexAugmenter{} | ||
|
||
// Custom augmenter for Yandex which sets token to Authorization header | ||
func (y *yandexAugmenter) Augment(r *http.Request, body []byte, secret json.RawMessage) error { | ||
if secret == nil { | ||
return errors.New("secret is nil") | ||
} | ||
token := gjson.GetBytes(secret, "accessToken").String() | ||
// format -> Authorization : OAuth <accessToken> | ||
r.Header.Set("Authorization", fmt.Sprintf("OAuth %s", token)) | ||
r.Body = io.NopCloser(bytes.NewReader(body)) | ||
return nil | ||
} | ||
|
||
func GetAuthErrorCategoryForYandex(responseBody []byte) (string, error) { | ||
/* | ||
Sample response for Yandex | ||
{ | ||
"errors": [ | ||
{ | ||
"error_type": "invalid_token", | ||
"message": "Invalid oauth_token" | ||
} | ||
], | ||
"code": 403, | ||
"message": "Invalid oauth_token" | ||
} | ||
*/ | ||
if len(lo.Filter(gjson.GetBytes(responseBody, "errors.#.error_type").Array(), func(errorTypeResult gjson.Result, _ int) bool { | ||
return strings.Contains(errorTypeResult.String(), "invalid_token") | ||
})) > 0 { | ||
return common.CategoryRefreshToken, nil | ||
} | ||
return "", nil | ||
} |
4 changes: 4 additions & 0 deletions
4
router/batchrouter/asyncdestinationmanager/yandexmetrica/testdata/uploadData.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{"message":{"DateTime":"361519255","Price":894.7297191082301,"Target":"1234","UserId":"221312"},"metadata":{"job_id":5}} | ||
{"message":{"DateTime":"361789255","Price":894.729,"Target":"1234","UserId":"221232"},"metadata":{"job_id":6}} | ||
{"message":{"DateTime":"361511235","Price":23,"Target":"1234","UserId":"221652"},"metadata":{"job_id":7}} | ||
{"message":{"DateTime":"361545655","Price":65,"Target":"1234","UserId":"289712"},"metadata":{"job_id":8}} |
Oops, something went wrong.