Skip to main content
Version: 7 - Gugelhupf

ConnectorTypeGOOGLE

class connector_types.connector_type_google.ConnectorTypeGOOGLE

Interact with Google APIs

This connector type enables you to access any Google API. See The official Python client library for Google's discovery based APIs or The Google API Explorer for a description of available APIs and their collections and requests.

Inputs

NameTypeDefaultDescription
api_namestrThe name of the API to use
api_paramsdictNoneAdditional parameters to pass to the API build call
api_versionstrThe version of the API to use
argslistNonePositional arguments to pass to the method call
collectionstrThe collection of the API to use. Can take the form of <resource>.<subresource>[...]
encodingstrutf-8The encoding to use when binary data is returned by the server
grantstrNonethe name of an oauth grant to use for authentication
ignore_decoding_errorsboolTrueIf set, decoding errors will be ignored. Binary data which cannot be decoded into strings will be returned as bytes:base64:[base64-string].
keydictNoneThe content of the key file of the service account to use
kwargsdictNoneKeyword arguments to pass to the method call
paramsdictNoneDeprecated. Replaced by kwargs. Additional parameters to pass to the request call
requeststrThe request to use
scopeslistNoneOauth2 scopes to request

Outputs

NameTypeDefaultDescription
resultdict

Constants

input_list = ['api_name', 'api_params', 'api_version', 'args', 'collection', 'encoding', 'grant', 'ignore_decoding_errors', 'key', 'kwargs', 'params', 'request', 'scopes'] output_list = ['result'] ssl_context_inputs = ['check_hostname', 'client_cert', 'client_key', 'server_ca'] version = 1

Methods

execute

log

one_of_inputs

run

Example

import flow_api

def handler(system: flow_api.System, this: flow_api.Execution):
this.connect(
connector_type='GOOGLE',
name='launch instance',
api_name='compute',
api_version='v1',
collection='instances',
request='insert',
kwargs={
'body': instance_config,
'project': project_id,
'zone': 'europe-west3-b',
}
key=key,
scopes=['https://www.googleapis.com/auth/compute'],
)
this.log('instance was started')

return this.success('all done')

More

Media Upload

Some API methods support uploading media files. All of these methods have a parameter called media_body. Cloudomation supports uploading strings, Cloudomation file objects or base64-encoded binary data.

Uploading Strings

Use the following format for the media_body parameter:

import flow_api

def handler(system: flow_api.System, this: flow_api.Execution):
this.connect(
connector_type='GOOGLE',
name='upload a string to a cloud storage bucket',
api_name='storage',
api_version='v1',
collection='objects',
request='insert',
params={
'bucket': 'my-bucket-name',
'body': {
'name': 'the-file-name.ext'
},
'media_body': {
'string': 'the-file-content',
'mimetype': 'text/plain',
},
},
)
return this.success('all done')
Uploading Cloudomation Files

Use the following format for the media_body parameter:

import flow_api

def handler(system: flow_api.System, this: flow_api.Execution):
this.connect(
connector_type='GOOGLE',
name='upload a Cloudomation file to a cloud storage bucket',
api_name='storage',
api_version='v1',
collection='objects',
request='insert',
params={
'bucket': 'my-bucket-name',
'body': {
# The file name in the bucket can be different, it has to be set explicitely.
'name': 'the-file-name.ext'
},
'media_body': {
'file': 'the-cloudomation-file-name',
'mimetype': 'text/plain',
},
},
)
return this.success('all done')
Uploading Binary Data

Use the following format for the media_body parameter:

import flow_api

def handler(system: flow_api.System, this: flow_api.Execution):
this.connect(
connector_type='GOOGLE',
name='upload binary data to a cloud storage bucket',
api_name='storage',
api_version='v1',
collection='objects',
request='insert',
params={
'bucket': 'my-bucket-name',
'body': {
'name': 'the-file-name.bin'
},
'media_body': {
'base64': 'cmVhZGluZyB0aGlzPyBhcHBseSBub3cgYXQgaHR0cHM6Ly9jbG91ZG9tYXRpb24uY29tL2pvYnMvICE=',
'mimetype': 'application/octet-stream',
},
},
)
return this.success('all done')