Esempio n. 1
0
def _get_last_website_login(username):
    """ Retrieve from FAS the last time this user has been seen.

    :arg username, the fas username from who we would like to see the
        last connection in FAS.
    """
    from fedora.client import AccountSystem
    fasclient = AccountSystem()

    log.debug('Querying FAS for user: {0}'.format(username))
    try:
        import fedora_cert
        fasusername = fedora_cert.read_user_cert()
    except Exception:
        log.debug('Could not read Fedora cert, using login name')
        if PY3:
            fasusername = input('FAS username: '******'FAS username: '******'FAS password for %s: ' % fasusername)
    fasclient.username = fasusername
    fasclient.password = password
    person = fasclient.person_by_username(username)
    print('Last login in FAS:')
    print('   %s %s' % (username, person['last_seen'].split(' ')[0]))
    print()
def main():
    user_home = os.path.expanduser('~')
    print 'Setting up Fedora packager environment'
    user_cert = os.path.join(user_home, '.fedora.cert')
    upload_ca_cert = os.path.join(user_home, '.fedora-upload-ca.cert')
    server_ca_cert = os.path.join(user_home, '.fedora-server-ca.cert')
    if not os.path.isfile(user_cert):
        print '''You need a client certificate from the Fedora Account System, lets get one now'''
        fedora_cert.create_user_cert()
    else:
        #check if the cert has expired  if it has lets get a new one
        if fedora_cert.certificate_expired():
            username = fedora_cert.read_user_cert()
            print "Certificate has expired, getting a new one"
            fedora_cert.create_user_cert(username)

    download_cert('https://admin.fedoraproject.org/accounts/fedora-server-ca.cert', server_ca_cert)
    if not os.path.islink(upload_ca_cert):
        print 'Linking: ~/.fedora-server-ca.cert to ~/.fedora-upload-ca.cert'
        if os.path.exists(upload_ca_cert):
            os.unlink(upload_ca_cert)
        os.symlink(server_ca_cert, upload_ca_cert)
    if not os.path.isdir(os.path.join(user_home, '.koji')):
        os.mkdir(os.path.join(user_home, '.koji'))
    for arch in ['sparc', 'arm', 'alpha', 's390', 'hppa', 'ppc']:
        config_file = '%s/.koji/%s-config' % (user_home, arch)
        if not  os.path.isfile(config_file):
            write_arch_config(arch, config_file)
        else:
            print "koji config for %s exists. Replacing with new file." % arch
            os.unlink(config_file)
            write_arch_config(arch, config_file)
            
    print 'Setting up Browser Certificates'
    generate_browser_cert()
Esempio n. 3
0
def main(opts):
    # lets read in the existing cert if it exists.
    # gets us existing acc info
    if not opts.username:
        try:
            username = fedora_cert.read_user_cert()
        except:
            print "Can't determine fas name, lets get a new cert"
            fedora_cert.create_user_cert(None)
            sys.exit(0)
    else:
        username = opts.username
    #has cert expired? do we force a new cert? get a new one
    if opts.newcert:
        print "Getting a new User Certificate"
        fedora_cert.create_user_cert(username)
        sys.exit(0)
    if fedora_cert.certificate_expired():
        print "Certificate has expired, getting a new one"
        fedora_cert.create_user_cert(username)
        sys.exit(0)
    if opts.verifycert:
        print "Verifying Certificate"
        fedora_cert.verify_cert()
        print "CRL Checking not implemented yet"
Esempio n. 4
0
def build(args):
    # We may not actually nave an srpm arg if we come directly from the build task
    if hasattr(args, 'srpm') and args.srpm and not args.scratch:
        log.error('Non-scratch builds cannot be from srpms.')
        sys.exit(1)
    # Place holder for if we build with an uploaded srpm or not
    url = None
    # See if this is a chain or not
    chain = None
    if hasattr(args, 'chain'):
        chain = args.chain
    if not args.user:
        # Doing a try doesn't really work since the fedora_cert library just
        # exits on error, but if that gets fixed this will work better.
        try:
            args.user = fedora_cert.read_user_cert()
        except:
            log.debug('Could not read Fedora cert, using login name')
            args.user = os.getlogin()
    # Need to do something with BUILD_FLAGS or KOJI_FLAGS here for compat
    try:
        mymodule = pyfedpkg.PackageModule(args.path)
    except pyfedpkg.FedpkgError, e:
        # This error needs a better print out
        log.error('Could not use module: %s' % e)
        sys.exit(1)
