存储配置

更新
Cover image for: 存储配置

存储配置资源描述了API可以存储属于民意调查结果的数据的位置。存储配置中指定的所有位置必须是Google云端存储Amazon S3(AWS)中的 云存储 分区

属性

名称类型描述
id storage config ID Resource identifier.
resource string, always storage_config Resource type specifier.
organisation organisation ID The organisation the resource belongs to.
type string One of: gs, s3. This is a read-only attribute generated from the url.
url string A URL representing the target to which results will be published.
credentials dictionary A dictionary containing the credential information used by the API to authenticate against the storage service.
signed_urls_enabled optional bool, default false Whether signed URLs should be generated for results published using the storage config.
signed_urls_expiry optional timedelta If signed URLs are enabled, the time, in seconds, they will remain valid.
state string One of: 'new', 'valid', 'invalid', 'deactivated'.
date_created datetime When the resource was created.

类型

gs
Google云端存储存储配置类型。需要服务帐户凭据。
s3
Amazon S3(AWS)存储配置类型。需要AWS用户凭据。

网址

url属性遵循以下格式:

<type>://<bucket name>/<path within bucket>

例如,假设Google云端存储中有一个名为“my-bucket”的存储桶,我们希望API发布到此存储桶中名为“results”的文件夹中,该url将如下所示:

gs://my-bucket/results

证书

Google云端存储凭据

API期望credentials属性是具有以下格式的字典:

{
    "type": "service_account",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "client_id": "<Google Cloud Platform client ID>",
    "token_uri": "https://oauth2.googleapis.com/token",
    "project_id": "<Google Cloud Platform project ID>",
    "private_key": "<Service Account private key>",
    "client_email": "<Service Account ID>.iam.gserviceaccount.com",
    "private_key_id": "<Service Account private key ID>",
    "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/<Service Account ID>.iam.gserviceaccount.com",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs"
}

这通过Google Cloud Platform控制台创建服务帐户密钥时,与输出JSON文件完全匹配。

为了使用导出的JSON文件凭证简化设置存储配置, ricloud-py包含一个简单的cli命令:

ricloud storage-config create --url "gs://<bucket name>" --credentials <path to JSON file>

Amazon S3凭据

API期望credentials属性是具有以下格式的字典:

{
    "user_name": "<aws user name>",
    "access_key_id": "<aws user access key ID>",
    "secret_access_key": "<aws user secret access key>",
}

在上面的凭证有效负载中, user_name参数对应于访问密钥所属的AWS IAM用户的用户名。这对于包括管理和审核目的会有所帮助。

这可以通过AWS控制台中显示的详细信息手动构建,也可以通过ricloud-py的cli命令从可导出的CSV文件构建

ricloud storage-config create --url "s3://<bucket name>" --credentials <path to CSV file>

签名网址

签名的URL是限时的,预授权的链接,用于访问云存储桶中的项目。它们使实现能够安全地访问客户端否则将没有凭据或根本没有凭据的特定项目。

在存储配置上启用签名URL时,使用该配置发布的所有结果都将填充signed_url属性。有关更多详细信息,请参见结果属性

Google Cloud Storage( 链接到GCS签名URL docs )和AWS S3( 链接到S3 docs )都支持签名URL。

对签名URL的另一项要求是,与存储配置凭据关联的用户必须对存储桶中的对象具有读取权限。在GCS中,这是“存储对象查看器”角色。在S3中是“ s3:GetObject”策略动作。

状态

new
刚刚创建或最近更新但尚未测试。
valid
已通过验证并准备好使用。组织必须至少具有一个处于此状态的存储配置才能使用。
invalid
验证测试未通过。必须更新或重新测试。
deactivated
被拥有的组织关闭了。

变更日志

2020-02-27

  • 添加对签名URL的支持。这会在存储配置对象上添加signed_urls_enabledsigned_urls_expiry ,以切换生成签名URL的结果,以及激活签名URL的时间。

创建POST /configs/storage

创建新的存储配置时,API将尝试通过创建storage_config.test任务来测试它。此任务将使用配置发布一个小测试有效负载,之后可以安全地删除。如果操作成功,则配置的状态设置为valid并且可用于轮询。如果失败,配置的状态将被设置为invalid ,但可以使用测试操作轻松地重新测试。

组织中的第一个有效存储配置将自动设置为组织的默认配置。

请注意,存储配置的创建会在url属性上进行重复数据删除。因此,无法使用相同的url创建两个存储配置但credentials不同。

参数

name type description
url required The storage configuration URL for your bucket.
credentials required The storage configuration credentials for your bucket.

使用cURL

此处,凭据字典的内容来自复制在Google Cloud Service帐户设置期间生成的JSON凭证文件的内容。

