예제 #1
0
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
예제 #2
0
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
예제 #3
0
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
예제 #4
0
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)
예제 #5
0
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)
예제 #6
0
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)
예제 #7
0
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)
예제 #8
0
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