UserSession class - Platform - BlueCat Gateway - 23.1

Gateway Administration Guide

Locale
English
Product name
BlueCat Gateway
Version
23.1

class bluecat.gateway.sessions.UserSession(username, api, unique_name='', *, bam_api=None, platform=None)

The structure made available to workflows for the currently logged-in user. It provides details about the BAM

Instances of this class are created automatically by the platform. It is not expected for a workflow to instantiate the class.

property bam_api

The structure for accessing the already authenticated BlueCat Address Manager API clients, provided by the platform. The values are populated depending on the configured BAM API version.

Example:

from bluecat import route
from bluecat_libraries.address_manager.api import Client as V1Client
from bluecat_libraries.address_manager.apiv2 import Client as V2Client
from flask import g, jsonify

def get_servers_v1(client: V1Client):
    # Implement using BAM REST v1 API
    data = client.get_entities(<configuration_id>, ObjectType.SERVER)
    # process data
    return data

def get_servers_v2(client: V2Client):
    # Implement using BAM REST v2 API
    data = client.http_get("/servers", ...)
    # process data
    return data

@route(app, "/example/servers"
def get_servers():
    if g.user.bam_api.v2:
        data = get_servers_v2(g.user.bam_api.v2)
    else:
        data = get_servers_v1(g.user.bam_api.v1)
    return jsonify(data)

Return type: BAMAPI

New in version 23.1.0.

property bam_url

The base URL to the BlueCat Address Manager the session is for.

It contains only the scheme, host, and (if explicitly specified in the configuration) port.

Return type: str

New in version 23.1.0.

property bam_version

The version of the BlueCat Address Manager the session is for.

Return type: Version

New in version 23.1.0.

get_api()

Get the object-oriented client to BlueCat Address Manager REST v1 API, provided by the platform. The client is already authenticated for the user, whom the session is for.

Return type: API

property logger

A logger that can be used to log messages which will have a context value unique to this user session. This is useful when identifying or tracing a user’s activities in logs.

Note:

In practice, this is a LoggerAdapter. As such it has a slightly more limited interface than a full-fledged logging.Logger. Do not (attempt to) change its logging level.

Return type: LoggerAdapter

property logger_context

A value included in the log messages made via the logger of this user session. It is unique to this user session as it derives from the username and the session. This is useful when identifying or tracing a user’s activities in logs.

Return type: str

property session_auth

The authentication value identifying this user session in Gateway.

This property does not support assignment.

Return type: str

property username

The username of the currently logged-in user.

This property does not support assignment.

Return type: str