Commit a1009275 authored by Alessio Caiazza's avatar Alessio Caiazza

Merge branch 'jv-config-no-pointers' into 'master'

Remove unnecessary config struct pointers NO CHANGELOG

See merge request gitlab-org/gitlab-workhorse!642
parents b2de7e46 94b1d05a
......@@ -85,10 +85,9 @@ func newUpstreamWithCableConfig(authBackend string, cableBackend string) *config
}
return &config.Config{
Version: "123",
DocumentRoot: testDocumentRoot,
Backend: helper.URLMustParse(authBackend),
CableBackend: cableBackendURL,
ImageResizerConfig: config.DefaultImageResizerConfig,
Version: "123",
DocumentRoot: testDocumentRoot,
Backend: helper.URLMustParse(authBackend),
CableBackend: cableBackendURL,
}
}
......@@ -88,26 +88,26 @@ type ImageResizerConfig struct {
}
type Config struct {
Redis *RedisConfig `toml:"redis"`
Backend *url.URL `toml:"-"`
CableBackend *url.URL `toml:"-"`
Version string `toml:"-"`
DocumentRoot string `toml:"-"`
DevelopmentMode bool `toml:"-"`
Socket string `toml:"-"`
CableSocket string `toml:"-"`
ProxyHeadersTimeout time.Duration `toml:"-"`
APILimit uint `toml:"-"`
APIQueueLimit uint `toml:"-"`
APIQueueTimeout time.Duration `toml:"-"`
APICILongPollingDuration time.Duration `toml:"-"`
ObjectStorageConfig ObjectStorageConfig `toml:"-"`
ObjectStorageCredentials *ObjectStorageCredentials `toml:"object_storage"`
PropagateCorrelationID bool `toml:"-"`
ImageResizerConfig *ImageResizerConfig `toml:"image_resizer"`
}
var DefaultImageResizerConfig = &ImageResizerConfig{
Redis *RedisConfig `toml:"redis"`
Backend *url.URL `toml:"-"`
CableBackend *url.URL `toml:"-"`
Version string `toml:"-"`
DocumentRoot string `toml:"-"`
DevelopmentMode bool `toml:"-"`
Socket string `toml:"-"`
CableSocket string `toml:"-"`
ProxyHeadersTimeout time.Duration `toml:"-"`
APILimit uint `toml:"-"`
APIQueueLimit uint `toml:"-"`
APIQueueTimeout time.Duration `toml:"-"`
APICILongPollingDuration time.Duration `toml:"-"`
ObjectStorageConfig ObjectStorageConfig `toml:"-"`
ObjectStorageCredentials ObjectStorageCredentials `toml:"object_storage"`
PropagateCorrelationID bool `toml:"-"`
ImageResizerConfig ImageResizerConfig `toml:"image_resizer"`
}
var DefaultImageResizerConfig = ImageResizerConfig{
MaxScalerProcs: uint32(math.Max(2, float64(runtime.NumCPU())/2)),
MaxFilesize: 250 * 1000, // 250kB,
}
......@@ -126,10 +126,6 @@ func (c *Config) RegisterGoCloudURLOpeners() error {
c.ObjectStorageConfig.URLMux = new(blob.URLMux)
creds := c.ObjectStorageCredentials
if creds == nil {
return nil
}
if strings.EqualFold(creds.Provider, "AzureRM") && creds.AzureCredentials.AccountName != "" && creds.AzureCredentials.AccountKey != "" {
accountName := azureblob.AccountName(creds.AzureCredentials.AccountName)
accountKey := azureblob.AccountKey(creds.AzureCredentials.AccountKey)
......
......@@ -24,7 +24,7 @@ func TestLoadEmptyConfig(t *testing.T) {
require.Equal(t, cfg.ImageResizerConfig.MaxFilesize, uint64(250000))
require.GreaterOrEqual(t, cfg.ImageResizerConfig.MaxScalerProcs, uint32(2))
require.Nil(t, cfg.ObjectStorageCredentials)
require.Equal(t, ObjectStorageCredentials{}, cfg.ObjectStorageCredentials)
require.NoError(t, cfg.RegisterGoCloudURLOpeners())
}
......@@ -51,7 +51,7 @@ aws_secret_access_key = "gdk-minio"
},
}
require.Equal(t, expected, *cfg.ObjectStorageCredentials)
require.Equal(t, expected, cfg.ObjectStorageCredentials)
}
func TestRegisterGoCloudURLOpeners(t *testing.T) {
......@@ -68,7 +68,7 @@ func TestRegisterGoCloudURLOpeners(t *testing.T) {
},
}
require.Equal(t, expected, *cfg.ObjectStorageCredentials)
require.Equal(t, expected, cfg.ObjectStorageCredentials)
require.Nil(t, cfg.ObjectStorageConfig.URLMux)
require.NoError(t, cfg.RegisterGoCloudURLOpeners())
......@@ -95,5 +95,5 @@ max_filesize = 350000
MaxFilesize: 350000,
}
require.Equal(t, expected, *cfg.ImageResizerConfig)
require.Equal(t, expected, cfg.ImageResizerConfig)
}
......@@ -255,7 +255,7 @@ func (r *Resizer) unpackParameters(paramsData string) (*resizeParams, error) {
}
// Attempts to rescale the given image data, or in case of errors, falls back to the original image.
func (r *Resizer) tryResizeImage(req *http.Request, reader io.Reader, errorWriter io.Writer, params *resizeParams, fileSize int64, cfg *config.ImageResizerConfig) (io.Reader, *exec.Cmd, error) {
func (r *Resizer) tryResizeImage(req *http.Request, reader io.Reader, errorWriter io.Writer, params *resizeParams, fileSize int64, cfg config.ImageResizerConfig) (io.Reader, *exec.Cmd, error) {
if fileSize > int64(cfg.MaxFilesize) {
return reader, nil, fmt.Errorf("ImageResizer: %db exceeds maximum file size of %db", fileSize, cfg.MaxFilesize)
}
......
......@@ -19,7 +19,7 @@ func TestLfsUploadPreparerWithConfig(t *testing.T) {
}
c := config.Config{
ObjectStorageCredentials: &config.ObjectStorageCredentials{
ObjectStorageCredentials: config.ObjectStorageCredentials{
Provider: "AWS",
S3Credentials: creds,
},
......
......@@ -12,13 +12,7 @@ type ObjectStoragePreparer struct {
}
func NewObjectStoragePreparer(c config.Config) Preparer {
creds := c.ObjectStorageCredentials
if creds == nil {
creds = &config.ObjectStorageCredentials{}
}
return &ObjectStoragePreparer{credentials: *creds, config: c.ObjectStorageConfig}
return &ObjectStoragePreparer{credentials: c.ObjectStorageCredentials, config: c.ObjectStorageConfig}
}
func (p *ObjectStoragePreparer) Prepare(a *api.Response) (*filestore.SaveFileOpts, Verifier, error) {
......
......@@ -19,7 +19,7 @@ func TestPrepareWithS3Config(t *testing.T) {
}
c := config.Config{
ObjectStorageCredentials: &config.ObjectStorageCredentials{
ObjectStorageCredentials: config.ObjectStorageCredentials{
Provider: "AWS",
S3Credentials: creds,
},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment