Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix response message data race #423

Merged
merged 1 commit into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions plugin/client/plugin_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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...)
Expand All @@ -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...)
Expand All @@ -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...)
Expand All @@ -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...)
Expand Down Expand Up @@ -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"),
}
}
19 changes: 7 additions & 12 deletions plugin/storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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))

Expand All @@ -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))

Expand All @@ -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))

Expand Down