mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-09-20 13:30:46 +02:00
shell: distinguish NotFound from transient errors in provision, use %w wrapping
- s3.user.provision: check gRPC status code on GetUser error — only proceed on NotFound, abort on transient/network errors - s3.iam.import: use %w for error wrapping to preserve error chains, wrap PutConfiguration error with context
This commit is contained in:
@@ -58,12 +58,12 @@ func (c *commandS3IAMImport) Do(args []string, commandEnv *CommandEnv, writer io
|
||||
|
||||
data, err := os.ReadFile(*file)
|
||||
if err != nil {
|
||||
return fmt.Errorf("read file: %v", err)
|
||||
return fmt.Errorf("read file: %w", err)
|
||||
}
|
||||
|
||||
config := &iam_pb.S3ApiConfiguration{}
|
||||
if err := filer.ParseS3ConfigurationFromBytes(data, config); err != nil {
|
||||
return fmt.Errorf("parse configuration: %v", err)
|
||||
return fmt.Errorf("parse configuration: %w", err)
|
||||
}
|
||||
|
||||
err = pb.WithGrpcClient(false, 0, func(conn *grpc.ClientConn) error {
|
||||
@@ -76,7 +76,7 @@ func (c *commandS3IAMImport) Do(args []string, commandEnv *CommandEnv, writer io
|
||||
return err
|
||||
}, commandEnv.option.FilerAddress.ToGrpcAddress(), false, commandEnv.option.GrpcDialOption)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("put IAM configuration: %w", err)
|
||||
}
|
||||
|
||||
fmt.Fprintf(writer, "Imported IAM configuration from %s\n", *file)
|
||||
|
||||
@@ -13,6 +13,8 @@ import (
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/iam_pb"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -126,6 +128,8 @@ func (c *commandS3UserProvision) Do(args []string, commandEnv *CommandEnv, write
|
||||
// Step 0: Check if user already exists
|
||||
if resp, getErr := client.GetUser(ctx, &iam_pb.GetUserRequest{Username: *name}); getErr == nil && resp.Identity != nil {
|
||||
return fmt.Errorf("user %q already exists", *name)
|
||||
} else if getErr != nil && status.Code(getErr) != codes.NotFound {
|
||||
return fmt.Errorf("check user existence: %w", getErr)
|
||||
}
|
||||
|
||||
// Step 1: Create policy
|
||||
|
||||
Reference in New Issue
Block a user