mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
Support env vars in import; make sure it's a file
This commit is contained in:
parent
c5524b0bab
commit
8b8afd72d7
1 changed files with 12 additions and 2 deletions
|
@ -201,11 +201,14 @@ func (p *parser) directives() error {
|
||||||
// other words, call Next() to access the first token that was
|
// other words, call Next() to access the first token that was
|
||||||
// imported.
|
// imported.
|
||||||
func (p *parser) doImport() error {
|
func (p *parser) doImport() error {
|
||||||
// syntax check
|
// syntax checks
|
||||||
if !p.NextArg() {
|
if !p.NextArg() {
|
||||||
return p.ArgErr()
|
return p.ArgErr()
|
||||||
}
|
}
|
||||||
importPattern := p.Val()
|
importPattern := replaceEnvVars(p.Val())
|
||||||
|
if importPattern == "" {
|
||||||
|
return p.Err("Import requires a non-empty filepath")
|
||||||
|
}
|
||||||
if p.NextArg() {
|
if p.NextArg() {
|
||||||
return p.Err("Import takes only one argument (glob pattern or file)")
|
return p.Err("Import takes only one argument (glob pattern or file)")
|
||||||
}
|
}
|
||||||
|
@ -284,6 +287,13 @@ func (p *parser) doSingleImport(importFile string) ([]Token, error) {
|
||||||
return nil, p.Errf("Could not import %s: %v", importFile, err)
|
return nil, p.Errf("Could not import %s: %v", importFile, err)
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
|
if info, err := file.Stat(); err != nil {
|
||||||
|
return nil, p.Errf("Could not import %s: %v", importFile, err)
|
||||||
|
} else if info.IsDir() {
|
||||||
|
return nil, p.Errf("Could not import %s: is a directory", importFile)
|
||||||
|
}
|
||||||
|
|
||||||
importedTokens := allTokens(file)
|
importedTokens := allTokens(file)
|
||||||
|
|
||||||
// Tack the filename onto these tokens so errors show the imported file's name
|
// Tack the filename onto these tokens so errors show the imported file's name
|
||||||
|
|
Loading…
Reference in a new issue