gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-anastasis] branch master updated: allow providers to be enabled/d


From: gnunet
Subject: [taler-anastasis] branch master updated: allow providers to be enabled/disabled
Date: Thu, 30 Sep 2021 14:42:55 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository anastasis.

The following commit(s) were added to refs/heads/master by this push:
     new edd65b2  allow providers to be enabled/disabled
edd65b2 is described below

commit edd65b2fa2ee029fb670150f92513d20edce0bf1
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Thu Sep 30 14:42:53 2021 +0200

    allow providers to be enabled/disabled
---
 doc/sphinx/reducer.rst                     |  32 +++---
 src/reducer/anastasis_api_backup_redux.c   | 176 +++++++++++++++++++++++------
 src/reducer/anastasis_api_recovery_redux.c |  17 +++
 src/reducer/anastasis_api_redux.c          |  51 +++------
 4 files changed, 195 insertions(+), 81 deletions(-)

diff --git a/doc/sphinx/reducer.rst b/doc/sphinx/reducer.rst
index 320db48..defd088 100644
--- a/doc/sphinx/reducer.rst
+++ b/doc/sphinx/reducer.rst
@@ -358,7 +358,7 @@ providers that accept payments in the selected currency:
         },
            {
               "type": "string",
-           "name": "tax_number",
+               "name": "tax_number",
               "label": "Taxpayer identification number",
               "label_i18n":{
                     "de_DE": "Steuerliche Identifikationsnummer",
@@ -366,7 +366,7 @@ providers that accept payments in the selected currency:
                     "en": "German taxpayer identification number"
               },
               "widget": "anastasis_gtk_ia_tax_de",
-           "uuid": "dae48f85-e3ff-47a4-a4a3-ed981ed8c3c6",
+               "uuid": "dae48f85-e3ff-47a4-a4a3-ed981ed8c3c6",
               "validation-regex": "^[0-9]{11}$",
               "validation-logic": "DE_TIN_check"
            },
@@ -381,8 +381,8 @@ providers that accept payments in the selected currency:
             "en": "Social security number"
           },
           "widget": "anastasis_gtk_ia_ssn",
-             "validation-regex": "^[0-9]{8}[[:upper:]][0-9]{3}$",
-             "validation-logic": "DE_SVN_check"
+         "validation-regex": "^[0-9]{8}[[:upper:]][0-9]{3}$",
+         "validation-logic": "DE_SVN_check"
           "optional" : true
       }
       ],
@@ -494,22 +494,23 @@ adds one or more Anastasis providers to the list of 
providers the reducer
 should henceforth consider.  Note that removing providers is not possible at
 this time.
 
-Here, the client must provide an array with the base URLs of the
-providers to add, for example:
+Here, the client must provide an object with the base URLs of the
+providers to add or disable. The object maps the
+URLs to status information about the provider to
+use. For example:
 
 .. code-block:: json
 
     {
-      "urls": [
-        "http://localhost:8888/";,
-        "http://localhost:8089/";
-      ]
+      "http://localhost:8088/"; : { "disabled" : false },
+      "http://localhost:8089/"; : { "disabled" : false }
+      "http://localhost:8090/"; : { "disabled" : true },
     }
 
-Note that existing providers will remain in the state.  The following is an
+Note that existing providers will remain in the state they were in.  The 
following is an
 example for an expected new state where the service on port 8089 is
-unreachable, the service on port 8088 was previously known, and service on
-port 8888 was now added:
+unreachable, the services on port 8088 and 8888 were previously known, and 
service on
+port 8088 was now added, and on 8090 is disabled:
 
 .. code-block:: json
 
