Skip to content

Commit 59a80ef

Browse files
committed
- Updated strings with f-strings wherever possible.
1 parent 848ce5a commit 59a80ef

21 files changed

Lines changed: 271 additions & 310 deletions

examples/get_cert.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def main():
3232
user = environ.get('TPP_USER')
3333
password = environ.get('TPP_PASSWORD')
3434
url = environ.get('TPP_URL')
35-
zone = environ.get("ZONE")
35+
zone = environ.get('ZONE')
3636
fake = environ.get('FAKE')
3737

3838
if fake:
@@ -43,19 +43,19 @@ def main():
4343
# If token is passed Venafi Cloud connection will be used.
4444
# If user, password, and URL Venafi Platform (TPP) will be used.
4545
conn = Connection(url=url, token=token, user=user, password=password,
46-
http_request_kwargs={"verify": False})
46+
http_request_kwargs={'verify': False})
4747
# If your TPP server certificate signed with your own CA, or available only via proxy, you can specify
4848
# a trust bundle using requests vars:
4949
# conn = Connection(url=url, token=token, user=user, password=password,
5050
# http_request_kwargs={"verify": "/path-to/bundle.pem"})
5151

52-
request = CertificateRequest(common_name=randomword(10) + ".venafi.example.com")
52+
request = CertificateRequest(common_name=f"{randomword(10)}.venafi.example.com")
5353
request.san_dns = ["www.client.venafi.example.com", "ww1.client.venafi.example.com"]
5454
if not isinstance(conn, CloudConnection):
5555
# Venafi Cloud doesn't support email or IP SANs in CSR
5656
request.email_addresses = ["e1@venafi.example.com", "e2@venafi.example.com"]
5757
request.ip_addresses = ["127.0.0.1", "192.168.1.1"]
58-
request.uniform_resource_identifiers = ["http://wgtest.com","https://ragnartest.com"]
58+
request.uniform_resource_identifiers = ["http://wgtest.com", "https://ragnartest.com"]
5959
request.user_principal_names = ["e1@venafi.example.com", "e2@venafi.example.com"]
6060
# Specify ordering certificates in chain. Root can be "first" or "last". By default it last. You also can
6161
# specify "ignore" to ignore chain (supported only for Platform).
@@ -96,9 +96,7 @@ def main():
9696
if not isinstance(conn, FakeConnection):
9797
# fake connection doesn't support certificate renewing
9898
print("Trying to renew certificate")
99-
new_request = CertificateRequest(
100-
cert_id=request.id,
101-
)
99+
new_request = CertificateRequest(cert_id=request.id)
102100
conn.renew_cert(new_request)
103101
while True:
104102
new_cert = conn.retrieve_cert(new_request)
@@ -113,8 +111,7 @@ def main():
113111
fn.write(new_request.private_key_pem)
114112
fn.close()
115113
if isinstance(conn, TPPConnection):
116-
revocation_req = RevocationRequest(req_id=request.id,
117-
comments="Just for test")
114+
revocation_req = RevocationRequest(req_id=request.id, comments="Just for test")
118115
print("Revoke", conn.revoke_cert(revocation_req))
119116

120117
print("Trying to sign CSR")

examples/ssh_certificates/get_cert_ssh.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
def main():
2929
# Get credentials from environment variables
3030
url = environ.get('TPP_URL')
31-
user = environ.get("TPP_USER")
32-
password = environ.get("TPP_PASSWORD")
31+
user = environ.get('TPP_USER')
32+
password = environ.get('TPP_PASSWORD')
3333

