From cfaeb852a9375079d5afd773d6a540d4b1041c64 Mon Sep 17 00:00:00 2001 From: gravi638 Date: Tue, 9 Dec 2025 14:53:45 +0530 Subject: [PATCH 01/10] Changes for using xac and ada keyspace for accountId and accountProducts --- common/const_var.go | 1 + config/sample_xconfwebconfig.conf | 1 + dataapi/dataapi_common.go | 21 ++--- dataapi/estb_firmware_context.go | 31 +++++- dataapi/feature_control_context.go | 46 ++++++++- dataapi/router.go | 2 + http/group_service_connector.go | 36 +++++++ protobuf/xboaccount.pb.go | 146 +++++++++++++++++++++++++++++ 8 files changed, 266 insertions(+), 18 deletions(-) create mode 100644 protobuf/xboaccount.pb.go diff --git a/common/const_var.go b/common/const_var.go index 57fa850f..dc468469 100644 --- a/common/const_var.go +++ b/common/const_var.go @@ -111,6 +111,7 @@ const ( APPLICATION_TYPE = "applicationType" ACCOUNT_ID = "accountId" ACCOUNT_HASH = "accountHash" + ACCOUNT_PRODUCTS = "accountProducts" CONFIG_SET_HASH = "configSetHash" SYNDICATION_PARTNER = "SyndicationPartner" MAC = "mac" diff --git a/config/sample_xconfwebconfig.conf b/config/sample_xconfwebconfig.conf index 1e4dd606..a6674665 100644 --- a/config/sample_xconfwebconfig.conf +++ b/config/sample_xconfwebconfig.conf @@ -189,6 +189,7 @@ xconfwebconfig { enable_rfc_penetration_metrics = false // Enable RFC penetration metrics enable_device_service = false // Enable device service integration enable_account_service = false // Enable account service integration + enable_account_data_service = true enable_tagging_service = false // Enable tagging service integration enable_device_db_lookup = false // Enable device DB lookup enable_group_service = false // Enable group service integration diff --git a/dataapi/dataapi_common.go b/dataapi/dataapi_common.go index b87aab5d..2b2f78cc 100644 --- a/dataapi/dataapi_common.go +++ b/dataapi/dataapi_common.go @@ -161,18 +161,17 @@ func GetPartnerFromAccountServiceByHostMac(ws *xhttp.XconfServer, macAddress str } var partnerId string - if Xc.EnableAccountService { - var accountObject xhttp.AccountServiceDevices - var err error - if util.IsValidMacAddress(macAddress) { - accountObject, err = ws.AccountServiceConnector.GetDevices(common.HOST_MAC_PARAM, macAddress, satToken, fields) - } - if err != nil { - log.WithFields(log.Fields{"error": err}).Error("Error getting account information") - } else { - partnerId = strings.ToUpper(accountObject.DeviceData.Partner) - } + var accountObject xhttp.AccountServiceDevices + var err error + if util.IsValidMacAddress(macAddress) { + accountObject, err = ws.AccountServiceConnector.GetDevices(common.HOST_MAC_PARAM, macAddress, satToken, fields) } + if err != nil { + log.WithFields(log.Fields{"error": err}).Error("Error getting account information") + } else { + partnerId = strings.ToUpper(accountObject.DeviceData.Partner) + } + return partnerId } diff --git a/dataapi/estb_firmware_context.go b/dataapi/estb_firmware_context.go index 7340b21a..8c0826f1 100644 --- a/dataapi/estb_firmware_context.go +++ b/dataapi/estb_firmware_context.go @@ -230,12 +230,33 @@ func AddEstbFirmwareContext(ws *xhttp.XconfServer, r *http.Request, contextMap m return err } satToken := localToken.Token - - if util.IsUnknownValue(contextMap[common.PARTNER_ID]) { - partnerId := GetPartnerFromAccountServiceByHostMac(ws, contextMap[common.ESTB_MAC], satToken, fields) - if partnerId != "" { - contextMap[common.PARTNER_ID] = partnerId + if Xc.EnableAccountService { + if util.IsUnknownValue(contextMap[common.PARTNER_ID]) { + partnerId := GetPartnerFromAccountServiceByHostMac(ws, contextMap[common.ESTB_MAC], satToken, fields) + if partnerId != "" { + contextMap[common.PARTNER_ID] = partnerId + } + } + } else if Xc.EnableAccountDataService { + if util.IsValidMacAddress(contextMap[common.ESTB_MAC_ADDRESS]) || util.IsValidMacAddress(contextMap[common.ECM_MAC_ADDRESS]) { + xAccountId, err := ws.GroupServiceConnector.GetAccountIdData(contextMap[common.ECM_MAC_ADDRESS], fields) + if err != nil { + log.WithFields(log.Fields{"error": err}).Error("Error getting AccountService information") + } + if xAccountId != nil && xAccountId.GetAccountId() != "" { + accountProducts, err := ws.GroupServiceConnector.GetAccountProducts(xAccountId.GetAccountId(), fields) + if err != nil { + log.WithFields(log.Fields{"error": err}).Error("Error getting AccountService information") + } else { + if partner, ok := accountProducts["Partner"]; ok && partner != "" { + contextMap[common.PARTNER_ID] = partner + } + } + } } + } else { + //err both the service + log.WithFields(log.Fields{"error": err}).Error("Both the Account Service calls have been disabled") } AddContextFromTaggingService(ws, contextMap, satToken, "", false, fields) AddGroupServiceFTContext(Ws, common.ESTB_MAC, contextMap, true, fields) diff --git a/dataapi/feature_control_context.go b/dataapi/feature_control_context.go index 8b702800..3c9f9d59 100644 --- a/dataapi/feature_control_context.go +++ b/dataapi/feature_control_context.go @@ -234,16 +234,16 @@ 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 fields log.Fields if len(vargs) > 0 { fields = vargs[0] } else { fields = log.Fields{} } + var err error if Xc.EnableAccountService { var accountServiceObject xhttp.AccountServiceDevices - var err error if util.IsValidMacAddress(contextMap[common.ESTB_MAC_ADDRESS]) { accountServiceObject, err = ws.AccountServiceConnector.GetDevices(common.HOST_MAC_PARAM, contextMap[common.ESTB_MAC_ADDRESS], satToken, fields) if err == nil { @@ -297,6 +297,48 @@ func AddFeatureControlContextFromAccountService(ws *xhttp.XconfServer, contextMa } } } + } else if Xc.EnableAccountDataService { + if util.IsValidMacAddress(contextMap[common.ESTB_MAC_ADDRESS]) || util.IsValidMacAddress(contextMap[common.ECM_MAC_ADDRESS]) { + xboAccount, err := ws.GroupServiceConnector.GetAccountIdData(contextMap[common.ECM_MAC_ADDRESS], fields) + if err != nil { + log.WithFields(log.Fields{"error": err}).Error("Error getting accountId information") + xhttp.IncreaseAccountServiceEmptyResponseCounter(contextMap[common.MODEL]) + return td + } + if xboAccount != nil && xboAccount.GetAccountId() != "" { + accountId = xboAccount.GetAccountId() + contextMap[common.ACCOUNT_ID] = accountId + } else { + xhttp.IncreaseAccountServiceEmptyResponseCounter(contextMap[common.MODEL]) + return td + } + + td = &AccountServiceData{ + AccountId: accountId, + } + accountProducts, err := ws.GroupServiceConnector.GetAccountProducts(accountId, fields) + if err != nil { + log.WithFields(log.Fields{"error": err}).Error("Error getting accountProducts information") + } else { + if partner, ok := accountProducts["Partner"]; ok && partner != "" { + contextMap[common.PARTNER_ID] = strings.ToUpper(partner) + } + + contextMap[common.ACCOUNT_HASH] = util.CalculateHash(accountId) + + if accountProductsVal, ok := accountProducts["AccountProducts"]; ok { + contextMap[common.ACCOUNT_PRODUCTS] = accountProductsVal + } + + if countryCode, ok := accountProducts["CountryCode"]; ok { + contextMap[common.COUNTRY_CODE] = countryCode + } + + } + } + } else { + //error both service not enabled + log.WithFields(log.Fields{"error": err}).Error("Both the Account Service calls have been disabled") } return td } diff --git a/dataapi/router.go b/dataapi/router.go index 9d17f51f..fa62baa6 100644 --- a/dataapi/router.go +++ b/dataapi/router.go @@ -51,6 +51,7 @@ type XconfConfigs struct { EnableMacAccountServiceCall bool AccountServiceMacPrefix string EnableAccountService bool + EnableAccountDataService bool EnableTaggingService bool EnableTaggingServiceRFC bool IPv4NetworkMaskPrefixLength int32 @@ -298,6 +299,7 @@ func GetXconfConfigs(conf *conf.Config) *XconfConfigs { EnableDeviceDBLookup: conf.GetBoolean("xconfwebconfig.xconf.enable_device_db_lookup"), EnableMacAccountServiceCall: conf.GetBoolean("xconfwebconfig.xconf.enable_mac_accountservice_call"), EnableAccountService: conf.GetBoolean("xconfwebconfig.xconf.enable_account_service"), + EnableAccountDataService: conf.GetBoolean("xconfwebconfig.xconf.enable_account_data_service"), EnableTaggingService: conf.GetBoolean("xconfwebconfig.xconf.enable_tagging_service"), EnableTaggingServiceRFC: conf.GetBoolean("xconfwebconfig.xconf.enable_tagging_service_rfc"), ReturnAccountId: conf.GetBoolean("xconfwebconfig.xconf.return_account_id"), diff --git a/http/group_service_connector.go b/http/group_service_connector.go index 96afe570..6d9e9a14 100644 --- a/http/group_service_connector.go +++ b/http/group_service_connector.go @@ -20,6 +20,7 @@ package http import ( "crypto/tls" "fmt" + "net/http" "reflect" conversion "github.com/rdkcentral/xconfwebconfig/protobuf" @@ -35,6 +36,8 @@ const ( getRfcPrecookUrlTemplate = "%s/v2/xd/%s" getHashesUrlTemplate = "%s/v2/ft/%s" getSecurityTokenUrlTemplate = "%s/v2/st/%s" + getAccountIdTemplate = "%s/v2/xac/%s" + getAccountProductsTemplate = "%s/v2/ada/%s" ) type GroupServiceConnector interface { @@ -47,6 +50,8 @@ type GroupServiceConnector interface { CreateListFromGroupServiceProto(cpeGroup *conversion.CpeGroup) []string GetFeatureTagsHashedItems(name string, fields log.Fields) (map[string]string, error) GetSecurityTokenInfo(securityIdentifier string, fields log.Fields) (map[string]string, error) + GetAccountIdData(ecmMac string, fields log.Fields) (*conversion.XBOAccount, error) + GetAccountProducts(name string, fields log.Fields) (map[string]string, error) } type DefaultGroupService struct { @@ -171,3 +176,34 @@ func (c *DefaultGroupService) GetSecurityTokenInfo(securityIdentifier string, fi } return message.Fields, nil } + +func (c *DefaultGroupService) GetAccountIdData(ecmMac string, fields log.Fields) (*conversion.XBOAccount, error) { + url := fmt.Sprintf(getAccountIdTemplate, c.host, ecmMac) + rbytes, err := c.DoWithRetries(http.MethodGet, url, nil, nil, fields, groupServiceName) + if err != nil { + return nil, err + } + + var xboAccount conversion.XBOAccount + err = proto.Unmarshal(rbytes, &xboAccount) + if err != nil { + return nil, err + } + + return &xboAccount, nil +} + +func (c *DefaultGroupService) GetAccountProducts(name string, fields log.Fields) (map[string]string, error) { + url := fmt.Sprintf(getAccountProductsTemplate, c.GroupServiceHost(), name) + rbytes, err := c.DoWithRetries(http.MethodGet, url, nil, nil, fields, groupServiceName) + if err != nil { + return nil, err + } + message := conversion.XdasHashes{} + message.ProtoMessage() + err = proto.Unmarshal(rbytes, &message) + if err != nil { + return nil, err + } + return message.Fields, nil +} diff --git a/protobuf/xboaccount.pb.go b/protobuf/xboaccount.pb.go new file mode 100644 index 00000000..b1dc5a78 --- /dev/null +++ b/protobuf/xboaccount.pb.go @@ -0,0 +1,146 @@ +// keyspace xac + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.33.0 +// protoc v5.26.1 +// source: xboaccount.proto + +package conversion + +import ( + reflect "reflect" + sync "sync" + + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type XBOAccount struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + AccountId string `protobuf:"bytes,1,opt,name=account_id,json=accountId,proto3" json:"account_id,omitempty"` +} + +func (x *XBOAccount) Reset() { + *x = XBOAccount{} + if protoimpl.UnsafeEnabled { + mi := &file_xboaccount_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *XBOAccount) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*XBOAccount) ProtoMessage() {} + +func (x *XBOAccount) ProtoReflect() protoreflect.Message { + mi := &file_xboaccount_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use XBOAccount.ProtoReflect.Descriptor instead. +func (*XBOAccount) Descriptor() ([]byte, []int) { + return file_xboaccount_proto_rawDescGZIP(), []int{0} +} + +func (x *XBOAccount) GetAccountId() string { + if x != nil { + return x.AccountId + } + return "" +} + +var File_xboaccount_proto protoreflect.FileDescriptor + +var file_xboaccount_proto_rawDesc = []byte{ + 0x0a, 0x10, 0x78, 0x62, 0x6f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x12, 0x0e, 0x78, 0x70, 0x63, 0x2e, 0x78, 0x64, 0x61, 0x73, 0x2e, 0x6d, 0x6f, 0x64, + 0x65, 0x6c, 0x22, 0x2b, 0x0a, 0x0a, 0x58, 0x42, 0x4f, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, + 0x12, 0x1d, 0x0a, 0x0a, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x42, + 0x0e, 0x5a, 0x0c, 0x2e, 0x3b, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_xboaccount_proto_rawDescOnce sync.Once + file_xboaccount_proto_rawDescData = file_xboaccount_proto_rawDesc +) + +func file_xboaccount_proto_rawDescGZIP() []byte { + file_xboaccount_proto_rawDescOnce.Do(func() { + file_xboaccount_proto_rawDescData = protoimpl.X.CompressGZIP(file_xboaccount_proto_rawDescData) + }) + return file_xboaccount_proto_rawDescData +} + +var file_xboaccount_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_xboaccount_proto_goTypes = []interface{}{ + (*XBOAccount)(nil), // 0: xpc.xdas.model.XBOAccount +} +var file_xboaccount_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_xboaccount_proto_init() } +func file_xboaccount_proto_init() { + if File_xboaccount_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_xboaccount_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*XBOAccount); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_xboaccount_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_xboaccount_proto_goTypes, + DependencyIndexes: file_xboaccount_proto_depIdxs, + MessageInfos: file_xboaccount_proto_msgTypes, + }.Build() + File_xboaccount_proto = out.File + file_xboaccount_proto_rawDesc = nil + file_xboaccount_proto_goTypes = nil + file_xboaccount_proto_depIdxs = nil +} From c734e4ab7414b8aac94f237eb9435b7a33e189ad Mon Sep 17 00:00:00 2001 From: RahulRengeshOfficial Date: Fri, 19 Dec 2025 02:01:26 +0530 Subject: [PATCH 02/10] Update estb_firmware_context.go --- dataapi/estb_firmware_context.go | 40 +++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/dataapi/estb_firmware_context.go b/dataapi/estb_firmware_context.go index 8c0826f1..d694c6a7 100644 --- a/dataapi/estb_firmware_context.go +++ b/dataapi/estb_firmware_context.go @@ -238,25 +238,53 @@ func AddEstbFirmwareContext(ws *xhttp.XconfServer, r *http.Request, contextMap m } } } else if Xc.EnableAccountDataService { - if util.IsValidMacAddress(contextMap[common.ESTB_MAC_ADDRESS]) || util.IsValidMacAddress(contextMap[common.ECM_MAC_ADDRESS]) { - xAccountId, err := ws.GroupServiceConnector.GetAccountIdData(contextMap[common.ECM_MAC_ADDRESS], fields) + // Try ECM MAC first, then fall back to ESTB MAC + var macValue string + if util.IsValidMacAddress(contextMap[common.ECM_MAC]) { + macValue = contextMap[common.ECM_MAC] + } else if util.IsValidMacAddress(contextMap[common.ECM_MAC_PARAM]) { + macValue = contextMap[common.ECM_MAC_PARAM] + } else if util.IsValidMacAddress(contextMap[common.ESTB_MAC]) { + macValue = contextMap[common.ESTB_MAC] + } + + partnerFound := false + if macValue != "" { + // Remove colons from MAC for XAC call + macValueWithoutColons := strings.ReplaceAll(macValue, ":", "") + + xAccountId, err := ws.GroupServiceConnector.GetAccountIdData(macValueWithoutColons, fields) if err != nil { - log.WithFields(log.Fields{"error": err}).Error("Error getting AccountService information") + log.WithFields(fields).Warn(fmt.Sprintf("XAC call failed for MAC='%s': %v", macValueWithoutColons, err)) } + if xAccountId != nil && xAccountId.GetAccountId() != "" { - accountProducts, err := ws.GroupServiceConnector.GetAccountProducts(xAccountId.GetAccountId(), fields) + accountId := xAccountId.GetAccountId() + accountProducts, err := ws.GroupServiceConnector.GetAccountProducts(accountId, fields) if err != nil { - log.WithFields(log.Fields{"error": err}).Error("Error getting AccountService information") + log.WithFields(fields).Warn(fmt.Sprintf("ADA call failed for AccountId='%s': %v", accountId, err)) } else { if partner, ok := accountProducts["Partner"]; ok && partner != "" { contextMap[common.PARTNER_ID] = partner + partnerFound = true + log.WithFields(fields).Info(fmt.Sprintf("Partner='%s' retrieved from ADA", partner)) } } } } + + // Fallback to old Account Service logic if XAC/ADA didn't return partner + if !partnerFound && (util.IsUnknownValue(contextMap[common.PARTNER_ID]) || contextMap[common.PARTNER_ID] == "") { + log.WithFields(fields).Info("Trying fallback Account Service for partner retrieval") + partnerId := GetPartnerFromAccountServiceByHostMac(ws, contextMap[common.ESTB_MAC], satToken, fields) + if partnerId != "" { + contextMap[common.PARTNER_ID] = partnerId + log.WithFields(fields).Info(fmt.Sprintf("Partner='%s' retrieved from fallback Account Service", partnerId)) + } + } } else { //err both the service - log.WithFields(log.Fields{"error": err}).Error("Both the Account Service calls have been disabled") + log.Error("Both the Account Service calls have been disabled") } AddContextFromTaggingService(ws, contextMap, satToken, "", false, fields) AddGroupServiceFTContext(Ws, common.ESTB_MAC, contextMap, true, fields) From fc9d1fdacc1fc802580a767138da636b355a33b8 Mon Sep 17 00:00:00 2001 From: RahulRengeshOfficial Date: Mon, 22 Dec 2025 12:05:01 +0530 Subject: [PATCH 03/10] Update feature_control_context.go --- dataapi/feature_control_context.go | 98 ++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/dataapi/feature_control_context.go b/dataapi/feature_control_context.go index 3c9f9d59..eb030c3e 100644 --- a/dataapi/feature_control_context.go +++ b/dataapi/feature_control_context.go @@ -117,6 +117,68 @@ func CompareHashWithXDAS(contextMap map[string]string, xdasHash string, tags []s return calculatedHash == xdasHash, nil } +// tryXacAdaFlowForPods attempts to retrieve account data using XAC → ADA flow +func tryXacAdaFlowForPods(ws *xhttp.XconfServer, contextMap map[string]string, fields log.Fields) (*PodData, *AccountServiceData) { + var podData *PodData + var td *AccountServiceData + + // Try ECM MAC first, then fall back to ESTB MAC + var macValue string + if util.IsValidMacAddress(contextMap[common.ECM_MAC_ADDRESS]) { + macValue = contextMap[common.ECM_MAC_ADDRESS] + } else if util.IsValidMacAddress(contextMap[common.ESTB_MAC_ADDRESS]) { + macValue = contextMap[common.ESTB_MAC_ADDRESS] + } + + if macValue == "" { + return nil, nil + } + + // Remove colons from MAC for XAC call + macValueWithoutColons := strings.ReplaceAll(macValue, ":", "") + + // Call XAC to get AccountId + xAccountId, err := ws.GroupServiceConnector.GetAccountIdData(macValueWithoutColons, fields) + if err != nil { + log.WithFields(fields).Warn(fmt.Sprintf("XAC call failed for MAC='%s': %v", macValueWithoutColons, err)) + return nil, nil + } + + if xAccountId == nil || xAccountId.GetAccountId() == "" { + return nil, nil + } + + accountId := xAccountId.GetAccountId() + + // Call ADA to get account products + accountProducts, err := ws.GroupServiceConnector.GetAccountProducts(accountId, fields) + if err != nil { + log.WithFields(fields).Warn(fmt.Sprintf("ADA call failed for AccountId='%s': %v", accountId, err)) + return nil, nil + } + + // Extract Partner from ADA response + var partnerId string + if partner, ok := accountProducts["Partner"]; ok && partner != "" { + partnerId = strings.ToUpper(partner) + log.WithFields(fields).Info(fmt.Sprintf("Partner='%s' retrieved from ADA for pods", partnerId)) + } + + // Create PodData and AccountServiceData with retrieved information + podData = &PodData{ + AccountId: accountId, + PartnerId: partnerId, + // Note: TimeZone is not available from ADA, would need additional call if required + } + + td = &AccountServiceData{ + AccountId: accountId, + PartnerId: partnerId, + } + + return podData, td +} + func AddContextForPods(ws *xhttp.XconfServer, contextMap map[string]string, satToken string, vargs ...log.Fields) (*PodData, *AccountServiceData) { var fields log.Fields var podData *PodData @@ -130,6 +192,18 @@ func AddContextForPods(ws *xhttp.XconfServer, contextMap map[string]string, satT tfields := common.FilterLogFields(fields) if Xc.EnableMacAccountServiceCall && strings.HasPrefix(strings.ToUpper(contextMap[common.SERIAL_NUM]), Xc.AccountServiceMacPrefix) { + // Try XAC → ADA flow first if enabled + if Xc.EnableAccountDataService { + podData, td = tryXacAdaFlowForPods(ws, contextMap, fields) + if podData != nil && podData.AccountId != "" { + if util.IsUnknownValue(contextMap[common.ACCOUNT_ID]) && podData.AccountId != "" { + contextMap[common.ACCOUNT_ID] = podData.AccountId + } + return podData, td + } + } + + // Fallback: Old AccountService logic AccountServiceDeviceObject, err := ws.AccountServiceConnector.GetDevices(common.SERIAL_NUMBER_PARAM, contextMap[common.SERIAL_NUM], satToken, fields) if err != nil { log.WithFields(log.Fields{"error": err}).Errorf("Error getting AccountService device information: serialNum=%s", contextMap[common.SERIAL_NUM]) @@ -167,6 +241,18 @@ func AddContextForPods(ws *xhttp.XconfServer, contextMap map[string]string, satT podData.TimeZone = AccountServiceAccountObject.AccountData.AccountAttributes.TimeZone log.WithFields(tfields).Infof("Successfully got AccountService information for XLE device: accountId=%s, serialNum=%s", AccountServiceDeviceObject.DeviceData.ServiceAccountUri, contextMap[common.SERIAL_NUM]) } else if Xc.EnableDeviceDBLookup && contextMap[common.SERIAL_NUM] != "" && !strings.HasPrefix(contextMap[common.MODEL], GR_PREFIX) { + // Try XAC → ADA flow first if enabled + if Xc.EnableAccountDataService { + podData, td = tryXacAdaFlowForPods(ws, contextMap, fields) + if podData != nil && podData.AccountId != "" { + if util.IsUnknownValue(contextMap[common.ACCOUNT_ID]) && podData.AccountId != "" { + contextMap[common.ACCOUNT_ID] = podData.AccountId + } + return podData, td + } + } + + // Fallback: Old AccountService logic ecmMacAddress, err := ws.GetEcmMacFromPodTable(contextMap[common.SERIAL_NUM]) if err != nil { log.WithFields(log.Fields{"error": err}).Errorf("Error looking up pod information from odp db: serialNum=%s", contextMap[common.SERIAL_NUM]) @@ -213,6 +299,18 @@ func AddContextForPods(ws *xhttp.XconfServer, contextMap map[string]string, satT } podData.TimeZone = accountServiceAccountObject.AccountData.AccountAttributes.TimeZone } else if Xc.EnableDeviceService && contextMap[common.SERIAL_NUM] != "" && !strings.HasPrefix(contextMap[common.MODEL], GR_PREFIX) { + // Try XAC → ADA flow first if enabled + if Xc.EnableAccountDataService { + podData, td = tryXacAdaFlowForPods(ws, contextMap, fields) + if podData != nil && podData.AccountId != "" { + if util.IsUnknownValue(contextMap[common.ACCOUNT_ID]) && podData.AccountId != "" { + contextMap[common.ACCOUNT_ID] = podData.AccountId + } + return podData, td + } + } + + // Fallback: Old Device Service (Titan) logic deviceServiceObject, err := ws.DeviceServiceConnector.GetMeshPodAccountBySerialNum(contextMap[common.SERIAL_NUM], fields) if err != nil { log.WithFields(log.Fields{"error": err}).Errorf("Error getting Device Service information: serialNum=%s", contextMap[common.SERIAL_NUM]) From 2d908b12140a616a53d0bbbdf9144d33b07bccd0 Mon Sep 17 00:00:00 2001 From: RahulRengeshOfficial Date: Wed, 24 Dec 2025 13:14:53 +0530 Subject: [PATCH 04/10] Update feature_control_context.go --- dataapi/feature_control_context.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/dataapi/feature_control_context.go b/dataapi/feature_control_context.go index eb030c3e..2946bab7 100644 --- a/dataapi/feature_control_context.go +++ b/dataapi/feature_control_context.go @@ -117,11 +117,16 @@ func CompareHashWithXDAS(contextMap map[string]string, xdasHash string, tags []s return calculatedHash == xdasHash, nil } -// tryXacAdaFlowForPods attempts to retrieve account data using XAC → ADA flow -func tryXacAdaFlowForPods(ws *xhttp.XconfServer, contextMap map[string]string, fields log.Fields) (*PodData, *AccountServiceData) { +// getPartnerFromAccountDataService attempts to retrieve account data using XAC → ADA flow +func getPartnerFromAccountDataService(ws *xhttp.XconfServer, contextMap map[string]string, fields log.Fields) (*PodData, *AccountServiceData) { var podData *PodData var td *AccountServiceData + // Skip XAC/ADA if partner already known + if !util.IsUnknownValue(contextMap[common.PARTNER_ID]) && contextMap[common.PARTNER_ID] != "" { + return nil, nil + } + // Try ECM MAC first, then fall back to ESTB MAC var macValue string if util.IsValidMacAddress(contextMap[common.ECM_MAC_ADDRESS]) { @@ -194,7 +199,7 @@ func AddContextForPods(ws *xhttp.XconfServer, contextMap map[string]string, satT if Xc.EnableMacAccountServiceCall && strings.HasPrefix(strings.ToUpper(contextMap[common.SERIAL_NUM]), Xc.AccountServiceMacPrefix) { // Try XAC → ADA flow first if enabled if Xc.EnableAccountDataService { - podData, td = tryXacAdaFlowForPods(ws, contextMap, fields) + podData, td = getPartnerFromAccountDataService(ws, contextMap, fields) if podData != nil && podData.AccountId != "" { if util.IsUnknownValue(contextMap[common.ACCOUNT_ID]) && podData.AccountId != "" { contextMap[common.ACCOUNT_ID] = podData.AccountId @@ -243,7 +248,7 @@ func AddContextForPods(ws *xhttp.XconfServer, contextMap map[string]string, satT } else if Xc.EnableDeviceDBLookup && contextMap[common.SERIAL_NUM] != "" && !strings.HasPrefix(contextMap[common.MODEL], GR_PREFIX) { // Try XAC → ADA flow first if enabled if Xc.EnableAccountDataService { - podData, td = tryXacAdaFlowForPods(ws, contextMap, fields) + podData, td = getPartnerFromAccountDataService(ws, contextMap, fields) if podData != nil && podData.AccountId != "" { if util.IsUnknownValue(contextMap[common.ACCOUNT_ID]) && podData.AccountId != "" { contextMap[common.ACCOUNT_ID] = podData.AccountId @@ -301,7 +306,7 @@ func AddContextForPods(ws *xhttp.XconfServer, contextMap map[string]string, satT } else if Xc.EnableDeviceService && contextMap[common.SERIAL_NUM] != "" && !strings.HasPrefix(contextMap[common.MODEL], GR_PREFIX) { // Try XAC → ADA flow first if enabled if Xc.EnableAccountDataService { - podData, td = tryXacAdaFlowForPods(ws, contextMap, fields) + podData, td = getPartnerFromAccountDataService(ws, contextMap, fields) if podData != nil && podData.AccountId != "" { if util.IsUnknownValue(contextMap[common.ACCOUNT_ID]) && podData.AccountId != "" { contextMap[common.ACCOUNT_ID] = podData.AccountId From 122cbe6ff36ed2fa6a09d34d472c505941e7208c Mon Sep 17 00:00:00 2001 From: RahulRengeshOfficial Date: Wed, 24 Dec 2025 13:15:09 +0530 Subject: [PATCH 05/10] Update estb_firmware_context.go --- dataapi/estb_firmware_context.go | 71 ++++++++++++++++---------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/dataapi/estb_firmware_context.go b/dataapi/estb_firmware_context.go index d694c6a7..6124daa9 100644 --- a/dataapi/estb_firmware_context.go +++ b/dataapi/estb_firmware_context.go @@ -238,48 +238,49 @@ func AddEstbFirmwareContext(ws *xhttp.XconfServer, r *http.Request, contextMap m } } } else if Xc.EnableAccountDataService { - // Try ECM MAC first, then fall back to ESTB MAC - var macValue string - if util.IsValidMacAddress(contextMap[common.ECM_MAC]) { - macValue = contextMap[common.ECM_MAC] - } else if util.IsValidMacAddress(contextMap[common.ECM_MAC_PARAM]) { - macValue = contextMap[common.ECM_MAC_PARAM] - } else if util.IsValidMacAddress(contextMap[common.ESTB_MAC]) { - macValue = contextMap[common.ESTB_MAC] - } - - partnerFound := false - if macValue != "" { - // Remove colons from MAC for XAC call - macValueWithoutColons := strings.ReplaceAll(macValue, ":", "") - - xAccountId, err := ws.GroupServiceConnector.GetAccountIdData(macValueWithoutColons, fields) - if err != nil { - log.WithFields(fields).Warn(fmt.Sprintf("XAC call failed for MAC='%s': %v", macValueWithoutColons, err)) + // Only call XAC/ADA if partner is unknown or empty + if util.IsUnknownValue(contextMap[common.PARTNER_ID]) || contextMap[common.PARTNER_ID] == "" { + // Try ECM MAC first, then fall back to ESTB MAC + var macValue string + if util.IsValidMacAddress(contextMap[common.ECM_MAC]) { + macValue = contextMap[common.ECM_MAC] + } else if util.IsValidMacAddress(contextMap[common.ECM_MAC_PARAM]) { + macValue = contextMap[common.ECM_MAC_PARAM] + } else if util.IsValidMacAddress(contextMap[common.ESTB_MAC]) { + macValue = contextMap[common.ESTB_MAC] } - if xAccountId != nil && xAccountId.GetAccountId() != "" { - accountId := xAccountId.GetAccountId() - accountProducts, err := ws.GroupServiceConnector.GetAccountProducts(accountId, fields) + if macValue != "" { + // Remove colons from MAC for XAC call + macValueWithoutColons := strings.ReplaceAll(macValue, ":", "") + + xAccountId, err := ws.GroupServiceConnector.GetAccountIdData(macValueWithoutColons, fields) if err != nil { - log.WithFields(fields).Warn(fmt.Sprintf("ADA call failed for AccountId='%s': %v", accountId, err)) - } else { - if partner, ok := accountProducts["Partner"]; ok && partner != "" { - contextMap[common.PARTNER_ID] = partner - partnerFound = true - log.WithFields(fields).Info(fmt.Sprintf("Partner='%s' retrieved from ADA", partner)) + log.WithFields(fields).Warn(fmt.Sprintf("XAC call failed for MAC='%s': %v", macValueWithoutColons, err)) + } + + if xAccountId != nil && xAccountId.GetAccountId() != "" { + accountId := xAccountId.GetAccountId() + accountProducts, err := ws.GroupServiceConnector.GetAccountProducts(accountId, fields) + if err != nil { + log.WithFields(fields).Warn(fmt.Sprintf("ADA call failed for AccountId='%s': %v", accountId, err)) + } else { + if partner, ok := accountProducts["Partner"]; ok && partner != "" { + contextMap[common.PARTNER_ID] = partner + log.WithFields(fields).Info(fmt.Sprintf("Partner='%s' retrieved from ADA", partner)) + } } } } - } - // Fallback to old Account Service logic if XAC/ADA didn't return partner - if !partnerFound && (util.IsUnknownValue(contextMap[common.PARTNER_ID]) || contextMap[common.PARTNER_ID] == "") { - log.WithFields(fields).Info("Trying fallback Account Service for partner retrieval") - partnerId := GetPartnerFromAccountServiceByHostMac(ws, contextMap[common.ESTB_MAC], satToken, fields) - if partnerId != "" { - contextMap[common.PARTNER_ID] = partnerId - log.WithFields(fields).Info(fmt.Sprintf("Partner='%s' retrieved from fallback Account Service", partnerId)) + // Fallback to old Account Service logic if XAC/ADA didn't return partner + if util.IsUnknownValue(contextMap[common.PARTNER_ID]) || contextMap[common.PARTNER_ID] == "" { + log.WithFields(fields).Info("Trying fallback Account Service for partner retrieval") + partnerId := GetPartnerFromAccountServiceByHostMac(ws, contextMap[common.ESTB_MAC], satToken, fields) + if partnerId != "" { + contextMap[common.PARTNER_ID] = partnerId + log.WithFields(fields).Info(fmt.Sprintf("Partner='%s' retrieved from fallback Account Service", partnerId)) + } } } } else { From 8130a44eff015d982c397ec81dec38eda3aaff3f Mon Sep 17 00:00:00 2001 From: RahulRengeshOfficial Date: Tue, 30 Dec 2025 00:53:44 +0530 Subject: [PATCH 06/10] Update feature_control_context.go --- dataapi/feature_control_context.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/dataapi/feature_control_context.go b/dataapi/feature_control_context.go index 2946bab7..d9db0fb7 100644 --- a/dataapi/feature_control_context.go +++ b/dataapi/feature_control_context.go @@ -162,23 +162,28 @@ func getPartnerFromAccountDataService(ws *xhttp.XconfServer, contextMap map[stri return nil, nil } - // Extract Partner from ADA response - var partnerId string + // Extract Partner and TimeZone from ADA response + var partnerId, timeZone string if partner, ok := accountProducts["Partner"]; ok && partner != "" { partnerId = strings.ToUpper(partner) log.WithFields(fields).Info(fmt.Sprintf("Partner='%s' retrieved from ADA for pods", partnerId)) } + if tz, ok := accountProducts["TimeZone"]; ok && tz != "" { + timeZone = tz + log.WithFields(fields).Info(fmt.Sprintf("TimeZone='%s' retrieved from ADA for pods", timeZone)) + } // Create PodData and AccountServiceData with retrieved information podData = &PodData{ AccountId: accountId, PartnerId: partnerId, - // Note: TimeZone is not available from ADA, would need additional call if required + TimeZone: timeZone, } td = &AccountServiceData{ AccountId: accountId, PartnerId: partnerId, + TimeZone: timeZone, } return podData, td @@ -196,7 +201,12 @@ func AddContextForPods(ws *xhttp.XconfServer, contextMap map[string]string, satT tfields := common.FilterLogFields(fields) - if Xc.EnableMacAccountServiceCall && strings.HasPrefix(strings.ToUpper(contextMap[common.SERIAL_NUM]), Xc.AccountServiceMacPrefix) { + if Xc.EnableMacAccountServiceCall && strings.HasPrefix(strings.ToUpper(contextMap[common.SERIAL_NUM]), Xc.AccountServiceMacPrefix) { + // Remove colons from ecmMacAddress before sending to XAC + if ecmMac, ok := contextMap[common.ECM_MAC]; ok && ecmMac != "" { + contextMap[common.ECM_MAC] = strings.ReplaceAll(ecmMac, ":", "") + } + log.WithFields(tfields).Infof("Trying XAC/ADA for partner retrieval using serialum='%s' and contextMap[common.ECM_MAC]='%s'", contextMap[common.SERIAL_NUM], contextMap[common.ECM_MAC]) // Try XAC → ADA flow first if enabled if Xc.EnableAccountDataService { podData, td = getPartnerFromAccountDataService(ws, contextMap, fields) From d73ceda98bddd4619bb94487088e3fa8f1c0f5ef Mon Sep 17 00:00:00 2001 From: RahulRengeshOfficial Date: Tue, 30 Dec 2025 00:53:57 +0530 Subject: [PATCH 07/10] Update estb_firmware_context.go --- dataapi/estb_firmware_context.go | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/dataapi/estb_firmware_context.go b/dataapi/estb_firmware_context.go index 6124daa9..7103ad5a 100644 --- a/dataapi/estb_firmware_context.go +++ b/dataapi/estb_firmware_context.go @@ -221,7 +221,7 @@ func AddEstbFirmwareContext(ws *xhttp.XconfServer, r *http.Request, contextMap m fields = log.Fields{} } log.Debug(fmt.Sprintf("AddEstbFirmwareContext start ... contextMap %v", contextMap)) - NormalizeEstbFirmwareContext(ws, r, contextMap, usePartnerAppType, shouldAddIp, fields) + // No normalization, use contextMap[common.ESTB_MAC] directly AddGroupServiceContext(ws, contextMap, common.ESTB_MAC, fields) // getting local sat token localToken, err := xhttp.GetLocalSatToken(fields) @@ -240,25 +240,15 @@ func AddEstbFirmwareContext(ws *xhttp.XconfServer, r *http.Request, contextMap m } else if Xc.EnableAccountDataService { // Only call XAC/ADA if partner is unknown or empty if util.IsUnknownValue(contextMap[common.PARTNER_ID]) || contextMap[common.PARTNER_ID] == "" { - // Try ECM MAC first, then fall back to ESTB MAC - var macValue string - if util.IsValidMacAddress(contextMap[common.ECM_MAC]) { - macValue = contextMap[common.ECM_MAC] - } else if util.IsValidMacAddress(contextMap[common.ECM_MAC_PARAM]) { - macValue = contextMap[common.ECM_MAC_PARAM] - } else if util.IsValidMacAddress(contextMap[common.ESTB_MAC]) { - macValue = contextMap[common.ESTB_MAC] - } - + // Use contextMap[common.ESTB_MAC] directly for MAC + macValue := contextMap[common.ESTB_MAC] + log.WithFields(fields).Info(fmt.Sprintf("Trying XAC/ADA for partner retrieval using MAC='%s'", macValue)) if macValue != "" { - // Remove colons from MAC for XAC call macValueWithoutColons := strings.ReplaceAll(macValue, ":", "") - xAccountId, err := ws.GroupServiceConnector.GetAccountIdData(macValueWithoutColons, fields) if err != nil { log.WithFields(fields).Warn(fmt.Sprintf("XAC call failed for MAC='%s': %v", macValueWithoutColons, err)) } - if xAccountId != nil && xAccountId.GetAccountId() != "" { accountId := xAccountId.GetAccountId() accountProducts, err := ws.GroupServiceConnector.GetAccountProducts(accountId, fields) @@ -272,7 +262,6 @@ func AddEstbFirmwareContext(ws *xhttp.XconfServer, r *http.Request, contextMap m } } } - // Fallback to old Account Service logic if XAC/ADA didn't return partner if util.IsUnknownValue(contextMap[common.PARTNER_ID]) || contextMap[common.PARTNER_ID] == "" { log.WithFields(fields).Info("Trying fallback Account Service for partner retrieval") From 4d04e0b5c8e69bf8dee08b9d128ccd4e93fd6529 Mon Sep 17 00:00:00 2001 From: RahulRengeshOfficial Date: Tue, 30 Dec 2025 11:29:24 +0530 Subject: [PATCH 08/10] Update feature_control_context.go --- dataapi/feature_control_context.go | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/dataapi/feature_control_context.go b/dataapi/feature_control_context.go index d9db0fb7..dc73b136 100644 --- a/dataapi/feature_control_context.go +++ b/dataapi/feature_control_context.go @@ -142,6 +142,9 @@ func getPartnerFromAccountDataService(ws *xhttp.XconfServer, contextMap map[stri // Remove colons from MAC for XAC call macValueWithoutColons := strings.ReplaceAll(macValue, ":", "") + // Debug: show which MAC we're using and values in contextMap + log.WithFields(fields).Infof("[DEBUG] getPartnerFromAccountDataService: selected macValue='%s', stripped='%s', context.ECM_MAC='%s', context.ECM_MAC_ADDRESS='%s', context.ESTB_MAC_ADDRESS='%s'", macValue, macValueWithoutColons, contextMap[common.ECM_MAC], contextMap[common.ECM_MAC_ADDRESS], contextMap[common.ESTB_MAC_ADDRESS]) + // Call XAC to get AccountId xAccountId, err := ws.GroupServiceConnector.GetAccountIdData(macValueWithoutColons, fields) if err != nil { @@ -201,14 +204,18 @@ func AddContextForPods(ws *xhttp.XconfServer, contextMap map[string]string, satT tfields := common.FilterLogFields(fields) - if Xc.EnableMacAccountServiceCall && strings.HasPrefix(strings.ToUpper(contextMap[common.SERIAL_NUM]), Xc.AccountServiceMacPrefix) { - // Remove colons from ecmMacAddress before sending to XAC - if ecmMac, ok := contextMap[common.ECM_MAC]; ok && ecmMac != "" { - contextMap[common.ECM_MAC] = strings.ReplaceAll(ecmMac, ":", "") - } - log.WithFields(tfields).Infof("Trying XAC/ADA for partner retrieval using serialum='%s' and contextMap[common.ECM_MAC]='%s'", contextMap[common.SERIAL_NUM], contextMap[common.ECM_MAC]) - // Try XAC → ADA flow first if enabled + // Debug: dump MAC fields and relevant config flags at function entry + log.WithFields(tfields).Infof("[DEBUG] AddContextForPods entry: SERIAL_NUM='%s', MODEL='%s', ECM_MAC='%s', ECM_MAC_ADDRESS='%s', ESTB_MAC_ADDRESS='%s', EnableMacAccountServiceCall=%t, EnableAccountDataService=%t", contextMap[common.SERIAL_NUM], contextMap[common.MODEL], contextMap[common.ECM_MAC], contextMap[common.ECM_MAC_ADDRESS], contextMap[common.ESTB_MAC_ADDRESS], Xc.EnableMacAccountServiceCall, Xc.EnableAccountDataService) + + if Xc.EnableMacAccountServiceCall && strings.HasPrefix(strings.ToUpper(contextMap[common.SERIAL_NUM]), Xc.AccountServiceMacPrefix) { + // Remove colons from ecmMacAddress before sending to XAC + if ecmMac, ok := contextMap[common.ECM_MAC]; ok && ecmMac != "" { + contextMap[common.ECM_MAC] = strings.ReplaceAll(ecmMac, ":", "") + } + log.WithFields(tfields).Infof("Trying XAC/ADA for partner retrieval using serialum='%s' and contextMap[common.ECM_MAC]='%s'", contextMap[common.SERIAL_NUM], contextMap[common.ECM_MAC]) + // Try XAC → ADA flow first if enabled if Xc.EnableAccountDataService { + log.WithFields(tfields).Infof("Trying XAC/ADA for partner retrieval using serialum='%s'", contextMap[common.SERIAL_NUM]) podData, td = getPartnerFromAccountDataService(ws, contextMap, fields) if podData != nil && podData.AccountId != "" { if util.IsUnknownValue(contextMap[common.ACCOUNT_ID]) && podData.AccountId != "" { @@ -412,7 +419,14 @@ func AddFeatureControlContextFromAccountService(ws *xhttp.XconfServer, contextMa } } else if Xc.EnableAccountDataService { if util.IsValidMacAddress(contextMap[common.ESTB_MAC_ADDRESS]) || util.IsValidMacAddress(contextMap[common.ECM_MAC_ADDRESS]) { - xboAccount, err := ws.GroupServiceConnector.GetAccountIdData(contextMap[common.ECM_MAC_ADDRESS], fields) + // Normalize MAC (remove colons) before calling XAC + macForXac := contextMap[common.ECM_MAC_ADDRESS] + if macForXac == "" { + macForXac = contextMap[common.ESTB_MAC_ADDRESS] + } + macForXacStripped := strings.ReplaceAll(macForXac, ":", "") + log.WithFields(fields).Infof("[DEBUG] AddFeatureControlContextFromAccountService: calling GetAccountIdData with mac='%s' (stripped='%s')", macForXac, macForXacStripped) + xboAccount, err := ws.GroupServiceConnector.GetAccountIdData(macForXacStripped, fields) if err != nil { log.WithFields(log.Fields{"error": err}).Error("Error getting accountId information") xhttp.IncreaseAccountServiceEmptyResponseCounter(contextMap[common.MODEL]) From 7b4a47d11ac744bf959997cb04e495501898d0da Mon Sep 17 00:00:00 2001 From: RahulRengeshOfficial Date: Tue, 30 Dec 2025 12:01:57 +0530 Subject: [PATCH 09/10] Update estb_firmware_context.go --- dataapi/estb_firmware_context.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/dataapi/estb_firmware_context.go b/dataapi/estb_firmware_context.go index 7103ad5a..60951b09 100644 --- a/dataapi/estb_firmware_context.go +++ b/dataapi/estb_firmware_context.go @@ -221,7 +221,7 @@ func AddEstbFirmwareContext(ws *xhttp.XconfServer, r *http.Request, contextMap m fields = log.Fields{} } log.Debug(fmt.Sprintf("AddEstbFirmwareContext start ... contextMap %v", contextMap)) - // No normalization, use contextMap[common.ESTB_MAC] directly + NormalizeEstbFirmwareContext(ws, r, contextMap, usePartnerAppType, shouldAddIp, fields) AddGroupServiceContext(ws, contextMap, common.ESTB_MAC, fields) // getting local sat token localToken, err := xhttp.GetLocalSatToken(fields) @@ -240,15 +240,26 @@ func AddEstbFirmwareContext(ws *xhttp.XconfServer, r *http.Request, contextMap m } else if Xc.EnableAccountDataService { // Only call XAC/ADA if partner is unknown or empty if util.IsUnknownValue(contextMap[common.PARTNER_ID]) || contextMap[common.PARTNER_ID] == "" { - // Use contextMap[common.ESTB_MAC] directly for MAC - macValue := contextMap[common.ESTB_MAC] - log.WithFields(fields).Info(fmt.Sprintf("Trying XAC/ADA for partner retrieval using MAC='%s'", macValue)) + // Try ECM MAC first, then fall back to ESTB MAC + // MACs are already normalized and validated at the start of the function + var macValue string + if contextMap[common.ECM_MAC] != "" { + macValue = contextMap[common.ECM_MAC] + } else if contextMap[common.ECM_MAC_PARAM] != "" { + macValue = contextMap[common.ECM_MAC_PARAM] + } else if contextMap[common.ESTB_MAC] != "" { + macValue = contextMap[common.ESTB_MAC] + } + if macValue != "" { + // Remove colons from MAC for XAC call macValueWithoutColons := strings.ReplaceAll(macValue, ":", "") + xAccountId, err := ws.GroupServiceConnector.GetAccountIdData(macValueWithoutColons, fields) if err != nil { log.WithFields(fields).Warn(fmt.Sprintf("XAC call failed for MAC='%s': %v", macValueWithoutColons, err)) } + if xAccountId != nil && xAccountId.GetAccountId() != "" { accountId := xAccountId.GetAccountId() accountProducts, err := ws.GroupServiceConnector.GetAccountProducts(accountId, fields) @@ -262,6 +273,7 @@ func AddEstbFirmwareContext(ws *xhttp.XconfServer, r *http.Request, contextMap m } } } + // Fallback to old Account Service logic if XAC/ADA didn't return partner if util.IsUnknownValue(contextMap[common.PARTNER_ID]) || contextMap[common.PARTNER_ID] == "" { log.WithFields(fields).Info("Trying fallback Account Service for partner retrieval") From 2841c8e85639bad52766d285cd07dcf87065b6a4 Mon Sep 17 00:00:00 2001 From: gravi21 Date: Wed, 31 Dec 2025 17:14:20 +0530 Subject: [PATCH 10/10] Addressing few issues --- dataapi/estb_firmware_context.go | 16 ++-------- dataapi/feature_control_context.go | 49 +++++++++--------------------- 2 files changed, 17 insertions(+), 48 deletions(-) diff --git a/dataapi/estb_firmware_context.go b/dataapi/estb_firmware_context.go index 60951b09..c2357cf1 100644 --- a/dataapi/estb_firmware_context.go +++ b/dataapi/estb_firmware_context.go @@ -240,24 +240,14 @@ func AddEstbFirmwareContext(ws *xhttp.XconfServer, r *http.Request, contextMap m } else if Xc.EnableAccountDataService { // Only call XAC/ADA if partner is unknown or empty if util.IsUnknownValue(contextMap[common.PARTNER_ID]) || contextMap[common.PARTNER_ID] == "" { - // Try ECM MAC first, then fall back to ESTB MAC - // MACs are already normalized and validated at the start of the function - var macValue string - if contextMap[common.ECM_MAC] != "" { - macValue = contextMap[common.ECM_MAC] - } else if contextMap[common.ECM_MAC_PARAM] != "" { - macValue = contextMap[common.ECM_MAC_PARAM] - } else if contextMap[common.ESTB_MAC] != "" { - macValue = contextMap[common.ESTB_MAC] - } - + macValue := contextMap[common.ESTB_MAC] if macValue != "" { // Remove colons from MAC for XAC call macValueWithoutColons := strings.ReplaceAll(macValue, ":", "") xAccountId, err := ws.GroupServiceConnector.GetAccountIdData(macValueWithoutColons, fields) if err != nil { - log.WithFields(fields).Warn(fmt.Sprintf("XAC call failed for MAC='%s': %v", macValueWithoutColons, err)) + log.WithFields(fields).Warn(fmt.Sprintf("XAC call failed for MAC='%s': %v", macValue, err)) } if xAccountId != nil && xAccountId.GetAccountId() != "" { @@ -275,7 +265,7 @@ func AddEstbFirmwareContext(ws *xhttp.XconfServer, r *http.Request, contextMap m } // Fallback to old Account Service logic if XAC/ADA didn't return partner - if util.IsUnknownValue(contextMap[common.PARTNER_ID]) || contextMap[common.PARTNER_ID] == "" { + if util.IsUnknownValue(contextMap[common.PARTNER_ID]) { log.WithFields(fields).Info("Trying fallback Account Service for partner retrieval") partnerId := GetPartnerFromAccountServiceByHostMac(ws, contextMap[common.ESTB_MAC], satToken, fields) if partnerId != "" { diff --git a/dataapi/feature_control_context.go b/dataapi/feature_control_context.go index dc73b136..61f35579 100644 --- a/dataapi/feature_control_context.go +++ b/dataapi/feature_control_context.go @@ -122,28 +122,16 @@ func getPartnerFromAccountDataService(ws *xhttp.XconfServer, contextMap map[stri var podData *PodData var td *AccountServiceData - // Skip XAC/ADA if partner already known - if !util.IsUnknownValue(contextMap[common.PARTNER_ID]) && contextMap[common.PARTNER_ID] != "" { - return nil, nil - } - // Try ECM MAC first, then fall back to ESTB MAC - var macValue string - if util.IsValidMacAddress(contextMap[common.ECM_MAC_ADDRESS]) { - macValue = contextMap[common.ECM_MAC_ADDRESS] - } else if util.IsValidMacAddress(contextMap[common.ESTB_MAC_ADDRESS]) { - macValue = contextMap[common.ESTB_MAC_ADDRESS] - } - - if macValue == "" { - return nil, nil + var macAddress string + if util.IsValidMacAddress(contextMap[common.ESTB_MAC_ADDRESS]) { + macAddress = util.GetEcmMacAddress(util.AlphaNumericMacAddress(strings.TrimSpace(contextMap[common.ESTB_MAC_ADDRESS]))) + } else if util.IsValidMacAddress(contextMap[common.ECM_MAC_ADDRESS]) { + macAddress = contextMap[common.ECM_MAC_ADDRESS] } // Remove colons from MAC for XAC call - macValueWithoutColons := strings.ReplaceAll(macValue, ":", "") - - // Debug: show which MAC we're using and values in contextMap - log.WithFields(fields).Infof("[DEBUG] getPartnerFromAccountDataService: selected macValue='%s', stripped='%s', context.ECM_MAC='%s', context.ECM_MAC_ADDRESS='%s', context.ESTB_MAC_ADDRESS='%s'", macValue, macValueWithoutColons, contextMap[common.ECM_MAC], contextMap[common.ECM_MAC_ADDRESS], contextMap[common.ESTB_MAC_ADDRESS]) + macValueWithoutColons := strings.ReplaceAll(macAddress, ":", "") // Call XAC to get AccountId xAccountId, err := ws.GroupServiceConnector.GetAccountIdData(macValueWithoutColons, fields) @@ -204,18 +192,8 @@ func AddContextForPods(ws *xhttp.XconfServer, contextMap map[string]string, satT tfields := common.FilterLogFields(fields) - // Debug: dump MAC fields and relevant config flags at function entry - log.WithFields(tfields).Infof("[DEBUG] AddContextForPods entry: SERIAL_NUM='%s', MODEL='%s', ECM_MAC='%s', ECM_MAC_ADDRESS='%s', ESTB_MAC_ADDRESS='%s', EnableMacAccountServiceCall=%t, EnableAccountDataService=%t", contextMap[common.SERIAL_NUM], contextMap[common.MODEL], contextMap[common.ECM_MAC], contextMap[common.ECM_MAC_ADDRESS], contextMap[common.ESTB_MAC_ADDRESS], Xc.EnableMacAccountServiceCall, Xc.EnableAccountDataService) - if Xc.EnableMacAccountServiceCall && strings.HasPrefix(strings.ToUpper(contextMap[common.SERIAL_NUM]), Xc.AccountServiceMacPrefix) { - // Remove colons from ecmMacAddress before sending to XAC - if ecmMac, ok := contextMap[common.ECM_MAC]; ok && ecmMac != "" { - contextMap[common.ECM_MAC] = strings.ReplaceAll(ecmMac, ":", "") - } - log.WithFields(tfields).Infof("Trying XAC/ADA for partner retrieval using serialum='%s' and contextMap[common.ECM_MAC]='%s'", contextMap[common.SERIAL_NUM], contextMap[common.ECM_MAC]) - // Try XAC → ADA flow first if enabled if Xc.EnableAccountDataService { - log.WithFields(tfields).Infof("Trying XAC/ADA for partner retrieval using serialum='%s'", contextMap[common.SERIAL_NUM]) podData, td = getPartnerFromAccountDataService(ws, contextMap, fields) if podData != nil && podData.AccountId != "" { if util.IsUnknownValue(contextMap[common.ACCOUNT_ID]) && podData.AccountId != "" { @@ -419,14 +397,15 @@ func AddFeatureControlContextFromAccountService(ws *xhttp.XconfServer, contextMa } } else if Xc.EnableAccountDataService { if util.IsValidMacAddress(contextMap[common.ESTB_MAC_ADDRESS]) || util.IsValidMacAddress(contextMap[common.ECM_MAC_ADDRESS]) { - // Normalize MAC (remove colons) before calling XAC - macForXac := contextMap[common.ECM_MAC_ADDRESS] - if macForXac == "" { - macForXac = contextMap[common.ESTB_MAC_ADDRESS] + var macAddress string + if contextMap[common.ESTB_MAC_ADDRESS] != "" { + macAddress = util.GetEcmMacAddress(util.AlphaNumericMacAddress(strings.TrimSpace(contextMap[common.ESTB_MAC_ADDRESS]))) + } else { + macAddress = contextMap[common.ECM_MAC_ADDRESS] } - macForXacStripped := strings.ReplaceAll(macForXac, ":", "") - log.WithFields(fields).Infof("[DEBUG] AddFeatureControlContextFromAccountService: calling GetAccountIdData with mac='%s' (stripped='%s')", macForXac, macForXacStripped) - xboAccount, err := ws.GroupServiceConnector.GetAccountIdData(macForXacStripped, fields) + // Normalize MAC (remove colons) before calling XAC + macValue := strings.ReplaceAll(macAddress, ":", "") + xboAccount, err := ws.GroupServiceConnector.GetAccountIdData(macValue, fields) if err != nil { log.WithFields(log.Fields{"error": err}).Error("Error getting accountId information") xhttp.IncreaseAccountServiceEmptyResponseCounter(contextMap[common.MODEL])