将条目添加到项目 IP 访问列表
为指定项目添加一个或多个访问列表条目。MongoDB Cloud 仅允许客户端从项目 IP 访问列表中的 IP 地址连接到集群。每个条目写入为一个 IP 地址或一个以 CIDR 表示的 IP 地址区块。要使用此资源,请求的服务账户或 API 密钥必须具有“项目所有者”或“项目图表管理员”角色。此资源将替换白名单资源。MongoDB Cloud 于 2021 年 7 月删除了白名单。更新您的应用程序以使用此新资源。/groups/{GROUP-ID}/accessList
端点管理数据库 IP 访问列表。此端点与管理 MongoDB Cloud 组织访问列表的 orgs/{ORG-ID}/apiKeys/{API-KEY-ID}/accesslist
端点不同。此端点不支持并发 POST
请求。您必须同步提交多个 POST
请求。
路径参数
-
用于标识项目的唯一 24-十六进制数字字符串。 使用 /groups 端点检索身份验证的用户有权访问权限的所有项目。
注意:群组和项目是同义词。您的群组 ID 与项目 ID 相同。对于现有群组,群组/项目 ID 保持不变。资源和相应的端点使用“群组”一词。
格式应符合以下模式:
^([a-f0-9]{24})$
。
查询参数
-
指示应用程序是否将响应包装在
envelope
JSON 对象中的标志。某些 API 客户端无法访问 HTTP 响应标头或状态代码。要修复此问题,请在查询中设置 Envelope=true。返回结果列表的端点将结果对象用作 envelope。应用程序将状态参数添加到响应正文中。默认值为
false
。 -
标志,用于指示响应是否返回响应中的列项总数 (totalCount)。
默认值为
true
。 -
响应每页返回的列项数。
最小值为
1
,最大值为500
。默认值为100
。 -
显示响应返回的当前总对象集的页面编号。
最小值为
1
。默认值为1
。 -
指示响应正文是否应采用 prettyprint 格式的标记。
默认值为
false
。Prettyprint
body
必需
要添加到指定项目的一个或多个访问列表条目。
-
要添加到项目的 IP 访问列表的 Amazon Web Services (AWS) 安全群组的唯一字符串。您的 IP 访问列表条目可以是 1 个 awsSecurityGroup、1 个 cidrBlock 或 1 个 ipAddress。您必须先为项目配置虚拟专用连接 (VPC) 对等互连,然后才能将 AWS 安全群组添加到 IP 访问列表。您无法将 AWS 安全群组设置为临时访问列表条目。如果设置 cidrBlock 或 ipAddress,请勿设置此参数。
格式应符合以下模式:
^([0-9]*/)?sg-([0-9]*)
。 -
您想要添加到项目 IP 访问列表的 IP 地址范围,采用无类域间路由 (CIDR) 表示法。您的 IP 访问列表条目可以是 1 个 awsSecurityGroup、1 个 cidrBlock 或 1 个 ipAddress。如果设置了 awsSecurityGroup 或 ipAddress,请勿设置此参数。
格式应符合以下模式:
^([0-9]{1,3}\.){3}[0-9]{1,3}(%2[fF][0-9]{1,3})?|([0-9a-f]{1,4}\:){7}[0-9a-f]{1,4}(%2[fF][0-9]{1,3})?|([0-9a-f]{1,4}\:){1,6}\:(%2[fF][0-9]{1,3})?$
。 -
解释此 IP 访问列表条目的用途或范围的注释。
最大长度为
80
。 -
MongoDB Cloud 删除临时访问列表条目的日期和时间。此参数以 ISO 8601 时间戳格式(UTC 格式)表示其值,可以包括时区名称。该日期必须晚于当前日期,但不得晚于您提交此请求后的一周。如果您在创建此 IP 访问列表条目时指定了到期日期,则资源会返回此参数。
-
要添加到项目 IP 访问列表的 IP 地址。您的 IP 访问列表条目可以是 1 个 awsSecurityGroup、1 个 cidrBlock 或 1 个 ipAddress。如果设置了 awsSecurityGroup 或 cidrBlock,请勿设置此参数。
格式应符合以下模式:
^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}|([0-9a-f]{1,4}:){7}[0-9a-f]{1,4}$
。
atlas api projectIpAccessList createGroupAccessListEntry --help
import (
"os"
"context"
"log"
sdk "go.mongodb.org/atlas-sdk/v20230101001/admin"
)
func main() {
ctx := context.Background()
clientID := os.Getenv("MONGODB_ATLAS_CLIENT_ID")
clientSecret := os.Getenv("MONGODB_ATLAS_CLIENT_SECRET")
// See https://dochub.mongodb.org/core/atlas-go-sdk-oauth
client, err := sdk.NewClient(sdk.UseOAuthAuth(clientID, clientSecret))
if err != nil {
log.Fatalf("Error: %v", err)
}
params = &sdk.CreateGroupAccessListEntryApiParams{}
sdkResp, httpResp, err := client.ProjectIPAccessListApi.
CreateGroupAccessListEntryWithParams(ctx, params).
Execute()
}
curl --include --header "Authorization: Bearer ${ACCESS_TOKEN}" \
--header "Accept: application/vnd.atlas.2023-01-01+json" \
--header "Content-Type: application/json" \
-X POST "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/accessList" \
-d '{ <Payload> }'
curl --user "${PUBLIC_KEY}:${PRIVATE_KEY}" \
--digest --include \
--header "Accept: application/vnd.atlas.2023-01-01+json" \
--header "Content-Type: application/json" \
-X POST "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/accessList" \
-d '{ <Payload> }'
[
{
"awsSecurityGroup": "string",
"cidrBlock": "string",
"comment": "string",
"deleteAfterDate": "2025-05-04T09:42:00Z",
"ipAddress": "string"
}
]
{
"links": [
{
"href": "https://cloud.mongodb.com/api/atlas",
"rel": "self"
}
],
"results": [
{
"awsSecurityGroup": "string",
"cidrBlock": "string",
"comment": "string",
"deleteAfterDate": "2025-05-04T09:42:00Z",
"groupId": "32b6e34b3d91647abb20e7b8",
"ipAddress": "string",
"links": [
{
"href": "https://cloud.mongodb.com/api/atlas",
"rel": "self"
}
]
}
],
"totalCount": 42
}
{
"error": 400,
"detail": "(This is just an example, the exception may not be related to this endpoint) No provider AWS exists.",
"reason": "Bad Request",
"errorCode": "VALIDATION_ERROR"
}
{
"error": 401,
"detail": "(This is just an example, the exception may not be related to this endpoint)",
"reason": "Unauthorized",
"errorCode": "NOT_ORG_GROUP_CREATOR"
}
{
"error": 403,
"detail": "(This is just an example, the exception may not be related to this endpoint)",
"reason": "Forbidden",
"errorCode": "CANNOT_CHANGE_GROUP_NAME"
}
{
"error": 404,
"detail": "(This is just an example, the exception may not be related to this endpoint) Cannot find resource AWS",
"reason": "Not Found",
"errorCode": "RESOURCE_NOT_FOUND"
}
{
"error": 500,
"detail": "(This is just an example, the exception may not be related to this endpoint)",
"reason": "Internal Server Error",
"errorCode": "UNEXPECTED_ERROR"
}