Skip to content

Certificates API

The CertificatesAPI client provides methods for managing Incus certificates.

Usage

from incus_sdk import Client

async with Client() as client:
    # List all certificates
    certificates = await client.certificates.list()

    # Get a certificate by fingerprint
    certificate = await client.certificates.get("abcdef123456")

    # Create a new certificate
    with open("client.crt", "r") as f:
        cert_data = f.read()

    await client.certificates.create(
        certificate=cert_data,
        name="my-client",
        type="client",
        restricted=True,
        projects=["default"]
    )

    # Update a certificate
    await client.certificates.update(
        "abcdef123456",
        {
            "name": "updated-client",
            "restricted": False
        }
    )

    # Delete a certificate
    await client.certificates.delete("abcdef123456")

Class Documentation

API client for Incus certificates.

Source code in incus_sdk/api/certificates.py
 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
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
class CertificatesAPI:
    """API client for Incus certificates."""

    def __init__(self, client: APIClient):
        """
        Initialize a new CertificatesAPI client.

        Args:
            client: The base API client.
        """
        self.client = client

    async def list(self, recursion: int = 1) -> List[Certificate]:
        """
        List all certificates.

        Args:
            recursion: Level of recursion for the response.

        Returns:
            List[Certificate]: List of certificates.
        """
        params = {"recursion": recursion}
        response = await self.client.get("/1.0/certificates", params=params)

        certificates = []
        for cert_data in response.get("metadata", []):
            certificates.append(Certificate(client=self, **cert_data))

        return certificates

    async def get(self, fingerprint: str) -> Certificate:
        """
        Get a certificate by fingerprint.

        Args:
            fingerprint: Fingerprint of the certificate.

        Returns:
            Certificate: The certificate.
        """
        response = await self.client.get(f"/1.0/certificates/{fingerprint}")
        return Certificate(client=self, **response.get("metadata", {}))

    async def create(
        self,
        certificate: str,
        name: str = None,
        type: str = "client",
        restricted: bool = False,
        projects: List[str] = None,
        password: str = None,
    ) -> Dict[str, Any]:
        """
        Create a new certificate.

        Args:
            certificate: Certificate data.
            name: Name of the certificate.
            type: Type of certificate.
            restricted: Whether the certificate is restricted.
            projects: List of projects the certificate has access to.
            password: Password for the certificate.

        Returns:
            Dict[str, Any]: The operation response.
        """
        data = {"certificate": certificate, "type": type, "restricted": restricted}

        if name:
            data["name"] = name
        if projects:
            data["projects"] = projects
        if password:
            data["password"] = password

        return await self.client.post("/1.0/certificates", data=data)

    async def delete(self, fingerprint: str) -> Dict[str, Any]:
        """
        Delete a certificate.

        Args:
            fingerprint: Fingerprint of the certificate.

        Returns:
            Dict[str, Any]: The operation response.
        """
        return await self.client.delete(f"/1.0/certificates/{fingerprint}")

    async def update(self, fingerprint: str, data: Dict[str, Any]) -> Dict[str, Any]:
        """
        Update a certificate.

        Args:
            fingerprint: Fingerprint of the certificate.
            data: New certificate data.

        Returns:
            Dict[str, Any]: The operation response.
        """
        return await self.client.patch(f"/1.0/certificates/{fingerprint}", data=data)

__init__(client)

Initialize a new CertificatesAPI client.

Parameters:

Name Type Description Default
client APIClient

The base API client.

required
Source code in incus_sdk/api/certificates.py
14
15
16
17
18
19
20
21
def __init__(self, client: APIClient):
    """
    Initialize a new CertificatesAPI client.

    Args:
        client: The base API client.
    """
    self.client = client

create(certificate, name=None, type='client', restricted=False, projects=None, password=None) async

Create a new certificate.

Parameters:

Name Type Description Default
certificate str

Certificate data.

required
name str

Name of the certificate.

None
type str

Type of certificate.

'client'
restricted bool

Whether the certificate is restricted.

False
projects List[str]

List of projects the certificate has access to.

None
password str

Password for the certificate.

None

Returns:

Type Description
Dict[str, Any]

Dict[str, Any]: The operation response.

Source code in incus_sdk/api/certificates.py
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
async def create(
    self,
    certificate: str,
    name: str = None,
    type: str = "client",
    restricted: bool = False,
    projects: List[str] = None,
    password: str = None,
) -> Dict[str, Any]:
    """
    Create a new certificate.

    Args:
        certificate: Certificate data.
        name: Name of the certificate.
        type: Type of certificate.
        restricted: Whether the certificate is restricted.
        projects: List of projects the certificate has access to.
        password: Password for the certificate.

    Returns:
        Dict[str, Any]: The operation response.
    """
    data = {"certificate": certificate, "type": type, "restricted": restricted}

    if name:
        data["name"] = name
    if projects:
        data["projects"] = projects
    if password:
        data["password"] = password

    return await self.client.post("/1.0/certificates", data=data)

