def get(obj, key): """Retrieve value against given key.""" api = lib.get_api(**obj) value = lib.resilient_call( api.get_config, key, description=f"api.get_config({key})", idempotent=True ) lib.pretty_print(value, "json")
def save(obj, output): """Save entire configuration to given file.""" api = lib.get_api(**obj) config = lib.resilient_call( api.get_all_config, description="api.get_all_config()", idempotent=True ) lib.pretty_print(config, "json", output=output)
def show(obj): """Show entire configuration.""" api = lib.get_api(**obj) config = lib.resilient_call( api.get_all_config, description="api.get_all_config()", idempotent=True ) lib.pretty_print(config, "json")
def _log_result(result): """Pretty-print log the result from running a task, job, or view.""" if isinstance(result, FileDownloadResponse): lib.log( f"Response saved to: {result.filename} (mime_type={result.mime_type})" ) else: try: # Try to pretty print if it converts to JSON. lib.pretty_print(result, "json") except json.decoder.JSONDecodeError: # Otherwise print normally. lib.log_output(str(result))
def export_users_and_roles(obj, filename, with_roles): """Export users (and roles) to given TOML file.""" filename = Path(filename) api = lib.get_api(**obj) export_data = {} export_data["users"] = api.get_all_users() if with_roles: export_data["roles"] = api.get_all_roles() with filename.open(mode="w") as f: lib.pretty_print(export_data, "toml", f) lib.log_output( f"Exported {len(export_data['users'])} users and {len(export_data.get('roles', []))} roles to {filename}" )
def get(obj, key): """Retrieve value against given key.""" api = lib.get_api(**obj) lib.pretty_print(api.get_config(key), "json")
def save(obj, output): """Save entire configuration to given file.""" api = lib.get_api(**obj) lib.pretty_print(api.get_all_config(), "json", output=output)
def show(obj): """Show entire configuration.""" api = lib.get_api(**obj) lib.pretty_print(api.get_all_config(), "json")
def whoami(obj): """Print information about current owner of token.""" api = lib.get_api(**obj) lib.pretty_print(api.whoami(), "toml")