Exemple #1
0
def _load_key_file(config):

    updated_config = {}
    export_id = config['exports'].get('service_id')
    export_key = config['exports'].get('service_key')
    if not (export_id and export_key):
        export_key_file = parse_config_file(config['exports']['key_file'])
        if export_key_file:
            updated_config.update({
                'exports': {
                    'service_id': export_key_file['service_id'],
                    'service_key': export_key_file['service_key'],
                }
            })

    auth_username = config['auth'].get('username')
    auth_password = config['auth'].get('password')
    if not (auth_username and auth_password):
        key_file = parse_config_file(config['auth']['key_file'])
        if key_file:
            updated_config.update({
                'auth': {
                    'username': key_file['service_id'],
                    'password': key_file['service_key'],
                }
            })
    return updated_config
Exemple #2
0
    def _add_client(self, source_config):
        logger.debug('Instanciating a new confd client for %s',
                     source_config['uuid'])
        auth_config = dict(source_config['auth'])
        if auth_config.get('key_file'):
            # File must be readable by wazo-dird
            key_file = parse_config_file(auth_config.pop('key_file'))
            if not key_file:
                logger.info('failed to load key file for source %s',
                            source_config['name'])
                return
            auth_config['username'] = key_file['service_id']
            auth_config['password'] = key_file['service_key']
        auth_client = AuthClient(**auth_config)
        token_renewer = TokenRenewer(auth_client)

        confd_config = source_config['confd']
        logger.debug('confd config %s', confd_config)
        client = ConfdClient(**confd_config)
        client.set_tenant(source_config['tenant_uuid'])

        token_renewer.subscribe_to_token_change(client.set_token)
        token_renewer.start()

        self._clients[source_config['uuid']] = RegisteredClient(
            client, token_renewer)
Exemple #3
0
def complete():
    database_uri = get_database_uri_from_config()

    if os.path.exists(CLI_CONFIG_FILENAME):
        # NOTE(sileht): Allow custom username/password or reuse previous one
        wazo_auth_cli_config = parse_config_file(CLI_CONFIG_FILENAME)
        create_initial_user(
            database_uri,
            wazo_auth_cli_config["auth"]["username"],
            wazo_auth_cli_config["auth"]["password"],
            PURPOSE,
            DEFAULT_POLICY_NAME,
        )
    else:
        password = random_string(28)
        create_initial_user(
            database_uri, USERNAME, password, PURPOSE, DEFAULT_POLICY_NAME
        )

        try:
            os.makedirs(CLI_CONFIG_DIR)
        except FileExistsError:
            pass

        cli_config = CLI_CONFIG.format(USERNAME, password)
        write_private_file(CLI_CONFIG_FILENAME, USER, cli_config)
Exemple #4
0
 def configured_wazo_auth(cls):
     # NOTE(sileht): This creates a tenant tree and associated users
     key_file = parse_config_file(
         os.path.join(cls.assets_root, "keys", "wazo-webhookd-key.yml")
     )
     auth = cls.make_auth()
     auth.set_valid_credentials(
         MockCredentials(key_file['service_id'], key_file['service_key']),
         MASTER_TOKEN,
     )
     auth.set_token(
         MockUserToken(
             MASTER_TOKEN,
             MASTER_USER_UUID,
             WAZO_UUID,
             {"tenant_uuid": MASTER_TENANT, "uuid": MASTER_USER_UUID},
         )
     )
     auth.set_token(
         MockUserToken(
             USER_1_TOKEN,
             USER_1_UUID,
             WAZO_UUID,
             {"tenant_uuid": USERS_TENANT, "uuid": USER_1_UUID},
         )
     )
     auth.set_token(
         MockUserToken(
             USER_2_TOKEN,
             USER_2_UUID,
             WAZO_UUID,
             {"tenant_uuid": USERS_TENANT, "uuid": USER_2_UUID},
         )
     )
     auth.set_token(
         MockUserToken(
             OTHER_USER_TOKEN,
             OTHER_USER_UUID,
             WAZO_UUID,
             {"tenant_uuid": OTHER_TENANT, "uuid": OTHER_USER_UUID},
         )
     )
     auth.set_tenants(
         {
             'uuid': MASTER_TENANT,
             'name': 'webhookd-tests-master',
             'parent_uuid': MASTER_TENANT,
         },
         {
             'uuid': USERS_TENANT,
             'name': 'webhookd-tests-users',
             'parent_uuid': MASTER_TENANT,
         },
         {
             'uuid': OTHER_TENANT,
             'name': 'webhookd-tests-other',
             'parent_uuid': MASTER_TENANT,
         },
     )
