def __init__(self): user_folder = conan_expand_user("~") server_folder = os.path.join(user_folder, '.conan_server') server_config = migrate_and_get_server_config(user_folder) custom_auth = server_config.custom_authenticator if custom_auth: authenticator = load_authentication_plugin(server_folder, custom_auth) else: authenticator = BasicAuthenticator(dict(server_config.users)) authorizer = BasicAuthorizer(server_config.read_permissions, server_config.write_permissions) credentials_manager = JWTCredentialsManager( server_config.jwt_secret, server_config.jwt_expire_time) updown_auth_manager = JWTUpDownAuthManager( server_config.updown_secret, server_config.authorize_timeout) file_manager = get_file_manager( server_config, updown_auth_manager=updown_auth_manager) search_adapter = DiskSearchAdapter() search_manager = DiskSearchManager( SimplePaths(server_config.disk_storage_path), search_adapter) server_capabilities = SERVER_CAPABILITIES self.ra = ConanServer(server_config.port, credentials_manager, updown_auth_manager, authorizer, authenticator, file_manager, search_manager, Version(SERVER_VERSION), Version(MIN_CLIENT_COMPATIBLE_VERSION), server_capabilities)
def setUp(self): self.conan_reference = ConanFileReference.loads("openssl/2.0.3@lasote/testing") self.package_reference = PackageReference(self.conan_reference, "123123123") self.tmp_dir = temp_folder() read_perms = [("*/*@*/*", "*")] write_perms = [] authorizer = BasicAuthorizer(read_perms, write_perms) self.fake_url = "http://url" updown_auth_manager = JWTUpDownAuthManager("secret", timedelta(seconds=200)) adapter = ServerDiskAdapter(self.fake_url, self.tmp_dir, updown_auth_manager) self.paths = SimplePaths(self.tmp_dir) self.file_manager = FileManager(self.paths, adapter) search_adapter = DiskSearchAdapter() self.search_manager = DiskSearchManager(self.paths, search_adapter) self.service = ConanService(authorizer, self.file_manager, "lasote") self.search_service = SearchService(authorizer, self.search_manager, "lasote") files = hello_source_files("test") save_files(self.paths.export(self.conan_reference), files) self.conan_digest = FileTreeManifest.create(self.paths.export(self.conan_reference)) conan_digest_path = os.path.join(self.paths.export(self.conan_reference), CONAN_MANIFEST) save(conan_digest_path, str(self.conan_digest)) files = hello_source_files("package") save_files(self.paths.package(self.package_reference), files)
def setUp(self): folder = temp_folder() paths = SimplePaths(folder) search_adapter = DiskSearchAdapter() self.search_manager = DiskSearchManager(paths, search_adapter) os.chdir(paths.store) self.paths = paths
def __init__(self, base_folder=None, current_folder=None, servers=None, users=None, client_version=CLIENT_VERSION, min_server_compatible_version=MIN_SERVER_COMPATIBLE_VERSION, requester_class=None, runner=None, path_with_spaces=True): """ storage_folder: Local storage path current_folder: Current execution folder servers: dict of {remote_name: TestServer} logins is a list of (user, password) for auto input in order if required==> [("lasote", "mypass"), ("other", "otherpass")] """ self.all_output = "" # For debugging purpose, append all the run outputs self.users = users or { "default": [(TESTING_REMOTE_PRIVATE_USER, TESTING_REMOTE_PRIVATE_PASS)] } self.servers = servers or {} self.client_version = Version(str(client_version)) self.min_server_compatible_version = Version( str(min_server_compatible_version)) self.base_folder = base_folder or temp_folder(path_with_spaces) # Define storage_folder, if not, it will be read from conf file & pointed to real user home self.storage_folder = os.path.join(self.base_folder, ".conan", "data") self.client_cache = ClientCache(self.base_folder, self.storage_folder, TestBufferConanOutput()) search_adapter = DiskSearchAdapter() self.search_manager = DiskSearchManager(self.client_cache, search_adapter) self._default_settings(get_env("CONAN_COMPILER", "gcc"), get_env("CONAN_COMPILER_VERSION", "4.8"), get_env("CONAN_LIBCXX", "libstdc++")) self.requester_class = requester_class self.conan_runner = runner self.init_dynamic_vars() save(self.client_cache.registry, "") registry = RemoteRegistry(self.client_cache.registry, TestBufferConanOutput()) for name, server in self.servers.items(): if isinstance(server, TestServer): registry.add(name, server.fake_url) else: registry.add(name, server) logger.debug("Client storage = %s" % self.storage_folder) self.current_folder = current_folder or temp_folder(path_with_spaces)
def factory(): """Factory""" def instance_remote_manager(client_cache): requester = get_basic_requester(client_cache) # Verify client version against remotes version_checker_req = VersionCheckerRequester( requester, Version(client_version), Version(MIN_SERVER_COMPATIBLE_VERSION), out) # To handle remote connections put_headers = client_cache.read_put_headers() rest_api_client = RestApiClient(out, requester=version_checker_req, put_headers=put_headers) # To store user and token localdb = LocalDB(client_cache.localdb) # Wraps RestApiClient to add authentication support (same interface) auth_manager = ConanApiAuthManager(rest_api_client, user_io, localdb) # Handle remote connections remote_manager = RemoteManager(client_cache, auth_manager, out) return remote_manager use_color = get_env("CONAN_COLOR_DISPLAY", 1) if use_color and hasattr(sys.stdout, "isatty") and sys.stdout.isatty(): import colorama colorama.init() color = True else: color = False out = ConanOutput(sys.stdout, color) user_io = UserIO(out=out) try: client_cache = migrate_and_get_client_cache( get_conan_user_home(), out) except Exception as e: out.error(str(e)) raise with tools.environment_append(client_cache.conan_config.env_vars): # Adjust CONAN_LOGGING_LEVEL with the env readed conans.util.log.logger = configure_logger() # Get the new command instance after migrations have been done remote_manager = instance_remote_manager(client_cache) # Get a search manager search_adapter = DiskSearchAdapter() search_manager = DiskSearchManager(client_cache, search_adapter) # Settings preprocessor conan = Conan(client_cache, user_io, get_conan_runner(), remote_manager, search_manager, settings_preprocessor) return conan, client_cache, user_io
def __init__(self, base_folder=None, current_folder=None, servers=None, users=None, client_version=CLIENT_VERSION, min_server_compatible_version=MIN_SERVER_COMPATIBLE_VERSION, requester_class=None, runner=None, path_with_spaces=True, default_profile=True): """ storage_folder: Local storage path current_folder: Current execution folder servers: dict of {remote_name: TestServer} logins is a list of (user, password) for auto input in order if required==> [("lasote", "mypass"), ("other", "otherpass")] """ self.all_output = "" # For debugging purpose, append all the run outputs self.users = users or { "default": [(TESTING_REMOTE_PRIVATE_USER, TESTING_REMOTE_PRIVATE_PASS)] } self.client_version = Version(str(client_version)) self.min_server_compatible_version = Version( str(min_server_compatible_version)) self.base_folder = base_folder or temp_folder(path_with_spaces) # Define storage_folder, if not, it will be read from conf file & pointed to real user home self.storage_folder = os.path.join(self.base_folder, ".conan", "data") self.client_cache = ClientCache(self.base_folder, self.storage_folder, TestBufferConanOutput()) search_adapter = DiskSearchAdapter() self.search_manager = DiskSearchManager(self.client_cache, search_adapter) self.requester_class = requester_class self.conan_runner = runner self.update_servers(servers) self.init_dynamic_vars() logger.debug("Client storage = %s" % self.storage_folder) self.current_folder = current_folder or temp_folder(path_with_spaces) # Enforcing VS 2015, even if VS2017 is auto detected if default_profile: profile = self.client_cache.default_profile if profile.settings.get("compiler.version") == "15": profile.settings["compiler.version"] = "14" save(self.client_cache.default_profile_path, profile.dumps())
def case_insensitive_test(self): root_folder2 = "sdl/1.5/lasote/stable" conan_ref2 = ConanFileReference.loads("sdl/1.5@lasote/stable") os.makedirs("%s/%s" % (root_folder2, EXPORT_FOLDER)) root_folder3 = "assimp/0.14/phil/testing" conan_ref3 = ConanFileReference.loads("assimp/0.14@phil/testing") os.makedirs("%s/%s" % (root_folder3, EXPORT_FOLDER)) root_folder4 = "sdl/2.10/lasote/stable" conan_ref4 = ConanFileReference.loads("sdl/2.10@lasote/stable") os.makedirs("%s/%s" % (root_folder4, EXPORT_FOLDER)) root_folder5 = "SDL_fake/1.10/lasote/testing" conan_ref5 = ConanFileReference.loads("SDL_fake/1.10@lasote/testing") os.makedirs("%s/%s" % (root_folder5, EXPORT_FOLDER)) # Case insensitive searches search_adapter = DiskSearchAdapter() search_manager = DiskSearchManager(self.paths, search_adapter) reg_conans = sorted( [str(_reg) for _reg in search_manager.search_recipes("*")]) self.assertEqual(reg_conans, [ str(conan_ref5), str(conan_ref3), str(conan_ref2), str(conan_ref4) ]) reg_conans = sorted([ str(_reg) for _reg in search_manager.search_recipes(pattern="sdl*") ]) self.assertEqual(reg_conans, [str(conan_ref5), str(conan_ref2), str(conan_ref4)]) # Case sensitive search self.assertEqual( str( search_manager.search_recipes(pattern="SDL*", ignorecase=False)[0]), str(conan_ref5))
def __init__(self, base_path=None, read_permissions=None, write_permissions=None, users=None, base_url=None, plugins=None, server_version=None, min_client_compatible_version=None, server_capabilities=None): plugins = plugins or [] if not base_path: base_path = temp_folder() if server_capabilities is None: server_capabilities = SERVER_CAPABILITIES # Default enabled if not os.path.exists(base_path): raise Exception("Base path not exist! %s") # Define storage_folder, if not, it will be readed from conf file and pointed to real user home self.storage_folder = os.path.join(base_path, ".conan_server", "data") mkdir(self.storage_folder) server_config = migrate_and_get_server_config(base_path, self.storage_folder) if TestServerLauncher.port == 0: TestServerLauncher.port = server_config.port # Encode and Decode signature for Upload and Download service updown_auth_manager = JWTUpDownAuthManager( server_config.updown_secret, server_config.authorize_timeout) self.file_manager = get_file_manager( server_config, public_url=base_url, updown_auth_manager=updown_auth_manager) search_adapter = DiskSearchAdapter() self.search_manager = DiskSearchManager( SimplePaths(server_config.disk_storage_path), search_adapter) # Prepare some test users if not read_permissions: read_permissions = server_config.read_permissions read_permissions.append( ("private_library/1.0.0@private_user/testing", "*")) read_permissions.append(("*/*@*/*", "*")) if not write_permissions: write_permissions = server_config.write_permissions if not users: users = dict(server_config.users) users[TESTING_REMOTE_PRIVATE_USER] = TESTING_REMOTE_PRIVATE_PASS authorizer = BasicAuthorizer(read_permissions, write_permissions) authenticator = BasicAuthenticator(users) credentials_manager = JWTCredentialsManager( server_config.jwt_secret, server_config.jwt_expire_time) logger.debug("Storage path: %s" % self.storage_folder) self.port = TestServerLauncher.port self.ra = ConanServer(self.port, credentials_manager, updown_auth_manager, authorizer, authenticator, self.file_manager, self.search_manager, server_version, min_client_compatible_version, server_capabilities) for plugin in plugins: self.ra.api_v1.install(plugin)