我希望有人可以帮助我解决这个问题。我有一种感觉,这可能与我使用的凭据有关,但我不知道我做错了什么。
我对 Python 很陌生,虽然我从“创建存储桶”级别了解对象存储,但我很难掌握从编程接口进行的访问。
理想情况下,我希望为不同的任务使用不同的凭据,因此所有存储桶操作的“管理员”一直到特定用户的特定存储桶操作。
我已经测试了一些东西,例如 CLI 中的 CRN,我可以列出存储桶,但我使用我的 IBM 凭据登录,所以我怀疑这是在我运行时获取这些凭据:
Ibmcloud cos list-buckets
我尝试使用存储资源列表中的 API 密钥。
所以从文档中我正在尝试以下命令:
COS_ENDPOINT="https://s3.eu-gb.cloud-object-storage.appdomain.cloud"
COS_API_KEY_ID = "............................................"
COS_AUTH_ENDPOINT = "https://iam.eu-gb.bluemix.net/oidc/token"
COS_RESOURCE_CRN = "the last part from the CRN string"
# Create resource. In an ideal world, cos_m will be the big boss and I could use other
# users like cos_r or cos_a for specific bucket tasks
cos_m = ibm_boto3.resource("s3",
ibm_api_key_id=COS_API_KEY_ID,
ibm_service_instance_id=COS_RESOURCE_CRN,
ibm_auth_endpoint=COS_AUTH_ENDPOINT,
config=Config(signature_version="oauth"),
endpoint_url=COS_ENDPOINT)
def get_buckets():
print("Retrieving list of buckets")
try:
buckets = cos_r.buckets.all()
for bucket in buckets:
print("Bucket Name: {0}".format(bucket.name))
except ClientError as be:
print("CLIENT ERROR: {0}\n".format(be))
except Exception as e:
print("Unable to retrieve list buckets: {0}".format(e))
get_buckets()
Returns the error:
Retrieving list of buckets
Unable to retrieve list buckets: An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied
I have also tried a set of credentials that work on a specific bucket, but I don't think those credentials have the ability to do operations such as list-buckets.
I hope this makes sense and thanks for taking a look.