diff --git a/config/config_template.yaml b/config/config_template.yaml index 770cba06d..33bc462a9 100644 --- a/config/config_template.yaml +++ b/config/config_template.yaml @@ -141,6 +141,7 @@ #ibm_cos: #storage_bucket: #region: + #service_instance_id: #endpoint: #private_endpoint: #api_key: diff --git a/docs/source/storage_config/ibm_cos.md b/docs/source/storage_config/ibm_cos.md index d6e6dc3fa..08a130767 100644 --- a/docs/source/storage_config/ibm_cos.md +++ b/docs/source/storage_config/ibm_cos.md @@ -127,12 +127,13 @@ Alternative to using region, you can configure the public and private endpoints ### IBM Cloud Object Storage: -|Group|Key|Default|Mandatory|Additional info| -|---|---|---|---|---| -|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| -|ibm_cos | api_key | |yes | API Key to your COS account. Not needed if using IAM API Key| -|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 | -|ibm_cos | access_key_id | |no | HMAC Credentials. **Mandatory** if no api_key. Not needed if using IAM API Key| -|ibm_cos | secret_access_key | |no | HMAC Credentials. **Mandatory** if no api_key. Not needed if using IAM API Key| -|ibm_cos | endpoint | |no | Endpoint to your COS account. **Mandatory** if no region. Make sure to use the full path with 'https://' as prefix | -|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 | +| Group | Key |Default|Mandatory| Additional info | +|---------|---------------------|---|---|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| 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 | +| ibm_cos | api_key | |yes | API Key to your COS account. Not needed if using IAM API Key | +| 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 | +| ibm_cos | service_instance_id | |no | The service instance (CRN format) of your COS instance. **Mandatory** if no HMAC Credentials provided. | | | | | +| ibm_cos | access_key_id | |no | HMAC Credentials. **Mandatory** if no api_key. Not needed if using IAM API Key | +| ibm_cos | secret_access_key | |no | HMAC Credentials. **Mandatory** if no api_key. Not needed if using IAM API Key | +| ibm_cos | endpoint | |no | Endpoint to your COS account. **Mandatory** if no region. Make sure to use the full path with 'https://' as prefix | +| 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 | diff --git a/lithops/storage/backends/ibm_cos/config.py b/lithops/storage/backends/ibm_cos/config.py index c629d2fc2..2a03f0940 100644 --- a/lithops/storage/backends/ibm_cos/config.py +++ b/lithops/storage/backends/ibm_cos/config.py @@ -65,7 +65,8 @@ def load_config(config_data): if 'private_endpoint' not in config_data['ibm_cos']: raise Exception('You must provide the private_endpoint to access to IBM COS') elif 'direct' not in config_data['ibm_cos']['private_endpoint']: - raise Exception('The private_endpoint you provided to access to IBM COS is not valid. You must use the "direct" endpoint') + raise Exception('The private_endpoint you provided to access to IBM COS is not valid. You must use the ' + '"direct" endpoint') if not config_data['ibm_cos']['private_endpoint'].startswith('http'): raise Exception('IBM COS Private Endpoint must start with http:// or https://') @@ -78,3 +79,8 @@ def load_config(config_data): if 'region' not in config_data['ibm_cos']: endpoint = config_data['ibm_cos']['endpoint'] config_data['ibm_cos']['region'] = endpoint.split('//')[1].split('.')[1] + + if ('service_instance_id' not in config_data['ibm_cos'] + and {'access_key_id', 'secret_access_key'}.isdisjoint(config_data['ibm_cos'])): + raise Exception('You must provide the service_instance_id or the (access_key_id,secret_access_key) to ' + 'access to IBM COS') diff --git a/lithops/storage/backends/ibm_cos/ibm_cos.py b/lithops/storage/backends/ibm_cos/ibm_cos.py index e62f25c89..9a41a0b0f 100644 --- a/lithops/storage/backends/ibm_cos/ibm_cos.py +++ b/lithops/storage/backends/ibm_cos/ibm_cos.py @@ -103,7 +103,8 @@ def __init__(self, ibm_cos_config): aws_secret_access_key="", aws_session_token=token, config=client_config, - endpoint_url=service_endpoint + endpoint_url=service_endpoint, + ibm_service_instance_id=self.config.get('service_instance_id') ) msg = STORAGE_CLI_MSG.format('IBM COS')