mirror of https://github.com/ceph/go-ceph
rgw/admin: remove Debug field from API type
Instead of implementing our own logging let's the consumer implement their own potential debug for each HTTP requests. Closes: https://github.com/ceph/go-ceph/issues/508 Signed-off-by: Sébastien Han <seb@redhat.com>
This commit is contained in:
parent
402707f2f5
commit
9cae71ab54
|
@ -24,9 +24,6 @@ func main() {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// To enable debug requests
|
|
||||||
// co.Debug = true
|
|
||||||
|
|
||||||
// Get the "admin" user
|
// Get the "admin" user
|
||||||
user, err := co.GetUser(context.Background(), "admin")
|
user, err := co.GetUser(context.Background(), "admin")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package admin
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -10,8 +11,7 @@ import (
|
||||||
|
|
||||||
func (suite *RadosGWTestSuite) TestBucket() {
|
func (suite *RadosGWTestSuite) TestBucket() {
|
||||||
suite.SetupConnection()
|
suite.SetupConnection()
|
||||||
co, err := New(suite.endpoint, suite.accessKey, suite.secretKey, nil)
|
co, err := New(suite.endpoint, suite.accessKey, suite.secretKey, newDebugHTTPClient(http.DefaultClient))
|
||||||
co.Debug = true
|
|
||||||
assert.NoError(suite.T(), err)
|
assert.NoError(suite.T(), err)
|
||||||
|
|
||||||
s3, err := newS3Agent(suite.accessKey, suite.secretKey, suite.endpoint, true)
|
s3, err := newS3Agent(suite.accessKey, suite.secretKey, suite.endpoint, true)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package admin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -9,8 +10,7 @@ import (
|
||||||
|
|
||||||
func (suite *RadosGWTestSuite) TestQuota() {
|
func (suite *RadosGWTestSuite) TestQuota() {
|
||||||
suite.SetupConnection()
|
suite.SetupConnection()
|
||||||
co, err := New(suite.endpoint, suite.accessKey, suite.secretKey, nil)
|
co, err := New(suite.endpoint, suite.accessKey, suite.secretKey, newDebugHTTPClient(http.DefaultClient))
|
||||||
co.Debug = true
|
|
||||||
assert.NoError(suite.T(), err)
|
assert.NoError(suite.T(), err)
|
||||||
|
|
||||||
suite.T().Run("set quota to user but user ID is empty", func(t *testing.T) {
|
suite.T().Run("set quota to user but user ID is empty", func(t *testing.T) {
|
||||||
|
|
|
@ -4,9 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -39,7 +37,6 @@ type API struct {
|
||||||
SecretKey string
|
SecretKey string
|
||||||
Endpoint string
|
Endpoint string
|
||||||
HTTPClient HTTPClient
|
HTTPClient HTTPClient
|
||||||
Debug bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns client for Ceph RGW
|
// New returns client for Ceph RGW
|
||||||
|
@ -69,7 +66,6 @@ func New(endpoint, accessKey, secretKey string, httpClient HTTPClient) (*API, er
|
||||||
AccessKey: accessKey,
|
AccessKey: accessKey,
|
||||||
SecretKey: secretKey,
|
SecretKey: secretKey,
|
||||||
HTTPClient: httpClient,
|
HTTPClient: httpClient,
|
||||||
Debug: false,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,15 +90,6 @@ func (api *API) call(ctx context.Context, httpMethod, path string, args url.Valu
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print request if Debug is enabled
|
|
||||||
if api.Debug {
|
|
||||||
dump, err := httputil.DumpRequestOut(request, true)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
log.Printf("\n%s\n", string(dump))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send HTTP request
|
// Send HTTP request
|
||||||
resp, err := api.HTTPClient.Do(request)
|
resp, err := api.HTTPClient.Do(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -110,15 +97,6 @@ func (api *API) call(ctx context.Context, httpMethod, path string, args url.Valu
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
// Print response if Debug is enabled
|
|
||||||
if api.Debug {
|
|
||||||
dump, err := httputil.DumpResponse(resp, true)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
log.Printf("\n%s\n", string(dump))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode HTTP response
|
// Decode HTTP response
|
||||||
decodedResponse, err := ioutil.ReadAll(resp.Body)
|
decodedResponse, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package admin
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/http/httputil"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -24,6 +25,36 @@ type RadosGWTestSuite struct {
|
||||||
bucketTestName string
|
bucketTestName string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type debugHTTPClient struct {
|
||||||
|
client HTTPClient
|
||||||
|
}
|
||||||
|
|
||||||
|
func newDebugHTTPClient(client HTTPClient) *debugHTTPClient {
|
||||||
|
return &debugHTTPClient{client}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *debugHTTPClient) Do(req *http.Request) (*http.Response, error) {
|
||||||
|
dump, err := httputil.DumpRequestOut(req, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
fmt.Printf("\n%s\n", string(dump))
|
||||||
|
|
||||||
|
resp, err := c.client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
dump, err = httputil.DumpResponse(resp, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
fmt.Printf("\n%s\n", string(dump))
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
func TestRadosGWTestSuite(t *testing.T) {
|
func TestRadosGWTestSuite(t *testing.T) {
|
||||||
suite.Run(t, new(RadosGWTestSuite))
|
suite.Run(t, new(RadosGWTestSuite))
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package admin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -9,8 +10,7 @@ import (
|
||||||
|
|
||||||
func (suite *RadosGWTestSuite) TestUsage() {
|
func (suite *RadosGWTestSuite) TestUsage() {
|
||||||
suite.SetupConnection()
|
suite.SetupConnection()
|
||||||
co, err := New(suite.endpoint, suite.accessKey, suite.secretKey, nil)
|
co, err := New(suite.endpoint, suite.accessKey, suite.secretKey, newDebugHTTPClient(http.DefaultClient))
|
||||||
co.Debug = true
|
|
||||||
assert.NoError(suite.T(), err)
|
assert.NoError(suite.T(), err)
|
||||||
|
|
||||||
suite.T().Run("get usage", func(t *testing.T) {
|
suite.T().Run("get usage", func(t *testing.T) {
|
||||||
|
|
|
@ -79,8 +79,7 @@ func TestUnmarshal(t *testing.T) {
|
||||||
|
|
||||||
func (suite *RadosGWTestSuite) TestUser() {
|
func (suite *RadosGWTestSuite) TestUser() {
|
||||||
suite.SetupConnection()
|
suite.SetupConnection()
|
||||||
co, err := New(suite.endpoint, suite.accessKey, suite.secretKey, nil)
|
co, err := New(suite.endpoint, suite.accessKey, suite.secretKey, newDebugHTTPClient(http.DefaultClient))
|
||||||
co.Debug = true
|
|
||||||
assert.NoError(suite.T(), err)
|
assert.NoError(suite.T(), err)
|
||||||
|
|
||||||
suite.T().Run("fail to create user since no UID provided", func(t *testing.T) {
|
suite.T().Run("fail to create user since no UID provided", func(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue