示例#1
0
    def __init__(self, name, access_key=None, secret_key=None,
                 security_token=None, profile_name=None):
        self.host = None
        self.port = None
        self.host_header = None
        self.access_key = access_key
        self.secret_key = secret_key
        self.security_token = security_token
        self.profile_name = profile_name
        self.name = name
        self.acl_class = None # self.AclClassMap[self.name]
        self.canned_acls = None # self.CannedAclsMap[self.name]
        self._credential_expiry_time = None

        # Load shared credentials file if it exists
        shared_path = os.path.join(expanduser('~'), '.' + name, 'credentials')
        self.shared_credentials = Config(do_load=False)
        if os.path.isfile(shared_path):
            self.shared_credentials.load_from_path(shared_path)

        self.get_credentials(access_key, secret_key, security_token, profile_name)
        self.configure_headers()
        self.configure_errors()

        # Allow config file to override default host and port.
        host_opt_name = '%s_host' % self.HostKeyMap[self.name]
        if config.has_option('Credentials', host_opt_name):
            self.host = config.get('Credentials', host_opt_name)
        port_opt_name = '%s_port' % self.HostKeyMap[self.name]
        if config.has_option('Credentials', port_opt_name):
            self.port = config.getint('Credentials', port_opt_name)
        host_header_opt_name = '%s_host_header' % self.HostKeyMap[self.name]
        if config.has_option('Credentials', host_header_opt_name):
            self.host_header = config.get('Credentials', host_header_opt_name)
示例#2
0
 def __init__(self, path=None, fp=None, do_load=True):
     self._parser = ConfigParser({'working_dir': '/mnt/pyami',
                                  'debug': '0'})
     if do_load:
         if path:
             self.load_from_path(path)
         elif fp:
             self.readfp(fp)
         else:
             self.read(NiftycloudConfigLocations)
         if "AWS_CREDENTIAL_FILE" in os.environ:
             full_path = expanduser(os.environ['AWS_CREDENTIAL_FILE'])
             try:
                 self.load_credential_file(full_path)
             except IOError:
                 warnings.warn('Unable to load AWS_CREDENTIAL_FILE (%s)' % full_path)
示例#3
0
# IN THE SOFTWARE.
#
import os
import re
import warnings

import niftycloud

from niftycloud.compat import expanduser, ConfigParser, NoOptionError, NoSectionError, StringIO


# By default we use two locations for the niftycloud configurations,
# /etc/niftycloud.cfg and ~/.niftycloud (which works on Windows and Unix).
NiftycloudConfigPath = '/etc/niftycloud.cfg'
NiftycloudConfigLocations = [NiftycloudConfigPath]
UserConfigPath = os.path.join(expanduser('~'), '.niftycloud')
NiftycloudConfigLocations.append(UserConfigPath)

# If there's a BOTO_CONFIG variable set, we load ONLY
# that variable
if 'BOTO_CONFIG' in os.environ:
    NiftycloudConfigLocations = [expanduser(os.environ['BOTO_CONFIG'])]

# If there's a BOTO_PATH variable set, we use anything there
# as the current configuration locations, split with os.pathsep.
elif 'BOTO_PATH' in os.environ:
    NiftycloudConfigLocations = []
    for path in os.environ['BOTO_PATH'].split(os.pathsep):
        NiftycloudConfigLocations.append(expanduser(path))