Esempio n. 1
0
def set_get_user_pass(service):
	
	# store username and password in keychain if not found
	if not service in [x[0] for x in keychain.get_services()]:
		print 'Keychain does not contain %s username and password.' % service
		username = raw_input('Enter your %s username and press enter:' % service)
		password = raw_input('Enter your %s password and press enter:' % service)
		print 'Username %s and password saved for %s.' % (username, service)
		keychain.set_password(service, username, password)
		
	else:
		# get the username---can be multiple accounts for one service
		usernamelist = [x[1] for x in keychain.get_services() if x[0]==service]
		
		if len(usernamelist) > 1:
			print 'Multiple usernames were found for %s.' % service
			for uname in enumerate(usernamelist):
				print '     [%d]: %s'%(uname[0]+1, uname[1])
			unum = int(raw_input('Enter the number of the correct one:').strip()) - 1
			username = usernamelist[unum]
		else:
			username = usernamelist[0]
			
		# get the password based on correct username
		password = keychain.get_password(service, username)
	
	return username, password
Esempio n. 2
0
def git_push(args):
    parser = argparse.ArgumentParser(prog='git push'
                                     , usage='git push [http(s)://<remote repo> or remote] [-u username[:password]]'
                                     , description="Push to a remote repository")
    parser.add_argument('url', type=str, nargs='?', help='URL to push to')
    parser.add_argument('-u', metavar='username[:password]', type=str, required=False, help='username[:password]')
    result = parser.parse_args(args)

    user, sep, pw = result.u.partition(':') if result.u else (None,None,None)

    repo = _get_repo()

    origin='origin'
    if not result.url:
        result.url = repo.remotes.get('origin','')
    if result.url in repo.remotes:
        origin=result.url
        result.url=repo.remotes.get(origin)

    branch_name = os.path.join('refs','heads', repo.active_branch)  #'refs/heads/%s' % repo.active_branch

    print "Attempting to push to: {0}, branch: {1}".format(result.url, branch_name)

    netloc = urlparse.urlparse(result.url).netloc

    keychainservice = 'stash.git.{0}'.format(netloc)

    if sep and not user:
        # -u : clears keychain for this server
        for service in keychain.get_services():
            if service[0]==keychainservice:
                keychain.delete_password(*service)

    #Attempt to retrieve user
    if not user and SAVE_PASSWORDS and result.url.startswith('http'):
        try:
            user = dict(keychain.get_services())[keychainservice]
        except KeyError:
            user = raw_input('Enter username: '******'Enter password: '******'Enter credentials for {0}'.format(netloc))

    if user:
        if not pw and SAVE_PASSWORDS:
            pw = keychain.get_password(keychainservice, user)

        #Check again, did we retrieve a password?
        if not pw:
            user, pw = console.login_alert('Enter credentials for {0}'.format(netloc), login=user)
            #pw = getpass.getpass('Enter password for {0}: '.format(user))
        host_with_auth='{}:{}@{}'.format(user,pw,netloc)
        url=urlparse.urlunparse(
            urlparse.urlparse(result.url)._replace(
                netloc=host_with_auth))
        porcelain.push(repo.repo.path, url, branch_name)
        keychain.set_password(keychainservice, user, pw)

    else:
        porcelain.push(repo.repo.path, result.url, branch_name)
    print 'success!'
Esempio n. 3
0
def set_get_user_pass(service):

    # store username and password in keychain if not found
    if not service in [x[0] for x in keychain.get_services()]:
        print 'Keychain does not contain %s username and password.' % service
        username = raw_input('Enter your %s username and press enter:' %
                             service)
        password = raw_input('Enter your %s password and press enter:' %
                             service)
        print 'Username %s and password saved for %s.' % (username, service)
        keychain.set_password(service, username, password)

    else:
        # get the username---can be multiple accounts for one service
        usernamelist = [
            x[1] for x in keychain.get_services() if x[0] == service
        ]

        if len(usernamelist) > 1:
            print 'Multiple usernames were found for %s.' % service
            for uname in enumerate(usernamelist):
                print '     [%d]: %s' % (uname[0] + 1, uname[1])
            unum = int(
                raw_input('Enter the number of the correct one:').strip()) - 1
            username = usernamelist[unum]
        else:
            username = usernamelist[0]

        # get the password based on correct username
        password = keychain.get_password(service, username)

    return username, password