34-
connector = venafi_connection(url=url, user=user, password=password, http_request_kwargs={"verify": False})
34+
connector = venafi_connection(url=url, user=user, password=password, http_request_kwargs={'verify': False})
3535
# If your TPP server certificate is signed with your own CA, or available only via proxy,
3636
# you can specify a trust bundle using requests vars:
3737
# connector = venafi_connection(url=url, api_key=api_key, access_token=access_token,
@@ -58,15 +58,15 @@ def main():
5858
# This is a placeholder. Make sure an SSH CA already exists on your TPP instance
5959
cadn = "\\VED\\Certificate Authority\\SSH\\Templates\\my-ca"
6060
# The id of the SSH certificate
61-
key_id = "vcert-python-%s" % random_word(12)
61+
key_id = f"vcert-python-{random_word(12)}"
6262

6363
# Create the request object
6464
request = SSHCertRequest(cadn=cadn, key_id=key_id)
6565
# Add any additional info for the certificate, like:
6666
request.validity_period = "4h"
6767
request.source_addresses = ["test.com"]
6868
request.extensions = {
69-
"permit-pty": ""
69+
'permit-pty': ""
7070
}
7171
# Include the locally-generated public key. If not set, the server will generate one for the certificate
7272
request.set_public_key_data(ssh_kp.public_key())

examples/ssh_certificates/get_cert_ssh_service.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
def main():
2929
# Get credentials from environment variables
3030
url = environ.get('TPP_URL')
31-
user = environ.get("TPP_USER")
32-
password = environ.get("TPP_PASSWORD")
31+
user = environ.get('TPP_USER')
32+
password = environ.get('TPP_PASSWORD')
3333

34-
connector = venafi_connection(url=url, user=user, password=password, http_request_kwargs={"verify": False})
34+
connector = venafi_connection(url=url, user=user, password=password, http_request_kwargs={'verify': False})
3535
# If your TPP server certificate signed with your own CA, or available only via proxy,
3636
# you can specify a trust bundle using requests vars:
3737
# connector = venafi_connection(url=url, api_key=api_key, access_token=access_token,
@@ -51,15 +51,15 @@ def main():
5151
# The path to the SSH CA in the TPP instance
5252
cadn = "\\VED\\Certificate Authority\\SSH\\Templates\\my-ca"
5353
# The id of the SSH certificate
54-
key_id = "vcert-python-%s" % random_word(12)
54+
key_id = f"vcert-python-{random_word(12)}"
5555

5656
# Create the request object
5757
request = SSHCertRequest(cadn=cadn, key_id=key_id)
5858
# Add any additional info for the certificate, like:
5959
request.validity_period = "4h"
6060
request.source_addresses = ["test.com"]
6161
request.extensions = {
62-
"permit-pty": ""
62+
'permit-pty': ""
6363
}
6464

6565
# Request the certificate from TPP instance

examples/ssh_certificates/retrieve_ca_public_key.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ def main():
2929
ca_dn = environ.get('TPP_SSH_CADN')
3030
ca_guid = environ.get('TPP_SSH_CA_GUID')
3131
# Authentication is required for retrieving the CA principals only.
32-
user = environ.get("TPP_USER")
33-
password = environ.get("TPP_PASSWORD")
32+
user = environ.get('TPP_USER')
33+
password = environ.get('TPP_PASSWORD')
3434

3535
# A Connector can be instantiated with no values by using the platform argument.
3636
# url argument is always required for TPP.
3737
connector = venafi_connection(platform=VenafiPlatform.TPP, url=url,
38-
http_request_kwargs={"verify": "/tmp/chain.pem"})
38+
http_request_kwargs={'verify': "/tmp/chain.pem"})
3939
# Optionally, the connector can be instantiated passing the specific arguments:
4040
# connector = venafi_connection(url=url, user=user, password=password, http_request_kwargs={"verify": False})
4141

@@ -70,7 +70,7 @@ def main():
7070
ssh_config = connector.retrieve_ssh_config(ca_request=request)
7171
with open("./ca2-pub.key", 'w') as ca_file:
7272
ca_file.write(pub_key_data)
73-
print("Certificate Authority principals: %s" % ssh_config.ca_principals)
73+
print(f"Certificate Authority principals: {ssh_config.ca_principals}")
7474