Esempio n. 5
0
def build(args):
    # We may not actually nave an srpm arg if we come directly from the build task
    if hasattr(args, 'srpm') and args.srpm and not args.scratch:
        log.error('Non-scratch builds cannot be from srpms.')
        sys.exit(1)
    # Place holder for if we build with an uploaded srpm or not
    url = None
    # See if this is a chain or not
    chain = None
    if hasattr(args, 'chain'):
        chain = args.chain
    if not args.user:
        # Doing a try doesn't really work since the fedora_cert library just
        # exits on error, but if that gets fixed this will work better.
        try:
            args.user = fedora_cert.read_user_cert()
        except:
            log.debug('Could not read Fedora cert, using login name')
            args.user = os.getlogin()
    # Need to do something with BUILD_FLAGS or KOJI_FLAGS here for compat
    try:
        mymodule = pyfedpkg.PackageModule(args.path)
    except pyfedpkg.FedpkgError, e:
        # This error needs a better print out
        log.error('Could not use module: %s' % e)
        sys.exit(1)
def validateFedoraUser(request):
    # Setup FAS client
    fasclient = AccountSystem()
    try:
        fasusername = fedora_cert.read_user_cert()
        print " * FAS username: %s" % fasusername
    except:
        fasusername = raw_input(' * FAS username: '******' * FAS password: ')
    fasclient.username = fasusername
    fasclient.password = password

    # Query user
    fasid = request["fasid"]
    email = request["email"]
    person = fasclient.person_by_username(fasid)

    # Validate user
    if not person:
        raise Exception("Request submitter %s does not match a known FAS username" % fasid)

    if not person["bugzilla_email"] == email:
        raise Exception("Email %s of request submitter does not match email of specified FAS user %s" % (email, fasid))

    if "cla_fpca" not in person["group_roles"] or person["group_roles"]["cla_fpca"]["role_status"] != "approved":
        raise Exception("Request submitter %s has not signed the Fedora Project Contributor Agreement" % fasid)

    if "packager" not in person["group_roles"] or person["group_roles"]["packager"]["role_status"] != "approved":
        if request["branches"].difference(set(["master"])):
            raise Exception("Request contains patches for stable-release branches, but user %s is not a packager" % fasid)

    print " => User %s successfully validated" % fasid
Esempio n. 7
0
 def load_user(self):
     """This sets the user attribute, based on the Fedora SSL cert."""
     try:
         self._user = fedora_cert.read_user_cert()
     except Exception, e:
         self.log.debug('Could not read Fedora cert, falling back to '
                        'default method: %s' % e)
         super(Commands, self).load_user()
Esempio n. 8
0
 def load_user(self):
     """This sets the user attribute, based on the Fedora SSL cert."""
     try:
         self._user = fedora_cert.read_user_cert()
     except Exception, e:
         self.log.debug('Could not read Fedora cert, falling back to '
                        'default method: %s' % e)
         super(Commands, self).load_user()
 def fill_urls(self):
     """ Fill the spec and src.rpm urls into the info table using the
     info in the settings.
     """
     try:
         fasusername = fedora_cert.read_user_cert()
     except:
         self.log.debug('Could not read Fedora cert, using login name')
         fasusername = raw_input('FAS username: '******'public_html/')[1]
     url = 'http://%s.fedorapeople.org/%s/' % (fasusername, complement_url)
     self.info['specurl'] = url + os.path.basename(self.specfile)
     self.info['srpmurl'] = url + os.path.basename(self.srpmfile)
Esempio n. 10
0
 def fill_urls(self):
     """ Fill the spec and src.rpm urls into the info table using the
     info in the settings.
     """
     try:
         fasusername = fedora_cert.read_user_cert()
     except:
         self.log.debug('Could not read Fedora cert, using login name')
         fasusername = raw_input('FAS username: '******'public_html/')[1]
     url = 'http://%s.fedorapeople.org/%s/' % (fasusername, complement_url)
     self.info['specurl'] = url + os.path.basename(self.specfile)
     self.info['srpmurl'] = url + os.path.basename(self.srpmfile)
