Created
November 6, 2024 15:40
-
-
Save jagedn/17ddac3e613bdd76405eb54c43a1803e to your computer and use it in GitHub Desktop.
prepare micronaut to run using cosmosdb emulator cert
This file contains hidden or 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
tasks.findByName("run").doFirst{ | |
def emulatorkey = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==" | |
def emulator = "https://localhost:8081/_explorer/emulator.pem" | |
def sslContext = SSLContext.getInstance("SSL") | |
sslContext.init(null, (TrustManager[]) [ | |
[ | |
getAcceptedIssuers:{new X509Certificate[] {}}, | |
checkServerTrusted:{ X509Certificate[] chain, String authType->}, | |
checkClientTrusted:{X509Certificate[] chain, String authType->}, | |
] as X509TrustManager], new SecureRandom()) | |
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory()); | |
def keyStoreFile = new File(buildDir, "azure-cosmos-emulator.keystore") | |
keyStoreFile.bytes = emulator.toURL().bytes | |
def certificate = CertificateFactory.getInstance("X.509").generateCertificate(new ByteArrayInputStream(keyStoreFile.bytes)); | |
KeyStore keystore = KeyStore.getInstance("PKCS12"); | |
keystore.load(null, emulatorkey.toCharArray()); | |
keystore.setCertificateEntry("azure-cosmos-emulator", certificate); | |
keystore.store(new FileOutputStream(keyStoreFile), emulatorkey.toCharArray()) | |
systemProperty("javax.net.ssl.trustStore", keyStoreFile.absolutePath.toString()) | |
systemProperty("javax.net.ssl.trustStorePassword", emulatorkey) | |
systemProperty("javax.net.ssl.trustStoreType", "PKCS12") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment