Commit dfeca7c2 authored by Janoš Guljaš's avatar Janoš Guljaš Committed by GitHub

move chunks-pin endpoints from debugapi to api (#673)

parent 823f236d
......@@ -443,10 +443,85 @@ paths:
content:
application/json:
schema:
$ref: 'SwarmCommon.yaml#/components/schemas/Status'
$ref: 'SwarmCommon.yaml#/components/schemas/Status'
'404':
$ref: 'SwarmCommon.yaml#/components/responses/404'
'500':
$ref: 'SwarmCommon.yaml#/components/responses/500'
default:
description: Default response
\ No newline at end of file
description: Default response
'/pinning/chunks/{address}':
parameters:
- in: path
name: address
schema:
$ref: 'SwarmCommon.yaml#/components/schemas/SwarmAddress'
required: true
description: Swarm address of chunk
post:
summary: Pin chunk with given address
tags:
- Chunk pinning
responses:
'200':
description: Pinning chunk with address
content:
application/json:
schema:
$ref: 'SwarmCommon.yaml#/components/schemas/Response'
'400':
$ref: 'SwarmCommon.yaml#/components/responses/400'
'404':
$ref: 'SwarmCommon.yaml#/components/responses/404'
default:
description: Default response
delete:
summary: Unpin chunk with given address
tags:
- Chunk pinning
responses:
'200':
description: Unpinning chunk with address
content:
application/json:
schema:
$ref: 'SwarmCommon.yaml#/components/schemas/Response'
'400':
$ref: 'SwarmCommon.yaml#/components/responses/400'
'404':
$ref: 'SwarmCommon.yaml#/components/responses/404'
default:
description: Default response
get:
summary: Get pinning status of chunk with given address
tags:
- Chunk pinning
responses:
'200':
description: Pinning state of chunk with address
content:
application/json:
schema:
$ref: 'SwarmCommon.yaml#/components/schemas/PinningState'
'500':
$ref: 'SwarmCommon.yaml#/components/responses/500'
default:
description: Default response
'/pinning/chunks/':
get:
summary: Get list of pinned chunks
tags:
- Chunk pinning
responses:
'200':
description: List of pinned chunks
content:
application/json:
schema:
$ref: 'SwarmCommon.yaml#/components/schemas/BzzChunksPinned'
'500':
$ref: 'SwarmCommon.yaml#/components/responses/500'
default:
description: Default response
......@@ -134,81 +134,6 @@ paths:
default:
description: Default response
'/chunks-pin/{address}':
parameters:
- in: path
name: address
schema:
$ref: 'SwarmCommon.yaml#/components/schemas/SwarmAddress'
required: true
description: Swarm address of chunk
post:
summary: Pin chunk with given address
tags:
- Chunk pinning
responses:
'200':
description: Pinning chunk with address
content:
application/json:
schema:
$ref: 'SwarmCommon.yaml#/components/schemas/Response'
'400':
$ref: 'SwarmCommon.yaml#/components/responses/400'
'404':
$ref: 'SwarmCommon.yaml#/components/responses/404'
default:
description: Default response
delete:
summary: Unpin chunk with given address
tags:
- Chunk pinning
responses:
'200':
description: Unpinning chunk with address
content:
application/json:
schema:
$ref: 'SwarmCommon.yaml#/components/schemas/Response'
'400':
$ref: 'SwarmCommon.yaml#/components/responses/400'
'404':
$ref: 'SwarmCommon.yaml#/components/responses/404'
default:
description: Default response
get:
summary: Get pinning status of chunk with given address
tags:
- Chunk pinning
responses:
'200':
description: Pinning state of chunk with address
content:
application/json:
schema:
$ref: 'SwarmCommon.yaml#/components/schemas/PinningState'
'500':
$ref: 'SwarmCommon.yaml#/components/responses/500'
default:
description: Default response
'/chunks-pin/':
get:
summary: Get list of pinned chunks
tags:
- Chunk pinning
responses:
'200':
description: List of pinned chunks
content:
application/json:
schema:
$ref: 'SwarmCommon.yaml#/components/schemas/BzzChunksPinned'
'500':
$ref: 'SwarmCommon.yaml#/components/responses/500'
default:
description: Default response
'/connect/{multiAddress}':
post:
summary: Connect to address
......
......@@ -9,10 +9,12 @@ import "github.com/ethersphere/bee/pkg/swarm"
type Server = server
type (
BytesPostResponse = bytesPostResponse
FileUploadResponse = fileUploadResponse
TagResponse = tagResponse
TagRequest = tagRequest
BytesPostResponse = bytesPostResponse
FileUploadResponse = fileUploadResponse
TagResponse = tagResponse
TagRequest = tagRequest
PinnedChunk = pinnedChunk
ListPinnedChunksResponse = listPinnedChunksResponse
)
var (
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package debugapi
package api
import (
"errors"
......@@ -52,7 +52,7 @@ func (s *server) pinChunk(w http.ResponseWriter, r *http.Request) {
func (s *server) unpinChunk(w http.ResponseWriter, r *http.Request) {
addr, err := swarm.ParseHexAddress(mux.Vars(r)["address"])
if err != nil {
s.Logger.Debugf("debug api: pin chunk: parse chunk ddress: %v", err)
s.Logger.Debugf("debug api: pin chunk: parse chunk address: %v", err)
jsonhttp.BadRequest(w, "bad address")
return
}
......
......@@ -81,6 +81,15 @@ func (s *server) setupRouting() {
),
})
handle(router, "/pinning/chunks/{address}", jsonhttp.MethodHandler{
"GET": http.HandlerFunc(s.getPinnedChunk),
"POST": http.HandlerFunc(s.pinChunk),
"DELETE": http.HandlerFunc(s.unpinChunk),
})
handle(router, "/pinning/chunks", jsonhttp.MethodHandler{
"GET": http.HandlerFunc(s.listPinnedChunks),
})
s.Handler = web.ChainHandlers(
logging.NewHTTPAccessLogHandler(s.Logger, logrus.InfoLevel, "api access"),
handlers.CompressHandler,
......
......@@ -12,13 +12,11 @@ import (
"testing"
accountingmock "github.com/ethersphere/bee/pkg/accounting/mock"
"github.com/ethersphere/bee/pkg/api"
"github.com/ethersphere/bee/pkg/debugapi"
"github.com/ethersphere/bee/pkg/logging"
p2pmock "github.com/ethersphere/bee/pkg/p2p/mock"
"github.com/ethersphere/bee/pkg/pingpong"
"github.com/ethersphere/bee/pkg/resolver"
resolverMock "github.com/ethersphere/bee/pkg/resolver/mock"
"github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/tags"
......@@ -67,26 +65,6 @@ func newTestServer(t *testing.T, o testServerOptions) *testServer {
}
}
func newBZZTestServer(t *testing.T, o testServerOptions) *http.Client {
if o.Resolver == nil {
o.Resolver = resolverMock.NewResolver()
}
s := api.New(o.Tags, o.Storer, o.Resolver, nil, logging.New(ioutil.Discard, 0), nil)
ts := httptest.NewServer(s)
t.Cleanup(ts.Close)
return &http.Client{
Transport: web.RoundTripperFunc(func(r *http.Request) (*http.Response, error) {
u, err := url.Parse(ts.URL + r.URL.String())
if err != nil {
return nil, err
}
r.URL = u
return ts.Client().Transport.RoundTrip(r)
}),
}
}
func mustMultiaddr(t *testing.T, s string) multiaddr.Multiaddr {
t.Helper()
......
......@@ -5,17 +5,15 @@
package debugapi
type (
StatusResponse = statusResponse
PingpongResponse = pingpongResponse
PeerConnectResponse = peerConnectResponse
PeersResponse = peersResponse
AddressesResponse = addressesResponse
PinnedChunk = pinnedChunk
ListPinnedChunksResponse = listPinnedChunksResponse
WelcomeMessageRequest = welcomeMessageRequest
WelcomeMessageResponse = welcomeMessageResponse
BalancesResponse = balancesResponse
BalanceResponse = balanceResponse
StatusResponse = statusResponse
PingpongResponse = pingpongResponse
PeerConnectResponse = peerConnectResponse
PeersResponse = peersResponse
AddressesResponse = addressesResponse
WelcomeMessageRequest = welcomeMessageRequest
WelcomeMessageResponse = welcomeMessageResponse
BalancesResponse = balancesResponse
BalanceResponse = balanceResponse
)
var (
......
......@@ -70,14 +70,6 @@ func (s *server) setupRouting() {
"GET": http.HandlerFunc(s.hasChunkHandler),
"DELETE": http.HandlerFunc(s.removeChunk),
})
router.Handle("/chunks-pin/{address}", jsonhttp.MethodHandler{
"GET": http.HandlerFunc(s.getPinnedChunk),
"POST": http.HandlerFunc(s.pinChunk),
"DELETE": http.HandlerFunc(s.unpinChunk),
})
router.Handle("/chunks-pin", jsonhttp.MethodHandler{
"GET": http.HandlerFunc(s.listPinnedChunks),
})
router.Handle("/topology", jsonhttp.MethodHandler{
"GET": http.HandlerFunc(s.topologyHandler),
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment