expose max image size via config rest #307

This commit is contained in:
Umputun
2019-04-12 10:13:14 -05:00
parent db562ab8ab
commit c52e5b3920
5 changed files with 43 additions and 44 deletions
+2
View File
@@ -227,6 +227,7 @@ func (s *Rest) configCtrl(w http.ResponseWriter, r *http.Request) {
CriticalScore int `json:"critical_score"`
PositiveScore bool `json:"positive_score"`
ReadOnlyAge int `json:"readonly_age"`
MaxImageSize int `json:"max_image_size"`
}
cnf := config{
@@ -239,6 +240,7 @@ func (s *Rest) configCtrl(w http.ResponseWriter, r *http.Request) {
CriticalScore: s.ScoreThresholds.Critical,
PositiveScore: s.DataService.PositiveScore,
ReadOnlyAge: s.ReadOnlyAge,
MaxImageSize: s.ImageService.Store.SizeLimit(),
}
cnf.Auth = []string{}
+1
View File
@@ -425,6 +425,7 @@ func TestRest_Config(t *testing.T) {
assert.Equal(t, -10., j["critical_score"])
assert.False(t, j["positive_score"].(bool))
assert.Equal(t, 10., j["readonly_age"])
assert.Equal(t, 10000., j["max_image_size"])
t.Logf("%+v", j)
}
+5
View File
@@ -136,6 +136,11 @@ func (f *FileSystem) Cleanup(ctx context.Context, ttl time.Duration) error {
return errors.Wrap(err, "failed to cleanup images")
}
// SizeLimit returns max size of allowed image
func (f *FileSystem) SizeLimit() int {
return f.MaxSize
}
// location gets full path for id by adding partition to the final path in order to keep files in different subdirectories
// and avoid too many files in a single place.
// the end result is a full path like this - /tmp/images/user1/92/xxx-yyy.png.
+1
View File
@@ -25,6 +25,7 @@ type Store interface {
Commit(id string) error // move image from staging to permanent
Load(id string) (io.ReadCloser, int64, error) // load image by ID. Caller has to close the reader.
Cleanup(ctx context.Context, ttl time.Duration) error // run removal loop for old images on staging
SizeLimit() int // max image size
}
// Service extends Store with common functions needed for any store implementation
+34 -44
View File
@@ -1,95 +1,85 @@
// Code generated by MockGen. DO NOT EDIT.
// Automatically generated by MockGen. DO NOT EDIT!
// Source: image.go
// Package image is a generated GoMock package.
package image
import (
context "context"
gomock "github.com/golang/mock/gomock"
io "io"
reflect "reflect"
time "time"
)
// MockStore is a mock of Store interface
// Mock of Store interface
type MockStore struct {
ctrl *gomock.Controller
recorder *MockStoreMockRecorder
recorder *_MockStoreRecorder
}
// MockStoreMockRecorder is the mock recorder for MockStore
type MockStoreMockRecorder struct {
// Recorder for MockStore (not exported)
type _MockStoreRecorder struct {
mock *MockStore
}
// NewMockStore creates a new mock instance
func NewMockStore(ctrl *gomock.Controller) *MockStore {
mock := &MockStore{ctrl: ctrl}
mock.recorder = &MockStoreMockRecorder{mock}
mock.recorder = &_MockStoreRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockStore) EXPECT() *MockStoreMockRecorder {
return m.recorder
func (_m *MockStore) EXPECT() *_MockStoreRecorder {
return _m.recorder
}
// Save mocks base method
func (m *MockStore) Save(fileName, userID string, r io.Reader) (string, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Save", fileName, userID, r)
func (_m *MockStore) Save(fileName string, userID string, r io.Reader) (string, error) {
ret := _m.ctrl.Call(_m, "Save", fileName, userID, r)
ret0, _ := ret[0].(string)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Save indicates an expected call of Save
func (mr *MockStoreMockRecorder) Save(fileName, userID, r interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Save", reflect.TypeOf((*MockStore)(nil).Save), fileName, userID, r)
func (_mr *_MockStoreRecorder) Save(arg0, arg1, arg2 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "Save", arg0, arg1, arg2)
}
// Commit mocks base method
func (m *MockStore) Commit(id string) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Commit", id)
func (_m *MockStore) Commit(id string) error {
ret := _m.ctrl.Call(_m, "Commit", id)
ret0, _ := ret[0].(error)
return ret0
}
// Commit indicates an expected call of Commit
func (mr *MockStoreMockRecorder) Commit(id interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Commit", reflect.TypeOf((*MockStore)(nil).Commit), id)
func (_mr *_MockStoreRecorder) Commit(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "Commit", arg0)
}
// Load mocks base method
func (m *MockStore) Load(id string) (io.ReadCloser, int64, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Load", id)
func (_m *MockStore) Load(id string) (io.ReadCloser, int64, error) {
ret := _m.ctrl.Call(_m, "Load", id)
ret0, _ := ret[0].(io.ReadCloser)
ret1, _ := ret[1].(int64)
ret2, _ := ret[2].(error)
return ret0, ret1, ret2
}
// Load indicates an expected call of Load
func (mr *MockStoreMockRecorder) Load(id interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Load", reflect.TypeOf((*MockStore)(nil).Load), id)
func (_mr *_MockStoreRecorder) Load(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "Load", arg0)
}
// Cleanup mocks base method
func (m *MockStore) Cleanup(ctx context.Context, ttl time.Duration) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Cleanup", ctx, ttl)
func (_m *MockStore) Cleanup(ctx context.Context, ttl time.Duration) error {
ret := _m.ctrl.Call(_m, "Cleanup", ctx, ttl)
ret0, _ := ret[0].(error)
return ret0
}
// Cleanup indicates an expected call of Cleanup
func (mr *MockStoreMockRecorder) Cleanup(ctx, ttl interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Cleanup", reflect.TypeOf((*MockStore)(nil).Cleanup), ctx, ttl)
func (_mr *_MockStoreRecorder) Cleanup(arg0, arg1 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "Cleanup", arg0, arg1)
}
func (_m *MockStore) SizeLimit() int {
ret := _m.ctrl.Call(_m, "SizeLimit")
ret0, _ := ret[0].(int)
return ret0
}
func (_mr *_MockStoreRecorder) SizeLimit() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "SizeLimit")
}