commit 985d7d8c7aacbda8332cfc3e1e02ca0d354dca95
parent 3ee4447a653acf5977156391c71e760bd6902bee
Author: Christian Grothoff <christian@grothoff.org>
Date: Sun, 23 Jun 2024 15:37:47 +0200
complete GET /aml//measures endpoint
Diffstat:
3 files changed, 146 insertions(+), 6 deletions(-)
diff --git a/src/exchange/taler-exchange-httpd_aml-measures-get.c b/src/exchange/taler-exchange-httpd_aml-measures-get.c
@@ -25,11 +25,10 @@
#include <pthread.h>
#include "taler_json_lib.h"
#include "taler_mhd_lib.h"
+#include "taler_kyclogic_lib.h"
#include "taler_signatures.h"
#include "taler-exchange-httpd.h"
-#include "taler_exchangedb_plugin.h"
#include "taler-exchange-httpd_aml-measures-get.h"
-#include "taler-exchange-httpd_metrics.h"
MHD_RESULT
@@ -44,10 +43,9 @@ TEH_handler_aml_measures_get (
if (NULL == roots)
{
- // FIXME: initialize these properly!
- roots = json_object ();
- programs = json_object ();
- checks = json_object ();
+ TALER_KYCLOGIC_get_measure_configuration (&roots,
+ &programs,
+ &checks);
}
if (NULL != args[0])
{
diff --git a/src/include/taler_kyclogic_lib.h b/src/include/taler_kyclogic_lib.h
@@ -561,4 +561,18 @@ TALER_KYCLOGIC_kyc_get_details (
void *cb_cls);
+/**
+ * Return configuration data useful for the
+ * /aml/$PUB/measures endpoint.
+ *
+ * @param[out] proots set to the root measures
+ * @param[out] pprograms set to available AML programs
+ * @param[out] pchecks set to available KYC checks
+ */
+void
+TALER_KYCLOGIC_get_measure_configuration (
+ json_t **proots,
+ json_t **pprograms,
+ json_t **pchecks);
+
#endif
diff --git a/src/kyclogic/kyclogic_api.c b/src/kyclogic/kyclogic_api.c
@@ -2198,4 +2198,132 @@ TALER_KYCLOGIC_measure_to_requirement (
}
+void
+TALER_KYCLOGIC_get_measure_configuration (
+ json_t **proots,
+ json_t **pprograms,
+ json_t **pchecks)
+{
+ json_t *roots;
+ json_t *programs;
+ json_t *checks;
+
+ roots = json_object ();
+ for (unsigned int i = 0; i<default_rules.num_custom_measures; i++)
+ {
+ const struct TALER_KYCLOGIC_Measure *m
+ = &default_rules.custom_measures[i];
+ json_t *jm;
+
+ jm = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("check_name",
+ m->check_name),
+ GNUNET_JSON_pack_string ("prog_name",
+ m->prog_name),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_incref ("context",
+ m->context)));
+ GNUNET_assert (0 ==
+ json_object_set_new (roots,
+ m->measure_name,
+ jm));
+ }
+
+ programs = json_object ();
+ for (unsigned int i = 0; i<num_aml_programs; i++)
+ {
+ const struct TALER_KYCLOGIC_AmlProgram *ap
+ = aml_programs[i];
+ json_t *jp;
+ json_t *ctx;
+ json_t *inp;
+
+ ctx = json_array ();
+ GNUNET_assert (NULL != ctx);
+ for (unsigned int j = 0; j<ap->num_required_contexts; j++)
+ {
+ const char *rc = ap->required_contexts[j];
+
+ GNUNET_assert (0 ==
+ json_array_append_new (ctx,
+ json_string (rc)));
+ }
+ inp = json_array ();
+ GNUNET_assert (NULL != inp);
+ for (unsigned int j = 0; j<ap->num_required_attributes; j++)
+ {
+ const char *ra = ap->required_attributes[j];
+
+ GNUNET_assert (0 ==
+ json_array_append_new (inp,
+ json_string (ra)));
+ }
+
+ jp = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("description",
+ ap->description),
+ GNUNET_JSON_pack_array_steal ("context",
+ ctx),
+ GNUNET_JSON_pack_array_steal ("inputs",
+ inp));
+ GNUNET_assert (0 ==
+ json_object_set_new (programs,
+ ap->program_name,
+ jp));
+ }
+
+ checks = json_object ();
+ for (unsigned int i = 0; i<num_kyc_checks; i++)
+ {
+ const struct TALER_KYCLOGIC_KycCheck *ck
+ = kyc_checks[i];
+ json_t *jc;
+ json_t *requires;
+ json_t *outputs;
+
+ requires = json_array ();
+ GNUNET_assert (NULL != requires);
+ for (unsigned int j = 0; j<ck->num_requires; j++)
+ {
+ const char *ra = ck->requires[j];
+
+ GNUNET_assert (0 ==
+ json_array_append_new (requires,
+ json_string (ra)));
+ }
+ outputs = json_array ();
+ GNUNET_assert (NULL != outputs);
+ for (unsigned int j = 0; j<ck->num_outputs; j++)
+ {
+ const char *out = ck->outputs[j];
+
+ GNUNET_assert (0 ==
+ json_array_append_new (outputs,
+ json_string (out)));
+ }
+
+ jc = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("description",
+ ck->description),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_incref ("description",
+ ck->description_i18n)),
+ GNUNET_JSON_pack_array_steal ("requires",
+ requires),
+ GNUNET_JSON_pack_array_steal ("outputs",
+ outputs),
+ GNUNET_JSON_pack_string ("fallback",
+ ck->fallback));
+ GNUNET_assert (0 ==
+ json_object_set_new (checks,
+ ck->check_name,
+ jc));
+ }
+
+ *proots = roots;
+ *pprograms = programs;
+ *pchecks = checks;
+}
+
+
/* end of kyclogic_api.c */