7575

7676
if __name__ == '__main__':

examples/tpp/get_cert_tpp_token.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def main():
3131
user = environ.get('TPP_USER')
3232
password = environ.get('TPP_PASSWORD')
3333
url = environ.get('TPP_TOKEN_URL')
34-
zone = environ.get("TPP_ZONE")
34+
zone = environ.get('TPP_ZONE')
3535
fake = environ.get('FAKE')
3636

3737
if fake:
@@ -41,18 +41,18 @@ def main():
4141
# If user and password are passed, you can get a new token from them.
4242
# If access_token and refresh_token are passed, there is no need for the username and password.
4343
# If only access_token is passed, the Connection will fail when token expires, as there is no way to refresh it.
44-
conn = venafi_connection(url=url, user=user, password=password, http_request_kwargs={"verify": False})
44+
conn = venafi_connection(url=url, user=user, password=password, http_request_kwargs={'verify': False})
4545
# If your TPP server certificate signed with your own CA, or available only via proxy, you can specify
4646
# a trust bundle using requests vars:
4747
# conn = token_connection(url=url, user=user, password=password,
4848
# http_request_kwargs={"verify": "/path-to/bundle.pem"})
4949

50-
request = CertificateRequest(common_name=random_word(10) + ".venafi.example.com")
51-
request.san_dns = [u"www.client.venafi.example.com", u"ww1.client.venafi.example.com"]
52-
request.email_addresses = [u"e1@venafi.example.com", u"e2@venafi.example.com"]
53-
request.ip_addresses = [u"127.0.0.1", u"192.168.1.1"]
54-
request.uniform_resource_identifiers = [u"http://wgtest.com",u"https://ragnartest.com"]
55-
request.user_principal_names = [u"e1@venafi.example.com", u"e2@venafi.example.com"]
50+
request = CertificateRequest(common_name=f"{random_word(10)}.venafi.example.com")
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"]
53+
request.ip_addresses = ["127.0.0.1", u"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"]
5656
# Specify ordering certificates in chain. Root can be "first" or "last". By default its last. You also can
5757
# specify "ignore" to ignore chain (supported only for Platform).
5858
# To set Custom Fields for the certificate, specify an array of CustomField objects as name-value pairs

examples/tpp/get_service_gen_cert_tpp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,25 @@ def main():
2929
url = environ.get('TPP_TOKEN_URL')
3030
user = environ.get('TPP_USER')
3131
password = environ.get('TPP_PASSWORD')
32-
zone = environ.get("TPP_ZONE")
32+
zone = environ.get('TPP_ZONE')
3333
server_trust_bundle = environ.get('TPP_TRUST_BUNDLE')
3434

3535
# Connection will be chosen automatically based on which arguments are passed.
3636
# If token is passed Venafi Cloud connection will be used.
3737
# If user, password, and URL Venafi Platform (TPP) will be used.
3838
# If your TPP server certificate signed with your own CA, or available only via proxy, you can specify
3939
# a trust bundle using http_request_kwargs.
40-
conn = venafi_connection(url=url, user=user, password=password, http_request_kwargs={"verify": server_trust_bundle})
40+
conn = venafi_connection(url=url, user=user, password=password, http_request_kwargs={'verify': server_trust_bundle})
4141

