All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.datarouter.aws.rds.config.DatarouterAwsRdsConfigSettings Maven / Gradle / Ivy

There is a newer version: 0.0.125
Show newest version
/*
 * Copyright © 2009 HotPads ([email protected])
 *
 * Licensed 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 io.datarouter.aws.rds.config;

import javax.inject.Inject;
import javax.inject.Singleton;

import com.amazonaws.regions.Regions;

import io.datarouter.secret.service.CachedSecretFactory;
import io.datarouter.secret.service.CachedSecretFactory.CachedSecret;
import io.datarouter.storage.setting.SettingFinder;
import io.datarouter.storage.setting.SettingNode;
import io.datarouter.storage.setting.cached.CachedSetting;

@Singleton
public class DatarouterAwsRdsConfigSettings extends SettingNode{

	public final CachedSetting rdsReadOnlyCredentialsLocation;
	public final CachedSecret rdsReadOnlyCredentials;
	public final CachedSetting rdsAddTagsCredentialsLocation;
	public final CachedSecret rdsAddTagsCredentials;
	public final CachedSetting rdsOtherCredentialsLocation;
	public final CachedSecret rdsOtherCredentials;
	public final CachedSetting eastRegion;
	public final CachedSetting westRegion;
	public final CachedSetting rdsClusterEndpointEast;
	public final CachedSetting rdsClusterEndpointWest;
	public final CachedSetting rdsInstanceEndpoint;
	public final CachedSetting rdsInstanceHostnameSuffixEast;
	public final CachedSetting rdsInstanceHostnameSuffixWest;
	public final CachedSetting dnsSuffix;
	public final CachedSetting dbPrefix;
	public final CachedSetting dbOtherInstanceSuffix;
	public final CachedSetting dbOtherInstanceClass;
	public final CachedSetting dbOtherEngine;
	public final CachedSetting dbOtherEastParameterGroup;
	public final CachedSetting dbOtherWestParameterGroup;
	public final CachedSetting dbOtherPromotionTier;

	@Inject
	public DatarouterAwsRdsConfigSettings(SettingFinder finder, CachedSecretFactory cachedSecretFactory){
		super(finder, "datarouterAwsRds.config.");

		rdsReadOnlyCredentialsLocation = registerString("rdsReadOnlyCredentialsLocation", "placeholder");
		rdsReadOnlyCredentials = cachedSecretFactory.cacheSharedSecret(rdsReadOnlyCredentialsLocation, RdsCredentialsDto
				.class);
		rdsAddTagsCredentialsLocation = registerString("rdsAddTagsCredentialsLocation", "placeholder");
		rdsAddTagsCredentials = cachedSecretFactory.cacheSharedSecret(rdsAddTagsCredentialsLocation, RdsCredentialsDto
				.class);
		rdsOtherCredentialsLocation = registerString("rdsOtherCredentialsLocation", "placeholder");
		rdsOtherCredentials = cachedSecretFactory.cacheSharedSecret(rdsOtherCredentialsLocation, RdsCredentialsDto
				.class);
		eastRegion = registerStrings("eastRegion", defaultTo(Regions.US_EAST_1.getName()));
		westRegion = registerStrings("westRegion", defaultTo(Regions.US_WEST_2.getName()));
		dnsSuffix = registerString("dnsSuffix", "");
		rdsClusterEndpointEast = registerString("rdsClusterEndpointEast", "");
		rdsClusterEndpointWest = registerString("rdsClusterEndpointWest", "");
		rdsInstanceEndpoint = registerString("rdsInstanceEndpoint", "");
		rdsInstanceHostnameSuffixEast = registerString("rdsInstanceHostnameSuffixEast", "");
		rdsInstanceHostnameSuffixWest = registerString("rdsInstanceHostnameSuffixWest", "");
		dbPrefix = registerString("dbPrefix", "");
		dbOtherInstanceSuffix = registerString("dbOtherInstanceSuffix", "");
		dbOtherInstanceClass = registerString("dbOtherInstanceClass", "");
		dbOtherEngine = registerString("dbOtherEngine", "");
		dbOtherEastParameterGroup = registerString("dbOtherEastParameterGroup", "");
		dbOtherWestParameterGroup = registerString("dbOtherWestParameterGroup", "");
		dbOtherPromotionTier = registerInteger("dbOtherPromotionTier", 15);
	}

	public String getParameterGroup(String region){
		return region.equals(eastRegion.get()) ? dbOtherEastParameterGroup.get()
				: dbOtherWestParameterGroup.get();
	}

	public String getHostnameSuffix(String region){
		return region.equals(eastRegion.get()) ? rdsInstanceHostnameSuffixEast.get()
				: rdsInstanceHostnameSuffixWest.get();
	}

	public String getOtherSuffix(){
		return dbOtherInstanceSuffix.get();
	}

	public String getClusterEndpoint(String region){
		return region.equals(eastRegion.get()) ? rdsClusterEndpointEast.get()
				: rdsClusterEndpointWest.get();
	}

	public static class RdsCredentialsDto{

		public final String accessKey;
		public final String secretKey;

		public RdsCredentialsDto(String accessKey, String secretKey){
			this.accessKey = accessKey;
			this.secretKey = secretKey;
		}

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy