Utils
oaaclient
utility functions.
Copyright 2022 Veza Technologies Inc.
Use of this source code is governed by the MIT license that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
helper functions commonly used by OAA integrations
function log_arg_error
log_arg_error
Helper function for logging errors when loading parameters
Helper function used to create consistent messages in connectors when required parameters can be set at command line or as environment variables.
Message can include information on parameter and/or environment variable but must provide one.
Args:
log
(object): logging facility object to log toarg
(str, optional): Command line option for parameter such as--veza-url
. Defaults to None.env
(str, optional): OS Environment variable for parameter such asVEZA_URL
. Defaults to None.
Raises:
Exception
: if neitherarg
orenv
are supplied
function load_json_from_file
load_json_from_file
Load JSON from file
Args:
json_path
(str): path to JSON file on disk
Raises:
Exception
: Unable to process JSONException
: Error reading JSON file
Returns:
dict
: JSON decoded to dictionary
function encode_icon_file
encode_icon_file
read an icon file to a base64 encoded string
Args:
icon_path
(str): Path to icon file on disk
Returns:
str
: base64 encoding of file
function exists_in_query_array
exists_in_query_array
function build_report
build_report
Creates or updates a Veza report from a dictionary
Creates a report and containing queries from a dictionary definition. Function will create any queries it does not find based on name. If a query with the same name already exists the existing query will be added to the report.
If a report already exists with the same name any missing queries will be added to the report.
report_definition
must be a dictionary with name
for the report and queries
list of Veza query definitions:
{"name": "My Report", "queries": [{..},{...}]}
Args:
veza_con
(OAAClient): OAAClient connection to make Veza API callsreport_definition
(dict): Report definition
Raises:
ValueError
: Missing name or queries key
Returns:
dict
: API response from Report creation or update
function truncate_string
truncate_string
Helper function to truncate strings
Helper function to truncate strings to conform to maximum length requirements for templates.
Returns a string that is the first N bytes of the source string
Args:
source_str
(str): Source string to truncatelength
(int, optional): Length to shorten to. Defaults to 256.
Returns:
str
: truncated string
Last updated