Skip to content

AsyncAccessKeys

Bases: AsyncBaseRoute

A class for managing access keys on the Outline VPN server asynchronously.

Provides methods to retrieve, create, rename, delete, and set data limits on access keys, which are used to control access to the Outline VPN server.

Parameters:

Name Type Description Default
management_url str

The management URL used to communicate with the Outline server API.

required
ssl_verify bool

Flag to enable or disable SSL certificate verification. Default is False.

False
Source code in outline_vpn_api_client/async_client.py
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
class AsyncAccessKeys(AsyncBaseRoute):
    """
    A class for managing access keys on the Outline VPN server asynchronously.

    Provides methods to retrieve, create, rename, delete, and set data limits
    on access keys, which are used to control access to the Outline VPN server.

    Args:
        management_url (str): The management URL used to communicate with the Outline server API.
        ssl_verify (bool, optional): Flag to enable or disable SSL certificate verification. Default is False.
    """

    def __init__(self, management_url, ssl_verify=False):
        super().__init__(management_url, ssl_verify)
        self.base_url = f"{self.base_url}/access-keys"

    async def get_all(self) -> models.AccessKeyList:
        """
        Lists all the access keys on the Outline VPN server.

        Returns:
            models.AccessKeyList: All access keys on the server.

        Raises:
            ResponseNotOkException: If the server response indicates an error (status code >= 300).
        """
        async with httpx.AsyncClient(verify=self.ssl_verify) as client:
            response = await client.get(f"{self.base_url}")
            response_json = response.json()
            _check_response(response, response_json)
        return models.AccessKeyList.model_validate(response_json)

    async def get(self, id: int) -> models.AccessKey:
        """
        Retrieves the details of a specific access key.

        Args:
            id (int): The ID of the access key to retrieve.

        Returns:
            models.AccessKey: Details of the requested access key.

        Raises:
            ResponseNotOkException: If the server response indicates an error (status code >= 300).
        """
        async with httpx.AsyncClient(verify=self.ssl_verify) as client:
            response = await client.get(f"{self.base_url}/{id}")
            response_json = response.json()
            _check_response(response, response_json)
        return models.AccessKey.model_validate(response_json)

    async def create(
        self,
        name: str,
        method: str = "aes-192-gcm",
        password: Optional[str] = None,
        port: Optional[int] = None,
        limit: Optional[int] = None,
    ) -> models.AccessKey:
        """
        Creates a new access key on the Outline VPN server.

        Args:
            name (str): The name to assign to the new access key.
            method (str, optional): The encryption method to use for the access key. Default is "aes-192-gcm".
            password (str, optional): A custom password for the access key. If not provided, the server generates one.
            port (int, optional): A custom port for the access key. If not provided, the server default port is used.
            limit (int, optional): The data transfer limit for the access key in bytes. If not provided, the key will
                                   have no transfer limit.

        Returns:
            models.AccessKey: The newly created access key.

        Raises:
            ResponseNotOkException: If the server response indicates an error (status code >= 300).
        """
        data = {"name": name, "method": method}
        if password is not None:
            data["password"] = password
        if port is not None:
            data["port"] = port
        if limit is not None:
            data["limit"] = {"bytes": limit}
        async with httpx.AsyncClient(verify=self.ssl_verify) as client:
            response = await client.post(f"{self.base_url}", json=data)
            response_json = response.json()
            _check_response(response, response_json)
        return models.AccessKey.model_validate(response_json)

    async def create_with_special_id(
        self,
        id: int,
        name: str,
        method: str = "aes-192-gcm",
        password: Optional[str] = None,
        port: Optional[int] = None,
        limit: Optional[int] = None,
    ) -> models.AccessKey:
        """
        Creates a new access key with a specific identifier.

        Args:
            id (int): The custom ID to assign to the new access key.
            name (str): The name to assign to the new access key.
            method (str, optional): The encryption method to use for the access key. Default is "aes-192-gcm".
            password (str, optional): A custom password for the access key. If not provided, the server generates one.
            port (int, optional): A custom port for the access key. If not provided, the server default port is used.
            limit (int, optional): The data transfer limit for the access key in bytes. If not provided, the key will
                                   have no transfer limit.

        Returns:
            models.AccessKey: The newly created access key.

        Raises:
            ResponseNotOkException: If the server response indicates an error (status code >= 300).
        """
        data = {"name": name, "method": method}
        if password is not None:
            data["password"] = password
        if port is not None:
            data["port"] = port
        if limit is not None:
            data["limit"] = {"bytes": limit}
        async with httpx.AsyncClient(verify=self.ssl_verify) as client:
            response = await client.put(f"{self.base_url}/{id}", json=data)
            response_json = response.json()
            _check_response(response, response_json)
        return models.AccessKey.model_validate(response_json)

    async def delete(self, id: int) -> bool:
        """
        Deletes an access key on the Outline VPN server.

        Args:
            id (int): The ID of the access key to be deleted.

        Returns:
            bool: True if the access key was successfully deleted.

        Raises:
            ResponseNotOkException: If the server response indicates an error (status code >= 300).
        """
        async with httpx.AsyncClient(verify=self.ssl_verify) as client:
            response = await client.delete(f"{self.base_url}/{id}")
            _check_response(response)
        return True

    async def rename(self, id: int, name: str) -> bool:
        """
        Renames an existing access key.

        Args:
            id (int): The ID of the access key to be renamed.
            name (str): The new name to assign to the access key.

        Returns:
            bool: True if the access key was successfully renamed.

        Raises:
            ResponseNotOkException: If the server response indicates an error (status code >= 300).
        """
        data = {"name": name}
        async with httpx.AsyncClient(verify=self.ssl_verify) as client:
            response = await client.put(f"{self.base_url}/{id}/name", json=data)
            _check_response(response)
        return True

    async def change_data_limit(self, id: int, limit: int) -> bool:
        """
        Sets a data transfer limit for the specified access key.

        Args:
            id (int): The ID of the access key.
            limit (int): The data transfer limit in bytes.

        Returns:
            bool: True if the data transfer limit was successfully set.

        Raises:
            ResponseNotOkException: If the server response indicates an error (status code >= 300).
        """
        data = {"limit": {"bytes": limit}}
        async with httpx.AsyncClient(verify=self.ssl_verify) as client:
            response = await client.put(f"{self.base_url}/{id}/data-limit", json=data)
            _check_response(response)
        return True

    async def remove_data_limit(self, id: int) -> bool:
        """
        Removes the data transfer limit on the specified access key.

        Args:
            id (int): The ID of the access key.

        Returns:
            bool: True if the data transfer limit was successfully removed.

        Raises:
            ResponseNotOkException: If the server response indicates an error (status code >= 300).
        """
        async with httpx.AsyncClient(verify=self.ssl_verify) as client:
            response = await client.delete(f"{self.base_url}/{id}/data-limit")
            _check_response(response)
        return True

    def __str__(self):
        return json.dumps({"info": "AsyncAccessKeys object for managing access keys"}, ensure_ascii=False)

