aboutsummaryrefslogtreecommitdiff
path: root/weed/iamapi
diff options
context:
space:
mode:
authorChris Lu <chrislusf@users.noreply.github.com>2022-03-29 22:36:26 -0700
committerGitHub <noreply@github.com>2022-03-29 22:36:26 -0700
commit8732cc24c8f64634aa4e14dbb9e400bf84640a2d (patch)
treef6703a087be07ff9343c29ab3158d0626e4ed3d3 /weed/iamapi
parent683581c4127ab77a73e1bdcd143a9b3a6d642f78 (diff)
parented07e76f0e888451d00e4ee19f957ebdd8339acb (diff)
downloadseaweedfs-8732cc24c8f64634aa4e14dbb9e400bf84640a2d.tar.xz
seaweedfs-8732cc24c8f64634aa4e14dbb9e400bf84640a2d.zip
Merge pull request #2849 from guo-sj/update_user
Add AWS IAM update user API and its test case
Diffstat (limited to 'weed/iamapi')
-rw-r--r--weed/iamapi/iamapi_management_handlers.go32
-rw-r--r--weed/iamapi/iamapi_response.go5
-rw-r--r--weed/iamapi/iamapi_test.go21
3 files changed, 50 insertions, 8 deletions
diff --git a/weed/iamapi/iamapi_management_handlers.go b/weed/iamapi/iamapi_management_handlers.go
index e8092020b..a7ca69f45 100644
--- a/weed/iamapi/iamapi_management_handlers.go
+++ b/weed/iamapi/iamapi_management_handlers.go
@@ -4,10 +4,6 @@ import (
"crypto/sha1"
"encoding/json"
"fmt"
- "github.com/chrislusf/seaweedfs/weed/glog"
- "github.com/chrislusf/seaweedfs/weed/pb/iam_pb"
- "github.com/chrislusf/seaweedfs/weed/s3api/s3_constants"
- "github.com/chrislusf/seaweedfs/weed/s3api/s3err"
"math/rand"
"net/http"
"net/url"
@@ -16,6 +12,11 @@ import (
"sync"
"time"
+ "github.com/chrislusf/seaweedfs/weed/glog"
+ "github.com/chrislusf/seaweedfs/weed/pb/iam_pb"
+ "github.com/chrislusf/seaweedfs/weed/s3api/s3_constants"
+ "github.com/chrislusf/seaweedfs/weed/s3api/s3err"
+
"github.com/aws/aws-sdk-go/service/iam"
)
@@ -155,6 +156,22 @@ func (iama *IamApiServer) GetUser(s3cfg *iam_pb.S3ApiConfiguration, userName str
return resp, fmt.Errorf(iam.ErrCodeNoSuchEntityException)
}
+func (iama *IamApiServer) UpdateUser(s3cfg *iam_pb.S3ApiConfiguration, values url.Values) (resp UpdateUserResponse, err error) {
+ userName := values.Get("UserName")
+ newUserName := values.Get("NewUserName")
+ if newUserName != "" {
+ for _, ident := range s3cfg.Identities {
+ if userName == ident.Name {
+ ident.Name = newUserName
+ return resp, nil
+ }
+ }
+ } else {
+ return resp, nil
+ }
+ return resp, fmt.Errorf(iam.ErrCodeNoSuchEntityException)
+}
+
func GetPolicyDocument(policy *string) (policyDocument PolicyDocument, err error) {
if err = json.Unmarshal([]byte(*policy), &policyDocument); err != nil {
return PolicyDocument{}, err
@@ -396,6 +413,13 @@ func (iama *IamApiServer) DoActions(w http.ResponseWriter, r *http.Request) {
return
}
changed = false
+ case "UpdateUser":
+ response, err = iama.UpdateUser(s3cfg, values)
+ if err != nil {
+ glog.Errorf("UpdateUser: %+v", err)
+ s3err.WriteErrorResponse(w, r, s3err.ErrInvalidRequest)
+ return
+ }
case "DeleteUser":
userName := values.Get("UserName")
response, err = iama.DeleteUser(s3cfg, userName)
diff --git a/weed/iamapi/iamapi_response.go b/weed/iamapi/iamapi_response.go
index 77328b608..df9443f0d 100644
--- a/weed/iamapi/iamapi_response.go
+++ b/weed/iamapi/iamapi_response.go
@@ -66,6 +66,11 @@ type GetUserResponse struct {
} `xml:"GetUserResult"`
}
+type UpdateUserResponse struct {
+ CommonResponse
+ XMLName xml.Name `xml:"https://iam.amazonaws.com/doc/2010-05-08/ UpdateUserResponse"`
+}
+
type CreateAccessKeyResponse struct {
CommonResponse
XMLName xml.Name `xml:"https://iam.amazonaws.com/doc/2010-05-08/ CreateAccessKeyResponse"`
diff --git a/weed/iamapi/iamapi_test.go b/weed/iamapi/iamapi_test.go
index 09aaf0ac8..5b21e4293 100644
--- a/weed/iamapi/iamapi_test.go
+++ b/weed/iamapi/iamapi_test.go
@@ -2,6 +2,10 @@ package iamapi
import (
"encoding/xml"
+ "net/http"
+ "net/http/httptest"
+ "testing"
+
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/iam"
@@ -9,9 +13,6 @@ import (
"github.com/gorilla/mux"
"github.com/jinzhu/copier"
"github.com/stretchr/testify/assert"
- "net/http"
- "net/http/httptest"
- "testing"
)
var GetS3ApiConfiguration func(s3cfg *iam_pb.S3ApiConfiguration) (err error)
@@ -161,8 +162,20 @@ func TestGetUserPolicy(t *testing.T) {
assert.Equal(t, http.StatusOK, response.Code)
}
-func TestDeleteUser(t *testing.T) {
+func TestUpdateUser(t *testing.T) {
userName := aws.String("Test")
+ newUserName := aws.String("Test-New")
+ params := &iam.UpdateUserInput{NewUserName: newUserName, UserName: userName}
+ req, _ := iam.New(session.New()).UpdateUserRequest(params)
+ _ = req.Build()
+ out := UpdateUserResponse{}
+ response, err := executeRequest(req.HTTPRequest, out)
+ assert.Equal(t, nil, err)
+ assert.Equal(t, http.StatusOK, response.Code)
+}
+
+func TestDeleteUser(t *testing.T) {
+ userName := aws.String("Test-New")
params := &iam.DeleteUserInput{UserName: userName}
req, _ := iam.New(session.New()).DeleteUserRequest(params)
_ = req.Build()