delete(fingerprint) async

Delete a certificate.

Parameters:

Name Type Description Default
fingerprint str

Fingerprint of the certificate.

required

Returns:

Type Description
Dict[str, Any]

Dict[str, Any]: The operation response.

Source code in incus_sdk/api/certificates.py
89
90
91
92
93
94
95
96
97
98
99
async def delete(self, fingerprint: str) -> Dict[str, Any]:
    """
    Delete a certificate.

    Args:
        fingerprint: Fingerprint of the certificate.

    Returns:
        Dict[str, Any]: The operation response.
    """
    return await self.client.delete(f"/1.0/certificates/{fingerprint}")

get(fingerprint) async

Get a certificate by fingerprint.

Parameters:

Name Type Description Default
fingerprint str

Fingerprint of the certificate.

required

Returns:

Name Type Description
Certificate Certificate

The certificate.

Source code in incus_sdk/api/certificates.py
42
43
44
45
46
47
48
49
50
51
52
53
async def get(self, fingerprint: str) -> Certificate:
    """
    Get a certificate by fingerprint.

    Args:
        fingerprint: Fingerprint of the certificate.

    Returns:
        Certificate: The certificate.
    """
    response = await self.client.get(f"/1.0/certificates/{fingerprint}")
    return Certificate(client=self, **response.get("metadata", {}))

list(recursion=1) async

List all certificates.

Parameters:

Name Type Description Default
recursion int

Level of recursion for the response.

1

Returns:

Type Description
List[Certificate]

List[Certificate]: List of certificates.

Source code in incus_sdk/api/certificates.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
async def list(self, recursion: int = 1) -> List[Certificate]:
    """
    List all certificates.

    Args:
        recursion: Level of recursion for the response.

    Returns:
        List[Certificate]: List of certificates.
    """
    params = {"recursion": recursion}
    response = await self.client.get("/1.0/certificates", params=params)

    certificates = []
    for cert_data in response.get("metadata", []):
        certificates.append(Certificate(client=self, **cert_data))

    return certificates

update(fingerprint, data) async

Update a certificate.

Parameters:

Name Type Description Default
fingerprint str

Fingerprint of the certificate.

required
data Dict[str, Any]

New certificate data.

required

Returns:

Type Description
Dict[str, Any]

Dict[str, Any]: The operation response.

Source code in incus_sdk/api/certificates.py
101
102
103
104
105
106
107
108
109
110
111
112
async def update(self, fingerprint: str, data: Dict[str, Any]) -> Dict[str, Any]:
    """
    Update a certificate.

    Args:
        fingerprint: Fingerprint of the certificate.
        data: New certificate data.

    Returns:
        Dict[str, Any]: The operation response.
    """
    return await self.client.patch(f"/1.0/certificates/{fingerprint}", data=data)

Methods

list

async def list(recursion: int = 1) -> List[Certificate]

List all certificates.

Parameters: - recursion: Level of recursion for the response (default: 1).

Returns: - A list of Certificate objects.

get

async def get(fingerprint: str) -> Certificate

Get a certificate by fingerprint.

Parameters: - fingerprint: Fingerprint of the certificate.

Returns: - A Certificate object.

create

async def create(
    certificate: str,
    name: str = None,
    type: str = "client",
    restricted: bool = False,
    projects: List[str] = None,
    password: str = None,
) -> Dict[str, Any]

Create a new certificate.

Parameters: - certificate: Certificate data as a string. - name: Name of the certificate (optional). - type: Type of certificate (default: "client"). - restricted: Whether the certificate is restricted (default: False). - projects: List of projects the certificate has access to (optional). - password: Password for the certificate (optional).

Returns: - The operation response as a dictionary.

Example:

# Create a client certificate
with open("client.crt", "r") as f:
    cert_data = f.read()

await client.certificates.create(
    certificate=cert_data,
    name="my-client",
    type="client",
    restricted=True,
    projects=["default", "production"]
)

delete

async def delete(
    fingerprint: str
) -> Dict[str, Any]

Delete a certificate.

Parameters: - fingerprint: Fingerprint of the certificate.

Returns: - The operation response as a dictionary.

update

async def update(
    fingerprint: str, 
    data: Dict[str, Any]
) -> Dict[str, Any]

Update a certificate.

Parameters: - fingerprint: Fingerprint of the certificate. - data: New certificate data as a dictionary.

Returns: - The operation response as a dictionary.

Example:

# Update a certificate
await client.certificates.update(
    "abcdef123456",
    {
        "name": "updated-client",
        "restricted": False,
        "projects": ["default", "staging", "production"]
    }
)