change_data_limit(id, limit) async

Sets a data transfer limit for the specified access key.

Parameters:

Name Type Description Default
id int

The ID of the access key.

required
limit int

The data transfer limit in bytes.

required

Returns:

Name Type Description
bool bool

True if the data transfer limit was successfully set.

Raises:

Type Description
ResponseNotOkException

If the server response indicates an error (status code >= 300).

Source code in outline_vpn_api_client/async_client.py
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
async def change_data_limit(self, id: int, limit: int) -> bool:
    """
    Sets a data transfer limit for the specified access key.

    Args:
        id (int): The ID of the access key.
        limit (int): The data transfer limit in bytes.

    Returns:
        bool: True if the data transfer limit was successfully set.

    Raises:
        ResponseNotOkException: If the server response indicates an error (status code >= 300).
    """
    data = {"limit": {"bytes": limit}}
    async with httpx.AsyncClient(verify=self.ssl_verify) as client:
        response = await client.put(f"{self.base_url}/{id}/data-limit", json=data)
        _check_response(response)
    return True

create(name, method='aes-192-gcm', password=None, port=None, limit=None) async

Creates a new access key on the Outline VPN server.

Parameters:

Name Type Description Default
name str

The name to assign to the new access key.

required
method str

The encryption method to use for the access key. Default is "aes-192-gcm".

