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