Added the method to create a bucket when creating a new service account on minio
This commit is contained in:
@@ -5,7 +5,9 @@ import (
|
||||
"encoding/json"
|
||||
"oc-datacenter/conf"
|
||||
|
||||
oclib "cloud.o-forge.io/core/oc-lib"
|
||||
"github.com/minio/madmin-go/v4"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
|
||||
"github.com/necmettindev/randomstring"
|
||||
@@ -15,7 +17,7 @@ type MinioService struct{
|
||||
Url string
|
||||
RootKey string
|
||||
RootSecret string
|
||||
MinioClient *madmin.AdminClient
|
||||
MinioAdminClient *madmin.AdminClient
|
||||
}
|
||||
|
||||
type StatementEntry struct {
|
||||
@@ -45,7 +47,7 @@ func (m *MinioService) CreateClient() error {
|
||||
return err
|
||||
}
|
||||
|
||||
m.MinioClient = cli
|
||||
m.MinioAdminClient = cli
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -76,7 +78,7 @@ func (m *MinioService) CreateCredentials(executionId string) (string,string,erro
|
||||
SecretKey: randSecret,
|
||||
}
|
||||
|
||||
res, err := m.MinioClient.AddServiceAccount(context.Background(), req)
|
||||
res, err := m.MinioAdminClient.AddServiceAccount(context.Background(), req)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
@@ -102,5 +104,23 @@ func getRandomCreds() (string, string){
|
||||
|
||||
func (m *MinioService) CreateBucket(executionId string) error {
|
||||
|
||||
l := oclib.GetLogger()
|
||||
cred := credentials.NewStaticV4(m.RootKey,m.RootSecret,"")
|
||||
client, err := minio.New(m.Url, &minio.Options{
|
||||
Creds: cred,
|
||||
Secure: false,
|
||||
})
|
||||
if err != nil {
|
||||
l.Error().Msg("Error when creating the minio client for the data plane")
|
||||
return err
|
||||
}
|
||||
|
||||
err = client.MakeBucket(context.Background(), executionId, minio.MakeBucketOptions{})
|
||||
if err != nil {
|
||||
l.Error().Msg("Error when creating the bucket for namespace " + executionId)
|
||||
return err
|
||||
}
|
||||
|
||||
l.Info().Msg("Created the bucket " + executionId + " on " + m.Url + " minio")
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user