expose and retrieve intercom secret from config

This commit is contained in:
Ashley Harrison
2023-03-01 11:17:17 +00:00
parent 16d9f075b4
commit a58c2f5a5b
10 changed files with 22 additions and 15 deletions
+3
View File
@@ -265,6 +265,9 @@ rudderstack_sdk_url =
# Rudderstack Config url, optional, used by Rudderstack SDK to fetch source config
rudderstack_config_url =
# Intercom secret, optional, used to hash user_id before passing to Intercom via Rudderstack
intercom_secret =
# Application Insights connection string. Specify an URL string to enable this feature.
application_insights_connection_string =
+3
View File
@@ -272,6 +272,9 @@
# Rudderstack Config url, optional, used by Rudderstack SDK to fetch source config
;rudderstack_config_url =
# Intercom secret, optional, used to hash user_id before passing to Intercom via Rudderstack
;intercom_secret =
# Controls if the UI contains any links to user feedback forms
;feedback_links_enabled = true
+1 -1
View File
@@ -98,7 +98,7 @@ export type OAuthSettings = Partial<Record<OAuth, { name: string; icon?: IconNam
export interface AnalyticsSettings {
identifier: string;
hashedIdentifier?: string;
intercomIdentifier?: string;
}
/** Current user info included in bootData
+2 -2
View File
@@ -52,8 +52,8 @@ type CurrentUser struct {
}
type AnalyticsSettings struct {
Identifier string `json:"identifier"`
HashedIdentifier string `json:"hashedIdentifier,omitempty"`
Identifier string `json:"identifier"`
IntercomIdentifier string `json:"intercomIdentifier,omitempty"`
}
type UserPermissionsMap map[string]bool
+2 -2
View File
@@ -113,8 +113,8 @@ func (hs *HTTPServer) setIndexViewData(c *contextmodel.ReqContext) (*dtos.IndexV
HelpFlags1: c.HelpFlags1,
HasEditPermissionInFolders: hasEditPerm,
Analytics: dtos.AnalyticsSettings{
Identifier: c.SignedInUser.Analytics.Identifier,
HashedIdentifier: c.SignedInUser.Analytics.HashedIdentifier,
Identifier: c.SignedInUser.Analytics.Identifier,
IntercomIdentifier: c.SignedInUser.Analytics.IntercomIdentifier,
},
},
Settings: settings,
+2 -2
View File
@@ -194,8 +194,8 @@ type GetSignedInUserQuery struct {
}
type AnalyticsSettings struct {
Identifier string
HashedIdentifier string
Identifier string
IntercomIdentifier string
}
type SignedInUser struct {
+1 -1
View File
@@ -433,7 +433,7 @@ func (ss *sqlStore) GetSignedInUser(ctx context.Context, query *user.GetSignedIn
signedInUser.ExternalAuthID = ""
}
signedInUser.Analytics = buildUserAnalyticsSettings(signedInUser)
signedInUser.Analytics = buildUserAnalyticsSettings(signedInUser, ss.cfg.IntercomSecret)
return nil
})
return &signedInUser, err
+3 -4
View File
@@ -8,7 +8,6 @@ import (
"encoding/json"
"errors"
"fmt"
"os"
"strings"
"time"
@@ -606,7 +605,7 @@ func hashUserIdentifier(identifier string, secret string) string {
return hex.EncodeToString(h.Sum(nil))
}
func buildUserAnalyticsSettings(signedInUser user.SignedInUser) user.AnalyticsSettings {
func buildUserAnalyticsSettings(signedInUser user.SignedInUser, intercomSecret string) user.AnalyticsSettings {
var settings user.AnalyticsSettings
if signedInUser.ExternalAuthID != "" {
@@ -615,8 +614,8 @@ func buildUserAnalyticsSettings(signedInUser user.SignedInUser) user.AnalyticsSe
settings.Identifier = signedInUser.Email
}
if os.Getenv("GF_ANALYTICS_SECRET") != "" {
settings.HashedIdentifier = hashUserIdentifier(settings.Identifier, os.Getenv("GF_ANALYTICS_SECRET"))
if intercomSecret != "" {
settings.IntercomIdentifier = hashUserIdentifier(settings.Identifier, intercomSecret)
}
return settings
}
+2
View File
@@ -401,6 +401,7 @@ type Cfg struct {
RudderstackWriteKey string
RudderstackSDKURL string
RudderstackConfigURL string
IntercomSecret string
// AzureAD
AzureADSkipOrgRoleSync bool
@@ -1034,6 +1035,7 @@ func (cfg *Cfg) Load(args CommandLineArgs) error {
cfg.RudderstackDataPlaneURL = analytics.Key("rudderstack_data_plane_url").String()
cfg.RudderstackSDKURL = analytics.Key("rudderstack_sdk_url").String()
cfg.RudderstackConfigURL = analytics.Key("rudderstack_config_url").String()
cfg.IntercomSecret = analytics.Key("intercom_secret").String()
cfg.ReportingEnabled = analytics.Key("reporting_enabled").MustBool(true)
cfg.ReportingDistributor = analytics.Key("reporting_distributor").MustString("grafana-labs")
@@ -70,12 +70,12 @@ export class RudderstackBackend implements EchoBackend<PageviewEchoEvent, Rudder
window.rudderanalytics?.load?.(options.writeKey, options.dataPlaneUrl, { configUrl: options.configUrl });
if (options.user) {
const { identifier, hashedIdentifier } = options.user.analytics;
const { identifier, intercomIdentifier } = options.user.analytics;
const apiOptions: apiOptions = {};
if (hashedIdentifier) {
if (intercomIdentifier) {
apiOptions.Intercom = {
user_hash: hashedIdentifier,
user_hash: intercomIdentifier,
};
}