This function takes JSON data as an input, uses the json and yaml modules to convert JSON data to YAML and then returns with the YAML. Deploy the function, as a Python 3.7 runtime, pasting the following code into the code field:
-
-
Google Cloud Function to convert YAML to a plist
TLDR: The GCF at https://github.com/krypted/tinyconverters/blob/main/GCF_YAML_to_PLIST.py will convert basic YAML to PLISTs. Here’s a Google Cloud Function that converts YAML to a property list. The function takes the YAML data as an event object, uses the yaml and plistlib modules to convert the YAML data to a property list, and returns the property list. To deploy this function, use the “Create Function” button in the Google Cloud Console. When prompted, select the Python 3.7 runtime and paste in the following script: Once the function is deployed, call it with a POST request to the function’s URL and include the YAML data. For example: Given the above input, the response body will…
-
Google Cloud Function To Add JSON To A Cloud SQL Database
Here’s a Google Cloud Function that takes some arbitrary json (in json_data) and posts it to a new record in a Cloud SQL database. No error handling or deduplication/matching, just a straight post: https://github.com/krypted/tinyconverters/blob/548892cc377e1063770ab4a8cd53dc6573bae950/json_to_cloud_SQL.py Before using, it needs information to connect to the database, so customize the INSTANCE_NAME, DATABASE_NAME, and TABLE_NAME for the INSERT. For more on Cloud SQL, see https://cloud.google.com/sql/docs.
-
Google Cloud Function To Add JSON To A Google Sheet
Here’s a Google Cloud Function that uses the Google Sheets API to add arbitrary json to a Google Sheet: https://github.com/krypted/tinyconverters/blob/main/json_to_GoogleSheet.py To use the function, create a Google Cloud project and enable the Google Sheets API. Then create a service account and download the JSON key file for that account and place it in the same directory as the script. Once the Cloud Function is deployed, a request similar to the following will add the nested JSON data to the spreadsheet with the ID for that sheet swapped in with spreadsheetId in the below `curl`: This allows us to pipeline information in a variety of ways, like a web hook that…
-
Google Cloud Function To Check Status Of A Port
Sometimes you just need a little microservice to check that a port is up before you try and send some data to it. This does just that… https://github.com/krypted/NestMonitor/blob/main/socket%20check.py
-
Google Cloud Function To Encrypt A JSON Document With An ECC Key
To use this function, create a Google Cloud Function that uses the encrypt_json() function in Google Cloud Console or the gcloud command-line tool. Once created the function, invoke it by sending a POST request to the function’s URL. The request body should contain the JSON document to encrypt. The response body will contain the encrypted JSON document. For example, to encrypt the JSON document my_data.json, you would use the following command: The response body will contain the encrypted JSON document. This function uses the Google Cloud KMS service to encrypt the JSON document. So make sure there’s a KMS key enabled in a project before using the function.
-
Setup Google Cloud Functions
Google Cloud Functions provide a streamlined method for running a simple micro-service leveraging custom functions as well as SDKs for any Google service that can be imported into your script. Currently, node.js is the only non-beta language you can build scripts in. Permissions Before you setup Google Cloud Functions in your G Suite domain, first provide the account of a developer with the appropriate permissions, identified in the attached screen. Enable The SDKs You Need G Suite has a number of features exposed to their API by importing SDKs into projects. As an example, the Admin SDK provides us with endpoints and classes that make developing micro services to perform…