diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..9897f1a --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Microsoft Azure + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 249ee9d..f7503b1 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,7 +1,15 @@ # Starter pipeline +- task: UseDotNet@2 +displayName: 'Install .NET Core SDK' + inputs: + version: '3.0.x' + packageType: runtime + - task: DotNetCoreCLI@2 inputs: command: 'build' + + - task: VSTest@2 inputs: testSelector: 'testAssemblies' @@ -16,7 +24,7 @@ # https://aka.ms/yaml trigger: -- main +- CosmosDB pool: vmImage: ubuntu-latest diff --git a/packages.config b/packages.config deleted file mode 100644 index f002542..0000000 --- a/packages.config +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/CosmosDB/test.snk b/sign.snk similarity index 100% rename from src/CosmosDB/test.snk rename to sign.snk diff --git a/src/CosmosDB/Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.csproj b/src/CosmosDB/Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.csproj index 4241546..5cefeb6 100644 --- a/src/CosmosDB/Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.csproj +++ b/src/CosmosDB/Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.csproj @@ -4,22 +4,20 @@ netcoreapp3.1 true true - test.snk + ..\..\sign.snk - - - AnyCPU - - - + Always + + Always + diff --git a/src/CosmosDB/Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.sln b/src/CosmosDB/Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.sln deleted file mode 100644 index 7fc9616..0000000 --- a/src/CosmosDB/Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30503.244 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB", "Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.csproj", "{B58DD1C3-0141-41B6-B086-4F4745B04DFB}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {B58DD1C3-0141-41B6-B086-4F4745B04DFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B58DD1C3-0141-41B6-B086-4F4745B04DFB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B58DD1C3-0141-41B6-B086-4F4745B04DFB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B58DD1C3-0141-41B6-B086-4F4745B04DFB}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {BFBA28BE-9B3B-4E33-A597-C95445B11C87} - EndGlobalSection -EndGlobal diff --git a/src/CosmosDB/Providers/CosmosDbServiceOperationProvider.cs b/src/CosmosDB/Providers/CosmosDbServiceOperationProvider.cs index 8d45df9..235dad0 100644 --- a/src/CosmosDB/Providers/CosmosDbServiceOperationProvider.cs +++ b/src/CosmosDB/Providers/CosmosDbServiceOperationProvider.cs @@ -1,24 +1,23 @@ -using Microsoft.Azure.WebJobs.Description; -using Microsoft.Azure.WebJobs.Host.Config; -using Microsoft.Azure.Workflows.ServiceProviders.Abstractions; -using Microsoft.Azure.Workflows.ServiceProviders.WebJobs.Abstractions.Providers; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.WindowsAzure.ResourceStack.Common.Collections; -using Microsoft.WindowsAzure.ResourceStack.Common.Extensions; -using Microsoft.WindowsAzure.ResourceStack.Common.Storage.Cosmos; -using Microsoft.WindowsAzure.ResourceStack.Common.Swagger.Entities; -using Newtonsoft.Json.Linq; -using System; -using System.Collections.Generic; -using System.Threading.Tasks; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. namespace Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB { + using System; + using System.Collections.Generic; + using System.Threading.Tasks; + using Microsoft.Azure.Workflows.ServiceProviders.Abstractions; + using Microsoft.Azure.Workflows.ServiceProviders.WebJobs.Abstractions.Providers; + using Microsoft.WindowsAzure.ResourceStack.Common.Collections; + using Microsoft.WindowsAzure.ResourceStack.Common.Extensions; + using Microsoft.WindowsAzure.ResourceStack.Common.Swagger.Entities; + using Newtonsoft.Json.Linq; + /// - /// This is the main class where you define all the operations and apis. + /// This is the service operation provider class where you define all the operations and apis. /// - [ServiceOperationsProvider(Id = CosmosDbServiceOperationProvider.ServiceId, Name = CosmosDbServiceOperationProvider.ServiceName)] - public class CosmosDbServiceOperationProvider : IServiceOperationsTriggerProvider + [ServiceOperationsProvider(Id = CosmosDBServiceOperationProvider.ServiceId, Name = CosmosDBServiceOperationProvider.ServiceName)] + public class CosmosDBServiceOperationProvider : IServiceOperationsTriggerProvider { /// /// The service name. @@ -40,7 +39,10 @@ namespace Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB /// private readonly InsensitiveDictionary apiOperationsList; - public CosmosDbServiceOperationProvider() + /// + /// Constructor for Service operation provider. + /// + public CosmosDBServiceOperationProvider() { this.serviceOperationsList = new List(); this.apiOperationsList = new InsensitiveDictionary(); @@ -56,6 +58,12 @@ namespace Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB }); } + /// + /// Get binding connection information, needed for Azure function triggers. + /// + /// + /// + /// public string GetBindingConnectionInformation(string operationId, InsensitiveDictionary connectionParameters) { return ServiceOperationsProviderUtilities @@ -151,7 +159,7 @@ namespace Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB } }, { - "collectionName", new SwaggerSchema + "collectionName", new SwaggerSchema { Type = SwaggerSchemaType.String, Title = "collection name", @@ -159,7 +167,7 @@ namespace Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB } }, { - "connectionStringSetting", new SwaggerSchema + "connectionStringSetting", new SwaggerSchema { Type = SwaggerSchemaType.String, Title = "Connection String", @@ -192,19 +200,26 @@ namespace Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB return "cosmosDBTrigger"; } + /// + /// Get operations. + /// + /// Expand manifest generation. public IEnumerable GetOperations(bool expandManifest) { return expandManifest ? serviceOperationsList : GetApiOperations(); } /// - /// Gets the operations. + /// Gets the api operations. /// private IEnumerable GetApiOperations() { return this.apiOperationsList.Values; } + /// + /// Get service operation. + /// public ServiceOperationApi GetService() { return this.GetServiceOperationApi(); @@ -235,8 +250,8 @@ namespace Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB Properties = new ServiceOperationProperties { Api = this.GetServiceOperationApi().GetFlattenedApi(), - Summary = "receive document", - Description = "receive document", + Summary = "Receive document", + Description = "Receive document", Visibility = Visibility.Important, OperationType = OperationType.ServiceProvider, BrandColor = 0x1C3A56, @@ -261,7 +276,7 @@ namespace Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB BrandColor = 0xC4D5FF, Description = "Connect to Azure Cosmos db to receive document.", DisplayName = "Cosmos Db", - IconUri = new Uri("https://raw.githubusercontent.com/praveensri/LogicAppCustomConnector/main/ServiceProviders.CosmosDb.Extensions/icon.png"), + IconUri = new Uri("https://raw.githubusercontent.com/Azure//logicapps-connector-extensions/CosmosDB/src/CosmosDB/icon.png"), Capabilities = new ApiCapability[] { ApiCapability.Triggers }, ConnectionParameters = new ConnectionParameters { diff --git a/src/CosmosDB/Providers/CosmosDbServiceProvider.cs b/src/CosmosDB/Providers/CosmosDbServiceProvider.cs index c4a0e7d..a64c43d 100644 --- a/src/CosmosDB/Providers/CosmosDbServiceProvider.cs +++ b/src/CosmosDB/Providers/CosmosDbServiceProvider.cs @@ -1,34 +1,31 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -using Microsoft.Azure.Documents; -using Microsoft.Azure.WebJobs.Description; -using Microsoft.Azure.WebJobs.Host.Config; -using Microsoft.Azure.Workflows.ServiceProviders.Abstractions; -using Microsoft.WindowsAzure.ResourceStack.Common.Extensions; -using Microsoft.WindowsAzure.ResourceStack.Common.Json; -using Microsoft.WindowsAzure.ResourceStack.Common.Storage.Cosmos; -using Newtonsoft.Json.Linq; -using System; -using System.Collections.Generic; - namespace Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB { + using System.Collections.Generic; + using Microsoft.Azure.Documents; + using Microsoft.Azure.WebJobs.Description; + using Microsoft.Azure.WebJobs.Host.Config; + using Microsoft.Azure.Workflows.ServiceProviders.Abstractions; + using Microsoft.WindowsAzure.ResourceStack.Common.Json; + using Newtonsoft.Json.Linq; + /// /// Service Provider class which injects all the service operation provider.. /// - [Extension("CosmosDbServiceProvider", configurationSection: "CosmosDbServiceProvider")] - public class CosmosDbServiceProvider : IExtensionConfigProvider + [Extension("CosmosDBServiceProvider", configurationSection: "CosmosDBServiceProvider")] + public class CosmosDBServiceProvider : IExtensionConfigProvider { /// /// Register the service provider. /// /// /// - public CosmosDbServiceProvider(ServiceOperationsProvider serviceOperationsProvider, - CosmosDbServiceOperationProvider operationsProvider) + public CosmosDBServiceProvider(ServiceOperationsProvider serviceOperationsProvider, + CosmosDBServiceOperationProvider operationsProvider) { - serviceOperationsProvider.RegisterService(serviceName: CosmosDbServiceOperationProvider.ServiceName, serviceOperationsProviderId: CosmosDbServiceOperationProvider.ServiceId, serviceOperationsProviderInstance: operationsProvider); + serviceOperationsProvider.RegisterService(serviceName: CosmosDBServiceOperationProvider.ServiceName, serviceOperationsProviderId: CosmosDBServiceOperationProvider.ServiceId, serviceOperationsProviderInstance: operationsProvider); } /// diff --git a/src/CosmosDB/Startup/CosmosDbServiceProviderStartup.cs b/src/CosmosDB/Startup/CosmosDBStartup.cs similarity index 71% rename from src/CosmosDB/Startup/CosmosDbServiceProviderStartup.cs rename to src/CosmosDB/Startup/CosmosDBStartup.cs index b527f87..c5d6cbb 100644 --- a/src/CosmosDB/Startup/CosmosDbServiceProviderStartup.cs +++ b/src/CosmosDB/Startup/CosmosDBStartup.cs @@ -1,18 +1,18 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -using Microsoft.Azure.WebJobs; -using Microsoft.Azure.WebJobs.Hosting; -using Microsoft.Extensions.DependencyInjection.Extensions; - -[assembly: Microsoft.Azure.WebJobs.Hosting.WebJobsStartup(typeof(Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.CosmosDbServiceProviderStartup))] +[assembly: Microsoft.Azure.WebJobs.Hosting.WebJobsStartup(typeof(Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.CosmosDBStartup))] namespace Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB { + using Microsoft.Azure.WebJobs; + using Microsoft.Azure.WebJobs.Hosting; + using Microsoft.Extensions.DependencyInjection.Extensions; + /// /// This is a start up function, the discovery of this extension is based upon IWebJobsStartup implementation. /// In the function log file you should be able to see the log "Loading startup extension 'CosmosDbServiceProvider'" /// - public class CosmosDbServiceProviderStartup : IWebJobsStartup + public class CosmosDBStartup : IWebJobsStartup { /// /// The Configure method is invoked as initialization of the extension. @@ -20,8 +20,8 @@ namespace Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB /// public void Configure(IWebJobsBuilder builder) { - builder.AddExtension(); - builder.Services.TryAddSingleton(); + builder.AddExtension(); + builder.Services.TryAddSingleton(); } } } diff --git a/src/CosmosDB/deploy.ps1 b/src/CosmosDB/tools/deploy.ps1 similarity index 69% rename from src/CosmosDB/deploy.ps1 rename to src/CosmosDB/tools/deploy.ps1 index 1da4c52..44a069c 100644 --- a/src/CosmosDB/deploy.ps1 +++ b/src/CosmosDB/tools/deploy.ps1 @@ -1,4 +1,7 @@ -$extensionPath=$args[0] +$extensionPath=Split-Path -parent $PSCommandPath +$extensionPath = (get-item $extensionPath).parent.parent.FullName + +write-host "Nuget extension path is $extensionPath" $extensionName = "CosmosDB" $extensionNameServiceProvider = $extensionName+"ServiceProvider" @@ -30,26 +33,30 @@ catch write-host "func.exe not found" } -# Add Nuget package to existing project +# 1. Add Nuget package to existing project dotnet add package "Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB" --version 1.0.0 --source $extensionPath -$typeFullName = "Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.CosmosDBServiceProviderStartup, $fullAssemlyName" +# 2. Update extensions.json under extension module + +$typeFullName = "Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.CosmosDBStartup, $fullAssemlyName" $newNode = [pscustomobject] @{ name = $extensionNameServiceProvider typeName = $typeFullName} -# 1. Update extensions.json under extension module -$a = Get-Content $extensionModulePath -raw | ConvertFrom-Json -if ( ![bool]($a.extensions.name -match $extensionNameServiceProvider)) +$jsonContent = Get-Content $extensionModulePath -raw | ConvertFrom-Json +if ( ![bool]($jsonContent.extensions.name -match $extensionNameServiceProvider)) { -$a.extensions += $newNode - -$a | ConvertTo-Json -depth 32| set-content $extensionModulePath - + $jsonContent.extensions += $newNode } +else +{ + $jsonContent.extensions | % {if($_.name -eq $extensionNameServiceProvider){$_.typeName=$typeFullName}} +} +$jsonContent | ConvertTo-Json -depth 32| set-content $extensionModulePath +# 3. update dll in extension module. $spl = Split-Path $extensionModulePath Copy-Item $dll -Destination $spl diff --git a/test/CosmosDB/Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.Tests/CosmosDBOperationsTests.cs b/test/CosmosDB/Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.Tests/CosmosDBOperationsTests.cs index 7c8b27b..defd2e0 100644 --- a/test/CosmosDB/Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.Tests/CosmosDBOperationsTests.cs +++ b/test/CosmosDB/Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.Tests/CosmosDBOperationsTests.cs @@ -3,21 +3,13 @@ namespace Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.Tests { - using System; - using System.Collections.Generic; - using System.Threading; - using System.Threading.Tasks; - using Microsoft.Azure.Cosmos; - using Microsoft.Azure.WebJobs.Host.TestCommon; using Microsoft.Azure.Workflows.ServiceProviders.Abstractions; - using Microsoft.Extensions.Configuration; using Microsoft.WindowsAzure.ResourceStack.Common.Json; - using Moq; using Xunit; using Xunit.Abstractions; /// - /// Cosmos DB End2End tests. + /// Cosmos DB operation tests. /// public class CosmosDBOperationsTests { @@ -41,7 +33,7 @@ namespace Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.Tests [Fact] public void OperationConnectionParametersTest() { - var operations = new CosmosDbServiceOperationProvider(); + var operations = new CosmosDBServiceOperationProvider(); var connectionParameters = operations.GetService().Properties.ConnectionParameters as ConnectionParameters; var connectionStringParameters = new ConnectionStringParameters {