You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2022/03/08 20:28:08 UTC

[GitHub] [nifi] jfrazee commented on a change in pull request #5846: NIFI-9728: Added support for User Assigned Managed Identity authentic…

jfrazee commented on a change in pull request #5846:
URL: https://github.com/apache/nifi/pull/5846#discussion_r822037142



##########
File path: nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/services/azure/storage/ADLSCredentialsControllerService.java
##########
@@ -103,39 +106,50 @@
     protected Collection<ValidationResult> customValidate(ValidationContext validationContext) {
         final List<ValidationResult> results = new ArrayList<>();
 
-        boolean accountKeySet = StringUtils.isNotBlank(validationContext.getProperty(AzureStorageUtils.ACCOUNT_KEY).getValue());
-        boolean sasTokenSet = StringUtils.isNotBlank(validationContext.getProperty(AzureStorageUtils.PROP_SAS_TOKEN).getValue());
-        boolean useManagedIdentitySet = validationContext.getProperty(USE_MANAGED_IDENTITY).asBoolean();
+        final boolean accountKeySet = StringUtils.isNotBlank(validationContext.getProperty(AzureStorageUtils.ACCOUNT_KEY).getValue());
+        final boolean sasTokenSet = StringUtils.isNotBlank(validationContext.getProperty(AzureStorageUtils.PROP_SAS_TOKEN).getValue());
+        final boolean useManagedIdentitySet = validationContext.getProperty(USE_MANAGED_IDENTITY).asBoolean();
+
+        final boolean servicePrincipalTenantIdSet = StringUtils.isNotBlank(validationContext.getProperty(SERVICE_PRINCIPAL_TENANT_ID).getValue());
+        final boolean servicePrincipalClientIdSet = StringUtils.isNotBlank(validationContext.getProperty(SERVICE_PRINCIPAL_CLIENT_ID).getValue());
+        final boolean servicePrincipalClientSecretSet = StringUtils.isNotBlank(validationContext.getProperty(SERVICE_PRINCIPAL_CLIENT_SECRET).getValue());
 
-        boolean servicePrincipalTenantIdSet = StringUtils.isNotBlank(validationContext.getProperty(SERVICE_PRINCIPAL_TENANT_ID).getValue());
-        boolean servicePrincipalClientIdSet = StringUtils.isNotBlank(validationContext.getProperty(SERVICE_PRINCIPAL_CLIENT_ID).getValue());
-        boolean servicePrincipalClientSecretSet = StringUtils.isNotBlank(validationContext.getProperty(SERVICE_PRINCIPAL_CLIENT_SECRET).getValue());
+        final boolean servicePrincipalSet = servicePrincipalTenantIdSet || servicePrincipalClientIdSet || servicePrincipalClientSecretSet;
 
-        boolean servicePrincipalSet = servicePrincipalTenantIdSet || servicePrincipalClientIdSet || servicePrincipalClientSecretSet;
+        final String managedIdentityClientId = validationContext.getProperty(MANAGED_IDENTITY_CLIENT_ID).getValue();
 
         if (!onlyOneSet(accountKeySet, sasTokenSet, useManagedIdentitySet, servicePrincipalSet)) {
             results.add(new ValidationResult.Builder().subject(this.getClass().getSimpleName())
                 .valid(false)
                 .explanation("one and only one authentication method of [Account Key, SAS Token, Managed Identity, Service Principal] should be used")
                 .build());
-        } else if (servicePrincipalSet) {
-            String template = "'%s' must be set when Service Principal authentication is being configured";
-            if (!servicePrincipalTenantIdSet) {
-                results.add(new ValidationResult.Builder().subject(this.getClass().getSimpleName())
-                        .valid(false)
-                        .explanation(String.format(template, SERVICE_PRINCIPAL_TENANT_ID.getDisplayName()))
-                        .build());
-            }
-            if (!servicePrincipalClientIdSet) {
-                results.add(new ValidationResult.Builder().subject(this.getClass().getSimpleName())
-                        .valid(false)
-                        .explanation(String.format(template, SERVICE_PRINCIPAL_CLIENT_ID.getDisplayName()))
-                        .build());
+        } else {
+            if (servicePrincipalSet) {
+                final String template = "'%s' must be set when Service Principal authentication is being configured";
+                if (!servicePrincipalTenantIdSet) {
+                    results.add(new ValidationResult.Builder().subject(this.getClass().getSimpleName())
+                            .valid(false)
+                            .explanation(String.format(template, SERVICE_PRINCIPAL_TENANT_ID.getDisplayName()))
+                            .build());
+                }
+                if (!servicePrincipalClientIdSet) {
+                    results.add(new ValidationResult.Builder().subject(this.getClass().getSimpleName())
+                            .valid(false)
+                            .explanation(String.format(template, SERVICE_PRINCIPAL_CLIENT_ID.getDisplayName()))
+                            .build());
+                }
+                if (!servicePrincipalClientSecretSet) {
+                    results.add(new ValidationResult.Builder().subject(this.getClass().getSimpleName())
+                            .valid(false)
+                            .explanation(String.format(template, SERVICE_PRINCIPAL_CLIENT_SECRET.getDisplayName()))
+                            .build());
+                }

Review comment:
       These are almost exactly the same so it might be more succinct to do something like below. Definitely not something I'd block on.
   
   ```suggestion
                   String propertyDisplayName;
                   if (!servicePrincipalTenantIdSet) {
                       propertyDisplayName = SERVICE_PRINCIPAL_TENANT_ID.getDisplayName();
                   }
                   if (!servicePrincipalClientIdSet) {
                       propertyDisplayName = SERVICE_PRINCIPAL_CLIENT_ID.getDisplayName();
                   }
                   if (!servicePrincipalClientSecretSet) {
                       propertyDisplayName = SERVICE_PRINCIPAL_CLIENT_SECRET.getDisplayName();
                   }
                   results.add(new ValidationResult.Builder().subject(this.getClass().getSimpleName())
                           .valid(false)
                           .explanation(String.format(template, propertyDisplayName))
                           .build());                
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org