Note: We no longer publish the latest version of our code here. We primarily use a kumc-bmi github organization. The heron ETL repository, in particular, is not public. Peers in the informatics community should see MultiSiteDev for details on requesting access.

source: heron_load/setpass.py @ 0:42ad7288920a

heron-michigan tip
Last change on this file since 0:42ad7288920a was 0:42ad7288920a, checked in by Matt Hoag <mhoag@…>, 6 years ago

Merge with demo_concepts_3800

File size: 1.4 KB
Line 
1'''Set DB password using system keychain.
2
3Usage:
4
5  $ python setpass.py --format db1
6  oracle://localhost/db1
7
8  $ python setpass.py --format db1 host2
9  oracle://host2/db1
10
11  $ python setpass.py oracle://host2/db1
12  Password for dconnolly on oracle://host2/db1:
13
14'''
15import sys
16import getpass
17
18import keyring  # https://pypi.python.org/pypi/keyring
19
20from db_util import ora_access
21
22# Avoid warnings about application name not set (#1163)
23# ACK: http://mindbending.org/en/bending-gnome-keyring-with-python-part-2
24try:
25    import glib
26    glib.set_application_name('setpass')
27except ImportError:
28    pass
29
30
31def main(argv=sys.argv,
32         stderr=sys.stderr,
33         set_password=keyring.set_password,
34         getuser=getpass.getuser,
35         getpass=getpass.getpass):
36    if '--help' in argv or len(argv) <= 1:
37        print >> stderr, __doc__
38        raise SystemExit(1)
39    elif '--showkeyring' in argv:
40        print str(keyring.get_keyring())
41    elif '--format' in argv:
42        sid, host, port = (argv[2:6]
43                           + (['localhost'] if len(argv) < 4 else [])
44                           + (['1521'] if len(argv) < 5 else []))
45        port = int(port)
46        svc = ora_access(sid, host, port)
47        print svc
48    else:
49        svc = argv[1]
50        u = getuser()
51        p = getpass('Password for %s on %s: ' % (u, svc))
52        set_password(svc, u, p)
53
54
55if __name__ == '__main__':
56    main()
Note: See TracBrowser for help on using the repository browser.