From 03701b5422b73b47d6840305860f9247c2d8c3a6 Mon Sep 17 00:00:00 2001 From: Sylvain Renault Date: Thu, 5 Sep 2024 13:20:59 +0200 Subject: [PATCH 1/3] Implementation of the new API (generator issues). --- openapi | 2 +- .../RelocalizationInformationImpl.cs | 33 ++++++++++--------- .../ControllersImpl/TrackablesImpl.cs | 14 ++++---- .../ControllersImpl/WorldAnchorsImpl.cs | 14 ++++---- .../ControllersImpl/WorldLinksImpl.cs | 14 ++++---- .../ETSI-ARF/Services/TrackableService.cs | 2 +- .../ETSI-ARF/Services/WorldAnchorService.cs | 2 +- .../ETSI-ARF/Services/WorldLinkService.cs | 2 +- .../ETSI.ARF.OpenAPI.WorldStorage/Startup.cs | 2 +- 9 files changed, 43 insertions(+), 42 deletions(-) diff --git a/openapi b/openapi index 073fd72..b639a02 160000 --- a/openapi +++ b/openapi @@ -1 +1 @@ -Subproject commit 073fd7213fd9e6ebc2f8a47d628a650de30c8bc4 +Subproject commit b639a02180c2b5e301c77483b3a2fa645ba94169 diff --git a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/RelocalizationInformationImpl.cs b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/RelocalizationInformationImpl.cs index 9a377b3..02a0058 100644 --- a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/RelocalizationInformationImpl.cs +++ b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/RelocalizationInformationImpl.cs @@ -52,13 +52,14 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers /// Operation to retrieve all the relocalization information of one or severals WorldAnchors or Trackables. /// /// - public override IActionResult GetRelocalizationInformation([FromQuery(Name = "uuids")][Required()] List uuids, [FromQuery(Name = "capabilities")][Required()] List capabilities, [FromHeader(Name = "token")] string token) + // old: public override IActionResult GetRelocalizationInformation([FromQuery(Name = "uuids")][Required()] List uuids, [FromQuery(Name = "capabilities")][Required()] List capabilities, [FromHeader(Name = "token")] string token) + public override IActionResult GetRelocalizationInformation([FromQuery(Name = "uuids")][Required()] List uuids, [FromQuery(Name = "capabilities")][Required()] List capabilities, [FromHeader(Name = "token")] string token) { WorldAnchorService _worldAnchorService = WorldAnchorService.Singleton as WorldAnchorService; TrackableService _trackableService = TrackableService.Singleton as TrackableService; var history = new List(); - var result = new GetRelocalizationInformation200Response(); + var result = new RelocalizationInformations(); result.RelocInfo = new List(); foreach (var request in uuids) @@ -88,18 +89,18 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers else if (trackable != null) { history.Add(trackable.UUID); - + Matrix4x4 matrix = Matrix4x4.Identity; var relocalizationInformation = new RelocalizationInformation(); relocalizationInformation.RequestUUID = trackable.UUID; relocalizationInformation.RequestType = TypeWorldStorage.TRACKABLEEnum; - relocalizationInformation.RelocObjects = new List(); + relocalizationInformation.RelocObjects = new List(); if (trackable.Match(capabilities)) { // add itself with matrix identity as Transform3D - var itself = new RelocalizationInformationRelocObjectsInner(); + var itself = new RelocObject(); itself.Trackable = trackable; itself.Mode = request.Mode; itself.Transform3D = new List() @@ -122,12 +123,12 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers } } - return result.RelocInfo.Count > 0 ? new ObjectResult(result) : StatusCode(404, "Not found, could not find UUID in database."); + return result.RelocInfo.Count > 0 ? new ObjectResult(result) : StatusCode(404, new Error() { Message = "Not found, could not find UUID in database." }); } - private List FindRelocInfo(Guid targetUUID, ModeWorldStorage mode, Matrix4x4 matrix, List capabilities, ref List history) + private List FindRelocInfo(Guid targetUUID, ModeWorldStorage mode, Matrix4x4 matrix, List capabilities, ref List history) { - var results = new List(); + var results = new List(); results.AddRange(FindRelocInfoAsTo(targetUUID, mode, matrix, capabilities, ref history)); results.AddRange(FindRelocInfoAsFrom(targetUUID, mode, matrix, capabilities, ref history)); @@ -136,13 +137,13 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers } // Check links where the target UUID appeared as "To" - private List FindRelocInfoAsTo(Guid targetUUID, ModeWorldStorage mode, Matrix4x4 matrix, List capabilities, ref List history) + private List FindRelocInfoAsTo(Guid targetUUID, ModeWorldStorage mode, Matrix4x4 matrix, List capabilities, ref List history) { TrackableService _trackableService = TrackableService.Singleton as TrackableService; WorldAnchorService _worldAnchorService = WorldAnchorService.Singleton as WorldAnchorService; WorldLinkService _worldLinkService = WorldLinkService.Singleton as WorldLinkService; - var results = new List(); + var results = new List(); // Check links where the target UUID appeared as "To" List linksTo; @@ -199,7 +200,7 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers } // We found a valid trackable, add it to the results - var result = new RelocalizationInformationRelocObjectsInner(); + var result = new RelocObject(); result.Trackable = trackable; result.Mode = mode; result.Transform3D = new List() @@ -226,9 +227,9 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers if (anchor != null) { - + Matrix4x4 m; - m = link.Matrix()*matrix; + m = link.Matrix() * matrix; if (mode == ModeWorldStorage.REQUESTTOTRACKABLESEnum) { @@ -272,13 +273,13 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers } // Check links where the target UUID appeared as "From" - private List FindRelocInfoAsFrom(Guid targetUUID, ModeWorldStorage mode, Matrix4x4 matrix, List capabilities, ref List history) + private List FindRelocInfoAsFrom(Guid targetUUID, ModeWorldStorage mode, Matrix4x4 matrix, List capabilities, ref List history) { TrackableService _trackableService = TrackableService.Singleton as TrackableService; WorldAnchorService _worldAnchorService = WorldAnchorService.Singleton as WorldAnchorService; WorldLinkService _worldLinkService = WorldLinkService.Singleton as WorldLinkService; - var results = new List(); + var results = new List(); // Check links where the anchor appeared as "From" List linksTo; @@ -335,7 +336,7 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers } // We found a valid trackable, add it to the results - var result = new RelocalizationInformationRelocObjectsInner(); + var result = new RelocObject(); result.Trackable = trackable; result.Mode = mode; result.Transform3D = new List() diff --git a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/TrackablesImpl.cs b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/TrackablesImpl.cs index f6c4bdc..7997e6c 100644 --- a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/TrackablesImpl.cs +++ b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/TrackablesImpl.cs @@ -75,13 +75,13 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers Trackable mytrackable = _trackableService.Create(trackable); if (mytrackable == null) { - return StatusCode(409, "UUID already existing!"); + return StatusCode(409, new Error() { Message = "UUID already existing!" }); } - else return StatusCode(200, mytrackable.UUID.ToString()); + else return StatusCode(200, new Error() { Message = mytrackable.UUID.ToString() }); } catch (Exception e) { - return StatusCode(400, e.Message); + return StatusCode(400, new Error() { Message = e.Message }); } } @@ -121,7 +121,7 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers { result += ", removed object was referenced in " + worldlinkinfo + " and removed there as well"; } - return (count > 0) ? new ObjectResult(result) : StatusCode(404, "Not found, could not find UUID in database."); + return (count > 0) ? new ObjectResult(result) : StatusCode(404, new Error() { Message = "Not found, could not find UUID in database." }); } /// @@ -130,7 +130,7 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers public override IActionResult GetTrackableById([FromRoute(Name = "trackableUUID")][Required] Guid trackableUUID, [FromHeader] string token) { Trackable trackable = _trackableService.Get(trackableUUID); - return (null != trackable) ? new ObjectResult(trackable) : StatusCode(404, "Not found, could not find UUID in database."); + return (null != trackable) ? new ObjectResult(trackable) : StatusCode(404, new Error() { Message = "Not found, could not find UUID in database." }); } /// @@ -152,11 +152,11 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers long count = _trackableService.Replace(trackable); if (count == 0) { - return StatusCode(404, "Not found, could not find UUID in database."); + return StatusCode(404, new Error() { Message = "Not found, could not find UUID in database." }); } else { - return StatusCode(200, trackable.UUID.ToString()); + return StatusCode(200, new Error() { Message = trackable.UUID.ToString() }); } } } diff --git a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/WorldAnchorsImpl.cs b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/WorldAnchorsImpl.cs index 0d66633..8d6b265 100644 --- a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/WorldAnchorsImpl.cs +++ b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/WorldAnchorsImpl.cs @@ -75,13 +75,13 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers WorldAnchor myworldanchor = _worldAnchorService.Create(worldAnchor); if (myworldanchor == null) { - return StatusCode(409, "UUID alread exexisting!"); + return StatusCode(409, new Error() { Message = "UUID alread exexisting!" }); } - else return StatusCode(200, myworldanchor.UUID.ToString()); + else return StatusCode(200, new Error() { Message = myworldanchor.UUID.ToString() }); } catch (Exception e) { - return StatusCode(400, e.Message); + return StatusCode(400, new Error() { Message = e.Message }); } } @@ -121,7 +121,7 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers { result += ", but removed object was referenced in " + worldlinkinfo + " and removed there as well"; } - return (count > 0) ? new ObjectResult(result) : StatusCode(404, "Not found, could not find UUID in database."); + return (count > 0) ? new ObjectResult(result) : StatusCode(404, new Error() { Message = "Not found, could not find UUID in database." }); } /// @@ -130,7 +130,7 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers public override IActionResult GetWorldAnchorById([FromRoute(Name = "worldAnchorUUID")][Required] Guid worldAnchorUUID, [FromHeader] string token) { WorldAnchor myworldanchor = _worldAnchorService.Get(worldAnchorUUID); - return (null != myworldanchor) ? new ObjectResult(myworldanchor) : StatusCode(404, "Not found, could not find UUID in database."); + return (null != myworldanchor) ? new ObjectResult(myworldanchor) : StatusCode(404, new Error() { Message = "Not found, could not find UUID in database." }); } /// @@ -152,11 +152,11 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers long count = _worldAnchorService.Replace(worldAnchor); if (count == 0) { - return StatusCode(404, "Not found, could not find UUID in database."); + return StatusCode(404, new Error() { Message = "Not found, could not find UUID in database." }); } else { - return StatusCode(200, worldAnchor.UUID.ToString()); + return StatusCode(200, new Error() { Message = worldAnchor.UUID.ToString() }); } } diff --git a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/WorldLinksImpl.cs b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/WorldLinksImpl.cs index 27ce36e..ef44865 100644 --- a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/WorldLinksImpl.cs +++ b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/WorldLinksImpl.cs @@ -74,13 +74,13 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers WorldLink myworldlink = _worldLinkService.Create(worldLink); if (myworldlink == null) { - return StatusCode(409, "UUID already existing!"); + return StatusCode(409, new Error() { Message = "UUID already existing!" }); } - else return StatusCode(200, myworldlink.UUID.ToString()); + else return StatusCode(200, new Error() { Message = myworldlink.UUID.ToString() }); } catch (Exception e) { - return StatusCode(400, e.Message); + return StatusCode(400, new Error() { Message = e.Message}); } } @@ -90,7 +90,7 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers public override IActionResult DeleteWorldLink([FromRoute(Name = "worldLinkUUID")][Required] Guid worldLinkUUID, [FromHeader] string token) { long count = _worldLinkService.Remove(worldLinkUUID); - return (count > 0) ? new ObjectResult("ok") : StatusCode(404, "Not found, could not find UUID in database."); + return (count > 0) ? new ObjectResult("ok") : StatusCode(404, new Error() { Message = "Not found, could not find UUID in database." }); } @@ -141,7 +141,7 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers } } } - return (null != myworldlink) ? new ObjectResult(myworldlink) : StatusCode(404, "Not found, could not find UUID in database."); + return (null != myworldlink) ? new ObjectResult(myworldlink) : StatusCode(404, new Error() { Message = "Not found, could not find UUID in database." }); } /// @@ -204,11 +204,11 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers long count = _worldLinkService.Replace(worldLink); if (count == 0) { - return StatusCode(404, "Not found, could not find UUID in database."); + return StatusCode(404, new Error() { Message = "Not found, could not find UUID in database." }); } else { - return StatusCode(200, worldLink.UUID.ToString()); + return StatusCode(200, new Error() { Message = worldLink.UUID.ToString() }); } } } diff --git a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/Services/TrackableService.cs b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/Services/TrackableService.cs index c7601cb..3b4fb58 100644 --- a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/Services/TrackableService.cs +++ b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/Services/TrackableService.cs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // -// Last change: June 2022 +// Last change: June 2024 // using System; diff --git a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/Services/WorldAnchorService.cs b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/Services/WorldAnchorService.cs index 2b50133..78defd5 100644 --- a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/Services/WorldAnchorService.cs +++ b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/Services/WorldAnchorService.cs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // -// Last change: June 2022 +// Last change: June 2024 // using System; diff --git a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/Services/WorldLinkService.cs b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/Services/WorldLinkService.cs index dac8abd..7a0f1dd 100644 --- a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/Services/WorldLinkService.cs +++ b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/Services/WorldLinkService.cs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // -// Last change: June 2022 +// Last change: June 2024 // using System; diff --git a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/Startup.cs b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/Startup.cs index b2d59f7..ba5250a 100644 --- a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/Startup.cs +++ b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/Startup.cs @@ -180,7 +180,7 @@ namespace ETSI.ARF.OpenAPI.WorldStorage services .AddControllers(options => { - options.ModelBinderProviders.Insert(0, new FromJsonBinderProviderT()); + options.ModelBinderProviders.Insert(0, new FromJsonBinderProviderT()); options.ModelBinderProviders.Insert(0, new FromJsonBinderProviderT()); }); } -- GitLab From fe52ce9e20fd503808e782d48a7334d5e4ee5d0e Mon Sep 17 00:00:00 2001 From: esle7566 Date: Fri, 20 Sep 2024 18:22:11 +0200 Subject: [PATCH 2/3] fix: getreloc always send an empty list as response (bad class provided to binder provider) --- .../worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/Startup.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/Startup.cs b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/Startup.cs index ba5250a..09e46ad 100644 --- a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/Startup.cs +++ b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/Startup.cs @@ -180,7 +180,7 @@ namespace ETSI.ARF.OpenAPI.WorldStorage services .AddControllers(options => { - options.ModelBinderProviders.Insert(0, new FromJsonBinderProviderT()); + options.ModelBinderProviders.Insert(0, new FromJsonBinderProviderT()); options.ModelBinderProviders.Insert(0, new FromJsonBinderProviderT()); }); } -- GitLab From f883d2af8803a3c2e706e09c845107af9bc59374 Mon Sep 17 00:00:00 2001 From: Sylvain Renault Date: Mon, 23 Sep 2024 12:21:09 +0200 Subject: [PATCH 3/3] Adapt the API to new reloc info request. Activate the token (security) access for all API endpoints. --- openapi | 2 +- .../RelocalizationInformationImpl.cs | 13 ++++++-- .../ControllersImpl/TrackablesImpl.cs | 24 ++++++++++---- .../ControllersImpl/WorldAnchorsImpl.cs | 21 +++++++++--- .../ControllersImpl/WorldLinksImpl.cs | 26 +++++++++++---- .../ETSI.ARF.OpenAPI.WorldStorage/Startup.cs | 32 +++++++++++-------- .../appsettings.json | 6 ++-- 7 files changed, 86 insertions(+), 38 deletions(-) diff --git a/openapi b/openapi index b639a02..99ea877 160000 --- a/openapi +++ b/openapi @@ -1 +1 @@ -Subproject commit b639a02180c2b5e301c77483b3a2fa645ba94169 +Subproject commit 99ea877dca8ba0587699f12dab77a43f79a836fc diff --git a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/RelocalizationInformationImpl.cs b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/RelocalizationInformationImpl.cs index 02a0058..f4cf095 100644 --- a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/RelocalizationInformationImpl.cs +++ b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/RelocalizationInformationImpl.cs @@ -55,6 +55,8 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers // old: public override IActionResult GetRelocalizationInformation([FromQuery(Name = "uuids")][Required()] List uuids, [FromQuery(Name = "capabilities")][Required()] List capabilities, [FromHeader(Name = "token")] string token) public override IActionResult GetRelocalizationInformation([FromQuery(Name = "uuids")][Required()] List uuids, [FromQuery(Name = "capabilities")][Required()] List capabilities, [FromHeader(Name = "token")] string token) { + if (!Startup.IsAccessGranted(token)) return StatusCode(511, new Error() { Message = "Invalid token!" }); + WorldAnchorService _worldAnchorService = WorldAnchorService.Singleton as WorldAnchorService; TrackableService _trackableService = TrackableService.Singleton as TrackableService; @@ -62,8 +64,12 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers var result = new RelocalizationInformations(); result.RelocInfo = new List(); + Guid errorUid = Guid.Empty; + foreach (var request in uuids) { + //System.Diagnostics.Debug.WriteLine("RelocInfo: Looking in the WS database for UUID=" + request.Uuid.ToString()); + var anchor = _worldAnchorService.Get(request.Uuid); Trackable trackable = null; @@ -119,13 +125,16 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers } else { - Console.WriteLine($"WorldAnchor with UUID {request.Uuid} does not exist in database"); + Console.WriteLine($"Trackable or WorldAnchor with UUID {request.Uuid} does not exist in database"); } } - return result.RelocInfo.Count > 0 ? new ObjectResult(result) : StatusCode(404, new Error() { Message = "Not found, could not find UUID in database." }); + return result.RelocInfo.Count > 0 ? new ObjectResult(result) : StatusCode(404, new Error() { Message = "Not found, could not find UUID(s) in database." }); } + // + // Helpers + // private List FindRelocInfo(Guid targetUUID, ModeWorldStorage mode, Matrix4x4 matrix, List capabilities, ref List history) { var results = new List(); diff --git a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/TrackablesImpl.cs b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/TrackablesImpl.cs index 7997e6c..46e1365 100644 --- a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/TrackablesImpl.cs +++ b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/TrackablesImpl.cs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // -// Last change: June 2024 +// Last change: September 2024 // /* @@ -66,6 +66,8 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers /// public override IActionResult AddTrackable([FromBody] Trackable trackable, [FromHeader] string token) { + if (!Startup.IsAccessGranted(token)) return StatusCode(511, new Error() { Message = "Invalid token!" }); + if (String.IsNullOrEmpty(trackable.UUID.ToString())) { trackable.UUID = Guid.NewGuid(); @@ -77,7 +79,7 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers { return StatusCode(409, new Error() { Message = "UUID already existing!" }); } - else return StatusCode(200, new Error() { Message = mytrackable.UUID.ToString() }); + else return StatusCode(200, new Success() { Message = mytrackable.UUID.ToString() }); } catch (Exception e) { @@ -90,6 +92,8 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers /// public override IActionResult DeleteTrackable([FromRoute(Name = "trackableUUID")][Required] Guid trackableUUID, [FromHeader] string token) { + if (!Startup.IsAccessGranted(token)) return StatusCode(511, new Error() { Message = "Invalid token!" }); + // Access other service(s) WorldLinkService _worldLinkService = WorldLinkService.Singleton as WorldLinkService; @@ -121,7 +125,8 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers { result += ", removed object was referenced in " + worldlinkinfo + " and removed there as well"; } - return (count > 0) ? new ObjectResult(result) : StatusCode(404, new Error() { Message = "Not found, could not find UUID in database." }); + result += " Token: " + token; + return (count > 0) ? StatusCode(200, new Success() { Message = result }) : StatusCode(404, new Error() { Message = "Not found, could not find UUID in database." }); } /// @@ -129,6 +134,8 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers /// public override IActionResult GetTrackableById([FromRoute(Name = "trackableUUID")][Required] Guid trackableUUID, [FromHeader] string token) { + if (!Startup.IsAccessGranted(token)) return StatusCode(511, new Error() { Message = "Invalid token!" }); + Trackable trackable = _trackableService.Get(trackableUUID); return (null != trackable) ? new ObjectResult(trackable) : StatusCode(404, new Error() { Message = "Not found, could not find UUID in database." }); } @@ -138,8 +145,11 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers /// public override IActionResult GetTrackables([FromHeader] string token) { - List trackablelist = _trackableService.Get(); - return new ObjectResult(trackablelist); + if (!Startup.IsAccessGranted(token)) return StatusCode(511, new Error() { Message = "Invalid token!" }); + + TrackablesResponse response = new TrackablesResponse(); + response.Trackables = _trackableService.Get(); + return new ObjectResult(response); } @@ -149,6 +159,8 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers /// public override IActionResult ModifyTrackable([FromBody] Trackable trackable, [FromHeader] string token) { + if (!Startup.IsAccessGranted(token)) return StatusCode(511, new Error() { Message = "Invalid token!" }); + long count = _trackableService.Replace(trackable); if (count == 0) { @@ -156,7 +168,7 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers } else { - return StatusCode(200, new Error() { Message = trackable.UUID.ToString() }); + return StatusCode(200, new Success() { Message = trackable.UUID.ToString() }); } } } diff --git a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/WorldAnchorsImpl.cs b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/WorldAnchorsImpl.cs index 8d6b265..0aebce3 100644 --- a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/WorldAnchorsImpl.cs +++ b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/WorldAnchorsImpl.cs @@ -66,6 +66,8 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers /// public override IActionResult AddWorldAnchor([FromBody] WorldAnchor worldAnchor, [FromHeader] string token) { + if (!Startup.IsAccessGranted(token)) return StatusCode(511, new Error() { Message = "Invalid token!" }); + if (String.IsNullOrEmpty(worldAnchor.UUID.ToString())) { worldAnchor.UUID = Guid.NewGuid(); @@ -77,7 +79,7 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers { return StatusCode(409, new Error() { Message = "UUID alread exexisting!" }); } - else return StatusCode(200, new Error() { Message = myworldanchor.UUID.ToString() }); + else return StatusCode(200, new Success() { Message = myworldanchor.UUID.ToString() }); } catch (Exception e) { @@ -90,6 +92,8 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers /// public override IActionResult DeleteWorldAnchor([FromRoute(Name = "worldAnchorUUID")][Required] Guid worldAnchorUUID, [FromHeader] string token) { + if (!Startup.IsAccessGranted(token)) return StatusCode(511, new Error() { Message = "Invalid token!" }); + // Access other service(s) WorldLinkService _worldLinkService = WorldLinkService.Singleton as WorldLinkService; @@ -121,7 +125,7 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers { result += ", but removed object was referenced in " + worldlinkinfo + " and removed there as well"; } - return (count > 0) ? new ObjectResult(result) : StatusCode(404, new Error() { Message = "Not found, could not find UUID in database." }); + return (count > 0) ? StatusCode(200, new Success() { Message = result }) : StatusCode(404, new Error() { Message = "Not found, could not find UUID in database." }); } /// @@ -129,6 +133,8 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers /// public override IActionResult GetWorldAnchorById([FromRoute(Name = "worldAnchorUUID")][Required] Guid worldAnchorUUID, [FromHeader] string token) { + if (!Startup.IsAccessGranted(token)) return StatusCode(511, new Error() { Message = "Invalid token!" }); + WorldAnchor myworldanchor = _worldAnchorService.Get(worldAnchorUUID); return (null != myworldanchor) ? new ObjectResult(myworldanchor) : StatusCode(404, new Error() { Message = "Not found, could not find UUID in database." }); } @@ -138,8 +144,11 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers /// public override IActionResult GetWorldAnchors([FromHeader] string token) { - List worldanchorlist = _worldAnchorService.Get(); - return new ObjectResult(worldanchorlist); + if (!Startup.IsAccessGranted(token)) return StatusCode(511, new Error() { Message = "Invalid token!" }); + + WorldAnchorsResponse response = new WorldAnchorsResponse(); + response.WorldAnchors = _worldAnchorService.Get(); + return new ObjectResult(response); } @@ -149,6 +158,8 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers /// public override IActionResult ModifyWorldAnchor([FromBody] WorldAnchor worldAnchor, [FromHeader] string token) { + if (!Startup.IsAccessGranted(token)) return StatusCode(511, new Error() { Message = "Invalid token!" }); + long count = _worldAnchorService.Replace(worldAnchor); if (count == 0) { @@ -156,7 +167,7 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers } else { - return StatusCode(200, new Error() { Message = worldAnchor.UUID.ToString() }); + return StatusCode(200, new Success() { Message = worldAnchor.UUID.ToString() }); } } diff --git a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/WorldLinksImpl.cs b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/WorldLinksImpl.cs index ef44865..48a0b94 100644 --- a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/WorldLinksImpl.cs +++ b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/ETSI-ARF/ControllersImpl/WorldLinksImpl.cs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // -// Last change: June 2024 +// Last change: September 2024 // /* @@ -65,6 +65,8 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers /// public override IActionResult AddWorldLink([FromBody] WorldLink worldLink, [FromHeader] string token) { + if (!Startup.IsAccessGranted(token)) return StatusCode(511, new Error() { Message = "Invalid token!" }); + if (String.IsNullOrEmpty(worldLink.UUID.ToString())) { worldLink.UUID = Guid.NewGuid(); @@ -76,7 +78,7 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers { return StatusCode(409, new Error() { Message = "UUID already existing!" }); } - else return StatusCode(200, new Error() { Message = myworldlink.UUID.ToString() }); + else return StatusCode(200, new Success() { Message = myworldlink.UUID.ToString() }); } catch (Exception e) { @@ -89,8 +91,10 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers /// public override IActionResult DeleteWorldLink([FromRoute(Name = "worldLinkUUID")][Required] Guid worldLinkUUID, [FromHeader] string token) { + if (!Startup.IsAccessGranted(token)) return StatusCode(511, new Error() { Message = "Invalid token!" }); + long count = _worldLinkService.Remove(worldLinkUUID); - return (count > 0) ? new ObjectResult("ok") : StatusCode(404, new Error() { Message = "Not found, could not find UUID in database." }); + return (count > 0) ? StatusCode(200, new Success() { Message = "ok" } ) : StatusCode(404, new Error() { Message = "Not found, could not find UUID in database." }); } @@ -99,6 +103,8 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers /// public override IActionResult GetWorldLinkById([FromRoute(Name = "worldLinkUUID")][Required] Guid worldLinkUUID, [FromHeader] string token) { + if (!Startup.IsAccessGranted(token)) return StatusCode(511, new Error() { Message = "Invalid token!" }); + // Access other service(s) TrackableService _trackableService = TrackableService.Singleton as TrackableService; WorldAnchorService _worldAnchorService = WorldAnchorService.Singleton as WorldAnchorService; @@ -149,12 +155,16 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers /// public override IActionResult GetWorldLinks([FromHeader] string token) { + if (!Startup.IsAccessGranted(token)) return StatusCode(511, new Error() { Message = "Invalid token!" }); + + WorldLinksResponse response = new WorldLinksResponse(); + // Access other service(s) TrackableService _trackableService = TrackableService.Singleton as TrackableService; WorldAnchorService _worldAnchorService = WorldAnchorService.Singleton as WorldAnchorService; - List worldlinklist = _worldLinkService.Get(); - foreach (WorldLink myworldlink in worldlinklist) + response.WorldLinks = _worldLinkService.Get(); + foreach (WorldLink myworldlink in response.WorldLinks) { // check TypeFrom if (myworldlink.TypeFrom == TypeWorldStorage.TRACKABLEEnum) @@ -191,7 +201,7 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers } } } - return new ObjectResult(worldlinklist); + return new ObjectResult(response); } @@ -201,6 +211,8 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers /// public override IActionResult ModifyWorldLink([FromBody] WorldLink worldLink, [FromHeader] string token) { + if (!Startup.IsAccessGranted(token)) return StatusCode(511, new Error() { Message = "Invalid token!" }); + long count = _worldLinkService.Replace(worldLink); if (count == 0) { @@ -208,7 +220,7 @@ namespace ETSI.ARF.OpenAPI.WorldStorage.Controllers } else { - return StatusCode(200, new Error() { Message = worldLink.UUID.ToString() }); + return StatusCode(200, new Success() { Message = worldLink.UUID.ToString() }); } } } diff --git a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/Startup.cs b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/Startup.cs index ba5250a..4d7bf50 100644 --- a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/Startup.cs +++ b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/Startup.cs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // -// Last change: June 2024 +// Last change: September 2024 // /* @@ -23,7 +23,7 @@ * * API ensuring interoperability between an authoring tool and a World Storage service * - * The version of the OpenAPI document: 2.0.1 + * The version of the OpenAPI document: 2.0.2 * * Generated by: https://openapi-generator.tech */ @@ -68,17 +68,18 @@ namespace ETSI.ARF.OpenAPI.WorldStorage /// /// The API version. (how to read it from the yaml?) /// - static public string apiVersion = "2.0.1"; + static public string apiVersion = "2.0.0"; /// /// Demo access key /// - static public string accessKey = "My!Key.ETSI"; + static public string accessKey = "ARF"; /// /// Demo secret key /// - static public string secretKey = "GW0Wae1t4Cs5rAqEbPYFWO9J5nSbpJXxp1F3uv0J"; + //static public string secretKey = "GW0Wae1t4Cs5rAqEbPYFWO9J5nSbpJXxp1F3uv0J"; + static public string secretKey = "hhi"; /// /// Constructor @@ -97,14 +98,16 @@ namespace ETSI.ARF.OpenAPI.WorldStorage /// /// SylR: Check if the request is authorized /// - /// + /// /// - //static public bool IsAccessAllowed(ETSI.ARF.OpenAPI.WorldStorage.Models.SecureAccess security) - //{ - // Console.WriteLine(security.AccessKey); - // return true; - // //return (security.AccessKey == accessKey && security.SecretKey == secretKey); - //} + static public bool IsAccessGranted(string token) + { + if (token == null) return false; + else if (token == "dev") return true; // developermode + + string[] t = token .Split('&'); + return t[0] == accessKey && t[1] == secretKey; + } /// /// This method gets called by the runtime. Use this method to add services to the container. @@ -181,6 +184,7 @@ namespace ETSI.ARF.OpenAPI.WorldStorage .AddControllers(options => { options.ModelBinderProviders.Insert(0, new FromJsonBinderProviderT()); + options.ModelBinderProviders.Insert(0, new FromJsonBinderProviderT()); options.ModelBinderProviders.Insert(0, new FromJsonBinderProviderT()); }); } @@ -220,10 +224,10 @@ namespace ETSI.ARF.OpenAPI.WorldStorage // set route prefix to openapi, e.g. http://localhost:8080/openapi/index.html c.RoutePrefix = "openapi"; //TODO: Either use the SwaggerGen generated OpenAPI contract (generated from C# classes) - //c.SwaggerEndpoint("/openapi/" + apiVersion + "/openapi.json", "World Storage API"); + c.SwaggerEndpoint("/openapi/" + apiVersion + "/openapi.json", "World Storage API"); //TODO: Or alternatively use the original OpenAPI contract that's included in the static files - c.SwaggerEndpoint("/openapi-original.json", "World Storage API Original"); + //c.SwaggerEndpoint("/openapi-original.json", "World Storage API Original"); }); app.UseRouting(); app.UseEndpoints(endpoints => diff --git a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/appsettings.json b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/appsettings.json index f2c1c69..182c031 100644 --- a/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/appsettings.json +++ b/server/worldstorage/src/ETSI.ARF.OpenAPI.WorldStorage/appsettings.json @@ -5,9 +5,9 @@ "MongoSrv": "192-168-020-029.fe.hhi.de", "MongoPort": "27037", "DatabaseName": "WorldStorageAPI", - "CollectionNameWorldLinks": "WorldLinks-DEV", - "CollectionNameTrackables": "Trackables-DEV", - "CollectionNameWorldAnchors": "WorldAnchors-DEV" + "CollectionNameWorldLinks": "WorldLinks", + "CollectionNameTrackables": "Trackables", + "CollectionNameWorldAnchors": "WorldAnchors" }, "Logging": { "LogLevel": { -- GitLab