Skip to content

Commit 4679275

Browse files
🐛 Fix storage for IBM COS (api_key) non-read ops. (#1447)
Co-authored-by: German Telmo Eizaguirre Suarez <germantelmo.eizaguirre@urv.cat>
1 parent f94f4d6 commit 4679275

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

config/config_template.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
#ibm_cos:
142142
#storage_bucket: <BUCKET_NAME>
143143
#region: <REGION>
144+
#service_instance_id: <SERVICE_INSTANCE_ID>
144145
#endpoint: <REGION_ENDPOINT>
145146
#private_endpoint: <PRIVATE_REGION_ENDPOINT>
146147
#api_key: <API_KEY>

docs/source/storage_config/ibm_cos.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,13 @@ Alternative to using region, you can configure the public and private endpoints
127127

128128
### IBM Cloud Object Storage:
129129

130-
|Group|Key|Default|Mandatory|Additional info|
131-
|---|---|---|---|---|
132-
|ibm_cos | region | |yes | Region of your bucket. One of: `eu-gb`, `eu-de`, `us-south`, `us-east`, `br-sao`, `ca-tor`, `jp-tok`, `jp-osa`, `au-syd`. Lithops will use the region set under the `ibm` section if it is not set here|
133-
|ibm_cos | api_key | |yes | API Key to your COS account. Not needed if using IAM API Key|
134-
|ibm_cos | storage_bucket | | yes | The name of a bucket that exists in you account. This will be used by Lithops for intermediate data. You must provide HMAC Credentials if you want the bucket to be automatically created |
135-
|ibm_cos | access_key_id | |no | HMAC Credentials. **Mandatory** if no api_key. Not needed if using IAM API Key|
136-
|ibm_cos | secret_access_key | |no | HMAC Credentials. **Mandatory** if no api_key. Not needed if using IAM API Key|
137-
|ibm_cos | endpoint | |no | Endpoint to your COS account. **Mandatory** if no region. Make sure to use the full path with 'https://' as prefix |
138-
|ibm_cos | private_endpoint | |no | Private endpoint to your COS account. **Mandatory** if no region. Make sure to use the full path with 'https://' or http:// as prefix |
130+
| Group | Key |Default|Mandatory| Additional info |
131+
|---------|---------------------|---|---|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
132+
| ibm_cos | region | |yes | Region of your bucket. One of: `eu-gb`, `eu-de`, `us-south`, `us-east`, `br-sao`, `ca-tor`, `jp-tok`, `jp-osa`, `au-syd`. Lithops will use the region set under the `ibm` section if it is not set here |
133+
| ibm_cos | api_key | |yes | API Key to your COS account. Not needed if using IAM API Key |
134+
| ibm_cos | storage_bucket | | yes | The name of a bucket that exists in you account. This will be used by Lithops for intermediate data. You must provide HMAC Credentials if you want the bucket to be automatically created |
135+
| ibm_cos | service_instance_id | |no | The service instance (CRN format) of your COS instance. **Mandatory** if no HMAC Credentials provided. | | | | |
136+
| ibm_cos | access_key_id | |no | HMAC Credentials. **Mandatory** if no api_key. Not needed if using IAM API Key |
137+
| ibm_cos | secret_access_key | |no | HMAC Credentials. **Mandatory** if no api_key. Not needed if using IAM API Key |
138+
| ibm_cos | endpoint | |no | Endpoint to your COS account. **Mandatory** if no region. Make sure to use the full path with 'https://' as prefix |
139+
| ibm_cos | private_endpoint | |no | Private endpoint to your COS account. **Mandatory** if no region. Make sure to use the full path with 'https://' or http:// as prefix |

lithops/storage/backends/ibm_cos/config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def load_config(config_data):
6565
if 'private_endpoint' not in config_data['ibm_cos']:
6666
raise Exception('You must provide the private_endpoint to access to IBM COS')
6767
elif 'direct' not in config_data['ibm_cos']['private_endpoint']:
68-
raise Exception('The private_endpoint you provided to access to IBM COS is not valid. You must use the "direct" endpoint')
68+
raise Exception('The private_endpoint you provided to access to IBM COS is not valid. You must use the '
69+
'"direct" endpoint')
6970
if not config_data['ibm_cos']['private_endpoint'].startswith('http'):
7071
raise Exception('IBM COS Private Endpoint must start with http:// or https://')
7172

@@ -78,3 +79,8 @@ def load_config(config_data):
7879
if 'region' not in config_data['ibm_cos']:
7980
endpoint = config_data['ibm_cos']['endpoint']
8081
config_data['ibm_cos']['region'] = endpoint.split('//')[1].split('.')[1]
82+
83+
if ('service_instance_id' not in config_data['ibm_cos']
84+
and {'access_key_id', 'secret_access_key'}.isdisjoint(config_data['ibm_cos'])):
85+
raise Exception('You must provide the service_instance_id or the (access_key_id,secret_access_key) to '
86+
'access to IBM COS')

lithops/storage/backends/ibm_cos/ibm_cos.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ def __init__(self, ibm_cos_config):
103103
aws_secret_access_key="",
104104
aws_session_token=token,
105105
config=client_config,
106-
endpoint_url=service_endpoint
106+
endpoint_url=service_endpoint,
107+
ibm_service_instance_id=self.config.get('service_instance_id')
107108
)
108109

109110
msg = STORAGE_CLI_MSG.format('IBM COS')

0 commit comments

Comments
 (0)