|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +from __future__ import annotations |
| 19 | + |
| 20 | +from typing import TYPE_CHECKING |
| 21 | + |
| 22 | +from airflow.providers.google.cloud.links.base import BaseGoogleLink |
| 23 | + |
| 24 | +if TYPE_CHECKING: |
| 25 | + from airflow.utils.context import Context |
| 26 | + |
| 27 | +BASE_LINK = "https://console.cloud.google.com" |
| 28 | + |
| 29 | +DLP_BASE_LINK = BASE_LINK + "/security/dlp" |
| 30 | + |
| 31 | +DLP_DEIDENTIFY_TEMPLATES_LIST_LINK = ( |
| 32 | + DLP_BASE_LINK + "/landing/configuration/templates/deidentify?project={project_id}" |
| 33 | +) |
| 34 | +DLP_DEIDENTIFY_TEMPLATE_DETAILS_LINK = ( |
| 35 | + DLP_BASE_LINK |
| 36 | + + "/projects/{project_id}/locations/global/deidentifyTemplates/{template_name}?project={project_id}" |
| 37 | +) |
| 38 | + |
| 39 | +DLP_JOB_TRIGGER_LIST_LINK = DLP_BASE_LINK + "/landing/inspection/triggers?project={project_id}" |
| 40 | +DLP_JOB_TRIGGER_DETAILS_LINK = ( |
| 41 | + DLP_BASE_LINK + "/projects/{project_id}/locations/global/jobTriggers/{trigger_name}?project={project_id}" |
| 42 | +) |
| 43 | + |
| 44 | +DLP_JOBS_LIST_LINK = DLP_BASE_LINK + "/landing/inspection/jobs?project={project_id}" |
| 45 | +DLP_JOB_DETAILS_LINK = ( |
| 46 | + DLP_BASE_LINK + "/projects/{project_id}/locations/global/dlpJobs/{job_name}?project={project_id}" |
| 47 | +) |
| 48 | + |
| 49 | +DLP_INSPECT_TEMPLATES_LIST_LINK = ( |
| 50 | + DLP_BASE_LINK + "/landing/configuration/templates/inspect?project={project_id}" |
| 51 | +) |
| 52 | +DLP_INSPECT_TEMPLATE_DETAILS_LINK = ( |
| 53 | + DLP_BASE_LINK |
| 54 | + + "/projects/{project_id}/locations/global/inspectTemplates/{template_name}?project={project_id}" |
| 55 | +) |
| 56 | + |
| 57 | +DLP_INFO_TYPES_LIST_LINK = ( |
| 58 | + DLP_BASE_LINK + "/landing/configuration/infoTypes/stored?cloudshell=false&project={project_id}" |
| 59 | +) |
| 60 | +DLP_INFO_TYPE_DETAILS_LINK = ( |
| 61 | + DLP_BASE_LINK |
| 62 | + + "/projects/{project_id}/locations/global/storedInfoTypes/{info_type_name}?project={project_id}" |
| 63 | +) |
| 64 | +DLP_POSSIBLE_INFO_TYPES_LIST_LINK = ( |
| 65 | + DLP_BASE_LINK + "/landing/configuration/infoTypes/built-in?project={project_id}" |
| 66 | +) |
| 67 | + |
| 68 | + |
| 69 | +class CloudDLPDeidentifyTemplatesListLink(BaseGoogleLink): |
| 70 | + """Helper class for constructing Cloud Data Loss Prevention link""" |
| 71 | + |
| 72 | + name = "Cloud DLP Deidentify Templates List" |
| 73 | + key = "cloud_dlp_deidentify_templates_list_key" |
| 74 | + format_str = DLP_DEIDENTIFY_TEMPLATES_LIST_LINK |
| 75 | + |
| 76 | + @staticmethod |
| 77 | + def persist( |
| 78 | + context: Context, |
| 79 | + task_instance, |
| 80 | + project_id: str, |
| 81 | + ): |
| 82 | + task_instance.xcom_push( |
| 83 | + context=context, |
| 84 | + key=CloudDLPDeidentifyTemplatesListLink.key, |
| 85 | + value={ |
| 86 | + "project_id": project_id, |
| 87 | + }, |
| 88 | + ) |
| 89 | + |
| 90 | + |
| 91 | +class CloudDLPDeidentifyTemplateDetailsLink(BaseGoogleLink): |
| 92 | + """Helper class for constructing Cloud Data Loss Prevention link""" |
| 93 | + |
| 94 | + name = "Cloud DLP Deidentify Template Details" |
| 95 | + key = "cloud_dlp_deidentify_template_details_key" |
| 96 | + format_str = DLP_DEIDENTIFY_TEMPLATE_DETAILS_LINK |
| 97 | + |
| 98 | + @staticmethod |
| 99 | + def persist( |
| 100 | + context: Context, |
| 101 | + task_instance, |
| 102 | + project_id: str, |
| 103 | + template_name: str, |
| 104 | + ): |
| 105 | + task_instance.xcom_push( |
| 106 | + context=context, |
| 107 | + key=CloudDLPDeidentifyTemplateDetailsLink.key, |
| 108 | + value={ |
| 109 | + "project_id": project_id, |
| 110 | + "template_name": template_name, |
| 111 | + }, |
| 112 | + ) |
| 113 | + |
| 114 | + |
| 115 | +class CloudDLPJobTriggersListLink(BaseGoogleLink): |
| 116 | + """Helper class for constructing Cloud Data Loss Prevention link""" |
| 117 | + |
| 118 | + name = "Cloud DLP Job Triggers List" |
| 119 | + key = "cloud_dlp_job_triggers_list_key" |
| 120 | + format_str = DLP_JOB_TRIGGER_LIST_LINK |
| 121 | + |
| 122 | + @staticmethod |
| 123 | + def persist( |
| 124 | + context: Context, |
| 125 | + task_instance, |
| 126 | + project_id: str, |
| 127 | + ): |
| 128 | + task_instance.xcom_push( |
| 129 | + context=context, |
| 130 | + key=CloudDLPJobTriggersListLink.key, |
| 131 | + value={ |
| 132 | + "project_id": project_id, |
| 133 | + }, |
| 134 | + ) |
| 135 | + |
| 136 | + |
| 137 | +class CloudDLPJobTriggerDetailsLink(BaseGoogleLink): |
| 138 | + """Helper class for constructing Cloud Data Loss Prevention link""" |
| 139 | + |
| 140 | + name = "Cloud DLP Job Triggers Details" |
| 141 | + key = "cloud_dlp_job_trigger_details_key" |
| 142 | + format_str = DLP_JOB_TRIGGER_DETAILS_LINK |
| 143 | + |
| 144 | + @staticmethod |
| 145 | + def persist( |
| 146 | + context: Context, |
| 147 | + task_instance, |
| 148 | + project_id: str, |
| 149 | + trigger_name: str, |
| 150 | + ): |
| 151 | + task_instance.xcom_push( |
| 152 | + context=context, |
| 153 | + key=CloudDLPJobTriggerDetailsLink.key, |
| 154 | + value={ |
| 155 | + "project_id": project_id, |
| 156 | + "trigger_name": trigger_name, |
| 157 | + }, |
| 158 | + ) |
| 159 | + |
| 160 | + |
| 161 | +class CloudDLPJobsListLink(BaseGoogleLink): |
| 162 | + """Helper class for constructing Cloud Data Loss Prevention link""" |
| 163 | + |
| 164 | + name = "Cloud DLP Jobs List" |
| 165 | + key = "cloud_dlp_jobs_list_key" |
| 166 | + format_str = DLP_JOBS_LIST_LINK |
| 167 | + |
| 168 | + @staticmethod |
| 169 | + def persist( |
| 170 | + context: Context, |
| 171 | + task_instance, |
| 172 | + project_id: str, |
| 173 | + ): |
| 174 | + task_instance.xcom_push( |
| 175 | + context=context, |
| 176 | + key=CloudDLPJobsListLink.key, |
| 177 | + value={ |
| 178 | + "project_id": project_id, |
| 179 | + }, |
| 180 | + ) |
| 181 | + |
| 182 | + |
| 183 | +class CloudDLPJobDetailsLink(BaseGoogleLink): |
| 184 | + """Helper class for constructing Cloud Data Loss Prevention link""" |
| 185 | + |
| 186 | + name = "Cloud DLP Job Details" |
| 187 | + key = "cloud_dlp_job_details_key" |
| 188 | + format_str = DLP_JOB_DETAILS_LINK |
| 189 | + |
| 190 | + @staticmethod |
| 191 | + def persist( |
| 192 | + context: Context, |
| 193 | + task_instance, |
| 194 | + project_id: str, |
| 195 | + job_name: str, |
| 196 | + ): |
| 197 | + task_instance.xcom_push( |
| 198 | + context=context, |
| 199 | + key=CloudDLPJobDetailsLink.key, |
| 200 | + value={ |
| 201 | + "project_id": project_id, |
| 202 | + "job_name": job_name, |
| 203 | + }, |
| 204 | + ) |
| 205 | + |
| 206 | + |
| 207 | +class CloudDLPInspectTemplatesListLink(BaseGoogleLink): |
| 208 | + """Helper class for constructing Cloud Data Loss Prevention link""" |
| 209 | + |
| 210 | + name = "Cloud DLP Inspect Templates List" |
| 211 | + key = "cloud_dlp_inspect_templates_list_key" |
| 212 | + format_str = DLP_INSPECT_TEMPLATES_LIST_LINK |
| 213 | + |
| 214 | + @staticmethod |
| 215 | + def persist( |
| 216 | + context: Context, |
| 217 | + task_instance, |
| 218 | + project_id: str, |
| 219 | + ): |
| 220 | + task_instance.xcom_push( |
| 221 | + context=context, |
| 222 | + key=CloudDLPInspectTemplatesListLink.key, |
| 223 | + value={ |
| 224 | + "project_id": project_id, |
| 225 | + }, |
| 226 | + ) |
| 227 | + |
| 228 | + |
| 229 | +class CloudDLPInspectTemplateDetailsLink(BaseGoogleLink): |
| 230 | + """Helper class for constructing Cloud Data Loss Prevention link""" |
| 231 | + |
| 232 | + name = "Cloud DLP Inspect Template Details" |
| 233 | + key = "cloud_dlp_inspect_template_details_key" |
| 234 | + format_str = DLP_INSPECT_TEMPLATE_DETAILS_LINK |
| 235 | + |
| 236 | + @staticmethod |
| 237 | + def persist( |
| 238 | + context: Context, |
| 239 | + task_instance, |
| 240 | + project_id: str, |
| 241 | + template_name: str, |
| 242 | + ): |
| 243 | + task_instance.xcom_push( |
| 244 | + context=context, |
| 245 | + key=CloudDLPInspectTemplateDetailsLink.key, |
| 246 | + value={ |
| 247 | + "project_id": project_id, |
| 248 | + "template_name": template_name, |
| 249 | + }, |
| 250 | + ) |
| 251 | + |
| 252 | + |
| 253 | +class CloudDLPInfoTypesListLink(BaseGoogleLink): |
| 254 | + """Helper class for constructing Cloud Data Loss Prevention link""" |
| 255 | + |
| 256 | + name = "Cloud DLP Info Types List" |
| 257 | + key = "cloud_dlp_info_types_list_key" |
| 258 | + format_str = DLP_INFO_TYPES_LIST_LINK |
| 259 | + |
| 260 | + @staticmethod |
| 261 | + def persist( |
| 262 | + context: Context, |
| 263 | + task_instance, |
| 264 | + project_id: str, |
| 265 | + ): |
| 266 | + task_instance.xcom_push( |
| 267 | + context=context, |
| 268 | + key=CloudDLPInfoTypesListLink.key, |
| 269 | + value={ |
| 270 | + "project_id": project_id, |
| 271 | + }, |
| 272 | + ) |
| 273 | + |
| 274 | + |
| 275 | +class CloudDLPInfoTypeDetailsLink(BaseGoogleLink): |
| 276 | + """Helper class for constructing Cloud Data Loss Prevention link""" |
| 277 | + |
| 278 | + name = "Cloud DLP Info Type Details" |
| 279 | + key = "cloud_dlp_info_type_details_key" |
| 280 | + format_str = DLP_INFO_TYPE_DETAILS_LINK |
| 281 | + |
| 282 | + @staticmethod |
| 283 | + def persist( |
| 284 | + context: Context, |
| 285 | + task_instance, |
| 286 | + project_id: str, |
| 287 | + info_type_name: str, |
| 288 | + ): |
| 289 | + task_instance.xcom_push( |
| 290 | + context=context, |
| 291 | + key=CloudDLPInfoTypeDetailsLink.key, |
| 292 | + value={ |
| 293 | + "project_id": project_id, |
| 294 | + "info_type_name": info_type_name, |
| 295 | + }, |
| 296 | + ) |
| 297 | + |
| 298 | + |
| 299 | +class CloudDLPPossibleInfoTypesListLink(BaseGoogleLink): |
| 300 | + """Helper class for constructing Cloud Data Loss Prevention link""" |
| 301 | + |
| 302 | + name = "Cloud DLP Possible Info Types List" |
| 303 | + key = "cloud_dlp_possible_info_types_list_key" |
| 304 | + format_str = DLP_POSSIBLE_INFO_TYPES_LIST_LINK |
| 305 | + |
| 306 | + @staticmethod |
| 307 | + def persist( |
| 308 | + context: Context, |
| 309 | + task_instance, |
| 310 | + project_id: str, |
| 311 | + ): |
| 312 | + task_instance.xcom_push( |
| 313 | + context=context, |
| 314 | + key=CloudDLPPossibleInfoTypesListLink.key, |
| 315 | + value={ |
| 316 | + "project_id": project_id, |
| 317 | + }, |
| 318 | + ) |
0 commit comments