前述のように、Policy SDK の主な機能は次のとおりです。
- 使用可能なラベルを一覧表示する
- は、現在の状態と目的の状態に基づいて、アプリケーションが実行する必要がある一連のアクションを返します
プロセスの最後の手順では、ラベル識別子と、必要に応じて、既存のラベルに関するメタデータを ComputeActions() 関数に提供します。
この記事のサンプル コードは、GitHubで入手できます。
新しいラベルのアクションを計算する
ExecutionState で定義されているExecutionStateImplを使用して、新しいラベルのmip::Actionsを計算します。
// Replace with valid label ID.
string newLabelId = "d7b93a40-4df3-47e4-b2fd-7862fc6b095c";
sample::upe::ExecutionStateOptions options;
// Resolve desired label id to mip::Label and set in ExecutionStateOptions.
options.newLabel = mEngine->GetLabelById(newLabelId);
// Initialize ExecutionStateImpl with options, create handler, call ComputeActions.
std::unique_ptr<ExecutionStateImpl> state(new ExecutionStateImpl(options));
auto handler = mEngine->CreatePolicyHandler(false); // Don't generate audit event.
auto actions = handler->ComputeActions(*state);
mip::MetadataActions の一部として返される actions のみを記述すると、次のように表示されます:
Add: MSIP_Label_d7b93a40-4df3-47e4-b2fd-7862fc6b095c_Enabled : true
Add: MSIP_Label_d7b93a40-4df3-47e4-b2fd-7862fc6b095c_SetDate : 2018-10-23T20:39:06-0800
Add: MSIP_Label_d7b93a40-4df3-47e4-b2fd-7862fc6b095c_Method : Standard
Add: MSIP_Label_d7b93a40-4df3-47e4-b2fd-7862fc6b095c_Name : Contoso FTEs (C)
Add: MSIP_Label_d7b93a40-4df3-47e4-b2fd-7862fc6b095c_SiteId : 94f6984e-8d31-4794-bdeb-3ac89ad2b660
Add: MSIP_Label_d7b93a40-4df3-47e4-b2fd-7862fc6b095c_ActionId : 2266fbe8-a0d9-44e8-bad8-00008f2a0915
Add: MSIP_Label_d7b93a40-4df3-47e4-b2fd-7862fc6b095c_ContentBits : 3
PolicyHandlerはアクションを計算し、std::vectorのmip::Actionを返します。 このメタデータをファイルまたはデータに適用するのは、アプリケーション開発者が行う必要があります。
注
前の例では、 mip::MetadataAction 出力のみが表示されます。 他のアクションの種類を表示する例については、 ポリシー SDK のダウンロードを含むサンプル バンドルを参照してください。
既存のラベルを使用してアクションを計算する
Policy SDK を使用すると、アプリケーションはコンテンツからメタデータを読み取ります。 アプリケーションは、このメタデータを mip::ExecutionStateの一部として API に提供します。
ComputeActions() では、ラベル付けされていないドキュメントに新しいラベルを適用するよりも複雑な操作を処理できます。 次の例では、ラベルをより機密性の高いラベルから機密性の低いラベルにダウングレードする方法を示します。 このサンプルでは、メタデータのコンマ区切りの文字列を読み取り、 mip::ExecutionStateを介して API に提供することで、このプロセスをシミュレートします。
注
このサンプルでは、 SplitString() というユーティリティ関数を使用します。 例については、 SplitString() ユーティリティ関数ソースを参照してください。
// Replace with valid label ID.
string newLabelId = "d7b93a40-4df3-47e4-b2fd-7862fc6b095c";
// Comma and Pipe Delimited Metadata.
string metadata = "MSIP_Label_d7b93a40-4df3-47e4-b2fd-7862fc6b095c_Enabled|true,MSIP_Label_d7b93a40-4df3-47e4-b2fd-7862fc6b095c_SetDate|2018-10-23T21:53:31-0800,MSIP_Label_d7b93a40-4df3-47e4-b2fd-7862fc6b095c_Method|Standard,MSIP_Label_d7b93a40-4df3-47e4-b2fd-7862fc6b095c_Name|Contoso FTEs (C),MSIP_Label_d7b93a40-4df3-47e4-b2fd-7862fc6b095c_SiteId|94f6984e-8d31-4794-bdeb-3ac89ad2b660,MSIP_Label_d7b93a40-4df3-47e4-b2fd-7862fc6b095c_ActionId|b56491d9-155f-40ff-866f-0000acd85c31,MSIP_Label_d7b93a40-4df3-47e4-b2fd-7862fc6b095c_ContentBits|7";
// Create ExecutionStateOptions and resolve newLabelId to mip::Label
sample::upe::ExecutionStateOptions options;
options.newLabel = mEngine->GetLabelById(newLabelId);
// Split metadata string by commas, store in vector.
vector<string> metadataPairs = sample::utils::SplitString(metadata, ',');
// Iterate through each string, splitting by the pipe.
// Add each key/value pair to ExecutionStateOptions metadata.
for (const string& metadataPair : metadataPairs) {
vector<string> keyValue = sample::utils::SplitString(metadataPair, '|');
options.metadata[keyValue[0]] = keyValue[1];
}
// Initialize ExecutionStateImpl with options, create handler, call ComputeActions
std::unique_ptr<ExecutionStateImpl> state(new ExecutionStateImpl(options));
auto handler = mEngine->CreatePolicyHandler(false); // Don't generate audit event.
auto actions = handler->ComputeActions(*state);
前の例では、いくつかのアクションが発生する可能性があります。 これらのアクションは、入力として提供されるラベルとラベルの構成によって異なります。 少なくとも、結果は、GetMetadataToRemove()で削除するデータと、GetMetadataToAdd()を介して追加するデータを含む単一のmip::MetadataActionです。
Add: MSIP_Label_d48d0e60-c766-40d6-96d3-53b2857fe775_Enabled : true
Add: MSIP_Label_d48d0e60-c766-40d6-96d3-53b2857fe775_SetDate : 2018-10-23T23:59:41-0800
Add: MSIP_Label_d48d0e60-c766-40d6-96d3-53b2857fe775_Method : Standard
Add: MSIP_Label_d48d0e60-c766-40d6-96d3-53b2857fe775_Name : General
Add: MSIP_Label_d48d0e60-c766-40d6-96d3-53b2857fe775_SiteId : 94f6984e-8d31-4794-bdeb-3ac89ad2b660
Add: MSIP_Label_d48d0e60-c766-40d6-96d3-53b2857fe775_ActionId : 447a996b-28ea-482c-b0b5-000075bd4bb3
Add: MSIP_Label_d48d0e60-c766-40d6-96d3-53b2857fe775_ContentBits : 7
Remove: MSIP_Label_d7b93a40-4df3-47e4-b2fd-7862fc6b095c_Name
Remove: MSIP_Label_d7b93a40-4df3-47e4-b2fd-7862fc6b095c_Enabled
Remove: MSIP_Label_d7b93a40-4df3-47e4-b2fd-7862fc6b095c_SiteId
Remove: MSIP_Label_d7b93a40-4df3-47e4-b2fd-7862fc6b095c_SetDate
Remove: MSIP_Label_d7b93a40-4df3-47e4-b2fd-7862fc6b095c_Method
Remove: MSIP_Label_d7b93a40-4df3-47e4-b2fd-7862fc6b095c_ContentBits
Remove: MSIP_Label_d7b93a40-4df3-47e4-b2fd-7862fc6b095c_ActionId