Skip to content

AccessKeys

Bases: BaseRoute

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

This class provides methods to interact with the Outline server's access keys API. It allows you to retrieve, create, and manage access keys, which are used to control access to the Outline VPN server.

Attributes:

Name Type Description
base_url str

The base URL for the access keys endpoint of the Outline server, formed by appending "/access-keys" to the management URL.

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 for API requests. Default is False. You should set this flag to False if the server's SSL certificate is self-signed or if no certificate is present.

False
Source code in outline_vpn_api_client/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
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
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
class AccessKeys(BaseRoute):
    """
    A class for managing access keys on the Outline VPN server.

    This class provides methods to interact with the Outline server's access keys API. It allows you to retrieve,
    create, and manage access keys, which are used to control access to the Outline VPN server.

    Attributes:
        base_url (str): The base URL for the access keys endpoint of the Outline server, formed by appending "/access-keys"
                        to the management URL.

    Args:
        management_url (str): The management URL used to communicate with the Outline server API.
        ssl_verify (bool): Flag to enable or disable SSL certificate verification for API requests. Default is `False`.
                        You should set this flag to `False` if the server's SSL certificate is self-signed or if no certificate is present.
    """
    def __init__(self, management_url, ssl_verify = False):
        super().__init__(management_url, ssl_verify)
        self.base_url = f"{self.base_url}/access-keys"

    def __str__(self):
        return json.dumps(self.get_all().model_dump(), ensure_ascii=False, indent=4)

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

        This method sends a request to the server to retrieve a list of all access keys that are currently created.
        It returns a dictionary containing the details of all access keys.

        Returns:
            dict: A dictionary containing the details of all access keys, including their IDs and other related information.

        Raises:
            ResponseNotOkException: If the server responds with a status code indicating an error (status code >= 300).        
        """
        response = requests.get(self.base_url, verify=self.ssl_verify)
        response_json = response.json()
        _check_response(response, response_json)
        return models.AccessKeyList.model_validate(response_json)

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

        This method sends a request to the server to retrieve the information of a single access key, identified by its ID.

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

        Returns:
            dict: A dictionary containing the details of the requested access key, including its ID, name, creation date, 
                and other relevant information.

        Raises:
            ResponseNotOkException: If the server responds with a status code indicating an error (status code >= 300).
        """
        response = requests.get(f"{self.base_url}/{id}", verify=self.ssl_verify)
        response_json = response.json()
        _check_response(response, response_json)
        return models.AccessKey.model_validate(response_json)

    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.

        This method sends a request to the server to create a new access key. You can specify the name of the key, the 
        encryption method to use, an optional password, an optional port, and optionally set a data transfer limit for
        the key. If no limit is provided, the key will have no data transfer restrictions.

        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:
            dict: A dictionary containing the details of the newly created access key, including its ID, name and any other relevant information.

        Raises:
            ResponseNotOkException: If the server responds with a status code indicating 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}
        response = requests.post(f"{self.base_url}", json=data, verify=self.ssl_verify)
        response_json = response.json()
        _check_response(response, response_json)
        return models.AccessKey.model_validate(response_json)

    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 on the Outline VPN server with a specific identifier.

        This method sends a request to the server to create a new access key, allowing you to specify a custom ID for 
        the key, along with the key's name, encryption method, an optional password, an optional port, and an optional
        data transfer limit. If no limit is provided, the key will have no data transfer restrictions.

        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:
            dict: A dictionary containing the details of the newly created access key, including its ID, name, creation 
                date, encryption method, transfer limit, and other relevant information.

        Raises:
            ResponseNotOkException: If the server responds with a status code indicating 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}
        response = requests.put(f"{self.base_url}/{id}", json=data, verify=self.ssl_verify)
        response_json = response.json()
        _check_response(response, response_json)
        return models.AccessKey.model_validate(response_json)

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

        This method sends a request to the server to delete a specific access key identified by its ID. Deleting an access 
        key will revoke its access to the 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 responds with a status code indicating an error (status code >= 300).

        """
        response = requests.delete(f"{self.base_url}/{id}", verify=self.ssl_verify)
        _check_response(response)
        return True

    def rename(self, id: int, name: str) -> bool:
        """
        Renames an existing access key on the Outline VPN server.

        This method sends a request to the server to rename a specific access key identified by its ID. The new name for 
        the access key is provided as an argument.

        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 responds with a status code indicating an error (status code >= 300).
        """
        data = {
            "name": name
        }
        response = requests.put(f"{self.base_url}/{id}/name", json=data, verify=self.ssl_verify)
        _check_response(response)
        return True

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

        This method sends a request to the server to apply a data transfer limit for a specific access key, identified 
        by its ID. The limit is specified in bytes.

        Args:
            id (int): The ID of the access key for which the data transfer limit will be set.
            limit (int): The data transfer limit in bytes to apply to the access key.

        Returns:
            bool: `True` if the data transfer limit was successfully set for the access key.

        Raises:
            ResponseNotOkException: If the server responds with a status code indicating an error (status code >= 300).
        """
        data = {
            "limit": {
                "bytes": limit
            }
        }
        response = requests.put(f"{self.base_url}/{id}/data-limit", json=data, verify=self.ssl_verify)
        _check_response(response)
        return True

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

        This method sends a request to the server to remove the data transfer limit for a specific access key, identified 
        by its ID. After calling this method, the access key will no longer have any data transfer restrictions.

        Args:
            id (int): The ID of the access key for which the data transfer limit will be removed.

        Returns:
            bool: `True` if the data transfer limit was successfully removed for the access key.

        Raises:
            ResponseNotOkException: If the server responds with a status code indicating an error (status code >= 300).
        """
        response = requests.delete(f"{self.base_url}/{id}/data-limit", verify=self.ssl_verify)
        _check_response(response)
        return True

change_data_limit(id, limit)

Sets a data transfer limit for the specified access key on the Outline VPN server.

This method sends a request to the server to apply a data transfer limit for a specific access key, identified by its ID. The limit is specified in bytes.

Parameters:

Name Type Description Default
id int

The ID of the access key for which the data transfer limit will be set.

required
limit int

The data transfer limit in bytes to apply to the access key.

required

Returns:

Name Type Description
bool bool

True if the data transfer limit was successfully set for the access key.

Raises:

Type Description
ResponseNotOkException

If the server responds with a status code indicating an error (status code >= 300).

Source code in outline_vpn_api_client/client.py
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
def change_data_limit(self, id: int, limit: int) -> bool:
    """
    Sets a data transfer limit for the specified access key on the Outline VPN server.

    This method sends a request to the server to apply a data transfer limit for a specific access key, identified 
    by its ID. The limit is specified in bytes.

    Args:
        id (int): The ID of the access key for which the data transfer limit will be set.
        limit (int): The data transfer limit in bytes to apply to the access key.

    Returns:
        bool: `True` if the data transfer limit was successfully set for the access key.

    Raises:
        ResponseNotOkException: If the server responds with a status code indicating an error (status code >= 300).
    """
    data = {
        "limit": {
            "bytes": limit
        }
    }
    response = requests.put(f"{self.base_url}/{id}/data-limit", json=data, verify=self.ssl_verify)
    _check_response(response)
    return True

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

Creates a new access key on the Outline VPN server.

This method sends a request to the server to create a new access key. You can specify the name of the key, the encryption method to use, an optional password, an optional port, and optionally set a data transfer limit for the key. If no limit is provided, the key will have no data transfer restrictions.

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:

Name Type Description
dict AccessKey

A dictionary containing the details of the newly created access key, including its ID, name and any other relevant information.

Raises:

Type Description
ResponseNotOkException

If the server responds with a status code indicating an error (status code >= 300).

Source code in outline_vpn_api_client/client.py
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
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.

    This method sends a request to the server to create a new access key. You can specify the name of the key, the 
    encryption method to use, an optional password, an optional port, and optionally set a data transfer limit for
    the key. If no limit is provided, the key will have no data transfer restrictions.

    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:
        dict: A dictionary containing the details of the newly created access key, including its ID, name and any other relevant information.

    Raises:
        ResponseNotOkException: If the server responds with a status code indicating 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}
    response = requests.post(f"{self.base_url}", json=data, verify=self.ssl_verify)
    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)

Creates a new access key on the Outline VPN server with a specific identifier.

This method sends a request to the server to create a new access key, allowing you to specify a custom ID for the key, along with the key's name, encryption method, an optional password, an optional port, and an optional data transfer limit. If no limit is provided, the key will have no data transfer restrictions.

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:

Name Type Description
dict AccessKey

A dictionary containing the details of the newly created access key, including its ID, name, creation date, encryption method, transfer limit, and other relevant information.

Raises:

Type Description
ResponseNotOkException

If the server responds with a status code indicating an error (status code >= 300).

Source code in outline_vpn_api_client/client.py
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
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 on the Outline VPN server with a specific identifier.

    This method sends a request to the server to create a new access key, allowing you to specify a custom ID for 
    the key, along with the key's name, encryption method, an optional password, an optional port, and an optional
    data transfer limit. If no limit is provided, the key will have no data transfer restrictions.

    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:
        dict: A dictionary containing the details of the newly created access key, including its ID, name, creation 
            date, encryption method, transfer limit, and other relevant information.

    Raises:
        ResponseNotOkException: If the server responds with a status code indicating 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}
    response = requests.put(f"{self.base_url}/{id}", json=data, verify=self.ssl_verify)
    response_json = response.json()
    _check_response(response, response_json)
    return models.AccessKey.model_validate(response_json)

delete(id)

Deletes an access key on the Outline VPN server.

This method sends a request to the server to delete a specific access key identified by its ID. Deleting an access key will revoke its access to the 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 responds with a status code indicating an error (status code >= 300).

Source code in outline_vpn_api_client/client.py
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
def delete(self, id: int) -> bool:
    """
     Deletes an access key on the Outline VPN server.

    This method sends a request to the server to delete a specific access key identified by its ID. Deleting an access 
    key will revoke its access to the 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 responds with a status code indicating an error (status code >= 300).

    """
    response = requests.delete(f"{self.base_url}/{id}", verify=self.ssl_verify)
    _check_response(response)
    return True

get(id)

Retrieves the details of a specific access key on the Outline VPN server.

This method sends a request to the server to retrieve the information of a single access key, identified by its ID.

Parameters:

Name Type Description Default
id int

The ID of the access key to retrieve.

required

Returns:

Name Type Description
dict AccessKey

A dictionary containing the details of the requested access key, including its ID, name, creation date, and other relevant information.

Raises:

Type Description
ResponseNotOkException

If the server responds with a status code indicating an error (status code >= 300).

Source code in outline_vpn_api_client/client.py
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
def get(self, id: int) -> models.AccessKey:
    """
    Retrieves the details of a specific access key on the Outline VPN server.

    This method sends a request to the server to retrieve the information of a single access key, identified by its ID.

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

    Returns:
        dict: A dictionary containing the details of the requested access key, including its ID, name, creation date, 
            and other relevant information.

    Raises:
        ResponseNotOkException: If the server responds with a status code indicating an error (status code >= 300).
    """
    response = requests.get(f"{self.base_url}/{id}", verify=self.ssl_verify)
    response_json = response.json()
    _check_response(response, response_json)
    return models.AccessKey.model_validate(response_json)

get_all()

Lists all the access keys on the Outline VPN server.

This method sends a request to the server to retrieve a list of all access keys that are currently created. It returns a dictionary containing the details of all access keys.

Returns:

Name Type Description
dict AccessKeyList

A dictionary containing the details of all access keys, including their IDs and other related information.

Raises:

Type Description
ResponseNotOkException

If the server responds with a status code indicating an error (status code >= 300).

Source code in outline_vpn_api_client/client.py
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
def get_all(self) -> models.AccessKeyList:
    """
    Lists all the access keys on the Outline VPN server.

    This method sends a request to the server to retrieve a list of all access keys that are currently created.
    It returns a dictionary containing the details of all access keys.

    Returns:
        dict: A dictionary containing the details of all access keys, including their IDs and other related information.

    Raises:
        ResponseNotOkException: If the server responds with a status code indicating an error (status code >= 300).        
    """
    response = requests.get(self.base_url, verify=self.ssl_verify)
    response_json = response.json()
    _check_response(response, response_json)
    return models.AccessKeyList.model_validate(response_json)

remove_data_limit(id)

Removes the data transfer limit on the specified access key on the Outline VPN server.

This method sends a request to the server to remove the data transfer limit for a specific access key, identified by its ID. After calling this method, the access key will no longer have any data transfer restrictions.

Parameters:

Name Type Description Default
id int

The ID of the access key for which the data transfer limit will be removed.

required

Returns:

Name Type Description
bool bool

True if the data transfer limit was successfully removed for the access key.

Raises:

Type Description
ResponseNotOkException

If the server responds with a status code indicating an error (status code >= 300).

Source code in outline_vpn_api_client/client.py
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
def remove_data_limit(self, id: int) -> bool:
    """
    Removes the data transfer limit on the specified access key on the Outline VPN server.

    This method sends a request to the server to remove the data transfer limit for a specific access key, identified 
    by its ID. After calling this method, the access key will no longer have any data transfer restrictions.

    Args:
        id (int): The ID of the access key for which the data transfer limit will be removed.

    Returns:
        bool: `True` if the data transfer limit was successfully removed for the access key.

    Raises:
        ResponseNotOkException: If the server responds with a status code indicating an error (status code >= 300).
    """
    response = requests.delete(f"{self.base_url}/{id}/data-limit", verify=self.ssl_verify)
    _check_response(response)
    return True

rename(id, name)

Renames an existing access key on the Outline VPN server.

This method sends a request to the server to rename a specific access key identified by its ID. The new name for the access key is provided as an argument.

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 responds with a status code indicating an error (status code >= 300).

Source code in outline_vpn_api_client/client.py
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
def rename(self, id: int, name: str) -> bool:
    """
    Renames an existing access key on the Outline VPN server.

    This method sends a request to the server to rename a specific access key identified by its ID. The new name for 
    the access key is provided as an argument.

    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 responds with a status code indicating an error (status code >= 300).
    """
    data = {
        "name": name
    }
    response = requests.put(f"{self.base_url}/{id}/name", json=data, verify=self.ssl_verify)
    _check_response(response)
    return True