Exemplo n.º 1
0
def getPublicKey(registry=None):
    ''' Return the user's public key (generating and saving a new key pair if necessary) '''
    registry = registry or Registry_Base_URL
    pubkey_pem = None
    if _isPublicRegistry(registry):
        pubkey_pem = settings.getProperty('keys', 'public')
    else:
        for s in _getSources():
            if _sourceMatches(s, registry):
                if 'keys' in s and s['keys'] and 'public' in s['keys']:
                    pubkey_pem = s['keys']['public']
                    break
    if not pubkey_pem:
        pubkey_pem, privatekey_pem = _generateAndSaveKeys()
    else:
        # settings are unicode, we should be able to safely decode to ascii for
        # the key though, as it will either be hex or PEM encoded:
        pubkey_pem = pubkey_pem.encode('ascii')
    # if the key doesn't look like PEM, it might be hex-encided-DER (which we
    # used historically), so try loading that:
    if b'-----BEGIN PUBLIC KEY-----' in pubkey_pem:
        pubkey = serialization.load_pem_public_key(pubkey_pem, default_backend())
    else:
        pubkey_der = binascii.unhexlify(pubkey_pem)
        pubkey = serialization.load_der_public_key(pubkey_der, default_backend())
    return _pubkeyWireFormat(pubkey)
Exemplo n.º 2
0
def _getTarball(url, into_directory, cache_key, origin_info=None):
    '''unpack the specified tarball url into the specified directory'''

    try:
        access_common.unpackFromCache(cache_key, into_directory)
    except KeyError as e:
        tok = settings.getProperty('github', 'authtoken')
        headers = {}
        if tok is not None:
            headers['Authorization'] = 'token ' + str(tok)

        logger.debug('GET %s', url)
        response = requests.get(url, allow_redirects=True, stream=True, headers=headers)
        response.raise_for_status()

        logger.debug('getting file: %s', url)
        logger.debug('headers: %s', response.headers)
        response.raise_for_status()

        # github doesn't exposes hashes of the archives being downloaded as far
        # as I can tell :(
        access_common.unpackTarballStream(
                    stream = response,
            into_directory = into_directory,
                      hash = {},
                 cache_key = cache_key,
               origin_info = origin_info
        )
Exemplo n.º 3
0
def getPublicKey(registry=None):
    ''' Return the user's public key (generating and saving a new key pair if necessary) '''
    registry = registry or Registry_Base_URL
    pubkey_pem = None
    if _isPublicRegistry(registry):
        pubkey_pem = settings.getProperty('keys', 'public')
    else:
        for s in _getSources():
            if _sourceMatches(s, registry):
                if 'keys' in s and s['keys'] and 'public' in s['keys']:
                    pubkey_pem = s['keys']['public']
                    break
    if not pubkey_pem:
        pubkey_pem, privatekey_pem = _generateAndSaveKeys()
    else:
        # settings are unicode, we should be able to safely decode to ascii for
        # the key though, as it will either be hex or PEM encoded:
        pubkey_pem = pubkey_pem.encode('ascii')
    # if the key doesn't look like PEM, it might be hex-encided-DER (which we
    # used historically), so try loading that:
    if b'-----BEGIN PUBLIC KEY-----' in pubkey_pem:
        pubkey = serialization.load_pem_public_key(pubkey_pem,
                                                   default_backend())
    else:
        pubkey_der = binascii.unhexlify(pubkey_pem)
        pubkey = serialization.load_der_public_key(pubkey_der,
                                                   default_backend())
    return _pubkeyWireFormat(pubkey)
Exemplo n.º 4
0
def _getTarball(url, into_directory, cache_key, origin_info=None):
    '''unpack the specified tarball url into the specified directory'''

    try:
        access_common.unpackFromCache(cache_key, into_directory)
    except KeyError as e:
        tok = settings.getProperty('github', 'authtoken')
        headers = {}
        if tok is not None:
            headers['Authorization'] = 'token ' + str(tok)

        logger.debug('GET %s', url)
        response = requests.get(url,
                                allow_redirects=True,
                                stream=True,
                                headers=headers)
        response.raise_for_status()

        logger.debug('getting file: %s', url)
        logger.debug('headers: %s', response.headers)
        response.raise_for_status()

        # github doesn't exposes hashes of the archives being downloaded as far
        # as I can tell :(
        access_common.unpackTarballStream(stream=response,
                                          into_directory=into_directory,
                                          hash={},
                                          cache_key=cache_key,
                                          origin_info=origin_info)
