authorities can also have a 'name' for standalone deployments
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Tue, 2 Jun 2015 12:09:26 +0000 (14:09 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Tue, 2 Jun 2015 12:09:26 +0000 (14:09 +0200)
comes with a db migration to that effect as well
authority name can be set in sfi register and/or sfi update
in the mix, bugfix for user emails: sfi update ... --email foo
was not making it to the sfa db

Makefile
sfa/client/sfi.py
sfa/storage/migrations/versions/001_slice_researchers.py
sfa/storage/migrations/versions/002_authority_pis.py
sfa/storage/migrations/versions/003_sliver_allocations.py
sfa/storage/migrations/versions/004_authority_name.py [new file with mode: 0644]
sfa/storage/model.py

index 80eda20..45add83 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -226,6 +226,8 @@ synclib: synccheck
        +$(RSYNC) --relative ./sfa/ --exclude migrations $(SSHURL)/usr/lib\*/python2.\*/site-packages/
 synclibdeb: synccheck
        +$(RSYNC) --relative ./sfa/ --exclude migrations $(SSHURL)/usr/share/pyshared/
+syncmigrations:
+       +$(RSYNC) ./sfa/storage/migrations/versions/*.py $(SSHURL)/usr/share/sfa/migrations/versions/
 syncbin: synccheck
        +$(RSYNC)  $(BINS) $(SSHURL)/usr/bin/
 syncinit: synccheck
index 3699d55..31b8a05 100644 (file)
@@ -208,6 +208,9 @@ def load_record_from_opts(options):
         record_dict['reg-researchers'] = options.reg_researchers
     if hasattr(options, 'email') and options.email:
         record_dict['email'] = options.email
+    # authorities can have a name for standalone deployment
+    if hasattr(options, 'name') and options.name:
+        record_dict['name'] = options.name
     if hasattr(options, 'reg_pis') and options.reg_pis:
         record_dict['reg-pis'] = options.reg_pis
 
@@ -423,6 +426,7 @@ class Sfi:
             parser.add_option('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn (mandatory)')
             parser.add_option('-t', '--type', dest='type', metavar='<type>', help='object type', default=None)
             parser.add_option('-e', '--email', dest='email', default="",  help="email (mandatory for users)") 
+            parser.add_option('-n', '--name', dest='name', default="",  help="name (optional for authorities)") 
             parser.add_option('-k', '--key', dest='key', metavar='<key>', help='public key string or file', 
                               default=None)
             parser.add_option('-s', '--slices', dest='slices', metavar='<slices>', help='Set/replace slice xrns',
index eb1d3b7..2106fc6 100644 (file)
@@ -4,9 +4,9 @@
 from sqlalchemy import Table, MetaData, Column, ForeignKey
 from sqlalchemy import Integer, String
 
-metadata=MetaData()
+metadata = MetaData()
 
-# this is needed my migrate so it can locate 'records.record_id'
+# this is needed by migrate so it can locate 'records.record_id'
 records = \
     Table ( 'records', metadata,
             Column ('record_id', Integer, primary_key=True),
index b0dbe55..e19a6bc 100644 (file)
@@ -4,7 +4,7 @@
 from sqlalchemy import Table, MetaData, Column, ForeignKey
 from sqlalchemy import Integer, String
 
-metadata=MetaData()
+metadata = MetaData()
 
 # this is needed by migrate so it can locate 'records.record_id'
 records = \
index c1534db..9dba9e8 100644 (file)
@@ -1,7 +1,8 @@
 from sqlalchemy import Table, MetaData, Column
 from sqlalchemy import Integer, String
 
-metadata=MetaData()
+metadata = MetaData()
+
 sliver_allocation_table = \
     Table ( 'sliver_allocation', metadata,
             Column('sliver_id', String, primary_key=True),
diff --git a/sfa/storage/migrations/versions/004_authority_name.py b/sfa/storage/migrations/versions/004_authority_name.py
new file mode 100644 (file)
index 0000000..55ed1ef
--- /dev/null
@@ -0,0 +1,17 @@
+# this move is about adding a 'name' column in the 'authority' table
+
+#from sfa.util.sfalogging import logger
+
+from sqlalchemy import MetaData, Table, Column, String
+from migrate.changeset.schema import create_column, drop_column
+
+def upgrade(migrate_engine):
+    metadata = MetaData(bind = migrate_engine)
+    authorities = Table('authorities', metadata, autoload=True)
+    name_column = Column('name', String)
+    name_column.create(authorities)
+
+def downgrade(migrate_engine):
+    metadata = MetaData(bind = migrate_engine)
+    authorities = Table('authorities', metadata, autoload=True)
+    authorities.c.name.drop()
index 7c74977..f5bf71d 100644 (file)
@@ -174,6 +174,8 @@ class RegAuthority (RegRecord):
     __mapper_args__     = { 'polymorphic_identity' : 'authority' }
     record_id           = Column (Integer, ForeignKey ("records.record_id"), primary_key=True)
     #### extensions come here
+    name                = Column ('name', String)
+    #### extensions come here
     reg_pis             = relationship \
         ('RegUser',
          secondary=authority_pi_table,
@@ -182,6 +184,9 @@ class RegAuthority (RegRecord):
          backref='reg_authorities_as_pi')
     
     def __init__ (self, **kwds):
+        # handle local settings
+        if 'name' in kwds:
+            self.name = kwds.pop('name')
         # fill in type if not previously set
         if 'type' not in kwds: kwds['type']='authority'
         # base class constructor
@@ -189,7 +194,9 @@ class RegAuthority (RegRecord):
 
     # no proper data yet, just hack the typename
     def __repr__ (self):
-        return RegRecord.__repr__(self).replace("Record","Authority")
+        result = RegRecord.__repr__(self).replace("Record", "Authority")
+        result.replace(">", " name={}>".format(self.name))
+        return result
 
     def update_pis (self, pi_hrns, dbsession):
         # strip that in case we have <researcher> words </researcher>