Exemple #1
0
def user(config):

    master = config.get('master')
    op = config.get('op')
    username = config.get('username')
    passwd = config.get('passwd')
    master, port = master.split(":")
    port = int(port)
    bb_username = config.get('bb_username')
    bb_password = config.get('bb_password')
    if bb_username or bb_password:
        bb_password = users.encrypt(bb_password)
    info = config.get('info')
    ids = config.get('ids')

    # find identifier if op == add
    if info and op == 'add':
        for user in info:
            user['identifier'] = sorted(user.values())[0]

    uc = usersclient.UsersClient(master, username, passwd, port)
    output = yield uc.send(op, bb_username, bb_password, ids, info)
    if output:
        print(output)

    defer.returnValue(0)
    def test_usersclient_send_update_info(self):
        encrypted = users.encrypt("day")

        def _fake_encrypt(passwd):
            return encrypted

        self.patch(users, "encrypt", _fake_encrypt)

        d = runner.users_client(
            dict(
                master="a:9990",
                username="******",
                passwd="y",
                op="update",
                bb_username="******",
                bb_password="******",
                ids=None,
                info=[{"identifier": "x", "svn": "x"}],
            )
        )

        def check(_):
            c = self.usersclient
            self.assertEqual(
                (c.master, c.port, c.username, c.passwd, c.op, c.bb_username, c.bb_password, c.ids, c.info),
                ("a", 9990, "x", "y", "update", "bud", encrypted, None, [{"identifier": "x", "svn": "x"}]),
            )

        d.addCallback(check)
        return d
Exemple #3
0
def user(config):

    master = config.get('master')
    op = config.get('op')
    username = config.get('username')
    passwd = config.get('passwd')
    master, port = master.split(":")
    port = int(port)
    bb_username = config.get('bb_username')
    bb_password = config.get('bb_password')
    if bb_username or bb_password:
        bb_password = users.encrypt(bb_password)
    info = config.get('info')
    ids = config.get('ids')

    # find identifier if op == add
    if info and op == 'add':
        for user in info:
            user['identifier'] = sorted(user.values())[0]

    uc = usersclient.UsersClient(master, username, passwd, port)
    output = yield uc.send(op, bb_username, bb_password, ids, info)
    if output:
        print(output)

    defer.returnValue(0)
    def test_usersclient_send_update_info(self):
        encrypted = users.encrypt("day")
        def _fake_encrypt(passwd):
            return encrypted
        self.patch(users, 'encrypt', _fake_encrypt)

        d = runner.users_client(dict(master='a:9990', username="******",
                                     passwd="y", op='update', bb_username='******',
                                     bb_password='******', ids=None,
                                     info=[{'identifier':'x', 'svn':'x'}]))
        def check(_):
            c = self.usersclient
            self.assertEqual((c.master, c.port, c.username, c.passwd, c.op,
                              c.bb_username, c.bb_password, c.ids, c.info),
                             ('a', 9990, "x", "y", 'update', 'bud', encrypted,
                              None, [{'identifier':'x', 'svn':'x'}]))
        d.addCallback(check)
        return d
def users_client(config, runReactor=False):
    from buildbot.clients import usersclient
    from buildbot.process.users import users  # for srcs, encrypt

    # accepted attr_types by `buildbot user`, in addition to users.srcs
    attr_types = ['identifier', 'email']

    master = config.get('master')
    assert master, "you must provide the master location"
    try:
        master, port = master.split(":")
        port = int(port)
    except:
        raise AssertionError("master must have the form 'hostname:port'")

    op = config.get('op')
    assert op, "you must specify an operation: add, remove, update, get"
    if op not in ['add', 'remove', 'update', 'get']:
        raise AssertionError("bad op %r, use 'add', 'remove', 'update', "
                             "or 'get'" % op)

    username = config.get('username')
    passwd = config.get('passwd')
    assert username and passwd, "A username and password pair must be given"

    bb_username = config.get('bb_username')
    bb_password = config.get('bb_password')
    if bb_username or bb_password:
        if op != 'update':
            raise AssertionError("bb_username and bb_password only work "
                                 "with update")
        if not bb_username or not bb_password:
            raise AssertionError("Must specify both bb_username and "
                                 "bb_password or neither.")

        bb_password = users.encrypt(bb_password)

    # check op and proper args
    info = config.get('info')
    ids = config.get('ids')

    # check for erroneous args
    if not info and not ids:
        raise AssertionError("must specify either --ids or --info")
    if info and ids:
        raise AssertionError("cannot use both --ids and --info, use "
                             "--ids for 'remove' and 'get', --info "
                             "for 'add' and 'update'")

    if op == 'add' or op == 'update':
        if ids:
            raise AssertionError("cannot use --ids with 'add' or 'update'")
        if op == 'update':
            for user in info:
                if 'identifier' not in user:
                    raise ValueError("no ids found in update info, use: "
                                     "--info=id:type=value,type=value,..")
        if op == 'add':
            for user in info:
                if 'identifier' in user:
                    raise ValueError("id found in add info, use: "
                                     "--info=type=value,type=value,..")
    if op == 'remove' or op == 'get':
        if info:
            raise AssertionError("cannot use --info with 'remove' or 'get'")

    # find identifier if op == add
    if info:
        # check for valid types
        for user in info:
            for attr_type in user:
                if attr_type not in users.srcs + attr_types:
                    raise ValueError("Type not a valid attr_type, must be in: "
                                     "%r" % (users.srcs + attr_types))

            if op == 'add':
                user['identifier'] = user.values()[0]

    uc = usersclient.UsersClient(master, username, passwd, port)
    d = uc.send(op, bb_username, bb_password, ids, info)

    if runReactor:
        from twisted.internet import reactor
        status = [True]

        def printSuccess(res):
            print res

        def failed(f):
            status[0] = False
            print "user op NOT sent - something went wrong: " + str(f)

        d.addCallbacks(printSuccess, failed)
        d.addBoth(lambda _: reactor.stop())
        reactor.run()
        return status[0]
    return d
 def setUp(self):
     self.master = fakemaster.make_master(testcase=self, wantDb=True)
     self.db = self.master.db
     self.test_sha = users.encrypt("cancer")
 def setUp(self):
     self.master = mock.Mock()
     self.master.db = self.db = fakedb.FakeDBConnector(self)
     self.test_sha = users.encrypt("cancer")
Exemple #8
0
 def setUp(self):
     self.master = mock.Mock()
     self.master.db = self.db = fakedb.FakeDBConnector(self)
     self.test_sha = users.encrypt("cancer")
Exemple #9
0
 def setUp(self):
     self.setup_test_reactor()
     self.master = fakemaster.make_master(self, wantDb=True)
     self.db = self.master.db
     self.test_sha = users.encrypt("cancer")
 def setUp(self):
     self.master = fakemaster.make_master(testcase=self, wantDb=True)
     self.db = self.master.db
     self.test_sha = users.encrypt("cancer")
 def setUp(self):
     self.setUpTestReactor()
     self.master = fakemaster.make_master(self, wantDb=True)
     self.db = self.master.db
     self.test_sha = users.encrypt("cancer")