curl https://ricloud-api.reincubate.com/configs/storage \
  -X POST \
  -H 'Authorization: Token <your key_token>' \
  -H 'Content-Type: application/json' \
  -d '{
  "url": "gs://my-storage-bucket",
  "credentials": {
      "type": "service_account",
      "auth_uri": "https://accounts.google.com/o/oauth2/auth",
      "client_id": "<Google Cloud Platform client ID>",
      "token_uri": "https://oauth2.googleapis.com/token",
      "project_id": "<Google Cloud Platform project ID>",
      "private_key": "<Service Account private key>",
      "client_email": "<Service Account ID>.iam.gserviceaccount.com",
      "private_key_id": "<Service Account private key ID>",
      "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/<Service Account ID>.iam.gserviceaccount.com",
      "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs"
  }
}'

使用ricloud-py

import json
import ricloud

with open("<path to JSON file>", 'r') as credentials_file:
    credentials = json.load(credentials_file)

storage_config = ricloud.StorageConfig.create(
    url='gs://my-storage-bucket',
    credentials=credentials
)

检索GET /configs/storage/{storage_config ID}

使用cURL

curl https://ricloud-api.reincubate.com/configs/storage/<storage_config ID> \
  -H 'Authorization: Token <your key_token>'

使用ricloud-py

import ricloud

storage_config = ricloud.StorageConfig.retrieve(<storage_config ID>)

列出GET /configs/storage

处于deactivated状态的存储配置默认是隐藏的,只能通过显式过滤列出。

参数

名称类型描述
type string Filter by backing bucket's type.
state string Filter by the configuration's state.
date_created datetime filter Filter by resouce creation date.

使用cURL

curl https://ricloud-api.reincubate.com/configs/storage \
  -H 'Authorization: Token <your key_token>'

使用ricloud-py

import ricloud

storage_configs = ricloud.StorageConfig.list()

更新POST /configs/storage/{storage_config ID}

此操作将创建storage_config.test任务,以检查对配置所做的任何更改的有效性。

参数

名称类型描述
url string Update the URL to point to a different bucket or location within the bucket. Note that the type of a bucket cannot be changed through this operation.
credentials dictionary Update the credentials.
state string Only to new or deactivated.

使用cURL

curl https://ricloud-api.reincubate.com/configs/storage/<storage_config ID> \
  -X POST \
  -H 'Authorization: Token <your key_token>' \
  -H 'Content-Type: application/json' \
  -d '{
    "url": "gs://my-storage-bucket/subfolder"
}'

使用ricloud-py

import ricloud

storage_config = ricloud.StorageConfig.update_with_id(
  <storage_config ID>, url="gs://my-storage-bucket/subfolder"
)

# OR

storage_config = ricloud.StorageConfig.retrieve(<storage_config ID>)

storage_config.update(url='gs://my-storage-bucket/subfolder')

删除DELETE /configs/storage/{storage_config ID}

完全从API中删除存储配置。这将删除存储在API中的所有相关凭证信息。

使用cURL

curl https://ricloud-api.reincubate.com/configs/storage/<storage_config ID> \
  -X DELETE \
  -H 'Authorization: Token <your key_token>'

使用ricloud-py

自ricloud-py v3.0.0

import ricloud

ricloud.StorageConfig.delete_with_id(<storage_config ID>)

# OR

storage_config = ricloud.StorageConfig.retrieve(<storage_config ID>)

storage_config.delete()

测试POST /configs/storage/{storage_config ID}/test

此操作允许您重新测试存储配置的有效性。根据测试结果,配置状态将设置为validinvalid

请注意,此操作返回任务资源。

使用cURL

curl https://ricloud-api.reincubate.com/configs/storage/<storage_config ID>/test \
  -H 'Authorization: Token <your key_token>'

使用ricloud-py

import ricloud

test_task = ricloud.StorageConfig.test_with_id(<storage_config ID>)

# OR

storage_config = ricloud.StorageConfig.retrieve(<storage_config ID>)

test_task = storage_config.test()

我们能帮你什么吗?

我们的支持团队在这里提供帮助!

我们的办公时间是格林威治标准时间周一至周五上午9点至下午5点。 时间目前是 12:43 PM的 GMT。

我们力争在一个工作日内答复所有垂询。

我们的支持团队非常棒

我们可以改进这篇文章吗?

我们喜欢听取用户的意见:为什么不给我们发电子邮件,发表评论或发推文 @reincubate?

© 2008 - 2024 Reincubate Ltd. 保留所有权利。 在英格兰和威尔士注册 #5189175, VAT GB151788978. Reincubate®和Camo®是注册商标。 隐私政策 & 条款.