新建工作空间
功能介绍
在使用安全云脑的基线检查、告警管理、安全分析、安全编排等功能前,需要创建工作空间,它可以将资源划分为各个不同的工作场景,避免资源冗余查找不便,影响日常使用。
调用方法
请参见如何调用API。
URI
POST /v1/{project_id}/workspaces
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
项目id |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
用户Token。 通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。 |
content-type |
是 |
String |
application/json;charset=UTF-8 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
region_id |
是 |
String |
区域id |
enterprise_project_id |
否 |
String |
企业项目id |
enterprise_project_name |
否 |
String |
企业项目名称 |
view_bind_id |
否 |
String |
视图绑定的空间id |
is_view |
否 |
Boolean |
是否是视图 |
name |
是 |
String |
工作空间名称 |
description |
否 |
String |
工作空间描述 |
project_name |
是 |
String |
项目名称 |
tags |
否 |
Array of TagsPojo objects |
通过给账号下的资源添加标签,可以对资源进行自定义标记,实现资源的分类。可到标签管理服务使用可视化表格操作资源标签,并对标签进行批量编辑。 |
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
id |
String |
工作空间id |
create_time |
String |
创建时间 |
update_time |
String |
更新时间 |
name |
String |
工作空间名称 |
description |
String |
工作空间描述 |
creator_id |
String |
创建人id |
creator_name |
String |
创建人名称 |
modifier_id |
String |
修改人id |
modifier_name |
String |
修改人名称 |
project_id |
String |
所属项目id |
project_name |
String |
所属项目名称 |
domain_id |
String |
所属租户id |
domain_name |
String |
所属租户名称 |
enterprise_project_id |
String |
企业项目id |
enterprise_project_name |
String |
企业项目名称 |
is_view |
Boolean |
是否是视图 |
region_id |
String |
区域id |
view_bind_id |
String |
视图绑定的空间id |
view_bind_name |
String |
视图绑定的空间名称 |
workspace_agency_list |
Array of workspace_agency_list objects |
仅用于视图场景,列出了该视图纳管的空间列表 |
参数 |
参数类型 |
描述 |
---|---|---|
project_id |
String |
委托空间所属项目id |
id |
String |
空间委托id |
name |
String |
空间委托名称 |
region_id |
String |
委托空间所属region id |
workspace_attribution |
String |
THIS_ACCOUNT:本账号空间,CROSS_ACCOUNT:跨账号空间 |
agency_version |
String |
用户创建托管空间时使用的IAM委托版本,V3或者V5 |
domain_id |
String |
委托租户id |
domain_name |
String |
委托租户名称 |
iam_agency_id |
String |
iam委托id |
iam_agency_name |
String |
iam委托名称 |
resource_spec_code |
Array of strings |
委托空间购买版本 |
selected |
Boolean |
是否被视图选中 |
状态码: 400
参数 |
参数类型 |
描述 |
---|---|---|
code |
String |
错误码 |
message |
String |
错误消息 |
状态码: 500
参数 |
参数类型 |
描述 |
---|---|---|
code |
String |
错误码 |
message |
String |
错误消息 |
请求示例
创建工作空间请求体
{ "name" : "我的工作空间", "region_id" : "cn-north-4", "project_name" : "cn-north-4", "enterprise_project_id" : "", "enterprise_project_name" : "", "tags" : [ { "key" : "tag1", "value" : "value1" } ], "description" : "我的工作空间" }
响应示例
状态码: 200
请求成功
{ "create_time" : "2024-07-02T09:25:17Z+0800", "creator_id" : "b4*****************************46a", "creator_name" : "l00644738", "description" : "我的工作空间", "domain_id" : "ac*****************************bf4", "domain_name" : "scc****09", "enterprise_project_id" : "", "enterprise_project_name" : "", "id" : "39*************bf", "is_view" : false, "modifier_id" : "", "modifier_name" : "", "name" : "我的工作空间", "project_id" : "15**************************da6", "project_name" : "cn-north-4", "region_id" : "cn-north-4", "update_time" : "2024-07-02T09:25:17Z+0800", "view_bind_id" : "", "view_bind_name" : "", "workspace_agency_list" : [ ] }
SDK代码示例
SDK代码示例如下。
Java
创建工作空间请求体
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.secmaster.v2.region.SecMasterRegion; import com.huaweicloud.sdk.secmaster.v2.*; import com.huaweicloud.sdk.secmaster.v2.model.*; import java.util.List; import java.util.ArrayList; public class CreateWorkspaceSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); SecMasterClient client = SecMasterClient.newBuilder() .withCredential(auth) .withRegion(SecMasterRegion.valueOf("<YOUR REGION>")) .build(); CreateWorkspaceRequest request = new CreateWorkspaceRequest(); CreateWorkspaceRequestBody body = new CreateWorkspaceRequestBody(); List<TagsPojo> listbodyTags = new ArrayList<>(); listbodyTags.add( new TagsPojo() .withKey("tag1") .withValue("value1") ); body.withTags(listbodyTags); body.withProjectName("cn-north-4"); body.withDescription("我的工作空间"); body.withName("我的工作空间"); body.withEnterpriseProjectName(""); body.withEnterpriseProjectId(""); body.withRegionId("cn-north-4"); request.withBody(body); try { CreateWorkspaceResponse response = client.createWorkspace(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
Python
创建工作空间请求体
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdksecmaster.v2.region.secmaster_region import SecMasterRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdksecmaster.v2 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = SecMasterClient.new_builder() \ .with_credentials(credentials) \ .with_region(SecMasterRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateWorkspaceRequest() listTagsbody = [ TagsPojo( key="tag1", value="value1" ) ] request.body = CreateWorkspaceRequestBody( tags=listTagsbody, project_name="cn-north-4", description="我的工作空间", name="我的工作空间", enterprise_project_name="", enterprise_project_id="", region_id="cn-north-4" ) response = client.create_workspace(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
Go
创建工作空间请求体
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" secmaster "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v2/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := secmaster.NewSecMasterClient( secmaster.SecMasterClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreateWorkspaceRequest{} keyTags:= "tag1" valueTags:= "value1" var listTagsbody = []model.TagsPojo{ { Key: &keyTags, Value: &valueTags, }, } descriptionCreateWorkspaceRequestBody:= "我的工作空间" enterpriseProjectNameCreateWorkspaceRequestBody:= "" enterpriseProjectIdCreateWorkspaceRequestBody:= "" request.Body = &model.CreateWorkspaceRequestBody{ Tags: &listTagsbody, ProjectName: "cn-north-4", Description: &descriptionCreateWorkspaceRequestBody, Name: "我的工作空间", EnterpriseProjectName: &enterpriseProjectNameCreateWorkspaceRequestBody, EnterpriseProjectId: &enterpriseProjectIdCreateWorkspaceRequestBody, RegionId: "cn-north-4", } response, err := client.CreateWorkspace(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
请求成功 |
400 |
请求参数有误 |
500 |
请求失败 |
错误码
请参见错误码。