emiliosetiadarma commented on a change in pull request #5242: URL: https://github.com/apache/nifi/pull/5242#discussion_r681156714
########## File path: nifi-commons/nifi-sensitive-property-provider/src/test/java/org/apache/nifi/properties/GCPSensitivePropertyProviderIT.java ########## @@ -0,0 +1,125 @@ +/* + * 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.properties; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.mockito.internal.util.io.IOUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Properties; + +/** + * To run this test, make sure to first configure sensitive credential information as in the following link + * https://cloud.google.com/kms/docs/reference/libraries#cloud-console + * + * Create a project, keyring and key in the web console. + * + * Take note of the project name, location, keyring name and key name. + * + * Then, set the system properties as follows: + * -Dgcp.kms.project="project" + * -Dgcp.kms.location="location" + * -Dgcp.kms.keyring="key ring name" + * -Dgcp.kms.key="key name" + * when running the integration tests + */ + +public class GCPSensitivePropertyProviderIT { + private static final String SAMPLE_PLAINTEXT = "GCPSensitivePropertyProviderIT SAMPLE-PLAINTEXT"; + private static final String PROJECT_ID_PROPS_NAME = "gcp.kms.project"; + private static final String LOCATION_ID_PROPS_NAME = "gcp.kms.location"; + private static final String KEYRING_ID_PROPS_NAME = "gcp.kms.keyring"; + private static final String KEY_ID_PROPS_NAME = "gcp.kms.key"; + private static final String BOOTSTRAP_GCP_FILE_PROPS_NAME = "nifi.bootstrap.protection.gcp.kms.conf"; + + private static final String EMPTY_PROPERTY = ""; + + private static GCPSensitivePropertyProvider spp; + + private static BootstrapProperties props; + + private static Path mockBootstrapConf, mockGCPBootstrapConf; + + private static final Logger logger = LoggerFactory.getLogger(GCPSensitivePropertyProviderIT.class); + + private static void initializeBootstrapProperties() throws IOException{ + mockBootstrapConf = Files.createTempFile("bootstrap", ".conf").toAbsolutePath(); + mockGCPBootstrapConf = Files.createTempFile("bootstrap-gcp", ".conf").toAbsolutePath(); + IOUtil.writeText(BOOTSTRAP_GCP_FILE_PROPS_NAME + "=" + mockGCPBootstrapConf.toAbsolutePath(), mockBootstrapConf.toFile()); + + final Properties bootstrapProperties = new Properties(); + try (final InputStream inputStream = Files.newInputStream(mockBootstrapConf)) { + bootstrapProperties.load(inputStream); + props = new BootstrapProperties("nifi", bootstrapProperties, mockBootstrapConf); + } + + String projectId = System.getProperty(PROJECT_ID_PROPS_NAME, EMPTY_PROPERTY); + String locationId = System.getProperty(LOCATION_ID_PROPS_NAME, EMPTY_PROPERTY); + String keyringId = System.getProperty(KEYRING_ID_PROPS_NAME, EMPTY_PROPERTY); + String keyId = System.getProperty(KEY_ID_PROPS_NAME, EMPTY_PROPERTY); + + StringBuilder bootstrapConfText = new StringBuilder(); + bootstrapConfText.append(PROJECT_ID_PROPS_NAME + "=" + projectId); + bootstrapConfText.append("\n" + LOCATION_ID_PROPS_NAME + "=" + locationId); Review comment: I think that would be better yes, I will make the changes with the AWS and GCP SPP ITs! -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
