def run(event, context): load_dependency('plantuml') dot_static = '/tmp/lambdas-dependencies/plantuml/dot_static' plantuml_jar = '/tmp/lambdas-dependencies/plantuml/plantuml.jar' Process.run("chmod", ['+x', dot_static]) Process.run("chmod", ['+x', plantuml_jar]) os.environ['PLANTUML_LIMIT_SIZE'] = str( 4096 * 4) # set max with to 4 times the default (16,384) os.environ['GRAPHVIZ_DOT'] = dot_static (fd, puml_file) = tempfile.mkstemp('.puml') png_file = puml_file.replace(".puml", ".png") code = event.get('puml') Files.write(puml_file, code) subprocess.run([ 'java', '-jar', plantuml_jar, '-Xmx2512m', '-tpng', '-o', '/tmp', puml_file ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) if os.path.exists(png_file): with open(png_file, "rb") as image_file: png = base64.b64encode(image_file.read()).decode() else: png = None return {"png_base64": png}
def setup_tmp_web_root(payload): copy_tree('./html', web_root) cs_map_1 = web_root + '/coffee/map-1.coffee' if payload.get('coffee_script_code'): cs_code = payload.get('coffee_script_code') Files.write(cs_map_1, cs_code) if payload.get("queryStringParameters") and payload.get( "queryStringParameters").get('code'): cs_code = payload.get("queryStringParameters").get('code') Files.write(cs_map_1, cs_code) return Files.contents(cs_map_1)
def get_oauth_token(self, desired_scope): secret_data = json.loads(Secrets(self.gsuite_secret_id).value() ) # load secret from AWS Secrets store token_file = '/tmp/gmail_credential_{0}.json'.format( desired_scope ) # this is the tmp file with the token value for the desired scope if not Files.exists(token_file): # if the file does not exist if os.getenv('AWS_REGION') is not None or os.getenv( 'SYNC_SERVER' ): # check if we are running in AWS or in the sync server Files.write( token_file, secret_data['token.json'] ) # if we are, use the token.json value from the AWS secret_data else: secret_data = json.loads(Secrets( 'gsuite_token').value()) # BUG, need to refactor this credentials_file = '/tmp/gsuite_credentials.json' # file to hold the credentials.json value Files.write(credentials_file, secret_data['credentials.json'] ) # save value received from AWS into file store = file.Storage( token_file) # create a gsuite Storage object scopes = 'https://www.googleapis.com/auth/{0}'.format( desired_scope ) # full qualified name for the desired scopes flow = client.flow_from_clientsecrets( credentials_file, scopes) # create a gsuite flow object flags = argparser.parse_args( '--auth_host_name localhost --logging_level INFO'.split() ) # configure the use of a localhost server to received the oauth response run_flow( flow, store, flags ) # open browser and prompt user to follow the OAuth flow Files.delete( credentials_file ) # delete main gsuite credentials file (since we don't want it hanging around) return token_file # return file with token credentials
def __enter__(self): Files.write(self.file_path, self.html) return self
def __enter__(self): Files.write(self.file_path, self.contents) return self
def save(self, path): Files.write(path, self.puml) return self