17
17
app = Flask ('keychain' )
18
18
app .config ['DEBUG' ] = True
19
19
20
+ bucket_name = 'keychain.io'
20
21
action_expiry = 3600
21
22
pending_actions = {}
22
23
@@ -26,10 +27,17 @@ def s3key(email, name):
26
27
global s3
27
28
if not s3 :
28
29
s3 = boto .connect_s3 ()
29
- k = boto .s3 .key .Key (s3 .lookup ('keychain.io' ))
30
+ k = boto .s3 .key .Key (s3 .lookup (bucket_name ))
30
31
k .key = '{}.{}' .format (email , name )
31
32
return k
32
33
34
+ def s3keys (email ):
35
+ global s3
36
+ if not s3 :
37
+ s3 = boto .connect_s3 ()
38
+ b = s3 .get_bucket (bucket_name )
39
+ return b .list (prefix = email )
40
+
33
41
def lookup_key (email , name = None ):
34
42
name = name or 'default'
35
43
k = s3key (email , name )
@@ -38,6 +46,13 @@ def lookup_key(email, name=None):
38
46
except :
39
47
return None
40
48
49
+ def lookup_keys (email ):
50
+ keys = s3keys (email )
51
+ try :
52
+ return [k .get_contents_as_string () for k in keys ]
53
+ except Exception , e :
54
+ return None
55
+
41
56
def upload_key (email , name , key ):
42
57
k = s3key (email , name )
43
58
k .set_contents_from_string (key .strip ())
@@ -112,12 +127,12 @@ def default_fingerprint(email):
112
127
113
128
@app .route ('/<email>/all' )
114
129
def all_keys (email ):
115
- keys_ = [ lookup_key (email , key ) for key in keys [ email ]]
130
+ keys_ = lookup_keys (email )
116
131
return "{0}\n " .format ('\n ' .join (keys_ ))
117
132
118
133
@app .route ('/<email>/all/install' )
119
134
def all_install (email ):
120
- keys_ = [ lookup_key (email , key ) for key in keys [ email ]]
135
+ keys_ = lookup_keys (email )
121
136
return render_template ('install.sh' , keys = keys_ )
122
137
123
138
@app .route ('/<email>/<keyname>' , methods = ['GET' , 'PUT' , 'DELETE' ])
0 commit comments