Skip to content

Commit e2bbf91

Browse files
authored
Vacuum Swagger (#3533)
1 parent ee974a5 commit e2bbf91

File tree

138 files changed

+2085
-23990
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+2085
-23990
lines changed

api/embedded_spec.go

Lines changed: 1812 additions & 6246 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/user_buckets.go

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
"github.com/minio/mc/cmd"
3232
"github.com/minio/mc/pkg/probe"
3333
"github.com/minio/minio-go/v7/pkg/credentials"
34-
"github.com/minio/minio-go/v7/pkg/sse"
3534
"github.com/minio/minio-go/v7/pkg/tags"
3635

3736
"github.com/go-openapi/runtime/middleware"
@@ -480,66 +479,11 @@ func consoleAccess2policyAccess(bucketAccess models.BucketAccess) (bucketPolicy
480479
return bucketPolicy
481480
}
482481

483-
// enableBucketEncryption will enable bucket encryption based on two encryption algorithms, sse-s3 (server side encryption with external KMS) or sse-kms (aws s3 kms key)
484-
func enableBucketEncryption(ctx context.Context, client MinioClient, bucketName string, encryptionType models.BucketEncryptionType, kmsKeyID string) error {
485-
var config *sse.Configuration
486-
switch encryptionType {
487-
case models.BucketEncryptionTypeSseDashKms:
488-
config = sse.NewConfigurationSSEKMS(kmsKeyID)
489-
case models.BucketEncryptionTypeSseDashS3:
490-
config = sse.NewConfigurationSSES3()
491-
default:
492-
return ErrInvalidEncryptionAlgorithm
493-
}
494-
return client.setBucketEncryption(ctx, bucketName, config)
495-
}
496-
497482
// disableBucketEncryption will disable bucket for the provided bucket name
498483
func disableBucketEncryption(ctx context.Context, client MinioClient, bucketName string) error {
499484
return client.removeBucketEncryption(ctx, bucketName)
500485
}
501486

502-
func getBucketEncryptionInfo(ctx context.Context, client MinioClient, bucketName string) (*models.BucketEncryptionInfo, error) {
503-
bucketInfo, err := client.getBucketEncryption(ctx, bucketName)
504-
if err != nil {
505-
return nil, err
506-
}
507-
if len(bucketInfo.Rules) == 0 {
508-
return nil, ErrDefault
509-
}
510-
return &models.BucketEncryptionInfo{Algorithm: bucketInfo.Rules[0].Apply.SSEAlgorithm, KmsMasterKeyID: bucketInfo.Rules[0].Apply.KmsMasterKeyID}, nil
511-
}
512-
513-
// setBucketRetentionConfig sets object lock configuration on a bucket
514-
func setBucketRetentionConfig(ctx context.Context, client MinioClient, bucketName string, mode models.ObjectRetentionMode, unit models.ObjectRetentionUnit, validity *int32) error {
515-
if validity == nil {
516-
return errors.New("retention validity can't be nil")
517-
}
518-
519-
var retentionMode minio.RetentionMode
520-
switch mode {
521-
case models.ObjectRetentionModeGovernance:
522-
retentionMode = minio.Governance
523-
case models.ObjectRetentionModeCompliance:
524-
retentionMode = minio.Compliance
525-
default:
526-
return errors.New("invalid retention mode")
527-
}
528-
529-
var retentionUnit minio.ValidityUnit
530-
switch unit {
531-
case models.ObjectRetentionUnitDays:
532-
retentionUnit = minio.Days
533-
case models.ObjectRetentionUnitYears:
534-
retentionUnit = minio.Years
535-
default:
536-
return errors.New("invalid retention unit")
537-
}
538-
539-
retentionValidity := uint(*validity)
540-
return client.setObjectLockConfig(ctx, bucketName, &retentionMode, &retentionValidity, &retentionUnit)
541-
}
542-
543487
func getBucketRetentionConfig(ctx context.Context, client MinioClient, bucketName string) (*models.GetBucketRetentionConfig, error) {
544488
m, v, u, err := client.getBucketObjectLockConfig(ctx, bucketName)
545489
if err != nil {

api/user_buckets_test.go

Lines changed: 0 additions & 241 deletions
Original file line numberDiff line numberDiff line change
@@ -362,56 +362,6 @@ func TestSetBucketAccess(t *testing.T) {
362362
}
363363
}
364364

365-
func Test_enableBucketEncryption(t *testing.T) {
366-
ctx := context.Background()
367-
type args struct {
368-
ctx context.Context
369-
bucketName string
370-
encryptionType models.BucketEncryptionType
371-
kmsKeyID string
372-
mockEnableBucketEncryptionFunc func(ctx context.Context, bucketName string, config *sse.Configuration) error
373-
}
374-
tests := []struct {
375-
name string
376-
args args
377-
wantErr bool
378-
}{
379-
{
380-
name: "Bucket encryption enabled correctly",
381-
args: args{
382-
ctx: ctx,
383-
bucketName: "test",
384-
encryptionType: "sse-s3",
385-
mockEnableBucketEncryptionFunc: func(_ context.Context, _ string, _ *sse.Configuration) error {
386-
return nil
387-
},
388-
},
389-
wantErr: false,
390-
},
391-
{
392-
name: "Error when enabling bucket encryption",
393-
args: args{
394-
ctx: ctx,
395-
bucketName: "test",
396-
encryptionType: "sse-s3",
397-
mockEnableBucketEncryptionFunc: func(_ context.Context, _ string, _ *sse.Configuration) error {
398-
return ErrInvalidSession
399-
},
400-
},
401-
wantErr: true,
402-
},
403-
}
404-
for _, tt := range tests {
405-
t.Run(tt.name, func(_ *testing.T) {
406-
minClient := minioClientMock{}
407-
minClient.setBucketEncryptionMock = tt.args.mockEnableBucketEncryptionFunc
408-
if err := enableBucketEncryption(tt.args.ctx, minClient, tt.args.bucketName, tt.args.encryptionType, tt.args.kmsKeyID); (err != nil) != tt.wantErr {
409-
t.Errorf("enableBucketEncryption() errors = %v, wantErr %v", err, tt.wantErr)
410-
}
411-
})
412-
}
413-
}
414-
415365
func Test_disableBucketEncryption(t *testing.T) {
416366
ctx := context.Background()
417367
type args struct {
@@ -458,197 +408,6 @@ func Test_disableBucketEncryption(t *testing.T) {
458408
}
459409
}
460410

461-
func Test_getBucketEncryptionInfo(t *testing.T) {
462-
ctx := context.Background()
463-
type args struct {
464-
ctx context.Context
465-
bucketName string
466-
mockBucketEncryptionGet func(ctx context.Context, bucketName string) (*sse.Configuration, error)
467-
}
468-
tests := []struct {
469-
name string
470-
args args
471-
want *models.BucketEncryptionInfo
472-
wantErr bool
473-
}{
474-
{
475-
name: "Bucket encryption info returned correctly",
476-
args: args{
477-
ctx: ctx,
478-
bucketName: "test",
479-
mockBucketEncryptionGet: func(_ context.Context, _ string) (*sse.Configuration, error) {
480-
return &sse.Configuration{
481-
Rules: []sse.Rule{
482-
{
483-
Apply: sse.ApplySSEByDefault{SSEAlgorithm: "AES256", KmsMasterKeyID: ""},
484-
},
485-
},
486-
}, nil
487-
},
488-
},
489-
wantErr: false,
490-
want: &models.BucketEncryptionInfo{
491-
Algorithm: "AES256",
492-
KmsMasterKeyID: "",
493-
},
494-
},
495-
{
496-
name: "Bucket encryption info with no rules",
497-
args: args{
498-
ctx: ctx,
499-
bucketName: "test",
500-
mockBucketEncryptionGet: func(_ context.Context, _ string) (*sse.Configuration, error) {
501-
return &sse.Configuration{
502-
Rules: []sse.Rule{},
503-
}, nil
504-
},
505-
},
506-
wantErr: true,
507-
},
508-
{
509-
name: "Error when obtaining bucket encryption info",
510-
args: args{
511-
ctx: ctx,
512-
bucketName: "test",
513-
mockBucketEncryptionGet: func(_ context.Context, _ string) (*sse.Configuration, error) {
514-
return nil, ErrSSENotConfigured
515-
},
516-
},
517-
wantErr: true,
518-
},
519-
}
520-
for _, tt := range tests {
521-
t.Run(tt.name, func(_ *testing.T) {
522-
minClient := minioClientMock{}
523-
minClient.getBucketEncryptionMock = tt.args.mockBucketEncryptionGet
524-
got, err := getBucketEncryptionInfo(tt.args.ctx, minClient, tt.args.bucketName)
525-
if (err != nil) != tt.wantErr {
526-
t.Errorf("getBucketEncryptionInfo() errors = %v, wantErr %v", err, tt.wantErr)
527-
return
528-
}
529-
if !reflect.DeepEqual(got, tt.want) {
530-
t.Errorf("getBucketEncryptionInfo() got = %v, want %v", got, tt.want)
531-
}
532-
})
533-
}
534-
}
535-
536-
func Test_SetBucketRetentionConfig(t *testing.T) {
537-
assert := assert.New(t)
538-
ctx := context.Background()
539-
type args struct {
540-
ctx context.Context
541-
bucketName string
542-
mode models.ObjectRetentionMode
543-
unit models.ObjectRetentionUnit
544-
validity *int32
545-
mockBucketRetentionFunc func(ctx context.Context, bucketName string, mode *minio.RetentionMode, validity *uint, unit *minio.ValidityUnit) error
546-
}
547-
tests := []struct {
548-
name string
549-
args args
550-
expectedError error
551-
}{
552-
{
553-
name: "Set Bucket Retention Config",
554-
args: args{
555-
ctx: ctx,
556-
bucketName: "test",
557-
mode: models.ObjectRetentionModeCompliance,
558-
unit: models.ObjectRetentionUnitDays,
559-
validity: swag.Int32(2),
560-
mockBucketRetentionFunc: func(_ context.Context, _ string, _ *minio.RetentionMode, _ *uint, _ *minio.ValidityUnit) error {
561-
return nil
562-
},
563-
},
564-
expectedError: nil,
565-
},
566-
{
567-
name: "Set Bucket Retention Config 2",
568-
args: args{
569-
ctx: ctx,
570-
bucketName: "test",
571-
mode: models.ObjectRetentionModeGovernance,
572-
unit: models.ObjectRetentionUnitYears,
573-
validity: swag.Int32(2),
574-
mockBucketRetentionFunc: func(_ context.Context, _ string, _ *minio.RetentionMode, _ *uint, _ *minio.ValidityUnit) error {
575-
return nil
576-
},
577-
},
578-
expectedError: nil,
579-
},
580-
{
581-
name: "Invalid validity",
582-
args: args{
583-
ctx: ctx,
584-
bucketName: "test",
585-
mode: models.ObjectRetentionModeCompliance,
586-
unit: models.ObjectRetentionUnitDays,
587-
validity: nil,
588-
mockBucketRetentionFunc: func(_ context.Context, _ string, _ *minio.RetentionMode, _ *uint, _ *minio.ValidityUnit) error {
589-
return nil
590-
},
591-
},
592-
expectedError: errors.New("retention validity can't be nil"),
593-
},
594-
{
595-
name: "Invalid retention mode",
596-
args: args{
597-
ctx: ctx,
598-
bucketName: "test",
599-
mode: models.ObjectRetentionMode("othermode"),
600-
unit: models.ObjectRetentionUnitDays,
601-
validity: swag.Int32(2),
602-
mockBucketRetentionFunc: func(_ context.Context, _ string, _ *minio.RetentionMode, _ *uint, _ *minio.ValidityUnit) error {
603-
return nil
604-
},
605-
},
606-
expectedError: errors.New("invalid retention mode"),
607-
},
608-
{
609-
name: "Invalid retention unit",
610-
args: args{
611-
ctx: ctx,
612-
bucketName: "test",
613-
mode: models.ObjectRetentionModeCompliance,
614-
unit: models.ObjectRetentionUnit("otherunit"),
615-
validity: swag.Int32(2),
616-
mockBucketRetentionFunc: func(_ context.Context, _ string, _ *minio.RetentionMode, _ *uint, _ *minio.ValidityUnit) error {
617-
return nil
618-
},
619-
},
620-
expectedError: errors.New("invalid retention unit"),
621-
},
622-
{
623-
name: "Handle errors on objec lock function",
624-
args: args{
625-
ctx: ctx,
626-
bucketName: "test",
627-
mode: models.ObjectRetentionModeCompliance,
628-
unit: models.ObjectRetentionUnitDays,
629-
validity: swag.Int32(2),
630-
mockBucketRetentionFunc: func(_ context.Context, _ string, _ *minio.RetentionMode, _ *uint, _ *minio.ValidityUnit) error {
631-
return errors.New("error func")
632-
},
633-
},
634-
expectedError: errors.New("error func"),
635-
},
636-
}
637-
for _, tt := range tests {
638-
t.Run(tt.name, func(_ *testing.T) {
639-
minClient := minioClientMock{}
640-
minClient.setObjectLockConfigMock = tt.args.mockBucketRetentionFunc
641-
err := setBucketRetentionConfig(tt.args.ctx, minClient, tt.args.bucketName, tt.args.mode, tt.args.unit, tt.args.validity)
642-
if tt.expectedError != nil {
643-
fmt.Println(t.Name())
644-
assert.Equal(tt.expectedError.Error(), err.Error(), fmt.Sprintf("setObjectRetention() errors: `%s`, wantErr: `%s`", err, tt.expectedError))
645-
} else {
646-
assert.Nil(err, fmt.Sprintf("setBucketRetentionConfig() errors: %v, wantErr: %v", err, tt.expectedError))
647-
}
648-
})
649-
}
650-
}
651-
652411
func Test_GetBucketRetentionConfig(t *testing.T) {
653412
assert := assert.New(t)
654413
ctx := context.Background()

api/user_objects.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,43 +1032,6 @@ func getRequestURLWithScheme(r *http.Request) string {
10321032
return fmt.Sprintf("%s://%s", scheme, r.Host)
10331033
}
10341034

1035-
func setObjectLegalHold(ctx context.Context, client MinioClient, bucketName, prefix, versionID string, status models.ObjectLegalHoldStatus) error {
1036-
var lstatus minio.LegalHoldStatus
1037-
if status == models.ObjectLegalHoldStatusEnabled {
1038-
lstatus = minio.LegalHoldEnabled
1039-
} else {
1040-
lstatus = minio.LegalHoldDisabled
1041-
}
1042-
return client.putObjectLegalHold(ctx, bucketName, prefix, minio.PutObjectLegalHoldOptions{VersionID: versionID, Status: &lstatus})
1043-
}
1044-
1045-
func setObjectRetention(ctx context.Context, client MinioClient, bucketName, versionID, prefix string, retentionOps *models.PutObjectRetentionRequest) error {
1046-
if retentionOps == nil {
1047-
return errors.New("object retention options can't be nil")
1048-
}
1049-
if retentionOps.Expires == nil {
1050-
return errors.New("object retention expires can't be nil")
1051-
}
1052-
1053-
var mode minio.RetentionMode
1054-
if *retentionOps.Mode == models.ObjectRetentionModeGovernance {
1055-
mode = minio.Governance
1056-
} else {
1057-
mode = minio.Compliance
1058-
}
1059-
retentionUntilDate, err := time.Parse(time.RFC3339, *retentionOps.Expires)
1060-
if err != nil {
1061-
return err
1062-
}
1063-
opts := minio.PutObjectRetentionOptions{
1064-
GovernanceBypass: retentionOps.GovernanceBypass,
1065-
RetainUntilDate: &retentionUntilDate,
1066-
Mode: &mode,
1067-
VersionID: versionID,
1068-
}
1069-
return client.putObjectRetention(ctx, bucketName, prefix, opts)
1070-
}
1071-
10721035
func deleteObjectRetention(ctx context.Context, client MinioClient, bucketName, prefix, versionID string) error {
10731036
opts := minio.PutObjectRetentionOptions{
10741037
GovernanceBypass: true,

0 commit comments

Comments
 (0)