示例#1
0
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")
示例#2
0
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)
示例#3
0
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")
示例#4
0
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))
示例#5
0
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}"
        )
示例#6
0
def get(obj, key):
    """Retrieve value against given key."""
    api = lib.get_api(**obj)
    lib.pretty_print(api.get_config(key), "json")
示例#7
0
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)
示例#8
0
def show(obj):
    """Show entire configuration."""
    api = lib.get_api(**obj)
    lib.pretty_print(api.get_all_config(), "json")
示例#9
0
def whoami(obj):
    """Print information about current owner of token."""
    api = lib.get_api(**obj)
    lib.pretty_print(api.whoami(), "toml")