El contenido no se encuentra disponible en el idioma seleccionado. Estamos trabajando continuamente para agregar más idiomas. Gracias por su apoyo.
Creating a Workspace
Function
Before using the baseline inspection, alert management, security analysis, and security orchestration in SecMaster, you need to create at least one workspace first. You can use workspaces to group your resources by application scenario. This will make security operations more efficient.
Calling Method
For details, see Calling APIs.
URI
POST /v1/{project_id}/workspaces
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Project ID. |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
Yes |
String |
User token. It can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is the user token. |
content-type |
Yes |
String |
application/json;charset=UTF-8 |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
region_id |
Yes |
String |
Region ID. |
enterprise_project_id |
No |
String |
Enterprise project ID. |
enterprise_project_name |
No |
String |
Enterprise project name. |
view_bind_id |
No |
String |
ID of the workspace associated with the view. |
is_view |
No |
Boolean |
Whether the workspace is a workspace view. |
name |
Yes |
String |
Workspace name. |
description |
No |
String |
Workspace description. |
project_name |
Yes |
String |
Project name. |
tags |
No |
Array of TagsPojo objects |
Adding a Tag to Arrays |
Response Parameters
Status code: 200
Parameter |
Type |
Description |
---|---|---|
id |
String |
Workspace ID. |
create_time |
String |
Creation time. |
update_time |
String |
Update time. |
name |
String |
Workspace name. |
description |
String |
Workspace description. |
creator_id |
String |
Creator ID. |
creator_name |
String |
Creator name. |
modifier_id |
String |
Modifier ID. |
modifier_name |
String |
Modifier name. |
project_id |
String |
Project ID. |
project_name |
String |
Project name. |
domain_id |
String |
Tenant ID. |
domain_name |
String |
Tenant name. |
enterprise_project_id |
String |
Enterprise project ID. |
enterprise_project_name |
String |
Enterprise project name. |
is_view |
Boolean |
Whether the workspace is a workspace view. |
region_id |
String |
Region ID. |
view_bind_id |
String |
ID of the workspace associated with the view. |
view_bind_name |
String |
Name of the workspace associated with the view. |
workspace_agency_list |
Array of workspace_agency_list objects |
The list of managed workspaces. |
Parameter |
Type |
Description |
---|---|---|
project_id |
String |
ID of the project the workspace agency belongs to. |
id |
String |
Workspace agency ID. |
name |
String |
Workspace agency name. |
region_id |
String |
ID of the region the workspace agency belongs to. |
workspace_attribution |
String |
THIS_ACCOUNT: The workspace belongs to the current account; CROSS_ACCOUNT: The workspace is accessible across different accounts. |
agency_version |
String |
Agency version. |
domain_id |
String |
ID of the delegation account. |
domain_name |
String |
Name of the delegation account. |
iam_agency_id |
String |
IAM agency ID. |
iam_agency_name |
String |
IAM agency name. |
resource_spec_code |
Array of strings |
Workspace agency edition. |
selected |
Boolean |
Whether the workspace is selected for an agency view. |
Status code: 400
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code. |
error_msg |
String |
Error description. |
Status code: 500
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code. |
error_msg |
String |
Error description. |
Example Requests
Request body for creating a workspace.
{
"name" : "My Workspaces",
"region_id" : "region_id",
"project_name" : "project_name",
"enterprise_project_id" : "",
"enterprise_project_name" : "",
"tags" : [ {
"key" : "tag1",
"value" : "value1"
} ],
"description" : "My Workspaces"
}
Example Responses
Status code: 200
Request succeeded.
{
"create_time" : "2024-07-02T09:25:17Z+0800",
"creator_id" : "b4*****************************46a",
"creator_name" : "l0******",
"description" : "My Workspaces",
"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" : "My Workspaces",
"project_id" : "15**************************da6",
"project_name" : "project_name",
"region_id" : "region_id",
"update_time" : "2024-07-02T09:25:17Z+0800",
"view_bind_id" : "",
"view_bind_name" : "",
"workspace_agency_list" : [ ]
}
SDK Sample Code
The SDK sample code is as follows.
Java
Request body for creating a workspace.
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("project_name");
body.withDescription("My Workspaces");
body.withName("My Workspaces");
body.withEnterpriseProjectName("");
body.withEnterpriseProjectId("");
body.withRegionId("region_id");
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
Request body for creating a workspace.
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="project_name",
description="My Workspaces",
name="My Workspaces",
enterprise_project_name="",
enterprise_project_id="",
region_id="region_id"
)
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
Request body for creating a workspace.
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:= "My Workspaces"
enterpriseProjectNameCreateWorkspaceRequestBody:= ""
enterpriseProjectIdCreateWorkspaceRequestBody:= ""
request.Body = &model.CreateWorkspaceRequestBody{
Tags: &listTagsbody,
ProjectName: "project_name",
Description: &descriptionCreateWorkspaceRequestBody,
Name: "My Workspaces",
EnterpriseProjectName: &enterpriseProjectNameCreateWorkspaceRequestBody,
EnterpriseProjectId: &enterpriseProjectIdCreateWorkspaceRequestBody,
RegionId: "region_id",
}
response, err := client.CreateWorkspace(request)
if err == nil {
fmt.Printf("%+v\n", response)
} else {
fmt.Println(err)
}
}
|
More
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Status Codes
Status Code |
Description |
---|---|
200 |
Request succeeded. |
400 |
Invalid request parameter. |
500 |
Request failed. |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot