앞에서 설명한 것처럼 정책 SDK의 기본 함수는 다음과 같습니다.
- 사용 가능한 레이블 나열
- 현재 상태와 원하는 상태에 따라 애플리케이션에서 수행해야 하는 작업 집합을 반환합니다.
프로세스의 마지막 단계는 레이블 식별자 및 필요에 따라 기존 레이블에 대한 메타데이터를 함수에 제공하는 것입니다 ComputeActions() .
이 문서의 샘플 코드는 GitHub 사용할 수 있습니다.
새 레이블에 대한 작업 계산
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);
actions의 일부로 반환된 mip::MetadataActions만 작성하면 다음이 표시됩니다:
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::vectormip::Action반환합니다. 이 메타데이터를 파일 또는 데이터에 적용하는 것은 애플리케이션 개발자의 달려 있습니다.
비고
앞의 예제에서는 출력만 표시합니다 mip::MetadataAction . 다른 작업 유형을 표시하는 예제는 정책 SDK 다운로드가 포함된 샘플 번들을 참조하세요.
기존 레이블을 사용하여 작업 계산
정책 SDK를 사용하는 경우 애플리케이션은 콘텐츠에서 메타데이터를 읽습니다. 애플리케이션은 이 메타데이터를 API의 일부로 mip::ExecutionState제공합니다.
ComputeActions() 는 레이블이 지정되지 않은 문서에 새 레이블을 적용하는 것보다 더 복잡한 작업을 처리할 수 있습니다. 다음 예제에서는 레이블을 더 중요한 레이블에서 덜 중요한 레이블로 다운그레이드하는 방법을 보여 줍니다. 샘플은 쉼표로 구분된 메타데이터 문자열을 읽고 이를 통해 API mip::ExecutionState에 제공하여 이 프로세스를 시뮬레이션합니다.
비고
이 샘플에서는 .라는 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