Esempio n. 11
0
def main(opts):
    # lets read in the existing cert if it exists.
    # gets us existing acc info
    if not opts.username:
        try:
            username = fedora_cert.read_user_cert()
        except:
            print "Can't determine fas name, lets get a new cert"
            try:
                fedora_cert.create_user_cert(None)
            except  fedora_cert.fedora_cert_error, e:
                print e
                sys.exit(1)
            sys.exit(0)
Esempio n. 12
0
    def _git_release(self):

        commands.getoutput("mkdir -p %s" % self.cvs_workdir)
        os.chdir(self.cvs_workdir)
        user = fedora_cert.read_user_cert()
        pyfedpkg.clone(self.project_name, user, self.cvs_workdir)

        project_checkout = os.path.join(self.cvs_workdir, self.project_name)
        os.chdir(project_checkout)
        run_command("fedpkg switch-branch %s" % self.git_branches[0])

        self.builder.tgz()

        self._git_sync_files(project_checkout)
        self._git_upload_sources(project_checkout)
        self._git_user_confirm_commit(project_checkout)
Esempio n. 13
0
def _get_last_website_login(username):
    """ Retrieve from FAS the last time this user has been seen.

    :arg username, the fas username from who we would like to see the
        last connection in FAS.
    """
    try:
        fasusername = fedora_cert.read_user_cert()
    except:
        log.debug('Could not read Fedora cert, using login name')
        fasusername = raw_input('FAS username: '******'   FAS password for %s: ' % fasusername)
    fasclient.username = fasusername
    fasclient.password = password
    person = fasclient.person_by_username(username)
    print '  ', username, person['last_seen']
Esempio n. 14
0
def clone(args):
    if not args.user:
        # Doing a try doesn't really work since the fedora_cert library just
        # exits on error, but if that gets fixed this will work better.
        try:
            args.user = fedora_cert.read_user_cert()
        except:
            log.debug('Could not read Fedora cert, using login name')
            args.user = os.getlogin()
    try:
        if args.branches:
            pyfedpkg.clone_with_dirs(args.module[0], args.user)
        else:
            pyfedpkg.clone(args.module[0], args.user, args.path, args.branch)
    except pyfedpkg.FedpkgError, e:
        log.error('Could not clone: %s' % e)
        sys.exit(1)
Esempio n. 15
0
def clone(args):
    if not args.user:
        # Doing a try doesn't really work since the fedora_cert library just
        # exits on error, but if that gets fixed this will work better.
        try:
            args.user = fedora_cert.read_user_cert()
        except:
            log.debug('Could not read Fedora cert, using login name')
            args.user = os.getlogin()
    try:
        if args.branches:
            pyfedpkg.clone_with_dirs(args.module[0], args.user)
        else:
            pyfedpkg.clone(args.module[0], args.user, args.path, args.branch)
    except pyfedpkg.FedpkgError, e:
        log.error('Could not clone: %s' % e)
        sys.exit(1)
Esempio n. 16
0
def ask_password(username=None, bad_password=False):
    """ Example login_callback to ask username/password from user
    :kwarg username: Username
    :type username: str
    :kwarg bad_password: Whether there was a previous failed login attempt
    :type bad_password: bool
    :return: username, password
    :rtype: tuple
    """
    if bad_password:
        print("Bad password, please retry")
    if not username:
        try:
            username = fedora_cert.read_user_cert()
        except fedora_cert.fedora_cert_error:
            LOG.debug('Could not read Fedora cert, asking for username')
            username = input("Username: "******"FAS password for user {0}: ".format(username))
    return username, password
Esempio n. 17
0
def ask_password(username=None, bad_password=False):
    """ Example login_callback to ask username/password from user
    :kwarg username: Username
    :type username: str
    :kwarg bad_password: Whether there was a previous failed login attempt
    :type bad_password: bool
    :return: username, password
    :rtype: tuple
    """
    if bad_password:
        print("Bad password, please retry")
    if not username:
        try:
            username = fedora_cert.read_user_cert()
        except fedora_cert.fedora_cert_error:
            LOG.debug('Could not read Fedora cert, asking for username')
            username = input("Username: "******"FAS password for user {0}: ".format(username))
    return username, password
