Skip to content

Commit

Permalink
iam verify in init supports aws
Browse files Browse the repository at this point in the history
Signed-off-by: shaoyue.chen <[email protected]>
  • Loading branch information
haorenfsa committed May 24, 2024
1 parent 52336c5 commit d39f001
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/external/iam/aws.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package iam

import (
"context"

"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"github.com/pkg/errors"
)

func VerifyAWS(ctx context.Context, bucketName, address string, secure bool) error {
// Initialize minio client object.
client, err := minio.New(address, &minio.Options{
Creds: credentials.NewIAM(""),
Secure: secure,
})
if err != nil {
return errors.Wrap(err, "init minio client failed")
}
_, err = client.BucketExists(ctx, bucketName)
return errors.Wrapf(err, "access aws bucket[%s] failed", bucketName)
}
3 changes: 3 additions & 0 deletions pkg/util/yamlparser/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ var UserYamlPath = "/milvus/configs/operator/user.yaml"

type UserYaml struct {
Minio struct {
Address string `yaml:"address"`
Port int `yaml:"port"`
UseSSL bool `yaml:"useSSL"`
UseIAM bool `yaml:"useIAM"`
CloudProvider string `yaml:"cloudProvider"`
AccessKeyID string `yaml:"accessKeyID"`
Expand Down
6 changes: 6 additions & 0 deletions tool/iam-verify/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"fmt"
"log"
"os"
"time"
Expand Down Expand Up @@ -37,6 +38,11 @@ func main() {
ContainerName: userYaml.Minio.BucketName,
})
}
case "aws":
verifyFunc = func(ctx context.Context) error {
address := fmt.Sprintf("%s:%d", userYaml.Minio.Address, userYaml.Minio.Port)
return iam.VerifyAWS(ctx, userYaml.Minio.BucketName, address, userYaml.Minio.UseSSL)
}
default:
log.Printf("iam-verify for csp %s not implement, assume success\n", userYaml.Minio.CloudProvider)
os.Exit(0)
Expand Down

0 comments on commit d39f001

Please sign in to comment.