1414# See the License for the specific language governing permissions and
1515# limitations under the License.
1616#
17-
18- from __future__ import print_function
19- from vcert import (CertificateRequest , Connection , CloudConnection ,
20- FakeConnection , TPPConnection , RevocationRequest , KeyType )
17+ from vcert import (CertificateRequest , Connection , CloudConnection , FakeConnection , TPPConnection , RevocationRequest ,
18+ KeyType )
2119import string
2220import random
2321import logging
@@ -34,7 +32,7 @@ def main():
3432 user = environ .get ('TPP_USER' )
3533 password = environ .get ('TPP_PASSWORD' )
3634 url = environ .get ('TPP_URL' )
37- zone = environ .get (" ZONE" )
35+ zone = environ .get (' ZONE' )
3836 fake = environ .get ('FAKE' )
3937
4038 if fake :
@@ -45,28 +43,28 @@ def main():
4543 # If token is passed Venafi Cloud connection will be used.
4644 # If user, password, and URL Venafi Platform (TPP) will be used.
4745 conn = Connection (url = url , token = token , user = user , password = password ,
48- http_request_kwargs = {" verify" : False })
46+ http_request_kwargs = {' verify' : False })
4947 # If your TPP server certificate signed with your own CA, or available only via proxy, you can specify
5048 # a trust bundle using requests vars:
51- #conn = Connection(url=url, token=token, user=user, password=password,
49+ # conn = Connection(url=url, token=token, user=user, password=password,
5250 # http_request_kwargs={"verify": "/path-to/bundle.pem"})
5351
54- request = CertificateRequest (common_name = randomword (10 ) + " .venafi.example.com" )
52+ request = CertificateRequest (common_name = f" { randomword (10 )} .venafi.example.com" )
5553 request .san_dns = ["www.client.venafi.example.com" , "ww1.client.venafi.example.com" ]
5654 if not isinstance (conn , CloudConnection ):
5755 # Venafi Cloud doesn't support email or IP SANs in CSR
5856 request .email_addresses = ["e1@venafi.example.com" , "e2@venafi.example.com" ]
5957 request .ip_addresses = ["127.0.0.1" , "192.168.1.1" ]
60- request .uniform_resource_identifiers = ["http://wgtest.com" ,"https://ragnartest.com" ]
58+ request .uniform_resource_identifiers = ["http://wgtest.com" , "https://ragnartest.com" ]
6159 request .user_principal_names = ["e1@venafi.example.com" , "e2@venafi.example.com" ]
6260 # Specify ordering certificates in chain. Root can be "first" or "last". By default it last. You also can
6361 # specify "ignore" to ignore chain (supported only for Platform).
6462 # To set Custom Fields for the certificate, specify an array of CustomField objects as name-value pairs
65- #request.custom_fields = [
63+ # request.custom_fields = [
6664 # CustomField(name="Cost Center", value="ABC123"),
6765 # CustomField(name="Environment", value="Production"),
6866 # CustomField(name="Environment", value="Staging")
69- #]
67+ # ]
7068
7169 # configure key type, RSA example
7270 request .key_type = KeyType (KeyType .RSA , 2048 )
@@ -96,11 +94,9 @@ def main():
9694 f .close ()
9795
9896 if not isinstance (conn , FakeConnection ):
99- # fake connection doesn` t support certificate renewing
97+ # fake connection doesn' t support certificate renewing
10098 print ("Trying to renew certificate" )
101- new_request = CertificateRequest (
102- cert_id = request .id ,
103- )
99+ new_request = CertificateRequest (cert_id = request .id )
104100 conn .renew_cert (new_request )
105101 while True :
106102 new_cert = conn .retrieve_cert (new_request )
@@ -115,8 +111,7 @@ def main():
115111 fn .write (new_request .private_key_pem )
116112 fn .close ()
117113 if isinstance (conn , TPPConnection ):
118- revocation_req = RevocationRequest (req_id = request .id ,
119- comments = "Just for test" )
114+ revocation_req = RevocationRequest (req_id = request .id , comments = "Just for test" )
120115 print ("Revoke" , conn .revoke_cert (revocation_req ))
121116
122117 print ("Trying to sign CSR" )
@@ -141,6 +136,7 @@ def main():
141136 f .write (cert .full_chain )
142137 f .close ()
143138
139+
144140def randomword (length ):
145141 letters = string .ascii_lowercase
146142 return '' .join (random .choice (letters ) for i in range (length ))
0 commit comments