Exemplo n.º 1
0
def set_configuration_value(name, value):
    """
    Sets a configuration's value
    """
    cli_configuration = CLIConfig(COMMAND_SETTINGS_DIR, COMMAND_ENV_PREFIX)

    cli_configuration.set_value(COMMAND_NAME, name, value)
Exemplo n.º 2
0
def get_config_value(name, fallback=None):
    """Gets a config by name.

    In the case where the config name is not found, will use fallback value."""

    cli_config = CLIConfig(SF_CLI_CONFIG_DIR, SF_CLI_ENV_VAR_PREFIX)
    return cli_config.get('servicefabric', name, fallback)
Exemplo n.º 3
0
def _reload_config():
    if before_2_0_64:
        cli_ctx.config.config_parser.read(GLOBAL_CONFIG_PATH)
        return cli_ctx.config
    else:
        return CLIConfig(config_dir=GLOBAL_CONFIG_DIR,
                         config_env_var_prefix=ENV_VAR_PREFIX)
Exemplo n.º 4
0
def get_configuration_value(name, fallback=None):
    """
    Gets a configuration by name, if the configuration name is not found
    the function will return the provided fallback
    """
    cli_configuration = CLIConfig(COMMAND_SETTINGS_DIR, COMMAND_ENV_PREFIX)

    return cli_configuration.get(COMMAND_NAME, name, fallback)
Exemplo n.º 5
0
def get_state_value(name, fallback=None):
    """Gets a state entry by name.

    In the case where the state entry name is not found, will use fallback value."""

    cli_config = CLIConfig(SF_CLI_STATE_DIR, SF_CLI_NAME, 'state')

    return cli_config.get('servicefabric', name, fallback)
Exemplo n.º 6
0
    def _az_config(self):
        # NOTE: ideally we would've used get_default_cli().config from
        # azure.cli.core, but azure-cli-core has a lot of conflicts with other
        # dependencies. So instead we are just use knack directly
        from knack.config import CLIConfig

        config_dir = os.getenv("AZURE_CONFIG_DIR",
                               os.path.expanduser(os.path.join("~", ".azure")))
        return CLIConfig(config_dir=config_dir, config_env_var_prefix="AZURE")
Exemplo n.º 7
0
def get_state_path():
    """
    Returns the path of where the state file of sfctl is stored.
    :return: str
    """

    # This is the same as
    # self.config_path = os.path.join(self.config_dir, CLIConfig._CONFIG_FILE_NAME)
    return CLIConfig(SF_CLI_STATE_DIR, SF_CLI_NAME, 'state').config_path
Exemplo n.º 8
0
def set_state_value(name, value):
    """
    Set a state entry with a specified a value.

    :param name: (str) name of the state
    :param value: (str) value of the state
    :return: None
    """

    cli_config = CLIConfig(SF_CLI_STATE_DIR, SF_CLI_NAME, 'state')
    cli_config.set_value('servicefabric', name, value)
Exemplo n.º 9
0
def set_config_value(name, value):
    """Set a config by name to a value."""

    cli_config = CLIConfig(SF_CLI_CONFIG_DIR, SF_CLI_ENV_VAR_PREFIX)
    cli_config.set_value('servicefabric', name, value)
Exemplo n.º 10
0
def get_config_bool(name):
    """Checks if a config value is set to a valid bool value."""

    cli_config = CLIConfig(SF_CLI_CONFIG_DIR, SF_CLI_ENV_VAR_PREFIX)
    return cli_config.getboolean('servicefabric', name, False)
Exemplo n.º 11
0
def get_azure_config():
    return CLIConfig(config_dir=get_azure_config_dir(), config_env_var_prefix='AZURE')
Exemplo n.º 12
0
def get_azdev_config():
    return CLIConfig(config_dir=get_azdev_config_dir(), config_env_var_prefix='AZDEV')
Exemplo n.º 13
0
 def setUp(self):
     self.cli_config = CLIConfig(config_dir=tempfile.mkdtemp())
