更新时间:2024-10-16 GMT+08:00

创建并管理应用

操作场景

应用是一个功能相对完备的业务系统,由一个或多个特性相关的组件组成。

下面介绍如何调用创建应用API创建应用,再调用根据应用ID修改应用配置API为应用添加应用环境变量,最后调用根据应用ID获取应用详细信息API查询应用详细信息。

API的调用方法请参见如何调用API

前提条件

  • 已调用获取用户Token获取IAM用户的Token,并将token值设置为环境变量:export Token={token}。
  • 已获取ServiceStage的终端节点,详细信息请参见地区和终端节点,并用于替换以下操作步骤示例中的{servicestage_endpoint}。

操作步骤

  1. 调用创建应用API创建应用,请求示例如下:

    curl -k -H "Content-Type:application/json;charset=utf8" -H "X-Auth-Token:$Token" -X POST "https://{servicestage_endpoint}/v3/{project_id}/cas/applications" -d ' 
    {
        "name": "app-test-application",
        "description": "test application",
        "enterprise_project_id": "0",
        "labels": [
            {
                "key": "testKey",
                "value": "testValue"
            }
        ]
    }'

    返回结果:

    {
        "id": "2c458700-c8e0-4651-a73b-5219b70a6572",
        "name": "app-test-application",
        "description": "test application",
        "project_id": "063a3158b1a34710b36ad208b9497d00",
        "enterprise_project_id": "0",
        "creator": "test_user",
        "create_time": 1689575641705,
        "update_time": 1689575641705,
        "unified_model": null,
        "labels": [
            {
                "key": "testKey",
                "value": "testValue"
            }
        ]
    }

    记录返回结果中加粗显示的应用ID,用于替换后续示例中的{application_id}。

  2. 调用根据应用ID修改应用配置API为应用添加应用环境变量,请求示例如下:

    curl -k -H "Content-Type:application/json;charset=utf8" -H "X-Auth-Token:$Token" -X PUT "https://{servicestage_endpoint}/v3/{project_id}/cas/applications/{application_id}/configuration" -d ' 
    {
        "environment_id": "21a43958-f64f-4077-8ae3-3a03bf0111c7",
        "configuration": {
            "env": [
                {
                    "name": "testName",
                    "value": "testValue"
                }
            ]
        }
    }'

    返回结果:

    {
        "application_id": "2c458700-c8e0-4651-a73b-5219b70a6572",
        "environment_id": "21a43958-f64f-4077-8ae3-3a03bf0111c7",
        "configuration": {
            "env": [
                {
                    "name": "testName",
                    "value": "testValue"
                }
            ]
        }
    }

  3. 调用根据应用ID获取应用详细信息API根据应用ID查询应用详细信息,请求示例如下:

    curl -k -H "Content-Type:application/json;charset=utf8" -H "X-Auth-Token:$token" -X GET "https://{servicestage_endpoint}/v3/{project_id}/cas/applications/{application_id}"

    返回结果:

    {
        "id": "2c458700-c8e0-4651-a73b-5219b70a6572",
        "name": "app-test-application",
        "description": "test application",
        "project_id": "063a3158b1a34710b36ad208b9497d00",
        "enterprise_project_id": "0",
        "creator": "test_user",
        "create_time": 1689575641705,
        "update_time": 1689575641705,
        "unified_model": null,
        "labels": [
            {
                "key": "testKey",
                "value": "testValue"
            }
        ],
        "component_count": 0
    }