repoconfig

package
v0.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package repoconfig is a repo's settings file, .anfra/config.yml: committed, written by hand, and by anfra only through SetString, which changes nothing but the value it sets.

Index

Constants

View Source
const FileName = "config.yml"

FileName is the settings file, in the repo's config folder.

View Source
const RelPath = repo.ConfigDirName + "/" + FileName

RelPath is the settings file's path in a repo, as messages name it.

Variables

This section is empty.

Functions

func Hint

func Hint(section, key string) string

Hint is how a message names a setting, for a person to find it: ".anfra/config.yml org.url".

func Path

func Path(dir string) string

Path is the settings file of the repo at dir.

func SetString

func SetString(path, section, key, value string) error

SetString sets section.key to value in the YAML file at path, as git config sets a key: the file is parsed only to find where things are, and the new file is the old one's bytes with the value's bytes replaced, so comments, order and formatting are untouched; written to a lock file and renamed over the original, so a reader sees one or the other and two writers cannot interleave.

  • No file: it is created.
  • No section: a block for it is appended at the end, which disturbs nothing above it.
  • The key, a scalar on one line: its value's bytes are replaced.
  • Anything else (the section without the key, flow style, a value spanning lines): refused, naming the value to set by hand, rather than guessed at.

value must be a plain scalar that reads back as itself; the result is parsed again and checked before it replaces the file.

Types

type Config

type Config struct {
	Org struct {
		// URL is the org `anfra publish` publishes the repo to, by its address on
		// its server. Never a credential.
		URL string `yaml:"url"`
	} `yaml:"org"`
	Apps struct {
		// AllowOrigins are the origins the repo's Data Apps may load from beyond
		// the SDK's own CDNs, as `anfra serve` runs them. Never published: an org
		// holds its own list (AllowedOrigins checks them).
		AllowOrigins []string `yaml:"allow_origins"`
	} `yaml:"apps"`
	// Query is how the repo's queries run (docs/designs/query-settings.md).
	Query struct {
		// Default is what a query gets when it sets none: each key is the path
		// of the query's own field, in snake_case. Unset, anfra's own default.
		Default struct {
			Input struct {
				// Timezone is input.timezone's default, an IANA zone.
				Timezone string `yaml:"timezone"`
				// WeekStartDay is input.weekStartDay's default: monday to sunday.
				WeekStartDay string `yaml:"weekStartDay"`
			} `yaml:"input"`
			Cache struct {
				// Duration is cache.duration's default: how old a cached result
				// a query accepts, and how long the result it caches is kept.
				// Unset, a query that sets none doesn't use the cache.
				Duration string `yaml:"duration"`
			} `yaml:"cache"`
		} `yaml:"default"`
		// LockedDefaults are the paths of the defaults a query can't change, such
		// as input.weekStartDay. Each names a value Default sets.
		LockedDefaults []string `yaml:"locked_defaults"`
		Cache          struct {
			// Enabled turns the query cache off for the repo when false: no
			// store, no canal-lake. Unset is on.
			Enabled *bool `yaml:"enabled"`
			// MaxDuration is the longest a query's result may be cached, at most
			// querycache.MaxDuration, which it is when unset.
			MaxDuration string `yaml:"max_duration"`
		} `yaml:"cache"`
	} `yaml:"query"`
}

Config is what anfra reads from the settings file.

func Read

func Read(dir string) (Config, error)

Read is the settings of the repo at dir: none set when it has no file. A key anfra doesn't know, or a value it doesn't take, is an error rather than ignored, since an ignored setting fails without a sign.

func (Config) AllowedOrigins added in v0.12.0

func (c Config) AllowedOrigins() ([]string, error)

AllowedOrigins is apps.allow_origins, each an origin a Data App's content policy can take (repoformat.CheckOrigin), or an error naming the first that is not.

func (Config) QueryCacheEnabled added in v0.21.0

func (c Config) QueryCacheEnabled() bool

QueryCacheEnabled is query.cache.enabled: on unless the repo sets false.

func (Config) QueryCacheSettings added in v0.21.0

func (c Config) QueryCacheSettings() command.QueryCacheSettings

QueryCacheSettings are query.cache's rules the engine takes: its cap, zero when unset. Whether the cache is off is the host's to decide, since the environment can override the file. Read checked them.

func (Config) QueryDefaults added in v0.21.0

func (c Config) QueryDefaults() command.QueryDefaults

QueryDefaults are query.default and query.locked_defaults, as the engine takes them: the one place the file's defaults become a query's. Read checked them.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL