# CLI での CCD の使用

> Follow this workflow to use CCD through the UGS command line interface, such as to authenticate, create buckets, manage entries, and handle releases.

このセクションでは、コマンドラインインターフェース (CLI) で Cloud Content Delivery (CCD) を使用する方法の例を、以下のトピックを含めて示します。

* [認証](#authentication)
* [バケットの作成](#creating-a-bucket)
* [ローカルファイルセットからのエントリーーの作成](#creating-entries-in-the-bucket)
* [リリースの作成](#creating-a-release)
* [バッジの管理](#managing-badges)

> **Note:**
>
> v0.11.0 より前のバージョンの CLI では、`--environment` フラグや `--project` フラグは必要ありません。

## 認証##authentication

API キーを使用してサービスにサインインします。API キーを調べる方法については、[使用の準備](./cli.md#get-started) セクションを参照してください。

*認証*

```powershell
$ ucd auth login XXXXXXXXXXXX
Login successful.
```

`auth info` コマンドを使用して、サインインしているかどうかを確認します。

*サインインの確認*

```powershell
$ ucd auth info
Current user: Joe Smith
```

## バケットの作成##creating-a-bucket

最初のバケットを作成します。バケットは 1 つのプロジェクトに関連付けられます。この例のプロジェクト ID は `e1942cea-12df-4220-aa6d-f8c9c3ab7526` ですが、実際のプロジェクト ID のどれかを使用する必要があります。プロジェクト ID を調べる方法については、[使用の準備](./cli.md#get-started) セクションを参照してください。

同様に、この例の環境 ID は `b5179fae-d9be-4cd4-8afb-7bfdd691eb06` ですが、実際の環境 ID のどれかを使用する必要があります。プロジェクトの環境とそれに対応する ID のリストを見つけるには、ダッシュボードにアクセスして **Projects** (プロジェクト) > **Project Settings** (プロジェクト設定) > **Environments** (環境) に移動します。

このプロジェクトのバケットをリスト表示します (この時点では、リストは空のはずです)。

*バケットのリスト表示*

```powershell
$ ucd buckets list e1942cea-12df-4220-aa6d-f8c9c3ab7526 --environment=b5179fae-d9be-4cd4-8afb-7bfdd691eb06 
No buckets found for given project and environment.
```

このプロジェクトに `example_bucket` という名前のバケットを作成します。

*バケットの作成*

```powershell
$ ucd buckets create e1942cea-12df-4220-aa6d-f8c9c3ab7526 example_bucket --environment=b5179fae-d9be-4cd4-8afb-7bfdd691eb06
Created bucket: example_bucket (aee9ee5f-fa01-46d3-a293-731d15f066cf)
```

> **Note:**
>
> [ダッシュボード](./dashboard.md) から行えるのは、バケット名の編集と説明の追加のみです。

バケット名とエントリー名では大文字と小文字が区別されます。

新しく作成したバケットを確認するには、このプロジェクトのバケットを再度リスト表示します。

*バケットのリスト表示*

```powershell
$ ucd buckets list e1942cea-12df-4220-aa6d-f8c9c3ab7526 --environment=b5179fae-d9be-4cd4-8afb-7bfdd691eb06
Buckets for project (e1942cea-12df-4220-aa6d-f8c9c3ab7526) in environment (b5179fae-d9be-4cd4-8afb-7bfdd691eb06):
- example_bucket (aee9ee5f-fa01-46d3-a293-731d15f066cf)
```

エントリーとリリースの作成作業を簡単にするために、環境と新しく作成したバケットをローカル設定に保存します (操作ごとに CLI でパラメーターとして指定する必要がなくなります)。

環境 ID (この例では `b5179fae-d9be-4cd4-8afb-7bfdd691eb06`) をコピーします。

```powershell
$ ucd config set environment b5179fae-d9be-4cd4-8afb-7bfdd691eb06 --project=e1942cea-12df-4220-aa6d-f8c9c3ab7526
Successfully switched to environment b5179fae-d9be-4cd4-8afb-7bfdd691eb06.
Currently active project: e1942cea-12df-4220-aa6d-f8c9c3ab7526.
```

上のバケット作成メッセージから、バケットの ID (バケット名ではありません) をコピーします (この例では `aee9ee5f-fa01-46d3-a293-731d15f066cf`)。

*設定の実行*

```powershell
$ ucd config set bucket aee9ee5f-fa01-46d3-a293-731d15f066cf
Successfully switched to bucket aee9ee5f-fa01-46d3-a293-731d15f066cf.
Currently active project: e1942cea-12df-4220-aa6d-f8c9c3ab7526.
Currently active environment: b5179fae-d9be-4cd4-8afb-7bfdd691eb06.
Currently active bucket: aee9ee5f-fa01-46d3-a293-731d15f066cf (example_bucket).
```

CCD は、指定したバケットと環境で、エントリーとリリースに関するコマンドを自動的に実行します。

## バケットでのエントリーの作成##creating-entries-in-the-bucket

この新しく作成したバケット内のエントリーをリスト表示します (リストは空のはずです)。

*エントリーのリスト表示*

```powershell
$ ucd entries list
No Entries found for current bucket.
```

ローカルフォルダー内のすべてのファイルを同期します。この例では、ローカルフォルダーには生成された [アセットバンドル](https://docs.unity3d.com/Manual/AssetBundlesIntro.html) がコンテンツとして含まれています。

*ファイルの同期*

```powershell
$ ucd entries sync ./ServerData/StandaloneOSX
Calculating...
Added Entry: catalog_2019.07.30.18.24.34.hash
Added Entry: catalog_2019.07.30.18.24.34.json
Added Entry: remotedemodata_green.bundle
Added Entry: remotedemodata_mat1.bundle
Added Entry: remotedemodata_sphere.bundle
Added Entry: remotedemodata_unitylogo.bundle
Added Entry: remotedemodata_unitylogoprefab.bundle
Added Entry: remotedemodata_scenes_scene2.bundle
Added Entry: remotedemodata_scenes_scene.bundle
Added Entry: spaceshooterdata_done_asteroid01.bundle
Added Entry: spaceshooterdata_done_asteroid02.bundle
Added Entry: spaceshooterdata_done_asteroid03.bundle
Added Entry: spaceshooterdata_done_bolt-enemy.bundle
Added Entry: spaceshooterdata_done_bolt.bundle
Added Entry: spaceshooterdata_done_enemyship.bundle
Added Entry: spaceshooterdata_done_player.bundle
Added Entry: spaceshooterdata_engines_enemy.bundle
Added Entry: spaceshooterdata_engines_player.bundle
Added Entry: spaceshooterdata_explosion_asteroid.bundle
Added Entry: spaceshooterdata_explosion_enemy.bundle
Added Entry: spaceshooterdata_explosion_player.bundle
Added Entry: spaceshooterdata_starfield.bundle
Complete! Bytes uploaded: 5346781
```

これにより、ファイルがバケットにエントリーとして追加されます。バケットのコンテンツをリスト表示し、各エントリーに関するいくつかの基本情報を確認できます。

*バケットのコンテンツのリスト表示*

```powershell
$ ucd entries list
22 entries for current bucket (aee9ee5f-fa01-46d3-a293-731d15f066cf):
2019-08-21 14:27:03       167915 spaceshooterdata_starfield.bundle
2019-08-21 14:27:00       573539 spaceshooterdata_explosion_player.bundle
2019-08-21 14:26:56       412235 spaceshooterdata_explosion_enemy.bundle
2019-08-21 14:26:52       382630 spaceshooterdata_explosion_asteroid.bundle
2019-08-21 14:26:49       177018 spaceshooterdata_engines_player.bundle
2019-08-21 14:26:45       157215 spaceshooterdata_engines_enemy.bundle
2019-08-21 14:26:42      1085518 spaceshooterdata_done_player.bundle
2019-08-21 14:26:38      1070297 spaceshooterdata_done_enemyship.bundle
2019-08-21 14:26:34        27178 spaceshooterdata_done_bolt.bundle
2019-08-21 14:26:31        28362 spaceshooterdata_done_bolt-enemy.bundle
2019-08-21 14:26:28       231658 spaceshooterdata_done_asteroid03.bundle
2019-08-21 14:26:24       221450 spaceshooterdata_done_asteroid02.bundle
2019-08-21 14:26:20       227842 spaceshooterdata_done_asteroid01.bundle
2019-08-21 14:26:17        23016 remotedemodata_scenes_scene.bundle
2019-08-21 14:26:13        23064 remotedemodata_scenes_scene2.bundle
2019-08-21 14:26:10        10568 remotedemodata_unitylogoprefab.bundle
2019-08-21 14:26:07       462522 remotedemodata_unitylogo.bundle
2019-08-21 14:26:03         7864 remotedemodata_sphere.bundle
2019-08-21 14:26:00         6320 remotedemodata_mat1.bundle
2019-08-21 14:25:57         6320 remotedemodata_green.bundle
2019-08-21 14:25:53        44218 catalog_2019.07.30.18.24.34.json
2019-08-21 14:25:50           32 catalog_2019.07.30.18.24.34.hash
```

特定のエントリーについてさらに詳しい情報を取得するには、エントリーのパスを指定して `entries info` コマンドを使用します。

*エントリー情報の取得*

```powershell
$ ucd entries info spaceshooterdata_starfield.bundle`
Entry Info:
Path: spaceshooterdata_starfield.bundle
Id: 8ac46783-be01-4a47-b23e-74233fc7cc09
Last Modified: 2019-08-21 14:27:03
Content Size: 167915
Content Hash: 4a3ad5b69bd489699d1909e8868a7cb1
Content Type: application/octet-stream
Content Link: …
Labels:
Metadata:
Current Version: aa0304db-fd9f-4772-9549-dfeb44cc6d6f
```

これでゲームクライアントは、エントリーに関連付けられたパスを使用して、バケット内の個々のファイルのコンテンツをリクエストできるようになりました。ゲームクライアントのリクエストはすべて、`<project_guid>.client-api.unity3dusercontent.com` にあるプロジェクト固有のサブドメインに対して行います。リクエストのパスの URL はすべて、`/client_api/v1/` で始まります。これらのクライアントリクエストはいずれも認証を必要としません。

エントリー (例えば `spaceshooterdata_starfield.bundle`) のコンテンツをパスで取得するには、以下のように入力します。

`https://<project_guid>.client-api.unity3dusercontent.com/client_api/v1/buckets/aee9ee5f-fa01-46d3-a293-731d15f066cf/entry_by_path/content/?path=spaceshooterdata_starfield.bundle`

または、エントリーのコンテンツをエントリー ID で取得するには、以下のように入力します。

`https://<project_guid>.client-api.unity3dusercontent.com/client_api/v1/buckets/aee9ee5f-fa01-46d3-a293-731d15f066cf/entries/8ac46783-be01-4a47-b23e-74233fc7cc09/content/`

## リリースの作成##creating-a-release

エントリーの現在の状態からリリースを作成します。

*リリースの作成*

```powershell
$ ucd releases create -n "This is a sample note"
Created release (#1) in bucket (aee9ee5f-fa01-46d3-a293-731d15f066cf).
Id: 80653663-eb39-45e7-9323-e34b23df0d75
Created: 2019-08-21 14:27:30
...
```

これにより、後でそれらのエントリーを更新または削除した場合でも、コンテンツをリクエストする際にこれらの正確なバージョンのエントリーを使用できます。

> **Note:**
>
> リリースの作成時に `-n` フラグを使用することで注記を追加できますが、後で注記を編集する場合は [ダッシュボード](./dashboard.md#releases) からのみ行うことができます。

リリースについてさらに詳しい情報を取得するには、`releases info` コマンドを使用し、先ほど作成したリリースの ID を指定します。

*リリース情報の取得*

```powershell
$ ucd releases info 80653663-eb39-45e7-9323-e34b23df0d75
Release #1:
Id: 80653663-eb39-45e7-9323-e34b23df0d75
Created: 2019-08-21 14:27:30
Content Size: 123456
Content Hash: b62343cb3582a7de1286dd3cf23c3592
Notes: This is a sample note
Metadata:
Entries:
- remotedemodata_scenes_scene2.bundle  (version: d7c69bc0-5c0b-4625-8a7d-94a4972aa236)
- remotedemodata_unitylogo.bundle  (version: 97d3659f-0b74-403a-be67-02641ce2dc91)
- spaceshooterdata_done_enemyship.bundle  (version: edcedc81-80b6-4006-9732-0444898fcffa)
- remotedemodata_unitylogoprefab.bundle  (version: 4edfa2be-7fae-44c9-bb45-f601cc1130db)
- spaceshooterdata_done_bolt-enemy.bundle  (version: ef36bfa8-8b24-4b81-a329-b3fad0a0939b)
...
```

このバケットに生成したすべてのリリースのリストを取得するには、以下のように入力します。

*バケット内のリリースのリスト表示*

```powershell
$ ucd releases list
Releases for current bucket (aee9ee5f-fa01-46d3-a293-731d15f066cf):
2019-08-21 14:27:30  #1 (80653663-eb39-45e7-9323-e34b23df0d75)
```

これで、このリリース内に含まれているコンテンツを直接参照できるようになりました。これにより、後でバケット内のエントリーを変更した場合でも、CCD がリリースの生成に使用する正確なコンテンツのセットを確実に取得できます。

エントリー (例えば `spaceshooterdata_starfield.bundle`) のコンテンツをパスで取得するには、以下のように入力します。

`https://<project_guid>.client-api.unity3dusercontent.com/client_api/v1/buckets/aee9ee5f-fa01-46d3-a293-731d15f066cf/releases/80653663-eb39-45e7-9323-e34b23df0d75/entry_by_path/content/?path=spaceshooterdata_starfield.bundle`

または、エントリーのコンテンツをエントリー ID で取得するには、以下のように入力します。

`https://<project_guid>.client-api.unity3dusercontent.com/client_api/v1/buckets/aee9ee5f-fa01-46d3-a293-731d15f066cf/releases/80653663-eb39-45e7-9323-e34b23df0d75/entries/8ac46783-be01-4a47-b23e-74233fc7cc09/content/`

バケット内の最新のリリースに対応するコンテンツをリクエストすることもできるため、CCD が新しいリリースを生成するたびにクライアントが変更を行う必要はありません。これを行うには、`release_by_badge` ルートを使用するようにリクエストを更新し、`latest` というバッジ名を指定します ([バッジの管理](#managing-badges) を参照してください)。例えば、以下のようにします。

`https://<project_guid>.client-api.unity3dusercontent.com/client_api/v1/buckets/aee9ee5f-fa01-46d3-a293-731d15f066cf/release_by_badge/latest/entry_by_path/content/?path=spaceshooterdata_starfield.bundle`

## バッジの管理##managing-badges

リリースを生成したら、そのリリースを一意に識別するバッジを適用できます。バッジが指すことができるのはバケット内の 1 つのリリースのみですが、リリース間でバッジを移動できます。実行時には、特定のリリース ID ではなくバッジ名を使用してコンテンツのクエリを実行でき、ワークフローの柔軟性を向上させることができます。

例えば、`qa_latest` という名前のバッジを QA チームで使用するために最新のリリースに適用し、そのバッジをプロセス (手動または自動) の一環としてそれぞれの新しいリリースに移動することができます。

`my_first_badge` という名前のバッジを [リリースの作成](#creating-a-release) で生成したリリースに追加するには、以下のように `badge_name` と `release_ID` を引数として使用します。

*バッジの追加*

```powershell
$ ucd badges add my_first_badge 80653663-eb39-45e7-9323-e34b23df0d75
Added badge 'my_first_badge' to release (80653663-eb39-45e7-9323-e34b23df0d75).
```

このバケットで適用したすべてのバッジをリスト表示するには、以下のようにします。

*バケット内のバッジのリスト表示*

```powershell
$ ucd badges list
Badges for current bucket (aee9ee5f-fa01-46d3-a293-731d15f066cf):
2020-01-07 12:55:41  my_first_badge  (80653663-eb39-45e7-9323-e34b23df0d75)
```

バッジが参照しているリリースに関連付けられているコンテンツをダウンロードする準備ができました。これは、エントリー ID でコンテンツをダウンロードするのと同様の方法で行うことができます。

エントリー (例えば `spaceshooterdata_starfield.bundle`) のコンテンツをパスで取得するには、以下のように入力します。

`https://<project_guid>.client-api.unity3dusercontent.com/client_api/v1/buckets/aee9ee5f-fa01-46d3-a293-731d15f066cf/release_by_badge/my_first_badge/entry_by_path/content/?path=spaceshooterdata_starfield.bundle`

または、エントリーのコンテンツをエントリー ID で取得するには、以下のように入力します。

`https://<project_guid>.client-api.unity3dusercontent.com/client_api/v1/buckets/aee9ee5f-fa01-46d3-a293-731d15f066cf/release_by_badge/my_first_badge/entries/8ac46783-be01-4a47-b23e-74233fc7cc09/content/`
