changeset 3192:595bfee4391a

URI "/peers?expand" provides more information
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 05 Feb 2019 06:44:36 +0100
parents 20826867141f
children c6cfd502bf79
files Core/WebServiceParameters.cpp Core/WebServiceParameters.h NEWS OrthancServer/OrthancRestApi/OrthancRestModalities.cpp
diffstat 4 files changed, 49 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/Core/WebServiceParameters.cpp	Mon Feb 04 21:09:44 2019 +0100
+++ b/Core/WebServiceParameters.cpp	Tue Feb 05 06:44:36 2019 +0100
@@ -502,4 +502,47 @@
     }
   }
 #endif
+
+
+  void WebServiceParameters::FormatPublic(Json::Value& target) const
+  {
+    target = Json::objectValue;
+
+    // Only return the public information identifying the destination.
+    // "Security"-related information such as passwords and HTTP
+    // headers are shown as "null" values.
+    target[KEY_URL] = url_;
+
+    if (!username_.empty())
+    {
+      target[KEY_USERNAME] = username_;
+      target[KEY_PASSWORD] = Json::nullValue;
+    }
+
+    if (!certificateFile_.empty())
+    {
+      target[KEY_CERTIFICATE_FILE] = certificateFile_;
+      target[KEY_CERTIFICATE_KEY_FILE] = Json::nullValue;
+      target[KEY_CERTIFICATE_KEY_PASSWORD] = Json::nullValue;      
+    }
+
+    target[KEY_PKCS11] = pkcs11Enabled_;
+
+    Json::Value headers = Json::arrayValue;
+      
+    for (Dictionary::const_iterator it = headers_.begin();
+         it != headers_.end(); ++it)
+    {
+      // Only list the HTTP headers, not their value
+      headers.append(it->first);
+    }
+
+    target[KEY_HTTP_HEADERS] = headers;
+
+    for (Dictionary::const_iterator it = userProperties_.begin();
+         it != userProperties_.end(); ++it)
+    {
+      target[it->first] = it->second;
+    }
+  }
 }
--- a/Core/WebServiceParameters.h	Mon Feb 04 21:09:44 2019 +0100
+++ b/Core/WebServiceParameters.h	Tue Feb 05 06:44:36 2019 +0100
@@ -175,5 +175,7 @@
 #if ORTHANC_SANDBOXED == 0
     void CheckClientCertificate() const;
 #endif
+
+    void FormatPublic(Json::Value& target) const;
   };
 }
--- a/NEWS	Mon Feb 04 21:09:44 2019 +0100
+++ b/NEWS	Tue Feb 05 06:44:36 2019 +0100
@@ -15,6 +15,7 @@
 * API version has been upgraded to 1.4
 * New URI "/tools/metrics" to dynamically enable/disable the collection of metrics
 * New URI "/tools/metrics-prometheus" to retrieve metrics using Prometheus text format
+* URI "/peers?expand" provides more information about the peers
 
 Plugins
 -------
--- a/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp	Mon Feb 04 21:09:44 2019 +0100
+++ b/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp	Tue Feb 05 06:44:36 2019 +0100
@@ -1015,16 +1015,9 @@
         
         if (lock.GetConfiguration().LookupOrthancPeer(peer, *it))
         {
-          Json::Value jsonPeer = Json::objectValue;
-          // only return the minimum information to identify the
-          // destination, do not include "security" information like
-          // passwords
-          jsonPeer["Url"] = peer.GetUrl();
-          if (!peer.GetUsername().empty())
-          {
-            jsonPeer["Username"] = peer.GetUsername();
-          }
-          result[*it] = jsonPeer;
+          Json::Value info;
+          peer.FormatPublic(info);
+          result[*it] = info;
         }
       }
       call.GetOutput().AnswerJson(result);