admin管理员组

文章数量:1277901

I'm using groovy and below is my code, which is not working as expected, its saying, unable to find valid certification path to requested target, although while doing ls I find the file there, can someone help? Thanks in Advance.

    def certificateFactory = CertificateFactory.getInstance("X.509")
    def trustStore = KeyStore.getInstance(KeyStore.getDefaultType())
    trustStore.load(null, null) 
    
    def pemFilePath = "/etc/ca/cacerts.pem"
    FileInputStream fis = new FileInputStream(pemFilePath)
    try {
        def cert = certificateFactory.generateCertificate(fis) as X509Certificate
        trustStore.setCertificateEntry("customCA", cert)
    } finally {
        fis.close()  
    }
    def trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())
    trustManagerFactory.init(trustStore)
    def trustManagers = trustManagerFactory.trustManagers
    def sslContext = SSLContext.getInstance("TLS")
    sslContext.init(null, trustManagers, new SecureRandom())
    
    HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory())
    
    def vaultApiUrl = "URL"
    def vaultToken = "TOKEN"
    
    def connection = new URL(vaultApiUrl).openConnection() as HttpsURLConnection
    connection.setRequestMethod("GET")
    connection.setRequestProperty("X-Vault-Token", vaultToken)
    connection.setRequestProperty("Accept", "application/json")
    
    def responseCode = connection.responseCode
    if (responseCode == 200) {
        def responseText = connection.inputStream.text
        def vaultResponse = new JsonSlurper().parseText(responseText)
        dsl.echo("response is: ${vaultResponse}")
    } else {
        dsl.echo("Error: HTTP ${responseCode}")
    }

本文标签: