MCPcopy Create free account
hub / github.com/dataform-co/dataform / validateConnectionFormat

Function validateConnectionFormat

core/utils.ts:286–308  ·  view source on GitHub ↗
(
  connection: string,
)

Source from the content-addressed store, hash-verified

284 * @param connection String to be validated.
285 */
286export 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.

Callers 4

utils_test.tsFile · 0.90
compileMethod · 0.90
compileMethod · 0.90
promptForIcebergConfigFunction · 0.90

Calls 1

testMethod · 0.80

Tested by

no test coverage detected