def _get_last_website_login(username):
    """ Retrieve from FAS the last time this user has been seen.

    :arg username, the fas username from who we would like to see the
        last connection in FAS.
    """
    from fedora.client import AccountSystem
    fasclient = AccountSystem()

    log.debug('Querying FAS for user: {0}'.format(username))
    try:
        fasusername = fedora_cert.read_user_cert()
    except Exception:
        log.debug('Could not read Fedora cert, using login name')
        fasusername = raw_input('FAS username: '******'FAS password for %s: ' % fasusername)
    fasclient.username = fasusername
    fasclient.password = password
    person = fasclient.person_by_username(username)
    print('Last login in FAS:')
    print('   %s %s' % (username, person['last_seen'].split(' ')[0]))
Esempio n. 19
0
def __do_login(username=None, password=None):
    ''' Returned a BaseClient with authentification

    If the username is None, tries to retrieve it from fedora_cert.

    :arg pkgdbclient a PackageDB object to which username and password
    are added
    :karg username FAS username, if None it is asked to the user
    :karg password FAS password, if None it is asked to the user
    '''
    if pkgdbclient.is_logged_in:
        return
    else:
        if username is None:
            try:
                username = fedora_cert.read_user_cert()
            except:
                LOG.debug('Could not read Fedora cert, using login name')
                username = raw_input('FAS username: '******'FAS password: ')
        pkgdbclient.username = username
        pkgdbclient.login(username, password)
def main():
    user_home = os.path.expanduser('~')
    print 'Setting up Fedora packager environment'
    user_cert = os.path.join(user_home, '.fedora.cert')
    upload_ca_cert = os.path.join(user_home, '.fedora-upload-ca.cert')
    server_ca_cert = os.path.join(user_home, '.fedora-server-ca.cert')
    if not os.path.isfile(user_cert):
        print '''You need a client certificate from the Fedora Account System, lets get one now'''
        fedora_cert.create_user_cert()
    else:
        #check if the cert has expired  if it has lets get a new one
        if fedora_cert.certificate_expired():
            username = fedora_cert.read_user_cert()
            print "Certificate has expired, getting a new one"
            fedora_cert.create_user_cert(username)

    download_cert(
        'https://admin.fedoraproject.org/accounts/fedora-server-ca.cert',
        server_ca_cert)
    if not os.path.islink(upload_ca_cert):
        print 'Linking: ~/.fedora-server-ca.cert to ~/.fedora-upload-ca.cert'
        if os.path.exists(upload_ca_cert):
            os.unlink(upload_ca_cert)
        os.symlink(server_ca_cert, upload_ca_cert)
    if not os.path.isdir(os.path.join(user_home, '.koji')):
        os.mkdir(os.path.join(user_home, '.koji'))
    for arch in ['sparc', 'arm', 'alpha', 's390', 'hppa', 'ppc']:
        config_file = '%s/.koji/%s-config' % (user_home, arch)
        if not os.path.isfile(config_file):
            write_arch_config(arch, config_file)
        else:
            print "koji config for %s exists. Replacing with new file." % arch
            os.unlink(config_file)
            write_arch_config(arch, config_file)

    print 'Setting up Browser Certificates'
    generate_browser_cert()
            retcode = call("%s /usr/bin/cvs -d %s co %s" %
                           (cvs_env, cvs_root, module),
                           shell=True)
            if retcode < 0:
                print >> sys.stderr, "CVS Checkout failed Error:", -retcode
        except OSError, e:
            print >> sys.stderr, "Execution failed:", e


if __name__ == '__main__':
    opt_p = optparse.OptionParser(usage="%prog [OPTIONS] module ...")

    opt_p.add_option('-a',
                     '--anonymous',
                     action='store_true',
                     dest='anon',
                     help="Use anonymous CVS.")

    opts, pkgs = opt_p.parse_args()

    if len(pkgs) < 1:
        opt_p.error("You must specify at least one module to check out.")

    # Determine user name, if any
    if opts.anon:
        user = None
    else:
        user = fedora_cert.read_user_cert()

    main(user, pkgs)
Esempio n. 22
0
 def username(self):
     import fedora_cert
     return fedora_cert.read_user_cert()
Esempio n. 23
0
import os
import tempfile

import datetime

import requests
import fedora_cert
import xmlrpclib

