Skip to content

Latest commit

 

History

History
123 lines (73 loc) · 2.91 KB

cli_utils.md

File metadata and controls

123 lines (73 loc) · 2.91 KB

libraries.RW.CLI.cli_utils

verify_rsp

def verify_rsp(rsp: platform.ShellServiceResponse,
               expected_rsp_statuscodes: list[int] = [200],
               expected_rsp_returncodes: list[int] = [0],
               contains_stderr_ok: bool = True) -> None

Utility method to verify the ShellServieResponse is in the desired state and raise exceptions if not.

Arguments:

  • rsp platform.ShellServiceResponse - the rsp to verify
  • expected_rsp_statuscodes list[int], optional - the http response code returned by the process/shell service API, not the same as the bash return code. Defaults to [200].
  • expected_rsp_returncodes list[int], optional - the shell return code. Defaults to [0].
  • contains_stderr_ok bool, optional - if the presence of stderr is considered to be OK. This is expect for many CLI tools. Defaults to True.

Raises:

  • ValueError - indicates the presence of an undesired value in the response object

from_json

def from_json(json_str: str)

Wrapper keyword for json loads

Arguments:

  • json_str str - json string blob

Returns:

  • any - the loaded json object

to_json

def to_json(json_data: any)

Wrapper keyword for json dumps

Arguments:

  • json_data any - json data

Returns:

  • str - the str representation of the json blob

filter_by_time

def filter_by_time(list_data: list,
                   field_name: str,
                   operand: str = "filter_older_than",
                   duration_str: str = "30m")

Utility keyword to iterate through a list of dictionaries and remove list entries where the specified key datetime is older than the given duration string.

Arguments:

  • list_data list - list of dictionaries to filter
  • field_name str - what key to use for comparisons
  • operand str, optional - Defaults to "filter_older_than".
  • duration_str str, optional - Duration string in the form of 3d2h1s. Defaults to "30m".

Returns:

  • _type_ - description

escape_str_for_exec

def escape_str_for_exec(string: str, escapes: int = 1) -> str

Simple helper method to escape specific characters that cause issues in the pod exec passthrough

Arguments:

  • string str - original string for exec passthrough

Returns:

  • str - string with triple escaped quotes for passthrough

IssueCheckResults Objects

@dataclass
class IssueCheckResults()

Used to keep function signatures from getting too busy when passing issue data around.