src/wiotp/sdk/application/config.py
def parseEnvVars():
    """
    Parse environment variables into a Python dictionary suitable for passing to the 
    device client constructor as the `options` parameter

    - `WIOTP_IDENTITY_APPID`
    - `WIOTP_AUTH_KEY`
    - `WIOTP_AUTH_TOKEN`
    - `WIOTP_OPTIONS_DOMAIN` (optional)
    - `WIOTP_OPTIONS_LOGLEVEL` (optional)
    - `WIOTP_OPTIONS_MQTT_PORT` (optional)
    - `WIOTP_OPTIONS_MQTT_TRANSPORT` (optional)
    - `WIOTP_OPTIONS_MQTT_CAFILE` (optional)
    - `WIOTP_OPTIONS_MQTT_CLEANSTART` (optional)
    - `WIOTP_OPTIONS_MQTT_SESSIONEXPIRY` (optional)
    - `WIOTP_OPTIONS_MQTT_KEEPALIVE` (optional)
    - `WIOTP_OPTIONS_MQTT_SHAREDSUBSCRIPTION` (optional)
    - `WIOTP_OPTIONS_HTTP_VERIFY` (optional)
    """

    # Auth
    authKey = os.getenv("WIOTP_AUTH_KEY", None)
    authToken = os.getenv("WIOTP_AUTH_TOKEN", None)

    # Also support WIOTP_API_KEY / WIOTP_API_TOKEN usage
    if authKey is None and authToken is None:
        authKey = os.getenv("WIOTP_API_KEY", None)
        authToken = os.getenv("WIOTP_API_TOKEN", None)

    # Identity
    appId = os.getenv("WIOTP_IDENTITY_APPID", str(uuid.uuid4()))
    # Options
    domain = os.getenv("WIOTP_OPTIONS_DOMAIN", None)
    logLevel = os.getenv("WIOTP_OPTIONS_LOGLEVEL", "info")
    port = os.getenv("WIOTP_OPTIONS_MQTT_PORT", None)
    transport = os.getenv("WIOTP_OPTIONS_MQTT_TRANSPORT", None)
    caFile = os.getenv("WIOTP_OPTIONS_MQTT_CAFILE", None)
    cleanStart = os.getenv("WIOTP_OPTIONS_MQTT_CLEANSTART", "True")
    sessionExpiry = os.getenv("WIOTP_OPTIONS_MQTT_SESSIONEXPIRY", "3600")
    keepAlive = os.getenv("WIOTP_OPTIONS_MQTT_KEEPALIVE", "60")
    sharedSubs = os.getenv("WIOTP_OPTIONS_MQTT_SHAREDSUBSCRIPTION", "False")
    verifyCert = os.getenv("WIOTP_OPTIONS_HTTP_VERIFY", "True")

    if port is not None:
        try:
            port = int(port)
        except ValueError as e:
            raise ConfigurationException("WIOTP_PORT must be a number")

    try:
        sessionExpiry = int(sessionExpiry)
    except ValueError as e:
        raise ConfigurationException("WIOTP_OPTIONS_MQTT_SESSIONEXPIRY must be a number")

    try:
        keepAlive = int(keepAlive)
    except ValueError as e:
        raise ConfigurationException("WIOTP_OPTIONS_MQTT_KEEPAIVE must be a number")

    if logLevel not in ["error", "warning", "info", "debug"]:
        raise ConfigurationException("WIOTP_OPTIONS_LOGLEVEL must be one of error, warning, info, debug")
    else:
        # Convert log levels from string to int (we need to upper case our strings from the config)
        logLevel = logging.getLevelName(logLevel.upper())

    cfg = {
        "identity": {"appId": appId},
        "options": {
            "domain": domain,
            "logLevel": logLevel,
            "mqtt": {
                "port": port,
                "transport": transport,
                "cleanStart": cleanStart in ["True", "true", "1"],
                "sessionExpiry": sessionExpiry,
                "keepAlive": keepAlive,
                "sharedSubscription": sharedSubs in ["True", "true", "1"],
                "caFile": caFile,
            },
            "http": {"verify": verifyCert in ["True", "true", "1"]},
        },
    }

    # Quickstart doesn't support auth, so ensure we only add this if it's defined
    if authToken is not None:
        cfg["auth"] = {"key": authKey, "token": authToken}

    return cfg
