def volume_check_consistent( config, volume, volume_name, description, blocksize, email, **attrs ): """ Given an existing volume, is it consistent with the data we were given? Return a dict of inconsistent fields. """ # sanity check missing = [] for key in attrs.keys(): if key not in volume.keys(): missing.append(key) if len(missing) > 0: raise Exception("Missing volume fields: %s\n%s" % (", ".join(missing), json.dumps(volume,indent=4,sort_keys=True))) volume_cert = certs.get_volume_cert( config, volume_name ) if volume_cert is None: raise Exception("No certificate found for volume '%s'" % volume_name) user_cert = certs.get_user_cert( config, email ) if user_cert is None: raise Exception("No certificate found for user '%s'" % email) owner_cert = certs.get_user_cert( config, volume_cert.owner_email ) if owner_cert is None: raise Exception("No certificate found for volume owner '%s'" % volume_cert.owner_email ) # check consistency inconsistent = {} if volume['name'] != volume_name: log.debug("Volume mismatch: name") inconsistent['name'] = volume_name if volume['volume_id'] != volume_cert.volume_id: log.debug("Volume mismatch: volume_id") inconsistent['volume_id'] = volume_cert.volume_id if volume['description'] != description: log.debug("Volume mismatch: description") inconsistent['description'] = description if volume['blocksize'] != blocksize: log.debug("Volume mismatch: blocksize (%s != %s)" % (volume['blocksize'], blocksize)) inconsistent['blocksize'] = blocksize if volume['owner_id'] != user_cert.user_id: log.debug("Volume mismatch: owner ID (%s != %s)" % (volume['owner_id'], user_cert.user_id)) inconsistent['owner_id'] = user_cert.user_id match = True for key in attrs.keys(): if volume[key] != attrs[key]: inconsistent[key] = attrs[key] return inconsistent
def gateway_check_consistent( config, gateway, gateway_type, user_email, volume_name, **attrs ): """ Ensure that an existing gateway is consistent with the given fields. * We must have a user certificate on-file * We must have a volume certificate on-file Return a dict with inconsistent fields (empty dict indicates consistent) """ # sanity check ignore = [] for key in attrs.keys(): if key not in gateway.keys(): ignore.append(key) user_cert = certs.get_user_cert( config, user_email ) if user_cert is None: raise Exception("No certificate found for user '%s'" % user_email) volume_cert = certs.get_volume_cert( config, volume_name ) if volume_cert is None: raise Exception("No certificate found for volume '%s'" % volume_name ) type_aliases = object_stub.load_gateway_type_aliases( config ) type_id = type_aliases.get( gateway_type, None ) if type_id is None: raise Exception("Invalid gateway type '%s'" % gateway_type ) inconsistent = {} if not gateway.has_key('volume_id'): raise Exception("Missing volume_id:\n%s" % json.dumps(gateway,indent=4,sort_keys=True)) if not gateway.has_key('owner_id'): raise Exception("Missing owner_id:\n%s" % json.dumps(gateway,indent=4,sort_keys=True)) # validate if gateway['volume_id'] != volume_cert.volume_id: log.debug("Gateway mismatch: does not match volume") inconsistent['volume_id'] = volume_cert.volume_id if gateway['owner_id'] != user_cert.user_id: log.debug("Gateway mismatch: does not match user") inconsistent['owner_id'] = user_cert.user_id for key in attrs.keys(): if key in ignore: continue if gateway[key] != attrs[key]: # special case: caps if key == "caps": if object_stub.Gateway.parse_gateway_caps(attrs[key], None)[0] == gateway[key]: # not inconsistent continue inconsistent[key] = attrs[key] return inconsistent
def user_check_consistent( config, user, user_email, public_key, **attrs ): """ Given an existing user, is it consistent with the data we were given? NOTE: public_key must be a PEM-encoded 4096-bit RSA public key. Return a dict of inconsistent fields. """ # sanity check missing = [] for key in attrs.keys(): if key not in user.keys(): missing.append(key) if len(missing) > 0: raise Exception("Missing user fields: %s" % ", ".join(missing)) user_cert = certs.get_user_cert( config, user_email ) if user_cert is None: raise Exception("No certificate found for user '%s'" % user_email) # check consistency inconsistent = {} if user['public_key'].strip() != public_key.strip(): log.debug("User public key mismatch") inconsistent['public_key'] = public_key match = True for key in attrs.keys(): if user[key] != attrs[key]: inconsistent[key] = attrs[key] return inconsistent
def user_check_consistent(config, user, user_email, public_key, **attrs): """ Given an existing user, is it consistent with the data we were given? NOTE: public_key must be a PEM-encoded 4096-bit RSA public key. Return a dict of inconsistent fields. """ # sanity check missing = [] for key in attrs.keys(): if key not in user.keys(): missing.append(key) if len(missing) > 0: raise Exception("Missing user fields: %s" % ", ".join(missing)) user_cert = certs.get_user_cert(config, user_email) if user_cert is None: raise Exception("No certificate found for user '%s'" % user_email) # check consistency inconsistent = {} if user['public_key'].strip() != public_key.strip(): log.debug("User public key mismatch") inconsistent['public_key'] = public_key match = True for key in attrs.keys(): if user[key] != attrs[key]: inconsistent[key] = attrs[key] return inconsistent
def gateway_check_consistent(config, gateway, gateway_type, user_email, volume_name, **attrs): """ Ensure that an existing gateway is consistent with the given fields. * We must have a user certificate on-file * We must have a volume certificate on-file Return a dict with inconsistent fields (empty dict indicates consistent) """ # sanity check ignore = [] for key in attrs.keys(): if key not in gateway.keys(): ignore.append(key) user_cert = certs.get_user_cert(config, user_email) if user_cert is None: raise Exception("No certificate found for user '%s'" % user_email) volume_cert = certs.get_volume_cert(config, volume_name) if volume_cert is None: raise Exception("No certificate found for volume '%s'" % volume_name) type_aliases = object_stub.load_gateway_type_aliases(config) type_id = type_aliases.get(gateway_type, None) if type_id is None: raise Exception("Invalid gateway type '%s'" % gateway_type) inconsistent = {} if not gateway.has_key('volume_id'): raise Exception("Missing volume_id:\n%s" % json.dumps(gateway, indent=4, sort_keys=True)) if not gateway.has_key('owner_id'): raise Exception("Missing owner_id:\n%s" % json.dumps(gateway, indent=4, sort_keys=True)) # validate if gateway['volume_id'] != volume_cert.volume_id: log.debug("Gateway mismatch: does not match volume") inconsistent['volume_id'] = volume_cert.volume_id if gateway['owner_id'] != user_cert.user_id: log.debug("Gateway mismatch: does not match user") inconsistent['owner_id'] = user_cert.user_id for key in attrs.keys(): if key in ignore: continue if gateway[key] != attrs[key]: # special case: caps if key == "caps": if object_stub.Gateway.parse_gateway_caps( attrs[key], None)[0] == gateway[key]: # not inconsistent continue inconsistent[key] = attrs[key] return inconsistent
def volume_check_consistent(config, volume, volume_name, description, blocksize, email, **attrs): """ Given an existing volume, is it consistent with the data we were given? Return a dict of inconsistent fields. """ # sanity check missing = [] for key in attrs.keys(): if key not in volume.keys(): missing.append(key) if len(missing) > 0: raise Exception( "Missing volume fields: %s\n%s" % (", ".join(missing), json.dumps(volume, indent=4, sort_keys=True))) volume_cert = certs.get_volume_cert(config, volume_name) if volume_cert is None: raise Exception("No certificate found for volume '%s'" % volume_name) user_cert = certs.get_user_cert(config, email) if user_cert is None: raise Exception("No certificate found for user '%s'" % email) owner_cert = certs.get_user_cert(config, volume_cert.owner_email) if owner_cert is None: raise Exception("No certificate found for volume owner '%s'" % volume_cert.owner_email) # check consistency inconsistent = {} if volume['name'] != volume_name: log.debug("Volume mismatch: name") inconsistent['name'] = volume_name if volume['volume_id'] != volume_cert.volume_id: log.debug("Volume mismatch: volume_id") inconsistent['volume_id'] = volume_cert.volume_id if volume['description'] != description: log.debug("Volume mismatch: description") inconsistent['description'] = description if volume['blocksize'] != blocksize: log.debug("Volume mismatch: blocksize (%s != %s)" % (volume['blocksize'], blocksize)) inconsistent['blocksize'] = blocksize if volume['owner_id'] != user_cert.user_id: log.debug("Volume mismatch: owner ID (%s != %s)" % (volume['owner_id'], user_cert.user_id)) inconsistent['owner_id'] = user_cert.user_id match = True for key in attrs.keys(): if volume[key] != attrs[key]: inconsistent[key] = attrs[key] return inconsistent