mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-31 09:20:50 +01:00
LimitExceeded is a conflict (409), an unknown Action is InvalidAction (404) rather than NotImplemented, and internal failures report the IAM receiver fault type. Applies to both the embedded IAM endpoint and the standalone iamapi server. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
50 lines
1.8 KiB
Go
50 lines
1.8 KiB
Go
package iamapi
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/aws/aws-sdk-go/service/iam"
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
"github.com/seaweedfs/seaweedfs/weed/s3api/s3err"
|
|
)
|
|
|
|
func newErrorResponse(errCode string, errMsg string, requestID string) ErrorResponse {
|
|
errorResp := ErrorResponse{}
|
|
errorResp.Error.Type = "Sender"
|
|
errorResp.Error.Code = &errCode
|
|
errorResp.Error.Message = &errMsg
|
|
errorResp.SetRequestId(requestID)
|
|
return errorResp
|
|
}
|
|
|
|
func writeIamErrorResponse(w http.ResponseWriter, r *http.Request, reqID string, iamError *IamError) {
|
|
if iamError == nil {
|
|
glog.Errorf("writeIamErrorResponse called with nil error")
|
|
internalResp := newErrorResponse(iam.ErrCodeServiceFailureException, "Internal server error", reqID)
|
|
s3err.WriteXMLResponse(w, r, http.StatusInternalServerError, internalResp)
|
|
return
|
|
}
|
|
|
|
errCode := iamError.Code
|
|
errMsg := iamError.Error.Error()
|
|
glog.Errorf("Response %+v", errMsg)
|
|
|
|
errorResp := newErrorResponse(errCode, errMsg, reqID)
|
|
internalErrorResponse := newErrorResponse(iam.ErrCodeServiceFailureException, "Internal server error", reqID)
|
|
internalErrorResponse.Error.Type = "Receiver"
|
|
|
|
switch errCode {
|
|
case iam.ErrCodeNoSuchEntityException:
|
|
s3err.WriteXMLResponse(w, r, http.StatusNotFound, errorResp)
|
|
case iam.ErrCodeMalformedPolicyDocumentException, iam.ErrCodeInvalidInputException:
|
|
s3err.WriteXMLResponse(w, r, http.StatusBadRequest, errorResp)
|
|
case iam.ErrCodeDeleteConflictException, iam.ErrCodeEntityAlreadyExistsException:
|
|
s3err.WriteXMLResponse(w, r, http.StatusConflict, errorResp)
|
|
case iam.ErrCodeServiceFailureException:
|
|
// We do not want to expose internal server error to the client
|
|
s3err.WriteXMLResponse(w, r, http.StatusInternalServerError, internalErrorResponse)
|
|
default:
|
|
s3err.WriteXMLResponse(w, r, http.StatusInternalServerError, internalErrorResponse)
|
|
}
|
|
}
|