Merge branch 'master' into remove-keep-nameserver
This commit is contained in:
2
.github/workflows/markdown.yml
vendored
2
.github/workflows/markdown.yml
vendored
@@ -20,7 +20,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
|
|
||||||
- uses: DavidAnson/markdownlint-cli2-action@v20
|
- uses: DavidAnson/markdownlint-cli2-action@v21
|
||||||
with:
|
with:
|
||||||
globs: "**.md"
|
globs: "**.md"
|
||||||
config: .markdownlint-cli2.jsonc
|
config: .markdownlint-cli2.jsonc
|
||||||
|
|||||||
@@ -7,3 +7,4 @@ func newNoopLogger() *noopLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *noopLogger) Info(string) {}
|
func (l *noopLogger) Info(string) {}
|
||||||
|
func (l *noopLogger) Warn(string) {}
|
||||||
|
|||||||
@@ -81,7 +81,11 @@ func (c *CLI) Update(ctx context.Context, args []string, logger UpdaterLogger) e
|
|||||||
return fmt.Errorf("options validation failed: %w", err)
|
return fmt.Errorf("options validation failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
storage, err := storage.New(logger, constants.ServersData)
|
serversDataPath := constants.ServersData
|
||||||
|
if maintainerMode {
|
||||||
|
serversDataPath = ""
|
||||||
|
}
|
||||||
|
storage, err := storage.New(logger, serversDataPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("creating servers storage: %w", err)
|
return fmt.Errorf("creating servers storage: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
l.backoffTime = defaultBackoffTime
|
l.backoffTime = defaultBackoffTime
|
||||||
l.logger.Info("ready")
|
l.logger.Info("ready")
|
||||||
l.signalOrSetStatus(constants.Running)
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,6 +53,7 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
|
|||||||
}
|
}
|
||||||
l.logAndWait(ctx, err)
|
l.logAndWait(ctx, err)
|
||||||
}
|
}
|
||||||
|
l.signalOrSetStatus(constants.Running)
|
||||||
|
|
||||||
const fallback = false
|
const fallback = false
|
||||||
l.useUnencryptedDNS(fallback)
|
l.useUnencryptedDNS(fallback)
|
||||||
|
|||||||
@@ -371,7 +371,7 @@ func (c *apiClient) authInfo(ctx context.Context, username string, unauthCookie
|
|||||||
case info.SRPSession == "":
|
case info.SRPSession == "":
|
||||||
return "", "", "", "", 0, fmt.Errorf("%w: SRP session is empty", ErrDataFieldMissing)
|
return "", "", "", "", 0, fmt.Errorf("%w: SRP session is empty", ErrDataFieldMissing)
|
||||||
|
|
||||||
case info.Username != username:
|
case !strings.EqualFold(info.Username, username):
|
||||||
return "", "", "", "", 0, fmt.Errorf("%w: expected %s got %s",
|
return "", "", "", "", 0, fmt.Errorf("%w: expected %s got %s",
|
||||||
ErrUsernameMismatch, username, info.Username)
|
ErrUsernameMismatch, username, info.Username)
|
||||||
case info.Version == nil:
|
case info.Version == nil:
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
package storage
|
package storage
|
||||||
|
|
||||||
//go:generate mockgen -destination=mocks_test.go -package $GOPACKAGE . Infoer
|
//go:generate mockgen -destination=mocks_test.go -package $GOPACKAGE . Logger
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// Code generated by MockGen. DO NOT EDIT.
|
// Code generated by MockGen. DO NOT EDIT.
|
||||||
// Source: github.com/qdm12/gluetun/internal/storage (interfaces: Infoer)
|
// Source: github.com/qdm12/gluetun/internal/storage (interfaces: Logger)
|
||||||
|
|
||||||
// Package storage is a generated GoMock package.
|
// Package storage is a generated GoMock package.
|
||||||
package storage
|
package storage
|
||||||
@@ -10,37 +10,49 @@ import (
|
|||||||
gomock "github.com/golang/mock/gomock"
|
gomock "github.com/golang/mock/gomock"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MockInfoer is a mock of Infoer interface.
|
// MockLogger is a mock of Logger interface.
|
||||||
type MockInfoer struct {
|
type MockLogger struct {
|
||||||
ctrl *gomock.Controller
|
ctrl *gomock.Controller
|
||||||
recorder *MockInfoerMockRecorder
|
recorder *MockLoggerMockRecorder
|
||||||
}
|
}
|
||||||
|
|
||||||
// MockInfoerMockRecorder is the mock recorder for MockInfoer.
|
// MockLoggerMockRecorder is the mock recorder for MockLogger.
|
||||||
type MockInfoerMockRecorder struct {
|
type MockLoggerMockRecorder struct {
|
||||||
mock *MockInfoer
|
mock *MockLogger
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMockInfoer creates a new mock instance.
|
// NewMockLogger creates a new mock instance.
|
||||||
func NewMockInfoer(ctrl *gomock.Controller) *MockInfoer {
|
func NewMockLogger(ctrl *gomock.Controller) *MockLogger {
|
||||||
mock := &MockInfoer{ctrl: ctrl}
|
mock := &MockLogger{ctrl: ctrl}
|
||||||
mock.recorder = &MockInfoerMockRecorder{mock}
|
mock.recorder = &MockLoggerMockRecorder{mock}
|
||||||
return mock
|
return mock
|
||||||
}
|
}
|
||||||
|
|
||||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||||
func (m *MockInfoer) EXPECT() *MockInfoerMockRecorder {
|
func (m *MockLogger) EXPECT() *MockLoggerMockRecorder {
|
||||||
return m.recorder
|
return m.recorder
|
||||||
}
|
}
|
||||||
|
|
||||||
// Info mocks base method.
|
// Info mocks base method.
|
||||||
func (m *MockInfoer) Info(arg0 string) {
|
func (m *MockLogger) Info(arg0 string) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
m.ctrl.Call(m, "Info", arg0)
|
m.ctrl.Call(m, "Info", arg0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Info indicates an expected call of Info.
|
// Info indicates an expected call of Info.
|
||||||
func (mr *MockInfoerMockRecorder) Info(arg0 interface{}) *gomock.Call {
|
func (mr *MockLoggerMockRecorder) Info(arg0 interface{}) *gomock.Call {
|
||||||
mr.mock.ctrl.T.Helper()
|
mr.mock.ctrl.T.Helper()
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Info", reflect.TypeOf((*MockInfoer)(nil).Info), arg0)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Info", reflect.TypeOf((*MockLogger)(nil).Info), arg0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Warn mocks base method.
|
||||||
|
func (m *MockLogger) Warn(arg0 string) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
m.ctrl.Call(m, "Warn", arg0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Warn indicates an expected call of Warn.
|
||||||
|
func (mr *MockLoggerMockRecorder) Warn(arg0 interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Warn", reflect.TypeOf((*MockLogger)(nil).Warn), arg0)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ func Test_extractServersFromBytes(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
ctrl := gomock.NewController(t)
|
ctrl := gomock.NewController(t)
|
||||||
|
|
||||||
logger := NewMockInfoer(ctrl)
|
logger := NewMockLogger(ctrl)
|
||||||
var previousLogCall *gomock.Call
|
var previousLogCall *gomock.Call
|
||||||
for _, logged := range testCase.logged {
|
for _, logged := range testCase.logged {
|
||||||
call := logger.EXPECT().Info(logged)
|
call := logger.EXPECT().Info(logged)
|
||||||
|
|||||||
@@ -13,30 +13,35 @@ type Storage struct {
|
|||||||
// the embedded JSON file on every call to the
|
// the embedded JSON file on every call to the
|
||||||
// SyncServers method.
|
// SyncServers method.
|
||||||
hardcodedServers models.AllServers
|
hardcodedServers models.AllServers
|
||||||
logger Infoer
|
logger Logger
|
||||||
filepath string
|
filepath string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Infoer interface {
|
type Logger interface {
|
||||||
Info(s string)
|
Info(s string)
|
||||||
|
Warn(s string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new storage and reads the servers from the
|
// New creates a new storage and reads the servers from the
|
||||||
// embedded servers file and the file on disk.
|
// embedded servers file and the file on disk.
|
||||||
// Passing an empty filepath disables writing servers to a file.
|
// Passing an empty filepath disables the reading and writing of
|
||||||
func New(logger Infoer, filepath string) (storage *Storage, err error) {
|
// servers.
|
||||||
|
func New(logger Logger, filepath string) (storage *Storage, err error) {
|
||||||
// A unit test prevents any error from being returned
|
// A unit test prevents any error from being returned
|
||||||
// and ensures all providers are part of the servers returned.
|
// and ensures all providers are part of the servers returned.
|
||||||
hardcodedServers, _ := parseHardcodedServers()
|
hardcodedServers, _ := parseHardcodedServers()
|
||||||
|
|
||||||
storage = &Storage{
|
storage = &Storage{
|
||||||
hardcodedServers: hardcodedServers,
|
hardcodedServers: hardcodedServers,
|
||||||
|
mergedServers: hardcodedServers,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
filepath: filepath,
|
filepath: filepath,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := storage.syncServers(); err != nil {
|
if filepath != "" {
|
||||||
return nil, err
|
if err := storage.syncServers(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return storage, nil
|
return storage, nil
|
||||||
|
|||||||
@@ -46,13 +46,13 @@ func (s *Storage) syncServers() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Eventually write file
|
// Eventually write file
|
||||||
if s.filepath == "" || reflect.DeepEqual(serversOnFile, s.mergedServers) {
|
if reflect.DeepEqual(serversOnFile, s.mergedServers) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.flushToFile(s.filepath)
|
err = s.flushToFile(s.filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("writing servers to file: %w", err)
|
s.logger.Warn("failed writing servers to file: " + err.Error())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user