GS2-Account GS2-Deploy/CDK リファレンス

エンティティ

Namespace

ネームスペース

ネームスペースは一つのプロジェクトで同じサービスを異なる用途で複数利用できるようにするための仕組みです。
GS2 のサービスは基本的にネームスペースというレイヤーがあり、ネームスペースが異なれば同じサービスでもまったく別のデータ空間として取り扱われます。

そのため、各サービスの利用を開始するにあたってネームスペースを作成する必要があります。

必須デフォルト値の制限説明
namestring~ 128文字ネームスペース名
descriptionstring~ 1024文字説明文
changePasswordIfTakeOverboolfalseアカウント引き継ぎ時にパスワードを変更するか
differentUserIdForLoginAndDataRetentionboolfalseログインに使用するユーザーIDとデータの保持に使用するユーザーIDを異なるものにする
createAccountScriptScriptSettingアカウント新規作成したときに実行するスクリプト
authenticationScriptScriptSetting認証したときに実行するスクリプト
createTakeOverScriptScriptSetting引き継ぎ情報登録したときに実行するスクリプト
doTakeOverScriptScriptSetting引き継ぎ実行したときに実行するスクリプト
logSettingLogSettingログの出力設定

GetAttr

説明
ItemNamespace作成したネームスペース

実装例

Type: GS2::Account::Namespace
Properties:
  Name: namespace1
  Description: null
  ChangePasswordIfTakeOver: false
  DifferentUserIdForLoginAndDataRetention: null
  CreateAccountScript: null
  AuthenticationScript: null
  CreateTakeOverScript: null
  DoTakeOverScript: null
  LogSetting: 
    LoggingNamespaceId: grn:gs2:ap-northeast-1:YourOwnerId:log:namespace1
from gs2_cdk import Stack, core, account

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        account.Namespace(
            stack=self,
            name="namespace-0001",
            options=account.NamespaceOptions(
                change_password_if_take_over=False,
                log_setting=core.LogSetting(
                    logging_namespace_id='grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001',
                ),
            ),
        )

print(SampleStack().yaml())  # Generate Template
class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
    function __construct() {
        parent::__construct();
        new \Gs2Cdk\Account\Model\Namespace_(
            stack: $this,
            name: "namespace-0001",
            options: new \Gs2Cdk\Account\Model\Options\NamespaceOptions(
                changePasswordIfTakeOver: False,
                logSetting: new \Gs2Cdk\Core\Model\LogSetting(
                    loggingNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                )
            )
        );
    }
}

print((new SampleStack())->yaml());  // Generate Template
class SampleStack extends io.gs2.cdk.core.model.Stack
{
    public SampleStack() {
        super();
        new io.gs2.cdk.account.model.Namespace(
            this,
            "namespace-0001",
            new io.gs2.cdk.account.model.options.NamespaceOptions() {
                {
                    changePasswordIfTakeOver = false;
                    logSetting = new io.gs2.cdk.core.model.LogSetting(
                        loggingNamespaceId = "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                    );
                }
            }
        );
    }
}

System.out.println(new SampleStack().yaml());  // Generate Template
import core from "@/gs2cdk/core";
import account from "@/gs2cdk/account";

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new account.model.Namespace(
            this,
            "namespace-0001",
            {
                changePasswordIfTakeOver: false,
                logSetting: new core.LogSetting(
                    "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                )
            }
        );
    }
}

console.log(new SampleStack().yaml());  // Generate Template
public class SampleStack : Gs2Cdk.Core.Model.Stack
{
    public SampleStack() {
        new Gs2Cdk.Gs2Account.Model.Namespace(
            this,
            "namespace-0001",
            new Gs2Cdk.Gs2Account.Model.Options.NamespaceOptions {
                changePasswordIfTakeOver = false,
                logSetting = new Gs2Cdk.Core.Model.LogSetting(
                    LoggingNamespaceId = "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                )
            }
        );
    }
}

Debug.Log(new SampleStack().Yaml());  // Generate Template

Account

ゲームプレイヤーアカウント

ゲームプレイヤーを識別するID情報のエンティティです。
ゲームプレイヤーアカウントは匿名アカウントであり、ユーザーID(UUID)とパスワード(ランダムな32文字の文字列)で構成されるため、ゲームプレイヤーはメールアドレスなどの情報を入力する必要はありません。

発行されたゲームプレイヤーアカウントは、デバイスのローカルストレージに保存しておき、次回以降ログインに使用します。

必須デフォルト値の制限説明
namespaceNamestring~ 128文字ネームスペース名

GetAttr

説明
ItemAccount作成したゲームプレイヤーアカウント

実装例

Type: GS2::Account::Account
Properties:
  NamespaceName: namespace1
from gs2_cdk import Stack, core, account

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        account.Account(
            stack=self,
            namespace_name="namespace-0001",
        )

print(SampleStack().yaml())  # Generate Template
class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
    function __construct() {
        parent::__construct();
        new \Gs2Cdk\Account\Model\Account(
            stack: $this,
            namespaceName: "namespace-0001"
        );
    }
}