def parseEnvVars():
    """
    Parse environment variables into a Python dictionary suitable for passing to the 
    device client constructor as the `options` parameter

    - `WIOTP_IDENTITY_APPID`
    - `WIOTP_AUTH_KEY`
    - `WIOTP_AUTH_TOKEN`
    - `WIOTP_OPTIONS_DOMAIN` (optional)
    - `WIOTP_OPTIONS_LOGLEVEL` (optional)
    - `WIOTP_OPTIONS_MQTT_PORT` (optional)
    - `WIOTP_OPTIONS_MQTT_TRANSPORT` (optional)
    - `WIOTP_OPTIONS_MQTT_CAFILE` (optional)
    - `WIOTP_OPTIONS_MQTT_CLEANSTART` (optional)
    - `WIOTP_OPTIONS_MQTT_SESSIONEXPIRY` (optional)
    - `WIOTP_OPTIONS_MQTT_KEEPALIVE` (optional)
    - `WIOTP_OPTIONS_MQTT_SHAREDSUBSCRIPTION` (optional)
    - `WIOTP_OPTIONS_HTTP_VERIFY` (optional)
    """

    # Auth
    authKey = os.getenv("WIOTP_AUTH_KEY", None)
    authToken = os.getenv("WIOTP_AUTH_TOKEN", None)

    # Also support WIOTP_API_KEY / WIOTP_API_TOKEN usage
    if authKey is None and authToken is None:
        authKey = os.getenv("WIOTP_API_KEY", None)
        authToken = os.getenv("WIOTP_API_TOKEN", None)

    # Identity
    appId = os.getenv("WIOTP_IDENTITY_APPID", str(uuid.uuid4()))
    # Options
    domain = os.getenv("WIOTP_OPTIONS_DOMAIN", None)
    logLevel = os.getenv("WIOTP_OPTIONS_LOGLEVEL", "info")
    port = os.getenv("WIOTP_OPTIONS_MQTT_PORT", None)
    transport = os.getenv("WIOTP_OPTIONS_MQTT_TRANSPORT", None)
    caFile = os.getenv("WIOTP_OPTIONS_MQTT_CAFILE", None)
    cleanStart = os.getenv("WIOTP_OPTIONS_MQTT_CLEANSTART", "True")
    sessionExpiry = os.getenv("WIOTP_OPTIONS_MQTT_SESSIONEXPIRY", "3600")
    keepAlive = os.getenv("WIOTP_OPTIONS_MQTT_KEEPALIVE", "60")
    sharedSubs = os.getenv("WIOTP_OPTIONS_MQTT_SHAREDSUBSCRIPTION", "False")
    verifyCert = os.getenv("WIOTP_OPTIONS_HTTP_VERIFY", "True")

    if port is not None:
        try:
            port = int(port)
        except ValueError as e:
            raise ConfigurationException("WIOTP_PORT must be a number")

    try:
        sessionExpiry = int(sessionExpiry)
    except ValueError as e:
        raise ConfigurationException("WIOTP_OPTIONS_MQTT_SESSIONEXPIRY must be a number")

    try:
        keepAlive = int(keepAlive)
    except ValueError as e:
        raise ConfigurationException("WIOTP_OPTIONS_MQTT_KEEPAIVE must be a number")

    if logLevel not in ["error", "warning", "info", "debug"]:
        raise ConfigurationException("WIOTP_OPTIONS_LOGLEVEL must be one of error, warning, info, debug")
    else:
        # Convert log levels from string to int (we need to upper case our strings from the config)
        logLevel = logging.getLevelName(logLevel.upper())

    cfg = {
        "identity": {"appId": appId},
        "options": {
            "domain": domain,
            "logLevel": logLevel,
            "mqtt": {
                "port": port,
                "transport": transport,
                "cleanStart": cleanStart in ["True", "true", "1"],
                "sessionExpiry": sessionExpiry,
                "keepAlive": keepAlive,
                "sharedSubscription": sharedSubs in ["True", "true", "1"],
                "caFile": caFile,
            },
            "http": {"verify": verifyCert in ["True", "true", "1"]},
        },
    }

    # Quickstart doesn't support auth, so ensure we only add this if it's defined
    if authToken is not None:
        cfg["auth"] = {"key": authKey, "token": authToken}

    return cfg
