1717
1818from __future__ import print_function
1919
20- from vcert import (CertificateRequest , venafi_connection , RevocationRequest , CSR_ORIGIN_SERVICE )
20+ from vcert import (CertificateRequest , venafi_connection , CSR_ORIGIN_SERVICE , CHAIN_OPTION_FIRST )
2121import string
2222import random
2323import logging
24- import time
2524from os import environ
2625
2726logging .basicConfig (level = logging .INFO )
@@ -39,54 +38,60 @@ def main():
3938 # Connection will be chosen automatically based on which arguments are passed.
4039 # If token is passed Venafi Cloud connection will be used.
4140 # If user, password, and URL Venafi Platform (TPP) will be used.
42- conn = venafi_connection (url = url , user = user , password = password ,
43- http_request_kwargs = {"verify" : server_trust_bundle })
4441 # If your TPP server certificate signed with your own CA, or available only via proxy, you can specify
45- # a trust bundle using requests vars:
46- # conn = Connection(url=url, token=token, user=user, password=password,
47- # http_request_kwargs={"verify": "/path-to/bundle.pem"})
42+ # a trust bundle using http_request_kwargs.
43+ conn = venafi_connection (url = url , user = user , password = password , http_request_kwargs = {"verify" : server_trust_bundle })
4844
45+ # Build a Certificate request
4946 request = CertificateRequest (common_name = random_word (10 ) + ".venafi.example.com" )
47+ # Set the request to use a service generated CSR
5048 request .csr_origin = CSR_ORIGIN_SERVICE
51- request .san_dns = ["www.client.venafi.example.com" , "ww1.client.venafi.example.com" ]
52- request .email_addresses = ["e1@venafi.example.com" , "e2@venafi.example.com" ]
49+ # Include some Subject Alternative Names
50+ request .san_dns = ["www.dns.venafi.example.com" , "ww1.dns.venafi.example.com" ]
51+ request .email_addresses = ["email1@venafi.example.com" , "email2@venafi.example.com" ]
5352 request .ip_addresses = ["127.0.0.1" , "192.168.1.1" ]
54- request .uniform_resource_identifiers = ["http://wgtest.com" ,"https://ragnartest.com" ]
55- request .user_principal_names = ["e1@venafi.example.com" , "e2@venafi.example.com" ]
56- # Specify ordering certificates in chain. Root can be "first" or "last". By default it last. You also can
57- # specify "ignore" to ignore chain (supported only for Platform).
53+ request .uniform_resource_identifiers = ["http://wgtest.uri.com" ,"https://ragnartest.uri.com" ]
54+ request .user_principal_names = ["upn1@venafi.example.com" , "upn2@venafi.example.com" ]
55+ # Specify ordering certificates in chain. Root can be CHAIN_OPTION_FIRST ("first")
56+ # or CHAIN_OPTION_LAST ("last"). By default it is CHAIN_OPTION_LAST.
57+ # You can also specify CHAIN_OPTION_IGNORE ("ignore") to ignore chain (supported only for TPP).
58+ # request.chain_option = CHAIN_OPTION_FIRST
5859 # To set Custom Fields for the certificate, specify an array of CustomField objects as name-value pairs
5960 # request.custom_fields = [
6061 # CustomField(name="Cost Center", value="ABC123"),
6162 # CustomField(name="Environment", value="Production"),
6263 # CustomField(name="Environment", value="Staging")
6364 # ]
64- # Update certificate request from zone
65+ #
66+ # Update certificate request from zone.
6567 zone_config = conn .read_zone_conf (zone )
6668 request .update_from_zone_config (zone_config )
69+ # Request the certificate.
6770 conn .request_cert (request , zone )
6871
69- # and wait for signing
72+ # Wait for the certificate to be retrieved.
73+ # This operation may take some time to return, as it waits until the certificate is ISSUED or it timeout.
74+ # Timeout is 180s by default. Can be changed using:
75+ # request.timeout = 300
7076 cert = conn .retrieve_cert (request )
7177
72- # after that print cert and key
73- print (cert .full_chain , request . private_key_pem , sep = " \n " )
74- # and save into file
75- f = open ("/tmp /cert.pem" , "w" )
78+ # Print the certificate
79+ print (cert .full_chain )
80+ # Save it into a file
81+ f = open (". /cert.pem" , "w" )
7682 f .write (cert .full_chain )
77- f = open ("/tmp/cert.key" , "w" )
78- f .write (request .private_key_pem )
7983 f .close ()
8084
8185 print ("Trying to renew certificate" )
8286 new_request = CertificateRequest (cert_id = request .id )
87+ # The renewal request should use a service generated CSR as well
88+ # This may not be necessary and depends entirely on the settings of your Policy/Zone
89+ new_request .csr_origin = CSR_ORIGIN_SERVICE
8390 conn .renew_cert (new_request )
8491 new_cert = conn .retrieve_cert (new_request )
85- print (new_cert .cert , new_request . private_key_pem , sep = " \n " )
86- fn = open ("/tmp /new_cert.pem" , "w" )
92+ print (new_cert .cert )
93+ fn = open (". /new_cert.pem" , "w" )
8794 fn .write (new_cert .cert )
88- fn = open ("/tmp/new_cert.key" , "w" )
89- fn .write (new_request .private_key_pem )
9095 fn .close ()
9196
9297
0 commit comments