diff --git a/config/sample_xconfwebconfig.conf b/config/sample_xconfwebconfig.conf index d38e1dff..13d6520c 100644 --- a/config/sample_xconfwebconfig.conf +++ b/config/sample_xconfwebconfig.conf @@ -234,6 +234,7 @@ xconfwebconfig { mac_tags_prefix_list = "t_" // Prefix list for MAC tags account_tags_prefix_list = "t_;p_" // Prefix list for account tags partner_tags_prefix_list = "t_" // Prefix list for partner tags + accounttype_model_list = "" return_account_id = true // Return account ID in responses return_account_hash = true // Return account hash in responses estb_recovery_firmware_versions = ".* .*" // Regex for recovery firmware versions diff --git a/dataapi/estb_firmware_context.go b/dataapi/estb_firmware_context.go index ceb808b6..ec47c06c 100644 --- a/dataapi/estb_firmware_context.go +++ b/dataapi/estb_firmware_context.go @@ -243,9 +243,7 @@ func AddEstbFirmwareContext(ws *xhttp.XconfServer, r *http.Request, contextMap m //default flow calling xac/ada keyspace if Xc.EnableXacGroupService { - //metrics for IncreaseUnknownIdCounter var macAddress string - //this is for metrics unknown accntId if util.IsUnknownValue(contextMap[common.ACCOUNT_ID]) || contextMap[common.ACCOUNT_ID] == "" || util.IsUnknownValue(contextMap[common.PARTNER_ID]) { xhttp.IncreaseUnknownIdCounter(contextMap[common.MODEL], contextMap[common.PARTNER_ID]) if util.IsValidMacAddress(contextMap[common.ESTB_MAC]) { @@ -265,14 +263,42 @@ func AddEstbFirmwareContext(ws *xhttp.XconfServer, r *http.Request, contextMap m if xAccountId != nil && err == nil { accountId = xAccountId.GetAccountId() - accountType = xAccountId.GetAccountType() contextMap[common.ACCOUNT_ID] = accountId - contextMap[common.ACCOUNT_TYPE] = accountType + if Xc.AccountTypeModelSet.IsEmpty() || Xc.AccountTypeModelSet.Contains(strings.ToLower(contextMap[common.MODEL])) { + accountType = xAccountId.GetAccountType() + contextMap[common.ACCOUNT_TYPE] = accountType + } log.WithFields(fields).Debugf("AddEstbFirmwareContext Successfully fetched AcntId='%s' and AcntType='%s' from Grp Svc", accountId, accountType) } if contextMap[common.ACCOUNT_ID] != "" && !util.IsUnknownValue(contextMap[common.ACCOUNT_ID]) { - log.WithFields(fields).Debugf("AddEstbFirmwareContext AcntId='%s' already present,fetching AccntPrds directly from ada", contextMap[common.ACCOUNT_ID]) + log.WithFields(fields).Debugf("AddEstbFirmwareContext AcntId='%s' received from grpsvc,now fetching AccntPrds", contextMap[common.ACCOUNT_ID]) + + if Xc.AccountTypeModelSet.IsEmpty() || Xc.AccountTypeModelSet.Contains(strings.ToLower(contextMap[common.MODEL])) { + if util.IsValidMacAddress(contextMap[common.ESTB_MAC]) { + macAddress = contextMap[common.ESTB_MAC] + macPart := util.RemoveNonAlphabeticSymbols(contextMap[common.ESTB_MAC]) + xAccountId, err = ws.GroupServiceConnector.GetAccountIdData(macPart, fields) + } + + if xAccountId == nil && err != nil { + if util.IsValidMacAddress(contextMap[common.ECM_MAC_ADDRESS]) { + macAddress = contextMap[common.ECM_MAC_ADDRESS] + macPart := util.RemoveNonAlphabeticSymbols(contextMap[common.ECM_MAC_ADDRESS]) + xAccountId, err = ws.GroupServiceConnector.GetAccountIdData(macPart, fields) + } + + if xAccountId != nil && err == nil { + if Xc.AccountTypeModelSet.IsEmpty() || Xc.AccountTypeModelSet.Contains(strings.ToLower(contextMap[common.MODEL])) { + accountType = xAccountId.GetAccountType() + contextMap[common.ACCOUNT_TYPE] = accountType + } + } else { + log.WithFields(log.Fields{"error": err}).Errorf("Error getting accountId information from Grp Service for Mac=%s", macAddress) + } + } + + } accountProducts, err = ws.GroupServiceConnector.GetAccountProducts(accountId, fields) if err != nil { log.WithFields(log.Fields{"error": err}).Errorf("Error getting accountProducts information from Grp Service for AccountId=%s", contextMap[common.ACCOUNT_ID]) @@ -288,8 +314,10 @@ func AddEstbFirmwareContext(ws *xhttp.XconfServer, r *http.Request, contextMap m contextMap[common.TIME_ZONE] = TimeZone } - if accountType, ok := accountProducts["AccountType"]; ok && accountType != "" { - contextMap[common.ACCOUNT_TYPE] = accountType + if Xc.AccountTypeModelSet.IsEmpty() || Xc.AccountTypeModelSet.Contains(strings.ToLower(contextMap[common.MODEL])) { + if accountType, ok := accountProducts["AccountType"]; ok && accountType != "" { + contextMap[common.ACCOUNT_TYPE] = accountType + } } if raw, ok := accountProducts["AccountProducts"]; ok && raw != "" { diff --git a/dataapi/feature_control_context.go b/dataapi/feature_control_context.go index d3ebc3d5..dd963630 100644 --- a/dataapi/feature_control_context.go +++ b/dataapi/feature_control_context.go @@ -125,6 +125,7 @@ func getAccountInfoFromGrpService(ws *xhttp.XconfServer, contextMap map[string]s var td *AccountServiceData var xAccountId *conversion.XBOAccount + var accountType string var err error snURL := SN_PREFIX + contextMap[common.SERIAL_NUM] @@ -137,9 +138,11 @@ func getAccountInfoFromGrpService(ws *xhttp.XconfServer, contextMap map[string]s } if xAccountId != nil { accountId := xAccountId.GetAccountId() - accountType := xAccountId.GetAccountType() contextMap[common.ACCOUNT_ID] = accountId - contextMap[common.ACCOUNT_TYPE] = accountType + if Xc.AccountTypeModelSet.IsEmpty() || Xc.AccountTypeModelSet.Contains(strings.ToLower(contextMap[common.MODEL])) { + accountType = xAccountId.GetAccountType() + contextMap[common.ACCOUNT_TYPE] = accountType + } contextMap[common.ACCOUNT_HASH] = util.CalculateHash(accountId) log.WithFields(fields).Debugf("AddContextForPods Successfully fetched AcntId='%s' and AcntType='%s' from Grp Svc", accountId, accountType) @@ -162,8 +165,10 @@ func getAccountInfoFromGrpService(ws *xhttp.XconfServer, contextMap map[string]s contextMap[common.COUNTRY_CODE] = countryCode } - if accountType, ok := accountProducts["AccountType"]; ok && accountType != "" { - contextMap[common.ACCOUNT_TYPE] = accountType + if Xc.AccountTypeModelSet.IsEmpty() || Xc.AccountTypeModelSet.Contains(strings.ToLower(contextMap[common.MODEL])) { + if accountType, ok := accountProducts["AccountType"]; ok && accountType != "" { + contextMap[common.ACCOUNT_TYPE] = accountType + } } if raw, ok := accountProducts["AccountProducts"]; ok && raw != "" { @@ -330,6 +335,7 @@ func AddContextForPods(ws *xhttp.XconfServer, contextMap map[string]string, satT func AddFeatureControlContextFromAccountService(ws *xhttp.XconfServer, contextMap map[string]string, satToken string, vargs ...log.Fields) *AccountServiceData { var td *AccountServiceData var accountId string + var accountType string var fields log.Fields if len(vargs) > 0 { fields = vargs[0] @@ -362,9 +368,11 @@ func AddFeatureControlContextFromAccountService(ws *xhttp.XconfServer, contextMa } else { if xAccountId != nil && xAccountId.GetAccountId() != "" { accountId = xAccountId.GetAccountId() - accountType := xAccountId.GetAccountType() contextMap[common.ACCOUNT_ID] = accountId - contextMap[common.ACCOUNT_TYPE] = accountType + if Xc.AccountTypeModelSet.IsEmpty() || Xc.AccountTypeModelSet.Contains(strings.ToLower(contextMap[common.MODEL])) { + accountType = xAccountId.GetAccountType() + contextMap[common.ACCOUNT_TYPE] = accountType + } log.WithFields(fields).Debugf("AddFeatureControlContextFromAccountService Successfully fetched AcntId='%s' and AcntType='%s' from Grp Svc", accountId, accountType) } @@ -389,8 +397,10 @@ func AddFeatureControlContextFromAccountService(ws *xhttp.XconfServer, contextMa contextMap[common.TIME_ZONE] = TimeZone } - if accountType, ok := accountProducts["AccountType"]; ok && accountType != "" { - contextMap[common.ACCOUNT_TYPE] = accountType + if Xc.AccountTypeModelSet.IsEmpty() || Xc.AccountTypeModelSet.Contains(strings.ToLower(contextMap[common.MODEL])) { + if accountType, ok := accountProducts["AccountType"]; ok && accountType != "" { + contextMap[common.ACCOUNT_TYPE] = accountType + } } if raw, ok := accountProducts["AccountProducts"]; ok && raw != "" { @@ -410,7 +420,7 @@ func AddFeatureControlContextFromAccountService(ws *xhttp.XconfServer, contextMa } xhttp.IncreaseGrpServiceFetchCounter(contextMap[common.MODEL], contextMap[common.PARTNER_ID]) - log.WithFields(fields).Debugf("AddFeatureControlContextFromAccountService AcntId='%s' ,AccntPrd='%v' successfully retrieved from xac/ada", contextMap[common.ACCOUNT_ID], contextMap) + log.WithFields(fields).Debugf("AddFeatureControlContextFromAccountService AcntId='%s' ,AccntPrd='%v' successfully retrieved from grp svc", contextMap[common.ACCOUNT_ID], contextMap) return td } } @@ -498,6 +508,9 @@ func AddFeatureControlContext(ws *xhttp.XconfServer, r *http.Request, contextMap var fields log.Fields var podData *PodData var td *AccountServiceData + var macAddress string + var accountType string + var xAccountId *conversion.XBOAccount if len(vargs) > 0 { fields = vargs[0] } else { @@ -516,7 +529,33 @@ func AddFeatureControlContext(ws *xhttp.XconfServer, r *http.Request, contextMap if Xc.EnableXacGroupService { if contextMap[common.ACCOUNT_ID] != "" && !util.IsUnknownValue(contextMap[common.ACCOUNT_ID]) { - log.WithFields(fields).Debugf("AddFeatureControlContext AcntId='%s' already present,fetching AccntPrds directly from ada", contextMap[common.ACCOUNT_ID]) + log.WithFields(fields).Debugf("AddFeatureControlContext AcntId='%s' already present", contextMap[common.ACCOUNT_ID]) + + if Xc.AccountTypeModelSet.IsEmpty() || Xc.AccountTypeModelSet.Contains(strings.ToLower(contextMap[common.MODEL])) { + if util.IsValidMacAddress(contextMap[common.ESTB_MAC]) { + macAddress = contextMap[common.ESTB_MAC] + macPart := util.RemoveNonAlphabeticSymbols(contextMap[common.ESTB_MAC]) + xAccountId, err = ws.GroupServiceConnector.GetAccountIdData(macPart, fields) + } + + if xAccountId == nil && err != nil { + if util.IsValidMacAddress(contextMap[common.ECM_MAC_ADDRESS]) { + macAddress = contextMap[common.ECM_MAC_ADDRESS] + macPart := util.RemoveNonAlphabeticSymbols(contextMap[common.ECM_MAC_ADDRESS]) + xAccountId, err = ws.GroupServiceConnector.GetAccountIdData(macPart, fields) + } + } + + if xAccountId != nil && err == nil { + if Xc.AccountTypeModelSet.IsEmpty() || Xc.AccountTypeModelSet.Contains(strings.ToLower(contextMap[common.MODEL])) { + accountType = xAccountId.GetAccountType() + contextMap[common.ACCOUNT_TYPE] = accountType + } + } else { + log.WithFields(log.Fields{"error": err}).Errorf("Error getting accountId information from Grp Service for Mac=%s", macAddress) + } + } + accountProducts, err := ws.GroupServiceConnector.GetAccountProducts(contextMap[common.ACCOUNT_ID], fields) if err != nil { log.WithFields(log.Fields{"error": err}).Errorf("Error getting accountProducts information from Grp Service for AccountId=%s", contextMap[common.ACCOUNT_ID]) @@ -538,8 +577,10 @@ func AddFeatureControlContext(ws *xhttp.XconfServer, r *http.Request, contextMap contextMap[common.TIME_ZONE] = TimeZone } - if accountType, ok := accountProducts["AccountType"]; ok && accountType != "" { - contextMap[common.ACCOUNT_TYPE] = accountType + if Xc.AccountTypeModelSet.IsEmpty() || Xc.AccountTypeModelSet.Contains(strings.ToLower(contextMap[common.MODEL])) { + if accountType, ok := accountProducts["AccountType"]; ok && accountType != "" { + contextMap[common.ACCOUNT_TYPE] = accountType + } } if raw, ok := accountProducts["AccountProducts"]; ok && raw != "" { diff --git a/dataapi/log_uploader_context.go b/dataapi/log_uploader_context.go index bffef684..a88a1b4f 100644 --- a/dataapi/log_uploader_context.go +++ b/dataapi/log_uploader_context.go @@ -52,6 +52,7 @@ func NormalizeLogUploaderContext(ws *xhttp.XconfServer, r *http.Request, context func AddLogUploaderContext(ws *xhttp.XconfServer, r *http.Request, contextMap map[string]string, usePartnerAppType bool, vargs ...log.Fields) ([]string, error) { var fields log.Fields var accountId string + var accountType string if len(vargs) > 0 { fields = vargs[0] } else { @@ -90,14 +91,42 @@ func AddLogUploaderContext(ws *xhttp.XconfServer, r *http.Request, contextMap ma if xAccountId != nil && err == nil { accountId = xAccountId.GetAccountId() - accountType := xAccountId.GetAccountType() contextMap[common.ACCOUNT_ID] = accountId - contextMap[common.ACCOUNT_TYPE] = accountType + if Xc.AccountTypeModelSet.IsEmpty() || Xc.AccountTypeModelSet.Contains(strings.ToLower(contextMap[common.MODEL])) { + accountType = xAccountId.GetAccountType() + contextMap[common.ACCOUNT_TYPE] = accountType + } log.WithFields(fields).Debugf("AddLogUploaderContext Successfully fetched AcntId='%s' and AcntType='%s' from Grp Svc", accountId, accountType) } if contextMap[common.ACCOUNT_ID] != "" && !util.IsUnknownValue(contextMap[common.ACCOUNT_ID]) { - log.WithFields(fields).Debugf("AddLogUploaderContext AcntId='%s' already present,fetching AccntPrds directly from ada", contextMap[common.ACCOUNT_ID]) + log.WithFields(fields).Debugf("AddLogUploaderContext AcntId='%s' already present,fetching AccntPrds directly from grp svc", contextMap[common.ACCOUNT_ID]) + + if Xc.AccountTypeModelSet.IsEmpty() || Xc.AccountTypeModelSet.Contains(strings.ToLower(contextMap[common.MODEL])) { + if util.IsValidMacAddress(contextMap[common.ESTB_MAC]) { + macAddress = contextMap[common.ESTB_MAC] + macPart := util.RemoveNonAlphabeticSymbols(contextMap[common.ESTB_MAC]) + xAccountId, err = ws.GroupServiceConnector.GetAccountIdData(macPart, fields) + } + + if xAccountId == nil && err != nil { + if util.IsValidMacAddress(contextMap[common.ECM_MAC_ADDRESS]) { + macAddress = contextMap[common.ECM_MAC_ADDRESS] + macPart := util.RemoveNonAlphabeticSymbols(contextMap[common.ECM_MAC_ADDRESS]) + xAccountId, err = ws.GroupServiceConnector.GetAccountIdData(macPart, fields) + } + } + + if xAccountId != nil && err == nil { + if Xc.AccountTypeModelSet.IsEmpty() || Xc.AccountTypeModelSet.Contains(strings.ToLower(contextMap[common.MODEL])) { + accountType = xAccountId.GetAccountType() + contextMap[common.ACCOUNT_TYPE] = accountType + } + } else { + log.WithFields(log.Fields{"error": err}).Errorf("Error getting accountId information from Grp Service for Mac=%s", macAddress) + } + } + accountProducts, err := ws.GroupServiceConnector.GetAccountProducts(accountId, fields) if err != nil { log.WithFields(log.Fields{"error": err}).Errorf("Error getting accountProducts information from Grp Service for AccountId=%s", accountId) @@ -116,8 +145,10 @@ func AddLogUploaderContext(ws *xhttp.XconfServer, r *http.Request, contextMap ma contextMap[common.TIME_ZONE] = TimeZone } - if accountType, ok := accountProducts["AccountType"]; ok && accountType != "" { - contextMap[common.ACCOUNT_TYPE] = accountType + if Xc.AccountTypeModelSet.IsEmpty() || Xc.AccountTypeModelSet.Contains(strings.ToLower(contextMap[common.MODEL])) { + if accountType, ok := accountProducts["AccountType"]; ok && accountType != "" { + contextMap[common.ACCOUNT_TYPE] = accountType + } } if raw, ok := accountProducts["AccountProducts"]; ok && raw != "" { diff --git a/dataapi/router.go b/dataapi/router.go index 9e32b564..7c3b4596 100644 --- a/dataapi/router.go +++ b/dataapi/router.go @@ -90,6 +90,7 @@ type XconfConfigs struct { ValidPartnerIdRegex *regexp.Regexp SecurityTokenManagerEnabled bool EnableTaggingComparison bool + AccountTypeModelSet util.Set } // Function to register the table name and the corresponding model/struct constructor @@ -294,6 +295,15 @@ func GetXconfConfigs(conf *conf.Config) *XconfConfigs { validPartnerIdRegex = regexp.MustCompile(defaultValidPartnerIdRegex) } + accountTypeModelSet := util.NewSet() + accountTypeModelList := conf.GetString("xconfwebconfig.xconf.accounttype_model_list") + if !util.IsBlank(accountTypeModelList) { + accountTypeModels := strings.Split(accountTypeModelList, ",") + for _, model := range accountTypeModels { + accountTypeModelSet.Add(strings.ToUpper(strings.TrimSpace(model))) + } + } + xc := &XconfConfigs{ DeriveAppTypeFromPartnerId: conf.GetBoolean("xconfwebconfig.xconf.derive_application_type_from_partner_id"), PartnerApplicationTypes: appTypes, @@ -328,6 +338,7 @@ func GetXconfConfigs(conf *conf.Config) *XconfConfigs { MacTagsModelSet: macTagsModelSet, AccountTagsModelSet: accountTagsModelSet, PartnerTagsModelSet: partnerTagsModelSet, + AccountTypeModelSet: accountTypeModelSet, MacTagsPrefixList: macTagsPrefixList, AccountTagsPrefixList: accountTagsPrefixList, PartnerTagsPrefixList: partnerTagsPrefixList,