Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 # Copyright 2014 The Swarming Authors. All rights reserved. | 1 # Copyright 2014 The Swarming Authors. All rights reserved. |
2 # Use of this source code is governed by the Apache v2.0 license that can be | 2 # Use of this source code is governed by the Apache v2.0 license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Primary side of Primary <-> Replica protocol.""" | 5 """Primary side of Primary <-> Replica protocol.""" |
6 | 6 |
7 from google.appengine.ext import ndb | 7 from google.appengine.ext import ndb |
8 | 8 |
9 from components import datastore_utils | 9 from components import datastore_utils |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... | |
21 # How to convert this entity to serializable dict. | 21 # How to convert this entity to serializable dict. |
22 serializable_properties = { | 22 serializable_properties = { |
23 'replica_url': datastore_utils.READABLE, | 23 'replica_url': datastore_utils.READABLE, |
24 'auth_db_rev': datastore_utils.READABLE, | 24 'auth_db_rev': datastore_utils.READABLE, |
25 'rev_modified_ts': datastore_utils.READABLE, | 25 'rev_modified_ts': datastore_utils.READABLE, |
26 } | 26 } |
27 | 27 |
28 # URL of a host to push AuthDB updates to, especially useful on dev_appserver. | 28 # URL of a host to push AuthDB updates to, especially useful on dev_appserver. |
29 replica_url = ndb.StringProperty(indexed=False) | 29 replica_url = ndb.StringProperty(indexed=False) |
30 # Revision of auth DB replica is synced to. | 30 # Revision of auth DB replica is synced to. |
31 auth_db_rev = ndb.IntegerProperty(indexed=False) | 31 auth_db_rev = ndb.IntegerProperty(default=0, indexed=False) |
32 # Time when auth_db_rev was created (by primary clock). | 32 # Time when auth_db_rev was created (by primary clock). |
33 rev_modified_ts = ndb.DateTimeProperty(indexed=False) | 33 rev_modified_ts = ndb.DateTimeProperty(indexed=False) |
34 # Secret known to both Primary and Replica. | |
35 shared_secret = ndb.BlobProperty(indexed=False) | |
M-A
2014/06/30 01:18:31
Why not use asymmetric encryption?
vadimsh
2014/06/30 22:58:52
Good idea. I initially (~several months ago) wante
| |
36 | 34 |
37 | 35 |
38 def register_replica(app_id, replica_url, shared_secret): | 36 def register_replica(app_id, replica_url): |
39 """Create a new AuthReplicaState or reset the state of existing one.""" | 37 """Creates a new AuthReplicaState or resets the state of existing one.""" |
M-A
2014/06/30 01:18:31
Creates
resets
vadimsh
2014/06/30 22:58:52
Done.
| |
40 ent = AuthReplicaState( | 38 ent = AuthReplicaState( |
41 id=app_id, | 39 id=app_id, |
42 parent=REPLICAS_ROOT_KEY, | 40 parent=REPLICAS_ROOT_KEY, |
43 replica_url=replica_url, | 41 replica_url=replica_url) |
44 auth_db_rev=0, | |
M-A
2014/06/30 01:18:31
Why not use default=0?
vadimsh
2014/06/30 22:58:52
Done.
| |
45 rev_modified_ts=None, | |
M-A
2014/06/30 01:18:31
Not really necessary?
vadimsh
2014/06/30 22:58:52
Done.
| |
46 shared_secret=shared_secret) | |
47 ent.put() | 42 ent.put() |
LEFT | RIGHT |