github.com/verrazzano/verrazzano@v1.7.0/pkg/certs/acme_utils.go (about) 1 // Copyright (c) 2023, 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 4 package certs 5 6 import ( 7 "github.com/verrazzano/verrazzano/pkg/constants" 8 "strings" 9 10 vzapi "github.com/verrazzano/verrazzano/platform-operator/apis/verrazzano/v1alpha1" 11 "github.com/verrazzano/verrazzano/platform-operator/apis/verrazzano/v1beta1" 12 ) 13 14 func IsLetsEncryptProductionEnv(acme interface{}) bool { 15 var envName string 16 if v1alpha1LEIssuer, ok := acme.(vzapi.LetsEncryptACMEIssuer); ok { 17 envName = v1alpha1LEIssuer.Environment 18 } 19 if v1beta1LEIssuer, ok := acme.(v1beta1.LetsEncryptACMEIssuer); ok { 20 envName = v1beta1LEIssuer.Environment 21 } 22 if v1alpha1ACME, ok := acme.(vzapi.Acme); ok { 23 envName = v1alpha1ACME.Environment 24 } 25 if v1beta1ACME, ok := acme.(v1beta1.Acme); ok { 26 envName = v1beta1ACME.Environment 27 } 28 if len(envName) == 0 { 29 // the default if not specified 30 return true 31 } 32 return strings.ToLower(envName) == constants.LetsEncryptProduction 33 } 34 35 func IsLetsEncryptStagingEnv(acme interface{}) bool { 36 var envName string 37 if v1alpha1LEIssuer, ok := acme.(vzapi.LetsEncryptACMEIssuer); ok { 38 envName = v1alpha1LEIssuer.Environment 39 } 40 if v1beta1LEIssuer, ok := acme.(v1beta1.LetsEncryptACMEIssuer); ok { 41 envName = v1beta1LEIssuer.Environment 42 } 43 if v1alpha1ACME, ok := acme.(vzapi.Acme); ok { 44 envName = v1alpha1ACME.Environment 45 } 46 if v1beta1ACME, ok := acme.(v1beta1.Acme); ok { 47 envName = v1beta1ACME.Environment 48 } 49 return strings.ToLower(envName) == constants.LetsEncryptStaging 50 } 51 52 func IsLetsEncryptProvider(acme interface{}) bool { 53 if v1alpha1ACME, ok := acme.(vzapi.Acme); ok { 54 return strings.ToLower(string(v1alpha1ACME.Provider)) == strings.ToLower(string(vzapi.LetsEncrypt)) 55 } 56 if v1beta1ACME, ok := acme.(v1beta1.Acme); ok { 57 return strings.ToLower(string(v1beta1ACME.Provider)) == strings.ToLower(string(v1beta1.LetsEncrypt)) 58 } 59 return false 60 } 61 62 func IsPrivateIssuer(c interface{}) (bool, error) { 63 var isCAIssuer, isLetsEncryptStagingIssuer bool 64 var err error 65 if v1alpha1Issuer, ok := c.(*vzapi.ClusterIssuerComponent); ok { 66 isCAIssuer, err = v1alpha1Issuer.IsCAIssuer() 67 if !isCAIssuer { 68 isLetsEncryptStagingIssuer = IsLetsEncryptStagingEnv(*v1alpha1Issuer.LetsEncrypt) 69 } 70 } 71 if v1beta1Issuer, ok := c.(*v1beta1.ClusterIssuerComponent); ok { 72 isCAIssuer, err = v1beta1Issuer.IsCAIssuer() 73 if !isCAIssuer { 74 isLetsEncryptStagingIssuer = IsLetsEncryptStagingEnv(*v1beta1Issuer.LetsEncrypt) 75 } 76 } 77 if err != nil { 78 return false, err 79 } 80 return isCAIssuer || isLetsEncryptStagingIssuer, nil 81 }