4242
# Build a Certificate request
43-
request = CertificateRequest(common_name=random_word(10) + ".venafi.example.com")
43+
request = CertificateRequest(common_name=f"{random_word(10)}.venafi.example.com")
4444
# Set the request to use a service generated CSR
4545
request.csr_origin = CSR_ORIGIN_SERVICE
4646
# Include some Subject Alternative Names
4747
request.san_dns = ["www.dns.venafi.example.com", "ww1.dns.venafi.example.com"]
4848
request.email_addresses = ["email1@venafi.example.com", "email2@venafi.example.com"]
4949
request.ip_addresses = ["127.0.0.1", "192.168.1.1"]
50-
request.uniform_resource_identifiers = ["http://wgtest.uri.com","https://ragnartest.uri.com"]
50+
request.uniform_resource_identifiers = ["http://wgtest.uri.com", "https://ragnartest.uri.com"]
5151
request.user_principal_names = ["upn1@venafi.example.com", "upn2@venafi.example.com"]
5252
# Specify whether or not to return the private key. It is False by default.
5353
# A password should be defined for the private key if include_private_key is True.

examples/tpp/set_policy_tpp_token.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def main():
4040
# Get connector object.
4141
# The default state of this connection only allows for certificate management.
4242
connector = venafi_connection(url=url, user=user, password=password,
43-
http_request_kwargs={"verify": server_trust_bundle})
43+
http_request_kwargs={'verify': server_trust_bundle})
4444

4545
# Create Authentication object with required scope for policy management.
4646
auth = Authentication(user=user, password=password, scope=SCOPE_PM)

examples/vaas/get_service_gen_cert_vaas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ def main():
2828
# Get credentials from environment variables
2929
url = environ.get('VAAS_URL') # Optional, only use when connecting to a specific VaaS server
3030
api_key = environ.get('VAAS_APIKEY')
31-
zone = environ.get("VAAS_ZONE")
31+
zone = environ.get('VAAS_ZONE')
3232

3333
# Connection will be chosen automatically based on which arguments are passed.
3434
# If api_key is passed, Venafi Cloud connection will be used.
3535
# url attribute is no required when connecting to production VaaS platform
3636
conn = venafi_connection(url=url, api_key=api_key)
3737

3838
# Build a Certificate request
39-
request = CertificateRequest(common_name=random_word(10) + ".venafi.example.com")
39+
request = CertificateRequest(common_name=f"{random_word(10)}.venafi.example.com")
4040
# Set the request to use a service generated CSR
4141
request.csr_origin = CSR_ORIGIN_SERVICE
4242
# A password should be defined for the private key to be generated.

vcert/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
from .common import CertificateRequest, CommonConnection, RevocationRequest, ZoneConfig, CertField, KeyType, \
17-
CustomField, Authentication, SCOPE_CM, SCOPE_PM, SCOPE_SSH, CSR_ORIGIN_LOCAL, CSR_ORIGIN_PROVIDED, \
18-
CSR_ORIGIN_SERVICE, CHAIN_OPTION_FIRST, CHAIN_OPTION_IGNORE, CHAIN_OPTION_LAST, VenafiPlatform
16+
from .common import (CertificateRequest, CommonConnection, RevocationRequest, ZoneConfig, CertField, KeyType,
17+
CustomField, Authentication, SCOPE_CM, SCOPE_PM, SCOPE_SSH, CSR_ORIGIN_LOCAL, CSR_ORIGIN_PROVIDED,
18+
CSR_ORIGIN_SERVICE, CHAIN_OPTION_FIRST, CHAIN_OPTION_IGNORE, CHAIN_OPTION_LAST, VenafiPlatform)
1919
from .connection_cloud import CloudConnection
2020
from .connection_tpp import TPPConnection
2121
from .connection_tpp_token import TPPTokenConnection
@@ -80,7 +80,7 @@ def venafi_connection(url=None, api_key=None, user=None, password=None, access_t
8080
elif platform == VenafiPlatform.VAAS:
8181
return CloudConnection(token=api_key, url=url, http_request_kwargs=http_request_kwargs)
8282
else:
83-
raise VenafiError("Invalid Platform: %s. Cannot instantiate a Connector." % platform)
83+
raise VenafiError(f"Invalid Platform: {platform}. Cannot instantiate a Connector.")
8484
else:
8585
if fake:
8686
return FakeConnection()

0 commit comments

Comments
 (0)