from bugzilla import Bugzilla
from fedora.client import AccountSystem, AuthError

import pkgdb2client

try:
    USERNAME = fedora_cert.read_user_cert()
except fedora_cert.fedora_cert_error:
    pkgdb2client.LOG.debug('Could not read Fedora cert, asking for username')
    USERNAME = None

RH_BZ_API = 'https://bugzilla.redhat.com/xmlrpc.cgi'
BZCLIENT = None
FASCLIENT = AccountSystem('https://admin.fedoraproject.org/accounts',
                          username=USERNAME)


def _get_bz(url=RH_BZ_API, insecure=False):
    ''' Return a bugzilla object. '''
    global BZCLIENT
    if not BZCLIENT:
        BZCLIENT = Bugzilla(url=url)
Esempio n. 24
0
 def username(self):
     import fedora_cert
     return fedora_cert.read_user_cert()
Esempio n. 25
0
import os
import tempfile

import datetime

import requests
import fedora_cert
import xmlrpclib

from bugzilla import Bugzilla
from fedora.client import AccountSystem, AuthError

import pkgdb2client

try:
    USERNAME = fedora_cert.read_user_cert()
except fedora_cert.fedora_cert_error:
    pkgdb2client.LOG.debug('Could not read Fedora cert, asking for username')
    USERNAME = None

BZCLIENT = None
FASCLIENT = None


def _get_bz(url=pkgdb2client.BZ_URL, insecure=False):
    ''' Return a bugzilla object. '''
    global BZCLIENT
    if not BZCLIENT or BZCLIENT.url != url:
        BZCLIENT = Bugzilla(url=url)

    BZCLIENT._sslverify = not insecure
    print 'Setting up Fedora packager environment'
    user_cert = os.path.join(user_home, '.fedora.cert')
    upload_ca_cert = os.path.join(user_home, '.fedora-upload-ca.cert')
    server_ca_cert = os.path.join(user_home, '.fedora-server-ca.cert')
    if not os.path.isfile(user_cert):
        print '''You need a client certificate from the Fedora Account System, lets get one now'''
        try:
            fedora_cert.create_user_cert()
        except  fedora_cert.fedora_cert_error, e:
            print e
            sys.exit(1)
    else:
        #check if the cert has expired  if it has lets get a new one
        try:
            if fedora_cert.certificate_expired():
                username = fedora_cert.read_user_cert()
                print "Certificate has expired, getting a new one"
                fedora_cert.create_user_cert(username)
        except  fedora_cert.fedora_cert_error, e:
            print e
            sys.exit(1)

    download_cert('https://admin.fedoraproject.org/accounts/fedora-server-ca.cert', server_ca_cert)
    if not os.path.islink(upload_ca_cert):
        print 'Linking: ~/.fedora-server-ca.cert to ~/.fedora-upload-ca.cert'
        if os.path.exists(upload_ca_cert):
            os.unlink(upload_ca_cert)
        os.symlink(server_ca_cert, upload_ca_cert)
    if not os.path.isdir(os.path.join(user_home, '.koji')):
        os.mkdir(os.path.join(user_home, '.koji'))
    for arch in ['sparc', 'arm', 'alpha', 's390', 'hppa', 'ppc', 'mips']:
Esempio n. 27
0
        cvs_env = ""
        cvs_root = ":pserver:anonymous@" + PKG_ROOT

    for module in pkg_list:
        print "Checking out %s from fedora CVS as %s:" % (module, user or "anonymous")
        try:
            retcode = call("%s /usr/bin/cvs -d %s co %s" % (cvs_env, cvs_root, module), shell=True)
            if retcode < 0:
                print >> sys.stderr, "CVS Checkout failed Error:", -retcode
        except OSError, e:
            print >> sys.stderr, "Execution failed:", e


if __name__ == "__main__":
    opt_p = optparse.OptionParser(usage="%prog [OPTIONS] module ...")

    opt_p.add_option("-a", "--anonymous", action="store_true", dest="anon", help="Use anonymous CVS.")

    opts, pkgs = opt_p.parse_args()

    if len(pkgs) < 1:
        opt_p.error("You must specify at least one module to check out.")

    # Determine user name, if any
    if opts.anon:
        user = None
    else:
        user = fedora_cert.read_user_cert()

    main(user, pkgs)