( connection: string, )
| 284 | * @param connection String to be validated. |
| 285 | */ |
| 286 | export function validateConnectionFormat( |
| 287 | connection: string, |
| 288 | ) { |
| 289 | // Connection pattern of the form project.location.connection_id. Example: |
| 290 | // my-project.us-central1.my-connection |
| 291 | const dotPattern = /^[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+$/; |
| 292 | |
| 293 | // Connection pattern of the form projects/<substring>/locations/<substring>/connections/<substring> |
| 294 | // Example: projects/my-project/locations/us-central1/connections/my-connection |
| 295 | // Substrings cannot contain '/'. |
| 296 | const resourcePattern = |
| 297 | /^projects\/[^/]+\/locations\/[^/]+\/connections\/[^/]+$/; |
| 298 | |
| 299 | const isValidFormat = |
| 300 | dotPattern.test(connection) || resourcePattern.test(connection); |
| 301 | |
| 302 | if (connection !== 'DEFAULT' && !isValidFormat) { |
| 303 | throw new Error( |
| 304 | 'The connection must be in the format `{project}.{location}.{connection_id}` or `projects/{project}/locations/{location}/connections/{connection_id}`, or be set to `DEFAULT`.', |
| 305 | ); |
| 306 | } |
| 307 | |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * Checks if the storageUri is a valid GCS path. |
no test coverage detected