def _load_key_file(config):
    key_file = parse_config_file(config['auth']['key_file'])
    return {
        'auth': {
            'username': key_file['service_id'],
            'password': key_file['service_key']
        },
    }
def _load_key_file(config):
    key_file = parse_config_file(config['auth']['key_file'])
    return {
        'auth': {
            'service_id': key_file['service_id'],
            'service_key': key_file['service_key']
        }
    }
Exemple #7
0
def _load_key_file(config):
    if config['auth'].get('username') and config['auth'].get('password'):
        return {}

    key_file = parse_config_file(config['auth']['key_file'])
    return {
        'auth': {
            'username': key_file['service_id'],
            'password': key_file['service_key'],
        }
    }
Exemple #8
0
def _load_key_file(config):
    filename = config.get('auth', {}).get('key_file')
    if not filename:
        return {}

    key_file = parse_config_file(filename)
    if not key_file:
        return {}

    return {
        'auth': {
            'username': key_file['service_id'],
            'password': key_file['service_key']
        }
    }
Exemple #9
0
    def configure_wazo_auth(cls):
        key_file = parse_config_file(
            os.path.join(cls.assets_root, 'auth_keys', 'wazo-phoned-key.yml'))
        mock_auth = cls.make_mock_auth()
        mock_auth.set_valid_credentials(
            MockCredentials(key_file['service_id'], key_file['service_key']),
            MASTER_TOKEN,
        )
        mock_auth.set_token(
            MockUserToken(
                MASTER_TOKEN,
                MASTER_USER_UUID,
                WAZO_UUID,
                {
                    'tenant_uuid': MASTER_TENANT,
                    'uuid': MASTER_USER_UUID
                },
            ))
        mock_auth.set_token(
            MockUserToken(
                USER_1_TOKEN,
                USER_1_UUID,
                WAZO_UUID,
                {
                    'tenant_uuid': USERS_TENANT,
                    'uuid': USER_1_UUID
                },
            ))

        mock_auth.set_tenants(
            {
                'uuid': MASTER_TENANT,
                'name': 'phoned-tests-master',
                'parent_uuid': MASTER_TENANT,
            },
            {
                'uuid': USERS_TENANT,
                'name': 'phoned-tests-users',
                'parent_uuid': MASTER_TENANT,
            },
        )

        auth = cls.make_auth()
        auth.users.new(
            uuid=USER_1_UUID,
            tenant_uuid=USERS_TENANT,
        )
Exemple #10
0
if args:
    _CONFIG['provd']['host'] = args[0]
if opts.port is not None:
    _CONFIG['provd']['port'] = int(opts.port)
if opts.prefix is not None:
    _CONFIG['provd']['prefix'] = int(opts.prefix)
if opts.https is not None:
    _CONFIG['provd']['https'] = _bool(opts.https)
if opts.verify is not None:
    _CONFIG['provd']['verify_certificate'] = _bool(opts.verify)

# # create client object
client = cli_client.new_cli_provisioning_client(_CONFIG['provd'])

# read key from key file and setup token renewer
key_file = parse_config_file(_CONFIG['auth'].pop('key_file'))
auth_client = AuthClient(username=key_file['service_id'], password=key_file['service_key'], **_CONFIG['auth'])
token_renewer = TokenRenewer(auth_client, expiration=600)
token_renewer.subscribe_to_token_change(client.prov_client.set_token)


configs = client.configs()
devices = client.devices()
plugins = client.plugins()
parameters = client.parameters()


# create help
RAW_HELP_MAP = {
    None: """\
\x1b[1mDescription\x1b[0m
Exemple #11
0
def _load_key_file(config):
    key_file = parse_config_file(config['auth']['key_file'])
    return {'auth': {'username': key_file['service_id'],
                     'password': key_file['service_key']}}