diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 8240b5b1ef..9bde859a90 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -6,6 +6,7 @@ * Support for the URL parameter 'orderBy' (must be an attribute) in GET //ngsi-ld/v1/entities, but only if 'local' is set. (This is not NGSI-LD standard. Yet ...) - Also supporting sorting on entity id, type, and modifiedAt - One more URL parameter '?reverse=true' to reverse the sorting order + * Rudimentary support for GET /info/sourceIdentity ## Notes * Lots of improvements for subordinate subscriptions - still not 100% ready, but a lot better. diff --git a/src/app/orionld/orionldRestServices.cpp b/src/app/orionld/orionldRestServices.cpp index 5b66ddea36..c18be9b573 100644 --- a/src/app/orionld/orionldRestServices.cpp +++ b/src/app/orionld/orionldRestServices.cpp @@ -69,6 +69,7 @@ #include "orionld/serviceRoutines/orionldPutAttribute.h" #include "orionld/serviceRoutines/orionldGetEntityMap.h" #include "orionld/serviceRoutines/orionldDeleteEntityMap.h" +#include "orionld/serviceRoutines/orionldGetInfo.h" #include "orionld/serviceRoutines/orionldGetTemporalEntities.h" #include "orionld/serviceRoutines/orionldGetTemporalEntity.h" @@ -105,6 +106,7 @@ static OrionLdRestServiceSimplified getServiceV[] = { "/ngsi-ld/v1/csourceRegistrations", orionldGetRegistrations }, { "/ngsi-ld/v1/jsonldContexts/*", orionldGetContext }, { "/ngsi-ld/v1/jsonldContexts", orionldGetContexts }, + { "/ngsi-ld/v1/info/sourceIdentity", orionldGetInfo }, { "/ngsi-ld/v1/temporal/entities/*", orionldGetTemporalEntity }, { "/ngsi-ld/v1/temporal/entities", orionldGetTemporalEntities }, { "/ngsi-ld/ex/v1/version", orionldGetVersion }, diff --git a/src/lib/orionld/serviceRoutines/CMakeLists.txt b/src/lib/orionld/serviceRoutines/CMakeLists.txt index 6929239bf3..06754f64fc 100644 --- a/src/lib/orionld/serviceRoutines/CMakeLists.txt +++ b/src/lib/orionld/serviceRoutines/CMakeLists.txt @@ -78,6 +78,7 @@ SET (SOURCES orionldPatchTemporalAttributeInstance.cpp orionldPostTemporalAttributes.cpp orionldDeleteEntities.cpp + orionldGetInfo.cpp ) # Include directories diff --git a/src/lib/orionld/serviceRoutines/orionldGetInfo.cpp b/src/lib/orionld/serviceRoutines/orionldGetInfo.cpp new file mode 100644 index 0000000000..a1a9d1332e --- /dev/null +++ b/src/lib/orionld/serviceRoutines/orionldGetInfo.cpp @@ -0,0 +1,71 @@ +/* +* +* Copyright 2024 FIWARE Foundation e.V. +* +* This file is part of Orion-LD Context Broker. +* +* Orion-LD Context Broker is free software: you can redistribute it and/or +* modify it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* Orion-LD Context Broker is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero +* General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with Orion-LD Context Broker. If not, see http://www.gnu.org/licenses/. +* +* For those usages not covered by this license please contact with +* orionld at fiware dot org +* +* Author: Ken Zangelin +*/ +extern "C" +{ +#include "kjson/KjNode.h" // KjNode +#include "kjson/kjBuilder.h" // kjObject, kjString, kjBoolean, ... +} + +#include "logMsg/logMsg.h" // LM_* + +#include "orionld/common/orionldState.h" // orionldState +#include "orionld/serviceRoutines/orionldGetInfo.h" // Own Interface + + + +// ---------------------------------------------------------------------------- +// +// orionldGetInfo - +// +bool orionldGetInfo(void) +{ + static int runNo = 1; + char id[128]; + + snprintf(id, sizeof(id) - 1, "urn:ngsi-ld:cs:%06d", runNo); + ++runNo; + + KjNode* infoP = kjObject(orionldState.kjsonP, NULL); + KjNode* idP = kjString(orionldState.kjsonP, "id", id); + KjNode* typeP = kjString(orionldState.kjsonP, "type", "ContextSourceIdentity"); + KjNode* aliasP = kjString(orionldState.kjsonP, "contextSourceAlias", brokerId); + + kjChildAdd(infoP, idP); + kjChildAdd(infoP, typeP); + kjChildAdd(infoP, aliasP); + + orionldState.responseTree = infoP; + + // This request is ALWAYS returned with pretty-print + orionldState.uriParams.prettyPrint = true; + orionldState.kjsonP->spacesPerIndent = 2; + orionldState.kjsonP->nlString = (char*) "\n"; + orionldState.kjsonP->stringBeforeColon = (char*) ""; + orionldState.kjsonP->stringAfterColon = (char*) " "; + + orionldState.noLinkHeader = true; // We don't want the Link header for version requests + + return true; +} diff --git a/src/lib/orionld/serviceRoutines/orionldGetInfo.h b/src/lib/orionld/serviceRoutines/orionldGetInfo.h new file mode 100644 index 0000000000..c468e97b9e --- /dev/null +++ b/src/lib/orionld/serviceRoutines/orionldGetInfo.h @@ -0,0 +1,37 @@ +#ifndef SRC_LIB_ORIONLD_SERVICEROUTINES_ORIONLDGETINFO_H_ +#define SRC_LIB_ORIONLD_SERVICEROUTINES_ORIONLDGETINFO_H_ + +/* +* +* Copyright 2022 FIWARE Foundation e.V. +* +* This file is part of Orion-LD Context Broker. +* +* Orion-LD Context Broker is free software: you can redistribute it and/or +* modify it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* Orion-LD Context Broker is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero +* General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with Orion-LD Context Broker. If not, see http://www.gnu.org/licenses/. +* +* For those usages not covered by this license please contact with +* orionld at fiware dot org +* +* Author: Ken Zangelin +*/ + + + +// ---------------------------------------------------------------------------- +// +// orionldGetInfo - +// +extern bool orionldGetInfo(void); + +#endif // SRC_LIB_ORIONLD_SERVICEROUTINES_ORIONLDGETINFO_H_ diff --git a/src/lib/orionld/serviceRoutines/orionldGetVersion.cpp b/src/lib/orionld/serviceRoutines/orionldGetVersion.cpp index 7897d7c986..2fb04bbe97 100644 --- a/src/lib/orionld/serviceRoutines/orionldGetVersion.cpp +++ b/src/lib/orionld/serviceRoutines/orionldGetVersion.cpp @@ -44,7 +44,6 @@ extern "C" #include "kjson/kjBuilder.h" // kjObject, kjString, kjBoolean, ... } - #include "logMsg/logMsg.h" // LM_* #include "cache/subCache.h" // subCacheItems diff --git a/test/functionalTest/cases/0000_ngsild/ngsild_get_info.test b/test/functionalTest/cases/0000_ngsild/ngsild_get_info.test new file mode 100644 index 0000000000..101c1fd47d --- /dev/null +++ b/test/functionalTest/cases/0000_ngsild/ngsild_get_info.test @@ -0,0 +1,60 @@ +# Copyright 2024 FIWARE Foundation e.V. +# +# This file is part of Orion-LD Context Broker. +# +# Orion-LD Context Broker is free software: you can redistribute it and/or +# modify it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# Orion-LD Context Broker is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero +# General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Orion-LD Context Broker. If not, see http://www.gnu.org/licenses/. +# +# For those usages not covered by this license please contact with +# orionld at fiware dot org + +# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh + +--NAME-- +Test of orionld version service, with branch name + +--SHELL-INIT-- +dbInit CB +orionldStart CB -troe -brokerId urn:B1 -experimental + +--SHELL-- + +# +# 01. GET /ngsi-ld/v1/info/sourceIdentity +# + +echo "01. GET /ngsi-ld/info/sourceIdentity" +echo "====================================" +orionCurl --url /ngsi-ld/v1/info/sourceIdentity +echo +echo + + +--REGEXPECT-- +01. GET /ngsi-ld/info/sourceIdentity +==================================== +HTTP/1.1 200 OK +Content-Length: 105 +Content-Type: application/json +Date: REGEX(.*) + +{ + "contextSourceAlias": "urn:B1", + "id": "urn:ngsi-ld:cs:000001", + "type": "ContextSourceIdentity" +} + + +--TEARDOWN-- +brokerStop CB +dbDrop CB