chore: release 0.29.0.rc0 (#1600)

This commit is contained in:
Jan-Otto Kröpke
2024-09-11 00:34:10 +02:00
committed by GitHub
parent 83b0aa8f62
commit f712c07c38
119 changed files with 5113 additions and 2255 deletions

View File

@@ -14,16 +14,16 @@
package config
import (
"context"
"crypto/tls"
"fmt"
"io"
"log/slog"
"net/http"
"os"
"strings"
"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"gopkg.in/yaml.v3"
)
@@ -37,9 +37,11 @@ type Resolver struct {
}
// NewResolver returns a Resolver structure.
func NewResolver(file string, logger log.Logger, insecureSkipVerify bool) (*Resolver, error) {
func NewResolver(file string, logger *slog.Logger, insecureSkipVerify bool) (*Resolver, error) {
flags := map[string]string{}
var fileBytes []byte
var err error
if strings.HasPrefix(file, "http://") || strings.HasPrefix(file, "https://") {
fileBytes, err = readFromURL(file, logger, insecureSkipVerify)
@@ -57,7 +59,7 @@ func NewResolver(file string, logger log.Logger, insecureSkipVerify bool) (*Reso
err = yaml.Unmarshal(fileBytes, &rawValues)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to unmarshal configuration file: %w", err)
}
// Flatten nested YAML values
@@ -71,35 +73,42 @@ func NewResolver(file string, logger log.Logger, insecureSkipVerify bool) (*Reso
return &Resolver{flags: flags}, nil
}
func readFromFile(file string, logger log.Logger) ([]byte, error) {
_ = level.Info(logger).Log("msg", fmt.Sprintf("Loading configuration file: %v", file))
func readFromFile(file string, logger *slog.Logger) ([]byte, error) {
logger.Info("Loading configuration file: " + file)
if _, err := os.Stat(file); err != nil {
return nil, err
return nil, fmt.Errorf("failed to read configuration file: %w", err)
}
fileBytes, err := os.ReadFile(file)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to read configuration file: %w", err)
}
return fileBytes, err
return fileBytes, nil
}
func readFromURL(file string, logger log.Logger, insecureSkipVerify bool) ([]byte, error) {
_ = level.Info(logger).Log("msg", fmt.Sprintf("Loading configuration file from URL: %v", file))
func readFromURL(file string, logger *slog.Logger, insecureSkipVerify bool) ([]byte, error) {
logger.Info("Loading configuration file from URL: " + file)
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: insecureSkipVerify}, //nolint:gosec
}
if insecureSkipVerify {
_ = level.Warn(logger).Log("msg", "Loading configuration file with TLS verification disabled")
logger.Warn("Loading configuration file with TLS verification disabled")
}
client := &http.Client{Transport: tr}
resp, err := client.Get(file)
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, file, nil)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to create HTTP request: %w", err)
}
resp, err := client.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to read configuration file from URL: %w", err)
}
defer resp.Body.Close()
@@ -130,6 +139,7 @@ func (c *Resolver) Bind(app *kingpin.Application, args []string) error {
}
c.setDefault(app)
if pc.SelectedCommand != nil {
c.setDefault(pc.SelectedCommand)
}