Skip to content

Commit

Permalink
ClientEncryption: Adds support for preview and non-preview version of…
Browse files Browse the repository at this point in the history
… Cosmos SDK in Encryption package. (Azure#3070)

Adds support for both preview and non-preview version of Cosmos SDK in Encryption package and adds the pipeline to build the preview and non preview nuget packages.
  • Loading branch information
kr-santosh authored Mar 22, 2022
1 parent 07cca6e commit 79fb98f
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 67 deletions.
6 changes: 4 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
<ClientPreviewVersion>3.26.0</ClientPreviewVersion>
<ClientPreviewSuffixVersion>preview</ClientPreviewSuffixVersion>
<DirectVersion>3.24.1</DirectVersion>
<EncryptionVersion>1.0.0-previewV20</EncryptionVersion>
<EncryptionOfficialVersion>1.0.0</EncryptionOfficialVersion>
<EncryptionPreviewVersion>1.0.0</EncryptionPreviewVersion>
<EncryptionPreviewSuffixVersion>preview20</EncryptionPreviewSuffixVersion>
<CustomEncryptionVersion>1.0.0-preview02</CustomEncryptionVersion>
<HybridRowVersion>1.1.0-preview3</HybridRowVersion>
<LangVersion>9.0</LangVersion>
<AboveDirBuildProps>$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))</AboveDirBuildProps>
<DefineConstants Condition=" '$(IsNightly)' == 'true' or '$(IsPreview)' == 'true' ">$(DefineConstants);PREVIEW</DefineConstants>
<DefineConstants Condition=" '$(IsNightly)' == 'true' or '$(IsPreview)' == 'true' ">$(DefineConstants);PREVIEW;ENCRYPTIONPREVIEW</DefineConstants>
</PropertyGroup>
<Import Project="$(AboveDirBuildProps)" Condition=" '$(AboveDirBuildProps)' != '' " />
</Project>
104 changes: 53 additions & 51 deletions Microsoft.Azure.Cosmos.Encryption/src/EncryptionContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,46 +454,6 @@ public override Task<IReadOnlyList<FeedRange>> GetFeedRangesAsync(
return this.container.GetFeedRangesAsync(cancellationToken);
}

public override Task<IEnumerable<string>> GetPartitionKeyRangesAsync(
FeedRange feedRange,
CancellationToken cancellationToken = default)
{
return this.container.GetPartitionKeyRangesAsync(feedRange, cancellationToken);
}

public override FeedIterator GetItemQueryStreamIterator(
FeedRange feedRange,
QueryDefinition queryDefinition,
string continuationToken,
QueryRequestOptions requestOptions = null)
{
QueryRequestOptions clonedRequestOptions = requestOptions != null ? (QueryRequestOptions)requestOptions.ShallowCopy() : new QueryRequestOptions();

return new EncryptionFeedIterator(
this.container.GetItemQueryStreamIterator(
feedRange,
queryDefinition,
continuationToken,
clonedRequestOptions),
this,
clonedRequestOptions);
}

public override FeedIterator<T> GetItemQueryIterator<T>(
FeedRange feedRange,
QueryDefinition queryDefinition,
string continuationToken = null,
QueryRequestOptions requestOptions = null)
{
return new EncryptionFeedIterator<T>(
(EncryptionFeedIterator)this.GetItemQueryStreamIterator(
feedRange,
queryDefinition,
continuationToken,
requestOptions),
this.ResponseFactory);
}

public override ChangeFeedEstimator GetChangeFeedEstimator(
string processorName,
Container leaseContainer)
Expand Down Expand Up @@ -719,17 +679,6 @@ public override async Task<FeedResponse<T>> ReadManyItemsAsync<T>(
return this.ResponseFactory.CreateItemFeedResponse<T>(responseMessage);
}

public override Task<ResponseMessage> DeleteAllItemsByPartitionKeyStreamAsync(
Cosmos.PartitionKey partitionKey,
RequestOptions requestOptions = null,
CancellationToken cancellationToken = default)
{
return this.container.DeleteAllItemsByPartitionKeyStreamAsync(
partitionKey,
requestOptions,
cancellationToken);
}

public async Task<EncryptionSettings> GetOrUpdateEncryptionSettingsFromCacheAsync(
EncryptionSettings obsoleteEncryptionSettings,
CancellationToken cancellationToken)
Expand All @@ -741,6 +690,59 @@ public async Task<EncryptionSettings> GetOrUpdateEncryptionSettingsFromCacheAsyn
cancellationToken: cancellationToken);
}

public override FeedIterator GetItemQueryStreamIterator(
FeedRange feedRange,
QueryDefinition queryDefinition,
string continuationToken,
QueryRequestOptions requestOptions = null)
{
QueryRequestOptions clonedRequestOptions = requestOptions != null ? (QueryRequestOptions)requestOptions.ShallowCopy() : new QueryRequestOptions();

return new EncryptionFeedIterator(
this.container.GetItemQueryStreamIterator(
feedRange,
queryDefinition,
continuationToken,
clonedRequestOptions),
this,
clonedRequestOptions);
}

