Skip to content

Commit

Permalink
refractor: bucket handler
Browse files Browse the repository at this point in the history
  • Loading branch information
imstevez committed Sep 2, 2023
1 parent b7eca10 commit 187f740
Show file tree
Hide file tree
Showing 30 changed files with 430 additions and 429 deletions.
4 changes: 2 additions & 2 deletions blocks/blockstoreutil/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ func RmBlocks(ctx context.Context, blocks bs.GCBlockstore, pins pin.Pinner, cids
}

// FilterPinned takes a slice of Cids and returns it with the pinned Cids
// removed. If a Cid is pinned, it will place RemovedBlock objects in the given
// out channel, with an error which indicates that the Cid is pinned.
// removed. If a CID is pinned, it will place RemovedBlock objects in the given
// out channel, with an error which indicates that the CID is pinned.
// This function is used in RmBlocks to filter out any blocks which are not
// to be removed (because they are pinned).
func FilterPinned(ctx context.Context, pins pin.Pinner, out chan<- interface{}, cids []cid.Cid) []cid.Cid {
Expand Down
2 changes: 1 addition & 1 deletion core/commands/cid.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ The optional format string is a printf style format string:
}

type CidFormatRes struct {
CidStr string // Original Cid String passed in
CidStr string // Original CID String passed in
Formatted string // Formatted Result
ErrorMsg string // Error
}
Expand Down
2 changes: 1 addition & 1 deletion core/commands/cmdenv/cidbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func CidBaseDefined(req *cmds.Request) bool {
}

// CidEncoderFromPath creates a new encoder that is influenced from
// the encoded Cid in a Path. For CidV0 the multibase from the base
// the encoded CID in a Path. For CidV0 the multibase from the base
// encoder is used and automatic upgrades are disabled. For CidV1 the
// multibase from the CID is used and upgrades are enabled.
//
Expand Down
4 changes: 2 additions & 2 deletions core/commands/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ const (
filesHashOptionName = "hash"
)

var cidVersionOption = cmds.IntOption(filesCidVersionOptionName, "cid-ver", "Cid version to use. (experimental)")
var hashOption = cmds.StringOption(filesHashOptionName, "Hash function to use. Will set Cid version to 1 if used. (experimental)")
var cidVersionOption = cmds.IntOption(filesCidVersionOptionName, "cid-ver", "CID version to use. (experimental)")
var hashOption = cmds.StringOption(filesHashOptionName, "Hash function to use. Will set CID version to 1 if used. (experimental)")

var errFormat = errors.New("format was set by multiple options. Only one format option is allowed")

