satellite/console: Disable segment limit checking during project update

This is not supported on the client side yet.

Change-Id: Id2df75278efe4b3a48be21d0992ee835e804fc3a
This commit is contained in:
Moby von Briesen 2021-12-23 14:25:31 -05:00
parent f6a33ec110
commit 1bd74658df
3 changed files with 1 additions and 22 deletions

View File

@ -99,7 +99,6 @@ type ProjectInfo struct {
Description string `json:"description"`
StorageLimit memory.Size `json:"project specific storage limit"`
BandwidthLimit memory.Size `json:"project specific bandwidth limit"`
SegmentLimit int64 `json:"project specific segment limit"`
CreatedAt time.Time `json:"createdAt"`
}

View File

@ -1211,10 +1211,7 @@ func (s *Service) UpdateProject(ctx context.Context, projectID uuid.UUID, projec
if project.StorageLimit != nil && *project.StorageLimit == 0 {
return nil, Error.New("current storage limit for project is set to 0 (updating disabled)")
}
if project.SegmentLimit != nil && *project.SegmentLimit == 0 {
return nil, Error.New("current segment limit for project is set to 0 (updating disabled)")
}
if projectInfo.StorageLimit <= 0 || projectInfo.BandwidthLimit <= 0 || projectInfo.SegmentLimit <= 0 {
if projectInfo.StorageLimit <= 0 || projectInfo.BandwidthLimit <= 0 {
return nil, Error.New("project limits must be greater than 0")
}
@ -1226,10 +1223,6 @@ func (s *Service) UpdateProject(ctx context.Context, projectID uuid.UUID, projec
return nil, Error.New("specified bandwidth limit exceeds allowed maximum for current tier")
}
if projectInfo.SegmentLimit > s.config.UsageLimits.Segment.Paid {
return nil, Error.New("specified segment limit exceeds allowed maximum for current tier")
}
storageUsed, err := s.projectUsage.GetProjectStorageTotals(ctx, projectID)
if err != nil {
return nil, Error.Wrap(err)
@ -1250,7 +1243,6 @@ func (s *Service) UpdateProject(ctx context.Context, projectID uuid.UUID, projec
*project.StorageLimit = projectInfo.StorageLimit
project.BandwidthLimit = new(memory.Size)
*project.BandwidthLimit = projectInfo.BandwidthLimit
*project.SegmentLimit = projectInfo.SegmentLimit
}
err = s.store.Projects().Update(ctx, project)

View File

@ -64,7 +64,6 @@ func TestService(t *testing.T) {
updatedDescription := "newDescription"
updatedStorageLimit := memory.Size(100)
updatedBandwidthLimit := memory.Size(100)
updatedSegmentLimit := int64(100)
// user should be in free tier
user, err := service.GetUser(ctx, up1Pro1.OwnerID)
@ -86,7 +85,6 @@ func TestService(t *testing.T) {
Description: updatedDescription,
StorageLimit: updatedStorageLimit,
BandwidthLimit: updatedBandwidthLimit,
SegmentLimit: updatedSegmentLimit,
})
require.NoError(t, err)
require.NotEqual(t, up1Pro1.Name, updatedProject.Name)
@ -97,8 +95,6 @@ func TestService(t *testing.T) {
require.Equal(t, updatedStorageLimit, *updatedProject.StorageLimit)
require.NotEqual(t, *up1Pro1.BandwidthLimit, *updatedProject.BandwidthLimit)
require.Equal(t, updatedBandwidthLimit, *updatedProject.BandwidthLimit)
require.NotEqual(t, *up1Pro1.SegmentLimit, *updatedProject.SegmentLimit)
require.Equal(t, updatedSegmentLimit, *updatedProject.SegmentLimit)
// Updating someone else project details should not work
updatedProject, err = service.UpdateProject(authCtx1, up2Pro1.ID, console.ProjectInfo{
@ -106,7 +102,6 @@ func TestService(t *testing.T) {
Description: "TestUpdate",
StorageLimit: memory.Size(100),
BandwidthLimit: memory.Size(100),
SegmentLimit: 100,
})
require.Error(t, err)
require.Nil(t, updatedProject)
@ -118,7 +113,6 @@ func TestService(t *testing.T) {
*size100 = memory.Size(100)
up1Pro1.StorageLimit = size0
up1Pro1.SegmentLimit = (*int64)(size0)
err = sat.DB.Console().Projects().Update(ctx, up1Pro1)
require.NoError(t, err)
@ -127,7 +121,6 @@ func TestService(t *testing.T) {
Description: "1 2 3",
StorageLimit: memory.Size(123),
BandwidthLimit: memory.Size(123),
SegmentLimit: 123,
}
updatedProject, err = service.UpdateProject(authCtx1, up1Pro1.ID, updateInfo)
require.Error(t, err)
@ -145,7 +138,6 @@ func TestService(t *testing.T) {
up1Pro1.StorageLimit = size100
up1Pro1.BandwidthLimit = size100
up1Pro1.SegmentLimit = (*int64)(size100)
err = sat.DB.Console().Projects().Update(ctx, up1Pro1)
require.NoError(t, err)
@ -157,7 +149,6 @@ func TestService(t *testing.T) {
require.NotNil(t, updatedProject.BandwidthLimit)
require.Equal(t, updateInfo.StorageLimit, *updatedProject.StorageLimit)
require.Equal(t, updateInfo.BandwidthLimit, *updatedProject.BandwidthLimit)
require.Equal(t, updateInfo.SegmentLimit, *updatedProject.SegmentLimit)
})
t.Run("TestAddProjectMembers", func(t *testing.T) {
@ -339,7 +330,6 @@ func TestPaidTier(t *testing.T) {
require.NoError(t, err)
require.Equal(t, usageConfig.Storage.Free, *proj1.StorageLimit)
require.Equal(t, usageConfig.Bandwidth.Free, *proj1.BandwidthLimit)
require.Equal(t, usageConfig.Segment.Free, *proj1.SegmentLimit)
// user should be in free tier
user, err := service.GetUser(ctx, proj1.OwnerID)
@ -367,13 +357,11 @@ func TestPaidTier(t *testing.T) {
require.NoError(t, err)
require.Equal(t, usageConfig.Storage.Paid, *proj1.StorageLimit)
require.Equal(t, usageConfig.Bandwidth.Paid, *proj1.BandwidthLimit)
require.Equal(t, usageConfig.Segment.Paid, *proj1.SegmentLimit)
// expect new project to be created with paid tier usage limits
proj2, err := service.CreateProject(authCtx, console.ProjectInfo{Name: "Project 2"})
require.NoError(t, err)
require.Equal(t, usageConfig.Storage.Paid, *proj2.StorageLimit)
require.Equal(t, usageConfig.Segment.Paid, *proj2.SegmentLimit)
})
}