使用 Anaconda Cloud API 管理您的组织#

通过 Anaconda Cloud 图形用户界面 (GUI) 手动添加单个团队成员可能很耗时。对于大型团队,Anaconda 建议使用 API 调用来简化流程。

Anaconda Cloud API 提供各种调用,使您能够将用户添加到 Anaconda Cloud 组织并更改其席位和令牌权限。**您必须是具有活动付费订阅的 Anaconda Cloud 组织的管理员才能使用这些 API 调用。**

您可以使用 API 接口(例如 Postman)来处理这些 API 调用,或者创建一个脚本来运行需要添加到组织中的用户列表。

注意

导入提供的 Postman 集合环境 模板 以快速入门此过程。

本文档概述了您在此过程中可能需要的每个 API 调用的端点以及请求和响应变量。

对 API 进行身份验证#

Anaconda Cloud API 使用 OAuth2 标准身份验证(使用组织管理员的 anaconda.cloud 用户名和密码)来生成 User_Token。需要 User_Token 来创建服务帐户。

创建服务帐户后,使用其凭据(返回的 client_idclient_secret)进行身份验证,以生成 ServiceAccount_Token,通过下面描述的其他 API 调用来管理用户。

创建服务帐户#

创建服务帐户允许管理员用户为特定机器或机器(如构建服务器或其他用于管道自动化的机器)指定凭据,并以类似于用户的方式管理这些机器。然后,服务帐户可以允许对组织进行其他 API 调用,该机器用户是其中的一部分。

您可以在每个组织中创建任意数量的服务帐户。但是,Anaconda 建议将服务帐户的数量限制在绝对必要的数量。限制服务帐户的数量可以增强组织的安全态势。

注意

服务帐户名称必须使用小写字母、数字、连字符或下划线创建,并且不能包含空格或特殊字符。

API 调用#

# Replace <ORG_ID> with your organization ID, found in your Anaconda Cloud organization's URL: anaconda.cloud/organizations/<ORG_ID>/
POST /organizations/<ORG_ID>/service-accounts
{
   "name":"<SERVICE_ACCOUNT_NAME>"
}
{
   "name":"anaconda_cloud_org"
}
{
   "name": "<SERVICE_ACCOUNT_NAME>",
   "client_id": "<GUID>",
   "org_id": "<GUID>",
   "client_secret": "<SECRET_ID>"
}
{
   "name": "anaconda_cloud_org",
   "client_id": "1234abcd-1a2b-3c4d-5e6f-123456abcdef",
   "org_id": "abcd1234-1234-abcd-1a2b-3c4d5e6f7g8h",
   "client_secret": "1234567890abcdefghij_abcdefghij1234567_1a2b"
}

获取服务帐户 ID#

此调用返回先前创建的服务帐户的 ID,但不会泄露其密钥。

API 调用#

# Replace <ORG_ID> with your organization ID, found in your Anaconda Cloud organization's URL: anaconda.cloud/organizations/<ORG_ID>/
GET organizations/<ORG_ID>/service-accounts
{
   "name": "<SERVICE_ACCOUNT_NAME>",
   "client_id": "<GUID>",
   "org_id": "<GUID>",
}
{
   "name": "anaconda_cloud_org",
   "client_id": "1234abcd-1a2b-3c4d-5e6f-123456abcdef",
   "org_id": "abcd1234-1234-abcd-1a2b-3c4d5e6f7g8h",
}

删除服务帐户#

此调用删除与提供的 client_id 关联的服务帐户。

API 调用#

# Replace <ORG_ID> with your organization ID, found in your Anaconda Cloud organization's URL: anaconda.cloud/organizations/<ORG_ID>/
# Replace <CLIENT_ID> with your client_id value
DELETE organizations/<ORG_ID>/service-accounts/<CLIENT_ID>

此调用没有请求或响应信息。如果请求成功,您将收到 204 状态代码。

新用户的自动入职#

如果您要将尚未拥有 anaconda.cloud 帐户的用户添加到您的组织,您可以使用此调用来启动自动入职流程,该流程将他们添加到您的组织,将其分配为成员席位,并向他们发放令牌以访问存储库。

管理员将收到一封电子邮件,通知用户已添加到组织中。用户将收到两封电子邮件,一封欢迎他们加入组织,另一封包含他们的私有访问令牌,该令牌允许他们使用来自 anaconda.cloud 的包。

{
   "user_emails":"[<[email protected]>, <[email protected]>]"
}
{
   "user_emails":"[[email protected], [email protected]]"
}
{
   "users_in_onboarding_process": [
      "[email protected]" "[email protected]"
   ],
   "users_unavailable_for_onboarding": [],
   "total_organization_seats": "<TOTAL_SEATS>",
   "available_organization_seats": "<REMAINING_SEATS>"
}
{
   "users_in_onboarding_process": [
      "[email protected]" "[email protected]"
   ],
   "users_unavailable_for_onboarding": [],
   "total_organization_seats": "1000",
   "available_organization_seats": "921"
}

