Last active
October 15, 2020 13:47
-
-
Save infamousjoeg/1dcb504e83d4609f52e5b97f91477793 to your computer and use it in GitHub Desktop.
Full Java source code for examples given in AWS IAM Authenticator Tutorial for Conjur Open Source (https://www.conjur.org/blog/aws-iam-authenticator-tutorial-for-conjur-open-source/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package authn-iam_test; | |
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.io.IOException; | |
import java.net.URL; | |
import org.json.JSONObject; | |
import com.cyberark.conjur.api.Conjur; | |
public class authn-iam_test { | |
public static void main() throws IOException { | |
URL queryRoleUrl = new URL( | |
"http://169.254.169.254/latest/meta-data/iam/info" | |
); | |
BufferedReader reader = new BufferedReader( | |
new InputStreamReader(queryRoleUrl.openStream()) | |
); | |
StringBuilder sb = new StringBuilder(); | |
String line; | |
while ((line = reader.readLine()) != null) { | |
sb.append((line)); | |
} | |
JSONObject arnInfo = new JSONObject(sb.toString()); | |
String arnString = arnInfo.getString("InstanceProfileArn"); | |
String[] arnParts = arnString.split(":"); | |
String RoleName = arnParts[5].split("/")[1]; | |
String hostName = String.format("host/%s/%s", arnParts[4], RoleName); | |
System.out.println(hostName); | |
static final String SECRET_KEY = "connectionstring"; | |
Conjur conjur = new Conjur(); | |
String secretValue = conjur.variables().retrieveSecret(SECRET); | |
System.out.println(secretValue); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment