Commit 0073245e authored by Walid Boudebouda's avatar Walid Boudebouda Committed by Nils Goroll

vmod_directors: restrict methods and functions

parent acf3b946
......@@ -9,9 +9,6 @@ varnish v1 -vcl+backend {
import directors;
sub vcl_recv {
if (req.url == "/lookup") {
set req.http.foo = directors.lookup("s1");
}
return (pass);
}
......@@ -24,10 +21,6 @@ client c1 {
txreq -url "/"
rxresp
expect resp.http.X-Backend-Name == "s1"
txreq -url "/lookup"
rxresp
expect resp.status == 503
expect resp.reason == "VCL failed"
} -run
varnish v1 -vcl+backend {
......@@ -55,3 +48,17 @@ client c1 {
expect resp.http.X-Director-Name == "bar"
expect resp.http.X-Backend-Name == "s1"
} -run
varnish v1 -errvcl "Not available in subroutine 'vcl_recv'" {
import directors;
backend dummy None;
sub vcl_recv {
if (req.url == "/lookup") {
set req.http.foo = directors.lookup("s1");
}
return (pass);
}
}
......@@ -16,8 +16,6 @@ varnish v1 -vcl {
if (req.url == "/1") {
set req.backend_hint = shard.backend(
param=blob.decode(HEX, encoded=""));
} else if (req.url == "/2") {
p.set(by=HASH);
}
}
} -start
......@@ -30,9 +28,6 @@ logexpect l1 -v v1 -g raw -d 1 {
logexpect l2 -v v1 -g raw {
expect * 1001 VCL_Error {vmod_directors: shard shard: .backend.key_blob. param invalid}
} -start
logexpect l3 -v v1 -g raw {
expect * 1003 VCL_Error {vmod_directors: shard p: shard_param.set.. may only be used in vcl_init and in backend/pipe context}
} -start
client c1 {
txreq -url "/1"
......@@ -41,15 +36,8 @@ client c1 {
expect_close
} -run
client c1 {
txreq -url "/2"
rxresp
expect resp.status == 503
expect_close
} -run
logexpect l2 -wait
logexpect l3 -wait
varnish v1 -errvcl {shard .associate param invalid} {
import directors;
......@@ -206,3 +194,22 @@ varnish v1 -errvcl {vmod_directors: shard shard: .remove_backend(): either backe
shard.remove_backend();
}
}
varnish v1 -errvcl "Not available in subroutine 'vcl_recv'" {
import directors;
import blob;
backend dummy None;
sub vcl_init {
new shard = directors.shard();
new p = directors.shard_param();
p.set(by=BLOB, key_blob=blob.decode(HEX, encoded=""));
}
sub vcl_recv {
if (req.url == "/2") {
p.set(by=HASH);
}
}
}
......@@ -48,12 +48,7 @@
VCL_BACKEND
VPFX(lookup)(VRT_CTX, VCL_STRING name)
{
if ((ctx->method & VCL_MET_TASK_H) == 0) {
VRT_fail(ctx,
"lookup() may only be called from vcl_init / vcl_fini");
return (NULL);
}
AN(ctx->method & VCL_MET_TASK_H);
return (VRT_LookupDirector(ctx, name));
}
......
......@@ -650,7 +650,7 @@ Reset the parameter set to default values as documented for
* backend context and in ``vcl_pipe {}``, resets the parameter set for
this backend request to the VCL defaults
This method may not be used in client context other than ``vcl_pipe {}``.
$Restrict vcl_pipe backend housekeeping
$Method VOID .set(
[ ENUM {HASH, URL, KEY, BLOB} by ],
......@@ -670,7 +670,7 @@ Change the given parameters of a parameter set as documented for
for this backend request, keeping the defaults set for this VCL for
unspecified arguments.
This method may not be used in client context other than ``vcl_pipe {}``.
$Restrict vcl_pipe backend housekeeping
$Method STRING .get_by()
......@@ -706,16 +706,16 @@ shard director using this parameter object would use. See
$Method BLOB .use()
This method may only be used in backend context and in ``vcl_pipe {}``.
For use with the *param* argument of `xshard.backend()`_
to associate this shard parameter set with a shard director.
$Restrict vcl_pipe backend housekeeping
$Function BACKEND lookup(STRING)
Lookup a backend by its name.
This function can only be used from ``vcl_init{}`` and ``vcl_fini{}``.
$Restrict housekeeping
ACKNOWLEDGEMENTS
================
......
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