summaryrefslogtreecommitdiffstats
path: root/src/test/rgw/rgw_multi/conn.py
blob: 3edb75111258f0d8b76930be9110f08e67ae81e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import boto
import boto.s3.connection
import boto.iam.connection
import boto3

def get_gateway_connection(gateway, credentials):
    """ connect to the given gateway """
    if gateway.connection is None:
        gateway.connection = boto.connect_s3(
                aws_access_key_id = credentials.access_key,
                aws_secret_access_key = credentials.secret,
                host = gateway.host,
                port = gateway.port,
                is_secure = False,
                calling_format = boto.s3.connection.OrdinaryCallingFormat())
    return gateway.connection

def get_gateway_secure_connection(gateway, credentials):
    """ secure connect to the given gateway """
    if gateway.ssl_port == 0:
        return None
    if gateway.secure_connection is None:
        gateway.secure_connection = boto.connect_s3(
            aws_access_key_id = credentials.access_key,
            aws_secret_access_key = credentials.secret,
            host = gateway.host,
            port = gateway.ssl_port,
            is_secure = True,
            validate_certs=False,
            calling_format = boto.s3.connection.OrdinaryCallingFormat())
    return gateway.secure_connection

def get_gateway_iam_connection(gateway, credentials, region):
    """ connect to iam api of the given gateway """
    if gateway.iam_connection is None:
        endpoint = f'http://{gateway.host}:{gateway.port}'
        print(endpoint)
        gateway.iam_connection = boto3.client(
                service_name = 'iam',
                aws_access_key_id = credentials.access_key,
                aws_secret_access_key = credentials.secret,
                endpoint_url = endpoint,
                region_name=region,
                use_ssl = False)
    return gateway.iam_connection


def get_gateway_s3_client(gateway, credentials, region):
  """ connect to boto3 s3 client api of the given gateway """
  if gateway.s3_client is None:
      gateway.s3_client = boto3.client('s3',
                                        endpoint_url='http://' + gateway.host + ':' + str(gateway.port),
                                        aws_access_key_id=credentials.access_key,
                                        aws_secret_access_key=credentials.secret,
                                        region_name=region)
  return gateway.s3_client


def get_gateway_sns_client(gateway, credentials, region):
  """ connect to boto3 s3 client api of the given gateway """
  if gateway.sns_client is None:
      gateway.sns_client = boto3.client('sns',
                                        endpoint_url='http://' + gateway.host + ':' + str(gateway.port),
                                        aws_access_key_id=credentials.access_key,
                                        aws_secret_access_key=credentials.secret,
                                        region_name=region)
  return gateway.sns_client