print((new SampleStack())->yaml());  // Generate Template
class SampleStack extends io.gs2.cdk.core.model.Stack
{
    public SampleStack() {
        super();
        new io.gs2.cdk.account.model.Account(
            this,
            "namespace-0001"
        );
    }
}

System.out.println(new SampleStack().yaml());  // Generate Template
import core from "@/gs2cdk/core";
import account from "@/gs2cdk/account";

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new account.model.Account(
            this,
            "namespace-0001"
        );
    }
}

console.log(new SampleStack().yaml());  // Generate Template
public class SampleStack : Gs2Cdk.Core.Model.Stack
{
    public SampleStack() {
        new Gs2Cdk.Gs2Account.Model.Account(
            this,
            "namespace-0001"
        );
    }
}

Debug.Log(new SampleStack().Yaml());  // Generate Template

CurrentModelMaster

現在有効なマスターデータ

GS2ではマスターデータの管理にJSON形式のファイルを使用します。
ファイルをアップロードすることで、実際にサーバーに設定を反映することができます。

JSONファイルを作成する方法として、マネージメントコンソール上でのマスターデータエディタを提供していますが
よりゲームの運営に相応しいツールを作成し、適切なフォーマットのJSONファイルを書き出すことでもサービスを利用可能です。

必須デフォルト値の制限説明
namespaceNamestring~ 128文字ネームスペース名
settingsstring~ 5242880文字マスターデータ

GetAttr

説明
ItemCurrentModelMaster更新した現在有効なエントリー設定

実装例

Type: GS2::Account::CurrentModelMaster
Properties:
  NamespaceName: namespace1
  Settings: {
    "version": "2024-07-30",
    "takeOverTypeModels": [
      {
        "openIdConnectSetting":
          {
            "configurationPath": "https://accounts.google.com/.well-known/openid-configuration",
            "clientId": "695893071400-qelt0dsu8tkotl13psnq5d1ko7kki4sl.apps.googleusercontent.com",
            "clientSecret": "secret"
          },
        "metadata": "Google"
      },
      {
        "type": 1,
        "openIdConnectSetting":
          {
            "configurationPath": "https://appleid.apple.com/.well-known/openid-configuration",
            "clientId": "io.gs2.sample.auth",
            "appleTeamId": "9LX9LA85H8",
            "appleKeyId": "P937MLY6Z7",
            "applePrivateKeyPem": "-----BEGIN PRIVATE KEY-----\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n-----END PRIVATE KEY-----"
          },
        "metadata": "Apple"
      }
    ]
  }
from gs2_cdk import Stack, core, account

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        account.Namespace(
            stack=self,
            # 省略
        ).master_data(
            take_over_type_models=[
                account.TakeOverTypeModel(
                    open_id_connect_setting=account.OpenIdConnectSetting(
                            configuration_path='https://accounts.google.com/.well-known/openid-configuration',
                            client_id='695893071400-qelt0dsu8tkotl13psnq5d1ko7kki4sl.apps.googleusercontent.com',
                            client_secret='secret'
                        ),
                    options=account.TakeOverTypeModelOptions(
                        metadata='Google',
                    ),
                ),
                account.TakeOverTypeModel(
                    type=1,
                    open_id_connect_setting=account.OpenIdConnectSetting(
                            configuration_path='https://appleid.apple.com/.well-known/openid-configuration',
                            client_id='io.gs2.sample.auth',
                            apple_team_id='9LX9LA85H8',
                            apple_key_id='P937MLY6Z7',
                            apple_private_key_pem='-----BEGIN PRIVATE KEY-----\\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\n-----END PRIVATE KEY-----'
                        ),
                    options=account.TakeOverTypeModelOptions(
                        metadata='Apple',
                    ),
                ),
            ],
        )

