Skip to content

Commit

Permalink
Merge pull request #873 from fledge-iot/2.0.1RC
Browse files Browse the repository at this point in the history
2.0.1RC Update
  • Loading branch information
Mohit04tomar authored Nov 4, 2022
2 parents a791263 + 833c93c commit 3132fef
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 39 deletions.
27 changes: 15 additions & 12 deletions C/common/management_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) << "\", ";
Expand All @@ -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());
Expand All @@ -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__,
Expand Down
43 changes: 29 additions & 14 deletions C/services/south/ingest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> 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)
{
Expand All @@ -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);
Expand All @@ -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"));
Expand All @@ -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());
}
}
}
Expand Down
30 changes: 17 additions & 13 deletions python/fledge/services/core/api/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3132fef

Please sign in to comment.