Skip to content

Commit

Permalink
Adjust converting auth config to JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Aug 26, 2024
1 parent a026143 commit 5439987
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
12 changes: 4 additions & 8 deletions handlers/firebase/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,8 @@ func (h *handler) sendWithCredsJSON(ctx context.Context, msg courier.MsgOut, res
return courier.ErrChannelConfig
}

credentialsFileJSON, ok := credentialsFile.(map[string]string)
if !ok {
return courier.ErrChannelConfig
}
var credentialsFileJSON map[string]string
jsonx.MustUnmarshal(jsonx.MustMarshal(credentialsFile), &credentialsFileJSON)

accessToken, err := h.getAccessToken(ctx, msg.Channel(), clog)
if err != nil {
Expand Down Expand Up @@ -377,10 +375,8 @@ func (h *handler) fetchAccessToken(ctx context.Context, channel courier.Channel,
return "", 0, courier.ErrChannelConfig
}

credentialsFileJSON, ok := credentialsFile.(map[string]string)
if !ok {
return "", 0, courier.ErrChannelConfig
}
var credentialsFileJSON map[string]string
jsonx.MustUnmarshal(jsonx.MustMarshal(credentialsFile), &credentialsFileJSON)

sendURL := fmt.Sprintf("https://fcm.googleapis.com/v1/projects/%s/messages:send", credentialsFileJSON["project_id"])

Expand Down
4 changes: 2 additions & 2 deletions handlers/firebase/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var testChannels = []courier.Channel{
[]string{urns.Firebase.Prefix},
map[string]any{
configTitle: "FCMTitle",
configCredentialsFile: map[string]string{
configCredentialsFile: map[string]any{
"type": "service_account",
"project_id": "foo-project-id",
"private_key_id": "123",
Expand All @@ -68,7 +68,7 @@ var testChannels = []courier.Channel{
map[string]any{
configNotification: true,
configTitle: "FCMTitle",
configCredentialsFile: map[string]string{
configCredentialsFile: map[string]any{
"type": "service_account",
"project_id": "bar-project-id",
"private_key_id": "123",
Expand Down

0 comments on commit 5439987

Please sign in to comment.