print(SampleStack().yaml())  # Generate Template
class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
    function __construct() {
        parent::__construct();
        (new \Gs2Cdk\Account\Model\Namespace_(
            stack: $this,
            // 省略
        ))->masterData(
            [
                new \Gs2Cdk\Account\Model\TakeOverTypeModel(
                    openIdConnectSetting:new \Gs2Cdk\Account\Model\OpenIdConnectSetting(
                        configurationPath: "https://accounts.google.com/.well-known/openid-configuration",
                        clientId: "695893071400-qelt0dsu8tkotl13psnq5d1ko7kki4sl.apps.googleusercontent.com",
                        clientSecret: "secret"
                    ),
                    options: new \Gs2Cdk\Account\Model\Options\TakeOverTypeModelOptions(
                        metadata:"Google"
                    )
                ),
                new \Gs2Cdk\Account\Model\TakeOverTypeModel(
                    type:1,
                    openIdConnectSetting:new \Gs2Cdk\Account\Model\OpenIdConnectSetting(
                        configurationPath: "https://appleid.apple.com/.well-known/openid-configuration",
                        clientId: "io.gs2.sample.auth",
                        appleTeamId: "9LX9LA85H8",
                        appleKeyId: "P937MLY6Z7",
                        applePrivateKeyPem: "-----BEGIN PRIVATE KEY-----\\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\n-----END PRIVATE KEY-----"
                    ),
                    options: new \Gs2Cdk\Account\Model\Options\TakeOverTypeModelOptions(
                        metadata:"Apple"
                    )
                )
            ]
        );
    }
}

print((new SampleStack())->yaml());  // Generate Template
class SampleStack extends io.gs2.cdk.core.model.Stack
{
    public SampleStack() {
        super();
        new io.gs2.cdk.account.model.Namespace(
            this,
            // 省略
        ).masterData(
            Arrays.asList(
                new io.gs2.cdk.account.model.TakeOverTypeModel(
                    new io.gs2.cdk.account.model.OpenIdConnectSetting(
                        "https://accounts.google.com/.well-known/openid-configuration",
                        "695893071400-qelt0dsu8tkotl13psnq5d1ko7kki4sl.apps.googleusercontent.com",
                        "secret"
                    ),
                    new io.gs2.cdk.account.model.options.TakeOverTypeModelOptions() {
                        {
                            metadata: "Google";
                        }
                    }
                ),
                new io.gs2.cdk.account.model.TakeOverTypeModel(
                    1,
                    new io.gs2.cdk.account.model.OpenIdConnectSetting(
                        "https://appleid.apple.com/.well-known/openid-configuration",
                        "io.gs2.sample.auth",
                        "9LX9LA85H8",
                        "P937MLY6Z7",
                        "-----BEGIN PRIVATE KEY-----\\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\n-----END PRIVATE KEY-----"
                    ),
                    new io.gs2.cdk.account.model.options.TakeOverTypeModelOptions() {
                        {
                            metadata: "Apple";
                        }
                    }
                )
            )
        );
    }
}

System.out.println(new SampleStack().yaml());  // Generate Template
import core from "@/gs2cdk/core";
import account from "@/gs2cdk/account";

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new account.model.Namespace(
            this,
            // 省略
        ).masterData(
            [
                new account.model.TakeOverTypeModel(
                    new account.model.OpenIdConnectSetting(
                        "https://accounts.google.com/.well-known/openid-configuration",
                        "695893071400-qelt0dsu8tkotl13psnq5d1ko7kki4sl.apps.googleusercontent.com",
                        "secret"
                    ),
                    {
                        metadata: "Google"
                    }
                ),
                new account.model.TakeOverTypeModel(
                    1,
                    new account.model.OpenIdConnectSetting(
                        "https://appleid.apple.com/.well-known/openid-configuration",
                        "io.gs2.sample.auth",
                        "9LX9LA85H8",
                        "P937MLY6Z7",
                        "-----BEGIN PRIVATE KEY-----\\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\n-----END PRIVATE KEY-----"
                    ),
                    {
                        metadata: "Apple"
                    }
                )
            ]
        );
    }
}

console.log(new SampleStack().yaml());  // Generate Template
public class SampleStack : Gs2Cdk.Core.Model.Stack
{
    public SampleStack() {
        new Gs2Cdk.Gs2Account.Model.Namespace(
            this,
            // 省略
        ).MasterData(
            new [] {
                new Gs2Cdk.Gs2Account.Model.TakeOverTypeModel(
                    new Gs2Cdk.Gs2Account.Model.OpenIdConnectSetting(
                        configurationPath: "https://accounts.google.com/.well-known/openid-configuration",
                        clientId: "695893071400-qelt0dsu8tkotl13psnq5d1ko7kki4sl.apps.googleusercontent.com",
                        clientSecret: "secret"
                    ),
                    new Gs2Cdk.Gs2Account.Model.Options.TakeOverTypeModelOptions {
                        metadata = "Google"
                    }
                ),
                new Gs2Cdk.Gs2Account.Model.TakeOverTypeModel(
                    1,
                    new Gs2Cdk.Gs2Account.Model.OpenIdConnectSetting(
                        configurationPath: "https://appleid.apple.com/.well-known/openid-configuration",
                        clientId: "io.gs2.sample.auth",
                        appleTeamId: "9LX9LA85H8",
                        appleKeyId: "P937MLY6Z7",
                        applePrivateKeyPem: "-----BEGIN PRIVATE KEY-----\\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\n-----END PRIVATE KEY-----"
                    ),
                    new Gs2Cdk.Gs2Account.Model.Options.TakeOverTypeModelOptions {
                        metadata = "Apple"
                    }
                )
            }
        );
    }
}

