From 7cab69e5a84c0853a5442535254cf1f9b5d5d04b Mon Sep 17 00:00:00 2001 From: airycanon Date: Fri, 7 Apr 2023 18:04:05 +0800 Subject: [PATCH] fix response message --- plugin/client/plugin_client.go | 24 ++++++++++++------------ plugin/storage/client/client.go | 19 +++++++------------ 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/plugin/client/plugin_client.go b/plugin/client/plugin_client.go index f9d01ad1..7507d850 100644 --- a/plugin/client/plugin_client.go +++ b/plugin/client/plugin_client.go @@ -30,14 +30,6 @@ import ( duckv1 "knative.dev/pkg/apis/duck/v1" ) -var ( - // DefaultOptions for default plugin client options - DefaultOptions = []OptionFunc{ - ErrorOpts(&ResponseStatusErr{}), - HeaderOpts("Content-Type", "application/json"), - } -) - // PluginClient client for plugins type PluginClient struct { client *resty.Client @@ -124,7 +116,7 @@ func (p *PluginClient) WithIntegrationClassName(integrationClassName string) *Pl // Get performs a GET request using defined options func (p *PluginClient) Get(ctx context.Context, baseURL *duckv1.Addressable, path string, options ...OptionFunc) error { - clientOptions := append(DefaultOptions, MetaOpts(p.meta), SecretOpts(p.secret)) + clientOptions := append(DefaultOptions(), MetaOpts(p.meta), SecretOpts(p.secret)) options = append(clientOptions, options...) request := p.R(ctx, baseURL, options...) @@ -135,7 +127,7 @@ func (p *PluginClient) Get(ctx context.Context, baseURL *duckv1.Addressable, pat // Post performs a POST request with the given parameters func (p *PluginClient) Post(ctx context.Context, baseURL *duckv1.Addressable, path string, options ...OptionFunc) error { - clientOptions := append(DefaultOptions, MetaOpts(p.meta), SecretOpts(p.secret)) + clientOptions := append(DefaultOptions(), MetaOpts(p.meta), SecretOpts(p.secret)) options = append(clientOptions, options...) request := p.R(ctx, baseURL, options...) @@ -146,7 +138,7 @@ func (p *PluginClient) Post(ctx context.Context, baseURL *duckv1.Addressable, pa // Put performs a PUT request with the given parameters func (p *PluginClient) Put(ctx context.Context, baseURL *duckv1.Addressable, path string, options ...OptionFunc) error { - clientOptions := append(DefaultOptions, MetaOpts(p.meta), SecretOpts(p.secret)) + clientOptions := append(DefaultOptions(), MetaOpts(p.meta), SecretOpts(p.secret)) options = append(clientOptions, options...) request := p.R(ctx, baseURL, options...) @@ -157,7 +149,7 @@ func (p *PluginClient) Put(ctx context.Context, baseURL *duckv1.Addressable, pat // Delete performs a DELETE request with the given parameters func (p *PluginClient) Delete(ctx context.Context, baseURL *duckv1.Addressable, path string, options ...OptionFunc) error { - clientOptions := append(DefaultOptions, MetaOpts(p.meta), SecretOpts(p.secret)) + clientOptions := append(DefaultOptions(), MetaOpts(p.meta), SecretOpts(p.secret)) options = append(clientOptions, options...) request := p.R(ctx, baseURL, options...) @@ -467,3 +459,11 @@ func (p *PluginClient) TestCaseExecution(meta Meta, secret corev1.Secret) Client func (p *PluginClient) NewToolService() ClientToolService { return newToolService(p, p.ClassAddress) } + +// DefaultOptions for default plugin client options +func DefaultOptions() []OptionFunc { + return []OptionFunc{ + ErrorOpts(&ResponseStatusErr{}), + HeaderOpts("Content-Type", "application/json"), + } +} diff --git a/plugin/storage/client/client.go b/plugin/storage/client/client.go index c9213c72..ff1f4898 100644 --- a/plugin/storage/client/client.go +++ b/plugin/storage/client/client.go @@ -82,15 +82,16 @@ func NewStoragePluginClient(baseURL *duckv1.Addressable, opts ...BuildOptions) * // GetResponse performs a GET request using defined options and return raw resty.Response func (p *StoragePluginClient) GetResponse(ctx context.Context, path string, options ...client.OptionFunc) (*resty.Response, error) { - options = append(client.DefaultOptions, options...) + options = append(client.DefaultOptions(), options...) request := p.R(ctx, options...) + return request.Get(p.FullUrl(path)) } // Get performs a GET request using defined options func (p *StoragePluginClient) Get(ctx context.Context, path string, options ...client.OptionFunc) error { - options = append(client.DefaultOptions, options...) + options = append(client.DefaultOptions(), options...) request := p.R(ctx, options...) response, err := request.Get(p.FullUrl(path)) @@ -100,9 +101,7 @@ func (p *StoragePluginClient) Get(ctx context.Context, path string, // Post performs a POST request with the given parameters func (p *StoragePluginClient) Post(ctx context.Context, path string, options ...client.OptionFunc) error { - clientOptions := append(client.DefaultOptions) - options = append(clientOptions, options...) - + options = append(client.DefaultOptions(), options...) request := p.R(ctx, options...) response, err := request.Post(p.FullUrl(path)) @@ -112,10 +111,8 @@ func (p *StoragePluginClient) Post(ctx context.Context, path string, // Put performs a PUT request with the given parameters func (p *StoragePluginClient) Put(ctx context.Context, path string, options ...client.OptionFunc) error { - clientOptions := client.DefaultOptions - clientOptions = append(clientOptions, options...) - - request := p.R(ctx, clientOptions...) + options = append(client.DefaultOptions(), options...) + request := p.R(ctx, options...) request.SetContentLength(true) response, err := request.Put(p.FullUrl(path)) @@ -125,9 +122,7 @@ func (p *StoragePluginClient) Put(ctx context.Context, path string, // Delete performs a DELETE request with the given parameters func (p *StoragePluginClient) Delete(ctx context.Context, path string, options ...client.OptionFunc) error { - clientOptions := append(client.DefaultOptions) - options = append(clientOptions, options...) - + options = append(client.DefaultOptions(), options...) request := p.R(ctx, options...) response, err := request.Delete(p.FullUrl(path))