def _unify_auth(self, auth):
     '''Add id and secret.'''
     id_key = get_id_key(auth)
     secret_key = get_secret_key(auth)
     if id_key and secret_key:
         auth['id'] = auth[id_key]
         auth['secret'] = auth[secret_key] 
Exemple #2
0
 def _unify_auth(self, auth):
     '''Add id and secret.'''
     id_key = get_id_key(auth)
     secret_key = get_secret_key(auth)
     if id_key and secret_key:
         auth['id'] = auth[id_key]
         auth['secret'] = auth[secret_key]
    def __init__(self, config):
        '''*config* is a dictionary with the keys id (access_key_id), secret (secret_access_key), and bucket_name. For instance::

                config['id'] = 'FDS54548SDF8D2S311DF' 
                config['secret'] = 'D370JKD=564++873ZHFD9FDKDD'
                config['bucket_name'] = 'cloudfusion'
                
            The bucket will be created if it does not exist. A bucket is similar to a subfolder,
            to which access with CloudFusion is restricted.         
            Id and secret can be obtained from the console.aws.amazon.com/s3/home
            
            * Click on your name on the top left and select Security Credentials form the drop down menu.
            * Go to Access Keys and Generate New Access Keys to generate the new key pair.
            
        :param config: dictionary with key value pairs'''
        super(AmazonStore, self).__init__()
        self.name = 'amazon'
        self._logging_handler = self.name
        self.logger = logging.getLogger(self._logging_handler)
        self.logger = db_logging_thread.make_logger_multiprocessingsave(self.logger)
        self.logger.info("creating %s store", self.name)
        self.bucket_name = config['bucket_name']
        id_key = get_id_key(config)
        secret_key = get_secret_key(config)
        self.access_key_id = config[id_key]
        self.secret_access_key = config[secret_key]
        try:
            boto.config.add_section('Boto')
        except DuplicateSectionError, e:
            pass
Exemple #4
0
    def __init__(self, config):
        '''*config* is a dictionary with the keys id (access_key_id), secret (secret_access_key), and bucket_name. For instance::

                config['id'] = 'FDS54548SDF8D2S311DF' 
                config['secret'] = 'D370JKD=564++873ZHFD9FDKDD'
                config['bucket_name'] = 'cloudfusion'
                
            The bucket will be created if it does not exist. A bucket is similar to a subfolder,
            to which access with CloudFusion is restricted.         
            Id and secret can be obtained from the console.aws.amazon.com/s3/home
            
            * Click on your name on the top left and select Security Credentials form the drop down menu.
            * Go to Access Keys and Generate New Access Keys to generate the new key pair.
            
        :param config: dictionary with key value pairs'''
        super(AmazonStore, self).__init__()
        self.name = 'amazon'
        self._logging_handler = self.name
        self.logger = logging.getLogger(self._logging_handler)
        self.logger = db_logging_thread.make_logger_multiprocessingsave(
            self.logger)
        self.logger.info("creating %s store", self.name)
        self.bucket_name = config['bucket_name']
        id_key = get_id_key(config)
        secret_key = get_secret_key(config)
        self.access_key_id = config[id_key]
        self.secret_access_key = config[secret_key]
        try:
            boto.config.add_section('Boto')
        except DuplicateSectionError, e:
            pass
 def __init__(self, config):
     '''*config* can be obtained from the function :func:`cloudfusion.store.gdrive.google_drive.GoogleDrive.get_config`,
     but you need to add the id and secret, which can be obtained by creating an id and secret for an "Installed Application" in the developer console: 
     https://console.developers.google.com/project, as described in https://developers.google.com/drive/web/quickstart/quickstart-python::
     
         config = GoogleDrive.get_config()
         config['id'] = '4523154788555-kjsdfj87sdfjh44dfsdfj45kjj.apps.googleusercontent.com' #your id            
         config['secret'] = 'sdfjk3h5j444jnjfo0' #your secret
     
     You may add a cache id, so that you can continue previous sessions. If you use the same cache id in a later session, 
     the store will remember some metadata and won't need the id and secret for authentication (just use empty strings in this case)::
     
         config['cache_id'] = 'gdrive_db'
     
     Or you can use a configuration file that already has id and secret set by specifying a path::
     
         path_to_my_config_file = '/home/joe/gdrive.ini'       
         config = GoogleDrive.get_config(path_to_my_config_file)
     
     :param config: dictionary with key value pairs'''
     super(GoogleDrive, self).__init__()
     self.name = 'google_drive'
     self._logging_handler = self.name
     self.logger = logging.getLogger(self._logging_handler)
     self.logger = db_logging_thread.make_logger_multiprocessingsave(self.logger)
     self.logger.info("creating %s store", self.name)
     id_key = get_id_key(config)
     secret_key = get_secret_key(config)
     client_auth = self.CLIENT_AUTH_TEMPLATE.substitute(SECRET=config[secret_key], ID=config[id_key])
     # workaround for possible side effect in fuse when called without foreground option
     self._settings_yaml = self._get_cachedir_name(config)+'/settings.yaml'
     self._client_secrets = self._get_cachedir_name(config)+'/client_secrets.json'
     credentials = self._get_cachedir_name(config)+'/credentials.json'
     settings_yaml = self.SETTINGS_YAML_TEMPLATE.substitute(CLIENT_SECRETS=self._client_secrets, 
                                                            CREDENTIALS_DB=credentials)
     with open(self._settings_yaml, 'w') as fh:
         fh.write(settings_yaml)
     with open(self._client_secrets, 'w') as client_secrets:
         client_secrets.write(client_auth)
     self.gauth = GoogleAuth(settings_file=self._settings_yaml)
     try:
         self.gauth.Authorize()
     except AuthenticationError, e:
         self.logger.info("Authentication error: %s", e)
         # The call to LocalWebserverAuth raises RefreshError if credentials are out of date.
         # Thus, remove credentials and reinitialize gauth:
         if os.path.exists(credentials):
             os.remove(credentials)
         self.gauth = GoogleAuth(settings_file=self._settings_yaml)
         self.gauth.LocalWebserverAuth()
         self.gauth.Authorize()