Esempio n. 4
0
    def git_push(args):
        parser = argparse.ArgumentParser(prog='git push'
                                         , usage='git push [http(s)://<remote repo>] [-u username[:password]]'
                                         , description="Push to a remote repository")
        parser.add_argument('url', type=str, nargs='?', help='URL to push to')
        parser.add_argument('-u', metavar='username[:password]', type=str, required=False, help='username[:password]')
        result = parser.parse_args(args)

        user, sep, pw = result.u.partition(':') if result.u else (None,None,None)

        repo = _get_repo()
        
        #Try to get the remote origin
        if not result.url:
            result.url = repo.remotes.get('origin','')

        branch_name = os.path.join('refs','heads', repo.active_branch)  #'refs/heads/%s' % repo.active_branch

        print "Attempting to push to: {0}, branch: {1}".format(result.url, branch_name)

        netloc = urlparse.urlparse(result.url).netloc

        keychainservice = 'shellista.git.{0}'.format(netloc)

        if sep and not user:
            # -u : clears keychain for this server
            for service in keychain.get_services():
                if service[0]==keychainservice:
                    keychain.delete_password(*service)

        #Attempt to retrieve user
        if not user and SAVE_PASSWORDS:
            try:
                user = dict(keychain.get_services())[keychainservice]
            except KeyError:
                user, pw = console.login_alert('Enter credentials for {0}'.format(netloc))

        if user:
            if not pw and SAVE_PASSWORDS:
                pw = keychain.get_password(keychainservice, user)

            #Check again, did we retrieve a password?
            if not pw:
                user, pw = console.login_alert('Enter credentials for {0}'.format(netloc), login=user)
                #pw = getpass.getpass('Enter password for {0}: '.format(user))

            opener = auth_urllib2_opener(None, result.url, user, pw)

            porcelain.push(repo.repo, result.url, branch_name, opener=opener)
            keychain.set_password(keychainservice, user, pw)

        else:
            porcelain.push(repo.repo, result.url, branch_name)
Esempio n. 5
0
 def do_list(self, cmd):
     """list: lists the dropbox usernames."""
     self.stdout.write("\n")
     for service, account in keychain.get_services():
         if service == dbutils.DB_SERVICE:
             self.stdout.write(account + "\n")
     self.stdout.write("\n")
Esempio n. 6
0
	def do_list(self, cmd):
		"""list: lists the dropbox usernames."""
		print
		for service, account in keychain.get_services():
			if service == dbutils.DB_SERVICE:
				print account
		print
Esempio n. 7
0
	def do_list(self, cmd):
		"""list: lists the dropbox usernames."""
		self.stdout.write("\n")
		for service, account in keychain.get_services():
			if service == dbutils.DB_SERVICE:
				self.stdout.write(account + "\n")
		self.stdout.write("\n")
Esempio n. 8
0
File: gh.py Progetto: ywangd/stash
def setup_gh():
	keychainservice='stash.git.github.com'
	user = dict(keychain.get_services())[keychainservice]
	pw = keychain.get_password(keychainservice, user)
	g=Github(user,pw)
	u=g.get_user()
	
	return g, u
Esempio n. 9
0
File: gh.py Progetto: zychen/stash
def setup_gh():
    keychainservice = 'stash.git.github.com'
    user = dict(keychain.get_services())[keychainservice]
    pw = keychain.get_password(keychainservice, user)
    g = Github(user, pw)
    u = g.get_user()

    return g, u
Esempio n. 10
0
 def get_services(self, blob=None):
     if blob and os.path.isfile(blob):
         import lastpass
         email = keychain.get_password('lastpass_email', 'lastpass')
         password = keychain.get_password('lastpass_master', 'lastpass') or ''
         email, password = console.login_alert('LastPass login', '', email, password)
         vault = lastpass.Vault.open_local(blob, email, password)
         return [(x.name, x.username, x.password) for x in vault.accounts]
     else:
         return keychain.get_services()
Esempio n. 11
0
    def push_action(self, sender):
        # pdb.set_trace()
        user, sep, pw = (None, None, None)
        repo = self._get_repo()

        remote = self.view['remote'].text
        if remote in self.remotes_iterator():
            remote = repo.remotes.get(remote, '')

        branch_name = os.path.join(
            'refs', 'heads',
            repo.active_branch)  #'refs/heads/%s' % repo.active_branch
        # tODO  use remote branch_name

        netloc = urlparse.urlparse(remote).netloc

        keychainservice = 'shellista.git.{0}'.format(netloc)

        #define some callbacks for use by uidialog
        def push_callback(user, pw):
            print "Attempting to push to: {0}, branch: {1}".format(
                remote, branch_name)
            console.show_activity()
            if user:
                try:
                    parsedurl = urlparse.urlparse(remote)
                    host_with_auth = '{}:{}@{}'.format(user, pw,
                                                       parsedurl.netloc)
                    url = urlparse.urlunparse(
                        parsedurl._replace(netloc=host_with_auth))
                    porcelain.push(repo.path, url, branch_name)
                    keychain.set_password(keychainservice, user, pw)
                except urllib2.URLError:
                    console.hide_activity()
                    console.hud_alert('push failed', 'error')
                    return
            else:
                porcelain.push(repo.repo, result.url, branch_name)
            console.hide_activity()
            console.hud_alert('push complete')

        def push_callback_dict(d):
            push_callback(d['username'], d['password'])

        #Attempt to retrieve user
        try:
            user = dict(keychain.get_services())[keychainservice]
            pw = keychain.get_password(keychainservice, user)
            if pw:
                push_callback(user, pw)
            else:
                raise KeyError
        except KeyError:
            self.get_pass(netloc, push_callback_dict)
