diff --git a/internal/command/statics.go b/internal/command/statics.go index b74e95c5f4..cfe9c9fd4a 100644 --- a/internal/command/statics.go +++ b/internal/command/statics.go @@ -5,13 +5,9 @@ import ( "io" "github.com/caos/zitadel/internal/domain" - caos_errors "github.com/caos/zitadel/internal/errors" ) func (c *Commands) UploadAsset(ctx context.Context, bucketName, objectName, contentType string, file io.Reader, size int64) (*domain.AssetInfo, error) { - if c.static == nil { - return nil, caos_errors.ThrowPreconditionFailed(nil, "STATIC-Fm92f", "Errors.Assets.Store.NotConfigured") - } return c.static.PutObject(ctx, bucketName, objectName, diff --git a/internal/management/repository/eventsourcing/handler/label_policy.go b/internal/management/repository/eventsourcing/handler/label_policy.go index 6c2b6c7ab1..26d59b30e2 100644 --- a/internal/management/repository/eventsourcing/handler/label_policy.go +++ b/internal/management/repository/eventsourcing/handler/label_policy.go @@ -129,9 +129,6 @@ func (m *LabelPolicy) OnSuccess() error { } func (p *LabelPolicy) CleanUpBucket(policy *iam_model.LabelPolicyView) { - if p.static == nil { - return - } ctx := context.Background() objects, err := p.static.ListObjectInfos(ctx, policy.AggregateID, domain.LabelPolicyPrefix+"/", false) if err != nil { diff --git a/internal/static/config/config.go b/internal/static/config/config.go index fdbf7a263a..d5d62c6f56 100644 --- a/internal/static/config/config.go +++ b/internal/static/config/config.go @@ -1,8 +1,13 @@ package config import ( + "context" "encoding/json" + "io" + "net/url" + "time" + "github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/errors" "github.com/caos/zitadel/internal/static" "github.com/caos/zitadel/internal/static/s3" @@ -14,7 +19,9 @@ type AssetStorageConfig struct { } var storage = map[string]func() static.Config{ - "s3": func() static.Config { return &s3.Config{} }, + "s3": func() static.Config { return &s3.Config{} }, + "none": func() static.Config { return &NoStorage{} }, + "": func() static.Config { return &NoStorage{} }, } func (c *AssetStorageConfig) UnmarshalJSON(data []byte) error { @@ -55,3 +62,53 @@ func newStorageConfig(storageType string, configData []byte) (static.Config, err return staticConfig, nil } + +var ( + errNoStorage = errors.ThrowInternal(nil, "STATIC-ashg4", "Errors.Assets.Store.NotConfigured") +) + +type NoStorage struct{} + +func (_ *NoStorage) NewStorage() (static.Storage, error) { + return &NoStorage{}, nil +} + +func (_ *NoStorage) CreateBucket(ctx context.Context, name, location string) error { + return errNoStorage +} + +func (_ *NoStorage) RemoveBucket(ctx context.Context, name string) error { + return errNoStorage +} + +func (_ *NoStorage) ListBuckets(ctx context.Context) ([]*domain.BucketInfo, error) { + return nil, errNoStorage +} + +func (_ *NoStorage) PutObject(ctx context.Context, bucketName, objectName, contentType string, object io.Reader, objectSize int64, createBucketIfNotExisting bool) (*domain.AssetInfo, error) { + return nil, errNoStorage +} + +func (_ *NoStorage) GetObjectInfo(ctx context.Context, bucketName, objectName string) (*domain.AssetInfo, error) { + return nil, errNoStorage +} + +func (_ *NoStorage) GetObject(ctx context.Context, bucketName, objectName string) (io.Reader, func() (*domain.AssetInfo, error), error) { + return nil, nil, errNoStorage +} + +func (_ *NoStorage) ListObjectInfos(ctx context.Context, bucketName, prefix string, recursive bool) ([]*domain.AssetInfo, error) { + return nil, errNoStorage +} + +func (_ *NoStorage) GetObjectPresignedURL(ctx context.Context, bucketName, objectName string, expiration time.Duration) (*url.URL, error) { + return nil, errNoStorage +} + +func (_ *NoStorage) RemoveObject(ctx context.Context, bucketName, objectName string) error { + return errNoStorage +} + +func (_ *NoStorage) RemoveObjects(ctx context.Context, bucketName, path string, recursive bool) error { + return errNoStorage +}