def parseEnvVars ( ) : # Auth authKey = os . getenv ( "WIOTP_AUTH_KEY" , None ) authToken = os . getenv ( "WIOTP_AUTH_TOKEN" , None ) # Also support WIOTP_API_KEY / WIOTP_API_TOKEN usage if authKey is None and authToken is None : authKey = os . getenv ( "WIOTP_API_KEY" , None ) authToken = os . getenv ( "WIOTP_API_TOKEN" , None ) # Identity appId = os . getenv ( "WIOTP_IDENTITY_APPID" , str ( uuid . uuid4 ( ) ) ) # Options domain = os . getenv ( "WIOTP_OPTIONS_DOMAIN" , None ) logLevel = os . getenv ( "WIOTP_OPTIONS_LOGLEVEL" , "info" ) port = os . getenv ( "WIOTP_OPTIONS_MQTT_PORT" , None ) transport = os . getenv ( "WIOTP_OPTIONS_MQTT_TRANSPORT" , None ) caFile = os . getenv ( "WIOTP_OPTIONS_MQTT_CAFILE" , None ) cleanStart = os . getenv ( "WIOTP_OPTIONS_MQTT_CLEANSTART" , "True" ) sessionExpiry = os . getenv ( "WIOTP_OPTIONS_MQTT_SESSIONEXPIRY" , "3600" ) keepAlive = os . getenv ( "WIOTP_OPTIONS_MQTT_KEEPALIVE" , "60" ) sharedSubs = os . getenv ( "WIOTP_OPTIONS_MQTT_SHAREDSUBSCRIPTION" , "False" ) verifyCert = os . getenv ( "WIOTP_OPTIONS_HTTP_VERIFY" , "True" ) if port is not None : try : port = int ( port ) except ValueError as e : raise ConfigurationException ( "WIOTP_PORT must be a number" ) try : sessionExpiry = int ( sessionExpiry ) except ValueError as e : raise ConfigurationException ( "WIOTP_OPTIONS_MQTT_SESSIONEXPIRY must be a number" ) try : keepAlive = int ( keepAlive ) except ValueError as e : raise ConfigurationException ( "WIOTP_OPTIONS_MQTT_KEEPAIVE must be a number" ) if logLevel not in [ "error" , "warning" , "info" , "debug" ] : raise ConfigurationException ( "WIOTP_OPTIONS_LOGLEVEL must be one of error, warning, info, debug" ) else : # Convert log levels from string to int (we need to upper case our strings from the config) logLevel = logging . getLevelName ( logLevel . upper ( ) ) cfg = { "identity" : { "appId" : appId } , "options" : { "domain" : domain , "logLevel" : logLevel , "mqtt" : { "port" : port , "transport" : transport , "cleanStart" : cleanStart in [ "True" , "true" , "1" ] , "sessionExpiry" : sessionExpiry , "keepAlive" : keepAlive , "sharedSubscription" : sharedSubs in [ "True" , "true" , "1" ] , "caFile" : caFile , } , "http" : { "verify" : verifyCert in [ "True" , "true" , "1" ] } , } , } # Quickstart doesn't support auth, so ensure we only add this if it's defined if authToken is not None : cfg [ "auth" ] = { "key" : authKey , "token" : authToken } return cfg
Parse environment variables into a Python dictionary suitable for passing to the 
    device client constructor as the `options` parameter

    - `WIOTP_IDENTITY_APPID`
    - `WIOTP_AUTH_KEY`
    - `WIOTP_AUTH_TOKEN`
    - `WIOTP_OPTIONS_DOMAIN` (optional)
    - `WIOTP_OPTIONS_LOGLEVEL` (optional)
    - `WIOTP_OPTIONS_MQTT_PORT` (optional)
    - `WIOTP_OPTIONS_MQTT_TRANSPORT` (optional)
    - `WIOTP_OPTIONS_MQTT_CAFILE` (optional)
    - `WIOTP_OPTIONS_MQTT_CLEANSTART` (optional)
    - `WIOTP_OPTIONS_MQTT_SESSIONEXPIRY` (optional)
    - `WIOTP_OPTIONS_MQTT_KEEPALIVE` (optional)
    - `WIOTP_OPTIONS_MQTT_SHAREDSUBSCRIPTION` (optional)
    - `WIOTP_OPTIONS_HTTP_VERIFY` (optional)
Parse environment variables into a Python dictionary suitable for passing to the device client constructor as the options parameter