Esempio n. 12
0
def get_credentials(svc):

    f = filter(lambda x: x[0] == svc, keychain.get_services())

    res = [x for x in f]

    if not res:

        usr, pwd = console.login_alert(svc)
        keychain.set_password(svc, usr, pwd)

        return usr, pwd

    return (res[0][1], keychain.get_password(*res[0]))
Esempio n. 13
0
def get_apikey(service="", account=""):
    assert service is not None and account is not None
    d = {}
    d.update(keychain.get_services())
    if service in d:
        assert d.get(service, "") == account
        PWD = keychain.get_password(service, account)
        touchid_status = 0
        touchid_status = authenticate("Authenticate API lookup", allow_passcode=True, timeout=10)
        if touchid_status:
            return PWD
        else:
            sys.stderr.write("Bad fingerprint!")
    else:
        raise Exception("API key not found")
Esempio n. 14
0
    def push_action(self,sender):
       # pdb.set_trace()
        user, sep, pw =  (None,None,None)
        repo = self._get_repo()
        
        remote=self.view['remote'].text
        if remote in self.remotes_iterator():
            remote = repo.remotes.get(remote,'')

        branch_name = os.path.join('refs','heads', repo.active_branch)  #'refs/heads/%s' % repo.active_branch
        # tODO  use remote branch_name 


        netloc = urlparse.urlparse(remote).netloc

        keychainservice = 'shellista.git.{0}'.format(netloc)

        #define some callbacks for use by uidialog
        def push_callback(user,pw):
            print  "Attempting to push to: {0}, branch: {1}".format(remote, branch_name)
            console.show_activity()
            if user:
               try:
                  opener = auth_urllib2_opener(None, remote, user, pw)
                  porcelain.push(repo.path, remote, branch_name, opener=opener)
                  keychain.set_password(keychainservice, user, pw)
               except urllib2.URLError:
                  console.hide_activity()
                  console.hud_alert('push failed','error')
                  return
            else:
                porcelain.push(repo.repo, result.url, branch_name)
            console.hide_activity()
            console.hud_alert('push complete')
        def push_callback_dict(d):
            push_callback(d['username'],d['password'])
            
        #Attempt to retrieve user
        try:
            user = dict(keychain.get_services())[keychainservice]
            pw = keychain.get_password(keychainservice, user)
            if pw:
                push_callback(user,pw)
            else:
                raise KeyError
        except KeyError:
            self.get_pass(netloc,push_callback_dict)
Esempio n. 15
0
    def resetPW(self, sender):
        repo = self._get_repo()

        remote = self.view['remote'].text
        if remote in self.remotes_iterator():
            remote = repo.remotes.get(remote, '')

        branch_name = os.path.join('refs', 'heads', repo.active_branch)  # 'refs/heads/%s' % repo.active_branch
        # tODO  use remote branch_name

        netloc = urlparse.urlparse(remote).netloc

        keychainservice = 'shellista.git.{0}'.format(netloc)
        try:
            user = dict(keychain.get_services())[keychainservice]
            keychain.delete_password(keychainservice, user)
            console.hud_alert('removed password for {}@{}'.format(user, netloc))
        except KeyError:
            console.hud_alert('no saved auth for {}'.format(netloc))
Esempio n. 16
0
    def resetPW(self,sender):
        repo = self._get_repo()
        
        remote=self.view['remote'].text
        if remote in self.remotes_iterator():
            remote = repo.remotes.get(remote,'')

        branch_name = os.path.join('refs','heads', repo.active_branch)  #'refs/heads/%s' % repo.active_branch
        # tODO  use remote branch_name 


        netloc = urlparse.urlparse(remote).netloc

        keychainservice = 'shellista.git.{0}'.format(netloc)
        try:
            user = dict(keychain.get_services())[keychainservice]
            keychain.delete_password(keychainservice,user)
            console.hud_alert('removed password for {}@{}'.format( user,netloc))
        except KeyError:
            console.hud_alert('no saved auth for {}'.format( netloc))
