Skip to content

Commit

Permalink
add bucket name to minio file manager
Browse files Browse the repository at this point in the history
  • Loading branch information
gnmahanth committed Oct 18, 2023
1 parent 98c4662 commit abde656
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion deepfence_file_server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ RUN rm ./linux_amd64_full.tar.gz
RUN mkdir -p /data

ENTRYPOINT ["/entrypoint.sh"]
CMD ["weed", "server", "-ip=0.0.0.0", "-dir=/data", "-s3", "-s3.port=9000", "-s3.config=/etc/seaweed.json", "-volume.max=15"]
CMD ["weed", "server", "-ip=0.0.0.0", "-dir=/data", "-s3", "-s3.port=9000", "-s3.config=/etc/seaweed.json", "-volume.max=100"]
31 changes: 20 additions & 11 deletions deepfence_utils/directory/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import (
_ "github.com/lib/pq"
)

var minioClientMap sync.Map
var (
MinioBucket = utils.GetEnvOrDefault("DEEPFENCE_MINIO_BUCKET", string(NonSaaSDirKey))
MinioDatabaseBucket = utils.GetEnvOrDefault("DEEPFENCE_MINIO_DB_BUCKET", string(DatabaseDirKey))
minioClientMap sync.Map
)

func init() {
minioClientMap = sync.Map{}
Expand All @@ -46,11 +50,12 @@ type FileManager interface {
CreatePublicUploadURL(ctx context.Context, filePath string, addFilePathPrefix bool, expires time.Duration, reqParams url.Values) (string, error)
Client() interface{}
Bucket() string
CreatePublicBucket(ctx context.Context) error
CreatePublicBucket(ctx context.Context, bucket string) error
}

type MinioFileManager struct {
client *minio.Client
bucket string
namespace string
}

Expand Down Expand Up @@ -113,7 +118,7 @@ func (mfm *MinioFileManager) ListFiles(ctx context.Context, pathPrefix string, r
var objectsInfo []ObjectInfo
for obj := range objects {
isDir := strings.HasSuffix(obj.Key, "/")
if skipDir == true && isDir == true {
if skipDir && isDir {
continue
}
objectsInfo = append(objectsInfo, ObjectInfo{
Expand Down Expand Up @@ -273,35 +278,33 @@ func (mfm *MinioFileManager) Client() interface{} {
}

func (mfm *MinioFileManager) Bucket() string {
return mfm.namespace
return mfm.bucket
}

func (mfm *MinioFileManager) createBucketIfNeeded(ctx context.Context) error {

exists, err := mfm.client.BucketExists(ctx, mfm.namespace)
exists, err := mfm.client.BucketExists(ctx, mfm.bucket)

if err != nil {
return err
}

if !exists {
err = mfm.client.MakeBucket(ctx, mfm.namespace,
minio.MakeBucketOptions{ObjectLocking: false})

err = mfm.client.MakeBucket(ctx, mfm.bucket, minio.MakeBucketOptions{ObjectLocking: false})
}
return err
}

func (mfm *MinioFileManager) CreatePublicBucket(ctx context.Context) error {
func (mfm *MinioFileManager) CreatePublicBucket(ctx context.Context, bucket string) error {

exists, err := mfm.client.BucketExists(ctx, mfm.namespace)
exists, err := mfm.client.BucketExists(ctx, bucket)
if err != nil {
return err
} else if exists {
return nil
}

err = mfm.client.MakeBucket(ctx, mfm.namespace, minio.MakeBucketOptions{ObjectLocking: false})
err = mfm.client.MakeBucket(ctx, bucket, minio.MakeBucketOptions{ObjectLocking: false})
if err != nil {
return err
}
Expand Down Expand Up @@ -343,8 +346,14 @@ func MinioClient(ctx context.Context) (FileManager, error) {
return nil, err
}

bucket := MinioBucket
if ns == DatabaseDirKey {
bucket = MinioDatabaseBucket
}

return &MinioFileManager{
client: client,
bucket: bucket,
namespace: string(ns),
}, err
}
2 changes: 1 addition & 1 deletion deepfence_worker/cronscheduler/init_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func InitMinioDatabase() error {
}
retries := 3
for {
if err := mc.CreatePublicBucket(ctx); err != nil {
if err := mc.CreatePublicBucket(ctx, directory.MinioDatabaseBucket); err != nil {
log.Error().Err(err).Msgf("failed to create bucket")
retries -= 1
if retries != 0 {
Expand Down

0 comments on commit abde656

Please sign in to comment.