| 106 | |
| 107 | |
| 108 | def load_data( |
| 109 | platform: str, |
| 110 | default: str | None = None, |
| 111 | sample_name: str | None = None, |
| 112 | timestamp=None, |
| 113 | start_timestamp=None, |
| 114 | trace: str | None = None, |
| 115 | span_id: str | None = None, |
| 116 | spans=None, |
| 117 | trace_context=None, |
| 118 | fingerprint=None, |
| 119 | event_id=None, |
| 120 | ): |
| 121 | # NOTE: Before editing this data, make sure you understand the context |
| 122 | # in which its being used. It is NOT only used for local development and |
| 123 | # has production consequences. |
| 124 | # * bin/load-mocks to generate fake data for local testing |
| 125 | # * When a new project is created, a fake event is generated as a "starter" |
| 126 | # event so it's not an empty project. |
| 127 | # * When a user clicks Test Configuration from notification plugin settings page, |
| 128 | # a fake event is generated to go through the pipeline. |
| 129 | data = None |
| 130 | language = None |
| 131 | platform_data = INTEGRATION_ID_TO_PLATFORM_DATA.get(platform) |
| 132 | |
| 133 | if platform_data is not None and platform_data["type"] != "language": |
| 134 | language = platform_data["language"] |
| 135 | |
| 136 | samples_root = os.path.join(DATA_ROOT, "samples") |
| 137 | |
| 138 | # this loop will try to load the specified platform first, but if we do not |
| 139 | # have a specific sample for it, we then move on to the `language`, then the `default`. |
| 140 | # The `default` is set to `javascript` in ./src/sentry/api/endpoints/project_create_sample.py |
| 141 | # on the `ProjectCreateSampleEndpoint` |
| 142 | for sample in (platform, language, default): |
| 143 | if not sample: |
| 144 | continue |
| 145 | |
| 146 | # Verify the requested path is valid and disallow path traversal attempts |
| 147 | json_file = f"{sample}.json" |
| 148 | |
| 149 | expected_commonpath = os.path.realpath( |
| 150 | samples_root |
| 151 | ) # .realpath() ensures symlinks are handled |
| 152 | json_path = os.path.join(samples_root, json_file) |
| 153 | json_real_path = os.path.realpath(json_path) |
| 154 | |
| 155 | if expected_commonpath != os.path.commonpath([expected_commonpath, json_real_path]): |
| 156 | raise SuspiciousFileOperation("potential path traversal attack detected") |
| 157 | |
| 158 | # the requested `sample` does not exist, so continue through to the next iteration |
| 159 | if not os.path.exists(json_path): |
| 160 | continue |
| 161 | |
| 162 | if not os.path.isfile(json_path): |
| 163 | raise IsADirectoryError("expected file but found a directory instead") |
| 164 | |
| 165 | if not sample_name: |