summaryrefslogtreecommitdiff
path: root/caddyconfig
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-08-21 15:50:02 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-08-21 15:50:02 -0600
commitc0da7d487abcdcd9761220d75400f75584482b5f (patch)
tree2ea5f400a1c2bb58b8317d46f2e7f28006ee8351 /caddyconfig
parent8420a2f250cf467a06c0081cb47a8f73b70e7f3f (diff)
file_server: Automatically hide all involved Caddyfiles
Diffstat (limited to 'caddyconfig')
-rw-r--r--caddyconfig/httpcaddyfile/directives.go20
-rw-r--r--caddyconfig/httpcaddyfile/httptype.go1
2 files changed, 21 insertions, 0 deletions
diff --git a/caddyconfig/httpcaddyfile/directives.go b/caddyconfig/httpcaddyfile/directives.go
index 526ac87..dad27ba 100644
--- a/caddyconfig/httpcaddyfile/directives.go
+++ b/caddyconfig/httpcaddyfile/directives.go
@@ -81,6 +81,26 @@ type Helper struct {
*caddyfile.Dispenser
warnings *[]caddyconfig.Warning
matcherDefs map[string]map[string]json.RawMessage
+ parentBlock caddyfile.ServerBlock
+}
+
+// Caddyfiles returns the list of config files from
+// which tokens in the current server block were loaded.
+func (h Helper) Caddyfiles() []string {
+ // first obtain set of names of files involved
+ // in this server block, without duplicates
+ files := make(map[string]struct{})
+ for _, segment := range h.parentBlock.Segments {
+ for _, token := range segment {
+ files[token.File] = struct{}{}
+ }
+ }
+ // then convert the set into a slice
+ filesSlice := make([]string, 0, len(files))
+ for file := range files {
+ filesSlice = append(filesSlice, file)
+ }
+ return filesSlice
}
// JSON converts val into JSON. Any errors are added to warnings.
diff --git a/caddyconfig/httpcaddyfile/httptype.go b/caddyconfig/httpcaddyfile/httptype.go
index e7e7c87..00ce2cf 100644
--- a/caddyconfig/httpcaddyfile/httptype.go
+++ b/caddyconfig/httpcaddyfile/httptype.go
@@ -95,6 +95,7 @@ func (st ServerType) Setup(originalServerBlocks []caddyfile.ServerBlock,
Dispenser: caddyfile.NewDispenser(segment),
warnings: &warnings,
matcherDefs: matcherDefs,
+ parentBlock: sb.block,
})
if err != nil {
return nil, warnings, fmt.Errorf("parsing caddyfile tokens for '%s': %v", dir, err)