aboutsummaryrefslogtreecommitdiff
path: root/weed/filer
diff options
context:
space:
mode:
Diffstat (limited to 'weed/filer')
-rw-r--r--weed/filer/filer_conf.go2
-rw-r--r--weed/filer/read.go27
-rw-r--r--weed/filer/read_write.go63
-rw-r--r--weed/filer/s3iam_conf.go25
-rw-r--r--weed/filer/s3iam_conf_test.go57
5 files changed, 147 insertions, 27 deletions
diff --git a/weed/filer/filer_conf.go b/weed/filer/filer_conf.go
index d56db3b8e..6a746f7ba 100644
--- a/weed/filer/filer_conf.go
+++ b/weed/filer/filer_conf.go
@@ -15,6 +15,8 @@ import (
const (
DirectoryEtc = "/etc"
FilerConfName = "filer.conf"
+ IamConfigDirecotry = "/etc/iam"
+ IamIdentityFile = "identity.json"
)
type FilerConf struct {
diff --git a/weed/filer/read.go b/weed/filer/read.go
deleted file mode 100644
index 13f282dc7..000000000
--- a/weed/filer/read.go
+++ /dev/null
@@ -1,27 +0,0 @@
-package filer
-
-import (
- "bytes"
- "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
- "github.com/chrislusf/seaweedfs/weed/wdclient"
- "math"
-)
-
-func ReadEntry(masterClient *wdclient.MasterClient, filerClient filer_pb.SeaweedFilerClient, dir, name string, byteBuffer *bytes.Buffer) error {
-
- request := &filer_pb.LookupDirectoryEntryRequest{
- Directory: dir,
- Name: name,
- }
- respLookupEntry, err := filer_pb.LookupEntry(filerClient, request)
- if err != nil {
- return err
- }
- if len(respLookupEntry.Entry.Content) > 0 {
- _, err = byteBuffer.Write(respLookupEntry.Entry.Content)
- return err
- }
-
- return StreamContent(masterClient, byteBuffer, respLookupEntry.Entry.Chunks, 0, math.MaxInt64)
-
-}
diff --git a/weed/filer/read_write.go b/weed/filer/read_write.go
new file mode 100644
index 000000000..8561d848b
--- /dev/null
+++ b/weed/filer/read_write.go
@@ -0,0 +1,63 @@
+package filer
+
+import (
+ "bytes"
+ "fmt"
+ "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
+ "github.com/chrislusf/seaweedfs/weed/util"
+ "github.com/chrislusf/seaweedfs/weed/wdclient"
+ "math"
+ "net/http"
+)
+
+func ReadEntry(masterClient *wdclient.MasterClient, filerClient filer_pb.SeaweedFilerClient, dir, name string, byteBuffer *bytes.Buffer) error {
+
+ request := &filer_pb.LookupDirectoryEntryRequest{
+ Directory: dir,
+ Name: name,
+ }
+ respLookupEntry, err := filer_pb.LookupEntry(filerClient, request)
+ if err != nil {
+ return err
+ }
+ if len(respLookupEntry.Entry.Content) > 0 {
+ _, err = byteBuffer.Write(respLookupEntry.Entry.Content)
+ return err
+ }
+
+ return StreamContent(masterClient, byteBuffer, respLookupEntry.Entry.Chunks, 0, math.MaxInt64)
+
+}
+
+func ReadContent(filerAddress string, dir, name string) ([]byte, error) {
+
+ target := fmt.Sprintf("http://%s%s/%s", filerAddress, dir, name)
+
+ data, _, err := util.Get(target)
+
+ return data, err
+}
+
+func SaveAs(host string, port int, dir, name string, contentType string, byteBuffer *bytes.Buffer) error {
+
+ target := fmt.Sprintf("http://%s:%d%s/%s", host, port, dir, name)
+
+ // set the HTTP method, url, and request body
+ req, err := http.NewRequest(http.MethodPut, target, byteBuffer)
+ if err != nil {
+ return err
+ }
+
+ // set the request header Content-Type for json
+ if contentType != "" {
+ req.Header.Set("Content-Type", contentType)
+ }
+ resp, err := http.DefaultClient.Do(req)
+ if err != nil {
+ return err
+ }
+ util.CloseResponse(resp)
+
+ return nil
+
+}
diff --git a/weed/filer/s3iam_conf.go b/weed/filer/s3iam_conf.go
new file mode 100644
index 000000000..92387fb09
--- /dev/null
+++ b/weed/filer/s3iam_conf.go
@@ -0,0 +1,25 @@
+package filer
+
+import (
+ "bytes"
+ "github.com/chrislusf/seaweedfs/weed/pb/iam_pb"
+ "github.com/golang/protobuf/jsonpb"
+ "io"
+)
+
+func ParseS3ConfigurationFromBytes(content []byte, config *iam_pb.S3ApiConfiguration) error {
+ if err := jsonpb.Unmarshal(bytes.NewBuffer(content), config); err != nil {
+ return err
+ }
+ return nil
+}
+
+func S3ConfigurationToText(writer io.Writer, config *iam_pb.S3ApiConfiguration) error {
+
+ m := jsonpb.Marshaler{
+ EmitDefaults: false,
+ Indent: " ",
+ }
+
+ return m.Marshal(writer, config)
+}
diff --git a/weed/filer/s3iam_conf_test.go b/weed/filer/s3iam_conf_test.go
new file mode 100644
index 000000000..88f446151
--- /dev/null
+++ b/weed/filer/s3iam_conf_test.go
@@ -0,0 +1,57 @@
+package filer
+
+import (
+ "bytes"
+ "github.com/chrislusf/seaweedfs/weed/s3api"
+ "testing"
+
+ "github.com/chrislusf/seaweedfs/weed/pb/iam_pb"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestS3Conf(t *testing.T) {
+ s3Conf := &iam_pb.S3ApiConfiguration{
+ Identities: []*iam_pb.Identity{
+ {
+ Name: "some_name",
+ Credentials: []*iam_pb.Credential{
+ {
+ AccessKey: "some_access_key1",
+ SecretKey: "some_secret_key1",
+ },
+ },
+ Actions: []string{
+ s3api.ACTION_ADMIN,
+ s3api.ACTION_READ,
+ s3api.ACTION_WRITE,
+ },
+ },
+ {
+ Name: "some_read_only_user",
+ Credentials: []*iam_pb.Credential{
+ {
+ AccessKey: "some_access_key2",
+ SecretKey: "some_secret_key2",
+ },
+ },
+ Actions: []string{
+ s3api.ACTION_READ,
+ s3api.ACTION_TAGGING,
+ s3api.ACTION_LIST,
+ },
+ },
+ },
+ }
+ var buf bytes.Buffer
+ err := S3ConfigurationToText(&buf, s3Conf)
+ assert.Equal(t, err, nil)
+ s3ConfSaved := &iam_pb.S3ApiConfiguration{}
+ err = ParseS3ConfigurationFromBytes(buf.Bytes(), s3ConfSaved)
+ assert.Equal(t, err, nil)
+
+ assert.Equal(t, "some_name", s3ConfSaved.Identities[0].Name)
+ assert.Equal(t, "some_read_only_user", s3ConfSaved.Identities[1].Name)
+ assert.Equal(t, "some_access_key1", s3ConfSaved.Identities[0].Credentials[0].AccessKey)
+ assert.Equal(t, "some_secret_key2", s3ConfSaved.Identities[1].Credentials[0].SecretKey)
+}