Commit 6dfc5fcc authored by Geoff Simmons's avatar Geoff Simmons

Add dump_keys().

parent 3f407ff8
......@@ -38,6 +38,7 @@
#include "cache/cache.h"
#include "vtim.h"
#include "vsb.h"
#include "verrno.h"
/* XXX grr */
......@@ -610,3 +611,52 @@ KEY_Updated(VRT_CTX, uint8_t *id, uint8_t idlen)
{
return (key_time(ctx, id, idlen, UPDATED));
}
#define TIMSZ (sizeof("YYYY-mm-ddTHH:MM:SS"))
void
KEY_Dump(VRT_CTX)
{
struct key_tree *tree_h;
struct key *key;
struct vsb *vsb = VSB_new_auto();
time_t tim;
struct tm tm;
char tim_buf[TIMSZ];
const char *p[0];
struct strands strands = { 1, p };
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
VSB_printf(vsb, "id,added,updated\n");
for (unsigned i = 0; i < UINT8_MAX; i++) {
KEY_Rdlock(i);
tree_h = &key_tbl[i].tree;
VRBT_FOREACH(key, key_tree, tree_h) {
CHECK_OBJ_NOTNULL(key, KEY_MAGIC);
AN(key->id);
AN(key->added);
AN(key->updated);
VSB_bcat(vsb, key->id, key->idlen);
tim = (time_t)key->added;
localtime_r(&tim, &tm);
strftime(tim_buf, TIMSZ, "%Y-%m-%dT%T", &tm);
VSB_printf(vsb, ",%s,", tim_buf);
tim = (time_t)key->updated;
localtime_r(&tim, &tm);
strftime(tim_buf, TIMSZ, "%Y-%m-%dT%T", &tm);
VSB_printf(vsb, "%s\n", tim_buf);
}
KEY_Unlock(i);
}
VSB_finish(vsb);
strands.n = 1;
strands.p[0] = VSB_data(vsb);
VRT_synth_page(ctx, &strands);
VSB_destroy(&vsb);
return;
}
......@@ -45,3 +45,4 @@ int KEY_Delete(VRT_CTX, uint8_t *id, uint8_t idlen);
VCL_BOOL KEY_Exists(uint8_t *id, uint8_t idlen);
VCL_TIME KEY_Added(VRT_CTX, uint8_t *id, uint8_t idlen);
VCL_TIME KEY_Updated(VRT_CTX, uint8_t *id, uint8_t idlen);
void KEY_Dump(VRT_CTX);
......@@ -214,6 +214,77 @@ client c1 {
logexpect l1 -wait
varnish v1 -vcl {
import ${vmod_ece};
import blob;
backend b { .host="${bad_ip}"; }
sub vcl_recv {
if (ece.key_exists("")) {
ece.delete_key("");
}
if (req.url == "/2") {
ece.set_key("foo", blob.decode(BASE64,
encoded="H0JUi1Jb/WkAn5Ow0oyjCA=="));
ece.set_key("bar", blob.decode(BASE64,
encoded="/9InuRuPOTQOj/7dXZ/ZNw=="));
ece.set_key("baz", blob.decode(BASE64,
encoded="Wfhr2up4uvsVDo9ZLqweSw=="));
ece.set_key("quux", blob.decode(BASE64,
encoded="JfQd/wZAeH8swl8Fw92Vmw=="));
}
return (synth(200));
}
sub vcl_synth {
set resp.http.Content-Type = "text/csv";
ece.dump_keys();
return (deliver);
}
}
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.Content-Type == "text/csv"
expect resp.body ~ "^id,added,updated"
txreq -url /2
rxresp
expect resp.status == 200
expect resp.http.Content-Type == "text/csv"
expect resp.body ~ "^id,added,updated"
expect resp.body ~ {(?m)^foo,(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2},?){2}$}
expect resp.body ~ {(?m)^bar,(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2},?){2}$}
expect resp.body ~ {(?m)^baz,(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2},?){2}$}
expect resp.body ~ {(?m)^quux,(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2},?){2}$}
} -run
varnish v1 -vcl {
import ${vmod_ece};
backend b { .host="${bad_ip}"; }
sub vcl_recv {
ece.dump_keys();
}
}
logexpect l1 -v v1 -d 0 -g vxid -q "VCL_Error" {
expect 0 * Begin req
expect * = VCL_Error {^dump_keys\(\) may only be called in vcl_synth$}
expect * = End
} -start
client c1 {
txreq
rxresp
expect resp.status == 503
expect resp.reason == "VCL failed"
} -run
logexpect l1 -wait
varnish v1 -vcl {
import ${vmod_ece};
import blob;
......
......@@ -33,6 +33,7 @@
#include <openssl/crypto.h>
#include "cache/cache.h"
#include "vcl.h"
#include "vcc_if.h"
......@@ -187,6 +188,19 @@ vmod_key_updated(VRT_CTX, VCL_STRING id)
return (KEY_Updated(ctx, (uint8_t *)id, (uint8_t)len));
}
VCL_VOID
vmod_dump_keys(VRT_CTX)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if ((ctx->method & VCL_MET_SYNTH) == 0) {
VRT_fail(ctx, "dump_keys() may only be called in vcl_synth");
return;
}
KEY_Dump(ctx);
}
VCL_STRING
vmod_libcrypto_version(VRT_CTX)
{
......
......@@ -104,6 +104,14 @@ last updated.
XXX ...
$Function VOID dump_keys()
Generate a synthetic client response body with information in CSV
format (comma-separated values) about all of the keys that are
currently stored.
XXX ...
$Function STRING libcrypto_version()
Return the libcrypto version string.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment