117 lines
3.1 KiB
Go
117 lines
3.1 KiB
Go
package config
|
|
|
|
import "gitea.maximumdirect.net/eric/distributor/internal/transform"
|
|
|
|
const DefaultConfigPath = "/usr/local/etc/distributor/config.yml"
|
|
|
|
const (
|
|
BackendLocal = "local"
|
|
BackendSSH = "ssh"
|
|
BackendS3 = "s3"
|
|
)
|
|
|
|
const (
|
|
ValidationActionFail = "fail"
|
|
)
|
|
|
|
const (
|
|
TransferActionSkip = "skip"
|
|
TransferActionReplace = "replace"
|
|
TransferActionFail = "fail"
|
|
)
|
|
|
|
const (
|
|
TransformModeSidecar = transform.MarkdownModeSidecar
|
|
TransformModeIndex = transform.MarkdownModeIndex
|
|
)
|
|
|
|
const (
|
|
PathMappingPreserveRelative = "preserve_relative"
|
|
PathMappingFixed = "fixed"
|
|
)
|
|
|
|
const (
|
|
LinkPrimaryAuto = "auto"
|
|
LinkPrimaryHTML = "html"
|
|
LinkPrimarySource = "source"
|
|
)
|
|
|
|
const DefaultS3Region = "us-east-1"
|
|
|
|
func ApplyDefaults(cfg *Config) {
|
|
for pipelineIndex := range cfg.Pipelines {
|
|
pipeline := &cfg.Pipelines[pipelineIndex]
|
|
applyBackendDefaults(&pipeline.Source)
|
|
if pipeline.Validation.OnDigestMismatch == "" {
|
|
pipeline.Validation.OnDigestMismatch = ValidationActionFail
|
|
}
|
|
for destinationIndex := range pipeline.Destinations {
|
|
destination := &pipeline.Destinations[destinationIndex]
|
|
applyDestinationDefaults(destination)
|
|
if destination.Publish == nil {
|
|
destination.Publish = &PublishPolicy{Source: true}
|
|
}
|
|
if destination.Transform.MarkdownToHTML != nil && destination.Transform.MarkdownToHTML.Mode == "" {
|
|
destination.Transform.MarkdownToHTML.Mode = TransformModeSidecar
|
|
}
|
|
if destination.PathMap.Mode == "" {
|
|
destination.PathMap.Mode = PathMappingPreserveRelative
|
|
}
|
|
if destination.Links != nil && destination.Links.Primary == "" {
|
|
destination.Links.Primary = LinkPrimaryAuto
|
|
}
|
|
if destination.Transfer.OnDestinationSame == "" {
|
|
destination.Transfer.OnDestinationSame = TransferActionSkip
|
|
}
|
|
if destination.Transfer.OnDestinationOlder == "" {
|
|
destination.Transfer.OnDestinationOlder = TransferActionReplace
|
|
}
|
|
if destination.Transfer.OnDestinationNewer == "" {
|
|
destination.Transfer.OnDestinationNewer = TransferActionSkip
|
|
}
|
|
if destination.Transfer.OnConflict == "" {
|
|
destination.Transfer.OnConflict = TransferActionFail
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func applyBackendDefaults(backend *Backend) {
|
|
if backend.Backend == BackendSSH {
|
|
if backend.Port == 0 {
|
|
backend.Port = 22
|
|
}
|
|
if backend.SSH.HostKeyPolicy == "" {
|
|
backend.SSH.HostKeyPolicy = HostKeyPolicyAcceptNew
|
|
}
|
|
}
|
|
if backend.Backend == BackendS3 {
|
|
applyS3Defaults(&backend.Region, &backend.Prefix, &backend.ForcePath)
|
|
}
|
|
}
|
|
|
|
func applyDestinationDefaults(destination *Destination) {
|
|
if destination.Backend == BackendSSH {
|
|
if destination.Port == 0 {
|
|
destination.Port = 22
|
|
}
|
|
if destination.SSH.HostKeyPolicy == "" {
|
|
destination.SSH.HostKeyPolicy = HostKeyPolicyAcceptNew
|
|
}
|
|
}
|
|
if destination.Backend == BackendS3 {
|
|
applyS3Defaults(&destination.Region, &destination.Prefix, &destination.ForcePath)
|
|
}
|
|
}
|
|
|
|
func applyS3Defaults(region, prefix *string, forcePath **bool) {
|
|
if *region == "" {
|
|
*region = DefaultS3Region
|
|
}
|
|
*prefix = NormalizeS3Prefix(*prefix)
|
|
if *forcePath == nil {
|
|
defaultForcePath := true
|
|
*forcePath = &defaultForcePath
|
|
}
|
|
}
|