Exemplo n.º 14
0
from azure.cli.command_modules.iot.mgmt_iot_hub_device.lib.iot_hub_device_client import IotHubDeviceClient
from azure.cli.command_modules.iot.mgmt_iot_hub_device.lib.models.authentication import Authentication
from azure.cli.command_modules.iot.mgmt_iot_hub_device.lib.models.device_description import DeviceDescription
from azure.cli.command_modules.iot.mgmt_iot_hub_device.lib.models.x509_thumbprint import X509Thumbprint
from azure.cli.command_modules.iot.sas_token_auth import SasTokenAuthentication
from azure.cli.core.extension import extension_exists
from azure.cli.core._environment import get_config_dir

from ._client_factory import resource_service_factory
from ._utils import create_self_signed_certificate, open_certificate

logger = get_logger(__name__)

# IoT Extension run once awareness
if not extension_exists('azure_cli_iot_ext'):
    config = CLIConfig(get_config_dir())
    ran_before = config.getboolean('iot', 'first_run', fallback=False)
    if not ran_before:
        extension_text = """
                         Comprehensive IoT data-plane functionality is available
                         in the Azure IoT CLI Extension. For more info and install guide
                         go to https://github.com/Azure/azure-iot-cli-extension
                         """
        logger.warning(extension_text)
        config.set_value('iot', 'first_run', 'yes')


# CUSTOM TYPE
class KeyType(Enum):
    primary = 'primary'
    secondary = 'secondary'
Exemplo n.º 15
0
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import os
import traceback
import json
import re
import sys
import pkginfo

from azure.cli.core._config import GLOBAL_CONFIG_DIR, ENV_VAR_PREFIX
from distutils.sysconfig import get_python_lib
from knack.config import CLIConfig
from knack.log import get_logger

az_config = CLIConfig(config_dir=GLOBAL_CONFIG_DIR,
                      config_env_var_prefix=ENV_VAR_PREFIX)
_CUSTOM_EXT_DIR = az_config.get('extension', 'dir', None)
_DEV_EXTENSION_SOURCES = az_config.get('extension', 'dev_sources', None)
EXTENSIONS_DIR = os.path.expanduser(
    _CUSTOM_EXT_DIR) if _CUSTOM_EXT_DIR else os.path.join(
        GLOBAL_CONFIG_DIR, 'cliextensions')
DEV_EXTENSION_SOURCES = _DEV_EXTENSION_SOURCES.split(
    ',') if _DEV_EXTENSION_SOURCES else []
EXTENSIONS_SYS_DIR = os.path.join(
    get_python_lib(),
    'azure-cli-extensions') if sys.platform.startswith('linux') else ""

EXTENSIONS_MOD_PREFIX = 'azext_'

WHL_METADATA_FILENAME = 'metadata.json'
EGG_INFO_METADATA_FILE_NAME = 'PKG-INFO'  # used for dev packages
Exemplo n.º 16
0
 def setUp(self):
     self.cli_config = CLIConfig(config_dir=new_temp_folder())
     # In case the previous test is stopped and doesn't clean up
     clean_local_temp_folder()
Exemplo n.º 17
0
# --------------------------------------------------------------------------------------------

import random
import os
from knack.config import CLIConfig
from azure.cli.core.commands import LongRunningOperation, _is_poller

CONFIG_DIR = os.path.expanduser(os.path.join('~', '.azext_db_up'))
ENV_VAR_PREFIX = 'AZEXT'
MYSQL_CONFIG_SECTION = 'mysql_up'
POSTGRES_CONFIG_SECTION = 'postgres_up'
CONFIG_MAP = {
    'mysql': MYSQL_CONFIG_SECTION,
    'postgres': POSTGRES_CONFIG_SECTION
}
DB_CONFIG = CLIConfig(config_dir=CONFIG_DIR,
                      config_env_var_prefix=ENV_VAR_PREFIX)


def create_random_resource_name(prefix='azure', length=15):
    append_length = length - len(prefix)
    digits = [str(random.randrange(10)) for i in range(append_length)]
    return prefix + ''.join(digits)


def get_config_value(db_type, option, fallback='_fallback_none'):
    config_section = CONFIG_MAP[db_type]
    if fallback == '_fallback_none':
        return DB_CONFIG.get(config_section, option)
    return DB_CONFIG.get(config_section, option, fallback=fallback)