github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/pkg/acme_ca_certs.go (about) 1 // Copyright (c) 2021, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 package pkg 4 5 import ( 6 "fmt" 7 "net/http" 8 ) 9 10 const letsEncryptStagingIntR3 = "https://letsencrypt.org/certs/staging/letsencrypt-stg-int-r3.pem" 11 const letsEncryptStagingIntE1 = "https://letsencrypt.org/certs/staging/letsencrypt-stg-int-e1.pem" 12 13 func getACMEStagingCAs() [][]byte { 14 letsEncryptStagingIntE1CA := loadStagingCA(newSimpleHTTPClient(), letsEncryptStagingIntE1, "E1") 15 letsEncryptStagingIntR3CA := loadStagingCA(newSimpleHTTPClient(), letsEncryptStagingIntR3, "R3") 16 return [][]byte{letsEncryptStagingIntE1CA, letsEncryptStagingIntR3CA} 17 } 18 19 func newSimpleHTTPClient() *http.Client { 20 tr := &http.Transport{ 21 Proxy: http.ProxyFromEnvironment, 22 } 23 httpClient := &http.Client{Transport: tr} 24 return httpClient 25 } 26 27 func loadStagingCA(httpClient *http.Client, resURL string, caCertName string) []byte { 28 resp, err := doReq(resURL, "GET", "", "", "", "", nil, newRetryableHTTPClient(httpClient)) 29 if err != nil { 30 Log(Error, fmt.Sprintf("Error loading ACME staging CA: %v", err)) 31 return nil 32 } 33 if resp.StatusCode < 200 || resp.StatusCode > 299 { 34 Log(Error, fmt.Sprintf("Unable to load ACME %s staging CA, status: %v\n", caCertName, resp.StatusCode)) 35 return nil 36 } 37 return resp.Body 38 }