2 # The contents of this file are subject to the Common Public Attribution
3 # License Version 1.0. (the "License"); you may not use this file except in
4 # compliance with the License. You may obtain a copy of the License at
5 # http://code.reddit.com/LICENSE. The License is based on the Mozilla Public
6 # License Version 1.1, but Sections 14 and 15 have been added to cover use of
7 # software over a computer network and provide for limited attribution for the
8 # Original Developer. In addition, Exhibit A has been modified to be consistent
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
13 # the specific language governing rights and limitations under the License.
15 # The Original Code is reddit.
17 # The Original Developer is the Initial Developer. The Initial Developer of
18 # the Original Code is reddit Inc.
20 # All portions of the code written by reddit are Copyright (c) 2006-2015 reddit
21 # Inc. All Rights Reserved.
22 ###############################################################################
30 from r2
.lib
.utils
import parse_ini_file
31 from r2
.lib
.zookeeper
import connect_to_zookeeper
32 from r2
.lib
.app_globals
import fetch_secrets
35 def read_secrets_from_zookeeper(config
):
36 zk_hostlist
= config
.get("DEFAULT", "zookeeper_connection_string")
37 username
= config
.get("DEFAULT", "zookeeper_username")
38 password
= config
.get("DEFAULT", "zookeeper_password")
40 client
= connect_to_zookeeper(zk_hostlist
, (username
, password
))
41 secrets
= fetch_secrets(client
)
43 ini
= ConfigParser
.RawConfigParser()
45 ini
.add_section("secrets")
46 for name
, secret
in secrets
.iteritems():
47 ini
.set("secrets", name
, base64
.b64encode(secret
))
49 output
= cStringIO
.StringIO()
51 return output
.getvalue()
55 progname
= os
.path
.basename(sys
.argv
[0])
58 ini_file_name
= sys
.argv
[1]
60 print >> sys
.stderr
, "USAGE: %s INI" % progname
64 with
open(ini_file_name
) as ini_file
:
65 config
= parse_ini_file(ini_file
)
66 except (IOError, ConfigParser
.Error
), e
:
67 print >> sys
.stderr
, "%s: %s: %s" % (progname
, ini_file_name
, e
)
70 print read_secrets_from_zookeeper(config
)
73 if __name__
== "__main__":