更新时间:2025-08-30 GMT+08:00
分享

更新工作空间

功能介绍

更新工作空间名称、描述等信息

调用方法

请参见如何调用API

URI

PUT /v1/{project_id}/workspaces/{workspace_id}

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数解释:

项目ID,用于明确项目归属,配置后可通过该ID查询项目下资产,可以通过调用API获取,也可以从控制台获取。获取项目ID

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

workspace_id

String

参数解释:

工作空间ID

取值范围:

不涉及

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

用户Token。

通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。

content-type

String

application/json;charset=UTF-8

表3 请求Body参数

参数

是否必选

参数类型

描述

name

String

工作空间名称

description

String

工作空间描述

view_bind_id

String

视图绑定的空间id

响应参数

状态码:200

表4 响应Body参数

参数

参数类型

描述

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

纳管空间列表

表5 workspace_agency_list

参数

参数类型

描述

project_id

String

委托空间所属项目id

id

String

空间委托id

name

String

空间委托名称

region_id

String

委托空间所属region id

workspace_attribution

String

THIS_ACCOUNT:本账号空间,CROSS_ACCOUNT:跨账号空间

agency_version

String

委托版本

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

表6 响应Body参数

参数

参数类型

描述

error_code

String

Error code.

error_msg

String

Error description.

状态码:500

表7 响应Body参数

参数

参数类型

描述

error_code

String

Error code.

error_msg

String

Error description.

请求示例

更新工作空间请求体

{
  "name" : "更新工作空间",
  "description" : "更新工作空间"
}

响应示例

状态码:200

请求成功

{
  "create_time" : "2024-07-02T09:25:17Z+0800",
  "creator_id" : "b4*****************************46a",
  "creator_name" : "l0******",
  "description" : "更新工作空间",
  "domain_id" : "ac*****************************bf4",
  "domain_name" : "scc****09",
  "enterprise_project_id" : "",
  "enterprise_project_name" : "",
  "id" : "39*************bf",
  "is_view" : false,
  "modifier_id" : "b4*****************************46a",
  "modifier_name" : "l0******",
  "name" : "更新工作空间",
  "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代码示例

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
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.*;


public class UpdateWorkspaceSolution {

    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();
        UpdateWorkspaceRequest request = new UpdateWorkspaceRequest();
        request.withWorkspaceId("{workspace_id}");
        UpdateWorkspaceRequestBody body = new UpdateWorkspaceRequestBody();
        body.withDescription("更新工作空间");
        body.withName("更新工作空间");
        request.withBody(body);
        try {
            UpdateWorkspaceResponse response = client.updateWorkspace(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
# 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 = UpdateWorkspaceRequest()
        request.workspace_id = "{workspace_id}"
        request.body = UpdateWorkspaceRequestBody(
            description="更新工作空间",
            name="更新工作空间"
        )
        response = client.update_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
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.UpdateWorkspaceRequest{}
	request.WorkspaceId = "{workspace_id}"
	descriptionUpdateWorkspaceRequestBody:= "更新工作空间"
	nameUpdateWorkspaceRequestBody:= "更新工作空间"
	request.Body = &model.UpdateWorkspaceRequestBody{
		Description: &descriptionUpdateWorkspaceRequestBody,
		Name: &nameUpdateWorkspaceRequestBody,
	}
	response, err := client.UpdateWorkspace(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

请求成功

400

请求参数有误

500

请求失败

错误码

请参见错误码

相关文档