> For the complete documentation index, see [llms.txt](https://docs.veza.com/4yItIzMvkpAvMVFAamTf/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.veza.com/4yItIzMvkpAvMVFAamTf/developers/api/oaa/python-sdk/oaaclient-modules/utils.md).

# 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

***

## <kbd>function</kbd> `log_arg_error`

```python
log_arg_error(log: object, arg: str = None, env: str = None) → None
```

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 to
* `arg` (str, optional): Command line option for parameter such as `--veza-url`. Defaults to None.
* `env` (str, optional): OS Environment variable for parameter such as `VEZA_URL`. Defaults to None.

**Raises:**

* `Exception`: if neither `arg` or `env` are supplied

***

## <kbd>function</kbd> `load_json_from_file`

```python
load_json_from_file(json_path: str) → dict
```

Load JSON from file

**Args:**

* `json_path` (str): path to JSON file on disk

**Raises:**

* `Exception`: Unable to process JSON
* `Exception`: Error reading JSON file

**Returns:**

* `dict`: JSON decoded to dictionary

***

## <kbd>function</kbd> `encode_icon_file`

```python
encode_icon_file(icon_path: str) → str
```

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

***

## <kbd>function</kbd> `exists_in_query_array`

```python
exists_in_query_array(value_to_find, input_array) → bool
```

***

## <kbd>function</kbd> `build_report`

```python
build_report(veza_con, report_definition: dict) → dict
```

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 calls
* `report_definition` (dict): Report definition

**Raises:**

* `ValueError`: Missing name or queries key

**Returns:**

* `dict`: API response from Report creation or update

***

## <kbd>function</kbd> `truncate_string`

```python
truncate_string(source_str: str, length: int = 256) → str
```

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 truncate
* `length` (int, optional): Length to shorten to. Defaults to 256.

**Returns:**

* `str`: truncated string


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.veza.com/4yItIzMvkpAvMVFAamTf/developers/api/oaa/python-sdk/oaaclient-modules/utils.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