Expand Down
4 changes: 2 additions & 2 deletions core/commands/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ The output is:
`,
},
Arguments: []cmds.Argument{
cmds.StringArg("obj", false, true, "Cid of objects to list."),
cmds.StringArg("obj", false, true, "CID of objects to list."),
},
Options: []cmds.Option{
cmds.BoolOption(fileOrderOptionName, "sort the results based on the path of the backing file"),
Expand Down Expand Up @@ -122,7 +122,7 @@ For ERROR entries the error will also be printed to stderr.
`,
},
Arguments: []cmds.Argument{
cmds.StringArg("obj", false, true, "Cid of objects to verify."),
cmds.StringArg("obj", false, true, "CID of objects to verify."),
},
Options: []cmds.Option{
cmds.BoolOption(fileOrderOptionName, "verify the objects based on the order of the backing file"),
Expand Down
2 changes: 1 addition & 1 deletion core/commands/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func (rw *RefWriter) visit(c cid.Cid, depth int) (bool, bool) {
// Unique == true && depth < MaxDepth (or unlimited) from this point

// Branch pruning cases:
// - We saw the Cid before and either:
// - We saw the CID before and either:
// - Depth is unlimited (MaxDepth = -1)
// - We saw it higher (smaller depth) in the DAG (means we must have
// explored deep enough before)
Expand Down
2 changes: 1 addition & 1 deletion core/corehttp/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type IPFSBackend interface {
// Get returns a GetResponse with UnixFS file, directory or a block in IPLD
// format e.g., (DAG-)CBOR/JSON.
//
// Returned Directories are preferably a minimum info required for enumeration: Name, Size, and Cid.
// Returned Directories are preferably a minimum info required for enumeration: Name, Size, and CID.
//
// Optional ranges follow [HTTP Byte Ranges] notation and can be used for
// pre-fetching specific sections of a file or a block.
Expand Down
6 changes: 3 additions & 3 deletions core/corehttp/gateway/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ func TestIPNSHostnameRedirect(t *testing.T) {
// assert.Contains(t, s, "<a class=\"btfs-hash\" translate=\"no\" href=\"https://cid.btfs.tech/#", "expected links to cid.btfs.tech in CID column when on DNSLink website")
// assert.Contains(t, s, "<a href=\"/foo%3F%20%23%3C%27/..\">", "expected backlink in directory listing")
// assert.Contains(t, s, "<a href=\"/foo%3F%20%23%3C%27/file.txt\">", "expected file in directory listing")
// assert.Contains(t, s, s, k2.Cid().String(), "expected hash in directory listing")
// assert.Contains(t, s, s, k2.CID().String(), "expected hash in directory listing")

// // make request to directory listing at root
// req, err = http.NewRequest(http.MethodGet, ts.URL, nil)
Expand All @@ -440,7 +440,7 @@ func TestIPNSHostnameRedirect(t *testing.T) {
// assert.Contains(t, s, "<a href=\"/file.txt\">", "expected file in directory listing")
// // https://github.com/btfs/dir-index-html/issues/42
// assert.Contains(t, s, "<a class=\"btfs-hash\" translate=\"no\" href=\"https://cid.btfs.tech/#", "expected links to cid.btfs.tech in CID column when on DNSLink website")
// assert.Contains(t, s, k.Cid().String(), "expected hash in directory listing")
// assert.Contains(t, s, k.CID().String(), "expected hash in directory listing")

// // make request to directory listing
// req, err = http.NewRequest(http.MethodGet, ts.URL+"/foo%3F%20%23%3C%27/bar/", nil)
Expand All @@ -460,7 +460,7 @@ func TestIPNSHostnameRedirect(t *testing.T) {
// assert.True(t, matchPathOrBreadcrumbs(s, "/btns/<a href=\"//example.net/\">example.net</a>/<a href=\"//example.net/foo%3F%20%23%3C%27\">foo? #&lt;&#39;</a>/<a href=\"//example.net/foo%3F%20%23%3C%27/bar\">bar</a>"), "expected a path in directory listing")
// assert.Contains(t, s, "<a href=\"/foo%3F%20%23%3C%27/bar/..\">", "expected backlink in directory listing")
// assert.Contains(t, s, "<a href=\"/foo%3F%20%23%3C%27/bar/file.txt\">", "expected file in directory listing")
// assert.Contains(t, s, k3.Cid().String(), "expected hash in directory listing")
// assert.Contains(t, s, k3.CID().String(), "expected hash in directory listing")
// }

func TestPretty404(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
require (
bazil.org/fuse v0.0.0-20200117225306-7b5117fecadc
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137
github.com/aws/aws-sdk-go v1.27.0
github.com/aws/aws-sdk-go v1.45.2
github.com/bittorrent/go-btfs-api v0.5.0
github.com/bittorrent/go-btfs-chunker v0.4.0
github.com/bittorrent/go-btfs-cmds v0.3.0
Expand Down Expand Up @@ -181,7 +181,7 @@ require (
github.com/ipfs/go-ipld-legacy v0.1.1 // indirect
github.com/ipfs/go-ipns v0.3.0 // indirect
github.com/ipld/edelweiss v0.2.0 // indirect
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/libp2p/go-libp2p-core v0.20.1 // indirect
github.com/libp2p/go-libp2p-xor v0.1.0 // indirect
github.com/libp2p/go-yamux/v4 v4.0.0 // indirect
Expand Down
12 changes: 10 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj
github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
github.com/aws/aws-sdk-go v1.27.0 h1:0xphMHGMLBrPMfxR2AmVjZKcMEESEgWF8Kru94BNByk=
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.45.2 h1:hTong9YUklQKqzrGk3WnKABReb5R8GjbG4Y6dEQfjnk=
github.com/aws/aws-sdk-go v1.45.2/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
Expand Down Expand Up @@ -894,8 +895,11 @@ github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
Expand Down Expand Up @@ -1960,6 +1964,7 @@ golang.org/x/net v0.0.0-20220531201128-c960675eff93/go.mod h1:XRhObCWvk6IyKnWLug
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.0.0-20220920183852-bf014ff85ad5/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
Expand Down Expand Up @@ -2089,13 +2094,15 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -2106,6 +2113,7 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
8 changes: 4 additions & 4 deletions s3/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ const (
// DeleteBucketAction - DeleteBucket Rest API action.
DeleteBucketAction = "s3:DeleteBucket"

// PutBucketAclAction - PutBucketAcl Rest API action.
PutBucketAclAction = "s3:PutBucketAcl"
// PutBucketAclAction - PutBucketACL Rest API action.
PutBucketAclAction = "s3:PutBucketACL"

// GetBucketAclAction - GetBucketAcl Rest API action.
GetBucketAclAction = "s3:GetBucketAcl"
// GetBucketAclAction - GetBucketACL Rest API action.
GetBucketAclAction = "s3:GetBucketACL"

//--- object

Expand Down
24 changes: 19 additions & 5 deletions s3/consts/consts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package consts

import (
"github.com/aws/aws-sdk-go/service/s3"
"github.com/dustin/go-humanize"
"time"
)
Expand All @@ -16,8 +17,6 @@ const (
MaxLocationConstraintSize = 3 * humanize.MiByte
EmptySHA256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
StsRequestBodyLimit = 10 * (1 << 20) // 10 MiB
DefaultRegion = ""
DefaultAcl = "public-read"
SlashSeparator = "/"

MaxSkewTime = 15 * time.Minute // 15 minutes skew allowed.
Expand All @@ -29,11 +28,26 @@ const (
AssumeRole = "AssumeRole"
SignV4Algorithm = "AWS4-HMAC-SHA256"

DefaultOwnerID = "02d6176db174dc93cb1b899f7c6078f08654445fe8cf1b6ce98d8855f66bdbf4"
DisplayName = "FileDagStorage"
DefaultStorageClass = "DAGSTORE"
DefaultLocation = "us-east-1"
DefaultBucketACL = s3.BucketCannedACLPublicRead
DefaultObjectACL = ""
AllUsersURI = "http://acs.amazonaws.com/groups/global/AllUsers"
)

var SupportedLocations = map[string]bool{
DefaultLocation: true,
}

var SupportedBucketACLs = map[string]bool{
s3.BucketCannedACLPrivate: true,
s3.BucketCannedACLPublicRead: true,
s3.BucketCannedACLPublicReadWrite: true,
}

var SupportedObjectACLs = map[string]bool{
DefaultObjectACL: true,
}

// Standard S3 HTTP request constants
const (
IfModifiedSince = "If-Modified-Since"
Expand Down
12 changes: 6 additions & 6 deletions s3/handlers/handlers_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (h *Handlers) CreateBucketHandler(w http.ResponseWriter, r *http.Request) {
cctx.SetHandleInf(r, h.name(), err)
}()

req, rerr := requests.ParsePutBucketRequest(r)
req, rerr := requests.ParseCreateBucketRequest(r)
if rerr != nil {
err = rerr
responses.WriteErrorResponse(w, r, rerr)
Expand Down Expand Up @@ -119,7 +119,7 @@ func (h *Handlers) ListBucketsHandler(w http.ResponseWriter, r *http.Request) {
return
}

responses.WriteListBucketsResponse(w, r, req.AccessKey, "", list)
responses.WriteListBucketsResponse(w, r, req.AccessKey, list)

return
}
Expand All @@ -130,21 +130,21 @@ func (h *Handlers) GetBucketAclHandler(w http.ResponseWriter, r *http.Request) {
cctx.SetHandleInf(r, h.name(), err)
}()

req, rerr := requests.ParseGetBucketAclRequest(r)
req, rerr := requests.ParseGetBucketACLRequest(r)
if rerr != nil {
err = rerr
responses.WriteErrorResponse(w, r, rerr)
return
}

acl, err := h.objsvc.GetBucketAcl(r.Context(), req.AccessKey, req.Bucket)
acl, err := h.objsvc.GetBucketACL(r.Context(), req.AccessKey, req.Bucket)
if err != nil {
rerr = h.respErr(err)
responses.WriteErrorResponse(w, r, rerr)
return
}

responses.WriteGetBucketAclResponse(w, r, req.AccessKey, "", acl)
responses.WriteGetBucketACLResponse(w, r, req.AccessKey, acl)
}

func (h *Handlers) PutBucketAclHandler(w http.ResponseWriter, r *http.Request) {
Expand All @@ -160,7 +160,7 @@ func (h *Handlers) PutBucketAclHandler(w http.ResponseWriter, r *http.Request) {
return
}

err = h.objsvc.PutBucketAcl(r.Context(), req.AccessKey, req.Bucket, req.ACL)
err = h.objsvc.PutBucketACL(r.Context(), req.AccessKey, req.Bucket, req.ACL)
if err != nil {
rerr = h.respErr(err)
responses.WriteErrorResponse(w, r, rerr)
Expand Down
2 changes: 1 addition & 1 deletion s3/handlers/handlers_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ const lockWaitTimeout = 5 * time.Minute
// }
// defer runlock()
//
// acl, err := h.bucsvc.GetBucketAcl(ctx, bucname)
// acl, err := h.bucsvc.GetBucketACL(ctx, bucname)
// if err != nil {
// responses.WriteErrorResponse(w, r, err)
// return
Expand Down
Loading

0 comments on commit 187f740

Please sign in to comment.