Exemplo n.º 5
0
def _getTags(repo):
    ''' return a dictionary of {tag: tarball_url}'''
    logger.debug('get tags for %s', repo)
    g = Github(settings.getProperty('github', 'authtoken'))
    repo = g.get_repo(repo)
    tags = repo.get_tags()
    logger.debug('tags for %s: %s', repo, [t.name for t in tags])
    return {t.name: _ensureDomainPrefixed(t.tarball_url) for t in tags}
Exemplo n.º 6
0
def _getTags(repo):
    ''' return a dictionary of {tag: tarball_url}'''
    logger.debug('get tags for %s', repo)
    g = Github(settings.getProperty('github', 'authtoken'))
    repo = g.get_repo(repo)
    tags = repo.get_tags()
    logger.debug('tags for %s: %s', repo, [t.name for t in tags])
    return {t.name: _ensureDomainPrefixed(t.tarball_url) for t in tags}
Exemplo n.º 7
0
def _getPrivateKey(registry):
    if _isPublicRegistry(registry):
        return settings.getProperty('keys', 'private')
    else:
        for s in _getSources():
            if _sourceMatches(s, registry):
                if 'keys' in s and s['keys'] and 'private' in s['keys']:
                    return s['keys']['private']
        return None
Exemplo n.º 8
0
 def retryWithAuthOrRaise(original_exception):
     # in all cases ask for auth, so that in non-interactive mode a
     # login URL is displayed
     auth.authorizeUser(provider='github', interactive=interactive)
     if not interactive:
         raise original_exception
     else:
         logger.debug('trying with authtoken: %s', settings.getProperty('github', 'authtoken'))
         return fn(*args, **kwargs)
Exemplo n.º 9
0
def _getPrivateKey(registry):
    if _isPublicRegistry(registry):
        return settings.getProperty('keys', 'private')
    else:
        for s in _getSources():
            if _sourceMatches(s, registry):
                if 'keys' in s and s['keys'] and 'private' in s['keys']:
                    return s['keys']['private']
        return None
Exemplo n.º 10
0
 def retryWithAuthOrRaise(original_exception):
     # in all cases ask for auth, so that in non-interactive mode a
     # login URL is displayed
     auth.authorizeUser(provider='github', interactive=interactive)
     if not interactive:
         raise original_exception
     else:
         logger.debug('trying with authtoken: %s',
                      settings.getProperty('github', 'authtoken'))
         return fn(*args, **kwargs)
Exemplo n.º 11
0
def installDeps(args, current_component):
    # settings, , load and save settings, internal
    from yotta.lib import settings

    logging.debug('install deps for %s' % current_component)
    if not current_component:
        logging.debug(str(current_component.getError()))
        logging.error('The current directory does not contain a valid module.')
        return 1
    # warn if the target hasn't been explicitly specified when running a build:
    # this is likely user-error
    if not settings.getProperty('build', 'targetSetExplicitly') and not \
        getattr(args, '_target_set_explicitly', False):
        logging.warning(
            'The build target has not been set, so the default (%s) is being '
            +
            'used. You can use `yotta target <targetname>` to set the build ' +
            'target. See http://yottadocs.mbed.com/tutorial/targets.html for '
            'more information on using targets.', args.target)
    target, errors = current_component.satisfyTarget(
        args.target, additional_config=args.config)
    if errors:
        for error in errors:
            logging.error(error)
        return 1
    if args.act_globally:
        # the npm behaviour here would be to install the working directory
        # module into the global modules dir
        raise NotImplementedError()
    else:
        # satisfyDependenciesRecursive will always prefer to install
        # dependencies in the yotta_modules directory of the top-level module,
        # so it's safe to set traverse_links here when we're only *installing*
        # modules (not updating them). This will never result in
        # Spooky-Action-Through-A-Symlink.
        components, errors = current_component.satisfyDependenciesRecursive(
            target=target,
            traverse_links=True,
            available_components=[(current_component.getName(),
                                   current_component)],
            test={
                'own': 'toplevel',
                'all': True,
                'none': False
            }[args.install_test_deps])
        return checkPrintStatus(errors, components, current_component, target)
