prefixes: Add 'resolver-blocked.txt' config
This commit is contained in:
parent
6f2ba18227
commit
3be5e85ef7
12 changed files with 95 additions and 19 deletions
|
|
@ -143,7 +143,7 @@ func (bs bootstrap) Run(context wisski_distillery.Context) error {
|
||||||
core.DefaultOverridesJSON,
|
core.DefaultOverridesJSON,
|
||||||
fs.ModePerm,
|
fs.ModePerm,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return errBootstrapCreateFile.WithMessageF(err)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
context.Println(tpl.AuthorizedKeys)
|
context.Println(tpl.AuthorizedKeys)
|
||||||
|
|
@ -153,12 +153,22 @@ func (bs bootstrap) Run(context wisski_distillery.Context) error {
|
||||||
core.DefaultAuthorizedKeys,
|
core.DefaultAuthorizedKeys,
|
||||||
fs.ModePerm,
|
fs.ModePerm,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return errBootstrapCreateFile.WithMessageF(err)
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
context.Println(tpl.SelfResolverBlockFile)
|
||||||
|
if err := environment.WriteFile(
|
||||||
|
env,
|
||||||
|
tpl.SelfResolverBlockFile,
|
||||||
|
core.DefaultResolverBlockedTXT,
|
||||||
|
fs.ModePerm,
|
||||||
|
); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}, context.IOStream, "Creating additional config files"); err != nil {
|
}, context.IOStream, "Creating additional config files"); err != nil {
|
||||||
return err
|
return errBootstrapCreateFile.WithMessageF(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,9 @@ func (upc updateprefixconfig) Run(context wisski_distillery.Context) error {
|
||||||
// read the prefix config
|
// read the prefix config
|
||||||
data, err := instance.PrefixConfig()
|
data, err := instance.PrefixConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
data = "# error, skipped\n"
|
||||||
|
context.EPrintln(err)
|
||||||
|
err = nil
|
||||||
}
|
}
|
||||||
context.IOStream.Printf("%s", data)
|
context.IOStream.Printf("%s", data)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ func (control *Control) backupFiles() []string {
|
||||||
control.Config.ConfigPath,
|
control.Config.ConfigPath,
|
||||||
control.Config.ExecutablePath(),
|
control.Config.ExecutablePath(),
|
||||||
control.Config.SelfOverridesFile,
|
control.Config.SelfOverridesFile,
|
||||||
|
control.Config.SelfResolverBlockFile,
|
||||||
control.Config.GlobalAuthorizedKeysFile,
|
control.Config.GlobalAuthorizedKeysFile,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,4 +6,5 @@ LETSENCRYPT_EMAIL=${LETSENCRYPT_EMAIL}
|
||||||
CONFIG_PATH=${CONFIG_PATH}
|
CONFIG_PATH=${CONFIG_PATH}
|
||||||
DEPLOY_ROOT=${DEPLOY_ROOT}
|
DEPLOY_ROOT=${DEPLOY_ROOT}
|
||||||
GLOBAL_AUTHORIZED_KEYS_FILE=${GLOBAL_AUTHORIZED_KEYS_FILE}
|
GLOBAL_AUTHORIZED_KEYS_FILE=${GLOBAL_AUTHORIZED_KEYS_FILE}
|
||||||
SELF_OVERRIDES_FILE=${SELF_OVERRIDES_FILE}
|
SELF_OVERRIDES_FILE=${SELF_OVERRIDES_FILE}
|
||||||
|
SELF_RESOLVER_BLOCK_FILE=${SELF_RESOLVER_BLOCK_FILE}
|
||||||
|
|
@ -46,6 +46,7 @@ func (control *Control) Stack(env environment.Environment) component.StackWithRe
|
||||||
|
|
||||||
"GLOBAL_AUTHORIZED_KEYS_FILE": control.Config.GlobalAuthorizedKeysFile,
|
"GLOBAL_AUTHORIZED_KEYS_FILE": control.Config.GlobalAuthorizedKeysFile,
|
||||||
"SELF_OVERRIDES_FILE": control.Config.SelfOverridesFile,
|
"SELF_OVERRIDES_FILE": control.Config.SelfOverridesFile,
|
||||||
|
"SELF_RESOLVER_BLOCK_FILE": control.Config.SelfResolverBlockFile,
|
||||||
},
|
},
|
||||||
|
|
||||||
TouchFiles: []string{control.ResolverFile},
|
TouchFiles: []string{control.ResolverFile},
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ services:
|
||||||
- "${DEPLOY_ROOT}:${DEPLOY_ROOT}:ro"
|
- "${DEPLOY_ROOT}:${DEPLOY_ROOT}:ro"
|
||||||
- "${GLOBAL_AUTHORIZED_KEYS_FILE}:${GLOBAL_AUTHORIZED_KEYS_FILE}:ro"
|
- "${GLOBAL_AUTHORIZED_KEYS_FILE}:${GLOBAL_AUTHORIZED_KEYS_FILE}:ro"
|
||||||
- "${SELF_OVERRIDES_FILE}:${SELF_OVERRIDES_FILE}:ro"
|
- "${SELF_OVERRIDES_FILE}:${SELF_OVERRIDES_FILE}:ro"
|
||||||
|
- "${SELF_RESOLVER_BLOCK_FILE}:${SELF_RESOLVER_BLOCK_FILE}:ro"
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package instances
|
package instances
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"bufio"
|
||||||
"io"
|
"io"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -25,7 +25,7 @@ var listURIPrefixesPHP string
|
||||||
// Prefixes returns the prefixes
|
// Prefixes returns the prefixes
|
||||||
func (wisski *WissKI) Prefixes() (prefixes []string, err error) {
|
func (wisski *WissKI) Prefixes() (prefixes []string, err error) {
|
||||||
// get all the ugly prefixes
|
// get all the ugly prefixes
|
||||||
err = wisski.ExecPHPScript(stream.FromEnv(), &prefixes, listURIPrefixesPHP, "list_prefixes")
|
err = wisski.ExecPHPScript(stream.FromNil(), &prefixes, listURIPrefixesPHP, "list_prefixes")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -35,29 +35,53 @@ func (wisski *WissKI) Prefixes() (prefixes []string, err error) {
|
||||||
return strings.HasPrefix(now, prev)
|
return strings.HasPrefix(now, prev)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// load the list of blocked prefixes
|
||||||
|
blocks, err := wisski.instances.BlockedPrefixes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// filter out blocked prefixes
|
// filter out blocked prefixes
|
||||||
return slicesx.Filter(prefixes, func(uri string) bool { return !IsNonServedURI(uri) }), nil
|
return slicesx.Filter(prefixes, func(uri string) bool { return !hasAnyPrefix(uri, blocks) }), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Eventually move this into a configuration file.
|
func (instances *Instances) BlockedPrefixes() ([]string, error) {
|
||||||
// But for now this is fine
|
// open the resolver block file
|
||||||
var blockedURIs = []string{
|
file, err := instances.Environment.Open(instances.Config.SelfResolverBlockFile)
|
||||||
"http://erlangen-crm.org/",
|
if err != nil {
|
||||||
"http://www.w3.org/",
|
return nil, err
|
||||||
"xsd:",
|
}
|
||||||
|
|
||||||
|
var lines []string
|
||||||
|
|
||||||
|
// read all the lines that aren't a comment!
|
||||||
|
scanner := bufio.NewScanner(file)
|
||||||
|
for scanner.Scan() {
|
||||||
|
line := strings.TrimSpace(scanner.Text())
|
||||||
|
if line == "" || strings.HasPrefix(line, "//") || strings.HasPrefix(line, "#") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
lines = append(lines, line)
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if there was an error
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// and done!
|
||||||
|
return lines, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsNonServedURI(candidate string) bool {
|
func hasAnyPrefix(candidate string, prefixes []string) bool {
|
||||||
return slicesx.Any(
|
return slicesx.Any(
|
||||||
blockedURIs,
|
prefixes,
|
||||||
func(prefix string) bool {
|
func(prefix string) bool {
|
||||||
return strings.HasPrefix(candidate, prefix)
|
return strings.HasPrefix(candidate, prefix)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
var errPrefixExecFailed = errors.New("PrefixConfig: Failed to call list_uri_prefixes")
|
|
||||||
|
|
||||||
// PrefixConfig returns the prefix config belonging to this instance.
|
// PrefixConfig returns the prefix config belonging to this instance.
|
||||||
func (wisski *WissKI) PrefixConfig() (config string, err error) {
|
func (wisski *WissKI) PrefixConfig() (config string, err error) {
|
||||||
// if the user requested to skip the prefix, then don't do anything with it!
|
// if the user requested to skip the prefix, then don't do anything with it!
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,10 @@ type Config struct {
|
||||||
// Do this by adding URLs (without trailing '/'s) into a JSON file
|
// Do this by adding URLs (without trailing '/'s) into a JSON file
|
||||||
SelfOverridesFile string `env:"SELF_OVERRIDES_FILE" default:"" parser:"file"`
|
SelfOverridesFile string `env:"SELF_OVERRIDES_FILE" default:"" parser:"file"`
|
||||||
|
|
||||||
|
// You can block specific prefixes from being picked up by the resolver.
|
||||||
|
// Do this by adding one prefix per file.
|
||||||
|
SelfResolverBlockFile string `env:"SELF_RESOLVER_BLOCK_FILE" default:"" parser:"file"`
|
||||||
|
|
||||||
// The system can support setting up certificate(s) automatically.
|
// The system can support setting up certificate(s) automatically.
|
||||||
// It can be enabled by setting an email for certbot certificates.
|
// It can be enabled by setting an email for certbot certificates.
|
||||||
// This email address can be configured here.
|
// This email address can be configured here.
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,10 @@ SELF_EXTRA_DOMAINS=
|
||||||
# Do this by adding URLs (without trailing '/'s) into a JSON file
|
# Do this by adding URLs (without trailing '/'s) into a JSON file
|
||||||
SELF_OVERRIDES_FILE=${SELF_OVERRIDES_FILE}
|
SELF_OVERRIDES_FILE=${SELF_OVERRIDES_FILE}
|
||||||
|
|
||||||
|
# You can block specific prefixes within Triplestore from showing up in the resolver configuration file.
|
||||||
|
# Do this by adding one prefix per line in this file.
|
||||||
|
SELF_RESOLVER_BLOCK_FILE=${SELF_RESOLVER_BLOCK_FILE}
|
||||||
|
|
||||||
# The system can support setting up certificate(s) automatically.
|
# The system can support setting up certificate(s) automatically.
|
||||||
# It can be enabled by setting an email for certbot certificates.
|
# It can be enabled by setting an email for certbot certificates.
|
||||||
# This email address can be configured here.
|
# This email address can be configured here.
|
||||||
|
|
@ -28,7 +32,6 @@ CERTBOT_EMAIL=
|
||||||
# Backups older than this will be removed when a new backup is made.
|
# Backups older than this will be removed when a new backup is made.
|
||||||
MAX_BACKUP_AGE=30
|
MAX_BACKUP_AGE=30
|
||||||
|
|
||||||
|
|
||||||
# Each Drupal instance requires a corresponding system user, database users and databases.
|
# Each Drupal instance requires a corresponding system user, database users and databases.
|
||||||
# These are also set by the appropriate domain name.
|
# These are also set by the appropriate domain name.
|
||||||
# To differentiate them from other users of the system, these names can be prefixed.
|
# To differentiate them from other users of the system, these names can be prefixed.
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ type Template struct {
|
||||||
DeployRoot string `env:"DEPLOY_ROOT"`
|
DeployRoot string `env:"DEPLOY_ROOT"`
|
||||||
DefaultDomain string `env:"DEFAULT_DOMAIN"`
|
DefaultDomain string `env:"DEFAULT_DOMAIN"`
|
||||||
SelfOverridesFile string `env:"SELF_OVERRIDES_FILE"`
|
SelfOverridesFile string `env:"SELF_OVERRIDES_FILE"`
|
||||||
|
SelfResolverBlockFile string `env:"SELF_RESOLVER_BLOCK_FILE"`
|
||||||
AuthorizedKeys string `env:"AUTHORIZED_KEYS_FILE"`
|
AuthorizedKeys string `env:"AUTHORIZED_KEYS_FILE"`
|
||||||
TriplestoreAdminUser string `env:"GRAPHDB_ADMIN_USER"`
|
TriplestoreAdminUser string `env:"GRAPHDB_ADMIN_USER"`
|
||||||
TriplestoreAdminPassword string `env:"GRAPHDB_ADMIN_PASSWORD"`
|
TriplestoreAdminPassword string `env:"GRAPHDB_ADMIN_PASSWORD"`
|
||||||
|
|
@ -43,6 +44,10 @@ func (tpl *Template) SetDefaults(env environment.Environment) (err error) {
|
||||||
tpl.SelfOverridesFile = filepath.Join(tpl.DeployRoot, core.OverridesJSON)
|
tpl.SelfOverridesFile = filepath.Join(tpl.DeployRoot, core.OverridesJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tpl.SelfResolverBlockFile == "" {
|
||||||
|
tpl.SelfResolverBlockFile = filepath.Join(tpl.DeployRoot, core.ResolverBlockedTXT)
|
||||||
|
}
|
||||||
|
|
||||||
if tpl.AuthorizedKeys == "" {
|
if tpl.AuthorizedKeys == "" {
|
||||||
tpl.AuthorizedKeys = filepath.Join(tpl.DeployRoot, core.AuthorizedKeys)
|
tpl.AuthorizedKeys = filepath.Join(tpl.DeployRoot, core.AuthorizedKeys)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
16
internal/core/bootstrap/resolver-blocked.txt
Normal file
16
internal/core/bootstrap/resolver-blocked.txt
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
# This file contains prefixes that should not be picked up by the global resolver.
|
||||||
|
# They will not appear in the list of prefixes.
|
||||||
|
# It should be one prefix per line, '#' and '//' as well as blank lines are treated as comments
|
||||||
|
|
||||||
|
# definitely shouldn't be resolved to any WissKI
|
||||||
|
http://www.w3.org/
|
||||||
|
xsd:
|
||||||
|
urn:
|
||||||
|
|
||||||
|
# generic prefixes by some common adapters.
|
||||||
|
# you may or may not want these.
|
||||||
|
http://d-nb.info/gnd/
|
||||||
|
http://erlangen-crm.org/
|
||||||
|
http://id.gnm.de/ont/
|
||||||
|
http://zotero.org/
|
||||||
|
https://api.zotero.org/
|
||||||
|
|
@ -23,6 +23,14 @@ const OverridesJSON = "overrides.json"
|
||||||
//go:embed bootstrap/overrides.json
|
//go:embed bootstrap/overrides.json
|
||||||
var DefaultOverridesJSON []byte
|
var DefaultOverridesJSON []byte
|
||||||
|
|
||||||
|
// ResolverBlockTXT is the name of the resolver blocked prefix file.
|
||||||
|
// It should be located inside the deployment directory.
|
||||||
|
const ResolverBlockedTXT = "resolver-blocked.txt"
|
||||||
|
|
||||||
|
// ResolverBlockTXT contains a template for 'resolver-blocked' file
|
||||||
|
//go:embed bootstrap/resolver-blocked.txt
|
||||||
|
var DefaultResolverBlockedTXT []byte
|
||||||
|
|
||||||
// AuthorizedKeys contains the default name for the 'global_authorized_keys' file
|
// AuthorizedKeys contains the default name for the 'global_authorized_keys' file
|
||||||
const AuthorizedKeys = "authorized_keys"
|
const AuthorizedKeys = "authorized_keys"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue