コード例 #1
0
 def get_host_vars(self, host, vault_password=None):
     """ Get host specific variables. """
     if "-s" in sys.argv or "--sudo" in sys.argv:
         x_auth_system = host.get_variables().get("x_auth_system")
         if VarsModule.sudo_password.get(x_auth_system) is None:
             if x_auth_system == "Old Auth Shell User":
                 user = os.environ.get("OLD_AUTH_SHELL_USER")
                 VarsModule.remote_user[x_auth_system] = user
                 passwd = keyring.get_password(x_auth_system, user)
             if x_auth_system == "New Auth Shell User":
                 user = os.environ.get("NEW_AUTH_SHELL_USER")
                 VarsModule.remote_user[x_auth_system] = user
                 passwd = keyring.get_password(x_auth_system, user)
             elif x_auth_system == "Standard Shell User":
                 user = os.environ.get("USER")
                 VarsModule.remote_user[x_auth_system] = user
                 passwd = keyring.get_password(x_auth_system, user)
             elif x_auth_system == "Vagrant Shell User":
                 VarsModule.remote_user[x_auth_system] = "vagrant"
                 passwd = "vagrant"
             else:
                 raise Exception("Unknown Authentication System %s for host %s" % (x_auth_system, host.name))
             if passwd is None:
                 passwd = getpass.getpass(prompt="%s: sudo password" % x_auth_system)
             VarsModule.sudo_password[x_auth_system] = passwd
         host.set_variable('ansible_sudo_pass', VarsModule.sudo_password[x_auth_system])
         host.set_variable('ansible_ssh_user', VarsModule.remote_user[x_auth_system])
コード例 #2
0
 def button_clicked(self, button):
     if button != self.button_box.button(QtWidgets.QDialogButtonBox.Apply):
         return self.reject()
     # change config
     self.config_store.set('user', 'copyright_name', self.copyright_name.text())
     self.config_store.set('user', 'creator_name', self.creator_name.text())
     if (self.reset_flickr.isChecked() and
                         keyring.get_password('photini', 'flickr')):
         keyring.delete_password('photini', 'flickr')
     if (self.reset_picasa.isChecked() and
                         keyring.get_password('photini', 'picasa')):
         keyring.delete_password('photini', 'picasa')
     if (self.reset_facebook.isChecked() and
                         keyring.get_password('photini', 'facebook')):
         keyring.delete_password('photini', 'facebook')
     self.config_store.set(
         'files', 'force_iptc', str(self.write_iptc.isChecked()))
     if self.sc_always.isChecked():
         sc_mode = 'always'
     elif self.sc_auto.isChecked():
         sc_mode = 'auto'
     else:
         sc_mode = 'delete'
     self.config_store.set('files', 'sidecar', sc_mode)
     self.config_store.set('files', 'image', str(self.write_if.isChecked()))
     return self.accept()
コード例 #3
0
def ftp_list_modules(ftp_location="/www/htdocs/enseignement/setup",
                     http_location="http://www.xavierdupre.fr/enseignement/setup",
                     filename="index_modules_list.html"):
    """
    Updates the list of backuped modules assuming they are stored on a FTP website.
    It gets the list of wheels in a folder and creates a HTML pages.
    It then uploads the final pages.

    @param  ftp_location    location on the website
    @param  http_location   same location but on http protocol
    @param  filename        name of the file to produce
    @return                 list of modules

    The module uses *keyring* to retrieve the credentials.
    You can set them up with:

    ::

        keyring.get_password("ftp_list_modules", "ensae_teaching_cs,site", "...")
        keyring.get_password("ftp_list_modules", "ensae_teaching_cs,login", "...")
        keyring.get_password("ftp_list_modules", "ensae_teaching_cs,password", "...")
    """
    with warnings.catch_warnings():
        warnings.simplefilter('ignore', DeprecationWarning)
        import keyring

    ftp_site = keyring.get_password(
        "ftp_list_modules", "ensae_teaching_cs,site")
    login = keyring.get_password("ftp_list_modules", "ensae_teaching_cs,login")
    password = keyring.get_password(
        "ftp_list_modules", "ensae_teaching_cs,password")

    if not ftp_site:
        raise ValueError("ftp_site is empty, some missing keyring?")
    if not login:
        raise ValueError("login is empty")
    if not password:
        raise ValueError("password is empty")

    ftp = TransferFTP(ftp_site, login, password)
    res = ftp.ls(ftp_location)

    rows = ["<html><body><h1>storage for unit test</h1>\n<ul>"]
    ret = []
    for i, v in enumerate(sorted(_["name"] for _ in res)):
        if v in ('.', '..'):
            continue
        ret.append(v)
        line = '<li>{1} - <a href="{2}/{0}">{0}</a></li>'.format(
            v, i, http_location)
        rows.append(line)
    rows.append("</ul></body></html>")

    content = "\n".join(rows)
    bstr = content.encode('ascii')
    ftp.transfer(bstr, ftp_location + "/", filename)

    ftp.close()

    return ret
コード例 #4
0
ファイル: eyeoh.py プロジェクト: brett-johnson/stash
def do_auth(username, apikey, use_cache=True):

    if use_cache:
        token_expires = keyring.get_password('stash', 'tokenexpires')
        token = keyring.get_password('stash', 'token')
        ep_text = keyring.get_password('stash', 'endpoints')

        if token_expires and token and ep_text:
            expires_date = stash.util.parse_iso_8601(token_expires)
            now = datetime.datetime.utcnow()

            if now < expires_date:
                # we should be good, just re-use the
                # token
                return token, json.loads(ep_text)

    url = "https://identity.api.rackspacecloud.com/v2.0/tokens"
    hdrs = {
        'Content-Type': 'application/json'
    }

    body = {
        "auth":
        {
            "RAX-KSKEY:apiKeyCredentials":
            {
                "username": username,
                "apiKey": apikey
            }
        }
    }

    resp = requests.post(url, data=json.dumps(body), headers=hdrs)

    if resp.ok:
        output = resp.json()

        token = output['access']['token']['id']
        expires_text = output['access']['token']['expires']

        # Cache the token and expiry in the keyring
        keyring.set_password('stash', 'tokenexpires', expires_text)
        keyring.set_password('stash', 'token', token)

        # now find the block storage endpoints
        sc = output['access']['serviceCatalog']


        # Find all of the object store endpoints
        os_endpoints = [service['endpoints'] for
            service in sc if service['type'] == 'object-store'][0]

        ep_text = json.dumps(os_endpoints)
        keyring.set_password('stash', 'endpoints', ep_text)

        return token, os_endpoints

    elif resp.status_code == 401:
        print (Fore.RED, "Invalid username/API key?")
        return False
コード例 #5
0
ファイル: auth_eos.py プロジェクト: roshan/auth_eos
def get_credentials():
    logging.info("Getting username")
    user = keyring.get_password(REALM, "username")
    logging.info("Getting password")
    passwd = keyring.get_password(REALM, "password")

    return user, passwd
コード例 #6
0
ファイル: connect.py プロジェクト: lyndsysimon/mekk.rtm
def create_and_authorize_connector_prompting_for_api_key(
    app_name,
    permission = "delete",
    invite_to_authorize = _console_invite_to_auth,
    wait_for_authorization = _console_wait_for_user,
    prompt_secure_data = _prompt_secure_data):
    """
    Creates and authorizes connector interactively asing
    for api key (and saving it for future uses)
    """
    API_LABEL = "api-key"
    SEC_LABEL = "sec-code"

    api_key = keyring.get_password(app_name, API_LABEL)
    if not api_key:
        api_key = prompt_secure_data("API Key")
        keyring.set_password(app_name, API_LABEL, api_key)

    api_sec = keyring.get_password(app_name, SEC_LABEL)
    if not api_sec:
        api_sec = prompt_secure_data("shared secret")
        keyring.set_password(app_name, SEC_LABEL, api_sec)

    try:
        connector = create_and_authorize_connector(app_name, api_key, api_sec)
        return connector
    except RtmServiceException, e:
        if "Invalid API Key" in str(e):
            keyring.set_password(app_name, API_LABEL, "")
        if "Invalid signature" in str(e):
            keyring.set_password(app_name, SEC_LABEL, "")
        raise
コード例 #7
0
ファイル: run.py プロジェクト: robertdavidwest/keen
def get_keen_client(credentials_key):
    """ Get KeenCLient

    Parameters
    ----------
    credentials_key : str
        either a path to a json file containing 'project_id' and 'read_key'
        or a service_name for keyring entries containing 'project_id' and
        'read_key'

    Returns
    -------
    KeenClient
    """
    if credentials_key.endswith('.json'):
        credentials = open(credentials_key, 'r').read()
        credentials = json.loads(credentials)
        project_id = credentials['project_id']
        read_key = credentials['read_key']
    else:
        project_id=keyring.get_password(credentials_key, 'project_id')
        read_key=keyring.get_password(credentials_key, 'read_key')

    client = KeenClient(project_id=project_id, read_key=read_key)
    return client