警告

  • 如果用户具有与其电子邮件地址关联的 anaconda.cloud 帐户,则自动入职将失败。

  • 如果在 users_in_onboarding_process 中列出的用户已开始入职流程,则入职过程中发生的任何问题都不会反映在这里。如果用户未被添加到您的组织,您就会知道存在问题。

  • 如果可用席位数量少于您尝试添加到组织的成员数量,则用户将被添加到没有可用席位为止,剩余的用户将显示在 users_unavailable_for_onboarding 列表中。

将用户添加到您的组织#

此调用将用户添加到组织中。

API 调用#

# Replace <ORG_ID> with your organization ID, found in your Anaconda Cloud organization's URL: anaconda.cloud/organizations/<ORG_ID>/
POST /organizations/<ORG_ID>/users
{
   "email":"<EMAIL_ADDRESS>"
   "first_name": "<FIRST_NAME>",
   "last_name": "<LAST_NAME>"
}
{
   "email":"[email protected]"
   "first_name": "Annie",
   "last_name": "Conda"
}
{
   "first_name": "<FIRST_NAME>",
   "last_name": "<LAST_NAME>",
   "email": "<EMAIL_ADDRESS>",
   "id": "<GUID>"
}
{
   "first_name": "Annie",
   "last_name": "Conda",
   "email": "[email protected]",
   "id": "1a2b3c4d-1a2b-3c4d-5e6f-1a2b3c4d5f"
}

注意

如果您没有为用户提供姓氏和名字,API 调用将返回 null。用户可以在需要时从其个人资料中编辑此信息。

将座位分配给用户#

此调用将座位分配给用户所属组织的特定用户。

API 调用#

# Replace <ORG_ID> with your organization ID, found in your Anaconda Cloud organization's URL: anaconda.cloud/organizations/<ORG_ID>/
# Replace <USER_ID> with the ID of the user you want to assign a seat
POST  /organizations/<ORG_ID>/users/<USER_ID>/seats

此调用没有请求或响应信息。如果请求成功,您将收到 201 状态代码。

将令牌分配给用户#

此调用将令牌分配给特定用户。令牌是唯一的安全密钥,允许用户访问已分配给他们的订阅座位。

API 调用#

# Replace <ORG_ID> with your organization ID, found in your Anaconda Cloud organization's URL: anaconda.cloud/organizations/<ORG_ID>/
# Replace <USER_ID> with the ID of the user you want to assign a token
POST /organizations/<ORG_ID>/users/<USER_ID>/token
{
   "expires_at": "<DATETIME>"
}
{
   "expires_at": "2022-07-29T00:00:00+00:00"
}
{
   "token": "<TOKEN>",
   "expires_at": null
}
{
   "token": "1a2b34567c8d9101112e13f14g151617h18i19202122i23j",
   "expires_at": null
}

同步用户令牌#

续订订阅不会延长令牌的有效期。如果您续订了订阅并希望保留当前令牌,请运行此调用以同步您的令牌并将其有效期延长至组织的新订阅到期日期。

# Replace <ORG_ID> with your organization ID, found in your Anaconda Cloud organization's URL: anaconda.cloud/organizations/<ORG_ID>/
# Replace <USER_ID> with the ID of the user whose token needs to be synchronized
PATCH /organizations/<ORG_ID>/users/<USER_ID>/token

撤销用户的令牌#

此调用会从给定用户 ID 中撤销令牌。当用户不再需要访问其软件订阅时,应使用此调用,并且可以用作用户删除过程的第一部分。

API 调用#

# Replace <ORG_ID> with your organization ID, found in your Anaconda Cloud organization's URL: anaconda.cloud/organizations/<ORG_ID>/
# Replace <USER_ID> with the ID of the user whose token you want to delete
DELETE /organizations/<ORG_ID>/users/<USER_ID>/token

从用户处移除座位#

此调用会从给定用户处移除订阅座位,并且可以用作用户删除过程的第二部分。

API 调用#

# Replace <ORG_ID> with your organization ID, found in your Anaconda Cloud organization's URL: anaconda.cloud/organizations/<ORG_ID>/
# Replace <USER_ID> with the ID of the user whose token you want to delete
DELETE /organizations/<ORG_ID>/users/<USER_ID>/seats

从组织中移除用户#

此调用会从给定组织中移除给定用户,并且可以用作用户删除过程的最后部分。

API 调用#

# Replace <ORG_ID> with your organization ID, found in your Anaconda Cloud organization's URL: anaconda.cloud/organizations/<ORG_ID>/
# Replace <USER_ID> with the ID of the user whose token you want to delete
DELETE /organizations/<ORG_ID>/users/<USER_ID>