mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 01:47:33 +00:00
fix: instance remove (#4602)
This commit is contained in:
@@ -180,3 +180,20 @@ func (c *crdbStorage) RemoveObjects(ctx context.Context, instanceID, resourceOwn
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *crdbStorage) RemoveInstanceObjects(ctx context.Context, instanceID string) error {
|
||||
stmt, args, err := squirrel.Delete(assetsTable).
|
||||
Where(squirrel.Eq{
|
||||
AssetColInstanceID: instanceID,
|
||||
}).
|
||||
PlaceholderFormat(squirrel.Dollar).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return caos_errors.ThrowInternal(err, "DATAB-Sfgeq", "Errors.Internal")
|
||||
}
|
||||
_, err = c.client.ExecContext(ctx, stmt, args...)
|
||||
if err != nil {
|
||||
return caos_errors.ThrowInternal(err, "DATAB-Efgt2", "Errors.Assets.Object.RemoveFailed")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@@ -35,6 +35,8 @@ const (
|
||||
" WHERE asset_type = $1" +
|
||||
" AND instance_id = $2" +
|
||||
" AND resource_owner = $3"
|
||||
removeInstanceObjectsStmt = "DELETE FROM system.assets" +
|
||||
" WHERE instance_id = $1"
|
||||
)
|
||||
|
||||
func Test_crdbStorage_CreateObject(t *testing.T) {
|
||||
@@ -224,6 +226,50 @@ func Test_crdbStorage_RemoveObjects(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
func Test_crdbStorage_RemoveInstanceObjects(t *testing.T) {
|
||||
type fields struct {
|
||||
client db
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
instanceID string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
"remove ok",
|
||||
fields{
|
||||
client: prepareDB(t,
|
||||
expectExec(
|
||||
removeInstanceObjectsStmt,
|
||||
nil,
|
||||
"instanceID",
|
||||
)),
|
||||
},
|
||||
args{
|
||||
ctx: context.Background(),
|
||||
instanceID: "instanceID",
|
||||
},
|
||||
false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
c := &crdbStorage{
|
||||
client: tt.fields.client.db,
|
||||
}
|
||||
err := c.RemoveInstanceObjects(tt.args.ctx, tt.args.instanceID)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("RemoveInstanceObjects() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type db struct {
|
||||
mock sqlmock.Sqlmock
|
||||
|
@@ -82,6 +82,20 @@ func (mr *MockStorageMockRecorder) PutObject(ctx, instanceID, location, resource
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutObject", reflect.TypeOf((*MockStorage)(nil).PutObject), ctx, instanceID, location, resourceOwner, name, contentType, objectType, object, objectSize)
|
||||
}
|
||||
|
||||
// RemoveInstanceObjects mocks base method.
|
||||
func (m *MockStorage) RemoveInstanceObjects(ctx context.Context, instanceID string) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "RemoveInstanceObjects", ctx, instanceID)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// RemoveInstanceObjects indicates an expected call of RemoveInstanceObjects.
|
||||
func (mr *MockStorageMockRecorder) RemoveInstanceObjects(ctx, instanceID interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveInstanceObjects", reflect.TypeOf((*MockStorage)(nil).RemoveInstanceObjects), ctx, instanceID)
|
||||
}
|
||||
|
||||
// RemoveObject mocks base method.
|
||||
func (m *MockStorage) RemoveObject(ctx context.Context, instanceID, resourceOwner, name string) error {
|
||||
m.ctrl.T.Helper()
|
||||
|
@@ -136,6 +136,11 @@ func (m *Minio) RemoveObjects(ctx context.Context, instanceID, resourceOwner str
|
||||
return g.Wait()
|
||||
}
|
||||
|
||||
func (m *Minio) RemoveInstanceObjects(ctx context.Context, instanceID string) error {
|
||||
bucketName := m.prefixBucketName(instanceID)
|
||||
return m.Client.RemoveBucket(ctx, bucketName)
|
||||
}
|
||||
|
||||
func (m *Minio) createBucket(ctx context.Context, name, location string) error {
|
||||
if location == "" {
|
||||
location = m.Location
|
||||
|
@@ -15,6 +15,7 @@ type Storage interface {
|
||||
GetObjectInfo(ctx context.Context, instanceID, resourceOwner, name string) (*Asset, error)
|
||||
RemoveObject(ctx context.Context, instanceID, resourceOwner, name string) error
|
||||
RemoveObjects(ctx context.Context, instanceID, resourceOwner string, objectType ObjectType) error
|
||||
RemoveInstanceObjects(ctx context.Context, instanceID string) error
|
||||
//TODO: add functionality to move asset location
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user