コード例 #8
0
    def test_transfer_ftp_true(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        with warnings.catch_warnings():
            warnings.simplefilter('ignore', DeprecationWarning)
            import keyring
        prefix = "pyquickhelper,"
        try:
            user = keyring.get_password("web", prefix + "user")
            pwd = keyring.get_password("web", prefix + "pwd")
        except RuntimeError:
            user = None
            pwd = None
        if user is None:
            if not is_travis_or_appveyor():
                zoo = []
                for k, v in sorted(os.environ.items()):
                    zoo.append("{0}={1}".format(k, v))
                raise Exception("user password is empty, prefix='{0}', username='******'\n{2}".format(
                    prefix, get_user(), "\n".join(zoo)))
            return

        web = TransferFTP("ftp.xavierdupre.fr", user, pwd, fLOG=fLOG)
        r = web.ls(".")
        fLOG(r)
        self.assertTrue(isinstance(r, list))
        web.close()
コード例 #9
0
ファイル: nike_harvester.py プロジェクト: allmende/indx
    def set_config(self, args):
        stored_config_harvester = keyring.get_password("INDX", "INDX_Nike_Harvester")
        if stored_config_harvester is not None:
            stored_config_harvester = json.loads(stored_config_harvester)
        stored_config_nike = keyring.get_password("Nike.com", "Nike+")
        if stored_config_nike is not None:
            stored_config_nike = json.loads(stored_config_nike)

        received_config = json.loads(args['config'])
        if (type(received_config) != dict):
            received_config = json.loads(received_config)
        self.logger.debug("Received config: {0}".format(received_config))
        if 'nike' in received_config:
            nike_config = received_config['nike']
            if nike_config and ('user' in nike_config) and ('password' in nike_config): 
                self.logger.debug("Received user: {0} and password: {1}".format(nike_config['user'], nike_config['password']))
                try:
                    self.nike.login(nike_config['user'], nike_config['password'])
                    self.logger.debug("Logged in with username {0} and password {1}".format(nike_config['user'], nike_config['password']))
                    token = self.nike.get_token()
                    self.logger.debug("Got token {0}".format(token))
                    if token:
                        nike_config['token'] = token
                        if 'error' in nike_config:
                            del nike_config['error']
                except Exception as exc:
                    self.logger.error("Could not authorise to Nike, with username {0} and password {1},  error: {2}".format(nike_config['user'], nike_config['password'], exc))
                    nike_config['error'] = str(exc)
                    del nike_config['password']
                keyring.set_password("Nike.com", "Nike+", json.dumps(nike_config))
        if 'harvester' in received_config:
            harvester_config = received_config['harvester']
            if harvester_config != stored_config_harvester:
                keyring.set_password("INDX", "INDX_Nike_Harvester", json.dumps(harvester_config)) 
コード例 #10
0
ファイル: scrape.py プロジェクト: blipp/scrape
    def __init__(self, factory=mechanize.RobustFactory(), history=None, request_class=None):
        mechanize.Browser.__init__(self, factory, history, request_class)
        br = self
        
        if len(keyring.get_password('ilias', user)):
            keyring.set_password('ilias', user,'password')
        

        br.set_handle_robots(False)
        br.set_handle_equiv(True)
        br.set_handle_redirect(True)
        br.set_handle_referer(True)
        br.open('https://ilias.studium.kit.edu/login.php?target=&client_id=produktiv&cmd=force_login&lang=de')
        br.select_form(name="formlogin")
        control = br.find_control(name="idp_selection")
        control.items[1].selected=True
        br.submit()
        br.select_form(nr=0)
        br["j_username"] = user
        br["j_password"] = keyring.get_password('ilias', user)
        br.submit()
        br.select_form(nr=0)
        br.submit()
        br.select_form(nr=0)
        br.submit()
        br.select_form(nr=0)
        br.submit()
コード例 #11
0
def check_transmission(argv):
    remote_bin = '/usr/local/bin/transmission-remote' # also make this configurable ?
    host_ip = keyring.get_password("transmission-bitbar", "ip")
    host_port = keyring.get_password("transmission-bitbar", "port")
    host_user = keyring.get_password("transmission-bitbar", "username")
    host_pswd = keyring.get_password("transmission-bitbar", host_user)

    if 'slowdown' in argv:
        subprocess.check_output(remote_bin+' '+host_ip+':'+host_port+' --auth '+host_user+':'+host_pswd+' -as', shell=True)
        exit()
    elif 'speedup' in argv:
        subprocess.check_output(remote_bin+' '+host_ip+':'+host_port+' --auth '+host_user+':'+host_pswd+' -AS', shell=True)
        exit()
    elif 'pause' in argv:
        subprocess.check_output(remote_bin+' '+host_ip+':'+host_port+' --auth '+host_user+':'+host_pswd+' -t ' + argv[-1] + ' -S', shell=True)
    elif 'resume' in argv:
        subprocess.check_output(remote_bin+' '+host_ip+':'+host_port+' --auth '+host_user+':'+host_pswd+' -t ' + argv[-1] + ' -s', shell=True)

    session_info = subprocess.check_output(remote_bin+' '+host_ip+':'+host_port+' --auth '+host_user+':'+host_pswd+' -si -st', shell=True)
    session_info_lines = session_info.split('\n')

    slow_speed = False

    for session_info_line in session_info_lines:
        if 'speed limit' in session_info_line:
            if not 'Unlimited' in session_info_line:
                slow_speed = True

    info = subprocess.check_output(remote_bin+' '+host_ip+':'+host_port+' --auth '+host_user+':'+host_pswd+' -l', shell=True)
    info_lines = info.split('\n')

    host_pswd = ''

    return slow_speed,info_lines
コード例 #12
0
ファイル: Config.py プロジェクト: ricardoamaro/Nagstamon
    def _LoadServersMultipleConfig(self):
        """
        load servers config - special treatment because of obfuscated passwords
        """
        self.keyring_available = self.KeyringAvailable()

        servers = self.LoadMultipleConfig('servers', 'server', 'Server')
        # deobfuscate username + password inside a try-except loop
        # if entries have not been obfuscated yet this action should raise an error
        # and old values (from nagstamon < 0.9.0) stay and will be converted when next
        # time saving config
        try:
            for server in servers:
                # usernames for monitor server and proxy
                servers[server].username = self.DeObfuscate(servers[server].username)
                servers[server].proxy_username = self.DeObfuscate(servers[server].proxy_username)
                # passwords for monitor server and proxy
                if servers[server].save_password == 'False':
                    servers[server].password = ""
                elif self.keyring_available and self.use_system_keyring:
                    # necessary to import on-the-fly due to possible Windows crashes
                    import keyring
                    password = keyring.get_password('Nagstamon', '@'.join((servers[server].username,
                                                                           servers[server].monitor_url))) or ""
                    if password == "":
                        if servers[server].password != "":
                            servers[server].password = self.DeObfuscate(servers[server].password)
                    else:
                        servers[server].password = password
                elif servers[server].password != "":
                    servers[server].password = self.DeObfuscate(servers[server].password)
                # proxy password
                if self.keyring_available and self.use_system_keyring:
                    # necessary to import on-the-fly due to possible Windows crashes
                    import keyring
                    proxy_password = keyring.get_password('Nagstamon', '@'.join(('proxy',
                                                                                 servers[server].proxy_username,
                                                                                 servers[server].proxy_address))) or ""
                    if proxy_password == "":
                        if servers[server].proxy_password != "":
                            servers[server].proxy_password = self.DeObfuscate(servers[server].proxy_password)
                    else:
                        servers[server].proxy_password = proxy_password
                elif servers[server].proxy_password != "":
                    servers[server].proxy_password = self.DeObfuscate(servers[server].proxy_password)

                # do only deobfuscating if any autologin_key is set - will be only Centreon
                if 'autologin_key' in servers[server].__dict__.keys():
                    if len(servers[server].__dict__['autologin_key']) > 0:
                        servers[server].autologin_key = self.DeObfuscate(servers[server].autologin_key)

                # only needed for those who used Icinga2 before it became IcingaWeb2
                if servers[server].type == 'Icinga2':
                    servers[server].type = 'IcingaWeb2'

        except:
            import traceback
            traceback.print_exc(file=sys.stdout)

        return servers
コード例 #13
0
ファイル: yagmail.py プロジェクト: srm-soumya/yagmail
 def login(self, password):
     """ 
     Login to the SMTP server using password. 
     This only needs to be manually run when the connection to the SMTP server was closed by the user.
     """
     self.smtp = smtplib.SMTP(self.host, self.port, **self.kwargs)
     self.smtp.set_debuglevel(self.debuglevel)
     if self.starttls is not None:
         self.smtp.ehlo()
         if self.starttls:
             self.smtp.starttls()
         else:
             self.smtp.starttls(**self.starttls)
         self.smtp.ehlo()
     if password is None:
         password = keyring.get_password('yagmail', self.user) 
         if password is None:
             password = keyring.get_password('yagmail', self.user)
         if password is None:
             import getpass
             password = getpass.getpass('Password for <{}>: '.format(self.user))
             answer = ''
             # Python 2 fix 
             while answer != 'y' and answer != 'n':
                 prompt_string = 'Save username and password in keyring? [y/n]: '
                 # pylint: disable=undefined-variable
                 try: 
                     answer = raw_input(prompt_string).strip()
                 except NameError: 
                     answer = input(prompt_string).strip()
             if answer == 'y':    
                 register(self.user, password) 
     self.smtp.login(self.user, password)
     self.is_closed = False
コード例 #14
0
ファイル: __init__.py プロジェクト: bosr/aws-keyring
def get_credentials(name=None):
    if not name:
        name = get_default_name()

    access_key_id = keyring.get_password('aws-keyring-access-key-id', name)
    secret_access_key = keyring.get_password('aws-keyring-secret-access-key', name)
    mfa_serial = keyring.get_password('aws-keyring-mfa', name)
    temporary_credentials = keyring.get_password('aws-keyring-temporary-credentials', name)
    if temporary_credentials:
        access_key, secret_key, session_token, expiration = temporary_credentials.split()
        temporary_credentials = TemporaryCredentials(
            temporary_access_key=access_key,
            temporary_secret_key=secret_key,
            session_token=session_token,
            expiration=expiration
        )
   
    credentials = Credentials(
        name=name,
        access_key_id=access_key_id,
        secret_access_key=secret_access_key,
        mfa_serial=mfa_serial,
        temporary_credentials=temporary_credentials
    )
    return credentials
コード例 #15
0
ファイル: nike_harvester.py プロジェクト: allmende/indx
    def load_configuration(self):
        stored_config_harvester = keyring.get_password("INDX", "INDX_Nike_Harvester")
        self.logger.debug("Loaded harvester config from keyring: {0}".format(stored_config_harvester))
        if stored_config_harvester is None :
            self.logger.error("Harvester not configured. Please configure before use.")
            return
        if (type(stored_config_harvester) != dict):
            stored_config_harvester = json.loads(stored_config_harvester)

        stored_config_nike = keyring.get_password("Nike.com", "Nike+")
        self.logger.debug("Loaded nike config from keyring: {0}".format(stored_config_nike))

        if stored_config_nike is None :
            self.logger.error("No credentials for Nike.com. Please configure before use.")
            return
        else :
            if (type(stored_config_nike) != dict):
                stored_config_nike = json.loads(stored_config_nike)
            if ('password' in stored_config_nike) and ('user' in stored_config_nike):
                self.config_nike_user = stored_config_nike['user']
                self.config_nike_pass = stored_config_nike['password']    
                if not self.try_nike_login():
                    return
        self.config_box = stored_config_harvester['box']
        self.config_indx_user = stored_config_harvester['user']
        self.config_indx_pass = stored_config_harvester['password']
コード例 #16
0
    def test_transfer_ftp_true(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        if sys.version_info[0] < 3:
            warnings.warn(
                "No testing transfer FTP on Pyghon 2.7 (issue with str and bytes)")
            return
        import keyring
        machine = os.environ.get(
            "COMPUTERNAME", os.environ.get("HOSTNAME", "CI"))
        try:
            user = keyring.get_password("web", machine + "user")
            pwd = keyring.get_password("web", machine + "pwd")
        except RuntimeError:
            user = None
            pwd = None
        if user is None:
            if not is_travis_or_appveyor():
                raise Exception("user password is empty, machine='{0}', username='******'".format(
                    machine, os.environ.get("USERNAME", None)))
            else:
                return

        web = TransferFTP("ftp.xavierdupre.fr", user, pwd, fLOG=fLOG)
        r = web.ls(".")
        fLOG(r)
        assert isinstance(r, list)
コード例 #17
0
ファイル: mailPi.py プロジェクト: cthare/Raspberry-Spy
def openConnection():
	smtpObj = smtplib.SMTP()
	smtpObj.connect(keyring.get_password('RPIemail', 'SMTP-URL'), int(keyring.get_password('RPIemail', 'SMTP-Port')))
	smtpObj.ehlo()
	smtpObj.login(keyring.get_password('RPIemail', 'emailFrom'), keyring.get_password('RPIemail', 'emailPass'))

	return smtpObj
コード例 #18
0
ファイル: web_api.py プロジェクト: giuppi/pydio-sync
    def get(self, job_id):
        if job_id != 'request':
            jobs = JobsLoader.Instance().get_jobs()
            if not job_id in jobs:
                return {"error":"Cannot find job"}
            job = jobs[job_id]
            url = job.server + '/api/'+job.workspace+'/ls/?options=d&recursive=true'
            auth = (job.user_id, keyring.get_password(job.server, job.user_id))
            verify = not job.trust_ssl
        else:
            args = request.args
            base = args['url'].rstrip('/')
            verify = False if args['trust_ssl'] == 'true' else True
            url = base + '/api/'+args['ws']+'/ls/?options=d&recursive=true&max_depth=2'
            if 'password' in args:
                auth = (args['user'], args['password'])
            else:
                auth = (args['user'], keyring.get_password(base, args['user']))

        if verify and "REQUESTS_CA_BUNDLE" in os.environ:
            verify = os.environ["REQUESTS_CA_BUNDLE"]
        resp = requests.get( url, stream=True, auth=auth, verify=verify,
                             proxies=ConfigManager.Instance().get_defined_proxies())
        o = xmltodict.parse(resp.content)
        if not 'tree' in o or not o['tree'] or 'message' in o['tree']:
            return [{'error':'Cannot load workspace'}]
        if not 'tree' in o['tree']:
            return []
        if isinstance(o['tree']['tree'], types.DictType):
            return [o['tree']['tree']]
        return o['tree']['tree']
コード例 #19
0
ファイル: temporal_lobe.py プロジェクト: BeauGieskens/rpi_ai
def translateText(s,language): 
	translation = ""
	try:
		pattern = re.compile('([^\s\w]|_)+')
		b_string = re.sub(pattern, '', s.lower())
		phrase=" " + b_string + " "
		pattern = re.compile("\\b(in|chinese|italian|german|hebrew|say|translate|spanish|to)\\W", re.I)
		phrase_noise_removed = [pattern.sub("", phrase)] 
		text = phrase_noise_removed[0]
		print "translating " + text + " to " + language + "..."
		args = {
			'client_id': keyring.get_password('msft_azure','api_client'),#your client id here
			'client_secret': keyring.get_password('msft_azure','api_secret'),#your azure secret here
			'scope': 'http://api.microsofttranslator.com',
			'grant_type': 'client_credentials'
			}
			
		oauth_url = 'https://datamarket.accesscontrol.windows.net/v2/OAuth2-13'
		oauth_junk = json.loads(requests.post(oauth_url,data=urllib.urlencode(args)).content)
		translation_args = {
			'text': text,
			'to': language,
			'from': 'en'
			}
		 
		headers={'Authorization': 'Bearer '+oauth_junk['access_token']}
		translation_url = 'http://api.microsofttranslator.com/V2/Ajax.svc/Translate?'
		translation_result = requests.get(translation_url+urllib.urlencode(translation_args),headers=headers)
		translation=translation_result.text[2:-1]
		print 'Translating ' + translation_args["text"]
		print 'Translation: ' + translation
		return translation
	except:
		print "Unexpected error:", sys.exc_info()[0]
コード例 #20
0
ファイル: fitbit_harvester.py プロジェクト: sociam/indx
    def set_config(self, args):
        stored_config_harvester = keyring.get_password("INDX", "INDX_Fitbit_Harvester")
        if stored_config_harvester is not None:
            stored_config_harvester = json.loads(stored_config_harvester)
        stored_config_fitbit = keyring.get_password("Fitbit.com", "Fitbit")
        if stored_config_fitbit is not None:
            stored_config_fitbit = json.loads(stored_config_fitbit)

        received_config = json.loads(args['config'])
        if (type(received_config) != dict):
            received_config = json.loads(received_config)
        self.logger.debug("Received config ({0}): {1}".format(type(received_config), received_config))
        config = {}
        if 'fitbit' in received_config:
            fitbit_config = received_config['fitbit']
            if fitbit_config and ('pin' in fitbit_config) and ('req_token' in fitbit_config): # this should check for the req_token in the stored config!
                self.logger.debug("Received pin: {0}".format(fitbit_config['pin']))
                try:
                    token = self.fitbit.get_token_with_pin(fitbit_config['pin'], fitbit_config['req_token'])
                    self.logger.debug("Got auth token {0}, of type {1}".format(token, type(token)))
                    if token:
                        config['token']=token
                        keyring.set_password("Fitbit.com", "Fitbit", json.dumps(config))
                except Exception as exc:
                    self.logger.error("Could not authorise to fitbit, with pin {0}, error: {1}".format(fitbit_config['pin'], exc))
        if 'harvester' in received_config:
            harvester_config = received_config['harvester']
            if harvester_config != stored_config_harvester:
                keyring.set_password("INDX", "INDX_Fitbit_Harvester", json.dumps(harvester_config)) 
コード例 #21
0
def pass_is_set():
    if keyring.get_password("system", "passman-salt") is None or \
                    keyring.get_password("system", "passman-cipher") is None or \
                    keyring.get_password("system", "passman-userkey") is None:
        return False
    else:
        return True
コード例 #22
0
ファイル: fitbit_harvester.py プロジェクト: sociam/indx
    def get_config(self, args):
        stored_config_harvester = keyring.get_password("INDX", "INDX_Fitbit_Harvester")
        stored_config_fitbit = keyring.get_password("Fitbit.com", "Fitbit")

        self.logger.debug("Loaded harvester config from keyring: {0}".format(stored_config_harvester))
        self.logger.debug("Loaded fitbit config from keyring: {0}".format(stored_config_fitbit))

        if stored_config_fitbit is None :
            token_url = self.fitbit.get_token_url()
            config_fitbit = {}
            config_fitbit["url"] = token_url['url']
            config_fitbit["req_token"] = token_url['req_token']
        else :
            if (type(stored_config_fitbit) != dict):
                config_fitbit = json.loads(stored_config_fitbit)
            # if (type(config_fitbit) != dict):
            #     config_fitbit = json.loads(config_fitbit)
            if 'token' not in config_fitbit :
                token_url = self.fitbit.get_token_url()
                config_fitbit["url"] = token_url['url']
                config_fitbit["req_token"] = token_url['req_token']
                keyring.set_password("Fitbit.com", "Fitbit", json.dumps(config_fitbit))
        if stored_config_harvester is None:
            return json.dumps({"fitbit":config_fitbit}) # don't send the req_token
        return json.dumps({"fitbit":config_fitbit, "harvester":json.loads(stored_config_harvester)}) # don't send the req_token
コード例 #23
0
ファイル: web_api.py プロジェクト: Acidburn0zzz/pydio-sync
    def get(self, job_id):
        if job_id != 'request':
            jobs = self.loader.get_jobs()
            if not job_id in jobs:
                return {"error":"Cannot find job"}
            job = jobs[job_id]
            url = job.server + '/api/'+job.workspace+'/ls/?options=d&recursive=true'
            auth = (job.user_id, keyring.get_password(job.server, job.user_id))
        else:
            args = request.args
            base = args['url'].rstrip('/')
            url = base + '/api/'+args['ws']+'/ls/?options=d&recursive=true'
            if 'password' in args:
                auth = (args['user'], args['password'])
            else:
                auth = (args['user'], keyring.get_password(base, args['user']))

        resp = requests.get( url, stream = True, auth=auth )
        o = xmltodict.parse(resp.content)
        if not 'tree' in o or 'message' in o['tree']:
            return [{'error':'Cannot load workspace'}];
        if not 'tree' in o['tree']:
            return []
        if isinstance(o['tree']['tree'], types.DictType):
            return [o['tree']['tree']]
        return o['tree']['tree']
コード例 #24
0
ファイル: querying_sample.py プロジェクト: MiCHiLU/gaereader
def get_username_and_password(force_fresh_input = False):
    """
    Reads username and password from keyring or prompts user for them
    and saves them to the keyring. force_fresh_input enforces
    the prompt (to be used after bad login for example).
    """
    import keyring, getpass

    username = keyring.get_password("mekk.greader", "default-login")
    if (not username) or force_fresh_input:
        while True:
            username = raw_input("Your Google account name: ")
            if username:
                break
        keyring.set_password("mekk.greader", "default-login", username)

    password = keyring.get_password("mekk.greader", username)
    if (not password) or force_fresh_input:
        while True:
            password = getpass.getpass("Password for %s: " % username)
            if password:
                break
        keyring.set_password("mekk.greader", username, password)

    return username, password
コード例 #25
0
    def get(self, job_id):
        if job_id != 'request':
            jobs = JobsLoader.Instance().get_jobs()
            if not job_id in jobs:
                return {"error":"Cannot find job"}
            job = jobs[job_id]

            url = job.server + '/api/pydio/state/user/repositories?format=json'
            auth = (job.user_id, keyring.get_password(job.server, job.user_id))
            verify = not job.trust_ssl
        else:
            args = request.args
            base = args['url'].rstrip('/')
            verify = False if args['trust_ssl'] == 'true' else True
            url = base + '/api/pydio/state/user/repositories?format=json'
            if 'password' in args:
                auth = (args['user'], args['password'])
            else:
                auth = (args['user'], keyring.get_password(base, args['user']))

        if verify and "REQUESTS_CA_BUNDLE" in os.environ:
            verify = os.environ["REQUESTS_CA_BUNDLE"]
        resp = requests.get(url,stream=True,auth=auth,verify=verify)
        data = json.loads(resp.content)
        if 'repositories' in data and 'repo' in data['repositories']:
            if isinstance(data['repositories']['repo'], types.DictType):
                data['repositories']['repo'] = [data['repositories']['repo']]
            data['repositories']['repo'] = filter(lambda x: not x['@access_type'].startswith('ajxp_'), data['repositories']['repo'])

        return data
コード例 #26
0
ファイル: test_keyring.py プロジェクト: avivien/oauth2client
  def test_json_credentials_storage(self):
    access_token = 'foo'
    client_id = 'some_client_id'
    client_secret = 'cOuDdkfjxxnv+'
    refresh_token = '1/0/a.df219fjls0'
    token_expiry = datetime.datetime.utcnow()
    user_agent = 'refresh_checker/1.0'

    credentials = OAuth2Credentials(
        access_token, client_id, client_secret,
        refresh_token, token_expiry, GOOGLE_TOKEN_URI,
        user_agent)

    m = mox.Mox()
    m.StubOutWithMock(keyring, 'get_password')
    m.StubOutWithMock(keyring, 'set_password')
    keyring.get_password('my_unit_test', 'me').AndReturn(None)
    keyring.set_password('my_unit_test', 'me', credentials.to_json())
    keyring.get_password('my_unit_test', 'me').AndReturn(credentials.to_json())
    m.ReplayAll()

    s = Storage('my_unit_test', 'me')
    self.assertEquals(None, s.get())

    s.put(credentials)

    restored = s.get()
    self.assertEqual('foo', restored.access_token)
    self.assertEqual('some_client_id', restored.client_id)

    m.UnsetStubs()
    m.VerifyAll()
コード例 #27
0
ファイル: run.py プロジェクト: uho/cftpl
def get_password(config):
    name = "CFMGR: %s (Account %s)" % (config['STACK_NAME'], config['ACCOUNT'])
    key = keyring.get_password(name, config['ACCOUNT'])
    if not key:
        pw = getpass.getpass('Please enter password for "%s": ' % config['ACCOUNT'])
        keyring.set_password(name, config['ACCOUNT'], pw)
        key = keyring.get_password(name, config['ACCOUNT'])
    return key
コード例 #28
0
def read_config(args, appname=None, authfile=None):
    appname   = appname   or APPNAME
    authfile  = authfile  or AUTHFILE

    username = ""
    password = ""

    # read
    if keyring:
        log.debug("Reading credentials from keyring")
        try:
            username, password = (
                keyring.get_password(appname, appname).split('\n') +
                ['\n']
            )[:2]
        except AttributeError as e:
            # Check for old keyring format and migrate before throwing warning
            data = keyring.get_password(appname, '')
            if data:
                log.info("Migrating credentials to new keyring format")
                keyring.set_password(appname, appname, data)
                try:
                    keyring.delete_password(appname, '')
                except AttributeError as e:
                    log.warning("Error deleting old keyring. Outdated library? (%s)", e)
            else:
                log.warning("Credentials not found in keyring. First time usage?")
        except IOError as e:  # keyring sometimes raises this
            log.error(e)
    else:
        log.debug("Reading credentials from '%s'" % authfile)
        try:
            with open(authfile, 'r') as fd:
                username, password = (fd.read().splitlines() + ['\n'])[:2]
        except IOError as e:
            if e.errno == 2:  # No such file or directory
                log.warning("Credentials file not found. First time usage?")
            else:
                log.error(e)

    # save
    if args.username or args.password:
        log.info("Saving credentials")
        if keyring:
            keyring.set_password(appname, appname,
                                 '%s\n%s' % (args.username or username,
                                             args.password or password,))
        else:
            try:
                with open(authfile, 'w') as fd:
                    fd.write("%s\n%s\n" % (args.username or username,
                                           args.password or password,))
                os.chmod(authfile, 0o600)
            except IOError as e:
                log.error(e)

    return dict(username=username,
                password=password,)
コード例 #29
0
ファイル: backend.py プロジェクト: burrbull/spyder
    def get_user_credentials(self):
        """Get user credentials with the login dialog."""
        password = None
        token = None
        (username, remember_me,
         remember_token) = self._get_credentials_from_settings()
        valid_py_os = not (PY2 and sys.platform.startswith('linux'))
        if username and remember_me and valid_py_os:
            # Get password from keyring
            try:
                password = keyring.get_password('github', username)
            except Exception:
                # No safe keyring backend
                if self._show_msgbox:
                    QMessageBox.warning(self.parent_widget,
                                        _('Failed to retrieve password'),
                                        _('It was not possible to retrieve '
                                          'your password. Please introduce '
                                          'it again.'))
        if remember_token and valid_py_os:
            # Get token from keyring
            try:
                token = keyring.get_password('github', 'token')
            except Exception:
                # No safe keyring backend
                if self._show_msgbox:
                    QMessageBox.warning(self.parent_widget,
                                        _('Failed to retrieve token'),
                                        _('It was not possible to retrieve '
                                          'your token. Please introduce it '
                                          'again.'))

        if not running_under_pytest():
            credentials = DlgGitHubLogin.login(self.parent_widget, username,
                                            password, token, remember_me,
                                            remember_token)

            if (credentials['username'] and credentials['password'] and
                    valid_py_os):
                self._store_credentials(credentials['username'],
                                        credentials['password'],
                                        credentials['remember'])
                CONF.set('main', 'report_error/remember_me',
                         credentials['remember'])

            if credentials['token'] and valid_py_os:
                self._store_token(credentials['token'],
                                  credentials['remember_token'])
                CONF.set('main', 'report_error/remember_token',
                         credentials['remember_token'])
        else:
            return dict(username=username,
                        password=password,
                        token='',
                        remember=remember_me,
                        remember_token=remember_token)

        return credentials
コード例 #30
0
ファイル: interface.py プロジェクト: johnbeard/jira-cli
def initialize(config, base_url=None, username=None, password=None,
               persist=True, error=False, protocol='soap'):
    url = base_url or config.base_url
    bridge = get_bridge(protocol)(url, config, persist) if (url and not error) else None
    if error or not (url and bridge and bridge.ping()):
        url = url or prompt("Base url for the jira instance: ")
        username = (
            username
            or (not error and config.username)
            or prompt("username: "******"password: "******"would you like to persist the credentials to the local keyring? [y/n]:"

        first_run = (
            not(
                config.base_url
                or config.username
                or keyring.get_password('jira-cli',username)
            )
        )
        if persist or first_run:
            config.base_url = url
            config.save()
            keyring.set_password('jira-cli',username,password)
        try:
            jira.login(username, password)
            if (
                (persist or first_run)
                 and (
                    not (
                        config.username == username
                        or config.password == password
                    )
                )
                and "y" == prompt(persist_warning)
            ):
                config.username = username
                keyring.set_password('jira-cli',username,password)
                config.save()
            config.save()
            return jira
        except JiraAuthenticationError:
            print_error("invalid username/password", severity=WARNING)
            return initialize(config, base_url=url, error=True, protocol=protocol, persist=persist)
        except JiraInitializationError:
            print_error("invalid jira location", severity=WARNING)
            config.base_url = ""
            return initialize(config, error=True, protocol=protocol, persist=persist)
    else:
        return bridge
コード例 #31
0
ファイル: web_api.py プロジェクト: sanand0/pydio-sync
    def get(self, job_id):
        if job_id != 'request':
            jobs = JobsLoader.Instance().get_jobs()
            if not job_id in jobs:
                return {"error": "Cannot find job"}
            job = jobs[job_id]

            url = job.server + '/api/pydio/state/user/repositories?format=json'
            auth = (job.user_id, keyring.get_password(job.server, job.user_id))
            verify = not job.trust_ssl
        else:
            args = request.args
            base = args['url'].rstrip('/')
            verify = False if args['trust_ssl'] == 'true' else True
            url = base + '/api/pydio/state/user/repositories?format=json'
            if 'password' in args:
                auth = (args['user'], args['password'])
            else:
                auth = (args['user'], keyring.get_password(base, args['user']))
            app_name_url = base + '/api/pydio/state/plugins?format=json'
            display_name_url = base + '/api/pydio/state/user/preferences?format=json'

        if verify and "REQUESTS_CA_BUNDLE" in os.environ:
            verify = os.environ["REQUESTS_CA_BUNDLE"]
        try:
            # TRY TO GET APPLICATION TITLE
            if app_name_url:
                resp = requests.get(
                    app_name_url,
                    stream=False,
                    auth=auth,
                    verify=verify,
                    proxies=ConfigManager.Instance().get_defined_proxies())
                resp.raise_for_status()
                try:
                    app_data = json.loads(resp.content)
                    app_name = ''
                    ajxpcores = app_data['plugins']['ajxpcore']
                    for core in ajxpcores:
                        if core['@id'] == 'core.ajaxplorer':
                            for prop in core['plugin_configs']['property']:
                                if prop['@name'] == 'APPLICATION_TITLE':
                                    app_name = json.loads(prop['$'])
                                    break
                            break
                except KeyError as k:
                    pass
                except ValueError:
                    pass
            # TRY TO GET USER DISPLAY NAME
            if display_name_url:
                resp = requests.get(
                    display_name_url,
                    stream=False,
                    auth=auth,
                    verify=verify,
                    proxies=ConfigManager.Instance().get_defined_proxies())
                resp.raise_for_status()
                try:
                    user_data = json.loads(resp.content)
                    user_display_name = ''
                    prefs = user_data['preferences']['pref']
                    for pref in prefs:
                        if pref['@name'] == 'USER_DISPLAY_NAME':
                            if pref['@value']:
                                user_display_name = pref['@value']
                            break
                except KeyError as k:
                    pass
                except ValueError:
                    pass

            resp = requests.get(
                url,
                stream=True,
                auth=auth,
                verify=verify,
                proxies=ConfigManager.Instance().get_defined_proxies())
            resp.raise_for_status()
            data = json.loads(resp.content)
            if 'repositories' in data and 'repo' in data['repositories']:
                if isinstance(data['repositories']['repo'], types.DictType):
                    data['repositories']['repo'] = [
                        data['repositories']['repo']
                    ]
                data['repositories']['repo'] = filter(
                    lambda x: not x['@access_type'].startswith('ajxp_'),
                    data['repositories']['repo'])
            if app_name:
                data['application_title'] = app_name
            if user_display_name:
                data['user_display_name'] = user_display_name
            return data
        except requests.HTTPError:
            r = resp.status_code
            message = _("Couldn't load your workspaces, check your server !")
            if r == 404:
                message = _(
                    "Server not found (404), is it up and has it Pydio installed ?"
                )
            elif r == 401:
                message = _(
                    "Authentication failed: please verify your login and password"
                )
            elif r == 403:
                message = _("Access to the server is forbidden")
            elif r == 500 or r == 408:
                message = _("Server seems to be encountering problems (500)")
            logging.debug("Error while loading workspaces : " + message)
            return {'error': message}, resp.status_code
        except SSLError as rt:
            logging.error(rt.message)
            return {
                'error':
                _("An SSL error happened! Is your server using a self-signed certificate? In that case please check 'Trust SSL certificate'"
                  )
            }, 400
        except ProxyError as rt:
            logging.error(rt.message)
            return {
                'error': _('A proxy error happened, please check the logs')
            }, 400
        except TooManyRedirects as rt:
            logging.error(rt.message)
            return {'error': _('Connection error: too many redirects')}, 400
        except ChunkedEncodingError as rt:
            logging.error(rt.message)
            return {
                'error': _('Chunked encoding error, please check the logs')
            }, 400
        except ContentDecodingError as rt:
            logging.error(rt.message)
            return {
                'error': _('Content Decoding error, please check the logs')
            }, 400
        except InvalidSchema as rt:
            logging.error(rt.message)
            return {'error': _('Http connection error: invalid schema.')}, 400
        except InvalidURL as rt:
            logging.error(rt.message)
            return {'error': _('Http connection error: invalid URL.')}, 400
        except ValueError:
            message = "Error while parsing request result:" + resp.content
            logging.debug(message)
            return {'error': message}, 400
        except Timeout as to:
            logging.error(to)
            return {'error': _('Connection timeout!')}, 400
        except RequestException as ree:
            logging.error(ree.message)
            return {'error': _('Cannot resolve domain!')}, 400
コード例 #32
0
    def connect(self, database='', host='', user='', port='', passwd='',
                dsn='', **kwargs):
        # Connect to the database.

        if not user:
            user = getuser()

        if not database:
            database = user

        # If password prompt is not forced but no password is provided, try
        # getting it from environment variable.
        if not self.force_passwd_prompt and not passwd:
            passwd = os.environ.get('PGPASSWORD', '')

        # Find password from store
        key = '%s@%s' % (user, host)
        if not passwd:
            passwd = keyring.get_password('pgcli', key)

        # Prompt for a password immediately if requested via the -W flag. This
        # avoids wasting time trying to connect to the database and catching a
        # no-password exception.
        # If we successfully parsed a password from a URI, there's no need to
        # prompt for it, even with the -W flag
        if self.force_passwd_prompt and not passwd:
            passwd = click.prompt('Password for %s' % user, hide_input=True,
                                  show_default=False, type=str)

        # Prompt for a password after 1st attempt to connect without a password
        # fails. Don't prompt if the -w flag is supplied
        auto_passwd_prompt = not passwd and not self.never_passwd_prompt

        # Attempt to connect to the database.
        # Note that passwd may be empty on the first attempt. If connection
        # fails because of a missing password, but we're allowed to prompt for
        # a password (no -w flag), prompt for a passwd and try again.
        try:
            try:
                pgexecute = PGExecute(database, user, passwd, host, port, dsn,
                                      application_name='pgcli', **kwargs)
                if passwd:
                    keyring.set_password('pgcli', key, passwd)
            except (OperationalError, InterfaceError) as e:
                if ('no password supplied' in utf8tounicode(e.args[0]) and
                        auto_passwd_prompt):
                    passwd = click.prompt('Password for %s' % user,
                                          hide_input=True, show_default=False,
                                          type=str)
                    pgexecute = PGExecute(database, user, passwd, host, port,
                                          dsn, application_name='pgcli',
                                          **kwargs)
                    if passwd:
                        keyring.set_password('pgcli', key, passwd)
                else:
                    raise e

        except Exception as e:  # Connecting to a database could fail.
            self.logger.debug('Database connection failed: %r.', e)
            self.logger.error("traceback: %r", traceback.format_exc())
            click.secho(str(e), err=True, fg='red')
            exit(1)

        self.pgexecute = pgexecute
コード例 #33
0
ファイル: btc_wallet.py プロジェクト: yanheven/tribler
 def get_wallet_password(self):
     return keyring.get_password('tribler', 'btc_wallet_password')
コード例 #34
0
def main():
    import getpass
    import argparse

    try:
        import keyring
    except ImportError:
        keyring = None

    # Parse command-line arguments {{{
    cmdline = argparse.ArgumentParser()
    cmdline.add_argument('email',
                         nargs='?',
                         default=None,
                         help='The e-mail address for your Mint.com account')
    cmdline.add_argument('password',
                         nargs='?',
                         default=None,
                         help='The password for your Mint.com account')

    cmdline.add_argument('--accounts',
                         action='store_true',
                         dest='accounts',
                         default=False,
                         help='Retrieve account information'
                         '(default if nothing else is specified)')
    cmdline.add_argument('--budgets',
                         action='store_true',
                         dest='budgets',
                         default=False,
                         help='Retrieve budget information')
    cmdline.add_argument('--net-worth',
                         action='store_true',
                         dest='net_worth',
                         default=False,
                         help='Retrieve net worth information')
    cmdline.add_argument('--extended-accounts',
                         action='store_true',
                         dest='accounts_ext',
                         default=False,
                         help='Retrieve extended account information (slower, '
                         'implies --accounts)')
    cmdline.add_argument('--transactions',
                         '-t',
                         action='store_true',
                         default=False,
                         help='Retrieve transactions')
    cmdline.add_argument(
        '--extended-transactions',
        action='store_true',
        default=False,
        help='Retrieve transactions with extra information and arguments')
    cmdline.add_argument(
        '--start-date',
        nargs='?',
        default=None,
        help='Earliest date for transactions to be retrieved from. '
        'Used with --extended-transactions. Format: mm/dd/yy')
    cmdline.add_argument('--include-investment',
                         action='store_true',
                         default=False,
                         help='Used with --extended-transactions')
    cmdline.add_argument('--skip-duplicates',
                         action='store_true',
                         default=False,
                         help='Used with --extended-transactions')
    # Displayed to the user as a postive switch, but processed back
    # here as a negative
    cmdline.add_argument(
        '--show-pending',
        action='store_false',
        default=True,
        help='Exclude pending transactions from being retrieved. '
        'Used with --extended-transactions')
    cmdline.add_argument('--filename',
                         '-f',
                         help='write results to file. can '
                         'be {csv,json} format. default is to write to '
                         'stdout.')
    cmdline.add_argument('--keyring',
                         action='store_true',
                         help='Use OS keyring for storing password '
                         'information')
    cmdline.add_argument(
        '--headless',
        action='store_true',
        help='Whether to execute chromedriver with no visible window.')
    cmdline.add_argument('--mfa-method',
                         default='sms',
                         choices=['sms', 'email'],
                         help='The MFA method to automate.')

    options = cmdline.parse_args()

    if options.keyring and not keyring:
        cmdline.error('--keyring can only be used if the `keyring` '
                      'library is installed.')

    try:  # python 2.x
        from __builtin__ import raw_input as input
    except ImportError:  # python 3
        from builtins import input
    except NameError:
        pass

    # Try to get the e-mail and password from the arguments
    email = options.email
    password = options.password

    if not email:
        # If the user did not provide an e-mail, prompt for it
        email = input("Mint e-mail: ")

    if keyring and not password:
        # If the keyring module is installed and we don't yet have
        # a password, try prompting for it
        password = keyring.get_password('mintapi', email)

    if not password:
        # If we still don't have a password, prompt for it
        password = getpass.getpass("Mint password: ")

    if options.keyring:
        # If keyring option is specified, save the password in the keyring
        keyring.set_password('mintapi', email, password)

    if options.accounts_ext:
        options.accounts = True

    if not any([
            options.accounts, options.budgets, options.transactions,
            options.extended_transactions, options.net_worth
    ]):
        options.accounts = True

    mint = Mint.create(email,
                       password,
                       mfa_method=options.mfa_method,
                       headless=options.headless)
    atexit.register(mint.close)  # Ensure everything is torn down.

    data = None
    if options.accounts and options.budgets:
        try:
            accounts = make_accounts_presentable(
                mint.get_accounts(get_detail=options.accounts_ext))
        except:
            accounts = None

        try:
            budgets = mint.get_budgets()
        except:
            budgets = None

        data = {'accounts': accounts, 'budgets': budgets}
    elif options.budgets:
        try:
            data = mint.get_budgets()
        except:
            data = None
    elif options.accounts:
        try:
            data = make_accounts_presentable(
                mint.get_accounts(get_detail=options.accounts_ext))
        except:
            data = None
    elif options.transactions:
        data = mint.get_transactions(
            include_investment=options.include_investment)
    elif options.extended_transactions:
        data = mint.get_detailed_transactions(
            start_date=options.start_date,
            include_investment=options.include_investment,
            remove_pending=options.show_pending,
            skip_duplicates=options.skip_duplicates)
    elif options.net_worth:
        data = mint.get_net_worth()

    # output the data
    if options.transactions or options.extended_transactions:
        if options.filename is None:
            print(data.to_json(orient='records'))
        elif options.filename.endswith('.csv'):
            data.to_csv(options.filename, index=False)
        elif options.filename.endswith('.json'):
            data.to_json(options.filename, orient='records')
        else:
            raise ValueError('file extension must be either .csv or .json')
    else:
        if options.filename is None:
            print(json.dumps(data, indent=2))
        elif options.filename.endswith('.json'):
            with open(options.filename, 'w+') as f:
                json.dump(data, f, indent=2)
        else:
            raise ValueError('file type must be json for non-transaction data')
コード例 #35
0
#        https://github.com/Starignus
#######################################
"""
 Credentials
"""

import keyring
from pytz import timezone
from datetime import datetime
from pyexchange import Exchange2010Service, ExchangeNTLMAuthConnection
import json

credentials = json.load(open('calendarid.json'))

USERNAME = credentials["exchange"][0]["email"]
PASSWORD = keyring.get_password("ExchangeCalShopDirect", USERNAME)
URL = credentials["exchange"][0]["URL"]

print(PASSWORD)
# Set up the connection to Exchange
connection = ExchangeNTLMAuthConnection(
    url=URL, username="******", password=PASSWORD)

service = Exchange2010Service(connection)

my_calendar = service.calendar()

events = my_calendar.list_events(
    start=timezone("Europe/London").localize(datetime(2018, 01, 5)),
    end=timezone("Europe/London").localize(datetime(2018, 01, 10)),
    details=True)
コード例 #36
0
ファイル: run_linkeur.py プロジェクト: Michal-Mikolas/ttm
import ccxt
import ttm
import keyring

#
# Init
#
data_folder = 'output/link_eur_keep_value'

exchange = ttm.exchange.BinanceFix({
    'enableRateLimit':
    True,
    'apiKey':
    keyring.get_password('binance', 'apiKey'),
    'secret':
    keyring.get_password('binance', 'secret'),
})
strategy = ttm.strategy.KeepValue(
    pair='LINK/EUR',
    initial_target_value=121.29712,  # EUR
    minimal_move=11.8,  # percent
    tick_period=60,
    timeframe='5m',
    sell_modifier=0.9556842,  # 0.9778421
    buy_modifier=1.0443158,  # 1.0221579
)
storage = ttm.storage.JSONFile(data_folder +
                               '/storage.json')  # storage for strategy data
cache = ttm.storage.JSONFile(
    'cache.json')  # storage for performance optimalisation
コード例 #37
0
def _main(argv=None):
    # Protect access token and potentially encryption keys
    block_tracing()

    if argv is None:
        argv = sys.argv

    parser = argparse.ArgumentParser()
    userspacefs.add_cli_arguments(parser)
    parser.add_argument("-c", "--config-file", help="config file path")
    parser.add_argument(
        "-e",
        "--encrypted-folder",
        dest='encrypted_folders',
        type=parse_encrypted_folder_arg,
        default=[],
        action='append',
        help=
        "relative paths of encrypted folders, can be used multiple times. requires safefs"
    )
    parser.add_argument(
        "--print-default-config-file",
        action='store_true',
        help="print default config file path to standard out and quit")
    parser.add_argument("mount_point", nargs='?')
    args = parser.parse_args(argv[1:])

    config_dir = appdirs.user_config_dir(APP_NAME)

    if args.config_file is not None:
        config_file = args.config_file
    else:
        config_file = os.path.join(config_dir, "config.json")

    if args.print_default_config_file:
        print(config_file)
        return 0

    os.makedirs(config_dir, exist_ok=True)

    config = {}
    try:
        f = open(config_file)
    except IOError as e:
        if e.errno != errno.ENOENT: raise
    else:
        try:
            with f:
                config = json.load(f)
        except ValueError as e:
            print("Config file %r is not valid json: %s" % (config_file, e))
            return -1

    mount_point = args.mount_point
    if mount_point is None:
        mount_point = config.get("mount_point")

    if not args.smb_no_mount and mount_point is None:
        parser.print_usage()
        print("%s: error: please provide the mount_point argument" %
              (os.path.basename(argv[0]), ))
        return 1

    encrypted_folders = config.get("encrypted_folders",
                                   []) + args.encrypted_folders
    if safefs_wrap_create_fs is None and encrypted_folders:
        print(
            "safefs not installed, can't transparently decrypt encrypted folders"
        )
        return 1

    access_token = None
    save_access_token = False
    save_config = False

    access_token_command = config.get("access_token_command", None)
    if access_token_command is not None:
        print("Running %r for access token" %
              (' '.join(access_token_command), ))
        try:
            access_token = subprocess.check_output(
                access_token_command).decode("utf-8")
        except UnicodeDecodeError:
            print("Access token command output is not utf-8 encoded")
            return -1
        except TypeError:
            print("Bad access token command: %r, " % (access_token_command, ))
            return -1

    if access_token is None:
        keyring_user = config.get("keyring_user", None)

        if keyring_user is not None:
            try:
                access_token = keyring.get_password(APP_NAME, keyring_user)
            except KeyringError as e:
                print("Failed to get access token from keyring: %s" % (e, ))

    if access_token is None:
        access_token_privy = config.get("access_token_privy", None)
        if access_token_privy is not None:
            passwd = None
            while True:
                passwd = getpass.getpass(
                    "Enter access token passphrase (not your Dropbox password) (Ctrl-C to quit): "
                )
                try:
                    access_token = privy.peek(access_token_privy,
                                              passwd).decode('utf-8')
                except ValueError:
                    if not yes_no_input(
                            "Incorrect password, create new access token?"):
                        continue
                break
            del passwd

    try_directly = False
    while True:
        if access_token is None:
            save_access_token = True

        if (access_token is None and try_directly and yes_no_input(
                "Want to try entering the access token directly?")):
            print("Go to https://dropbox.com/developers/apps to "
                  "create an app and generate a personal access token.")

            while True:
                access_token = getpass.getpass(
                    "Enter Access token (Ctrl-C to quit): ")
                if not access_token:
                    print("Access tokens cannot be empty")
                    continue
                break

        if access_token is None:
            auth_flow = dropbox.DropboxOAuth2FlowNoRedirect(
                APP_KEY, APP_SECRET)
            authorize_url = auth_flow.start()
            print("We need an access token. Perform the following steps:")
            print("1. Go to " + authorize_url)
            print("2. Click \"Allow\" (you may have to log in first)")
            print("3. Copy the authorization code.")

            while True:
                auth_code = input(
                    "Enter authoritization code (Ctrl-C to quit): ")
                if not auth_code:
                    print("Authorization code cannot be empty")
                    continue
                break

            try:
                oauth_result = auth_flow.finish(auth_code)
            except Exception as e:
                print("Authorization code was invalid!")
                try_directly = True
                continue

            access_token = oauth_result.access_token

        # test out access token
        try:
            dropbox.Dropbox(access_token).users_get_current_account()
        except (dropbox.exceptions.BadInputError, dropbox.exceptions.AuthError,
                ValueError) as e:
            print("Error using access token: %s" % (e, ))
            access_token = None
            try_directly = True
        except OSError:
            if not yes_no_input("Error connecting to Dropbox, Try again?"):
                return 1
        else:
            break

    if save_access_token and yes_no_input(
            "We're all connected. Do you want to save your credentials for future runs?",
            default_yes=True):
        keyring_user = ''.join(
            [random.choice("asdfghjklzxcvbnmqwertyuiop") for _ in range(24)])
        try:
            keyring.set_password(APP_NAME, keyring_user, access_token)
        except (KeyringError, RuntimeError) as e:
            print(
                "We need a passphrase to encrypt your access token before we can save it."
            )
            print(
                "Warning: Your access token passphrase must contain enough randomness to be resistent to hacking. You can read this for more info: https://blogs.dropbox.com/tech/2012/04/zxcvbn-realistic-password-strength-estimation/"
            )
            while True:
                pass_ = getpass.getpass("Enter new access token passphrase: ")
                pass2_ = getpass.getpass(
                    "Enter new access token passphrase (again): ")
                if pass_ != pass2_:
                    print("Passphrases didn't match, please re-enter")
                else:
                    del pass2_
                    break
            config.pop('keyring_user', None)
            config['access_token_privy'] = privy.hide(
                access_token.encode('utf-8'), pass_, server=False)
            del pass_
            save_config = True
        else:
            config.pop('access_token_privy', None)
            config['keyring_user'] = keyring_user
            save_config = True

    if not config.get("asked_send_error_reports", False):
        if yes_no_input(
                "Would you like to help us improve %s by providing anonymous error reports?"
                % (APP_NAME, ),
                default_yes=True):
            config['send_error_reports'] = True
        config['asked_send_error_reports'] = True
        save_config = True

    if not os.path.exists(mount_point):
        if yes_no_input(
                "Mount point \"%s\" doesn't exist, do you want to create it?" %
            (mount_point, ),
                default_yes=True):
            os.makedirs(mount_point, exist_ok=True)

    if save_access_token and yes_no_input(
            "Do you want \"%s\" to be the default mount point?" %
        (mount_point, ),
            default_yes=True):
        config['mount_point'] = mount_point
        save_config = True

    if save_config:
        with open(config_file, "w") as f:
            json.dump(config, f)

    log.info("Starting %s...", APP_NAME)

    wrap_fs_errors = False
    if config.get('send_error_reports', False):
        try:
            version = pkg_resources.require("dbxfs")[0].version
        except Exception:
            log.warning("Failed to get version", exc_info=True)
            version = ''

        try:
            sentry_sdk.init(
                "https://[email protected]/1293235",
                release='%s@%s' % (APP_NAME, version),
                with_locals=False)
            wrap_fs_errors = True
        except Exception:
            log.warning("Failed to initialize sentry", exc_info=True)

    cache_folder = os.path.join(appdirs.user_cache_dir(APP_NAME), "file_cache")
    try:
        os.makedirs(cache_folder, exist_ok=True)
    except OSError:
        log.warning(
            "Failed to create cache folder, running without file cache")
        cache_folder = None

    def create_fs():
        fs = CachingFileSystem(DropboxFileSystem(access_token),
                               cache_folder=cache_folder)
        if sys.platform == 'darwin':
            fs = DisableQuickLookFileSystem(fs)

        if wrap_fs_errors:
            fs = WrapErrorsFileSystem(fs)
        return fs

    if safefs_wrap_create_fs is not None:
        create_fs = safefs_wrap_create_fs(create_fs, encrypted_folders)

    return userspacefs.simple_main(mount_point, "dbxfs", create_fs, args)
コード例 #38
0
def authenticate(param):
    """
        Authenticates either via file or via CAS
    """
    url1 = 'http://courses.iiit.ac.in'
    try:
        response = SESSION.get(url1)
    except ValueError:
        print("You can not make manual requests. Use PreparedRequest")
        exit()
    except TooManyRedirects:
        print("Too many redirects... Something went wrong.")
        exit()
    except ConnectionError:
        print("Could not connect to courses.iiit.ac.in. Check your config")
        exit()
    except Exception as exception:
        print('Please Check Your Internet Connection')
        os.remove(os.path.join(DATA_FILE, "data"))
        if DEBUG:
            raise exception
        exit()

    if DEBUG:
        print('Pre-Authentication Sucessfull')

    html = response.content

    if DEBUG:
        print(html)

    class MyParser(HTMLParser.HTMLParser):
        """
            HTMLParser class derivative for parseing data.
        """
        def handle_starttag(self, tag, attrs):
            """
                handle_starttag for MyParser
                handles start tag.
                What did you expect?
            """
            if tag == 'form':
                for key, value in attrs:
                    if key == 'action':
                        self.action = value
                        break
            elif tag == 'input':
                self.flag = 0
                for key, value in attrs:
                    if key == 'name' and value == 'lt':
                        self.flag = 1
                    if key == 'value' and self.flag == 1:
                        self.lt = value
                        break
    parse = MyParser()
    parse.feed(html)
    try: 
        action = parse.action
        lt = parse.lt
    except AttributeError:
        print('Parsing Failed. Something went wrong. :(')
        exit()

    if DEBUG:
        print (param)

    if '!@#$%^' not in param:
        user = raw_input('Username [eg- [email protected]] : ')
        passwd = getpass.getpass()
        try:
            keyring.set_password('Courses', user, passwd)
        except TypeError:
            print("Keyring is not of type Keyring")
        except Exception:
            if DEBUG:
                print('Something is going wrong during auth')
        param['!@#$%^'] = user
    else:
        try:
            passwd = keyring.get_password('Courses', param['!@#$%^'])
        except Exception as exception:
            print("You need to enter password manually. Keyring not supported. :(")
            passwd = getpass.getpass()
    payload = {
        'username': param['!@#$%^'],
        'password': passwd,
        'lt': lt,
        '_eventId': 'submit',
        'submit': 'Login'
    }

    if DEBUG:
        print(payload)

    action = 'https://login.iiit.ac.in' + action
    response = SESSION.post(action, data=payload)
    return 0
コード例 #39
0
ファイル: latex_table.py プロジェクト: Bonfand/reduction
import numpy as np
from astropy.table import Table, Column
from astropy import table
import requests
import keyring
from astropy import units as u

from latex_info import (latexdict, format_float, round_to_n, rounded,
                        rounded_arr, strip_trailing_zeros, exp_to_tex)

latexdict = latexdict.copy()

result = requests.get(
    'https://bio.rc.ufl.edu/secure/adamginsburg/ALMA-IMF/October2020Release/tables/metadata_sc.ecsv',
    auth=('almaimf', keyring.get_password('almaimf', 'almaimf')))
with open('metadata_sc.ecsv', 'w') as fh:
    fh.write(result.text)

result = requests.get(
    'https://bio.rc.ufl.edu/secure/adamginsburg/ALMA-IMF/tables/bandpass_fraction.ecsv',
    auth=('almaimf', keyring.get_password('almaimf', 'almaimf')))
with open('bandpass_fraction.ecsv', 'w') as fh:
    fh.write(result.text)

bp_tbl = Table.read('bandpass_fraction.ecsv')
bp_tbl['band'] = [f'B{b}' for b in bp_tbl['band']]
bp_tbl.rename_column('field', 'region')
bp_tbl = table.join(bp_tbl.group_by('config').groups[0],
                    bp_tbl.group_by('config').groups[1],
                    keys=('region', 'band'))
bp_tbl.rename_column('bwfrac_1', '12Mlong_frac')
コード例 #40
0
ファイル: credential.py プロジェクト: yaxum62/ytpldiff
 def __enter__(self):
     self.__cred_val = keyring.get_password("ytpldiff", self.__kind.name)
     if self.__cred_val is None:
         return None
     self.__cred = self.__kind.deserialize(self.__cred_val)
     return self.__cred
コード例 #41
0
ファイル: imapdedup.py プロジェクト: xshocuspocusxd/IMAPdedup
def get_arguments(
        args: Optional[List[str]] = None
) -> Tuple[argparse.Namespace, List[str]]:
    """
    Parse the given command-line arguments - defaults to using sys.argv
    """

    parser = argparse.ArgumentParser(
        description="Mark duplicate messages in IMAP mailboxes for deletion")
    parser.add_argument("-P",
                        "--process",
                        dest="process",
                        help="IMAP process to access mailboxes")
    parser.add_argument("-s", "--server", dest="server", help="IMAP server")
    parser.add_argument("-p",
                        "--port",
                        dest="port",
                        help="IMAP server port",
                        type=int)
    parser.add_argument("-x",
                        "--ssl",
                        dest="ssl",
                        action="store_true",
                        help="Use SSL")
    parser.add_argument("-X",
                        "--starttls",
                        dest="starttls",
                        action="store_true",
                        help="Require STARTTLS")
    parser.add_argument("-u", "--user", dest="user", help="IMAP user name")
    parser.add_argument("-K",
                        "--keyring",
                        dest="keyring",
                        help="Keyring name to get password")
    parser.add_argument(
        "-w",
        "--password",
        dest="password",
        help="IMAP password (Will prompt if not specified)",
    )
    parser.add_argument("-v",
                        "--verbose",
                        dest="verbose",
                        action="store_true",
                        help="Verbose mode")
    parser.add_argument("-S",
                        "--show",
                        dest="show",
                        action="store_true",
                        help="Show duplicated messages")
    parser.add_argument(
        "-n",
        "--dry-run",
        dest="dry_run",
        action="store_true",
        help="Don't actually do anything, just report what would be done",
    )
    parser.add_argument(
        "-c",
        "--checksum",
        dest="use_checksum",
        action="store_true",
        help=
        "Use a checksum of several mail headers, instead of the Message-ID",
    )
    parser.add_argument(
        "-b",
        "--sentbefore",
        dest="sent_before",
        help=
        "Only process messages sent before given date, given as d-m-y, e.g: 1-Feb-2020. Useful when there are many duplicates of each message",
    )
    parser.add_argument(
        "-m",
        "--checksum-with-id",
        dest="use_id_in_checksum",
        action="store_true",
        help="Include the Message-ID (if any) in the -c checksum.",
    )
    parser.add_argument(
        "--no-close",
        dest="no_close",
        action="store_true",
        help=
        'Do not "close" mailbox when done. Some servers will purge deleted messages on a close command.',
    )
    parser.add_argument(
        "-l",
        "--list",
        dest="just_list",
        action="store_true",
        help="Just list mailboxes",
    )
    parser.add_argument(
        "-r",
        "--recursive",
        dest="recursive",
        action="store_true",
        help="Remove duplicates recursively",
    )
    parser.add_argument(
        "-R",
        "--reverse",
        dest="reverse",
        action="store_true",
        help="Walk through the folders in reverse order",
    )
    parser.add_argument(
        "-t",
        "--only-tag",
        dest="only_tag",
        action="store_true",
        help="Tag duplicates with '%s' instead of deleting them" % TAG_NAME)
    parser.add_argument('mailbox', nargs='*')

    options = parser.parse_args(args)
    mboxes = options.mailbox

    if ((not options.server) or (not options.user)) and not options.process:
        sys.stderr.write(
            "\nError: Must specify server, user, and at least one mailbox.\n\n"
        )
        parser.print_help()
        sys.exit(1)

    if options.recursive and len(mboxes) > 1:
        sys.stderr.write(
            "\nError: You can only specify one mailbox if you use -r.\n")
        sys.exit(1)

    if options.use_id_in_checksum and not options.use_checksum:
        sys.stderr.write("\nError: If you use -m you must also use -c.\n")
        sys.exit(1)

    if options.keyring:
        import keyring
        options.password = keyring.get_password(options.keyring, options.user)

    if not options.password and not options.process:
        # Read from IMAPDEDUP_PASSWORD env variable, or prompt for one.
        options.password = os.getenv("IMAPDEDUP_PASSWORD") or getpass.getpass()

    return (options, mboxes)
コード例 #42
0
def populate_keyring_fixture():
    cli = make_cli()
    keyring.set_password(cli.name, USER, PW)
    assert keyring.get_password(cli.name, USER) == PW
コード例 #43
0
ファイル: conf.py プロジェクト: mmohring/osc
def get_config(override_conffile=None,
               override_apiurl=None,
               override_debug=None,
               override_http_debug=None,
               override_http_full_debug=None,
               override_traceback=None,
               override_post_mortem=None,
               override_no_keyring=None,
               override_no_gnome_keyring=None,
               override_verbose=None):
    """do the actual work (see module documentation)"""
    global config

    conffile = override_conffile or os.environ.get('OSC_CONFIG', '~/.oscrc')
    conffile = os.path.expanduser(conffile)

    if not os.path.exists(conffile):
        raise oscerr.NoConfigfile(conffile, \
                                  account_not_configured_text % conffile)

    # okay, we made sure that .oscrc exists

    # make sure it is not world readable, it may contain a password.
    os.chmod(conffile, 0o600)

    cp = get_configParser(conffile)

    if not cp.has_section('general'):
        # FIXME: it might be sufficient to just assume defaults?
        msg = config_incomplete_text % conffile
        msg += new_conf_template % DEFAULTS
        raise oscerr.ConfigError(msg, conffile)

    config = dict(cp.items('general', raw=1))
    config['conffile'] = conffile

    for i in boolean_opts:
        try:
            config[i] = cp.getboolean('general', i)
        except ValueError as e:
            raise oscerr.ConfigError(
                'cannot parse \'%s\' setting: ' % i + str(e), conffile)

    config['packagecachedir'] = os.path.expanduser(config['packagecachedir'])
    config['exclude_glob'] = config['exclude_glob'].split()

    re_clist = re.compile('[, ]+')
    config['extra-pkgs'] = [
        i.strip() for i in re_clist.split(config['extra-pkgs'].strip()) if i
    ]

    # collect the usernames, passwords and additional options for each api host
    api_host_options = {}

    # Regexp to split extra http headers into a dictionary
    # the text to be matched looks essentially looks this:
    # "Attribute1: value1, Attribute2: value2, ..."
    # there may be arbitray leading and intermitting whitespace.
    # the following regexp does _not_ support quoted commas within the value.
    http_header_regexp = re.compile(r"\s*(.*?)\s*:\s*(.*?)\s*(?:,\s*|\Z)")

    # override values which we were called with
    # This needs to be done before processing API sections as it might be already used there
    if override_no_keyring:
        config['use_keyring'] = False
    if override_no_gnome_keyring:
        config['gnome_keyring'] = False

    aliases = {}
    for url in [x for x in cp.sections() if x != 'general']:
        # backward compatiblity
        scheme, host = parse_apisrv_url(config.get('scheme', 'https'), url)
        apiurl = urljoin(scheme, host)
        user = None
        password = None
        if config['use_keyring'] and GENERIC_KEYRING:
            try:
                # Read from keyring lib if available
                user = cp.get(url, 'user', raw=True)
                password = keyring.get_password(host, user)
            except:
                # Fallback to file based auth.
                pass
        elif config['gnome_keyring'] and GNOME_KEYRING:
            # Read from gnome keyring if available
            try:
                gk_data = gnomekeyring.find_network_password_sync(
                    protocol=scheme, server=host)
                if not 'user' in gk_data[0]:
                    raise oscerr.ConfigError('no user found in keyring',
                                             conffile)
                user = gk_data[0]['user']
                if 'password' in gk_data[0]:
                    password = gk_data[0]['password']
                else:
                    # this is most likely an error
                    print('warning: no password found in keyring',
                          file=sys.stderr)
            except gnomekeyring.NoMatchError:
                # Fallback to file based auth.
                pass

        if not user is None and len(user) == 0:
            user = None
            print('Warning: blank user in the keyring for the ' \
                'apiurl %s.\nPlease fix your keyring entry.', file=sys.stderr)

        if user is not None and password is None:
            err = (
                'no password defined for "%s".\nPlease fix your keyring '
                'entry or gnome-keyring setup.\nAssuming an empty password.' %
                url)
            print(err, file=sys.stderr)
            password = ''

        # Read credentials from config
        if user is None:
            #FIXME: this could actually be the ideal spot to take defaults
            #from the general section.
            user = cp.get(url, 'user',
                          raw=True)  # need to set raw to prevent '%' expansion
            password = cp.get(url, 'pass', raw=True)  # especially on password!
            try:
                passwordx = cp.get(url,
                                   'passx', raw=True).decode('base64').decode(
                                       'bz2')  # especially on password!
            except:
                passwordx = ''

            if password == None or password == 'your_password':
                password = ''

            if user is None or user == '':
                raise oscerr.ConfigError(
                    'user is blank for %s, please delete or complete the "user=" entry in %s.'
                    % (apiurl, config['conffile']), config['conffile'])

            if config['plaintext_passwd'] and passwordx or not config[
                    'plaintext_passwd'] and password:
                if config['plaintext_passwd']:
                    if password != passwordx:
                        print('%s: rewriting from encoded pass to plain pass' %
                              url,
                              file=sys.stderr)
                    add_section(conffile, url, user, passwordx)
                    password = passwordx
                else:
                    if password != passwordx:
                        print('%s: rewriting from plain pass to encoded pass' %
                              url,
                              file=sys.stderr)
                    add_section(conffile, url, user, password)

            if not config['plaintext_passwd']:
                password = passwordx

        if cp.has_option(url, 'http_headers'):
            http_headers = cp.get(url, 'http_headers')
            http_headers = http_header_regexp.findall(http_headers)
        else:
            http_headers = []
        if cp.has_option(url, 'aliases'):
            for i in cp.get(url, 'aliases').split(','):
                key = i.strip()
                if key == '':
                    continue
                if key in aliases:
                    msg = 'duplicate alias entry: \'%s\' is already used for another apiurl' % key
                    raise oscerr.ConfigError(msg, conffile)
                aliases[key] = url

        api_host_options[apiurl] = {
            'user': user,
            'pass': password,
            'http_headers': http_headers
        }

        optional = ('email', 'sslcertck', 'cafile', 'capath')
        for key in optional:
            if cp.has_option(url, key):
                if key == 'sslcertck':
                    api_host_options[apiurl][key] = cp.getboolean(url, key)
                else:
                    api_host_options[apiurl][key] = cp.get(url, key)

        if not 'sslcertck' in api_host_options[apiurl]:
            api_host_options[apiurl]['sslcertck'] = True

        if scheme == 'http':
            api_host_options[apiurl]['sslcertck'] = False

        if cp.has_option(url, 'trusted_prj'):
            api_host_options[apiurl]['trusted_prj'] = cp.get(
                url, 'trusted_prj').split(' ')
        else:
            api_host_options[apiurl]['trusted_prj'] = []

    # add the auth data we collected to the config dict
    config['api_host_options'] = api_host_options
    config['apiurl_aliases'] = aliases

    apiurl = aliases.get(config['apiurl'], config['apiurl'])
    config['apiurl'] = urljoin(*parse_apisrv_url(None, apiurl))
    # backward compatibility
    if 'apisrv' in config:
        apisrv = config['apisrv'].lstrip('http://')
        apisrv = apisrv.lstrip('https://')
        scheme = config.get('scheme', 'https')
        config['apiurl'] = urljoin(scheme, apisrv)
    if 'apisrc' in config or 'scheme' in config:
        print('Warning: Use of the \'scheme\' or \'apisrv\' in ~/.oscrc is deprecated!\n' \
                            'Warning: See README for migration details.', file=sys.stderr)
    if 'build_platform' in config:
        print(
            'Warning: Use of \'build_platform\' config option is deprecated! (use \'build_repository\' instead)',
            file=sys.stderr)
        config['build_repository'] = config['build_platform']

    config['verbose'] = int(config['verbose'])
    # override values which we were called with
    if override_verbose:
        config['verbose'] = override_verbose + 1

    if override_debug:
        config['debug'] = override_debug
    if override_http_debug:
        config['http_debug'] = override_http_debug
    if override_http_full_debug:
        config['http_debug'] = override_http_full_debug or config['http_debug']
        config['http_full_debug'] = override_http_full_debug
    if override_traceback:
        config['traceback'] = override_traceback
    if override_post_mortem:
        config['post_mortem'] = override_post_mortem
    if override_apiurl:
        apiurl = aliases.get(override_apiurl, override_apiurl)
        # check if apiurl is a valid url
        config['apiurl'] = urljoin(*parse_apisrv_url(None, apiurl))

    # XXX unless config['user'] goes away (and is replaced with a handy function, or
    # config becomes an object, even better), set the global 'user' here as well,
    # provided that there _are_ credentials for the chosen apiurl:
    try:
        config['user'] = get_apiurl_usr(config['apiurl'])
    except oscerr.ConfigMissingApiurl as e:
        e.msg = config_missing_apiurl_text % config['apiurl']
        e.file = conffile
        raise e

    # finally, initialize urllib2 for to use the credentials for Basic Authentication
    init_basicauth(config)
コード例 #44
0
import getpass
import keyring # pip3 install keyring
import re

# Customize this!

define_success = {
	'QB Rush': 5,
	'Outside Run': 3,
	'Inside Run': 3,
	'Pass': 0
}

#Checking/Prompting for username/password

user_name = keyring.get_password('glb2', 'user_name')
password = keyring.get_password('glb2', 'password')
if user_name is None:
	user_name = input('Your GLB2 Username: '******'glb2', 'user_name', user_name)
if password is None:
	password = getpass.getpass('Your GLB2 Password: '******'glb2', 'password', password)

login = {'action': 'login','user_name': user_name,'password': password}

# Grabs the whole defensive playbook:

import requests # pip3 install requests
import json
コード例 #45
0
ファイル: snippet.py プロジェクト: someburner/GistsHub
def parseArgs():

    # override the default parser to allow new lines
    class Parser(optparse.OptionParser):
        def format_epilog(self, formatter):
            return self.epilog

    global username, password, verbose, cacheExpiresNSec, useCache
    parser = Parser(usage="usage: %prog [options]",
        description="A simple Gmail unread count script for i3status or conky \
bars, using simple caching (avoid overhead in simplistic approaches such as \
i3status).",
        version="%%prog %s" % __VERSION__,
        epilog="""
Notes:

This script will attempt to access the account's password in the following manner:
  - if --password is informed, will use it
  - if not, will see if it has been hard-coded within the script (some people
    may prefer that)
  - lastly, if none of the above satisfies, it will retrieve it from keyring,
    if available. To add your password to the keyring, use option --add-keyring

""")
    parser.add_option("-u", "--username", dest="username", action="store",
                      help="The Gmail username (without the gmail.com). \
If Google Apps account, need to inform the complete email address.")

    parser.add_option("-p", "--password", dest="password", action="store",
                      help="The plain text password associated with the \
username. If not informed, this script will try to retrieve it from keyring. \
Alternatively, you can set the password by hand in this script source, if you \
don't want to send it as option. See source code for details.")

    parser.add_option("-r", "--refresh", dest="refresh", action="store",
                      help="minimum period, in seconds, to allow another call \
to Google (this is just to avoid HTTP overhead). Default value is %d. If using \
conky, you can use --no-cache option if you define execution time rules in \
conkyrc." % cacheExpiresNSec)

    parser.add_option("-v", "--verbose", dest="verbose", default=False,
                      action="store_true",
                      help="Used for troubleshooting problems (do not use this \
with output bars, which are usually expecting very few chars).")

    parser.add_option("-a", "--add-keyring", dest="add", default=False,
                      action="store_true",
                      help="Prompts for the password to store it in Gnome \
Keyring. Useful if it is the first time using this script.")

    parser.add_option("-n", "--no-cache", dest="cache", default=True,
                      action="store_false",
                      help="Does not use cache (overrides --refresh option). \
Only use this if you are controlling the calls to this script by yourself or \
another program (such as conky, etc).")

    (options, args) = parser.parse_args()
    verbose = options.verbose
    username = options.username
    useCache = options.cache

    # validate username
    if not username or len(username) == 0:
        dieGracefully("The --username option is required!")

    if options.add:
        setKeyringPassword()

    # validate password
    if not password or len(password) == 0:
        # no passwords stored locally, try to get from options
        password = options.password
        if not password:
            # still nothing, try from keyring
            try:
                import keyring
                password  = keyring.get_password(__NAME__, username)
                if not password:
                    dieGracefully("""Password not available (not in keyring).
Try to either:
    a) use option --password;
    b) add your password to keyring (see --help for details); or
    c) hard-code your password in this script (see password variable).
""")
            except Exception, e:
                dieGracefully("keyring module not found. See --help for details.")
コード例 #46
0
import secure_passwords
import keyring

MAGIC_USERNAME_KEY = 'im_the_magic_username_key'

# the service is just a namespace for your app
service_id = 'IM_YOUR_APP!'

netID = keyring.get_password(service_id, MAGIC_USERNAME_KEY)
password = keyring.get_password(service_id, netID)
コード例 #47
0
ファイル: CFx.py プロジェクト: renatof/ModController
    def parse_config(self):
        self.CONFIG = fxlib.CONFIG

        parser = argparse.ArgumentParser()
        parser.add_argument("-c",
                            help="load configuration from a file",
                            dest="config_file",
                            metavar="config_file")
        parser.add_argument("-u",
                            help="update configuration file if needed",
                            dest="update_config",
                            action="store_true")
        parser.add_argument("-p",
                            help="load remote ip configuration file",
                            dest="ip_config",
                            metavar="ip_config")
        parser.add_argument("-s",
                            help="configuration as json string"
                            " (overrides configuration from file)",
                            dest="config_string",
                            metavar="config_string")
        parser.add_argument("--pwdstdout",
                            help="use stdout as "
                            "password stream",
                            dest="pwdstdout",
                            action="store_true")

        args = parser.parse_args()

        if args.config_file:
            # load the configuration file
            with open(args.config_file) as f:
                # load the configuration file into an OrderedDict with the
                # modules in the order in which they appear
                self.json_data = json.load(f, object_pairs_hook=OrderedDict)
                for key in self.json_data:
                    if self.CONFIG.get(key, False):
                        self.CONFIG[key].update(self.json_data[key])
                    else:
                        self.CONFIG[key] = self.json_data[key]

        if args.config_string:
            loaded_config = json.loads(args.config_string)
            for key in loaded_config:
                if self.CONFIG.get(key, None):
                    self.CONFIG[key].update(loaded_config[key])

        need_save = self.setup_config(self.CONFIG)
        if need_save and args.config_file and args.update_config:
            with open(args.config_file, "w") as f:
                json.dump(self.CONFIG, f, indent=4, sort_keys=True)

        if not ("xmpp_username" in self.CONFIG["CFx"]
                and "xmpp_host" in self.CONFIG["CFx"]):
            raise ValueError("At least 'xmpp_username' and 'xmpp_host' "
                             "must be specified in config file or string")
        keyring_installed = False
        try:
            import keyring
            keyring_installed = True
        except:
            print("keyring module is not installed")

        if "xmpp_password" not in self.CONFIG["CFx"]:
            xmpp_pswd = None
            if keyring_installed:
                xmpp_pswd = keyring.get_password(
                    "ipop", self.CONFIG["CFx"]["xmpp_username"])
            if not keyring_installed or (keyring_installed
                                         and xmpp_pswd == None):
                prompt = "\nPassword for %s:" % self.CONFIG["CFx"][
                    "xmpp_username"]
                if args.pwdstdout:
                    xmpp_pswd = getpass(prompt, stream=sys.stdout)
                else:
                    xmpp_pswd = getpass(prompt)

            if xmpp_pswd != None:
                self.CONFIG["CFx"]["xmpp_password"] = xmpp_pswd
                if keyring_installed:
                    try:
                        keyring.set_password(
                            "ipop", self.CONFIG["CFx"]["xmpp_username"],
                            self.CONFIG["CFx"]["xmpp_password"])
                    except:
                        print("unable to store password in keyring")
            else:
                raise RuntimeError("no XMPP password found")

        if args.ip_config:
            fxlib.load_peer_ip_config(args.ip_config)
コード例 #48
0
def readLocalSettings(args=settingsArgs(), readonlyuser=True, dbalias=None):
    """Retrieves/updates last used settings from the local settings file .geoslurp_lastused.yaml"""

    #We need a deepcopy to properly separate input from output, and funny behavior
    argsout = copy.deepcopy(args)

    if dbalias:
        #overrules possible value from args
        argsout.dbalias = dbalias

    if argsout.local_settings:
        settingsFile = argsout.local_settings
    else:
        settingsFile = os.path.join(os.path.expanduser('~'),
                                    '.geoslurp_lastused.yaml')
    #read last used settings
    if os.path.exists(settingsFile):
        #Read parameters from yaml file
        with open(settingsFile, 'r') as fid:
            lastOpts = yaml.safe_load(fid)
    else:
        if not argsout.dbalias:
            argsout.dbalias = "geoslurp"
        #set the defaults (note a host with None will try to connect to a local unix socket
        lastOpts = {"dbalias": args.dbalias, args.dbalias: defaultdbdict}

    isUpdated = False
    if argsout.dbalias:
        lastOpts["dbalias"] = argsout.dbalias
        dbalias = argsout.dbalias
    else:
        #ue the default from the configuration file
        dbalias = lastOpts["dbalias"]
        argsout.dbalias = dbalias

    if not dbalias in lastOpts:
        #create a defaukt entry for this alias
        lastOpts[dbalias] = defaultdbdict

    #update dict with provided options from argsout
    if argsout.host:
        lastOpts[dbalias]["host"] = argsout.host
        isUpdated = True
    else:
        #take data from file options
        try:
            argsout.host = lastOpts[dbalias]["host"]
        except KeyError:
            #this will be interpreted as a unix socket
            argsout.host = ""
            # print("--host option is needed for initialization",file=sys.stderr)
            # sys.exit(1)

    if argsout.port:
        lastOpts[dbalias]["port"] = argsout.port
        isUpdated = True
    else:
        lastOpts[dbalias]["port"] = 5432

    if argsout.user:
        if readonlyuser:
            lastOpts[dbalias]["readonlyUser"] = argsout.user
        else:
            lastOpts[dbalias]["user"] = argsout.user
        isUpdated = True
    else:
        try:
            if readonlyuser:
                argsout.user = lastOpts[dbalias]["readonlyUser"]
            else:
                argsout.user = lastOpts[dbalias]["user"]

        except KeyError:
            print("--user option is needed for initialization",
                  file=sys.stderr)
            sys.exit(1)

    if argsout.usekeyring != None:
        #use the provided value (when explicitly set to False or True)
        lastOpts["useKeyring"] = True
        isUpdated = True
    else:
        try:
            argsout.usekeyring = lastOpts["useKeyring"]
        except KeyError:
            #don't use the keyring
            pass

    # we take a different strategy for the password as we don't want to store this unencrypted in a file
    if not argsout.password:
        if argsout.usekeyring:
            try:
                argsout.password = keyring.get_password(
                    "geoslurp", argsout.user)
                hasBackend = True
            except RuntimeError:
                slurplog.warning("no suitable python keyring backend found")
                argsout.password = None
                hasBackend = False

            if not argsout.password:
                argsout.password = getpass.getpass(
                    prompt='Please enter password for %s: ' % (argsout.user))
                if hasBackend:
                    keyring.set_password("geoslurp", argsout.user,
                                         argsout.password)
        else:
            #try checking the environment variable GEOSLURP_PGPASS
            try:
                if readonlyuser:
                    argsout.password = os.environ["GEOSLURP_PGPASSRO"]
                else:
                    argsout.password = os.environ["GEOSLURP_PGPASS"]
            except KeyError:
                #check for password in the lastused file (needs to be manually entered)
                if "passwd" in lastOpts[dbalias] and not readonlyuser:
                    argsout.password = lastOpts[dbalias]["passwd"]
                elif "readonlyPasswd" in lastOpts[dbalias] and readonlyuser:
                    argsout.password = lastOpts[dbalias]["readonlyPasswd"]
                else:
                    #prompt for password
                    argsout.password = getpass.getpass(
                        prompt='Please enter password for %s: ' %
                        (argsout.user))
                    if argsout.write_local_settings:
                        print(
                            "Warning: user database password will be stored unencrypted in the geoslurp configuration file,"
                            "consider using a keyring")
                        if readonlyuser:
                            lastOpts[dbalias][
                                "readonlyPasswd"] = argsout.password
                        else:
                            lastOpts[dbalias]["passwd"] = argsout.password
    else:
        #update keyring
        if argsout.usekeyring and argsout.write_local_settings:
            keyring.set_password("geoslurp", argsout.user, argsout.password)

    if argsout.dataroot:
        #register path to local data root
        lastOpts[dbalias]["dataroot"] = argsout.dataroot
    else:
        if "dataroot" in lastOpts[dbalias]:
            argsout.dataroot = lastOpts[dbalias]["dataroot"]
        else:
            argsout.dataroot = os.path.join(os.path.expanduser('~'),
                                            'geoslurp_data')

    if argsout.cache:
        lastOpts[dbalias]["cache"] = argsout.cache
    else:
        if "cache" in lastOpts[dbalias]:
            argsout.cache = lastOpts[dbalias]["cache"]
        else:
            argsout.cache = "/tmp/geoslurp_cache"

    if argsout.plugindir:
        lastOpts[dbalias]["plugindir"] = argsout.plugindir
    else:
        if "plugindir" in lastOpts[dbalias]:
            argsout.plugindir = lastOpts[dbalias]["plugindir"]
        else:
            argsout.plugindir = defaultdbdict["plugindir"]

    #write out  options to file to store these settings
    if isUpdated and argsout.write_local_settings:
        lastOpts["lastupdate"] = datetime.now()
        with open(settingsFile, 'w') as fid:
            yaml.dump(lastOpts, fid, default_flow_style=False)

    return argsout
コード例 #49
0
ファイル: getpackages.py プロジェクト: plaljx/ToMaTo
def parseArgs():
    """
	Defines required and optional arguments for the cli and parses them out of sys.argv.

	Available Arguments are:
			Argument *--help*:
					Prints a help text for the available arguments
			Argument *--hostname*:
					Address of the host of the server
			Argument *--port*:
					Port of the host server
			Argument *--ssl*:
					Whether to use ssl or not
			Argument *--client_cert*:
					Path to the ssl certificate of the client
			Argument *--username*:
					The username to use for login
			Argument *--password*:
					The password to user for login
			Argument *--file*:
					Path to a file to execute
			Argument *arguments*
					Python code to execute directly

	Return value:
			Parsed command-line arguments

	"""
    parser = argparse.ArgumentParser(
        prog="ToMaTo Package Installer Creator for RexTFV",
        description=
        "This program uses a package configuration and creates an archive which can install the given packages on a ToMaTo VM via Executable Archives.",
        epilog=
        "This program uploads a probing archive to ToMaTo in order to determine package dependencies. You need a ToMaTo account to do this.",
        add_help=False)
    parser.add_argument('--help', action='help')
    parser.add_argument("--hostname",
                        "-h",
                        required=True,
                        help="the host of the server")
    parser.add_argument("--port",
                        "-p",
                        default=8000,
                        help="the port of the server")
    parser.add_argument("--ssl",
                        "-s",
                        action="store_true",
                        default=False,
                        help="whether to use ssl")
    parser.add_argument("--client_cert",
                        required=False,
                        default=None,
                        help="path of the ssl certificate")
    parser.add_argument("--username",
                        "-U",
                        help="the username to use for login")
    parser.add_argument("--password",
                        "-P",
                        help="the password to use for login")
    parser.add_argument("--no-keyring",
                        action="store_true",
                        default=False,
                        help="ignore password stored in keyring")
    parser.add_argument("--target",
                        "-t",
                        help="the output filename.",
                        required=True)
    parser.add_argument(
        "--packetconfig",
        "-c",
        help=
        'The archive configuration. This should point to a JSON file of the form [{type:"string",site:"string",template:"string",packages:["string"]}]. Each entry must refer to a different operating system.',
        required=True)
    parser.add_argument("--verbose",
                        "-v",
                        help="verbose output",
                        action="store_true",
                        default=False)
    options = parser.parse_args()
    if not options.username and not options.client_cert:
        options.username = raw_input("Username: "******"ToMaTo"
                KEYRING_USER_NAME = "%s/%s" % (options.hostname,
                                               options.username)
                options.password = keyring.get_password(
                    KEYRING_SERVICE_NAME, KEYRING_USER_NAME)
            except ImportError:
                pass
        if not options.password:
            options.password = getpass.getpass("Password: ")
    if options.verbose:
        debugger.setVerbose()
    return options
コード例 #50
0
#########################################
# Logging et import des fonctions dont on a besoin.

from pyquickhelper.loghelper import fLOG  # fetch_student_projects_from_gmail
fLOG(OutputPrint=True)

from ensae_teaching_cs.automation_students import ProjectsRepository, grab_addresses
from pyquickhelper.filehelper import encrypt_stream
from pymmails import MailBoxImap, EmailMessageRenderer, EmailMessageListRenderer
from pymmails.render.email_message_style import template_email_html_short

###########
# Identifiants. On utilise :epkg:`keyring` pour récupérer des mots de passe.

user = keyring.get_password("gmail", "ensae_teaching_cs,user")
pwd = keyring.get_password("gmail", "ensae_teaching_cs,pwd")
password = keyring.get_password("enc", "ensae_teaching_cs,pwd")
if user is None or pwd is None or password is None:
    print(
        "ERROR: password or user or crypting password is empty, you should execute:"
    )
    print('keyring.set_password("gmail", "ensae_teaching_cs,user", "..")')
    print('keyring.set_password("gmail", "ensae_teaching_cs,pwd", "..")')
    print('keyring.set_password("enc", "ensae_teaching_cs,pwd", "..")')
    print("Exit")
    sys.exit(0)

password = bytes(password, "ascii")

###########
コード例 #51
0
 def _get_keyring_password(self, service, user):
     password = keyring.get_password(service, user)
     if not password:
         password = self._generate_random_password()
         keyring.set_password(service, user, password)
     return password
コード例 #52
0
    def __init__(self, unpickle=True):
        self.pickle = True
        home = str(Path.home())
        cfgpath = os.path.join(home, 'google.ini')
        cfg = configparser.ConfigParser()
        try:
            cfg.read(cfgpath)
        except Exception as e:
            print("Failed to read google.ini", str(e))
            sys.exit(1)
        #print(cfg.sections())
        if 'keep' not in cfg.sections():
            print('Require [keep] section from google.ini')
            sys.exit(1)

        kc = cfg['keep']
        oops = False
        for p in ['cachedir', 'cachefile', 'keepID', 'keepAPW']:
            if p not in kc:
                print(f"google.ini keep section missing {p} parameter")
                oops = True
        if oops:
            sys.exit(2)

        self.kPath = os.path.join(kc['cachedir'], kc['cachefile'])
        loginDone = False
        if unpickle:  # the client data retrieved is an authenticated session
            self.keep = pickle.load(open(self.kPath, 'rb'))
            #self.keep.sync()  # If fails, authentication might be required?
            # !! add exception processing to detect login necessity !!
            loginDone = True
        else:
            self.keep = gkeepapi.Keep()
            kid = kc['keepID']
            print(f"Login with ID:", kid)
            try:
                mtok = keyring.get_password('Keep', kid)
                if mtok:
                    print(f"Resuming with master token: {mtok}")
                    try:
                        success = self.keep.resume(kid, mtok)
                        print("Keep resume success:", success)
                        loginDone = True
                    except Exception as e:
                        print("Keep resume failed:", str(e))
                if not loginDone:
                    print("Login with app password...")
                    success = self.keep.login(kid, kc['keepAPW'])
                    print("Keep login success:", success)
                    loginDone = True
                    mtok = self.keep.getMasterToken()
                    try:
                        keyring.set_password('Keep', kid,
                                             mtok)  # alt to pickle
                    except Exception as e:
                        print(
                            "Failed to store password, probably cron-initiated"
                            + str(e))
            except Exception as e:
                print('Keep login failed: ' + str(e))
                sys.exit(3)
        self.keep.sync()
コード例 #53
0
 def password(self):
     try:
         return keyring.get_password(APP_NAME, self.username)
     except keyring.errors.KeyringError:
         logger.info("Cannot retrieve saved password from keyring.")
         return ""
コード例 #54
0
# -*- coding: utf-8 -*-
"""
Created on Wed May 24 11:09:53 2017

@author: jzuber
"""
import keyring
import requests
import progressbar

import pandas as pd

api_key = keyring.get_password('google-api', '*****@*****.**')


def get_drive_time(origin_zip, destination_zip):
    """
    Returns driving time from origin to destination in hours.
    """

    try:
        origin_zip = '{0:05d}'.format(origin_zip)
    except ValueError:
        origin_zip = '{0:05d}'.format(int(origin_zip))

    try:
        destination_zip = '{0:05d}'.format(destination_zip)
    except ValueError:
        destination_zip = '{0:05d}'.format(int(destination_zip))

    url = "https://maps.googleapis.com/maps/api/directions/json"
コード例 #55
0
ファイル: test_storage.py プロジェクト: opnmind/osenv-tool
"""Python 2 compat."""
try:
    import builtins
except ImportError:
    import __builtin__ as builtins

if "ResourceWarning" not in vars(builtins):

    class ResourceWarning(Warning):
        pass


try:
    keyring.set_password("TESTSYS", "BACKEND_TEST", "OK")
    password = keyring.get_password("TESTSYS", "BACKEND_TEST")
    if password is not "OK":
        raise RuntimeError
    keyring.delete_password("TESTSYS", "BACKEND_TEST")
    keyring_backend_available = True
except RuntimeError:
    keyring_backend_available = False


@unittest.skipIf(keyring_backend_available is False,
                 "No keyring backend not available.")
@unittest.skipIf(sys.version_info[:2] <= (2, 7),
                 "Keyring does not support python 2.7.")
class TestStorageKeyring(unittest.TestCase):
    data = (
        "https://python-reference.readthedocs.io/en/latest/docs/statements/assert.html"
コード例 #56
0
import json
import pymongo
import keyring
import math

password = keyring.get_password('nba_draft_stats', 'draftDataUser')
dbUrl = "".join([
    "mongodb+srv://draftDataUser:"******"@draftdatacluster.w18yo.mongodb.net/nba_draft_database?retryWrites=true&w=majority"
])

client = pymongo.MongoClient(dbUrl)
db = client.nba_draft_database
nba_draft_data = db.nba_draft_data


def getDraftScores(buckets):

    bestDraftScore = float("-inf")
    bestDraftPlayer = None

    playerDraftScores = []
    teamDraftScores = []

    picksPerTeam = {}
    totalDraftScorePerTeam = {}
    averageDraftScorePerTeam = {}
    for year in range(1989, 2019):
        print(year)
        draftedPlayers = nba_draft_data.find({"draft_year": year})
        draftedPlayersSorted = nba_draft_data.find({
コード例 #57
0
    def __init__(self, cookie_file=None, domain_name="", key_file=None):
        self.salt = b'saltysalt'
        self.iv = b' ' * 16
        self.length = 16
        # domain name to filter cookies by
        self.domain_name = domain_name
        if sys.platform == 'darwin':
            # running Chrome on OSX
            my_pass = keyring.get_password('Chrome Safe Storage',
                                           'Chrome').encode(
                                               'utf8')  # get key from keyring
            iterations = 1003  # number of pbkdf2 iterations on mac
            self.key = PBKDF2(my_pass, self.salt,
                              iterations=iterations).read(self.length)
            cookie_file = cookie_file \
                or os.path.expanduser('~/Library/Application Support/Google/Chrome/Default/Cookies')

        elif sys.platform.startswith('linux'):
            # running Chrome on Linux
            for name in ('Chrome', 'Chromium'):
                my_pass = get_linux_pass(name)
                if my_pass is not None:
                    my_pass = my_pass.encode('utf8')
                    if name == 'Chromium':
                        paths = map(os.path.expanduser, [
                            '~/.config/chromium/Default/Cookies',
                        ])
                    else:
                        paths = map(os.path.expanduser, [
                            '~/.config/google-chrome/Default/Cookies',
                            '~/.config/google-chrome-beta/Default/Cookies'
                        ])
                    break
            else:
                # try default key 'peanuts' with all possible paths (probably won't work)
                my_pass = '******'
                paths = map(os.path.expanduser, [
                    '~/.config/google-chrome/Default/Cookies',
                    '~/.config/chromium/Default/Cookies',
                    '~/.config/google-chrome-beta/Default/Cookies'
                ])
            iterations = 1
            self.key = PBKDF2(my_pass, self.salt,
                              iterations=iterations).read(self.length)
            cookie_file = cookie_file or next(filter(os.path.exists, paths),
                                              None)

        elif sys.platform == "win32":

            # Read key from file
            key_file = key_file or glob.glob(os.path.join(os.getenv('APPDATA', ''), '..\Local\\Google\\Chrome\\User Data\\Local State')) \
                or glob.glob(os.path.join(os.getenv('LOCALAPPDATA', ''), 'Google\\Chrome\\User Data\\Local State')) \
                or glob.glob(os.path.join(os.getenv('APPDATA', ''), 'Google\\Chrome\\User Data\\Local State'))

            if isinstance(key_file, list):
                if key_file:
                    key_file = key_file[0]

            if key_file:
                f = open(key_file, 'rb')
                key_file_json = json.load(f)
                key64 = key_file_json['os_crypt']['encrypted_key'].encode(
                    'utf-8')

                # Decode Key, get rid of DPAPI prefix, unprotect data
                keydpapi = base64.standard_b64decode(key64)[5:]
                _, self.key = crypt_unprotect_data(keydpapi, is_key=True)

            # get cookie file from APPDATA
            # Note: in windows the \\ is required before a u to stop unicode errors
            cookie_file = cookie_file or windows_group_policy_path() \
                or glob.glob(os.path.join(os.getenv('APPDATA', ''), '..\Local\\Google\\Chrome\\User Data\\Default\\Cookies')) \
                or glob.glob(os.path.join(os.getenv('LOCALAPPDATA', ''), 'Google\\Chrome\\User Data\\Default\\Cookies')) \
                or glob.glob(os.path.join(os.getenv('APPDATA', ''), 'Google\\Chrome\\User Data\\Default\\Cookies'))
        else:
            raise BrowserCookieError(
                "OS not recognized. Works on Chrome for OSX, Windows, and Linux."
            )

        # if the cookie_file is None, could not find a Chrome cookie
        if cookie_file is None:
            raise BrowserCookieError('Failed to find Chrome cookie')

        # if the type of cookie_file is list, use the first element in the list
        if isinstance(cookie_file, list):
            if not cookie_file:
                raise BrowserCookieError('Failed to find Chrome cookie')
            cookie_file = cookie_file[0]

        self.tmp_cookie_file = create_local_copy(cookie_file)
コード例 #58
0
 def __init__(self, parent):
     QtWidgets.QDialog.__init__(self, parent)
     self.config_store = QtWidgets.QApplication.instance().config_store
     self.setWindowTitle(self.tr('Photini: settings'))
     self.setLayout(QtWidgets.QVBoxLayout())
     # main dialog area
     scroll_area = QtWidgets.QScrollArea()
     self.layout().addWidget(scroll_area)
     panel = QtWidgets.QWidget()
     panel.setLayout(QtWidgets.QFormLayout())
     # apply & cancel buttons
     self.button_box = QtWidgets.QDialogButtonBox(
         QtWidgets.QDialogButtonBox.Apply
         | QtWidgets.QDialogButtonBox.Cancel)
     self.button_box.clicked.connect(self.button_clicked)
     self.layout().addWidget(self.button_box)
     # copyright holder name
     self.copyright_name = QtWidgets.QLineEdit()
     self.copyright_name.setText(
         self.config_store.get('user', 'copyright_name', ''))
     self.copyright_name.setMinimumWidth(200)
     panel.layout().addRow(self.tr('Copyright holder'), self.copyright_name)
     # creator name
     self.creator_name = QtWidgets.QLineEdit()
     self.creator_name.setText(
         self.config_store.get('user', 'creator_name', ''))
     panel.layout().addRow(self.tr('Creator'), self.creator_name)
     # reset flickr
     self.reset_flickr = QtWidgets.QCheckBox()
     panel.layout().addRow(self.tr('Disconnect from Flickr'),
                           self.reset_flickr)
     if not keyring or keyring.get_password('photini', 'flickr') is None:
         self.reset_flickr.setDisabled(True)
         panel.layout().labelForField(self.reset_flickr).setDisabled(True)
     # reset picasa
     self.reset_picasa = QtWidgets.QCheckBox()
     panel.layout().addRow(self.tr('Disconnect from Google Photos'),
                           self.reset_picasa)
     if not keyring or keyring.get_password('photini', 'picasa') is None:
         self.reset_picasa.setDisabled(True)
         panel.layout().labelForField(self.reset_picasa).setDisabled(True)
     # reset facebook
     self.reset_facebook = QtWidgets.QCheckBox()
     panel.layout().addRow(self.tr('Disconnect from Facebook'),
                           self.reset_facebook)
     if not keyring or keyring.get_password('photini', 'facebook') is None:
         self.reset_facebook.setDisabled(True)
         panel.layout().labelForField(self.reset_facebook).setDisabled(True)
     # IPTC data
     force_iptc = eval(self.config_store.get('files', 'force_iptc',
                                             'False'))
     self.write_iptc = QtWidgets.QCheckBox(self.tr('Write unconditionally'))
     self.write_iptc.setChecked(force_iptc)
     panel.layout().addRow(self.tr('IPTC metadata'), self.write_iptc)
     # sidecar files
     if_mode = eval(self.config_store.get('files', 'image', 'True'))
     sc_mode = self.config_store.get('files', 'sidecar', 'auto')
     if not if_mode:
         sc_mode = 'always'
     self.sc_always = QtWidgets.QRadioButton(self.tr('Always create'))
     self.sc_always.setChecked(sc_mode == 'always')
     panel.layout().addRow(self.tr('Sidecar files'), self.sc_always)
     self.sc_auto = QtWidgets.QRadioButton(self.tr('Create if necessary'))
     self.sc_auto.setChecked(sc_mode == 'auto')
     self.sc_auto.setEnabled(if_mode)
     panel.layout().addRow('', self.sc_auto)
     self.sc_delete = QtWidgets.QRadioButton(
         self.tr('Delete when possible'))
     self.sc_delete.setChecked(sc_mode == 'delete')
     self.sc_delete.setEnabled(if_mode)
     panel.layout().addRow('', self.sc_delete)
     # image file locking
     self.write_if = QtWidgets.QCheckBox(self.tr('(when possible)'))
     self.write_if.setChecked(if_mode)
     self.write_if.clicked.connect(self.new_write_if)
     panel.layout().addRow(self.tr('Write to image'), self.write_if)
     # add panel to scroll area after its size is known
     scroll_area.setWidget(panel)
コード例 #59
0
ファイル: core.py プロジェクト: vilhelmp/astroquery
    def _login(self,
               username=None,
               store_password=False,
               reenter_password=False):
        """
        Login to the ESO User Portal.

        Parameters
        ----------
        username : str, optional
            Username to the ESO Public Portal. If not given, it should be
            specified in the config file.
        store_password : bool, optional
            Stores the password securely in your keyring. Default is False.
        reenter_password : bool, optional
            Asks for the password even if it is already stored in the
            keyring. This is the way to overwrite an already stored passwork
            on the keyring. Default is False.
        """
        if username is None:
            if self.USERNAME == "":
                raise LoginError("If you do not pass a username to login(), "
                                 "you should configure a default one!")
            else:
                username = self.USERNAME

        # Get password from keyring or prompt
        if reenter_password is False:
            password_from_keyring = keyring.get_password(
                "astroquery:www.eso.org", username)
        else:
            password_from_keyring = None

        if password_from_keyring is None:
            if system_tools.in_ipynb():
                log.warning("You may be using an ipython notebook:"
                            " the password form will appear in your terminal.")
            password = getpass.getpass(
                "{0}, enter your ESO password:\n".format(username))
        else:
            password = password_from_keyring
        # Authenticate
        log.info("Authenticating {0} on www.eso.org...".format(username))

        # Do not cache pieces of the login process
        login_response = self._request("GET",
                                       "https://www.eso.org/sso/login",
                                       cache=False)
        root = BeautifulSoup(login_response.content, 'html5lib')
        login_input = root.find(name='input', attrs={'name': 'execution'})
        if login_input is None:
            raise ValueError(
                "ESO login page did not have the correct attributes.")
        execution = login_input.get('value')

        login_result_response = self._request("POST",
                                              "https://www.eso.org/sso/login",
                                              data={
                                                  'username': username,
                                                  'password': password,
                                                  'execution': execution,
                                                  '_eventId': 'submit',
                                                  'geolocation': '',
                                              })
        login_result_response.raise_for_status()
        root = BeautifulSoup(login_result_response.content, 'html5lib')
        authenticated = root.find('h4').text == 'Login successful'

        if authenticated:
            log.info("Authentication successful!")
        else:
            log.exception("Authentication failed!")

        # When authenticated, save password in keyring if needed
        if authenticated and password_from_keyring is None and store_password:
            keyring.set_password("astroquery:www.eso.org", username, password)
        return authenticated
コード例 #60
0
    def _from_keyring():
        import keyring

        return keyring.get_password('https://api.wolframalpha.com/',
                                    getpass.getuser())