diff --git a/C/common/management_client.cpp b/C/common/management_client.cpp index e871cbd46c..bb732fb6df 100644 --- a/C/common/management_client.cpp +++ b/C/common/management_client.cpp @@ -1742,13 +1742,16 @@ bool ManagementClient::addStorageAssetTrackingTuple(const std::string& service, const int& count) { ostringstream convert; - - std::string d = datapoints; - for ( int i = 0; i < datapoints.size(); ++i) - { - if (d[i] == ',') d.insert(i, "\",\"" ); - i = i+2; - } + std::string d ; + for ( int i = 0; i < datapoints.size(); ++i) + { + if (datapoints[i] == ',') + { + d.append("\",\""); + } + else + d.append(1,datapoints[i]); + } try { convert << "{ \"service\" : \"" << JSONescape(service) << "\", "; @@ -1760,6 +1763,11 @@ bool ManagementClient::addStorageAssetTrackingTuple(const std::string& service, convert << " \"count\" : " << count << " } }"; auto res = this->getHttpClient()->request("POST", "/fledge/track", convert.str()); + if (res->status_code[0] == '2') // A 2xx response + { + return true; + } + Document doc; string content = res->content.string(); doc.Parse(content.c_str()); @@ -1771,11 +1779,6 @@ bool ManagementClient::addStorageAssetTrackingTuple(const std::string& service, content.c_str()); return false; } - if (doc.HasMember("fledge")) - { - const char *reg_id = doc["fledge"].GetString(); - return true; - } else if (doc.HasMember("message")) { m_logger->error("%s:%d Failed to add storage asset tracking tuple: %s.",__FUNCTION__, __LINE__, diff --git a/C/services/south/ingest.cpp b/C/services/south/ingest.cpp index cd1a6c034b..978f5a593d 100755 --- a/C/services/south/ingest.cpp +++ b/C/services/south/ingest.cpp @@ -1201,11 +1201,27 @@ void Ingest::unDeprecateStorageAssetTrackingRecord(StorageAssetTrackingTuple* cu datapoints, count); - std::string data = "{\"datapoints\":["; - data.append(datapoints); - data.append("],\"count\":"); - data.append(to_string(count)); - data.append("}"); + vector tokens; + stringstream dpStringStream(datapoints); + string temp; + while(getline(dpStringStream, temp, ',')) + { + tokens.push_back(temp); + } + + ostringstream convert; + convert << "{"; + convert << "\"datapoints\":["; + for (unsigned int i = 0; i < tokens.size() ; ++i) + { + convert << "\"" << tokens[i].c_str() << "\"" ; + if (i < tokens.size()-1){ + convert << ","; + } + } + convert << "]," ; + convert << "\"count\":" << to_string(count).c_str(); + convert << "}"; if (updatedTuple) { @@ -1215,8 +1231,7 @@ void Ingest::unDeprecateStorageAssetTrackingRecord(StorageAssetTrackingTuple* cu // Update un-deprecated state in cached object currentTuple->unDeprecate(); - m_logger->error(" storage Asset '%s' is being un-deprecated", - assetName.c_str()); + m_logger->info("%s:%d, Asset '%s' is being un-deprecated",__FILE__, __LINE__, assetName.c_str()); // Prepare UPDATE query const Condition conditionParams(Equals); @@ -1231,12 +1246,14 @@ void Ingest::unDeprecateStorageAssetTrackingRecord(StorageAssetTrackingTuple* cu conditionParams, "store", wService); + Where *wData = new Where("data", - conditionParams, - data, - wEvent); + conditionParams, + JSONescape(convert.str()), + wEvent); + - InsertValues unDeprecated; + InsertValues unDeprecated; // Set NULL value unDeprecated.push_back(InsertValue("deprecated_ts")); @@ -1246,12 +1263,10 @@ void Ingest::unDeprecateStorageAssetTrackingRecord(StorageAssetTrackingTuple* cu unDeprecated, *wData); - // Check update operation if (rv < 0) { - m_logger->error("Failure while un-deprecating asset '%s'", - assetName.c_str()); + m_logger->error("%s:%d, Failure while un-deprecating asset '%s'", __FILE__, __LINE__, assetName.c_str()); } } } diff --git a/python/fledge/services/core/api/configuration.py b/python/fledge/services/core/api/configuration.py index b5b979d34e..3835bf2622 100644 --- a/python/fledge/services/core/api/configuration.py +++ b/python/fledge/services/core/api/configuration.py @@ -250,12 +250,13 @@ async def set_configuration_item(request): WHEN: if non-admin user is trying to update THEN: 403 Forbidden case """ - if request.user and (category_name == 'rest_api' and config_item == 'authentication'): - if not request.user_is_admin: - msg = "Admin role permissions required to change the {} value for category {}.".format( - config_item, category_name) - _logger.warning(msg) - raise web.HTTPForbidden(reason=msg, body=json.dumps({"message": msg})) + if hasattr(request, "user"): + if request.user and (category_name == 'rest_api' and config_item == 'authentication'): + if not request.user_is_admin: + msg = "Admin role permissions required to change the {} value for category {}.".format( + config_item, category_name) + _logger.warning(msg) + raise web.HTTPForbidden(reason=msg, body=json.dumps({"message": msg})) data = await request.json() cf_mgr = ConfigurationManager(connect.get_storage_async()) @@ -326,13 +327,16 @@ async def update_configuration_item_bulk(request): WHEN: if non-admin user is trying to update THEN: 403 Forbidden case """ - config_items = [k for k, v in data.items() if k == 'authentication'] - if request.user and (category_name == 'rest_api' and config_items): - if not request.user_is_admin: - msg = "Admin role permissions required to change the authentication value for category {}.".format( - category_name) - _logger.warning(msg) - return web.HTTPForbidden(reason=msg, body=json.dumps({"message": msg})) + + + if hasattr(request, "user"): + config_items = [k for k, v in data.items() if k == 'authentication'] + if request.user and (category_name == 'rest_api' and config_items): + if not request.user_is_admin: + msg = "Admin role permissions required to change the authentication value for category {}.".format( + category_name) + _logger.warning(msg) + return web.HTTPForbidden(reason=msg, body=json.dumps({"message": msg})) cf_mgr = ConfigurationManager(connect.get_storage_async()) try: is_core_mgt = request.is_core_mgt