sushilkm commented on a change in pull request #4863: URL: https://github.com/apache/nifi/pull/4863#discussion_r594776492
########## File path: nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/services/azure/keyvault/AzureKeyVaultClientService.java ########## @@ -0,0 +1,242 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.nifi.services.azure.keyvault; + +import org.apache.nifi.annotation.documentation.CapabilityDescription; +import org.apache.nifi.annotation.documentation.Tags; +import org.apache.nifi.annotation.lifecycle.OnEnabled; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.components.ValidationContext; +import org.apache.nifi.components.ValidationResult; +import org.apache.nifi.controller.AbstractControllerService; +import org.apache.nifi.controller.ConfigurationContext; +import org.apache.nifi.logging.ComponentLog; +import org.apache.nifi.util.StringUtils; + +import com.azure.identity.DefaultAzureCredentialBuilder; +import com.azure.identity.ClientSecretCredential; +import com.azure.identity.ClientSecretCredentialBuilder; +import com.azure.security.keyvault.secrets.SecretClient; +import com.azure.security.keyvault.secrets.SecretClientBuilder; + +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.concurrent.TimeUnit; + +@Tags({"azure", "keyvault", "credential", "service", "secure"}) +@CapabilityDescription( + "Provides a controller service that configures a connection to Azure Key Vault" + + " and provides access to that connection to Azure Key Vault components." +) +public class AzureKeyVaultClientService + extends AbstractControllerService + implements AzureKeyVaultConnectionService { + + private String keyVaultName; + private String servicePrincipalClientID; + private String servicePrincipalClientSecret; + private String tenantID; + private String endPointSuffix; + private Boolean useManagedIdentity; + private SecretClient keyVaultSecretClient; + private ComponentLog logger; + private LoadingCache<String, String> secretCache; + + public String getKeyVaultName() { + return this.keyVaultName; + } + + public String getServicePrincipalClientID() { + return this.servicePrincipalClientID; + } + + public String getServicePrincipalClientSecret() { + return this.servicePrincipalClientSecret; + } + + public String getTenantID() { + return this.tenantID; + } + + public String getEndPointSuffix() { + return this.endPointSuffix; + } + + public Boolean getUseManagedIdentity() { Review comment: cleaned ########## File path: nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/services/azure/cosmos/document/AzureCosmosSecureDBClientService.java ########## @@ -0,0 +1,158 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.nifi.services.azure.cosmos.document; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.apache.nifi.annotation.documentation.CapabilityDescription; +import org.apache.nifi.annotation.documentation.Tags; +import org.apache.nifi.annotation.lifecycle.OnEnabled; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.components.ValidationContext; +import org.apache.nifi.components.ValidationResult; +import org.apache.nifi.controller.ConfigurationContext; +import org.apache.nifi.processor.util.StandardValidators; +import org.apache.nifi.processors.azure.cosmos.document.AzureCosmosDBUtils; +import org.apache.nifi.services.azure.cosmos.AzureCosmosDBConnectionService; +import org.apache.nifi.services.azure.keyvault.AzureKeyVaultConnectionService; +import org.apache.nifi.util.StringUtils; + +@Tags({"azure", "cosmos", "document", "service", "secure"}) +@CapabilityDescription( + "Provides a controller service that configures a connection to Cosmos DB (Core SQL API) " + + " and provides access to that connection to other Cosmos DB-related components." +) +public class AzureCosmosSecureDBClientService + extends AbstractCosmosDBClientService + implements AzureCosmosDBConnectionService { + + private String uriSecret; + private String accessKeySecret; + private String consistencyLevel; + private AzureKeyVaultConnectionService keyVaultClientService; + + public static final PropertyDescriptor URI_SECRET = new PropertyDescriptor.Builder() + .name("azure-cosmos-db-uri-secret") + .displayName("Cosmos DB URI Secret Name") + .description("Cosmos DB URI Secret Name") + .required(true) + .addValidator(StandardValidators.URI_VALIDATOR) + .sensitive(true) + .build(); + + public static final PropertyDescriptor DB_ACCESS_KEY_SECRET = new PropertyDescriptor.Builder() + .name("azure-cosmos-db-key-secret") + .displayName("Cosmos DB Access Key Secret Name") + .description("Cosmos DB Access Key Secret Name") + .required(true) + .addValidator(StandardValidators.NON_BLANK_VALIDATOR) + .sensitive(true) + .build(); + + static final PropertyDescriptor KEYVAULT_CONNECTION_SERVICE = new PropertyDescriptor.Builder() + .name("azure-keyvault-connection-service") + .displayName("KeyVault Connection Service") + .description("If configured, the controller service used to obtain the secrets from KeyVault") + .required(true) + .identifiesControllerService(AzureKeyVaultConnectionService.class) + .build(); + @OnEnabled + public void onEnabled(final ConfigurationContext context) { + this.uriSecret = context.getProperty(URI_SECRET).getValue(); + this.accessKeySecret = context.getProperty(DB_ACCESS_KEY_SECRET).getValue(); + this.consistencyLevel = context.getProperty( + AzureCosmosDBUtils.CONSISTENCY).getValue(); + this.keyVaultClientService = context.getProperty( + KEYVAULT_CONNECTION_SERVICE + ).asControllerService(AzureKeyVaultConnectionService.class); + + createCosmosClient( + getURI(), + getAccessKey(), + getConsistencyLevel() + ); + } + + static List<PropertyDescriptor> descriptors = new ArrayList<>(); + + static { + descriptors.add(KEYVAULT_CONNECTION_SERVICE); + descriptors.add(URI_SECRET); + descriptors.add(DB_ACCESS_KEY_SECRET); + descriptors.add(AzureCosmosDBUtils.CONSISTENCY); + } + + @Override + protected List<PropertyDescriptor> getSupportedPropertyDescriptors() { + return descriptors; + } + + @Override + public String getURI() { + if (keyVaultClientService == null) { + throw new IllegalArgumentException(String.format( + "Cannot get '%s'.", KEYVAULT_CONNECTION_SERVICE.getDisplayName())); + } + if (StringUtils.isBlank(uriSecret)) { Review comment: cleaned ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