Exemplo n.º 12
0
def installDeps(args, current_component):
    # settings, , load and save settings, internal
    from yotta.lib import settings

    logging.debug('install deps for %s' % current_component)
    if not current_component:
        logging.debug(str(current_component.getError()))
        logging.error('The current directory does not contain a valid module.')
        return 1
    # warn if the target hasn't been explicitly specified when running a build:
    # this is likely user-error
    if not settings.getProperty('build', 'targetSetExplicitly') and not \
        getattr(args, '_target_set_explicitly', False):
        logging.warning(
            'The build target has not been set, so the default (%s) is being ' +
            'used. You can use `yotta target <targetname>` to set the build ' +
            'target. See http://docs.yottabuild.org/tutorial/targets.html for '
            'more information on using targets.',
            args.target
        )
    target, errors = current_component.satisfyTarget(args.target, additional_config=args.config)
    if errors:
        for error in errors:
            logging.error(error)
        return 1
    if args.act_globally:
        # the npm behaviour here would be to install the working directory
        # module into the global modules dir
        raise NotImplementedError()
    else:
        # satisfyDependenciesRecursive will always prefer to install
        # dependencies in the yotta_modules directory of the top-level module,
        # so it's safe to set traverse_links here when we're only *installing*
        # modules (not updating them). This will never result in
        # Spooky-Action-Through-A-Symlink.
        components, errors = current_component.satisfyDependenciesRecursive(
                          target = target,
                  traverse_links = True,
            available_components = [(current_component.getName(), current_component)],
                            test = {'own':'toplevel', 'all':True, 'none':False}[args.install_test_deps]
        )
        return checkPrintStatus(errors, components, current_component, target)
Exemplo n.º 13
0
def hasGithubConfig():
    # can't run tests that hit github without an authn token
    if not settings.getProperty('github', 'authtoken'):
        return False
    return True
Exemplo n.º 14
0
def ensureGithubConfig():
    # ensure we have authentication for the test github account
    if not settings.getProperty('github', 'authtoken'):
        settings.setProperty('github', 'authtoken', Test_Access_Token)
Exemplo n.º 15
0
def hasGithubConfig():
    # can't run tests that hit github without an authn token
    if not settings.getProperty('github', 'authtoken'):
        return False
    return True
Exemplo n.º 16
0
def defaultTarget(ignore_set_target=False):
    set_target = settings.getProperty('build', 'target')
    if set_target:
        return set_target
    else:
        return kubosDefaultTarget()
Exemplo n.º 17
0
def _userAuthedWithGithub():
    return settings.getProperty('github', 'authtoken')
Exemplo n.º 18
0
def deauthorize():
    if settings.getProperty('github', 'authtoken'):
        settings.setProperty('github', 'authtoken', '')
    if settings.getProperty('mbed', 'authtoken'):
        settings.setProperty('mbed', 'authtoken', '')
Exemplo n.º 19
0
def _getTipArchiveURL(repo):
    ''' return a string containing a tarball url '''
    g = Github(settings.getProperty('github', 'authtoken'))
    repo = g.get_repo(repo)
    return repo.get_archive_link('tarball')
Exemplo n.º 20
0
def defaultTarget(ignore_set_target=False):
    set_target = settings.getProperty("build", "target")
    if set_target:
        return set_target
    else:
        return systemDefaultTarget()
Exemplo n.º 21
0
def _getBranchHeads(repo):
    g = Github(settings.getProperty('github', 'authtoken'))
    repo = g.get_repo(repo)
    branches = repo.get_branches()

    return {b.name: _tarballUrlForBranch(repo, b.name) for b in branches}
Exemplo n.º 22
0
def _userAuthedWithGithub():
    return settings.getProperty('github', 'authtoken')
Exemplo n.º 23
0
def _getCommitArchiveURL(repo, commit):
    ''' return a string containing a tarball url '''
    g = Github(settings.getProperty('github', 'authtoken'))
    repo = g.get_repo(repo)
    return repo.get_archive_link('tarball', commit)
Exemplo n.º 24
0
def _getBranchHeads(repo):
    g = Github(settings.getProperty('github', 'authtoken'))
    repo = g.get_repo(repo)
    branches = repo.get_branches()

    return {b.name:_tarballUrlForBranch(repo, b.name) for b in branches}
Exemplo n.º 25
0
def deauthorize():
    if settings.getProperty('github', 'authtoken'):
        settings.setProperty('github', 'authtoken', '')
    if settings.getProperty('mbed', 'authtoken'):
        settings.setProperty('mbed', 'authtoken', '')