Repository: odahu/odahu-flow (language: python)

Issue:
ecr conn. tries to validate `uri` param even when I haven't passed it
**description**
when I didn't pass `uri` for `ecr` type conn, I get this error:
`the uri parameter is empty; not valid uri for ecr type: docker-credential-ecr-login can only be used with Amazon Elastic Container Registry.`
for others only: `the uri parameter is empty`

**specification**
[ecr_no_required_parameters.txt](https://github.com/odahu/odahu-flow/files/5607521/ecr_no_required_parameters.txt)

**to reproduce**
1. run `odahuflowctl conn create -f ecr_no_required_parameters.txt`

**Expected behavior**
should show error: `the uri parameter is empty`

**Actual behavior**
shows `the uri parameter is empty; not valid uri for ecr type: docker-credential-ecr-login can only be used with Amazon Elastic Container Registry.`

**Screenshots**
![image](https://user-images.githubusercontent.com/49116723/100444907-eb02ae00-30b4-11eb-95ba-0f0335bf9a92.png)



Discussion / hints:

Fix patch:
diff --git a/packages/operator/pkg/apiserver/routes/v1/connection/connection_validation.go b/packages/operator/pkg/apiserver/routes/v1/connection/connection_validation.go
index 953ed51bb..5ed48bcfb 100644
--- a/packages/operator/pkg/apiserver/routes/v1/connection/connection_validation.go
+++ b/packages/operator/pkg/apiserver/routes/v1/connection/connection_validation.go
@@ -138,14 +138,16 @@ func (cv *ConnValidator) validateBase64Fields(conn *connection.Connection) error
 
 func (cv *ConnValidator) validateEcrType(conn *connection.Connection) (err error) {
 	// Try to parse URI
-	registry, urlParsingErr := api.ExtractRegistry(conn.Spec.URI)
-	if urlParsingErr != nil {
-		err = multierr.Append(err, fmt.Errorf(ECRTypeNotValidURI, urlParsingErr.Error()))
-	}
+	if conn.Spec.URI != "" {  // If URI is empty then skip extracting Registry and further logic
+		registry, urlParsingErr := api.ExtractRegistry(conn.Spec.URI)
+		if urlParsingErr != nil {
+			err = multierr.Append(err, fmt.Errorf(ECRTypeNotValidURI, urlParsingErr.Error()))
+		}
 
-	if len(conn.Spec.Region) == 0 && registry != nil {
-		conn.Spec.Region = registry.Region
-		logC.Info("Connection region is empty. Set region from url", "id", conn.ID, "region", registry.Region)
+		if len(conn.Spec.Region) == 0 && registry != nil {
+			conn.Spec.Region = registry.Region
+			logC.Info("Connection region is empty. Set region from url", "id", conn.ID, "region", registry.Region)
+		}
 	}
 
 	if len(conn.Spec.KeySecret) == 0 || len(conn.Spec.KeyID) == 0 {


Test patch:
diff --git a/packages/operator/pkg/apiserver/routes/v1/connection/connection_validation_test.go b/packages/operator/pkg/apiserver/routes/v1/connection/connection_validation_test.go
index 073af066b..d3acd1777 100644
--- a/packages/operator/pkg/apiserver/routes/v1/connection/connection_validation_test.go
+++ b/packages/operator/pkg/apiserver/routes/v1/connection/connection_validation_test.go
@@ -83,6 +83,22 @@ func (s *ConnectionValidationSuite) TestEmptyURL() {
 	s.g.Expect(err.Error()).Should(ContainSubstring(conn_route.EmptyURIErrorMessage))
 }
 
+
+func (s *ConnectionValidationSuite) TestEmptyURLEcr() {
+	conn := &connection.Connection{
+		Spec: v1alpha1.ConnectionSpec{
+			Type:      connection.EcrType,
+			Reference: connReference,
+			KeySecret: creds,
+		},
+	}
+	err := s.v.ValidatesAndSetDefaults(conn)
+	s.g.Expect(err).Should(HaveOccurred())
+	s.g.Expect(err.Error()).Should(ContainSubstring(conn_route.EmptyURIErrorMessage))
+	// If URI is empty then not validate ECR specific format of URI
+	s.g.Expect(err.Error()).Should(Not(ContainSubstring(conn_route.ECRTypeNotValidURI)))
+}
+
 func (s *ConnectionValidationSuite) TestUnknownTypeType() {
 	connType := v1alpha1.ConnectionType("not-existed")
 	conn := &connection.Connection{