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

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

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

与 API 交互#

Anaconda 维护了一个 Jupyter 笔记本,其中包含用于与 API 交互的 Python 函数,以及一些关于使用笔记本本身的说明: jupyter-notebook-badge

向 API 验证身份#

Anaconda Cloud API 使用 OAuth2 标准身份验证(使用组织管理员的 anaconda.cloud 用户名和密码)来生成 User_TokenUser_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 列表中。

将用户添加到您的组织#

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

如果您在进行此调用时未提供电子邮件地址,系统将创建一个组织管理的用户。组织管理的用户未链接到个人帐户,旨在用于编程,允许专门为自动化流程或集成生成令牌。

您可以根据需要创建任意数量的托管用户。但是,Anaconda 建议将托管用户的数量限制为仅必要的数量。限制其使用可以增强您组织的安全态势。

提示

在发出创建组织管理用户的请求时,请使用 <FIRST_NAME><LAST_NAME> 字段为令牌的预期用途提供描述性名称。例如,如果您要向 Jupyter Notebooks 服务器提供令牌,则可以输入“Jupyter”和“Server-1”作为组织管理用户的名字和姓氏。

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>