Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/sample_xconfwebconfig.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 35 additions & 7 deletions dataapi/estb_firmware_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand All @@ -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])) {

@RahulRengeshOfficial RahulRengeshOfficial Jun 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @gravi21
I see the same AccountTypeModelSet.IsEmpty() || AccountTypeModelSet.Contains(...) condition being checked at both line 267 and line 277. Since contextMap[common.MODEL] doesn't change between these two points, the inner check at line 277 appears to be redundant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RahulRengeshOfficial in line 277 case is for when we already have accountId in the request from device and in line 267 is for unknown accountId case.
All these is for workround until we get accounttype in /ada keyspace

if util.IsValidMacAddress(contextMap[common.ESTB_MAC]) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gravi21 Can we cache the value of checking if mac address is valid so that we don't to do the same check again on line 285?

validMac := util.IsValidMacAddress(contextMap[common.ESTB_MAC])
if validMac {
...

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]) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to call check again.
if validMac {

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])
Expand All @@ -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 != "" {
Expand Down
65 changes: 53 additions & 12 deletions dataapi/feature_control_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)

Expand All @@ -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 != "" {
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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)
}

Expand All @@ -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])) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @gravi21
I see the same AccountTypeModelSet.IsEmpty() || AccountTypeModelSet.Contains(...) condition being checked before, Since contextMap[common.MODEL] doesn't change between these two points, the inner check appears to be redundant.

if accountType, ok := accountProducts["AccountType"]; ok && accountType != "" {
contextMap[common.ACCOUNT_TYPE] = accountType
}
}

if raw, ok := accountProducts["AccountProducts"]; ok && raw != "" {
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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]) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should cache value if mac is valid so don't have to call gain.

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])
Expand All @@ -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 != "" {
Expand Down
41 changes: 36 additions & 5 deletions dataapi/log_uploader_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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]) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should cache value if mac is valid so don't have to call gain.

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)
Expand All @@ -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 != "" {
Expand Down
11 changes: 11 additions & 0 deletions dataapi/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -328,6 +338,7 @@ func GetXconfConfigs(conf *conf.Config) *XconfConfigs {
MacTagsModelSet: macTagsModelSet,
AccountTagsModelSet: accountTagsModelSet,
PartnerTagsModelSet: partnerTagsModelSet,
AccountTypeModelSet: accountTypeModelSet,
MacTagsPrefixList: macTagsPrefixList,
AccountTagsPrefixList: accountTagsPrefixList,
PartnerTagsPrefixList: partnerTagsPrefixList,
Expand Down
Loading