Revision 08c317fa

b/snf-image-host/pithcat
25 25
the URL as the user when connecting to the backend.
26 26
"""
27 27

  
28
from optparse import OptionParser
28
from optparse import OptionParser, OptionGroup
29 29
from sys import exit, stdout, stderr
30 30
from os import environ
31 31
from binascii import hexlify, unhexlify
......
39 39

  
40 40

  
41 41
parser = OptionParser(usage='%prog [options] <URL>')
42
parser.add_option('--db', dest='db', metavar='URI',
43
                  help='SQLAlchemy URI of the database [REQUIRED]')
44 42
parser.add_option('--data', dest='data', metavar='DIR',
45
                  help='path to the directory where data are'
46
                       ' stored [REQUIRED]')
43
                  help='path to the directory where data are stored')
47 44
parser.add_option('-s', action='store_true', dest='size', default=False,
48 45
                  help='print file size and exit')
46
group = OptionGroup(
47
    parser, "Dangerous Options",
48
    "Caution: If the <URL> is a LocationURL (pithos://...), then you'll also "
49
    "need to define a database URI. You can use the `--db' option to do so, "
50
    "but this raises security concerns. For database URI's and pithos data "
51
    "paths, the recommended way to define them is to use the PITHCAT_INPUT_DB "
52
    "and PITHCAT_INPUT_DATA environmental variables respectfully.")
53
group.add_option('--db', dest='db', metavar='URI',
54
                 help='SQLAlchemy URI of the database', default=None)
55
parser.add_option_group(group)
49 56

  
50 57
LocationURL = namedtuple('LocationURL', ['account', 'container', 'object'])
51 58
HashmapURL = namedtuple('HashmapURL', ['hash', 'size'])
......
108 115
    url = parse_url(args[0])
109 116

  
110 117
    if not options.data and 'PITHCAT_INPUT_DATA' not in environ:
111
        stderr.write("Pithos data directory path is missing.\n")
118
        stderr.write(
119
            "Pithos data directory path is missing.\n"
120
            "Use the PITHCAT_INPUT_DATA environmental variable (recommended) "
121
            "or the --data command line option to define it.\n")
112 122
        exit(1)
113 123

  
114 124
    data_path = environ['PITHCAT_INPUT_DATA'] if not options.data else \
115 125
        options.data
116 126

  
117
    if not options.db and 'PITHCAT_INPUT_DB' not in environ:
118
        stderr.write("Pithos database uri is missing.\n")
127
    if options.db is None and 'PITHCAT_INPUT_DB' not in environ and \
128
            type(url) is LocationURL:
129
        stderr.write(
130
            "Pithos database uri is missing.\n"
131
            "Use the PITHCAT_INPUT_DB environmental variable (recommended) "
132
            "or the --db command line option to define it.\n")
119 133
        exit(1)
120 134

  
121 135
    db_uri = environ['PITHCAT_INPUT_DB'] if not options.db else options.db
122 136

  
137
    print "%s" % db_uri
138

  
123 139
    backend = ModularBackend(None,
124
                             db_uri if type(url) is LocationURL
125
                                    else None,
140
                             db_uri if type(url) is LocationURL else None,
126 141
                             None,
127 142
                             data_path)
128 143

  
......
133 148

  
134 149
if __name__ == '__main__':
135 150
    main()
151

  
152
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :

Also available in: Unified diff