Tony Blundell
06/18/2020, 8:54 PMclass SecretsManager(region: String) {
private val gson = Gson()
private val smClient = AWSSecretsManagerClientBuilder.standard().withRegion(region).build()
fun <T> getSecret(id: String): T {
val req = GetSecretValueRequest().withSecretId(id)
val json = smClient.getSecretValue(req).getSecretString()
return gson.fromJson(json, T::class.java)
}
}
To be used like this...
val myInstance = SecretsManager("eu-west-2").getSecret<MyDataClass>("myId")
Currently, I get an error Cannot use 'T' as reified type parameter
. I can get around this by marking the function as inline
and T as reified
, but then I can't access the private attributes from within the function.
What's the best way to do this in Kotlin?araqnid
06/18/2020, 9:44 PMWesley Acheson
06/19/2020, 11:38 AMTony Blundell
06/23/2020, 6:51 PM