'aes-192-gcm'
password str

A custom password for the access key. If not provided, the server generates one.

None
port int

A custom port for the access key. If not provided, the server default port is used.

None
limit int

The data transfer limit for the access key in bytes. If not provided, the key will have no transfer limit.

None

Returns:

Type Description
AccessKey

models.AccessKey: The newly created access key.

Raises:

Type Description
ResponseNotOkException

If the server response indicates an error (status code >= 300).

Source code in outline_vpn_api_client/async_client.py
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
async def create(
    self,
    name: str,
    method: str = "aes-192-gcm",
    password: Optional[str] = None,
    port: Optional[int] = None,
    limit: Optional[int] = None,
) -> models.AccessKey:
    """
    Creates a new access key on the Outline VPN server.

    Args:
        name (str): The name to assign to the new access key.
        method (str, optional): The encryption method to use for the access key. Default is "aes-192-gcm".
        password (str, optional): A custom password for the access key. If not provided, the server generates one.
        port (int, optional): A custom port for the access key. If not provided, the server default port is used.
        limit (int, optional): The data transfer limit for the access key in bytes. If not provided, the key will
                               have no transfer limit.

    Returns:
        models.AccessKey: The newly created access key.

    Raises:
        ResponseNotOkException: If the server response indicates an error (status code >= 300).
    """
    data = {"name": name, "method": method}
    if password is not None:
        data["password"] = password
    if port is not None:
        data["port"] = port
    if limit is not None:
        data["limit"] = {"bytes": limit}
    async with httpx.AsyncClient(verify=self.ssl_verify) as client:
        response = await client.post(f"{self.base_url}", json=data)
        response_json = response.json()
        _check_response(response, response_json)
    return models.AccessKey.model_validate(response_json)

create_with_special_id(id, name, method='aes-192-gcm', password=None, port=None, limit=None) async

Creates a new access key with a specific identifier.

Parameters:

Name Type Description Default
id int

The custom ID to assign to the new access key.

required
name str

The name to assign to the new access key.

required
method str

The encryption method to use for the access key. Default is "aes-192-gcm".

'aes-192-gcm'
password str

A custom password for the access key. If not provided, the server generates one.

None
port int

A custom port for the access key. If not provided, the server default port is used.

None
limit int

The data transfer limit for the access key in bytes. If not provided, the key will have no transfer limit.

None

Returns:

Type Description
AccessKey

models.AccessKey: The newly created access key.

Raises:

Type Description
ResponseNotOkException

If the server response indicates an error (status code >= 300).

Source code in outline_vpn_api_client/async_client.py
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
async def create_with_special_id(
    self,
    id: int,
    name: str,
    method: str = "aes-192-gcm",
    password: Optional[str] = None,
    port: Optional[int] = None,
    limit: Optional[int] = None,
) -> models.AccessKey:
    """
    Creates a new access key with a specific identifier.

    Args:
        id (int): The custom ID to assign to the new access key.
        name (str): The name to assign to the new access key.
        method (str, optional): The encryption method to use for the access key. Default is "aes-192-gcm".
        password (str, optional): A custom password for the access key. If not provided, the server generates one.
        port (int, optional): A custom port for the access key. If not provided, the server default port is used.
        limit (int, optional): The data transfer limit for the access key in bytes. If not provided, the key will
                               have no transfer limit.

    Returns:
        models.AccessKey: The newly created access key.

    Raises:
        ResponseNotOkException: If the server response indicates an error (status code >= 300).
    """
    data = {"name": name, "method": method}
    if password is not None:
        data["password"] = password
    if port is not None:
        data["port"] = port
    if limit is not None:
        data["limit"] = {"bytes": limit}
    async with httpx.AsyncClient(verify=self.ssl_verify) as client:
        response = await client.put(f"{self.base_url}/{id}", json=data)
        response_json = response.json()
        _check_response(response, response_json)
    return models.AccessKey.model_validate(response_json)

delete(id) async

Deletes an access key on the Outline VPN server.

Parameters:

Name Type Description Default
id int

The ID of the access key to be deleted.

required

Returns:

Name Type Description
bool bool

True if the access key was successfully deleted.

Raises:

Type Description
ResponseNotOkException

