diff --git a/docs/pingdom-transcation-configuration.md b/docs/pingdom-transcation-configuration.md index 59cb3c00..d33074d1 100644 --- a/docs/pingdom-transcation-configuration.md +++ b/docs/pingdom-transcation-configuration.md @@ -106,11 +106,11 @@ spec: args: input: textarea[name=q] # this will replaced with the value of the secret before sending the request to pingdom - value: '{{secret:my-secret-name:my-secret-key}}' + value: '{secret:my-secret-name:my-secret-key}' - function: basic_auth args: user: admin - password: '{{secret:my-secret-name:admin-password}}' + password: '{secret:my-secret-name:admin-password}' - function: submit args: form: form diff --git a/pkg/monitors/pingdomtransaction/pingdom-transaction-monitor.go b/pkg/monitors/pingdomtransaction/pingdom-transaction-monitor.go index 3b7d5969..17c409d4 100644 --- a/pkg/monitors/pingdomtransaction/pingdom-transaction-monitor.go +++ b/pkg/monitors/pingdomtransaction/pingdom-transaction-monitor.go @@ -160,7 +160,7 @@ func (service *PingdomTransactionMonitorService) createTransactionCheck(monitor providerConfig, _ := monitor.Config.(*endpointmonitorv1alpha1.PingdomTransactionConfig) if providerConfig == nil { // ignore monitor if type is not PingdomTransaction - log.Info("Monitor is not PingdomTransaction type" + monitor.Name) + log.Info("Monitor is not PingdomTransaction type " + monitor.Name) return nil } transactionCheck.Name = monitor.Name @@ -283,7 +283,7 @@ func (service *PingdomTransactionMonitorService) NewStepArgsByMap(input map[stri } // ReplaceSecretValuesInArgs replaces secrets in StepArgs with actual secret values from Kubernetes. -// It expects secrets to be formatted as {{secret:secret-name:key}} in the args. +// It expects secrets to be formatted as {secret:secret-name:key} in the args. // Returns an error if the secret or defined secret key cannot be retrieved. func replaceSecretValuesInArgs(args *pingdomNew.StepArgs, kubeClient KubernetesInterface, namespace string) error { if args == nil { @@ -318,7 +318,7 @@ func replaceSecretValuesInArgs(args *pingdomNew.StepArgs, kubeClient KubernetesI // parseSecretTemplate extracts secret name and key from a string template. func parseSecretTemplate(content string) (secretName string, secretKey string) { - const secretPattern = `{{secret:(.*):(.*)}}` + const secretPattern = `{secret:(.*):(.*)}` re := regexp.MustCompile(secretPattern) matches := re.FindStringSubmatch(content) diff --git a/pkg/monitors/pingdomtransaction/pingdom-transaction-monitor_test.go b/pkg/monitors/pingdomtransaction/pingdom-transaction-monitor_test.go index d3d39580..2a00a9a0 100644 --- a/pkg/monitors/pingdomtransaction/pingdom-transaction-monitor_test.go +++ b/pkg/monitors/pingdomtransaction/pingdom-transaction-monitor_test.go @@ -6,6 +6,7 @@ import ( pingdomNew "github.com/karlderkaefer/pingdom-golang-client/pkg/pingdom/openapi" "github.com/karlderkaefer/pingdom-golang-client/pkg/pingdom/openapi/ptr" + endpointmonitorv1alpha1 "github.com/stakater/IngressMonitorController/v2/api/v1alpha1" "github.com/stakater/IngressMonitorController/v2/pkg/config" "github.com/stakater/IngressMonitorController/v2/pkg/models" "github.com/stakater/IngressMonitorController/v2/pkg/util" @@ -34,47 +35,27 @@ func TestAddMonitorWithCorrectValues(t *testing.T) { log.Error(nil, "Failed to find provider") return } - - service.Setup(*provider) - m := models.Monitor{Name: "google-test", URL: "https://google1.com"} - - service.Add(m) - - mRes, err := service.GetByName("google-test") - assert.NilError(t, err) - - defer func() { - // Cleanup - service.Remove(*mRes) - }() - - if err != nil { - t.Error("Error: " + err.Error()) + spec := &endpointmonitorv1alpha1.PingdomTransactionConfig{ + Steps: []endpointmonitorv1alpha1.PingdomStep{ + { + Function: "go_to", + Args: map[string]string{ + "url": "https://google.com", + }, + }, + }, } - assert.Equal(t, mRes.Name, m.Name) - assert.Equal(t, mRes.URL, "https://google1.com") -} - -func TestUpdateMonitorWithCorrectValues(t *testing.T) { - config := config.GetControllerConfigTest() - - service := PingdomTransactionMonitorService{} - - provider := util.GetProviderWithName(config, "Pingdom") - if provider == nil { - // TODO: Currently forcing to pass the test as we dont have Pingdom account to test - // Fail this case in future when have a valid Pingdom account - log.Error(nil, "Failed to find provider") - return - } service.Setup(*provider) + m := models.Monitor{ + Name: "google-test", + URL: "https://google.com", + Config: spec, + } - // Create initial record - m := models.Monitor{Name: "google-update-test", URL: "https://google.com"} service.Add(m) - mRes, err := service.GetByName("google-update-test") + mRes, err := service.GetByName("google-test") assert.NilError(t, err) defer func() { @@ -82,18 +63,12 @@ func TestUpdateMonitorWithCorrectValues(t *testing.T) { service.Remove(*mRes) }() - // Update the record - mRes.URL = "https://facebook.com" - - service.Update(*mRes) - - mRes, err = service.GetByName("google-update-test") if err != nil { t.Error("Error: " + err.Error()) } assert.Equal(t, mRes.Name, m.Name) - assert.Equal(t, mRes.URL, "https://facebook.com") + assert.Equal(t, mRes.URL, "https://google.com") } func TestGetSecretFromTemplate(t *testing.T) { @@ -105,7 +80,7 @@ func TestGetSecretFromTemplate(t *testing.T) { }{ { name: "With Secret", - content: "This is a sample content with {{secret:my-secret:my-key}} embedded in it.", + content: "This is a sample content with {secret:my-secret:my-key} embedded in it.", expectedSecretName: "my-secret", expectedSecretKey: "my-key", }, @@ -117,7 +92,7 @@ func TestGetSecretFromTemplate(t *testing.T) { }, { name: "Invalid Format", - content: "This is a sample content with invalid secret format {{secret:my-secret}}", + content: "This is a sample content with invalid secret format {secret:my-secret}", expectedSecretName: "", expectedSecretKey: "", }, @@ -163,8 +138,8 @@ func TestReplaceSecrets(t *testing.T) { }{ { name: "Password field with secret", - password: "{{secret:my-secret:password}}", - value: "{{secret:my-secret:username}}", + password: "{secret:my-secret:password}", + value: "{secret:my-secret:username}", expectedPassword: "simple-password", expectedValue: "admin", expectError: false, @@ -179,7 +154,7 @@ func TestReplaceSecrets(t *testing.T) { }, { name: "Password field with invalid secret", - password: "{{secret:my-secret:invalidkey}}", + password: "{secret:my-secret:invalidkey}", value: "no-secret", expectedPassword: "", expectedValue: "no-secret",