/*
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.amazonaws.kafka.config.providers;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.apache.kafka.common.config.ConfigChangeCallback;
import org.apache.kafka.common.config.ConfigData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.amazonaws.kafka.config.providers.common.AwsServiceConfigProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.S3ClientBuilder;
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
import software.amazon.awssdk.services.s3.model.NoSuchKeyException;
/**
* This class implements a ConfigProvider for AWS S3 File Importer.
*
*
Usage:
* In a configuration file (e.g. {@code client.properties}) define following properties:
*
*
* # Step1. Configure the secrets manager as config provider: * config.providers=s3import * config.providers.s3import.class=com.amazonaws.kafka.config.providers.S3ImportConfigProvider * # optional parameter for default region: * config.providers.s3import.param.region=us-west-2 * * # Step 2. Usage of AWS S3 Importer as config provider with explicitly defined region: * database.sslcert=${s3import:us-west-2:my-bucket/full/path/file.jks} * # Alternatively, use default or current region: * database.sslcert=${s3import::my-bucket/full/path/file.jks} ** * Note, you must have permissions to access an object on S3. * * @param region - defines a region to get a secret from. * * Expression usage:
property_name=${s3import::}
*
*/
public class S3ImportConfigProvider extends AwsServiceConfigProvider {
private final Logger log = LoggerFactory.getLogger(getClass());
private S3ImportConfig config;
private String localDir;
@Override
public void configure(Map