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:
Chris Lu
2026-04-07 12:24:00 -07:00
parent 6e85068987
commit e2d9ae071c
2 changed files with 7 additions and 3 deletions
+3 -3
View File
@@ -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)
+4
View 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