This repository was archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathusage_certificate.py
More file actions
58 lines (43 loc) · 1.66 KB
/
usage_certificate.py
File metadata and controls
58 lines (43 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from yandex_cloud_client import CertificateClient
TOKEN = "YOUR_OAUTH_TOKEN"
client = CertificateClient(oauth_token=TOKEN)
def create_free_cert(folder, name, domains, challenge_type):
operation = client.createLetsEncryptCertificate(
folder_id=folder,
name=name,
domains=domains,
challenge_type=challenge_type
)
return operation.metadata.certificate_id # get certificate id from operation metadata
def get_vaildated_certificate(cid):
cert = client.certificate(cid)
content = cert.content()
print('Name:', cert.name)
print('Status:', cert.status)
print('Domains:', ','.join(cert.domains) if cert.domains else 'Empty')
print('Expires:', cert.expires)
print('\nFullChain:\n', ''.join(content.fullchain))
print('PrivateKey:\n', content.private_key)
def get_not_vaildated_certificate(cid):
cert = client.certificate(cid)
print('Name:', cert.name)
print('Status:', cert.status)
print('Domains:', ','.join(cert.domains))
for challenge in cert.challenges:
print('\n', challenge.message, sep='')
print('Status:', challenge.status)
print('Record Name:', challenge.dns_challenge.name)
print('Record Type:', challenge.dns_challenge.type)
print('Record Content:', challenge.dns_challenge.value)
if __name__ == '__main__':
get_vaildated_certificate("YOUR EXISTING VALID CERTIFICATE") # if you own validated cert
new_cert = create_free_cert(
folder="YOUR_FOLDER_ID",
name="test",
domains=[
"example.com",
"example.ru"
],
challenge_type="DNS"
)
get_not_vaildated_certificate(new_cert)