If the server response indicates an error (status code >= 300).

Source code in outline_vpn_api_client/async_client.py
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
async def delete(self, id: int) -> bool:
    """
    Deletes an access key on the Outline VPN server.

    Args:
        id (int): The ID of the access key to be deleted.

    Returns:
        bool: True if the access key was successfully deleted.

    Raises:
        ResponseNotOkException: If the server response indicates an error (status code >= 300).
    """
    async with httpx.AsyncClient(verify=self.ssl_verify) as client:
        response = await client.delete(f"{self.base_url}/{id}")
        _check_response(response)
    return True

get(id) async

Retrieves the details of a specific access key.

Parameters:

Name Type Description Default
id int

The ID of the access key to retrieve.

required

Returns:

Type Description
AccessKey

models.AccessKey: Details of the requested access key.

Raises:

Type Description
ResponseNotOkException

If the server response indicates an error (status code >= 300).

Source code in outline_vpn_api_client/async_client.py
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
async def get(self, id: int) -> models.AccessKey:
    """
    Retrieves the details of a specific access key.

    Args:
        id (int): The ID of the access key to retrieve.

    Returns:
        models.AccessKey: Details of the requested access key.

    Raises:
        ResponseNotOkException: If the server response indicates an error (status code >= 300).
    """
    async with httpx.AsyncClient(verify=self.ssl_verify) as client:
        response = await client.get(f"{self.base_url}/{id}")
        response_json = response.json()
        _check_response(response, response_json)
    return models.AccessKey.model_validate(response_json)

get_all() async

Lists all the access keys on the Outline VPN server.

Returns:

Type Description
AccessKeyList

models.AccessKeyList: All access keys on the server.

Raises:

Type Description
ResponseNotOkException

If the server response indicates an error (status code >= 300).

Source code in outline_vpn_api_client/async_client.py
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
async def get_all(self) -> models.AccessKeyList:
    """
    Lists all the access keys on the Outline VPN server.

    Returns:
        models.AccessKeyList: All access keys on the server.

    Raises:
        ResponseNotOkException: If the server response indicates an error (status code >= 300).
    """
    async with httpx.AsyncClient(verify=self.ssl_verify) as client:
        response = await client.get(f"{self.base_url}")
        response_json = response.json()
        _check_response(response, response_json)
    return models.AccessKeyList.model_validate(response_json)

remove_data_limit(id) async

Removes the data transfer limit on the specified access key.

Parameters:

Name Type Description Default
id int

The ID of the access key.

required

Returns:

Name Type Description
bool bool

True if the data transfer limit was successfully removed.

Raises:

Type Description
ResponseNotOkException

If the server response indicates an error (status code >= 300).

Source code in outline_vpn_api_client/async_client.py
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
async def remove_data_limit(self, id: int) -> bool:
    """
    Removes the data transfer limit on the specified access key.

    Args:
        id (int): The ID of the access key.

    Returns:
        bool: True if the data transfer limit was successfully removed.

    Raises:
        ResponseNotOkException: If the server response indicates an error (status code >= 300).
    """
    async with httpx.AsyncClient(verify=self.ssl_verify) as client:
        response = await client.delete(f"{self.base_url}/{id}/data-limit")
        _check_response(response)
    return True

rename(id, name) async

Renames an existing access key.

Parameters:

Name Type Description Default
id int

The ID of the access key to be renamed.

required
name str

The new name to assign to the access key.

required

Returns:

Name Type Description
bool bool

True if the access key was successfully renamed.

Raises:

Type Description
ResponseNotOkException

If the server response indicates an error (status code >= 300).

Source code in outline_vpn_api_client/async_client.py
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
async def rename(self, id: int, name: str) -> bool:
    """
    Renames an existing access key.

    Args:
        id (int): The ID of the access key to be renamed.
        name (str): The new name to assign to the access key.

    Returns:
        bool: True if the access key was successfully renamed.

    Raises:
        ResponseNotOkException: If the server response indicates an error (status code >= 300).
    """
    data = {"name": name}
    async with httpx.AsyncClient(verify=self.ssl_verify) as client:
        response = await client.put(f"{self.base_url}/{id}/name", json=data)
        _check_response(response)
    return True