projectaria-commons 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- projectaria_commons/__init__.py +28 -0
- projectaria_commons/commons/__init__.py +15 -0
- projectaria_commons/commons/config.py +231 -0
- projectaria_commons/commons/constants.py +63 -0
- projectaria_commons/commons/http_helper.py +254 -0
- projectaria_commons/commons/request_helper.py +141 -0
- projectaria_commons/commons/types.py +21 -0
- projectaria_commons-0.1.0.dist-info/METADATA +28 -0
- projectaria_commons-0.1.0.dist-info/RECORD +12 -0
- projectaria_commons-0.1.0.dist-info/WHEEL +5 -0
- projectaria_commons-0.1.0.dist-info/licenses/LICENSE +201 -0
- projectaria_commons-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
# pyre-strict
|
|
16
|
+
|
|
17
|
+
from projectaria_commons.commons.config import Config
|
|
18
|
+
from projectaria_commons.commons.http_helper import HttpHelper, retry
|
|
19
|
+
from projectaria_commons.commons.request_helper import RequestHelper
|
|
20
|
+
from projectaria_commons.commons.types import GraphQLError
|
|
21
|
+
|
|
22
|
+
__all__ = [
|
|
23
|
+
"Config",
|
|
24
|
+
"HttpHelper",
|
|
25
|
+
"retry",
|
|
26
|
+
"RequestHelper",
|
|
27
|
+
"GraphQLError",
|
|
28
|
+
]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
# pyre-strict
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
# pyre-strict
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import logging
|
|
20
|
+
from configparser import ConfigParser
|
|
21
|
+
from datetime import datetime
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
from typing import Union
|
|
24
|
+
|
|
25
|
+
from projectaria_commons.commons.constants import (
|
|
26
|
+
CONFIG_FILE as _DEFAULT_CONFIG_FILE,
|
|
27
|
+
ConfigBoundKey,
|
|
28
|
+
ConfigKey,
|
|
29
|
+
ConfigSection,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
logger: logging.Logger = logging.getLogger(__name__)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class Config(ConfigParser):
|
|
36
|
+
"""
|
|
37
|
+
Simple class to access the config object.
|
|
38
|
+
|
|
39
|
+
Uses a singleton pattern so one instance is shared across all modules.
|
|
40
|
+
Leverages ConfigParser to parse the config file.
|
|
41
|
+
If the config file does not exist, it is created with default values.
|
|
42
|
+
Users can overwrite values by editing the config file directly.
|
|
43
|
+
|
|
44
|
+
Subclasses can override ``config_file``, ``DEFAULT_CONFIG``, and
|
|
45
|
+
``CONFIG_BOUNDS`` to customise the configuration for their application.
|
|
46
|
+
Each subclass maintains its own singleton via ``_config``.
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
_config: ConfigParser | None = None
|
|
50
|
+
|
|
51
|
+
_is_verbose: bool = False
|
|
52
|
+
|
|
53
|
+
# Process-wide logging state, stored on the base Config (not per subclass) so
|
|
54
|
+
# every Config flavor shares a single log file per application session: PAL
|
|
55
|
+
# uses this base Config directly, while the MPS CLI has its own subclass. The
|
|
56
|
+
# first class to configure logging wins; later calls reuse this handler and
|
|
57
|
+
# path.
|
|
58
|
+
_log_path: Path | None = None
|
|
59
|
+
_file_handler: logging.FileHandler | None = None
|
|
60
|
+
|
|
61
|
+
config_file: Path = _DEFAULT_CONFIG_FILE
|
|
62
|
+
|
|
63
|
+
DEFAULT_CONFIG: dict[str, dict[str, str]] = {
|
|
64
|
+
ConfigSection.DEFAULT: {
|
|
65
|
+
ConfigKey.LOG_DIR: "/tmp/logs/projectaria/ # Path to log directory",
|
|
66
|
+
},
|
|
67
|
+
ConfigSection.GRAPHQL: {
|
|
68
|
+
ConfigKey.BACKOFF: "1.5 # Backoff factor for retries",
|
|
69
|
+
ConfigKey.INTERVAL_SEC: "4 # Interval between retries in seconds",
|
|
70
|
+
ConfigKey.RETRIES: "3 # Number of times to retry a failed request",
|
|
71
|
+
},
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
CONFIG_BOUNDS: dict[str, dict[str, dict[str, Union[str, int, float]]]] = {
|
|
75
|
+
ConfigSection.GRAPHQL: {
|
|
76
|
+
ConfigKey.BACKOFF: {
|
|
77
|
+
ConfigBoundKey.TYPE: ConfigBoundKey.TYPE_FLOAT,
|
|
78
|
+
ConfigBoundKey.MIN_VALUE: 1.0,
|
|
79
|
+
ConfigBoundKey.MAX_VALUE: 10.0,
|
|
80
|
+
},
|
|
81
|
+
ConfigKey.INTERVAL_SEC: {
|
|
82
|
+
ConfigBoundKey.TYPE: ConfigBoundKey.TYPE_INT,
|
|
83
|
+
ConfigBoundKey.MIN_VALUE: 1,
|
|
84
|
+
ConfigBoundKey.MAX_VALUE: 10,
|
|
85
|
+
},
|
|
86
|
+
ConfigKey.RETRIES: {
|
|
87
|
+
ConfigBoundKey.TYPE: ConfigBoundKey.TYPE_INT,
|
|
88
|
+
ConfigBoundKey.MIN_VALUE: 0,
|
|
89
|
+
ConfigBoundKey.MAX_VALUE: 10,
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@classmethod
|
|
95
|
+
def _apply_config_limits(cls) -> None:
|
|
96
|
+
"""
|
|
97
|
+
Apply min/max value constraints from CONFIG_BOUNDS to the loaded configuration.
|
|
98
|
+
Called after all config values are loaded/merged.
|
|
99
|
+
"""
|
|
100
|
+
if cls._config is None:
|
|
101
|
+
raise ValueError("Config was not loaded yet")
|
|
102
|
+
|
|
103
|
+
for section, keys in cls.CONFIG_BOUNDS.items():
|
|
104
|
+
for key, bounds in keys.items():
|
|
105
|
+
if cls._config.has_option(section, key):
|
|
106
|
+
value_type = bounds.get(
|
|
107
|
+
ConfigBoundKey.TYPE, ConfigBoundKey.TYPE_INT
|
|
108
|
+
)
|
|
109
|
+
min_value = bounds.get(ConfigBoundKey.MIN_VALUE)
|
|
110
|
+
max_value = bounds.get(ConfigBoundKey.MAX_VALUE)
|
|
111
|
+
|
|
112
|
+
if value_type == ConfigBoundKey.TYPE_FLOAT:
|
|
113
|
+
current_value = cls._config.getfloat(section, key)
|
|
114
|
+
else:
|
|
115
|
+
current_value = cls._config.getint(section, key)
|
|
116
|
+
|
|
117
|
+
clamped_value = current_value
|
|
118
|
+
if min_value is not None and current_value < min_value:
|
|
119
|
+
logger.warning(
|
|
120
|
+
f"Config {section}.{key}={current_value} is below minimum of {min_value}. "
|
|
121
|
+
f"Using {min_value}."
|
|
122
|
+
)
|
|
123
|
+
clamped_value = min_value
|
|
124
|
+
elif max_value is not None and current_value > max_value:
|
|
125
|
+
logger.warning(
|
|
126
|
+
f"Config {section}.{key}={current_value} exceeds maximum of {max_value}. "
|
|
127
|
+
f"Using {max_value}."
|
|
128
|
+
)
|
|
129
|
+
clamped_value = max_value
|
|
130
|
+
|
|
131
|
+
if clamped_value != current_value:
|
|
132
|
+
cls._config.set(section, key, str(clamped_value))
|
|
133
|
+
|
|
134
|
+
@classmethod
|
|
135
|
+
def _configure_logging(cls) -> None:
|
|
136
|
+
"""
|
|
137
|
+
Set up file logging once per process (idempotent).
|
|
138
|
+
|
|
139
|
+
The first Config (sub)class to configure logging wins: it creates a
|
|
140
|
+
single timestamped log file and installs it on the root logger. Any later
|
|
141
|
+
call — a re-entry, or a sibling flavor (e.g. the MPS CLI's Config subclass
|
|
142
|
+
alongside PAL's use of this base Config) — reuses that same file instead
|
|
143
|
+
of creating another one and stealing the root handler via
|
|
144
|
+
``basicConfig(force=True)``. This is what keeps one application session to
|
|
145
|
+
one log file.
|
|
146
|
+
"""
|
|
147
|
+
|
|
148
|
+
if Config._file_handler is not None:
|
|
149
|
+
return
|
|
150
|
+
|
|
151
|
+
config = cls.get()
|
|
152
|
+
default_log_dir = cls.DEFAULT_CONFIG.get(ConfigSection.DEFAULT, {}).get(
|
|
153
|
+
ConfigKey.LOG_DIR, "/tmp/logs/projectaria/"
|
|
154
|
+
)
|
|
155
|
+
default_log_dir = default_log_dir.split("#")[0].strip()
|
|
156
|
+
log_dir = Path(
|
|
157
|
+
config.get(
|
|
158
|
+
ConfigSection.DEFAULT, ConfigKey.LOG_DIR, fallback=default_log_dir
|
|
159
|
+
)
|
|
160
|
+
)
|
|
161
|
+
log_dir.mkdir(parents=True, exist_ok=True)
|
|
162
|
+
log_file: Path = log_dir / f"{datetime.now().strftime('%Y-%m-%d-%H-%M-%S')}.log"
|
|
163
|
+
file_handler = logging.FileHandler(log_file)
|
|
164
|
+
handlers: list[logging.Handler] = [file_handler]
|
|
165
|
+
if cls._is_verbose:
|
|
166
|
+
handlers.append(logging.StreamHandler())
|
|
167
|
+
logging.basicConfig(
|
|
168
|
+
handlers=handlers,
|
|
169
|
+
level=logging.DEBUG,
|
|
170
|
+
format="%(asctime)s [%(process)d] [%(levelname)s] [%(filename)s:%(lineno)d] - %(message)s",
|
|
171
|
+
force=True,
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
Config._file_handler = file_handler
|
|
175
|
+
Config._log_path = log_file
|
|
176
|
+
logger.info(f"log file : {log_file}")
|
|
177
|
+
|
|
178
|
+
@classmethod
|
|
179
|
+
def get(cls) -> ConfigParser:
|
|
180
|
+
"""
|
|
181
|
+
Get the config object.
|
|
182
|
+
|
|
183
|
+
Loads the config from the path specified by ``cls.config_file``.
|
|
184
|
+
If it doesn't exist, creates it with default values.
|
|
185
|
+
If the config exists but is missing keys, adds the missing keys
|
|
186
|
+
from DEFAULT_CONFIG.
|
|
187
|
+
"""
|
|
188
|
+
if cls._config is None:
|
|
189
|
+
cls._config = ConfigParser(inline_comment_prefixes="#")
|
|
190
|
+
|
|
191
|
+
if not cls.config_file.is_file():
|
|
192
|
+
c = ConfigParser()
|
|
193
|
+
c.read_dict(cls.DEFAULT_CONFIG)
|
|
194
|
+
cls.config_file.parent.mkdir(parents=True, exist_ok=True)
|
|
195
|
+
with cls.config_file.open("w") as fd:
|
|
196
|
+
c.write(fd)
|
|
197
|
+
|
|
198
|
+
cls._config.read(cls.config_file)
|
|
199
|
+
cls._configure_logging()
|
|
200
|
+
|
|
201
|
+
for section, keys in cls.DEFAULT_CONFIG.items():
|
|
202
|
+
if section != ConfigSection.DEFAULT and not cls._config.has_section(
|
|
203
|
+
section
|
|
204
|
+
):
|
|
205
|
+
cls._config.add_section(section)
|
|
206
|
+
logger.debug(
|
|
207
|
+
f"Loaded missing config section from defaults: {section}"
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
for key, value in keys.items():
|
|
211
|
+
if not cls._config.has_option(section, key):
|
|
212
|
+
actual_value = value.split("#")[0].strip()
|
|
213
|
+
cls._config.set(section, key, actual_value)
|
|
214
|
+
logger.debug(
|
|
215
|
+
f"Loaded missing config key from defaults: {section}.{key} = {actual_value}"
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
cls._apply_config_limits()
|
|
219
|
+
|
|
220
|
+
logger.info(f"Loaded config file {cls.config_file}")
|
|
221
|
+
return cls._config
|
|
222
|
+
|
|
223
|
+
@classmethod
|
|
224
|
+
def set_is_verbose(cls, is_verbose: bool) -> None:
|
|
225
|
+
cls._is_verbose = is_verbose
|
|
226
|
+
|
|
227
|
+
@classmethod
|
|
228
|
+
def get_log_path(cls) -> Path:
|
|
229
|
+
if Config._log_path is None:
|
|
230
|
+
raise ValueError("Config was not loaded yet")
|
|
231
|
+
return Config._log_path
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
# pyre-strict
|
|
16
|
+
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Final
|
|
19
|
+
|
|
20
|
+
if Path.home() == Path("/"):
|
|
21
|
+
from tempfile import TemporaryDirectory
|
|
22
|
+
|
|
23
|
+
local_temp_dir: TemporaryDirectory = TemporaryDirectory() # pyre-ignore [24]
|
|
24
|
+
HOME_DIR: Final[Path] = Path(local_temp_dir.name)
|
|
25
|
+
else:
|
|
26
|
+
HOME_DIR: Final[Path] = Path.home()
|
|
27
|
+
|
|
28
|
+
CONFIG_DIR: Final[Path] = HOME_DIR.joinpath(".projectaria")
|
|
29
|
+
CONFIG_FILE: Final[Path] = CONFIG_DIR.joinpath("projectaria.ini")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class ConfigSection:
|
|
33
|
+
DEFAULT: str = "DEFAULT"
|
|
34
|
+
GRAPHQL: str = "GRAPHQL"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class ConfigKey:
|
|
38
|
+
LOG_DIR: str = "LOG_DIR"
|
|
39
|
+
BACKOFF: str = "BACKOFF"
|
|
40
|
+
INTERVAL_SEC: str = "INTERVAL_SEC"
|
|
41
|
+
RETRIES: str = "RETRIES"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class ConfigBoundKey:
|
|
45
|
+
TYPE: Final[str] = "TYPE"
|
|
46
|
+
TYPE_FLOAT: Final[str] = "FLOAT"
|
|
47
|
+
TYPE_INT: Final[str] = "INT"
|
|
48
|
+
MIN_VALUE: Final[str] = "MIN"
|
|
49
|
+
MAX_VALUE: Final[str] = "MAX"
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
# GraphQL keys
|
|
53
|
+
KEY_ALIAS: Final[str] = "alias"
|
|
54
|
+
KEY_AUTH_TOKEN: Final[str] = "auth_token"
|
|
55
|
+
KEY_DATA: Final[str] = "data"
|
|
56
|
+
KEY_DOC_ID: Final[str] = "doc_id"
|
|
57
|
+
KEY_FRLM_ACCOUNT_ID: Final[str] = "frlm_account_id"
|
|
58
|
+
KEY_HORIZON_PROFILES: Final[str] = "horizon_profiles"
|
|
59
|
+
KEY_ID: Final[str] = "id"
|
|
60
|
+
KEY_ME: Final[str] = "me"
|
|
61
|
+
KEY_NAME: Final[str] = "name"
|
|
62
|
+
KEY_USER: Final[str] = "user"
|
|
63
|
+
KEY_VARIABLES: Final[str] = "variables"
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
# pyre-strict
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import asyncio
|
|
20
|
+
import json
|
|
21
|
+
import logging
|
|
22
|
+
from functools import wraps
|
|
23
|
+
from typing import Any, Callable
|
|
24
|
+
|
|
25
|
+
import aiohttp
|
|
26
|
+
from aiohttp import ClientSession, ClientTimeout
|
|
27
|
+
from aiohttp.client_exceptions import ContentTypeError
|
|
28
|
+
from projectaria_commons.commons.constants import KEY_AUTH_TOKEN
|
|
29
|
+
|
|
30
|
+
logger = logging.getLogger(__name__)
|
|
31
|
+
|
|
32
|
+
_AUTHORIZATION: str = "Authorization"
|
|
33
|
+
|
|
34
|
+
_REDACTED: str = "***REDACTED***"
|
|
35
|
+
_SENSITIVE_KEY_SUBSTRINGS: tuple[str, ...] = (
|
|
36
|
+
"password",
|
|
37
|
+
"passphrase",
|
|
38
|
+
"secret",
|
|
39
|
+
"token",
|
|
40
|
+
"auth_code",
|
|
41
|
+
"device_code",
|
|
42
|
+
"contact_point",
|
|
43
|
+
"email",
|
|
44
|
+
"credential",
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _redact_sensitive(value: Any) -> Any:
|
|
49
|
+
"""
|
|
50
|
+
Recursively redact credentials/PII from request data before logging.
|
|
51
|
+
|
|
52
|
+
Any dict key whose (case-insensitive) name contains a sensitive substring
|
|
53
|
+
has its value replaced with a placeholder; nested dicts/lists (e.g. GraphQL
|
|
54
|
+
``variables``) are walked so secrets can't hide one level down. Returns a new
|
|
55
|
+
structure; the original request payload is left unmodified.
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
value: The request data to redact.
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
The redacted request data.
|
|
62
|
+
"""
|
|
63
|
+
if isinstance(value, dict):
|
|
64
|
+
return {
|
|
65
|
+
k: (
|
|
66
|
+
_REDACTED
|
|
67
|
+
if isinstance(k, str)
|
|
68
|
+
and any(s in k.lower() for s in _SENSITIVE_KEY_SUBSTRINGS)
|
|
69
|
+
else _redact_sensitive(v)
|
|
70
|
+
)
|
|
71
|
+
for k, v in value.items()
|
|
72
|
+
}
|
|
73
|
+
if isinstance(value, list):
|
|
74
|
+
return [_redact_sensitive(item) for item in value]
|
|
75
|
+
if isinstance(value, tuple):
|
|
76
|
+
return tuple(_redact_sensitive(item) for item in value)
|
|
77
|
+
return value
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def retry(
|
|
81
|
+
exceptions: list[type[Exception]] | None = None,
|
|
82
|
+
error_codes: list[int] | None = None,
|
|
83
|
+
retries: int | Callable[[], int] = 3,
|
|
84
|
+
interval: float | Callable[[], float] = 1,
|
|
85
|
+
backoff: float | Callable[[], float] = 1.5,
|
|
86
|
+
):
|
|
87
|
+
"""
|
|
88
|
+
Decorator for retrying async functions with exponential backoff.
|
|
89
|
+
|
|
90
|
+
ClientResponseError from aiohttp is treated specially and will only be retried
|
|
91
|
+
if the status code is in `error_codes`.
|
|
92
|
+
At least one of `exceptions` or `error_codes` must be provided.
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
exceptions: List of exceptions to catch
|
|
96
|
+
error_codes: List of HTTP status codes to catch
|
|
97
|
+
retries: Number of times to retry
|
|
98
|
+
interval: Interval between retries in seconds
|
|
99
|
+
backoff: Backoff multiplier
|
|
100
|
+
|
|
101
|
+
Returns:
|
|
102
|
+
Decorated function
|
|
103
|
+
|
|
104
|
+
Raises:
|
|
105
|
+
ValueError: If no exceptions or error codes are provided
|
|
106
|
+
"""
|
|
107
|
+
if not exceptions and not error_codes:
|
|
108
|
+
raise ValueError(
|
|
109
|
+
"At least one of `exceptions` or `error_codes` must be provided."
|
|
110
|
+
)
|
|
111
|
+
exceptions = list(exceptions or [])
|
|
112
|
+
if error_codes and aiohttp.ClientResponseError not in exceptions:
|
|
113
|
+
exceptions.append(aiohttp.ClientResponseError)
|
|
114
|
+
|
|
115
|
+
def decorator(func):
|
|
116
|
+
@wraps(func)
|
|
117
|
+
async def wrapper(*args, **kwargs):
|
|
118
|
+
_retries = retries() if callable(retries) else retries
|
|
119
|
+
_interval = interval() if callable(interval) else interval
|
|
120
|
+
_backoff = backoff() if callable(backoff) else backoff
|
|
121
|
+
attempts = 0
|
|
122
|
+
while True:
|
|
123
|
+
try:
|
|
124
|
+
return await func(*args, **kwargs)
|
|
125
|
+
except tuple(exceptions) as e:
|
|
126
|
+
if (
|
|
127
|
+
isinstance(e, aiohttp.ClientResponseError)
|
|
128
|
+
and error_codes
|
|
129
|
+
and e.status not in error_codes
|
|
130
|
+
):
|
|
131
|
+
logger.exception(e)
|
|
132
|
+
raise e from e
|
|
133
|
+
if attempts >= _retries:
|
|
134
|
+
logger.error(f"Maximum number of retries reached ({_retries}).")
|
|
135
|
+
raise e from e
|
|
136
|
+
logger.warning(f"Exception encountered: {e}")
|
|
137
|
+
sleep_time = _interval * (_backoff ** (attempts))
|
|
138
|
+
attempts += 1
|
|
139
|
+
logger.warning(
|
|
140
|
+
f"Retrying attempt {attempts}/{_retries} in {sleep_time} seconds..."
|
|
141
|
+
)
|
|
142
|
+
await asyncio.sleep(sleep_time)
|
|
143
|
+
|
|
144
|
+
return wrapper
|
|
145
|
+
|
|
146
|
+
return decorator
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class HttpHelper:
|
|
150
|
+
"""
|
|
151
|
+
Helper class for making async HTTP requests.
|
|
152
|
+
Provides session management and auth token injection.
|
|
153
|
+
"""
|
|
154
|
+
|
|
155
|
+
def __init__(self):
|
|
156
|
+
logger.debug("Creating http session")
|
|
157
|
+
timeout: ClientTimeout = ClientTimeout(total=None)
|
|
158
|
+
self._http_session: ClientSession = ClientSession(
|
|
159
|
+
raise_for_status=True,
|
|
160
|
+
timeout=timeout,
|
|
161
|
+
headers={"Accept-Encoding": "gzip, deflate"},
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
@property
|
|
165
|
+
def session(self) -> ClientSession:
|
|
166
|
+
return self._http_session
|
|
167
|
+
|
|
168
|
+
async def __aenter__(self) -> "HttpHelper":
|
|
169
|
+
return self
|
|
170
|
+
|
|
171
|
+
async def __aexit__(self, exc_type, exc_value, traceback) -> None:
|
|
172
|
+
"""
|
|
173
|
+
Close the HTTP session on context exit.
|
|
174
|
+
|
|
175
|
+
Args:
|
|
176
|
+
exc_type: Exception type
|
|
177
|
+
exc_value: Exception value
|
|
178
|
+
traceback: Traceback object
|
|
179
|
+
"""
|
|
180
|
+
await self.close()
|
|
181
|
+
|
|
182
|
+
async def close(self):
|
|
183
|
+
"""Close the HTTP session."""
|
|
184
|
+
logger.debug("Closing http session")
|
|
185
|
+
await self._http_session.close()
|
|
186
|
+
|
|
187
|
+
def set_auth_token(self, auth_token: str) -> None:
|
|
188
|
+
"""
|
|
189
|
+
Set the authentication token header for the HTTP session.
|
|
190
|
+
|
|
191
|
+
Args:
|
|
192
|
+
auth_token: The authentication token to set.
|
|
193
|
+
"""
|
|
194
|
+
logger.debug("Setting http session auth header")
|
|
195
|
+
self._http_session.headers[_AUTHORIZATION] = f"OAuth {auth_token}"
|
|
196
|
+
|
|
197
|
+
async def post(self, **kwargs) -> dict[str, Any]:
|
|
198
|
+
"""
|
|
199
|
+
Make a POST request. Inserts the authorization header if an auth_token is provided.
|
|
200
|
+
|
|
201
|
+
Args:
|
|
202
|
+
**kwargs: Keyword arguments to pass to the aiohttp request method.
|
|
203
|
+
|
|
204
|
+
Returns:
|
|
205
|
+
The response from the request.
|
|
206
|
+
|
|
207
|
+
Raises:
|
|
208
|
+
ClientResponseError: If the request fails.
|
|
209
|
+
"""
|
|
210
|
+
return await self._run_method("post", **kwargs)
|
|
211
|
+
|
|
212
|
+
async def get(self, **kwargs) -> dict[str, Any]:
|
|
213
|
+
"""
|
|
214
|
+
Make a GET request. Inserts the authorization header if an auth_token is provided.
|
|
215
|
+
|
|
216
|
+
Args:
|
|
217
|
+
**kwargs: Keyword arguments to pass to the aiohttp request method.
|
|
218
|
+
|
|
219
|
+
Returns:
|
|
220
|
+
The response from the request.
|
|
221
|
+
|
|
222
|
+
Raises:
|
|
223
|
+
ClientResponseError: If the request fails.
|
|
224
|
+
"""
|
|
225
|
+
return await self._run_method("get", **kwargs)
|
|
226
|
+
|
|
227
|
+
async def _run_method(self, method: str, **kwargs) -> dict[str, Any]:
|
|
228
|
+
"""
|
|
229
|
+
Helper to get/post to an endpoint and return the JSON response.
|
|
230
|
+
Inserts the authorization header if an auth_token is provided.
|
|
231
|
+
|
|
232
|
+
Args:
|
|
233
|
+
method: The HTTP method to use.
|
|
234
|
+
**kwargs: Keyword arguments to pass to the aiohttp request method.
|
|
235
|
+
|
|
236
|
+
Returns:
|
|
237
|
+
The response from the request.
|
|
238
|
+
|
|
239
|
+
Raises:
|
|
240
|
+
ClientResponseError: If the request fails.
|
|
241
|
+
"""
|
|
242
|
+
headers = kwargs.pop("headers", {})
|
|
243
|
+
if auth_token := kwargs.pop(KEY_AUTH_TOKEN, None):
|
|
244
|
+
headers[_AUTHORIZATION] = f"OAuth {auth_token}"
|
|
245
|
+
logger.debug(f"_run_method args: {_redact_sensitive(kwargs)}")
|
|
246
|
+
m = getattr(self._http_session, method)
|
|
247
|
+
async with m(headers=headers, **kwargs) as r:
|
|
248
|
+
try:
|
|
249
|
+
return await r.json()
|
|
250
|
+
except ContentTypeError:
|
|
251
|
+
return json.loads(await r.text())
|
|
252
|
+
except Exception as e:
|
|
253
|
+
logger.exception(e)
|
|
254
|
+
raise e
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
# pyre-strict
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import json
|
|
20
|
+
import logging
|
|
21
|
+
import os
|
|
22
|
+
from http import HTTPStatus
|
|
23
|
+
from typing import Any, Final
|
|
24
|
+
|
|
25
|
+
from projectaria_commons.commons.config import Config
|
|
26
|
+
from projectaria_commons.commons.constants import (
|
|
27
|
+
ConfigKey,
|
|
28
|
+
ConfigSection,
|
|
29
|
+
KEY_ALIAS,
|
|
30
|
+
KEY_DATA,
|
|
31
|
+
KEY_DOC_ID,
|
|
32
|
+
KEY_FRLM_ACCOUNT_ID,
|
|
33
|
+
KEY_HORIZON_PROFILES,
|
|
34
|
+
KEY_ID,
|
|
35
|
+
KEY_ME,
|
|
36
|
+
KEY_NAME,
|
|
37
|
+
KEY_USER,
|
|
38
|
+
KEY_VARIABLES,
|
|
39
|
+
)
|
|
40
|
+
from projectaria_commons.commons.http_helper import HttpHelper, retry
|
|
41
|
+
from projectaria_commons.commons.types import GraphQLError
|
|
42
|
+
|
|
43
|
+
logger = logging.getLogger(__name__)
|
|
44
|
+
|
|
45
|
+
_DOC_ID_QUERY_ME: Final[int] = 26147971811524376
|
|
46
|
+
_DOC_ID_QUERY_USER_NAME: Final[int] = 25777025568628651
|
|
47
|
+
|
|
48
|
+
_GQL_URL: Final[str] = os.environ.get("GQL_URL", "https://graph.oculus.com/graphql")
|
|
49
|
+
|
|
50
|
+
_HTTP_RETRY_CODES: Final[list[int]] = [
|
|
51
|
+
HTTPStatus.BAD_GATEWAY,
|
|
52
|
+
HTTPStatus.INTERNAL_SERVER_ERROR,
|
|
53
|
+
HTTPStatus.REQUEST_TIMEOUT,
|
|
54
|
+
HTTPStatus.SERVICE_UNAVAILABLE,
|
|
55
|
+
HTTPStatus.TOO_MANY_REQUESTS,
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class RequestHelper:
|
|
60
|
+
"""Generic GraphQL query helper built on HttpHelper."""
|
|
61
|
+
|
|
62
|
+
def __init__(self, http_helper: HttpHelper):
|
|
63
|
+
self._http_helper: HttpHelper = http_helper
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def http_helper(self) -> HttpHelper:
|
|
67
|
+
return self._http_helper
|
|
68
|
+
|
|
69
|
+
async def query_me(self, auth_token: str | None = None) -> str:
|
|
70
|
+
"""
|
|
71
|
+
Validate the auth token and return the user's display name.
|
|
72
|
+
|
|
73
|
+
Queries the user's alias and FRLM account ID, then resolves the
|
|
74
|
+
display name from the Horizon profile.
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
auth_token: The auth token to use for the query. If None, the
|
|
78
|
+
http session's auth token will be used.
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
The user's display name.
|
|
82
|
+
|
|
83
|
+
Raises:
|
|
84
|
+
GraphQLError: If the query fails.
|
|
85
|
+
"""
|
|
86
|
+
logger.debug("Querying me")
|
|
87
|
+
response = await self.query_graph(
|
|
88
|
+
doc_id=_DOC_ID_QUERY_ME, variables={}, auth_token=auth_token
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
user_name: str = response[KEY_DATA][KEY_ME][KEY_ALIAS]
|
|
92
|
+
frlm_account: str = response[KEY_DATA][KEY_ME][KEY_FRLM_ACCOUNT_ID]
|
|
93
|
+
|
|
94
|
+
response = await self.query_graph(
|
|
95
|
+
doc_id=_DOC_ID_QUERY_USER_NAME,
|
|
96
|
+
variables={KEY_ID: frlm_account},
|
|
97
|
+
auth_token=auth_token,
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
if response[KEY_DATA][KEY_USER]:
|
|
101
|
+
user_name = response[KEY_DATA][KEY_USER][KEY_HORIZON_PROFILES][0][KEY_NAME]
|
|
102
|
+
return user_name
|
|
103
|
+
|
|
104
|
+
@retry(
|
|
105
|
+
error_codes=_HTTP_RETRY_CODES,
|
|
106
|
+
exceptions=[GraphQLError],
|
|
107
|
+
retries=lambda: Config.get().getint(ConfigSection.GRAPHQL, ConfigKey.RETRIES),
|
|
108
|
+
interval=lambda: Config.get().getint(
|
|
109
|
+
ConfigSection.GRAPHQL, ConfigKey.INTERVAL_SEC
|
|
110
|
+
),
|
|
111
|
+
backoff=lambda: Config.get().getfloat(ConfigSection.GRAPHQL, ConfigKey.BACKOFF),
|
|
112
|
+
)
|
|
113
|
+
async def query_graph(
|
|
114
|
+
self, doc_id: int, variables: dict[str, Any] | None = None, **kwargs
|
|
115
|
+
) -> dict[str, Any]:
|
|
116
|
+
"""
|
|
117
|
+
Execute a GraphQL query.
|
|
118
|
+
|
|
119
|
+
Args:
|
|
120
|
+
doc_id: GraphQL document ID.
|
|
121
|
+
variables: Variables to be passed to the query.
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
The response from the GraphQL server.
|
|
125
|
+
|
|
126
|
+
Raises:
|
|
127
|
+
GraphQLError: If the query fails.
|
|
128
|
+
"""
|
|
129
|
+
response = await self._http_helper.post(
|
|
130
|
+
url=_GQL_URL,
|
|
131
|
+
json={
|
|
132
|
+
KEY_DOC_ID: doc_id,
|
|
133
|
+
KEY_VARIABLES: variables,
|
|
134
|
+
},
|
|
135
|
+
**kwargs,
|
|
136
|
+
)
|
|
137
|
+
logger.debug(f"GraphQL response {json.dumps(response, indent=2)}")
|
|
138
|
+
if "errors" in response:
|
|
139
|
+
logger.error(f"GraphQL errors: {response['errors']}")
|
|
140
|
+
raise GraphQLError(response["errors"])
|
|
141
|
+
return dict(response)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
# pyre-strict
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class GraphQLError(Exception):
|
|
19
|
+
"""Raised when a GraphQL query returns errors."""
|
|
20
|
+
|
|
21
|
+
pass
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: projectaria-commons
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Project Aria Common Utilities Library
|
|
5
|
+
Home-page: https://www.projectaria.com
|
|
6
|
+
Author: Meta Reality Labs Research
|
|
7
|
+
License: Apache-2.0
|
|
8
|
+
Requires-Python: >=3.9
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: aiohttp>=3.9.0
|
|
12
|
+
Dynamic: author
|
|
13
|
+
Dynamic: description
|
|
14
|
+
Dynamic: description-content-type
|
|
15
|
+
Dynamic: home-page
|
|
16
|
+
Dynamic: license
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
Dynamic: requires-dist
|
|
19
|
+
Dynamic: requires-python
|
|
20
|
+
Dynamic: summary
|
|
21
|
+
|
|
22
|
+
Shared common utilities for Project Aria tools.
|
|
23
|
+
|
|
24
|
+
Provides a small, dependency-light foundation for configuration management and
|
|
25
|
+
async HTTP / GraphQL access, shared by the Project Aria login library, the MPS
|
|
26
|
+
CLI, and Aria Studio.
|
|
27
|
+
|
|
28
|
+
For more information, visit [Project Aria](https://www.projectaria.com).
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
projectaria_commons/__init__.py,sha256=GYuj1ttWkLVqa0Qyiug9wj6NclmNZ3RQvF7LckK2Vhk,968
|
|
2
|
+
projectaria_commons/commons/__init__.py,sha256=6xZPTzPtzy-lDojjgRGorJj9GQd2pzDdlt3gzc8rgAU,614
|
|
3
|
+
projectaria_commons/commons/config.py,sha256=bdWz5acdFcmRJ9ZNdnAZn2okYbVL6SnObJao4YTV8_Y,8996
|
|
4
|
+
projectaria_commons/commons/constants.py,sha256=E5NCPOrH6zQDV4uvjewR8sCZaw3xWM2DCtlXqHNr0IE,1880
|
|
5
|
+
projectaria_commons/commons/http_helper.py,sha256=JuFIk8-yeGv3I55KDBpFo6X00LUHPY0Upf8CWrWP1wo,8292
|
|
6
|
+
projectaria_commons/commons/request_helper.py,sha256=_yDo74DLWllcy1QYZoWLUNWuZbdp33UHnPljgDv1A7c,4367
|
|
7
|
+
projectaria_commons/commons/types.py,sha256=1EjHBHXapPjvJVBVEkP7FWhTuzcEtMILjJpECZtt9-Y,711
|
|
8
|
+
projectaria_commons-0.1.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
9
|
+
projectaria_commons-0.1.0.dist-info/METADATA,sha256=XANGGVvtngutlhrCOCPVF7-T-eB7g0Bk9lU2krlEEMU,817
|
|
10
|
+
projectaria_commons-0.1.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
11
|
+
projectaria_commons-0.1.0.dist-info/top_level.txt,sha256=xr0uto86Qrk03aSEEWNLWWCWJ8qhyaIf8zYKb6XAEas,20
|
|
12
|
+
projectaria_commons-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
projectaria_commons
|