/usr/lib/python3/dist-packages/digitalocean/Certificate.py is in python3-digitalocean 1.13.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | # -*- coding: utf-8 -*-
from .baseapi import BaseAPI, POST, DELETE
class Certificate(BaseAPI):
"""
An object representing an SSL Certificate stored on DigitalOcean.
Attributes accepted at creation time:
Args:
name (str): A name for the Certificate
private_key (str): The contents of a PEM-formatted private-key
corresponding to the SSL certificate
leaf_certificate (str): The contents of a PEM-formatted public SSL
certificate
certificate_chain (str): The full PEM-formatted trust chain between the
certificate authority's certificate and your domain's SSL
certificate
Attributes returned by API:
name (str): The name of the Certificate
id (str): A unique identifier for the Certificate
not_after (str): A string that represents the Certificate's expiration
date.
sha1_fingerprint (str): A unique identifier for the Certificate
generated from its SHA-1 fingerprint
created_at (str): A string that represents when the Certificate was
created
"""
def __init__(self, *args, **kwargs):
self.id = ""
self.name = None
self.private_key = None
self.leaf_certificate = None
self.certificate_chain = None
self.not_after = None
self.sha1_fingerprint = None
self.created_at = None
super(Certificate, self).__init__(*args, **kwargs)
@classmethod
def get_object(cls, api_token, cert_id):
"""
Class method that will return a Certificate object by its ID.
"""
certificate = cls(token=api_token, id=cert_id)
certificate.load()
return certificate
def load(self):
"""
Load the Certificate object from DigitalOcean.
Requires self.id to be set.
"""
data = self.get_data("certificates/%s" % self.id)
certificate = data["certificate"]
for attr in certificate.keys():
setattr(self, attr, certificate[attr])
return self
def create(self):
"""
Create the Certificate
"""
params = {
"name": self.name,
"private_key": self.private_key,
"leaf_certificate": self.leaf_certificate,
"certificate_chain": self.certificate_chain
}
data = self.get_data("certificates/", type=POST, params=params)
if data:
self.id = data['certificate']['id']
self.not_after = data['certificate']['not_after']
self.sha1_fingerprint = data['certificate']['sha1_fingerprint']
self.created_at = data['certificate']['created_at']
return self
def destroy(self):
"""
Delete the Certificate
"""
return self.get_data("certificates/%s" % self.id, type=DELETE)
def __str__(self):
return "<Certificate: %s %s>" % (self.id, self.name)
|