Esempio n. 17
0
 def __delitem__(self, key):
     for service in keychain.get_services():
         if key in service:
             keychain.delete_password(self._dbname, key)
Esempio n. 18
0
File: git.py Progetto: zx110101/00
def git_push(args):
    parser = argparse.ArgumentParser(
        prog='git push',
        usage=
        'git push [http(s)://<remote repo> or remote] [-u username[:password]]',
        description="Push to a remote repository")
    parser.add_argument('url', type=str, nargs='?', help='URL to push to')
    parser.add_argument('-u',
                        metavar='username[:password]',
                        type=str,
                        required=False,
                        help='username[:password]')
    result = parser.parse_args(args)

    user, sep, pw = result.u.partition(':') if result.u else (None, None, None)

    repo = _get_repo()

    origin = 'origin'
    if not result.url:
        result.url = repo.remotes.get('origin', '')
    if result.url in repo.remotes:
        origin = result.url
        result.url = repo.remotes.get(origin)

    branch_name = os.path.join(
        'refs', 'heads',
        repo.active_branch)  #'refs/heads/%s' % repo.active_branch

    print("Attempting to push to: {0}, branch: {1}".format(
        result.url, branch_name))

    netloc = urlparse.urlparse(result.url).netloc

    keychainservice = 'stash.git.{0}'.format(netloc)

    if sep and not user:
        # -u : clears keychain for this server
        for service in keychain.get_services():
            if service[0] == keychainservice:
                keychain.delete_password(*service)

    #Attempt to retrieve user
    if not user and SAVE_PASSWORDS and result.url.startswith('http'):
        try:
            user = dict(keychain.get_services())[keychainservice]
        except KeyError:
            user = input('Enter username: '******'Enter password: '******'Enter credentials for {0}'.format(netloc))

    outstream = StringIO()
    if user:
        if not pw and SAVE_PASSWORDS:
            pw = keychain.get_password(keychainservice, user)

        #Check again, did we retrieve a password?
        if not pw:
            user, pw = console.login_alert(
                'Enter credentials for {0}'.format(netloc), login=user)
        host_with_auth = '{}:{}@{}'.format(user, pw, netloc)
        url = urlparse.urlunparse(
            urlparse.urlparse(result.url)._replace(netloc=host_with_auth))
        porcelain.push(repo.repo.path, url, branch_name, errstream=outstream)
        keychain.set_password(keychainservice, user, pw)

    else:
        porcelain.push(repo.repo.path,
                       result.url,
                       branch_name,
                       errstream=outstream)

    for line in outstream.getvalue().split('\n'):
        print((line.replace(pw, '*******') if pw else line))

    print('success!')
Esempio n. 19
0
# this takes 2 arguments
# 1) the name of the account
# 2) the url to be redirected to
# best if used with Launch Center Pro
# https://launchcenterpro.com/q9qmfg 

from sys import argv
import keychain
import webbrowser
import ui
import clipboard
import console
services = keychain.get_services()

@ui.in_background
def item_selected(sender):
	acct = sender.items[sender.selected_row]['title'].split(' - ')
	pwd = keychain.get_password(acct[0],acct[1])
	clipboard.set(pwd)
	picker.close()
	webbrowser.open(argv[2])

@ui.in_background
def info_tapped(sender):
	row = sender.items[sender.tapped_accessory_row]
	console.alert(row['title'])
ds = ui.ListDataSource({'title':(x[0] +' - '+ x[1]),'accessory_type':'detail_button'} for x in services if argv[1].lower() in x[0].lower())
ds.action= item_selected
ds.accessory_action = info_tapped

picker = ui.load_view('lpfinder')
Esempio n. 20
0
 def __delitem__(self, key):
   for service in keychain.get_services():
     if key in service:
       keychain.delete_password(DB_NAME, key)
Esempio n. 21
0
 def keys(self):
     return [s[1] for s in keychain.get_services() if s[0] == DB_NAME]
Esempio n. 22
0
 def __getitem__(self, key):
     for service in keychain.get_services():
         if key == service[1]:
             return keychain.get_password(DB_NAME, key)
     raise KeyError
Esempio n. 23
0
 def __delitem__(self, key):
     for service in keychain.get_services():
         if key in service:
             keychain.delete_password(DB_NAME, key)
Esempio n. 24
0
 def __getitem__(self, key):
   for service in keychain.get_services():
     if key == service[1]:
       return keychain.get_password(DB_NAME, key)
   raise KeyError
Esempio n. 25
0
 def keys(self):
     return [s[1] for s in keychain.get_services() if s[0] == self._dbname]
Esempio n. 26
0
 def keys(self):
   return [s[1] for s in keychain.get_services() if s[0] == DB_NAME]