コード例 #1
0
ファイル: runtime_config_test.py プロジェクト: rtamalin/kiwi
    def test_config_sections_from_home_base_config(self, mock_Cli):
        cli = Mock()
        cli.get_global_args.return_value = {}
        mock_Cli.return_value = cli
        with patch.dict('os.environ', {'HOME': '../data/kiwi_config/ok'}):
            runtime_config = RuntimeConfig(reread=True)

        assert runtime_config.get_xz_options() == ['-a', '-b', 'xxx']
        assert runtime_config.is_obs_public() is True
        assert runtime_config.get_bundle_compression() is True
        assert runtime_config.get_obs_download_server_url() == \
            'http://example.com'
        assert runtime_config.get_obs_api_server_url() == \
            'https://api.example.com'
        assert runtime_config.get_container_compression() is None
        assert runtime_config.get_iso_tool_category() == 'cdrtools'
        assert runtime_config.get_oci_archive_tool() == 'umoci'
        assert runtime_config.get_package_changes() is True
        assert runtime_config.get_disabled_runtime_checks() == [
            'check_dracut_module_for_oem_install_in_package_list',
            'check_container_tool_chain_installed'
        ]
        assert runtime_config.get_obs_api_credentials() == [{
            'user_name':
            'user_credentials'
        }]
コード例 #2
0
    def __init__(self,
                 image_path: str,
                 ssl_verify: bool = True,
                 user: Optional[str] = None,
                 password: Optional[str] = None):
        """
        Initialize OBS API access for a given project and package

        :param str image_path: OBS project/package path
        :param str user: OBS account user name
        :param str password: OBS account password
        """
        runtime_config = RuntimeConfig()
        try:
            (self.project, self.package) = image_path.split(os.sep)
        except ValueError:
            raise KiwiOBSPluginProjectError(
                f'Invalid image path: {image_path}')
        if not password:
            for credentials in runtime_config.get_obs_api_credentials() or []:
                if not user:
                    # Use first user/credentials from config
                    (user, password) = list(credentials.items())[0]
                    break
                elif user in credentials:
                    # Use credentials for given user
                    password = credentials.get(user)
                    break
        if not user:
            raise KiwiOBSPluginCredentialsError(
                'No username to access the Open Build Service provided')
        if not password:
            credentials_interactive = Credentials()
            password = credentials_interactive.get_obs_credentials(user)
        self.user = user
        self.password = password
        self.api_server = runtime_config.get_obs_api_server_url()
        self.ssl_verify = ssl_verify or True