depot.py revision 812
20N/A# The contents of this file are subject to the terms of the 20N/A# Common Development and Distribution License (the "License"). 20N/A# You may not use this file except in compliance with the License. 20N/A# See the License for the specific language governing permissions 20N/A# and limitations under the License. 20N/A# When distributing Covered Code, include this CDDL HEADER in each 20N/A# If applicable, add the following below this CDDL HEADER, with the 20N/A# fields enclosed by brackets "[]" replaced with your own identifying 20N/A# information: Portions Copyright [yyyy] [name of copyright owner] 814N/A# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 20N/A# Use is subject to license terms. 22N/A# pkg.depotd - package repository daemon 50N/A# XXX The prototype pkg.depotd combines both the version management server that 50N/A# answers to pkgsend(1) sessions and the HTTP file server that answers to the 50N/A# various GET operations that a pkg(1) client makes. This split is expected to 50N/A# be made more explicit, by constraining the pkg(1) operations such that they 50N/A# can be served as a typical HTTP/HTTPS session. Thus, pkg.depotd will reduce 50N/A# to a special purpose HTTP/HTTPS server explicitly for the version management 50N/A# operations, and must manipulate the various state files--catalogs, in 50N/A# particular--such that the pkg(1) pull client can operately accurately with 50N/A# XXX We should support simple "last-modified" operations via HEAD queries. 50N/A# XXX Although we pushed the evaluation of next-version, etc. to the pull 50N/A# client, we should probably provide a query API to do same on the server, for 50N/A# dumb clients (like a notification service). 382N/A# The default authority for the depot. 382N/A# The default repository path. 589N/A# The default path for static and other web content. 965N/A# The default port(s) to serve data from. 965N/A# The minimum number of threads allowed. 965N/A# The default number of threads to start. 382N/A# The maximum number of threads that can be started. 382N/A# The default server socket timeout in seconds. We want this to be longer than 382N/A# the normal default of 10 seconds to accommodate clients with poor quality 382N/A# Whether modify operations should be allowed. 382N/A# Whether the repository catalog should be rebuilt on startup. 382N/A# Whether the indexes should be rebuilt 382N/A# Not in mirror mode by default 382N/A print >>
sys.
stderr,
"""cherrypy 3.1.0 or greater (but less than """ \
452N/A """3.2.0) is required to use this program.""" 26N/A """This is a dummy object that we can use to discard log entries 382N/A without relying on non-portable interfaces such as /dev/null.""" 428N/A """Discard the bits.""" 466N/A """Discard the bits.""" 466N/A [-t socket_timeout] [--cfg-file] [--content-root] [--log-access dest] 466N/A [--log-errors dest] [--mirror] [--proxy-base url] [--readonly] 466N/A [--rebuild] [--ssl-cert-file] [--ssl-dialog] [--ssl-key-file] 466N/A --cfg-file The pathname of the file from which to read and to 26N/A write configuration information. 589N/A --content-root The file system path to the directory containing the 858N/A the static and other web content used by the depot's 1191N/A browser user interface. The default value is 1191N/A --log-access The destination for any access related information 382N/A logged by the depot process. Possible values are: 812N/A stderr, stdout, none, or an absolute pathname. The 812N/A default value is stdout if stdout is a tty; otherwise 589N/A the default value is none. 589N/A --log-errors The destination for any errors or other information 589N/A logged by the depot process. Possible values are: 589N/A stderr, stdout, none, or an absolute pathname. The 858N/A default value is stderr. 858N/A --mirror Package mirror mode; publishing and metadata operations 858N/A disallowed. Cannot be used with --readonly or 466N/A --proxy-base The url to use as the base for generating internal 466N/A --readonly Read-only operation; modifying operations disallowed. 466N/A Cannot be used with --mirror or --rebuild. 466N/A --rebuild Re-build the catalog from pkgs in depot. Cannot be 466N/A used with --mirror or --readonly. 466N/A --ssl-cert-file The absolute pathname to a PEM-encoded Certificate file. 466N/A This option must be used with --ssl-key-file. Usage of 589N/A this option will cause the depot to only respond to SSL 589N/A requests on the provided port. 589N/A --ssl-dialog Specifies what method should be used to obtain the 1191N/A passphrase needed to decrypt the file specified by 1191N/A --ssl-key-file. Supported values are: builtin, 1191N/A --ssl-key-file The absolute pathname to a PEM-encoded Private Key file. 589N/A This option must be used with --ssl-cert-file. Usage of 589N/A this option will cause the depot to only respond to SSL 589N/A requests on the provided port. 812N/A """Option exception. """ 382N/A # By default, if the destination for a particular log type is not 429N/A # specified, this is where we will send the output. 812N/A # If stdout is a tty, then send access output there by default instead 30N/A "proxy-base=",
"readonly",
"rebuild",
"refresh-index",
589N/A "ssl-cert-file=",
"ssl-dialog=",
"ssl-key-file="]
135N/A "You must specify a log " \
812N/A # Attempt to decompose the url provided into 382N/A # its base parts. This is done so we can 382N/A # remove any scheme information since we 382N/A "determine the hostname from " \
812N/A "the provided URL; please use a " \
589N/A "and https are the only supported " \
858N/A # Rebuild the url with the sanitized components. 858N/A # Note: This argument is for internal use 858N/A # only. It's used when pkg.depotd is reexecing 858N/A # itself and needs to know that's the case. 858N/A # This flag is purposefully omitted in usage. 858N/A # The supported way to forcefully reindex is to 858N/A # kill any pkg.depot using that directory, 858N/A # remove the index directory, and restart the 466N/A # pkg.depot process. The index will be rebuilt 466N/A # automatically on startup. 1191N/A "the Certificate file must be " \
589N/A "the Private Key file must be " \
765N/A "pathname is not a file." 765N/A "specified. Expected: builtin, " \
382N/A # Don't allow a somewhat insecure 157N/A # authentication method on some 429N/A "a supported dialog type for " \
429N/A "this operating system." 429N/A "file path specified for " \
812N/A usage(
"pkg.depotd: illegal option value: %s specified " \
812N/A usage(
"--refresh-index cannot be used with --rebuild")
812N/A usage(
"--readonly and --mirror cannot be used with --rebuild")
812N/A usage(
"--readonly and --mirror cannot be used with " \
812N/A usage(
"The --ssl-cert-file and --ssl-key-file options must " 812N/A "must both be provided when using either option.")
812N/A # If they didn't already specify a particular port, use the 812N/A # default SSL port instead. 812N/A # If the program is going to reindex, the port is irrelevant since 812N/A # the program will not bind to a port. 812N/A print "pkg.depotd: unable to bind to the specified " \
812N/A # Not applicable for reindexing operations. 812N/A print "pkg.depotd: an error occurred while trying to " \
812N/A "initialize the depot repository directory " \
466N/A print "pkg.depotd: an error occurred while " \
466N/A "executing [%s]; unable to obtain the " \
451N/A "passphrase needed to decrypt the SSL" \
812N/A # The key file requires decryption, but the user has requested 812N/A # exec-based authentication, so it will have to be decoded first 812N/A # to an un-named temporary file. 429N/A print "pkg.depotd: unable to read the SSL private " \
612N/A print "pkg.depotd: authentication or cryptography " \
386N/A "failure while attempting to decode\nthe SSL " \
916N/A "private key file: %s" % e
1191N/A # Redirect the server to the decrypted key file. 1191N/A # Setup our global configuration. 1191N/A "environment":
"production",
382N/A "server.socket_host":
"0.0.0.0",
461N/A "server.shutdown_timeout":
0,
873N/A "param":
"log.error_file",
812N/A "param":
"log.access_file",
812N/A # Since we've replaced cherrypy's log handler with our 812N/A # own, we don't want the output directed to a file. 812N/A # Now that our logging, etc. has been setup, it's safe to perform any 812N/A # remaining preparation. 873N/A # Now build our site configuration. 812N/A # We have to override cherrypy's default response_class so that 873N/A # we have access to the write() callable to stream data 812N/A # directly to the client. 382N/A # This changes the base URL for our server, and is primarily 466N/A # intended to allow our depot process to operate behind Apache 965N/A # or some other webserver process. 452N/A # Visit the following URL for more information: 858N/A "tools.proxy.local":
"",
466N/A # Now merge or add our proxy configuration information into the 466N/A # existing configuration. 466N/A emsg(
"pkg.depotd: unknown error starting depot server, " \
466N/A "illegal option value specified?")