github.com/Venafi/vcert/v5@v5.10.2/examples/provision/main.go (about) 1 package main 2 3 import ( 4 "log" 5 "os" 6 7 "github.com/Venafi/vcert/v5" 8 "github.com/Venafi/vcert/v5/pkg/domain" 9 "github.com/Venafi/vcert/v5/pkg/endpoint" 10 ) 11 12 const ( 13 vcpURL = "VCP_URL" 14 vcpZone = "VCP_ZONE" 15 vcpApiKey = "CLOUD_APIKEY" 16 envVarNotSet = "environment variable not set: %s" 17 18 name = "example-provisioning" 19 ) 20 21 func main() { 22 23 // URL can be nil if using production TLSPC 24 url := os.Getenv(vcpURL) 25 26 zone, found := os.LookupEnv(vcpZone) 27 if !found { 28 log.Fatalf(envVarNotSet, vcpZone) 29 } 30 31 config := &vcert.Config{ 32 ConnectorType: endpoint.ConnectorTypeCloud, 33 BaseUrl: url, 34 Zone: zone, 35 Credentials: &endpoint.Authentication{APIKey: os.Getenv(vcpApiKey)}, 36 } 37 38 connector, err := vcert.NewClient(config) 39 if err != nil { 40 log.Fatalf("error creating client: %s", err.Error()) 41 } 42 43 certificateID := "<insert Certificate ID here>" 44 keystoreID := "<insert Keystore ID here>" 45 certName := "<insert google cert name>" // e.g. test2-venafi-com 46 47 optionsInput := domain.ProvisioningOptions{ 48 CloudCertificateName: certName, 49 } 50 51 req := &domain.ProvisioningRequest{ 52 CertificateID: &certificateID, 53 KeystoreID: &keystoreID, 54 } 55 56 certMetaData, err := connector.ProvisionCertificate(req, &optionsInput) 57 if err != nil { 58 log.Fatalf("error provisioning: %s", err.Error()) 59 } 60 61 // Example to get values from other keystores machine identities metadata 62 if certMetaData.CloudKeystoreType == domain.CloudKeystoreTypeACM { 63 log.Printf("Certificate AWS Metadata ARN:\n%v", certMetaData.CertificateID) 64 } 65 if certMetaData.CloudKeystoreType == domain.CloudKeystoreTypeAKV { 66 log.Printf("Certificate Azure Metadata ID:\n%v", certMetaData.CertificateID) 67 log.Printf("Certificate Azure Metadata Name:\n%v", certMetaData.CertificateName) 68 log.Printf("Certificate Azure Metadata Version:\n%v", certMetaData.CertificateVersion) 69 } 70 if certMetaData.CloudKeystoreType == domain.CloudKeystoreTypeGCM { 71 log.Printf("Certificate GCP Metadata ID:\n%v", certMetaData.CertificateID) 72 log.Printf("Certificate GCP Metadata Name:\n%v", certMetaData.CertificateName) 73 } 74 }