public override FeedIterator<T> GetItemQueryIterator<T>(
FeedRange feedRange,
QueryDefinition queryDefinition,
string continuationToken = null,
QueryRequestOptions requestOptions = null)
{
return new EncryptionFeedIterator<T>(
(EncryptionFeedIterator)this.GetItemQueryStreamIterator(
feedRange,
queryDefinition,
continuationToken,
requestOptions),
this.ResponseFactory);
}

#if ENCRYPTIONPREVIEW
public override Task<ResponseMessage> DeleteAllItemsByPartitionKeyStreamAsync(
Cosmos.PartitionKey partitionKey,
RequestOptions requestOptions = null,
CancellationToken cancellationToken = default)
{
return this.container.DeleteAllItemsByPartitionKeyStreamAsync(
partitionKey,
requestOptions,
cancellationToken);
}

public override Task<IEnumerable<string>> GetPartitionKeyRangesAsync(
FeedRange feedRange,
CancellationToken cancellationToken = default)
{
return this.container.GetPartitionKeyRangesAsync(feedRange, cancellationToken);
}
#endif

/// <summary>
/// This function handles the scenario where a container is deleted(say from different Client) and recreated with same Id but with different client encryption policy.
/// The idea is to have the container Rid cached and sent out as part of RequestOptions with Container Rid set in "x-ms-cosmos-intended-collection-rid" header.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
<AssemblyName>Microsoft.Azure.Cosmos.Encryption</AssemblyName>
<RootNamespace>Microsoft.Azure.Cosmos.Encryption</RootNamespace>
<LangVersion>$(LangVersion)</LangVersion>
<IsPreview>true</IsPreview>

<EncryptionVersion Condition=" '$(IsPreview)' != 'true' ">$(EncryptionOfficialVersion)</EncryptionVersion>
<EncryptionVersion Condition=" '$(IsPreview)' == 'true' ">$(EncryptionPreviewVersion)</EncryptionVersion>
<EncryptionVersionSuffix Condition=" '$(IsPreview)' == 'true' ">$(EncryptionPreviewSuffixVersion)</EncryptionVersionSuffix>
<Version Condition=" '$(EncryptionVersionSuffix)' == '' ">$(EncryptionVersion)</Version>
<Version Condition=" '$(EncryptionVersionSuffix)' != '' ">$(EncryptionVersion)-$(EncryptionVersionSuffix)</Version>
<CurrentDate>$([System.DateTime]::Now.ToString(yyyyMMdd))</CurrentDate>
<Version>$(EncryptionVersion)</Version>
<Company>Microsoft Corporation</Company>
<Authors>Microsoft</Authors>
<Description>This library provides an implementation for client-side encryption for Azure Cosmos's SQL API. For more information, refer to https://aka.ms/CosmosClientEncryption</Description>
Expand All @@ -18,23 +20,28 @@
<PackageLicenseUrl>https://aka.ms/netcoregaeula</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/Azure/azure-cosmos-dotnet-v3</PackageProjectUrl>
<PackageIconUrl>http://go.microsoft.com/fwlink/?LinkID=288890</PackageIconUrl>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<PackageTags>microsoft;azure;cosmos;cosmosdb;documentdb;docdb;nosql;azureofficial;dotnetcore;netcore;netstandard;client;encryption;byok</PackageTags>
</PropertyGroup>
<ItemGroup>
<AdditionalFiles Include="..\..\Microsoft.Azure.Cosmos\src\stylecop.json" Link="stylecop.json" />
</ItemGroup>

<ItemGroup Condition=" '$(SdkProjectRef)' != 'True' ">
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.26.0-preview" />
</ItemGroup>
<ItemGroup Condition=" '$(SdkProjectRef)' != 'True' AND '$(IsPreview)' != 'True' ">
<PackageReference Include="Microsoft.Azure.Cosmos" Version="[3.26.0,3.27)" />
</ItemGroup>

<ItemGroup Condition=" '$(SdkProjectRef)' != 'True' AND '$(IsPreview)' == 'True' ">
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.26.0-preview" />
</ItemGroup>

<ItemGroup Condition=" '$(SdkProjectRef)' == 'True' ">
<ProjectReference Include="..\..\Microsoft.Azure.Cosmos\src\Microsoft.Azure.Cosmos.csproj" />
</ItemGroup>

<ItemGroup Condition=" '$(SdkProjectRef)' == 'True' ">
<ProjectReference Include="..\..\Microsoft.Azure.Cosmos\src\Microsoft.Azure.Cosmos.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Azure.Core" Version="1.19.0" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageReference Include="Azure.Core" Version="1.19.0" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
</ItemGroup>

<ItemGroup>
Expand All @@ -53,14 +60,13 @@
<ItemGroup>
<PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
</ItemGroup>

<PropertyGroup>
<SigningType>Product</SigningType>
<SignAssembly>true</SignAssembly>
<DelaySign>true</DelaySign>
<AssemblyOriginatorKeyFile>..\..\35MSSharedLib1024.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<PropertyGroup Condition=" '$(SdkProjectRef)' == 'True' ">
<DefineConstants>$(DefineConstants);SDKPROJECTREF</DefineConstants>
</PropertyGroup>
Expand Down

0 comments on commit 79fb98f

Please sign in to comment.