File: preparers.py

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (81 lines) | stat: -rw-r--r-- 2,535 bytes parent folder | download | duplicates (2)
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
# coding: utf-8

# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------

from typing import List
import functools

from azure.security.attestation import AttestationType

try:
    from typing import TYPE_CHECKING
except ImportError:
    TYPE_CHECKING = False

if TYPE_CHECKING:
    from typing import Callable, Dict, Optional, Any, TypeVar

    T = TypeVar("T")


def AllAttestationTypes(
    __func=None,  # type: Callable[..., T]
    **kwargs  # type: Any
):
    """Decorator to apply to function to add attestation_type kwarg for each attestation type."""

    def decorator(func):
        # type: (Callable[..., T]) -> Callable[..., T]

        @functools.wraps(func)
        def wrapper_use_attestationtype(*args, **kwargs):
            # type: (*Any, **Any) -> T

            for attestation_type in [
                AttestationType.SGX_ENCLAVE,
                AttestationType.OPEN_ENCLAVE,
                AttestationType.TPM,
            ]:
                func(*args, attestation_type=attestation_type, **kwargs)

        return wrapper_use_attestationtype

    return decorator if __func is None else decorator(__func)


def AllInstanceTypes(
    __func=None,  # type: Callable[..., T]
    include_shared=True,  # type: bool
    **kwargs  # type: Any
):
    """Decorator to apply to function to add instance_url kwarg for each instance type."""

    def decorator(func):
        # type: (Callable[..., T]) -> Callable[..., T]

        @functools.wraps(func)
        def wrapper_use_instance(*args, **kwargs):
            # type: (*Any, **Any) -> T

            instances = []  # type:List[str]
            instances.append(kwargs.get("attestation_aad_url"))
            instances.append(kwargs.get("attestation_isolated_url"))
            if include_shared:
                instances.append(
                    "https://shared"
                    + kwargs.get("attestation_location_short_name")
                    + "."
                    + kwargs.get("attestation_location_short_name")
                    + ".attest.azure.net"
                )

            for attestation_type in instances:
                func(*args, instance_url=attestation_type, **kwargs)

        return wrapper_use_instance

    return decorator if __func is None else decorator(__func)