> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CloudScript

> 管理经典 CloudScript JavaScript 修订版以及 CloudScript 使用的 Azure Functions 注册。

`playfab cloudscript` 命令系列属于实验性功能。其 CLI 接口可能会根据反馈而更改或被删除。

使用 `classic` 管理经典 CloudScript(即 PlayFab 托管的 JavaScript),使用 `function` 管理 CloudScript 调用的 Azure
Functions。这些命令在运行之前都不会进行询问。

## `playfab cloudscript classic`

| 命令 | PlayFab API 路径 | 选项 |
| - | - | - |
| `playfab cloudscript classic revision get` | `/Admin/GetCloudScriptRevision` | 可选 `--version` 和 `--revision`;两者均默认为最新值。 |
| `playfab cloudscript classic version list` | `/Admin/GetCloudScriptVersions` | 无。 |
| `playfab cloudscript classic revision create` | `/Admin/UpdateCloudScript` | `--file`(必需),要作为新修订版上传的 JavaScript 文件。`--publish` 还会使新修订版上线。 |
| `playfab cloudscript classic revision publish` | `/Admin/SetPublishedRevision` | `--version` 和 `--revision`(两者均为必需)。 |

## `playfab cloudscript function`

`function` 将现有的 Azure Functions 注册到 PlayFab,以便 CloudScript 可以调用它们。它不会在 Azure 中创建或更改任何内容。

| 命令 | PlayFab API 路径 | 选项 |
| - | - | - |
| `playfab cloudscript function list` | `/CloudScript/ListFunctions`;如果使用 `--type`,则为 `/CloudScript/ListHttpFunctions`、`/CloudScript/ListQueuedFunctions` 或 `/CloudScript/ListEventHubFunctions` | 可选 `--type`:`http`、`queued` 或 `eventhub`。省略它可列出每个注册。 |
| `playfab cloudscript function register` | `/CloudScript/RegisterHttpFunction` | `--type http`、`--name` 和 `--url`(均为必需);可选 `--key-file`。`http` 是唯一可以注册的类型。 |
| `playfab cloudscript function unregister` | `/CloudScript/UnregisterFunction` | `--name`(必需)。 |

### 函数密钥

使用函数级授权(Azure 的默认设置)的 HTTP 触发的 Azure 函数需要其函数密钥。请在文件中而不是在 URL 中传递密钥,以免其出现在 shell
历史记录和进程列表中:

| 选项 | 说明 |
| - | - |
| `--url <url>` | 函数的 URL,不包含其密钥。带有 `code` 查询参数的 URL 会被拒绝。 |
| `--key-file <path>` | 包含函数密钥(与 Azure 门户中显示的一致)的文件,或者使用 `-` 从管道传输的 stdin 读取。前后的空格会被去除。对于不需要密钥的函数,请省略此选项。 |

CLI 会将密钥作为 `code` 添加到 URL 中,并注册与 Azure
门户的“**获取函数 URL**”中显示的相同 URL。

## 表格输出

以下命令接受 `--output table`;其他命令不接受。请参阅
[表格输出](https://docs.xbox.com/zh-CN/tools/xbox-cli/commands.md#table-output)。

| 命令 | 列 |
| - | - |
| `playfab cloudscript classic version list` | `VERSION`、`PUBLISHED REVISION`、`LATEST REVISION` |
| `playfab cloudscript function list` | `FUNCTION NAME` |

若要查看注册的 URL 和其他详细信息,请使用 JSON 输出。

```bash theme={null}
xbox --playfab-title-id ABC123 playfab cloudscript classic version list --output table
```

```text theme={null}
VERSION  PUBLISHED REVISION  LATEST REVISION
-------  ------------------  ---------------
1        3                   5
2        1                   1
```

## 示例

检查已发布的版本,并读取一个修订版:

```bash theme={null}
xbox --playfab-title-id ABC123 playfab cloudscript classic version list
xbox --playfab-title-id ABC123 playfab cloudscript classic revision get --version 1 --revision 2
```

将 `main.js` 上传为新修订版:

```bash theme={null}
xbox --playfab-title-id ABC123 playfab cloudscript classic revision create --file main.js
```

`create` 返回新修订版的 `Version` 和 `Revision`。检查修订版后,使用这些编号发布它:

```bash theme={null}
xbox --playfab-title-id ABC123 playfab cloudscript classic revision publish --version 1 --revision 3
```

列出 HTTP 函数注册:

```bash theme={null}
xbox --playfab-title-id ABC123 playfab cloudscript function list --type http
```

注册一个密钥位于 `function-key.txt` 中的函数:

```bash theme={null}
xbox --playfab-title-id ABC123 playfab cloudscript function register --type http --name MatchWebhook --url https://nodpublishers.azurewebsites.net/api/MatchWebhook --key-file ./function-key.txt
```

若要改为从 stdin 读取密钥(例如从机密存储中读取):

```bash theme={null}
get-function-key | xbox --playfab-title-id ABC123 playfab cloudscript function register --type http --name MatchWebhook --url https://nodpublishers.azurewebsites.net/api/MatchWebhook --key-file -
```

注册不需要密钥的函数:

```bash theme={null}
xbox --playfab-title-id ABC123 playfab cloudscript function register --type http --name PublicStatus --url https://nodpublishers.azurewebsites.net/api/PublicStatus
```

取消注册 `MatchWebhook`:

```bash theme={null}
xbox --playfab-title-id ABC123 playfab cloudscript function unregister --name MatchWebhook
```


## Related topics

- [CloudScript](https://docs.xbox.com/zh-CN/services/playfab/live-service-management/service-gateway/automation/cloudscript/index.md)
- [执行 Cloud Script](https://docs.xbox.com/zh-CN/services/playfab/api-references/rest/client/server-side-cloud-script/execute-cloud-script.md)
- [Execute Cloud Script](https://docs.xbox.com/api-reference/server-side-cloud-script/execute-cloud-script.md)
- [CloudScript 快速入门](https://docs.xbox.com/zh-CN/services/playfab/live-service-management/service-gateway/automation/cloudscript/quickstart.md)
- [cloudscript_executed](https://docs.xbox.com/zh-CN/services/playfab/api-references/events/CloudScript/cloudscript-executed.md)
