Merge branch v2.11 into v3.3
This commit is contained in:
commit
4fd6b10b7d
16 changed files with 88 additions and 52 deletions
|
@ -151,7 +151,7 @@ func (p *passTLSClientCert) ServeHTTP(rw http.ResponseWriter, req *http.Request)
|
|||
if req.TLS != nil && len(req.TLS.PeerCertificates) > 0 {
|
||||
req.Header.Set(xForwardedTLSClientCert, getCertificates(ctx, req.TLS.PeerCertificates))
|
||||
} else {
|
||||
logger.Warn().Msg("Tried to extract a certificate on a request without mutual TLS")
|
||||
logger.Debug().Msg("Tried to extract a certificate on a request without mutual TLS")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,7 +160,7 @@ func (p *passTLSClientCert) ServeHTTP(rw http.ResponseWriter, req *http.Request)
|
|||
headerContent := p.getCertInfo(ctx, req.TLS.PeerCertificates)
|
||||
req.Header.Set(xForwardedTLSClientCertInfo, url.QueryEscape(headerContent))
|
||||
} else {
|
||||
logger.Warn().Msg("Tried to extract a certificate on a request without mutual TLS")
|
||||
logger.Debug().Msg("Tried to extract a certificate on a request without mutual TLS")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package acme
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"os"
|
||||
|
@ -23,9 +24,9 @@ type LocalStore struct {
|
|||
}
|
||||
|
||||
// NewLocalStore initializes a new LocalStore with a file name.
|
||||
func NewLocalStore(filename string) *LocalStore {
|
||||
func NewLocalStore(filename string, routinesPool *safe.Pool) *LocalStore {
|
||||
store := &LocalStore{filename: filename, saveDataChan: make(chan map[string]*StoredData)}
|
||||
store.listenSaveAction()
|
||||
store.listenSaveAction(routinesPool)
|
||||
return store
|
||||
}
|
||||
|
||||
|
@ -100,18 +101,31 @@ func (s *LocalStore) get(resolverName string) (*StoredData, error) {
|
|||
}
|
||||
|
||||
// listenSaveAction listens to a chan to store ACME data in json format into `LocalStore.filename`.
|
||||
func (s *LocalStore) listenSaveAction() {
|
||||
safe.Go(func() {
|
||||
func (s *LocalStore) listenSaveAction(routinesPool *safe.Pool) {
|
||||
routinesPool.GoCtx(func(ctx context.Context) {
|
||||
logger := log.With().Str(logs.ProviderName, "acme").Logger()
|
||||
for object := range s.saveDataChan {
|
||||
data, err := json.MarshalIndent(object, "", " ")
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Send()
|
||||
}
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
|
||||
err = os.WriteFile(s.filename, data, 0o600)
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Send()
|
||||
case object := <-s.saveDataChan:
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
// Stop handling events because Traefik is shutting down.
|
||||
return
|
||||
default:
|
||||
}
|
||||
|
||||
data, err := json.MarshalIndent(object, "", " ")
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Send()
|
||||
}
|
||||
|
||||
err = os.WriteFile(s.filename, data, 0o600)
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Send()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package acme
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -9,6 +10,7 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/traefik/traefik/v3/pkg/safe"
|
||||
)
|
||||
|
||||
func TestLocalStore_GetAccount(t *testing.T) {
|
||||
|
@ -45,7 +47,7 @@ func TestLocalStore_GetAccount(t *testing.T) {
|
|||
|
||||
for _, test := range testCases {
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
s := NewLocalStore(test.filename)
|
||||
s := NewLocalStore(test.filename, safe.NewPool(context.Background()))
|
||||
|
||||
account, err := s.GetAccount("test")
|
||||
require.NoError(t, err)
|
||||
|
@ -58,7 +60,7 @@ func TestLocalStore_GetAccount(t *testing.T) {
|
|||
func TestLocalStore_SaveAccount(t *testing.T) {
|
||||
acmeFile := filepath.Join(t.TempDir(), "acme.json")
|
||||
|
||||
s := NewLocalStore(acmeFile)
|
||||
s := NewLocalStore(acmeFile, safe.NewPool(context.Background()))
|
||||
|
||||
email := "some@email.com"
|
||||
|
||||
|
|
|
@ -307,6 +307,8 @@ func TestHeadRequest(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNoContentLengthResponse(t *testing.T) {
|
||||
t.Skip("Waiting for a fix")
|
||||
|
||||
backendListener, err := net.Listen("tcp", ":0")
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue