Pull request 2111: 6545-schema-version

Updates #6545.

Squashed commit of the following:

commit b1969128a99ff21c97feb4e7805b4b8133d7122f
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Fri Dec 15 20:04:37 2023 +0300

    home: fix import

commit 872ccea1491a8da76cc24db79247438d0ce4d256
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Fri Dec 15 20:01:15 2023 +0300

    all: output schema version
This commit is contained in:
Ainar Garipov 2023-12-15 20:27:47 +03:00
parent 9241393ed2
commit d32832735c
92 changed files with 86 additions and 80 deletions

View File

@ -25,6 +25,9 @@ NOTE: Add new changes BELOW THIS COMMENT.
### Added
- The schema version of the configuration file to the output of running
`AdGuardHome` (or `AdGuardHome.exe) with `-v --version` command-line options
([#6545]).
- Ability to disable plain-DNS serving via UI if an encrypted protocol is
already used ([#1660]).
@ -34,6 +37,7 @@ NOTE: Add new changes BELOW THIS COMMENT.
work on iOS ([#6352]).
[#6352]: https://github.com/AdguardTeam/AdGuardHome/issues/6352
[#6545]: https://github.com/AdguardTeam/AdGuardHome/issues/6545
<!--
NOTE: Add new changes ABOVE THIS COMMENT.

View File

@ -0,0 +1,5 @@
// Package configmigrate provides a way to upgrade the YAML configuration file.
package configmigrate
// LastSchemaVersion is the most recent schema version.
const LastSchemaVersion uint = 27

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
import (
"testing"

View File

@ -1,5 +1,4 @@
// Package confmigrate provides a way to upgrade the YAML configuration file.
package confmigrate
package configmigrate
import (
"bytes"
@ -9,9 +8,6 @@ import (
yaml "gopkg.in/yaml.v3"
)
// LastSchemaVersion is the most recent schema version.
const LastSchemaVersion uint = 27
// Config is a the configuration for initializing a [Migrator].
type Config struct {
// WorkingDir is an absolute path to the working directory of AdGuardHome.

View File

@ -1,4 +1,4 @@
package confmigrate_test
package configmigrate_test
import (
"io/fs"
@ -6,7 +6,7 @@ import (
"path"
"testing"
"github.com/AdguardTeam/AdGuardHome/internal/confmigrate"
"github.com/AdguardTeam/AdGuardHome/internal/configmigrate"
"github.com/AdguardTeam/golibs/testutil"
"github.com/stretchr/testify/require"
"golang.org/x/crypto/bcrypt"
@ -200,7 +200,7 @@ func TestMigrateConfig_Migrate(t *testing.T) {
wantBody, err := fs.ReadFile(testdata, path.Join(t.Name(), outputFileName))
require.NoError(t, err)
migrator := confmigrate.New(&confmigrate.Config{
migrator := configmigrate.New(&configmigrate.Config{
WorkingDir: t.Name(),
})
newBody, upgraded, err := migrator.Migrate(body, tc.targetVersion)

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
import (
"os"

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
import (
"fmt"

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
// migrateTo11 performs the following changes:
//

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
import (
"time"

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
// migrateTo13 performs the following changes:
//

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
// migrateTo14 performs the following changes:
//

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
// migrateTo15 performs the following changes:
//

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
// migrateTo16 performs the following changes:
//

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
// migrateTo17 performs the following changes:
//

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
// migrateTo18 performs the following changes:
//

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
import "github.com/AdguardTeam/golibs/log"

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
import (
"os"

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
import (
"time"

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
// migrateTo21 performs the following changes:
//

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
import (
"fmt"

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
import (
"fmt"

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
// migrateTo24 performs the following changes:
//

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
// migrateTo25 performs the following changes:
//

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
// migrateTo26 performs the following changes:
//

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
// migrateTo27 performs the following changes:
//

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
// migrateTo3 performs the following changes:
//

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
// migrateTo4 performs the following changes:
//

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
import (
"fmt"

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
import "fmt"

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
// migrateTo7 performs the following changes:
//

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
// migrateTo8 performs the following changes:
//

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
// migrateTo9 performs the following changes:
//

View File

@ -1,4 +1,4 @@
package confmigrate
package configmigrate
import (
"fmt"

View File

@ -10,7 +10,7 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/aghalg"
"github.com/AdguardTeam/AdGuardHome/internal/aghtls"
"github.com/AdguardTeam/AdGuardHome/internal/confmigrate"
"github.com/AdguardTeam/AdGuardHome/internal/configmigrate"
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
@ -149,7 +149,7 @@ type configuration struct {
sync.RWMutex `yaml:"-"`
// SchemaVersion is the version of the configuration schema. See
// [confmigrate.LastSchemaVersion].
// [configmigrate.LastSchemaVersion].
SchemaVersion uint `yaml:"schema_version"`
}
@ -434,7 +434,7 @@ var config = &configuration{
MaxAge: 3,
},
OSConfig: &osConfig{},
SchemaVersion: confmigrate.LastSchemaVersion,
SchemaVersion: configmigrate.LastSchemaVersion,
Theme: ThemeAuto,
}
@ -479,14 +479,14 @@ func parseConfig() (err error) {
return err
}
migrator := confmigrate.New(&confmigrate.Config{
migrator := configmigrate.New(&configmigrate.Config{
WorkingDir: Context.workDir,
})
var upgraded bool
config.fileData, upgraded, err = migrator.Migrate(
config.fileData,
confmigrate.LastSchemaVersion,
configmigrate.LastSchemaVersion,
)
if err != nil {
// Don't wrap the error, because it's informative enough as is.

View File

@ -7,6 +7,7 @@ import (
"strconv"
"strings"
"github.com/AdguardTeam/AdGuardHome/internal/configmigrate"
"github.com/AdguardTeam/AdGuardHome/internal/version"
"github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/stringutil"
@ -308,7 +309,7 @@ var cmdLineOpts = []cmdLineOpt{{
effect: func(o options, exec string) (effect, error) {
return func() error {
if o.verbose {
fmt.Println(version.Verbose())
fmt.Print(version.Verbose(configmigrate.LastSchemaVersion))
} else {
fmt.Println(version.Full())
}

View File

@ -10,6 +10,7 @@ import (
"os"
"strings"
"github.com/AdguardTeam/AdGuardHome/internal/configmigrate"
"github.com/AdguardTeam/AdGuardHome/internal/next/configmgr"
"github.com/AdguardTeam/AdGuardHome/internal/version"
"github.com/AdguardTeam/golibs/log"
@ -382,7 +383,7 @@ func processOptions(
if opts.version {
if opts.verbose {
fmt.Println(version.Verbose())
fmt.Print(version.Verbose(configmigrate.LastSchemaVersion))
} else {
fmt.Printf("AdGuard Home %s\n", version.Version())
}

View File

@ -98,6 +98,7 @@ func fmtModule(m *debug.Module) (formatted string) {
const (
vFmtAGHHdr = "AdGuard Home"
vFmtVerHdr = "Version: "
vFmtSchemaVerHdr = "Schema version: "
vFmtChanHdr = "Channel: "
vFmtGoHdr = "Go version: "
vFmtTimeHdr = "Commit time: "
@ -113,6 +114,7 @@ const (
//
// AdGuard Home
// Version: v0.105.3
// Schema version: 27
// Channel: development
// Go version: go1.15.3
// Build time: 2021-03-30T16:26:08Z+0300
@ -125,34 +127,31 @@ const (
// ...
//
// TODO(e.burkov): Make it write into passed io.Writer.
func Verbose() (v string) {
func Verbose(schemaVersion uint) (v string) {
b := &strings.Builder{}
const nl = "\n"
stringutil.WriteToBuilder(
b,
vFmtAGHHdr,
nl,
vFmtVerHdr,
version,
nl,
vFmtChanHdr,
channel,
nl,
vFmtGoHdr,
runtime.Version(),
)
stringutil.WriteToBuilder(b, vFmtAGHHdr, nl)
stringutil.WriteToBuilder(b, vFmtVerHdr, version, nl)
schemaVerStr := strconv.FormatUint(uint64(schemaVersion), 10)
stringutil.WriteToBuilder(b, vFmtSchemaVerHdr, schemaVerStr, nl)
stringutil.WriteToBuilder(b, vFmtChanHdr, channel, nl)
stringutil.WriteToBuilder(b, vFmtGoHdr, runtime.Version(), nl)
writeCommitTime(b)
stringutil.WriteToBuilder(b, nl, vFmtGOOSHdr, nl, vFmtGOARCHHdr)
stringutil.WriteToBuilder(b, vFmtGOOSHdr, nl)
stringutil.WriteToBuilder(b, vFmtGOARCHHdr, nl)
if goarm != "" {
stringutil.WriteToBuilder(b, nl, vFmtGOARMHdr, "v", goarm)
stringutil.WriteToBuilder(b, vFmtGOARMHdr, "v", goarm, nl)
} else if gomips != "" {
stringutil.WriteToBuilder(b, nl, vFmtGOMIPSHdr, gomips)
stringutil.WriteToBuilder(b, vFmtGOMIPSHdr, gomips, nl)
}
stringutil.WriteToBuilder(b, nl, vFmtRaceHdr, strconv.FormatBool(isRace))
stringutil.WriteToBuilder(b, vFmtRaceHdr, strconv.FormatBool(isRace), nl)
info, ok := debug.ReadBuildInfo()
if !ok {
@ -163,10 +162,10 @@ func Verbose() (v string) {
return b.String()
}
stringutil.WriteToBuilder(b, nl, vFmtDepsHdr)
stringutil.WriteToBuilder(b, vFmtDepsHdr, nl)
for _, dep := range info.Deps {
if depStr := fmtModule(dep); depStr != "" {
stringutil.WriteToBuilder(b, "\n\t", depStr)
stringutil.WriteToBuilder(b, "\t", depStr, nl)
}
}
@ -180,8 +179,8 @@ func writeCommitTime(b *strings.Builder) {
commitTimeUnix, err := strconv.ParseInt(committime, 10, 64)
if err != nil {
stringutil.WriteToBuilder(b, "\n", vFmtTimeHdr, fmt.Sprintf("parse error: %s", err))
stringutil.WriteToBuilder(b, vFmtTimeHdr, fmt.Sprintf("parse error: %s", err), "\n")
} else {
stringutil.WriteToBuilder(b, "\n", vFmtTimeHdr, time.Unix(commitTimeUnix, 0).String())
stringutil.WriteToBuilder(b, vFmtTimeHdr, time.Unix(commitTimeUnix, 0).String(), "\n")
}
}

View File

@ -211,7 +211,7 @@ run_linter gocognit --over='10'\
./internal/aghtest/\
./internal/arpdb/\
./internal/client/\
./internal/confmigrate/\
./internal/configmigrate/\
./internal/dhcpsvc\
./internal/dnsforward/\
./internal/filtering/hashprefix/\
@ -250,7 +250,7 @@ run_linter fieldalignment \
./internal/aghtls/\
./internal/arpdb/\
./internal/client/\
./internal/confmigrate/\
./internal/configmigrate/\
./internal/dhcpsvc/\
./internal/filtering/hashprefix/\
./internal/filtering/rewrite/\
@ -280,7 +280,7 @@ run_linter gosec --quiet\
./internal/aghtest/\
./internal/arpdb/\
./internal/client/\
./internal/confmigrate/\
./internal/configmigrate/\
./internal/dhcpd/\
./internal/dhcpsvc/\
./internal/dnsforward/\