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 ...@@ -85,10 +85,9 @@ func newUpstreamWithCableConfig(authBackend string, cableBackend string) *config
} }
return &config.Config{ return &config.Config{
Version: "123", Version: "123",
DocumentRoot: testDocumentRoot, DocumentRoot: testDocumentRoot,
Backend: helper.URLMustParse(authBackend), Backend: helper.URLMustParse(authBackend),
CableBackend: cableBackendURL, CableBackend: cableBackendURL,
ImageResizerConfig: config.DefaultImageResizerConfig,
} }
} }
...@@ -88,26 +88,26 @@ type ImageResizerConfig struct { ...@@ -88,26 +88,26 @@ type ImageResizerConfig struct {
} }
type Config struct { type Config struct {
Redis *RedisConfig `toml:"redis"` Redis *RedisConfig `toml:"redis"`
Backend *url.URL `toml:"-"` Backend *url.URL `toml:"-"`
CableBackend *url.URL `toml:"-"` CableBackend *url.URL `toml:"-"`
Version string `toml:"-"` Version string `toml:"-"`
DocumentRoot string `toml:"-"` DocumentRoot string `toml:"-"`
DevelopmentMode bool `toml:"-"` DevelopmentMode bool `toml:"-"`
Socket string `toml:"-"` Socket string `toml:"-"`
CableSocket string `toml:"-"` CableSocket string `toml:"-"`
ProxyHeadersTimeout time.Duration `toml:"-"` ProxyHeadersTimeout time.Duration `toml:"-"`
APILimit uint `toml:"-"` APILimit uint `toml:"-"`
APIQueueLimit uint `toml:"-"` APIQueueLimit uint `toml:"-"`
APIQueueTimeout time.Duration `toml:"-"` APIQueueTimeout time.Duration `toml:"-"`
APICILongPollingDuration time.Duration `toml:"-"` APICILongPollingDuration time.Duration `toml:"-"`
ObjectStorageConfig ObjectStorageConfig `toml:"-"` ObjectStorageConfig ObjectStorageConfig `toml:"-"`
ObjectStorageCredentials *ObjectStorageCredentials `toml:"object_storage"` ObjectStorageCredentials ObjectStorageCredentials `toml:"object_storage"`
PropagateCorrelationID bool `toml:"-"` PropagateCorrelationID bool `toml:"-"`
ImageResizerConfig *ImageResizerConfig `toml:"image_resizer"` ImageResizerConfig ImageResizerConfig `toml:"image_resizer"`
} }
var DefaultImageResizerConfig = &ImageResizerConfig{ var DefaultImageResizerConfig = ImageResizerConfig{
MaxScalerProcs: uint32(math.Max(2, float64(runtime.NumCPU())/2)), MaxScalerProcs: uint32(math.Max(2, float64(runtime.NumCPU())/2)),
MaxFilesize: 250 * 1000, // 250kB, MaxFilesize: 250 * 1000, // 250kB,
} }
...@@ -126,10 +126,6 @@ func (c *Config) RegisterGoCloudURLOpeners() error { ...@@ -126,10 +126,6 @@ func (c *Config) RegisterGoCloudURLOpeners() error {
c.ObjectStorageConfig.URLMux = new(blob.URLMux) c.ObjectStorageConfig.URLMux = new(blob.URLMux)
creds := c.ObjectStorageCredentials creds := c.ObjectStorageCredentials
if creds == nil {
return nil
}
if strings.EqualFold(creds.Provider, "AzureRM") && creds.AzureCredentials.AccountName != "" && creds.AzureCredentials.AccountKey != "" { if strings.EqualFold(creds.Provider, "AzureRM") && creds.AzureCredentials.AccountName != "" && creds.AzureCredentials.AccountKey != "" {
accountName := azureblob.AccountName(creds.AzureCredentials.AccountName) accountName := azureblob.AccountName(creds.AzureCredentials.AccountName)
accountKey := azureblob.AccountKey(creds.AzureCredentials.AccountKey) accountKey := azureblob.AccountKey(creds.AzureCredentials.AccountKey)
......
...@@ -24,7 +24,7 @@ func TestLoadEmptyConfig(t *testing.T) { ...@@ -24,7 +24,7 @@ func TestLoadEmptyConfig(t *testing.T) {
require.Equal(t, cfg.ImageResizerConfig.MaxFilesize, uint64(250000)) require.Equal(t, cfg.ImageResizerConfig.MaxFilesize, uint64(250000))
require.GreaterOrEqual(t, cfg.ImageResizerConfig.MaxScalerProcs, uint32(2)) require.GreaterOrEqual(t, cfg.ImageResizerConfig.MaxScalerProcs, uint32(2))
require.Nil(t, cfg.ObjectStorageCredentials) require.Equal(t, ObjectStorageCredentials{}, cfg.ObjectStorageCredentials)
require.NoError(t, cfg.RegisterGoCloudURLOpeners()) require.NoError(t, cfg.RegisterGoCloudURLOpeners())
} }
...@@ -51,7 +51,7 @@ aws_secret_access_key = "gdk-minio" ...@@ -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) { func TestRegisterGoCloudURLOpeners(t *testing.T) {
...@@ -68,7 +68,7 @@ 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.Nil(t, cfg.ObjectStorageConfig.URLMux)
require.NoError(t, cfg.RegisterGoCloudURLOpeners()) require.NoError(t, cfg.RegisterGoCloudURLOpeners())
...@@ -95,5 +95,5 @@ max_filesize = 350000 ...@@ -95,5 +95,5 @@ max_filesize = 350000
MaxFilesize: 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) { ...@@ -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. // 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) { if fileSize > int64(cfg.MaxFilesize) {
return reader, nil, fmt.Errorf("ImageResizer: %db exceeds maximum file size of %db", fileSize, 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) { ...@@ -19,7 +19,7 @@ func TestLfsUploadPreparerWithConfig(t *testing.T) {
} }
c := config.Config{ c := config.Config{
ObjectStorageCredentials: &config.ObjectStorageCredentials{ ObjectStorageCredentials: config.ObjectStorageCredentials{
Provider: "AWS", Provider: "AWS",
S3Credentials: creds, S3Credentials: creds,
}, },
......
...@@ -12,13 +12,7 @@ type ObjectStoragePreparer struct { ...@@ -12,13 +12,7 @@ type ObjectStoragePreparer struct {
} }
func NewObjectStoragePreparer(c config.Config) Preparer { func NewObjectStoragePreparer(c config.Config) Preparer {
creds := c.ObjectStorageCredentials return &ObjectStoragePreparer{credentials: c.ObjectStorageCredentials, config: c.ObjectStorageConfig}
if creds == nil {
creds = &config.ObjectStorageCredentials{}
}
return &ObjectStoragePreparer{credentials: *creds, config: c.ObjectStorageConfig}
} }
func (p *ObjectStoragePreparer) Prepare(a *api.Response) (*filestore.SaveFileOpts, Verifier, error) { func (p *ObjectStoragePreparer) Prepare(a *api.Response) (*filestore.SaveFileOpts, Verifier, error) {
......
...@@ -19,7 +19,7 @@ func TestPrepareWithS3Config(t *testing.T) { ...@@ -19,7 +19,7 @@ func TestPrepareWithS3Config(t *testing.T) {
} }
c := config.Config{ c := config.Config{
ObjectStorageCredentials: &config.ObjectStorageCredentials{ ObjectStorageCredentials: config.ObjectStorageCredentials{
Provider: "AWS", Provider: "AWS",
S3Credentials: creds, 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