forked from ibm-functions/runtime-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestCOSService.py
More file actions
39 lines (30 loc) · 1.34 KB
/
Copy pathtestCOSService.py
File metadata and controls
39 lines (30 loc) · 1.34 KB
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
"""Python test fixture to check that cos sdk loads and connect to COS Service"""
import ibm_boto3
from ibm_botocore.client import Config
def main(args):
auth_endpoint = 'https://iam.bluemix.net/oidc/token'
service_endpoint = 'https://s3-api.us-geo.objectstorage.softlayer.net'
api_key = args["__bx_creds"]["cloud-object-storage"]["apikey"]
service_instance_id = args["__bx_creds"]["cloud-object-storage"]["resource_instance_id"]
cos = ibm_boto3.client('s3',
ibm_api_key_id=api_key,
ibm_service_instance_id=service_instance_id,
ibm_auth_endpoint=auth_endpoint,
config=Config(signature_version='oauth'),
endpoint_url=service_endpoint)
bucket = "ibm-functions-devops-testing"
key = "testdata.txt"
response = cos.get_object(Bucket=bucket, Key=key, ResponseContentType="application/text")
text = response["Body"].read().decode("utf-8")
return {"data": text}
if __name__ == "__main__":
# execute only if run as a script
input = {
"__bx_creds": {
"cloud-object-storage": {
"apikey": "<apikey from credentials>",
"resource_instance_id": "<resource_instance_id from credentials>"
}
}
}
print(main(input))