Ejemplo n.º 1
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
Ejemplo n.º 2
0
def _pollForAuth(registry=None):
    tokens = registry_access.getAuthData(registry=registry)
    if tokens:
        if 'github' in tokens:
            settings.setProperty('github', 'authtoken', tokens['github'])
        if 'mbed' in tokens:
            settings.setProperty('mbed', 'authtoken', tokens['mbed'])
        return True
    return False
Ejemplo n.º 3
0
def _pollForAuth(registry=None):
    tokens = registry_access.getAuthData(registry=registry)
    if tokens:
        if 'github' in tokens:
            settings.setProperty('github', 'authtoken', tokens['github'])
        if 'mbed' in tokens:
            settings.setProperty('mbed', 'authtoken', tokens['mbed'])
        return True
    return False
Ejemplo n.º 4
0
def execCommand(args, following_args):
    if args.set_target is None:
        return displayCurrentTarget(args)
    else:
        if not Target_RE.match(args.set_target):
            logging.error('Invalid target: "%s"' %
                          args.set_target)  #, targets must be one of:
            #
            #    a valid name (lowercase letters, numbers, and hyphen)
            #    a github ref (owner/project)
            #    a valid url
            #
            #Note that to use a local directory as a target you can use
            #
            #    # in the directory containing the target package:
            #    yotta link target
            #
            #    # then in the directory of the application to use the target:
            #    yotta link target {targetname}
            #    yotta target {targetname}
            #
            #''')
            return 1
        else:
            if args.set_target.find(',') == -1:
                t = args.set_target + ',*'
            else:
                t = args.set_target
            settings.setProperty('build', 'target', t, not args.save_global)
            settings.setProperty('build', 'targetSetExplicitly', True,
                                 not args.save_global)
            if not args.no_install:
                # if we have a module in the current directory, try to make sure
                # this target is installed
                c = component.Component(os.getcwd())
                if c:
                    target, errors = c.satisfyTarget(t)
                    for err in errors:
                        logging.error(err)
                    if len(errors):
                        logging.error(
                            'NOTE: use "yotta link-target" to test a locally modified target prior to publishing.'
                        )
                        return 1
            return 0
Ejemplo n.º 5
0
def execCommand(args, following_args):
    if args.set_target is None:
        return displayCurrentTarget(args)
    else:
        if not Target_RE.match(args.set_target):
            logging.error('Invalid target: "%s"' % args.set_target)#, targets must be one of:
            #
            #    a valid name (lowercase letters, numbers, and hyphen)
            #    a github ref (owner/project)
            #    a valid url
            #
            #Note that to use a local directory as a target you can use
            #
            #    # in the directory containing the target package:
            #    yotta link target
            #
            #    # then in the directory of the application to use the target:
            #    yotta link target {targetname}
            #    yotta target {targetname}
            #
            #''')
            return 1
        else:
            if args.set_target.find(',') == -1:
                t = args.set_target + ',*'
            else:
                t = args.set_target
            settings.setProperty('build', 'target', t, not args.save_global)
            settings.setProperty('build', 'targetSetExplicitly', True, not args.save_global)
            if not args.no_install:
                # if we have a module in the current directory, try to make sure
                # this target is installed
                c = component.Component(os.getcwd())
                if c:
                    target, errors = c.satisfyTarget(t)
                    for err in errors:
                        logging.error(err)
                    if len(errors):
                        logging.error('NOTE: use "yotta link-target" to test a locally modified target prior to publishing.')
                        return 1
            return 0
Ejemplo n.º 6
0
def execCommand(args, following_args):
    if args.set_target is None:
        return displayCurrentTarget(args)
    else:
        from yotta.lib import sourceparse
        from yotta.lib import validate

        name, spec = sourceparse.parseTargetNameAndSpec(args.set_target)
        if not re.match(validate.Target_Name_Regex, name):
            logging.error(
                'Invalid target name: "%s" should use only a-z 0-9 - and +, and start with a letter.'
                % name)
            return 1
        if not sourceparse.isValidSpec(spec):
            logging.error(
                'Could not parse target version specification: "%s"' % spec)
            return 1

        # separating the target name and spec is still done with a comma
        # internally (for now at least), although @ is the recommended way to
        # set it:
        t = '%s,%s' % (name, spec)

        settings.setProperty('build', 'target', t, not args.save_global)
        settings.setProperty('build', 'targetSetExplicitly', True,
                             not args.save_global)
        if not args.no_install:
            # if we have a module in the current directory, try to make sure
            # this target is installed
            c = component.Component(os.getcwd())
            if c:
                target, errors = c.satisfyTarget(t)
                for err in errors:
                    logging.error(err)
                if len(errors):
                    logging.error(
                        'NOTE: use "yotta link-target" to test a locally modified target prior to publishing.'
                    )
                    return 1
        return 0
Ejemplo n.º 7
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
Ejemplo n.º 8
0
def deauthorize():
    if settings.getProperty('github', 'authtoken'):
        settings.setProperty('github', 'authtoken', '')
    if settings.getProperty('mbed', 'authtoken'):
        settings.setProperty('mbed', 'authtoken', '')
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
def deauthorize():
    if settings.getProperty('github', 'authtoken'):
        settings.setProperty('github', 'authtoken', '')
    if settings.getProperty('mbed', 'authtoken'):
        settings.setProperty('mbed', 'authtoken', '')