def _getYottaClientUUID(): import uuid current_uuid = settings.get('uuid') if current_uuid is None: current_uuid = u'%s' % uuid.uuid4() settings.set('uuid', current_uuid) return current_uuid
def _generateAndSaveKeys(registry=None): registry = registry or Registry_Base_URL k = rsa.generate_private_key(public_exponent=65537, key_size=2048, backend=default_backend()) privatekey_pem = k.private_bytes(serialization.Encoding.PEM, serialization.PrivateFormat.PKCS8, serialization.NoEncryption()) pubkey_pem = k.public_key().public_bytes( serialization.Encoding.PEM, serialization.PublicFormat.SubjectPublicKeyInfo) if _isPublicRegistry(registry): settings.setProperty('keys', 'private', privatekey_pem.decode('ascii')) settings.setProperty('keys', 'public', pubkey_pem.decode('ascii')) else: sources = _getSources() keys = None for s in sources: if _sourceMatches(s, registry): if not 'keys' in s: s['keys'] = dict() keys = s['keys'] break if keys is None: keys = dict() sources.append({'type': 'registry', 'url': registry, 'keys': keys}) keys['private'] = privatekey_pem.decode('ascii') keys['public'] = pubkey_pem.decode('ascii') settings.set('sources', sources) return pubkey_pem, privatekey_pem
def deauthorize(registry=None): registry = registry or Registry_Base_URL if _isPublicRegistry(registry): if settings.get('keys'): settings.set('keys', dict()) else: sources = [s for s in _getSources() if not _sourceMatches(s, registry)] settings.set('sources', sources)
def setAPIKey(registry, api_key): ''' Set the api key for accessing a registry. This is only necessary for development/test registries. ''' if (registry is None) or (registry == Registry_Base_URL): return sources = _getSources() source = None for s in sources: if _sourceMatches(s, registry): source = s if source is None: source = { 'type':'registry', 'url':registry, } sources.append(source) source['apikey'] = api_key settings.set('sources', sources)
def setAPIKey(registry, api_key): ''' Set the api key for accessing a registry. This is only necessary for development/test registries. ''' if (registry is None) or (registry == Registry_Base_URL): return sources = _getSources() source = None for s in sources: if _sourceMatches(s, registry): source = s if source is None: source = { 'type': 'registry', 'url': registry, } sources.append(source) source['apikey'] = api_key settings.set('sources', sources)
def _generateAndSaveKeys(registry=None): registry = registry or Registry_Base_URL k = rsa.generate_private_key( public_exponent=65537, key_size=2048, backend=default_backend() ) privatekey_pem = k.private_bytes( serialization.Encoding.PEM, serialization.PrivateFormat.PKCS8, serialization.NoEncryption() ) pubkey_pem = k.public_key().public_bytes( serialization.Encoding.PEM, serialization.PublicFormat.SubjectPublicKeyInfo ) if _isPublicRegistry(registry): settings.setProperty('keys', 'private', privatekey_pem.decode('ascii')) settings.setProperty('keys', 'public', pubkey_pem.decode('ascii')) else: sources = _getSources() keys = None for s in sources: if _sourceMatches(s, registry): if not 'keys' in s: s['keys'] = dict() keys = s['keys'] break if keys is None: keys = dict() sources.append({ 'type':'registry', 'url':registry, 'keys':keys }) keys['private'] = privatekey_pem.decode('ascii') keys['public'] = pubkey_pem.decode('ascii') settings.set('sources', sources) return pubkey_pem, privatekey_pem