@@ -517,10 +518,15 @@ port 8888 was now added:
       "backup_state": "USER_ATTRIBUTES_COLLECTING",
       "authentication_providers": {
         "http://localhost:8089/": {
+          "disabled": false,
           "error_code": 11,
           "http_status": 0
         },
+        "http://localhost:8090/": {
+          "disabled": true
+        },
         "http://localhost:8088/": {
+          "disabled": false,
           "http_status": 200,
           "methods": [
             { "type" : "question",
diff --git a/src/reducer/anastasis_api_backup_redux.c 
b/src/reducer/anastasis_api_backup_redux.c
index cfef852..27b5730 100644
--- a/src/reducer/anastasis_api_backup_redux.c
+++ b/src/reducer/anastasis_api_backup_redux.c
@@ -286,22 +286,28 @@ add_authentication (json_t *state,
 
     json_object_foreach (auth_providers, url, details)
     {
-      json_t *methods;
+      json_t *methods = NULL;
       json_t *method;
       size_t index;
-      uint32_t size_limit_in_mb;
+      uint32_t size_limit_in_mb = 0;
+      bool disabled = false;
+      uint32_t http_status = 0;
       struct GNUNET_JSON_Specification ispec[] = {
-        GNUNET_JSON_spec_uint32 ("storage_limit_in_megabytes",
-                                 &size_limit_in_mb),
-        GNUNET_JSON_spec_json ("methods",
-                               &methods),
+        GNUNET_JSON_spec_mark_optional (
+          GNUNET_JSON_spec_uint32 ("storage_limit_in_megabytes",
+                                   &size_limit_in_mb)),
+        GNUNET_JSON_spec_mark_optional (
+          GNUNET_JSON_spec_uint32 ("http_status",
+                                   &http_status)),
+        GNUNET_JSON_spec_mark_optional (
+          GNUNET_JSON_spec_bool ("disabled",
+                                 &disabled)),
+        GNUNET_JSON_spec_mark_optional (
+          GNUNET_JSON_spec_json ("methods",
+                                 &methods)),
         GNUNET_JSON_spec_end ()
       };
 
-      if (MHD_HTTP_OK !=
-          json_integer_value (json_object_get (details,
-                                               "http_status")))
-        continue; /* skip providers that are down */
       if (GNUNET_OK !=
           GNUNET_JSON_parse (details,
                              ispec,
@@ -310,6 +316,16 @@ add_authentication (json_t *state,
         GNUNET_break (0);
         continue;
       }
+      if (disabled)
+        continue;
+      if (MHD_HTTP_OK != http_status)
+        continue; /* skip providers that are down */
+      if ( (NULL == methods) ||
+           (0 == size_limit_in_mb) )
+      {
+        GNUNET_break (0);
+        continue;
+      }
       json_array_foreach (methods, index, method)
       {
         const char *type;
@@ -1082,6 +1098,33 @@ provider_candidate (struct PolicyBuilder *pb,
 
   json_object_foreach (pb->providers, url, pconfig)
   {
+    bool disabled = false;
+    uint32_t http_status = 0;
+    struct GNUNET_JSON_Specification spec[] = {
+      GNUNET_JSON_spec_mark_optional (
+        GNUNET_JSON_spec_bool ("disabled",
+                               &disabled)),
+      GNUNET_JSON_spec_mark_optional (
+        GNUNET_JSON_spec_uint32 ("http_status",
+                                 &http_status)),
+      GNUNET_JSON_spec_end ()
+    };
+
+    if (GNUNET_OK !=
+        GNUNET_JSON_parse (pconfig,
+                           spec,
+                           NULL, NULL))
+    {
+      GNUNET_break (0);
+      continue;
+    }
+    if ( (MHD_HTTP_OK != http_status) ||
+         disabled)
+    {
+      GNUNET_JSON_parse_free (spec);
+      continue;
+    }
+    GNUNET_JSON_parse_free (spec);
     prov_sel[i] = url;
     if (i == pb->req_methods - 1)
     {
@@ -1178,16 +1221,25 @@ method_candidate (struct PolicyBuilder *pb,
  * @param[out] salt value to extract
  * @return #GNUNET_OK on success
  */
-static int
+static enum GNUNET_GenericReturnValue
 lookup_salt (const json_t *state,
              const char *provider_url,
              struct ANASTASIS_CRYPTO_ProviderSaltP *salt)
 {
   const json_t *aps;
   const json_t *cfg;
+  uint32_t http_status = 0;
+  bool disabled = false;
   struct GNUNET_JSON_Specification spec[] = {
-    GNUNET_JSON_spec_fixed_auto ("salt",
-                                 salt),
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_bool ("disabled",
+                             &disabled)),
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_uint32 ("http_status",
+                               &http_status)),
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_fixed_auto ("salt",
+                                   salt)),
     GNUNET_JSON_spec_end ()
   };
 
@@ -1205,10 +1257,6 @@ lookup_salt (const json_t *state,
     GNUNET_break (0);
     return GNUNET_SYSERR;
   }
-  if (MHD_HTTP_OK !=
-      json_integer_value (json_object_get (cfg,
-                                           "http_status")))
-    return GNUNET_NO; /* skip providers that are down */
   if (GNUNET_OK !=
       GNUNET_JSON_parse (cfg,
                          spec,
@@ -1218,6 +1266,12 @@ lookup_salt (const json_t *state,
     GNUNET_break_op (0);
     return GNUNET_NO;
   }
+  if (disabled)
+    return GNUNET_NO;
+  if (NULL ==
+      json_object_get (cfg,
+                       "salt"))
+    return GNUNET_NO;
   return GNUNET_OK;
 }
 
@@ -1904,7 +1958,15 @@ add_policy (json_t *state,
       {
         const json_t *prov_cfg;
         uint32_t limit;
+        bool disabled = false;
+        uint32_t http_status = 0;
         struct GNUNET_JSON_Specification spec[] = {
+          GNUNET_JSON_spec_mark_optional (
+            GNUNET_JSON_spec_bool ("disabled",
+                                   &disabled)),
+          GNUNET_JSON_spec_mark_optional (
+            GNUNET_JSON_spec_uint32 ("http_status",
+                                     &http_status)),
           GNUNET_JSON_spec_uint32 ("storage_limit_in_megabytes",
                                    &limit),
           GNUNET_JSON_spec_json ("methods",
@@ -1924,10 +1986,6 @@ add_policy (json_t *state,
                                  "provider URL unknown");
           return NULL;
         }
-        if (MHD_HTTP_OK !=
-            json_integer_value (json_object_get (prov_cfg,
-                                                 "http_status")))
-          continue;
         if (GNUNET_OK !=
             GNUNET_JSON_parse (prov_cfg,
                                spec,
@@ -1937,6 +1995,13 @@ add_policy (json_t *state,
           json_decref (methods);
           continue;
         }
+        if ( (MHD_HTTP_OK != http_status) ||
+             disabled)
+        {
+          /* skip provider, disabled or down */
+          json_decref (methods);
+          continue;
+        }
         if (! json_is_array (prov_methods))
         {
           GNUNET_break (0);
@@ -2373,17 +2438,21 @@ update_expiration_cost (json_t *state,
     json_object_foreach (providers, url, provider)
     {
       struct TALER_Amount annual_fee;
+      bool disabled = false;
+      uint32_t http_status = 0;
       struct GNUNET_JSON_Specification pspec[] = {
+        GNUNET_JSON_spec_mark_optional (
+          GNUNET_JSON_spec_bool ("disabled",
+                                 &disabled)),
+        GNUNET_JSON_spec_mark_optional (
+          GNUNET_JSON_spec_uint32 ("http_status",
+                                   &http_status)),
         TALER_JSON_spec_amount_any ("annual_fee",
                                     &annual_fee),
         GNUNET_JSON_spec_end ()
       };
       struct TALER_Amount fee;
 
-      if (MHD_HTTP_OK !=
-          json_integer_value (json_object_get (provider,
-                                               "http_status")))
-        continue; /* skip providers that are down */
       if (GNUNET_OK !=
           GNUNET_JSON_parse (provider,
                              pspec,
@@ -2393,6 +2462,9 @@ update_expiration_cost (json_t *state,
         GNUNET_break_op (0);
         continue;
       }
+      if ( (MHD_HTTP_OK != http_status) ||
+           disabled)
+        continue; /* skip providers that are down or disabled */
       if (0 >
           TALER_amount_multiply (&fee,
                                  &annual_fee,
@@ -2473,7 +2545,15 @@ update_expiration_cost (json_t *state,
         off++;
         {
           struct TALER_Amount upload_cost;
+          bool disabled = false;
+          uint32_t http_status = 0;
           struct GNUNET_JSON_Specification pspec[] = {
+            GNUNET_JSON_spec_mark_optional (
+              GNUNET_JSON_spec_bool ("disabled",
+                                     &disabled)),
+            GNUNET_JSON_spec_mark_optional (
+              GNUNET_JSON_spec_uint32 ("http_status",
+                                       &http_status)),
             TALER_JSON_spec_amount_any ("truth_upload_fee",
                                         &upload_cost),
             GNUNET_JSON_spec_end ()
@@ -2491,6 +2571,12 @@ update_expiration_cost (json_t *state,
             GNUNET_break (0);
             return GNUNET_SYSERR;
           }
+          if ( (MHD_HTTP_OK != http_status) ||
+               disabled)
+          {
+            GNUNET_break (0);
+            return GNUNET_SYSERR;
+          }
           if (0 >
               TALER_amount_multiply (&fee,
                                      &upload_cost,
@@ -4111,17 +4197,22 @@ check_upload_size_limit (json_t *state,
      see #6760. */
   json_object_foreach (aps, url, ap)
   {
-    uint32_t limit;
+    uint32_t limit = 0;
+    bool disabled = false;
+    uint32_t http_status = 0;
     struct GNUNET_JSON_Specification spec[] = {
-      GNUNET_JSON_spec_uint32 ("storage_limit_in_megabytes",
-                               &limit),
+      GNUNET_JSON_spec_mark_optional (
+        GNUNET_JSON_spec_bool ("disabled",
+                               &disabled)),
+      GNUNET_JSON_spec_mark_optional (
+        GNUNET_JSON_spec_uint32 ("http_status",
+                                 &http_status)),
+      GNUNET_JSON_spec_mark_optional (
+        GNUNET_JSON_spec_uint32 ("storage_limit_in_megabytes",
+                                 &limit)),
       GNUNET_JSON_spec_end ()
     };
 
-    if (MHD_HTTP_OK !=
-        json_integer_value (json_object_get (ap,
-                                             "http_status")))
-      continue;   /* skip providers that are down */
     if (GNUNET_OK !=
         GNUNET_JSON_parse (ap,
                            spec,
@@ -4131,6 +4222,9 @@ check_upload_size_limit (json_t *state,
       GNUNET_break_op (0);
       continue;
     }
+    if ( (MHD_HTTP_OK != http_status) ||
+         disabled)
+      continue;
     if (0 == limit)
       return GNUNET_SYSERR;
     min_limit = GNUNET_MIN (min_limit,
@@ -4935,7 +5029,25 @@ ANASTASIS_REDUX_backup_begin_ (json_t *state,
     json_object_foreach (provider_list, url, prov) {
       struct BackupStartStateProviderEntry *pe;
       json_t *istate;
+      bool disabled = false;
+      struct GNUNET_JSON_Specification spec[] = {
+        GNUNET_JSON_spec_mark_optional (
+          GNUNET_JSON_spec_bool ("disabled",
+                                 &disabled)),
+        GNUNET_JSON_spec_end ()
+      };
 
+      if (GNUNET_OK !=
+          GNUNET_JSON_parse (prov,
+                             spec,
+                             NULL, NULL))
+      {
+        /* skip malformed provider entry */
+        GNUNET_break_op (0);
+        continue;
+      }
+      if (disabled)
+        continue;
       pe = GNUNET_new (struct BackupStartStateProviderEntry);
       pe->bss = bss;
       istate = json_object ();
diff --git a/src/reducer/anastasis_api_recovery_redux.c 
b/src/reducer/anastasis_api_recovery_redux.c
index 8709cf9..59f5ae3 100644
--- a/src/reducer/anastasis_api_recovery_redux.c
+++ b/src/reducer/anastasis_api_recovery_redux.c
@@ -2867,6 +2867,23 @@ ANASTASIS_REDUX_recovery_challenge_begin_ (json_t *state,
     const char *url;
 
     json_object_foreach (providers, url, prov) {
+      bool disabled = false;
+      struct GNUNET_JSON_Specification spec[] = {
+        GNUNET_JSON_spec_mark_optional (
+          GNUNET_JSON_spec_bool ("disabled",
+                                 &disabled)),
+        GNUNET_JSON_spec_end ()
+      };
+
+      if (GNUNET_OK !=
+          GNUNET_JSON_parse (prov,
+                             spec,
+                             NULL, NULL))
+      {
+        /* skip malformed provider entry */
+        GNUNET_break_op (0);
+        continue;
+      }
       begin_query_provider (rss,
                             url);
     }
diff --git a/src/reducer/anastasis_api_redux.c 
b/src/reducer/anastasis_api_redux.c
index f55eece..851be12 100644
--- a/src/reducer/anastasis_api_redux.c
+++ b/src/reducer/anastasis_api_redux.c
@@ -1378,9 +1378,16 @@ ANASTASIS_add_provider_ (json_t *state,
                          ANASTASIS_ActionCallback cb,
                          void *cb_cls)
 {
-  json_t *urls;
   json_t *tlist;
 
+  if (NULL == arguments)
+  {
+    ANASTASIS_redux_fail_ (cb,
+                           cb_cls,
+                           TALER_EC_ANASTASIS_REDUCER_INPUT_INVALID,
+                           "arguments missing");
+    return true; /* cb was invoked */
+  }
   tlist = json_object_get (state,
                            "authentication_providers");
   if (NULL == tlist)
@@ -1392,47 +1399,19 @@ ANASTASIS_add_provider_ (json_t *state,
                                         "authentication_providers",
                                         tlist));
   }
-  if (NULL == arguments)
-  {
-    ANASTASIS_redux_fail_ (cb,
-                           cb_cls,
-                           TALER_EC_ANASTASIS_REDUCER_INPUT_INVALID,
-                           "arguments missing");
-    return true;
-  }
-  urls = json_object_get (arguments,
-                          "urls");
-  if (NULL == urls)
-  {
-    ANASTASIS_redux_fail_ (cb,
-                           cb_cls,
-                           TALER_EC_ANASTASIS_REDUCER_INPUT_INVALID,
-                           "'urls' missing");
-    return true;
-  }
   {
-    size_t index;
-    json_t *url;
+    json_t *params;
+    const char *url;
 
-    json_array_foreach (urls, index, url)
+    json_object_foreach (((json_t *) arguments), url, params)
     {
-      const char *url_str = json_string_value (url);
-
-      if (NULL == url_str)
-      {
-        ANASTASIS_redux_fail_ (cb,
-                               cb_cls,
-                               TALER_EC_ANASTASIS_REDUCER_INPUT_INVALID,
-                               "'urls' must be strings");
-        return true;
-      }
       GNUNET_assert (0 ==
-                     json_object_set_new (tlist,
-                                          url_str,
-                                          json_object ()));
+                     json_object_set (tlist,
+                                      url,
+                                      params));
     }
   }
-  return false;
+  return false; /* cb not invoked */
 }
 
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]