|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
| 15 | +from planet_auth_utils.builtins import Builtins |
15 | 16 |
|
16 |
| -class EnvironmentVariables: |
17 |
| - """ |
18 |
| - Environment Variables used in the planet_auth_utils packages |
19 |
| - """ |
20 |
| - |
21 |
| - AUTH_API_KEY = "PL_API_KEY" |
22 |
| - """ |
23 |
| - A literal Planet API key. |
24 |
| - """ |
25 |
| - |
26 |
| - AUTH_CLIENT_ID = "PL_AUTH_CLIENT_ID" |
27 |
| - """ |
28 |
| - Client ID for an OAuth service account |
29 |
| - """ |
30 |
| - |
31 |
| - AUTH_CLIENT_SECRET = "PL_AUTH_CLIENT_SECRET" |
32 |
| - """ |
33 |
| - Client Secret for an OAuth service account |
34 |
| - """ |
35 |
| - |
36 |
| - AUTH_EXTRA = "PL_AUTH_EXTRA" |
37 |
| - """ |
38 |
| - List of extra options. Values should be formatted as <key>=<value>. |
39 |
| - Multiple options should be whitespace delimited. |
40 |
| - """ |
41 |
| - |
42 |
| - AUTH_PROFILE = "PL_AUTH_PROFILE" |
43 |
| - """ |
44 |
| - Name of a profile to use for auth client configuration. |
45 |
| - """ |
46 |
| - |
47 |
| - AUTH_TOKEN = "PL_AUTH_TOKEN" |
48 |
| - """ |
49 |
| - Literal token string. |
50 |
| - """ |
51 | 17 |
|
52 |
| - AUTH_TOKEN_FILE = "PL_AUTH_TOKEN_FILE" |
53 |
| - """ |
54 |
| - File path to use for storing tokens. |
55 |
| - """ |
56 |
| - |
57 |
| - AUTH_ISSUER = "PL_AUTH_ISSUER" |
58 |
| - """ |
59 |
| - Issuer to use when requesting or validating OAuth tokens. |
60 |
| - """ |
61 |
| - |
62 |
| - AUTH_AUDIENCE = "PL_AUTH_AUDIENCE" |
63 |
| - """ |
64 |
| - Audience to use when requesting or validating OAuth tokens. |
65 |
| - """ |
66 |
| - |
67 |
| - AUTH_ORGANIZATION = "PL_AUTH_ORGANIZATION" |
68 |
| - """ |
69 |
| - Organization to use when performing client authentication. |
70 |
| - Only used for some authentication mechanisms. |
71 |
| - """ |
| 18 | +class classproperty(object): |
| 19 | + def __init__(self, method=None): |
| 20 | + self.fget = method |
72 | 21 |
|
73 |
| - AUTH_PROJECT = "PL_AUTH_PROJECT" |
74 |
| - """ |
75 |
| - Project ID to use when performing authentication. |
76 |
| - Not all implementations understand this option. |
77 |
| - """ |
| 22 | + def __get__(self, instance, cls=None): |
| 23 | + return self.fget(cls) |
78 | 24 |
|
79 |
| - AUTH_PASSWORD = "PL_AUTH_PASSWORD" |
80 |
| - """ |
81 |
| - Password to use when performing client authentication. |
82 |
| - Only used for some authentication mechanisms. |
83 |
| - """ |
84 | 25 |
|
85 |
| - AUTH_SCOPE = "PL_AUTH_SCOPE" |
86 |
| - """ |
87 |
| - List of scopes to request when requesting OAuth tokens. |
88 |
| - Multiple scopes should be whitespace delimited. |
89 |
| - """ |
90 |
| - |
91 |
| - AUTH_USERNAME = "PL_AUTH_USERNAME" |
| 26 | +class EnvironmentVariables: |
92 | 27 | """
|
93 |
| - Username to use when performing client authentication. |
94 |
| - Only used for some authentication mechanisms. |
| 28 | + Environment Variables used in the planet_auth_utils packages |
95 | 29 | """
|
96 | 30 |
|
97 |
| - AUTH_LOGLEVEL = "PL_LOGLEVEL" |
98 |
| - """ |
99 |
| - Specify the log level. |
100 |
| - """ |
| 31 | + @staticmethod |
| 32 | + def _namespace_variable(undecorated_variable: str): |
| 33 | + """ |
| 34 | + Decorate the variable name with a namespace. |
| 35 | + This is done so that multiple applications may use |
| 36 | + the Planet auth library without conflicting. |
| 37 | + """ |
| 38 | + |
| 39 | + namespace = Builtins.namespace() |
| 40 | + if namespace: |
| 41 | + return f"{namespace.upper()}_{undecorated_variable}" |
| 42 | + return undecorated_variable |
| 43 | + |
| 44 | + @classproperty |
| 45 | + def AUTH_API_KEY(cls): # pylint: disable=no-self-argument |
| 46 | + """ |
| 47 | + A literal Planet API key. |
| 48 | + """ |
| 49 | + return cls._namespace_variable("PL_API_KEY") |
| 50 | + |
| 51 | + @classproperty |
| 52 | + def AUTH_CLIENT_ID(cls): # pylint: disable=no-self-argument |
| 53 | + """ |
| 54 | + Client ID for an OAuth service account |
| 55 | + """ |
| 56 | + # traceback.print_stack(file=sys.stdout) |
| 57 | + return cls._namespace_variable("PL_AUTH_CLIENT_ID") |
| 58 | + |
| 59 | + @classproperty |
| 60 | + def AUTH_CLIENT_SECRET(cls): # pylint: disable=no-self-argument |
| 61 | + """ |
| 62 | + Client Secret for an OAuth service account |
| 63 | + """ |
| 64 | + return cls._namespace_variable("PL_AUTH_CLIENT_SECRET") |
| 65 | + |
| 66 | + @classproperty |
| 67 | + def AUTH_EXTRA(cls): # pylint: disable=no-self-argument |
| 68 | + """ |
| 69 | + List of extra options. Values should be formatted as <key>=<value>. |
| 70 | + Multiple options should be whitespace delimited. |
| 71 | + """ |
| 72 | + return cls._namespace_variable("PL_AUTH_EXTRA") |
| 73 | + |
| 74 | + @classproperty |
| 75 | + def AUTH_PROFILE(cls): # pylint: disable=no-self-argument |
| 76 | + """ |
| 77 | + Name of a profile to use for auth client configuration. |
| 78 | + """ |
| 79 | + return cls._namespace_variable("PL_AUTH_PROFILE") |
| 80 | + |
| 81 | + @classproperty |
| 82 | + def AUTH_TOKEN(cls): # pylint: disable=no-self-argument |
| 83 | + """ |
| 84 | + Literal token string. |
| 85 | + """ |
| 86 | + return cls._namespace_variable("PL_AUTH_TOKEN") |
| 87 | + |
| 88 | + @classproperty |
| 89 | + def AUTH_TOKEN_FILE(cls): # pylint: disable=no-self-argument |
| 90 | + """ |
| 91 | + File path to use for storing tokens. |
| 92 | + """ |
| 93 | + return cls._namespace_variable("PL_AUTH_TOKEN_FILE") |
| 94 | + |
| 95 | + @classproperty |
| 96 | + def AUTH_ISSUER(cls): # pylint: disable=no-self-argument |
| 97 | + """ |
| 98 | + Issuer to use when requesting or validating OAuth tokens. |
| 99 | + """ |
| 100 | + return cls._namespace_variable("PL_AUTH_ISSUER") |
| 101 | + |
| 102 | + @classproperty |
| 103 | + def AUTH_AUDIENCE(cls): # pylint: disable=no-self-argument |
| 104 | + """ |
| 105 | + Audience to use when requesting or validating OAuth tokens. |
| 106 | + """ |
| 107 | + return cls._namespace_variable("PL_AUTH_AUDIENCE") |
| 108 | + |
| 109 | + @classproperty |
| 110 | + def AUTH_ORGANIZATION(cls): # pylint: disable=no-self-argument |
| 111 | + """ |
| 112 | + Organization to use when performing client authentication. |
| 113 | + Only used for some authentication mechanisms. |
| 114 | + """ |
| 115 | + return cls._namespace_variable("PL_AUTH_ORGANIZATION") |
| 116 | + |
| 117 | + @classproperty |
| 118 | + def AUTH_PROJECT(cls): # pylint: disable=no-self-argument |
| 119 | + """ |
| 120 | + Project ID to use when performing authentication. |
| 121 | + Not all implementations understand this option. |
| 122 | + """ |
| 123 | + return cls._namespace_variable("PL_AUTH_PROJECT") |
| 124 | + |
| 125 | + @classproperty |
| 126 | + def AUTH_PASSWORD(cls): # pylint: disable=no-self-argument |
| 127 | + """ |
| 128 | + Password to use when performing client authentication. |
| 129 | + Only used for some authentication mechanisms. |
| 130 | + """ |
| 131 | + return cls._namespace_variable("PL_AUTH_PASSWORD") |
| 132 | + |
| 133 | + @classproperty |
| 134 | + def AUTH_SCOPE(cls): # pylint: disable=no-self-argument |
| 135 | + """ |
| 136 | + List of scopes to request when requesting OAuth tokens. |
| 137 | + Multiple scopes should be whitespace delimited. |
| 138 | + """ |
| 139 | + return cls._namespace_variable("PL_AUTH_SCOPE") |
| 140 | + |
| 141 | + @classproperty |
| 142 | + def AUTH_USERNAME(cls): # pylint: disable=no-self-argument |
| 143 | + """ |
| 144 | + Username to use when performing client authentication. |
| 145 | + Only used for some authentication mechanisms. |
| 146 | + """ |
| 147 | + return cls._namespace_variable("PL_AUTH_USERNAME") |
| 148 | + |
| 149 | + @classproperty |
| 150 | + def AUTH_LOGLEVEL(cls): # pylint: disable=no-self-argument |
| 151 | + """ |
| 152 | + Specify the log level. |
| 153 | + """ |
| 154 | + return cls._namespace_variable("PL_LOGLEVEL") |
0 commit comments