Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
4237d08d
Unverified
Commit
4237d08d
authored
Jul 22, 2021
by
mrekucci
Committed by
GitHub
Jul 22, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(api): move bzz patch under the stewardship endpoint (#2356)
parent
6f3a3829
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
116 additions
and
10 deletions
+116
-10
Swarm.yaml
openapi/Swarm.yaml
+21
-1
bzz.go
pkg/api/bzz.go
+1
-0
bzz_test.go
pkg/api/bzz_test.go
+0
-9
router.go
pkg/api/router.go
+7
-0
stewardship.go
pkg/api/stewardship.go
+33
-0
stewardship_test.go
pkg/api/stewardship_test.go
+54
-0
No files found.
openapi/Swarm.yaml
View file @
4237d08d
...
...
@@ -232,7 +232,8 @@ paths:
"
/bzz/{reference}"
:
patch
:
summary
:
"
Reupload
a
root
hash
to
the
network"
summary
:
"
Reupload
a
root
hash
to
the
network;
deprecated:
use
/stewardship/{reference}
instead"
deprecated
:
true
tags
:
-
BZZ
parameters
:
...
...
@@ -849,3 +850,22 @@ paths:
default
:
description
:
Default response
"
/stewardship/{reference}"
:
put
:
summary
:
"
Reupload
a
root
hash
to
the
network"
tags
:
-
Stewardship
parameters
:
-
in
:
path
name
:
reference
schema
:
$ref
:
"
SwarmCommon.yaml#/components/schemas/SwarmReference"
required
:
true
description
:
"
Root
hash
of
content
(can
be
of
any
type:
collection,
file,
chunk)"
responses
:
"
200"
:
description
:
Ok
"
500"
:
$ref
:
"
SwarmCommon.yaml#/components/responses/500"
default
:
description
:
Default response
\ No newline at end of file
pkg/api/bzz.go
View file @
4237d08d
...
...
@@ -522,6 +522,7 @@ func (s *server) manifestFeed(
return
s
.
feedFactory
.
NewLookup
(
*
t
,
f
)
}
// bzzPatchHandler endpoint has been deprecated; use stewardship endpoint instead.
func
(
s
*
server
)
bzzPatchHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
nameOrHex
:=
mux
.
Vars
(
r
)[
"address"
]
address
,
err
:=
s
.
resolveNameOrAddress
(
nameOrHex
)
...
...
pkg/api/bzz_test.go
View file @
4237d08d
...
...
@@ -625,12 +625,3 @@ func TestBzzReupload(t *testing.T) {
t
.
Fatalf
(
"got address %s want %s"
,
m
.
addr
.
String
(),
addr
.
String
())
}
}
type
mockSteward
struct
{
addr
swarm
.
Address
}
func
(
m
*
mockSteward
)
Reupload
(
_
context
.
Context
,
addr
swarm
.
Address
)
error
{
m
.
addr
=
addr
return
nil
}
pkg/api/router.go
View file @
4237d08d
...
...
@@ -177,6 +177,13 @@ func (s *server) setupRouting() {
})),
)
handle
(
"/stewardship/{address}"
,
jsonhttp
.
MethodHandler
{
"PUT"
:
web
.
ChainHandlers
(
s
.
gatewayModeForbidEndpointHandler
,
web
.
FinalHandlerFunc
(
s
.
stewardshipPutHandler
),
),
})
s
.
Handler
=
web
.
ChainHandlers
(
httpaccess
.
NewHTTPAccessLogHandler
(
s
.
logger
,
logrus
.
InfoLevel
,
s
.
tracer
,
"api access"
),
handlers
.
CompressHandler
,
...
...
pkg/api/stewardship.go
0 → 100644
View file @
4237d08d
// Copyright 2021 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
api
import
(
"net/http"
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/gorilla/mux"
)
// stewardshipPutHandler re-uploads root hash and all of its underlying
// associated chunks to the network.
func
(
s
*
server
)
stewardshipPutHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
nameOrHex
:=
mux
.
Vars
(
r
)[
"address"
]
address
,
err
:=
s
.
resolveNameOrAddress
(
nameOrHex
)
if
err
!=
nil
{
s
.
logger
.
Debugf
(
"stewardship put: parse address %s: %v"
,
nameOrHex
,
err
)
s
.
logger
.
Error
(
"stewardship put: parse address"
)
jsonhttp
.
NotFound
(
w
,
nil
)
return
}
err
=
s
.
steward
.
Reupload
(
r
.
Context
(),
address
)
if
err
!=
nil
{
s
.
logger
.
Debugf
(
"stewardship put: re-upload %s: %v"
,
address
,
err
)
s
.
logger
.
Error
(
"stewardship put: re-upload"
)
jsonhttp
.
InternalServerError
(
w
,
nil
)
return
}
jsonhttp
.
OK
(
w
,
nil
)
}
pkg/api/stewardship_test.go
0 → 100644
View file @
4237d08d
// Copyright 2021 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
api_test
import
(
"context"
"io/ioutil"
"net/http"
"testing"
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest"
"github.com/ethersphere/bee/pkg/logging"
statestore
"github.com/ethersphere/bee/pkg/statestore/mock"
smock
"github.com/ethersphere/bee/pkg/storage/mock"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/tags"
)
func
TestStewardshipReUpload
(
t
*
testing
.
T
)
{
var
(
logger
=
logging
.
New
(
ioutil
.
Discard
,
0
)
mockStatestore
=
statestore
.
NewStateStore
()
m
=
&
mockSteward
{}
storer
=
smock
.
NewStorer
()
addr
=
swarm
.
NewAddress
([]
byte
{
31
:
128
})
)
client
,
_
,
_
:=
newTestServer
(
t
,
testServerOptions
{
Storer
:
storer
,
Tags
:
tags
.
NewTags
(
mockStatestore
,
logger
),
Logger
:
logger
,
Steward
:
m
,
})
jsonhttptest
.
Request
(
t
,
client
,
http
.
MethodPut
,
"/v1/stewardship/"
+
addr
.
String
(),
http
.
StatusOK
,
jsonhttptest
.
WithExpectedJSONResponse
(
jsonhttp
.
StatusResponse
{
Message
:
http
.
StatusText
(
http
.
StatusOK
),
Code
:
http
.
StatusOK
,
}),
)
if
!
m
.
addr
.
Equal
(
addr
)
{
t
.
Fatalf
(
"
\n
have address: %q
\n
want address: %q"
,
m
.
addr
.
String
(),
addr
.
String
())
}
}
type
mockSteward
struct
{
addr
swarm
.
Address
}
func
(
m
*
mockSteward
)
Reupload
(
_
context
.
Context
,
addr
swarm
.
Address
)
error
{
m
.
addr
=
addr
return
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment