mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-11-24 11:09:12 +08:00
SaveAs S3 Configuration
This commit is contained in:
parent
82b0463fac
commit
9f26f2815c
@ -41,8 +41,12 @@ func ReadContent(filerAddress string, dir, name string) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SaveAs(host string, port int, dir, name string, contentType string, byteBuffer *bytes.Buffer) error {
|
func SaveAs(host string, port int, dir, name string, contentType string, byteBuffer *bytes.Buffer) error {
|
||||||
|
var target string
|
||||||
target := fmt.Sprintf("http://%s:%d%s/%s", host, port, dir, name)
|
if port == 0 {
|
||||||
|
target = fmt.Sprintf("http://%s%s/%s", host, dir, name)
|
||||||
|
} else {
|
||||||
|
target = fmt.Sprintf("http://%s:%d%s/%s", host, port, dir, name)
|
||||||
|
}
|
||||||
|
|
||||||
// set the HTTP method, url, and request body
|
// set the HTTP method, url, and request body
|
||||||
req, err := http.NewRequest(http.MethodPut, target, byteBuffer)
|
req, err := http.NewRequest(http.MethodPut, target, byteBuffer)
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package iamapi
|
package iamapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/filer"
|
||||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
"github.com/chrislusf/seaweedfs/weed/pb/iam_pb"
|
"github.com/chrislusf/seaweedfs/weed/pb/iam_pb"
|
||||||
"github.com/chrislusf/seaweedfs/weed/s3api/s3_constants"
|
"github.com/chrislusf/seaweedfs/weed/s3api/s3_constants"
|
||||||
@ -213,13 +215,15 @@ func GetActions(policy *PolicyDocument) (actions []string) {
|
|||||||
for _, resource := range statement.Resource {
|
for _, resource := range statement.Resource {
|
||||||
// Parse "arn:aws:s3:::my-bucket/shared/*"
|
// Parse "arn:aws:s3:::my-bucket/shared/*"
|
||||||
res := strings.Split(resource, ":")
|
res := strings.Split(resource, ":")
|
||||||
if len(res) != 6 || res[0] != "arn:" || res[1] != "aws" || res[2] != "s3" {
|
if len(res) != 6 || res[0] != "arn" || res[1] != "aws" || res[2] != "s3" {
|
||||||
|
glog.Infof("not math resource: %s", res)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, action := range statement.Action {
|
for _, action := range statement.Action {
|
||||||
// Parse "s3:Get*"
|
// Parse "s3:Get*"
|
||||||
act := strings.Split(action, ":")
|
act := strings.Split(action, ":")
|
||||||
if len(act) != 2 || act[0] != "s3" {
|
if len(act) != 2 || act[0] != "s3" {
|
||||||
|
glog.Infof("not match action: %s", act)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if res[5] == "*" {
|
if res[5] == "*" {
|
||||||
@ -229,8 +233,11 @@ func GetActions(policy *PolicyDocument) (actions []string) {
|
|||||||
// Parse my-bucket/shared/*
|
// Parse my-bucket/shared/*
|
||||||
path := strings.Split(res[5], "/")
|
path := strings.Split(res[5], "/")
|
||||||
if len(path) != 2 || path[1] != "*" {
|
if len(path) != 2 || path[1] != "*" {
|
||||||
actions = append(actions, fmt.Sprintf("%s:%s", MapAction(act[1]), path[0]))
|
glog.Infof("not match bucket: %s", path)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
actions = append(actions, fmt.Sprintf("%s:%s", MapAction(act[1]), path[0]))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -312,11 +319,14 @@ func (iama *IamApiServer) DoActions(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
glog.Info("values ", values)
|
glog.Info("values ", values)
|
||||||
var response interface{}
|
var response interface{}
|
||||||
|
changed := true
|
||||||
switch r.Form.Get("Action") {
|
switch r.Form.Get("Action") {
|
||||||
case "ListUsers":
|
case "ListUsers":
|
||||||
response = iama.ListUsers(s3cfg, values)
|
response = iama.ListUsers(s3cfg, values)
|
||||||
|
changed = false
|
||||||
case "ListAccessKeys":
|
case "ListAccessKeys":
|
||||||
response = iama.ListAccessKeys(s3cfg, values)
|
response = iama.ListAccessKeys(s3cfg, values)
|
||||||
|
changed = false
|
||||||
case "CreateUser":
|
case "CreateUser":
|
||||||
response = iama.CreateUser(s3cfg, values)
|
response = iama.CreateUser(s3cfg, values)
|
||||||
case "DeleteUser":
|
case "DeleteUser":
|
||||||
@ -343,5 +353,24 @@ func (iama *IamApiServer) DoActions(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeErrorResponse(w, s3err.ErrNotImplemented, r.URL)
|
writeErrorResponse(w, s3err.ErrNotImplemented, r.URL)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if changed {
|
||||||
|
buf := bytes.Buffer{}
|
||||||
|
if err := filer.S3ConfigurationToText(&buf, s3cfg); err != nil {
|
||||||
|
glog.Error("S3ConfigurationToText: ", err)
|
||||||
|
writeErrorResponse(w, s3err.ErrInternalError, r.URL)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := filer.SaveAs(
|
||||||
|
iama.option.Filer,
|
||||||
|
0,
|
||||||
|
filer.IamConfigDirecotry,
|
||||||
|
filer.IamIdentityFile,
|
||||||
|
"text/plain; charset=utf-8",
|
||||||
|
&buf); err != nil {
|
||||||
|
glog.Error("SaveAs: ", err)
|
||||||
|
writeErrorResponse(w, s3err.ErrInternalError, r.URL)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
writeSuccessResponseXML(w, encodeResponse(response))
|
writeSuccessResponseXML(w, encodeResponse(response))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user