sushilkm commented on a change in pull request #4863: URL: https://github.com/apache/nifi/pull/4863#discussion_r594776427
########## 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<>(); Review comment: fixed ---------------------------------------------------------------- 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]