Debug.Log(new SampleStack().Yaml());  // Generate Template

OpenIdConnectSetting

OpenID Connect の設定

必須デフォルト値の制限説明
configurationPathstring~ 1024文字Open ID Connect 設定 URL
clientIdstring~ 1024文字クライアントID
clientSecretstring{configurationPath} != “https://appleid.apple.com/.well-known/openid-configuration”~ 1024文字クライアントシークレット
appleTeamIdstring{configurationPath} == “https://appleid.apple.com/.well-known/openid-configuration”~ 1024文字Apple Developer チームID
appleKeyIdstring{configurationPath} == “https://appleid.apple.com/.well-known/openid-configuration”~ 1024文字Apple に登録済みのキーID
applePrivateKeyPemstring{configurationPath} == “https://appleid.apple.com/.well-known/openid-configuration”~ 10240文字Apple から受け取った秘密鍵

PlatformUser

各種プラットフォームにおけるユーザー情報

必須デフォルト値の制限説明
typeint~ 1024スロット番号
userIdentifierstring~ 1024文字各種プラットフォームにおけるユーザーID
userIdstring~ 128文字ユーザーID

GitHubCheckoutSetting

GitHubからマスターデータをチェックアウトする設定

必須デフォルト値の制限説明
apiKeyIdstring~ 1024文字GitHub のAPIキーGRN
repositoryNamestring~ 1024文字リポジトリ名
sourcePathstring~ 1024文字ソースコードのファイルパス
referenceTypeenum {
    “commit_hash”,
    “branch”,
    “tag”
}
~ 128文字コードの取得元
commitHashstring{referenceType} == “commit_hash”~ 1024文字コミットハッシュ
branchNamestring{referenceType} == “branch”~ 1024文字ブランチ名
tagNamestring{referenceType} == “tag”~ 1024文字タグ名

referenceType に指定する列挙型の定義

定義説明
commit_hashコミットハッシュ
branchブランチ
tagタグ

ScriptSetting

スクリプト設定

GS2 ではマイクロサービスのイベントに関連づけて、カスタムスクリプトを実行することができます。
このモデルは、スクリプトの実行をトリガーするための設定を保持します。

スクリプトの実行方式は大きく2種類あり、それは「同期実行」と「非同期実行」です。
同期実行は、スクリプトの実行が完了するまで処理がブロックされます。
かわりに、スクリプトの実行結果を使ってAPIの実行を止めたり、APIの結果を改ざんすることができます。

一方、非同期実行は、スクリプトの実行が完了するまで処理がブロックされません。
かわりに、スクリプトの実行結果を使ってAPIの実行を止めたり、APIの結果を改ざんすることはできません。
しかし、非同期実行は、スクリプトの実行が完了するまで処理がブロックされないため、APIの応答に影響を与えないため、原則非同期実行を使用することをおすすめします。

非同期実行には実行方式が2種類あり、GS2-Script と Amazon EventBridge があります。
Amazon EventBridge を使用することで、Lua 以外の言語で処理を記述することができます。

必須デフォルト値の制限説明
triggerScriptIdstring~ 1024文字同期実行スクリプトの GS2-Script のスクリプトGRN
doneTriggerTargetTypeenum {
    “none”,
    “gs2_script”,
    “aws”
}
“none”~ 128文字非同期スクリプトの実行方法
doneTriggerScriptIdstring{doneTriggerTargetType} == “gs2_script”~ 1024文字非同期実行スクリプトの GS2-Script のスクリプトGRN
doneTriggerQueueNamespaceIdstring{doneTriggerTargetType} == “gs2_script”~ 1024文字非同期実行スクリプトを実行する GS2-JobQueue ネームスペース

doneTriggerTargetType に指定する列挙型の定義

定義説明
noneなし
gs2_scriptGS2-Script
awsAmazon EventBridge

LogSetting

ログの書き出し設定

ログデータの書き出し設定を管理します。この型は、ログデータを書き出すために使用されるログ名前空間の識別子(Namespace ID)を保持します。
ログ名前空間IDは、ログデータを集約し、保存する対象の GS2-Log の名前空間を指定します。
この設定を通じて、この名前空間以下のAPIリクエスト・レスポンスログデータが対象の GS2-Log へ出力されるようになります。
GS2-Log にはリアルタイムでログが提供され、システムの監視や分析、デバッグなどに利用できます。

必須デフォルト値の制限説明
loggingNamespaceIdstring~ 1024文字ネームスペースGRN