def embedded(): # region embedded_example EmbeddedServer().start_server() with EmbeddedServer().get_document_store("Embedded") as store: with store.open_session() as session: # Your Code Here pass # endregion # region start_server # Start RavenDB Embedded Server with default options EmbeddedServer().start_server() # endregion # region start_server_with_options server_options = ServerOptions(data_directory="C:\\RavenData", server_url="http://127.0.0.1:8080") EmbeddedServer().start_server(server_options) # endregion # region get_document_store EmbeddedServer().get_document_store("Embedded") # endregion # region get_document_store_with_database_options database_options = DatabaseOptions(database_name="Embedded", skip_creating_database=True) EmbeddedServer().get_document_store(database_options) # endregion # region security server_options = ServerOptions() server_options.secured(certificate_path="PathToServerCertificate.pfx", certificate_password="******") # endregion # region security2 server_options_with_exec = ServerOptions() server_options_with_exec.secured_with_exec( "powershell", "C:\\secrets\\give_me_cert.ps1", Utils.get_cert_file_fingerprint("PATH_TO_PEM_CERT_FILE"), "PATH_TO_PEM_CERT_FILE") EmbeddedServer.start_server(server_options_with_exec) # endregion # region run_with_dotnet_path EmbeddedServer().start_server( ServerOptions(dotnet_path="PATH_TO_DOTNET_EXEC"))
def embedded(): # region embedded_example EmbeddedServer().start_server() with EmbeddedServer().get_document_store("Embedded") as store: with store.open_session() as session: # Your Code Here pass # endregion # region start_server # Start RavenDB Embedded Server with default options EmbeddedServer().start_server() # endregion # region start_server_with_options server_options = ServerOptions(data_directory="C:\\RavenData", server_url="http://127.0.0.1:8080") EmbeddedServer().start_server(server_options) # endregion # region get_document_store EmbeddedServer().get_document_store("Embedded") # endregion # region get_document_store_with_database_options database_options = DatabaseOptions(database_name="Embedded", skip_creating_database=True) EmbeddedServer().get_document_store(database_options) # endregion # region security server_options = ServerOptions() server_options.secured(certificate_path="PathToServerCertificate.pfx", certificate_password="******") # endregion # region security2 server_options_with_exec = ServerOptions() server_options_with_exec.secured_with_exec("powershell", "C:\\secrets\\give_me_cert.ps1", Utils.get_cert_file_fingerprint("PATH_TO_PEM_CERT_FILE"), "PATH_TO_PEM_CERT_FILE") EmbeddedServer.start_server(server_options_with_exec) # endregion # region run_with_dotnet_path EmbeddedServer().start_server(ServerOptions(dotnet_path="PATH_TO_DOTNET_EXEC"))
def secured(self, certificate_path, certificate_password=None): """ :param certificate_path: The path to a pfx file :param certificate_password: The password of the certificate file :type certificate_path: str :type certificate_password: str """ if certificate_path is None: raise ValueError("certificate_path cannot be None") if self.security is not None: raise InvalidOperationException("The security has already been setup for this ServerOptions object") server_cert_fingerprint = Utils.get_cert_file_fingerprint(certificate_path) client_cert_path = _SecurityOptions.get_pem_file(certificate_path, certificate_password) self.security = _SecurityOptions(certificate_path, certificate_password, client_cert_path, server_cert_fingerprint=server_cert_fingerprint)
def run(server_options: ServerOptions): if not server_options.server_directory: raise ValueError( "server_options.server_directory cannot be None or empty") if not server_options.data_directory: raise ValueError( "server_options.data_directory cannot be None or empty") server_dll_path = os.path.join(server_options.server_directory, "Raven.Server.dll") if not os.path.isfile(server_dll_path): raise FileNotFoundError("Server file was not found", server_dll_path) if not server_options.dotnet_path: raise ValueError( "server_options.dotnet_path cannot be None or empty") server_options.command_line_args.append("--Embedded.ParentProcessId=" + str(os.getpid())) server_options.command_line_args.append( "--License.Eula.Accepted=" + str(server_options.accept_eula)) server_options.command_line_args.append("--Setup.Mode=None") server_options.command_line_args.append( r"--DataDir=" + add_quotes_if_needed(server_options.data_directory)) if server_options.security: if not server_options.server_url: server_options.server_url = "https://127.0.0.1:0" if server_options.security.certificate_path is not None: server_options.command_line_args.append( "--Security.Certificate.Path=" + add_quotes_if_needed( server_options.security.certificate_path)) else: server_options.command_line_args.append( "--Security.Certificate.Exec=" + server_options.security.certificate_exec) server_options.command_line_args.append( "--Security.Certificate.Exec.Arguments=" + server_options.security.certificate_arguments) server_options.command_line_args.append( "--Security.WellKnownCertificates.Admin=" + Utils.get_cert_file_fingerprint( server_options.security.client_certificate)) else: if not server_options.server_url: server_options.server_url = "http://127.0.0.1:0" server_options.command_line_args.append("--ServerUrl=" + server_options.server_url) server_options.command_line_args[0:0] = [ add_quotes_if_needed(server_dll_path) ] server_options.command_line_args[0:0] = [ "--fx-version " + server_options.framework_version ] server_options.command_line_args[0:0] = [ add_quotes_if_needed(server_options.dotnet_path) ] argument_string = " ".join(server_options.command_line_args) try: process = subprocess.Popen(argument_string, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE) except Exception as e: process.send_signal(signal.SIGINT) raise InvalidOperationException( "Unable to execute server." + os.linesep + "Command was:" + os.linesep + argument_string, e) return process