Compare commits

...

1 commit

Author SHA1 Message Date
Ali Maredia
d227b13dde boto3: add https as a protocol for clients to connect to
Signed-off-by: Ali Maredia <amaredia@redhat.com>
2019-02-27 12:15:48 -05:00

View file

@ -156,6 +156,10 @@ def setup():
config.default_host = defaults.get("host") config.default_host = defaults.get("host")
config.default_port = int(defaults.get("port")) config.default_port = int(defaults.get("port"))
config.default_is_secure = defaults.get("is_secure") config.default_is_secure = defaults.get("is_secure")
if(config.default_is_secure == True):
config.proto = "https"
else:
config.proto = "http"
# vars from the main section # vars from the main section
config.main_access_key = cfg.get('s3 main',"access_key") config.main_access_key = cfg.get('s3 main',"access_key")
@ -211,7 +215,7 @@ def get_client(client_config=None):
if client_config == None: if client_config == None:
client_config = Config(signature_version='s3v4') client_config = Config(signature_version='s3v4')
endpoint_url = "http://%s:%d" % (config.default_host, config.default_port) endpoint_url = "%s://%s:%d" % (config.proto, config.default_host, config.default_port)
client = boto3.client(service_name='s3', client = boto3.client(service_name='s3',
aws_access_key_id=config.main_access_key, aws_access_key_id=config.main_access_key,
@ -224,7 +228,7 @@ def get_client(client_config=None):
def get_v2_client(): def get_v2_client():
endpoint_url = "http://%s:%d" % (config.default_host, config.default_port) endpoint_url = "%s://%s:%d" % (config.proto, config.default_host, config.default_port)
client = boto3.client(service_name='s3', client = boto3.client(service_name='s3',
aws_access_key_id=config.main_access_key, aws_access_key_id=config.main_access_key,
@ -239,7 +243,7 @@ def get_alt_client(client_config=None):
if client_config == None: if client_config == None:
client_config = Config(signature_version='s3v4') client_config = Config(signature_version='s3v4')
endpoint_url = "http://%s:%d" % (config.default_host, config.default_port) endpoint_url = "%s://%s:%d" % (config.proto, config.default_host, config.default_port)
client = boto3.client(service_name='s3', client = boto3.client(service_name='s3',
aws_access_key_id=config.alt_access_key, aws_access_key_id=config.alt_access_key,
@ -254,7 +258,7 @@ def get_tenant_client(client_config=None):
if client_config == None: if client_config == None:
client_config = Config(signature_version='s3v4') client_config = Config(signature_version='s3v4')
endpoint_url = "http://%s:%d" % (config.default_host, config.default_port) endpoint_url = "%s://%s:%d" % (config.proto, config.default_host, config.default_port)
client = boto3.client(service_name='s3', client = boto3.client(service_name='s3',
aws_access_key_id=config.tenant_access_key, aws_access_key_id=config.tenant_access_key,
@ -267,7 +271,7 @@ def get_tenant_client(client_config=None):
def get_unauthenticated_client(): def get_unauthenticated_client():
endpoint_url = "http://%s:%d" % (config.default_host, config.default_port) endpoint_url = "%s://%s:%d" % (config.proto, config.default_host, config.default_port)
client = boto3.client(service_name='s3', client = boto3.client(service_name='s3',
aws_access_key_id='', aws_access_key_id='',
@ -280,7 +284,7 @@ def get_unauthenticated_client():
def get_bad_auth_client(aws_access_key_id='badauth'): def get_bad_auth_client(aws_access_key_id='badauth'):
endpoint_url = "http://%s:%d" % (config.default_host, config.default_port) endpoint_url = "%s://%s:%d" % (config.proto, config.default_host, config.default_port)
client = boto3.client(service_name='s3', client = boto3.client(service_name='s3',
aws_access_key_id=aws_access_key_id, aws_access_key_id=aws_access_key_id,
@ -314,7 +318,7 @@ def get_new_bucket_resource(name=None):
Always recreates a bucket from scratch. This is useful to also Always recreates a bucket from scratch. This is useful to also
reset ACLs and such. reset ACLs and such.
""" """
endpoint_url = "http://%s:%d" % (config.default_host, config.default_port) endpoint_url = "%s://%s:%d" % (config.proto, config.default_host, config.default_port)
s3 = boto3.resource('s3', s3 = boto3.resource('s3',
use_ssl=False, use_ssl=False,
@ -347,6 +351,9 @@ def get_new_bucket(client=None, name=None):
def get_config_is_secure(): def get_config_is_secure():
return config.default_is_secure return config.default_is_secure
def get_config_proto():
return config.proto
def get_config_host(): def get_config_host():
return config.default_host return config.default_host