示例#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 = self.AclClassMap[self.name]
        self.canned_acls = 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):
     # We don't use ``super`` here, because ``ConfigParser`` still uses
     # old-style classes.
     ConfigParser.__init__(self, {"working_dir": "/mnt/pyami", "debug": "0"})
     if do_load:
         if path:
             self.load_from_path(path)
         elif fp:
             self.readfp(fp)
         else:
             self.read(TxBotoConfigLocations)
         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
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.

import os
import re
import warnings

from txboto.compat import expanduser, ConfigParser, StringIO


# By default we use two locations for the txboto configurations,
# /etc/boto.cfg and ~/.boto (which works on Windows and Unix).
TxBotoConfigPath = "/etc/txboto.cfg"
TxBotoConfigLocations = [TxBotoConfigPath]
UserConfigPath = os.path.join(expanduser("~"), ".txboto")
TxBotoConfigLocations.append(UserConfigPath)

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

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