GoogleCloudPlatform/node-red-contrib-google-cloud

ProjectID determination from GCE environment for BigQuery node ...

kolban-google opened this issue · 2 comments

The BigQuery node needs a projectId. This is specified (today) in the configuration of the node. If Node-RED runs on GCP then we can determine an implied value. This issue asks for the coding/enhancement to support this idea.

The mechanics for determination of the environment in which Node-RED is running (including its projectId) is achieved by performing a REST call to the GCE metadata server. A REST call is, by definition, an asynchronous operation in JavaScript. What this means is that node constructor will ideally want to:

node_constructor() {
   if (we have no statically configured projectId) {
      projectId = await getMetaDataProjectId()
   }
   .... rest of code
}

However, we now have a puzzle. This is a node constructor which is called to create an instance of the node. There is no indication that it can be an async function. It is a strong possibility that when the function is called, it is expected to create a new node synchronously. If that is the case and it returns with a promise ... it may break downstream as Node-RED may assume that the node is ready for work ... when it isn't. A question has been posed in the Node-RED slack channel.

The solution turned out to be extremely easy in the end. The BigQuery client APIs take no supply of a projectId as semantics to use the default. The solution was thus to not make a project id mandatory.

Delivered as part of 0.0.15