Exemple #6
0
 def __init__(self, config):
     '''*config* is a dictionary with the keys id (access_key_id), secret (secret_access_key), and bucket_name. For instance::
     
             config['id'] = 'FDS54548SDF8D2S311DF' 
             config['secret'] = 'D370JKD=564++873ZHFD9FDKDD'
             config['bucket_name'] = 'cloudfusion'
             
         The bucket will be created if it does not exist. A bucket is similar to a subfolder,
         to which access with CloudFusion is restricted.         
         Id and secret can be obtained from the developer's console:
         
         * Go to console.developers.google.com/project
         * Create a new project
         * Select Project dashboard on the left, which opens a new tab
         * Go to the new tab
         * Select Billing on the left to set up billing
         * Select Google Cloud Storage on the left 
         * Click on the button labeled "Make this my default project for interoperable storage access"
         * Click on Interoperable Access on the left 
         * Click Generate new key, to generate the new key pair
         
     :param config: dictionary with key value pairs'''
     super(GoogleStore, self).__init__()
     self.name = 'google'
     self._logging_handler = self.name
     self.logger = logging.getLogger(self._logging_handler)
     self.logger = db_logging_thread.make_logger_multiprocessingsave(self.logger)
     self.logger.info("creating %s store", self.name)
     self.bucket_name = config['bucket_name']
     id_key = get_id_key(config)
     secret_key = get_secret_key(config)
     self.access_key_id = config[id_key]
     self.secret_access_key = config[secret_key]
     self.write_gsutil_config()
     try:
         boto.config.add_section('Boto')
     except DuplicateSectionError, e:
         pass
Exemple #7
0
            pass
        return cache_dir

    def create_session(self, config, cache_dir):
        key = hashlib.sha224(
            config['user'] +
            config['password']).hexdigest()  #key for token from last session
        try:
            credentials_db = shelve.open(
                cache_dir + '/credentials',
                protocol=-1)  # use protocol -1 since token defines slots
        except Exception, e:
            self.logger.debug("Credentials database could not be loaded.")
            credentials_db = {}
        id_key = get_id_key(config)
        secret_key = get_secret_key(config)
        self.sess = session.DropboxSession(
            base64.b64decode(config[id_key]),
            base64.b64decode(config[secret_key]), config['root'])
        if key in credentials_db:
            self.sess.token = credentials_db[key]
            return self.sess
        self.request_token = self.sess.obtain_request_token()
        url = self.sess.build_authorize_url(self.request_token)
        try:
            self._auto_connect(url, config['user'], config['password'])
        except Exception, e:
            self.logger.exception(
                "Automatic login failed, falling back to manual login")
        access_token = self.reconnect(1)
        if not access_token:
     cache_dir = cache_dir+"/cachingstore_" + cache_id
     try:
         os.makedirs(cache_dir)
     except OSError,e: # exists
         pass
     return cache_dir
     
 def create_session(self, config, cache_dir):
     key = hashlib.sha224(config['user']+config['password']).hexdigest() #key for token from last session
     try:
         credentials_db = shelve.open(cache_dir+'/credentials', protocol=-1) # use protocol -1 since token defines slots
     except Exception, e:
         self.logger.debug("Credentials database could not be loaded.")
         credentials_db = {}
     id_key = get_id_key(config)
     secret_key = get_secret_key(config)
     self.sess = session.DropboxSession(base64.b64decode(config[id_key]), base64.b64decode(config[secret_key]), config['root'])
     if key in credentials_db:
         self.sess.token = credentials_db[key]
         return self.sess
     self.request_token = self.sess.obtain_request_token()
     url = self.sess.build_authorize_url(self.request_token)
     try:
         self._auto_connect(url, config['user'], config['password'])
     except Exception, e:
         self.logger.exception("Automatic login failed, falling back to manual login")
     access_token = self.reconnect(1)
     if not access_token:
         # Make the user sign in and authorize this token
         print "url:", url
         print "Please visit this website and press the 'Allow' button in the next Minute."