Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
This commit is contained in:
parent
8c7ae10f4c
commit
bc47aa3049
|
@ -26,7 +26,7 @@ type componentMetadata struct {
|
||||||
QueueName string `mapstructure:"queueName"`
|
QueueName string `mapstructure:"queueName"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var queueNameValidation = regexp.MustCompile("^([a-zA-Z0-9_\\-\\.]+)$")
|
var queueNameValidation = regexp.MustCompile(`^([a-zA-Z0-9_\-\.]+)$`)
|
||||||
|
|
||||||
// Validate the metadata object.
|
// Validate the metadata object.
|
||||||
func (m *componentMetadata) Validate() error {
|
func (m *componentMetadata) Validate() error {
|
||||||
|
|
|
@ -125,10 +125,8 @@ func InitBinding(s *httptest.Server, extraProps map[string]string) (bindings.Out
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
|
|
||||||
if extraProps != nil {
|
for k, v := range extraProps {
|
||||||
for k, v := range extraProps {
|
m.Properties[k] = v
|
||||||
m.Properties[k] = v
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hs := NewHTTP(logger.NewLogger("test"))
|
hs := NewHTTP(logger.NewLogger("test"))
|
||||||
|
|
|
@ -37,7 +37,7 @@ type mockClient struct {
|
||||||
zbc.Client
|
zbc.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mcf mockClientFactory) Get(metadata bindings.Metadata) (zbc.Client, error) {
|
func (mcf *mockClientFactory) Get(metadata bindings.Metadata) (zbc.Client, error) {
|
||||||
mcf.metadata = metadata //nolint:staticcheck
|
mcf.metadata = metadata //nolint:staticcheck
|
||||||
|
|
||||||
if mcf.error != nil {
|
if mcf.error != nil {
|
||||||
|
@ -53,7 +53,7 @@ func TestInit(t *testing.T) {
|
||||||
t.Run("returns error if client could not be instantiated properly", func(t *testing.T) {
|
t.Run("returns error if client could not be instantiated properly", func(t *testing.T) {
|
||||||
errParsing := errors.New("error on parsing metadata")
|
errParsing := errors.New("error on parsing metadata")
|
||||||
metadata := bindings.Metadata{}
|
metadata := bindings.Metadata{}
|
||||||
mcf := mockClientFactory{
|
mcf := &mockClientFactory{
|
||||||
error: errParsing,
|
error: errParsing,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ func TestInit(t *testing.T) {
|
||||||
|
|
||||||
t.Run("sets client from client factory", func(t *testing.T) {
|
t.Run("sets client from client factory", func(t *testing.T) {
|
||||||
metadata := bindings.Metadata{}
|
metadata := bindings.Metadata{}
|
||||||
mcf := mockClientFactory{}
|
mcf := &mockClientFactory{}
|
||||||
|
|
||||||
cmd := ZeebeCommand{clientFactory: mcf, logger: testLogger}
|
cmd := ZeebeCommand{clientFactory: mcf, logger: testLogger}
|
||||||
err := cmd.Init(context.Background(), metadata)
|
err := cmd.Init(context.Background(), metadata)
|
||||||
|
|
|
@ -37,8 +37,8 @@ type mockClient struct {
|
||||||
zbc.Client
|
zbc.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mcf mockClientFactory) Get(metadata bindings.Metadata) (zbc.Client, error) {
|
func (mcf *mockClientFactory) Get(metadata bindings.Metadata) (zbc.Client, error) {
|
||||||
mcf.metadata = metadata //nolint:staticcheck
|
mcf.metadata = metadata
|
||||||
|
|
||||||
if mcf.error != nil {
|
if mcf.error != nil {
|
||||||
return nil, mcf.error
|
return nil, mcf.error
|
||||||
|
@ -65,7 +65,7 @@ func TestInit(t *testing.T) {
|
||||||
metadata := bindings.Metadata{Base: metadata.Base{
|
metadata := bindings.Metadata{Base: metadata.Base{
|
||||||
Properties: map[string]string{"jobType": "a"},
|
Properties: map[string]string{"jobType": "a"},
|
||||||
}}
|
}}
|
||||||
mcf := mockClientFactory{
|
mcf := &mockClientFactory{
|
||||||
metadata: metadata,
|
metadata: metadata,
|
||||||
}
|
}
|
||||||
jobWorker := ZeebeJobWorker{clientFactory: mcf, logger: testLogger, closeCh: make(chan struct{})}
|
jobWorker := ZeebeJobWorker{clientFactory: mcf, logger: testLogger, closeCh: make(chan struct{})}
|
||||||
|
@ -84,7 +84,7 @@ func TestInit(t *testing.T) {
|
||||||
t.Run("returns error if client could not be instantiated properly", func(t *testing.T) {
|
t.Run("returns error if client could not be instantiated properly", func(t *testing.T) {
|
||||||
errParsing := errors.New("error on parsing metadata")
|
errParsing := errors.New("error on parsing metadata")
|
||||||
metadata := bindings.Metadata{}
|
metadata := bindings.Metadata{}
|
||||||
mcf := mockClientFactory{
|
mcf := &mockClientFactory{
|
||||||
error: errParsing,
|
error: errParsing,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ func TestInit(t *testing.T) {
|
||||||
metadata := bindings.Metadata{Base: metadata.Base{
|
metadata := bindings.Metadata{Base: metadata.Base{
|
||||||
Properties: map[string]string{"jobType": "a"},
|
Properties: map[string]string{"jobType": "a"},
|
||||||
}}
|
}}
|
||||||
mcf := mockClientFactory{
|
mcf := &mockClientFactory{
|
||||||
metadata: metadata,
|
metadata: metadata,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@ func (m *Middleware) GetHandler(_ context.Context, metadata middleware.Metadata)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tokenExpirationDuration := token.Expiry.Sub(time.Now())
|
tokenExpirationDuration := time.Until(token.Expiry)
|
||||||
m.log.Debugf("Token expires at %s (%s from now)", token.Expiry, tokenExpirationDuration)
|
m.log.Debugf("Token expires at %s (%s from now)", token.Expiry, tokenExpirationDuration)
|
||||||
|
|
||||||
headerValue = token.Type() + " " + token.AccessToken
|
headerValue = token.Type() + " " + token.AccessToken
|
||||||
|
|
|
@ -2,7 +2,6 @@ package kubemq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -148,7 +147,7 @@ func Test_kubeMQ_Close(t *testing.T) {
|
||||||
eventsClient: tt.fields.eventsClient,
|
eventsClient: tt.fields.eventsClient,
|
||||||
eventStoreClient: tt.fields.eventStoreClient,
|
eventStoreClient: tt.fields.eventStoreClient,
|
||||||
}
|
}
|
||||||
tt.wantErr(t, k.Close(), fmt.Sprintf("Close()"))
|
tt.wantErr(t, k.Close(), "Close()")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ func (m mqttMessage) Payload() []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m mqttMessage) Ack() {
|
func (m mqttMessage) Ack() {
|
||||||
return
|
// nop
|
||||||
}
|
}
|
||||||
|
|
||||||
type mockedMQTTToken struct {
|
type mockedMQTTToken struct {
|
||||||
|
@ -146,7 +146,7 @@ func (m mockedMQTTClient) Connect() mqtt.Token {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m mockedMQTTClient) Disconnect(quiesce uint) {
|
func (m mockedMQTTClient) Disconnect(quiesce uint) {
|
||||||
return
|
// nop
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m mockedMQTTClient) Publish(topic string, qos byte, retained bool, payload interface{}) mqtt.Token {
|
func (m mockedMQTTClient) Publish(topic string, qos byte, retained bool, payload interface{}) mqtt.Token {
|
||||||
|
@ -199,7 +199,7 @@ func (m mockedMQTTClient) Unsubscribe(topics ...string) mqtt.Token {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m mockedMQTTClient) AddRoute(topic string, callback mqtt.MessageHandler) {
|
func (m mockedMQTTClient) AddRoute(topic string, callback mqtt.MessageHandler) {
|
||||||
return
|
// nop
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m mockedMQTTClient) OptionsReader() mqtt.ClientOptionsReader {
|
func (m mockedMQTTClient) OptionsReader() mqtt.ClientOptionsReader {
|
||||||
|
|
|
@ -169,7 +169,7 @@ func (a *amqpPubSub) subscribeForever(ctx context.Context, receiver *amqp.Receiv
|
||||||
data := msg.GetData()
|
data := msg.GetData()
|
||||||
|
|
||||||
// if data is empty, then check the value field for data
|
// if data is empty, then check the value field for data
|
||||||
if data == nil || len(data) == 0 {
|
if len(data) == 0 {
|
||||||
data = []byte(fmt.Sprint(msg.Value))
|
data = []byte(fmt.Sprint(msg.Value))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,7 +256,7 @@ func (a *amqpPubSub) createClientOptions(uri *url.URL) amqp.ConnOptions {
|
||||||
|
|
||||||
switch scheme {
|
switch scheme {
|
||||||
case "amqp":
|
case "amqp":
|
||||||
if a.metadata.anonymous == true {
|
if a.metadata.anonymous {
|
||||||
opts.SASLType = amqp.SASLTypeAnonymous()
|
opts.SASLType = amqp.SASLTypeAnonymous()
|
||||||
} else {
|
} else {
|
||||||
opts.SASLType = amqp.SASLTypePlain(a.metadata.username, a.metadata.password)
|
opts.SASLType = amqp.SASLTypePlain(a.metadata.username, a.metadata.password)
|
||||||
|
|
|
@ -87,7 +87,7 @@ func (o *oosSecretStore) GetSecret(ctx context.Context, req secretstores.GetSecr
|
||||||
|
|
||||||
runtime := &util.RuntimeOptions{}
|
runtime := &util.RuntimeOptions{}
|
||||||
if deadline, ok := ctx.Deadline(); ok {
|
if deadline, ok := ctx.Deadline(); ok {
|
||||||
timeout := deadline.Sub(time.Now()).Milliseconds()
|
timeout := time.Until(deadline).Milliseconds()
|
||||||
runtime.SetReadTimeout(int(timeout))
|
runtime.SetReadTimeout(int(timeout))
|
||||||
}
|
}
|
||||||
output, err := o.client.GetSecretParameterWithOptions(&oos.GetSecretParameterRequest{
|
output, err := o.client.GetSecretParameterWithOptions(&oos.GetSecretParameterRequest{
|
||||||
|
@ -125,7 +125,7 @@ func (o *oosSecretStore) BulkGetSecret(ctx context.Context, req secretstores.Bul
|
||||||
for {
|
for {
|
||||||
runtime := &util.RuntimeOptions{}
|
runtime := &util.RuntimeOptions{}
|
||||||
if deadline, ok := ctx.Deadline(); ok {
|
if deadline, ok := ctx.Deadline(); ok {
|
||||||
timeout := deadline.Sub(time.Now()).Milliseconds()
|
timeout := time.Until(deadline).Milliseconds()
|
||||||
runtime.SetReadTimeout(int(timeout))
|
runtime.SetReadTimeout(int(timeout))
|
||||||
}
|
}
|
||||||
output, err := o.client.GetSecretParametersByPathWithOptions(&oos.GetSecretParametersByPathRequest{
|
output, err := o.client.GetSecretParametersByPathWithOptions(&oos.GetSecretParametersByPathRequest{
|
||||||
|
|
|
@ -78,10 +78,7 @@ func (k *keyvaultSecretStore) Init(_ context.Context, meta secretstores.Metadata
|
||||||
for suffix, environment := range keyVaultSuffixToEnvironment {
|
for suffix, environment := range keyVaultSuffixToEnvironment {
|
||||||
if strings.HasSuffix(m.VaultName, suffix) {
|
if strings.HasSuffix(m.VaultName, suffix) {
|
||||||
meta.Properties["azureEnvironment"] = environment
|
meta.Properties["azureEnvironment"] = environment
|
||||||
m.VaultName = strings.TrimSuffix(m.VaultName, suffix)
|
m.VaultName = strings.TrimPrefix(strings.TrimSuffix(m.VaultName, suffix), "https://")
|
||||||
if strings.HasPrefix(m.VaultName, "https://") {
|
|
||||||
m.VaultName = strings.TrimPrefix(m.VaultName, "https://")
|
|
||||||
}
|
|
||||||
k.vaultName = m.VaultName
|
k.vaultName = m.VaultName
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ type componentMetadata struct {
|
||||||
KVNamespaceID string `mapstructure:"kvNamespaceID"`
|
KVNamespaceID string `mapstructure:"kvNamespaceID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var kvNamespaceValidation = regexp.MustCompile("^([a-zA-Z0-9_\\-\\.]+)$")
|
var kvNamespaceValidation = regexp.MustCompile(`^([a-zA-Z0-9_\-\.]+)$`)
|
||||||
|
|
||||||
// Validate the metadata object.
|
// Validate the metadata object.
|
||||||
func (m *componentMetadata) Validate() error {
|
func (m *componentMetadata) Validate() error {
|
||||||
|
|
Loading…
Reference in New Issue