From ff0d0ab05d331c55d0b89ea1f02f9c6c8df99e92 Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Tue, 11 Feb 2025 16:10:11 +0530 Subject: [PATCH 01/10] feat: addcontentstackclient method overload --- .../ServiceCollectionExtensions.cs | 9 +++++++++ .../contentstack.management.aspnetcore.csproj | 9 +++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Contentstack.Management.ASPNETCore/ServiceCollectionExtensions.cs b/Contentstack.Management.ASPNETCore/ServiceCollectionExtensions.cs index 3798ed8..790aba2 100644 --- a/Contentstack.Management.ASPNETCore/ServiceCollectionExtensions.cs +++ b/Contentstack.Management.ASPNETCore/ServiceCollectionExtensions.cs @@ -6,6 +6,8 @@ using Microsoft.Extensions.Configuration; using Contentstack.Management.Core; using System.Net.Http; +using System; + namespace Microsoft.Extensions.DependencyInjection { public static class ServiceCollectionExtensions @@ -34,5 +36,12 @@ public static IServiceCollection TryAddContentstackClient(this IServiceCollectio return services; } + + public static IServiceCollection AddContentstackClient(this IServiceCollection services, Action configureClient) + { + services.AddHttpClient(configureClient); + + return services; + } } } \ No newline at end of file diff --git a/Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj b/Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj index a4880ce..2887b29 100644 --- a/Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj +++ b/Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj @@ -15,7 +15,7 @@ .NET SDK for the Contentstack Content Management API. LICENSE.txt v$(Version) - $(Version) + 0.1.3 Contentstack.Management.ASPNETCore @@ -26,8 +26,9 @@ - - - + + + + From 64b01ac40ab8a77a458d3d6256885ec106516507 Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Mon, 17 Feb 2025 13:25:20 +0530 Subject: [PATCH 02/10] chore: dependency update for synk issues --- .../Contentstack.Management.Core.Tests.csproj | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Contentstack.Management.Core.Tests/Contentstack.Management.Core.Tests.csproj b/Contentstack.Management.Core.Tests/Contentstack.Management.Core.Tests.csproj index 4450c78..f7f762f 100644 --- a/Contentstack.Management.Core.Tests/Contentstack.Management.Core.Tests.csproj +++ b/Contentstack.Management.Core.Tests/Contentstack.Management.Core.Tests.csproj @@ -4,26 +4,26 @@ net7.0 false - 0.1.10 + 0.1.3 true ../CSManagementSDK.snk - - - - runtime; build; native; contentfiles; analyzers; buildtransitive + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - - - - - - - + + + + + + + From 1ac3f3b46b54c9f6adfc07280d4eb2d5f2b43f24 Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Mon, 17 Feb 2025 13:38:23 +0530 Subject: [PATCH 03/10] fix: change version number to dynamic from directory.build.props --- .../Contentstack.Management.Core.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Contentstack.Management.Core.Tests/Contentstack.Management.Core.Tests.csproj b/Contentstack.Management.Core.Tests/Contentstack.Management.Core.Tests.csproj index f7f762f..4d605a0 100644 --- a/Contentstack.Management.Core.Tests/Contentstack.Management.Core.Tests.csproj +++ b/Contentstack.Management.Core.Tests/Contentstack.Management.Core.Tests.csproj @@ -4,7 +4,7 @@ net7.0 false - 0.1.3 + $(Version) true ../CSManagementSDK.snk From 0a4b9aa8d14dfac64c3e3b3f18b9bbe76d60dcbd Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Mon, 17 Feb 2025 13:46:17 +0530 Subject: [PATCH 04/10] chore: packages update for unit tests --- ...tentstack.Management.Core.Unit.Tests.csproj | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Contentstack.Management.Core.Unit.Tests/Contentstack.Management.Core.Unit.Tests.csproj b/Contentstack.Management.Core.Unit.Tests/Contentstack.Management.Core.Unit.Tests.csproj index 8c53ce9..82b764b 100644 --- a/Contentstack.Management.Core.Unit.Tests/Contentstack.Management.Core.Unit.Tests.csproj +++ b/Contentstack.Management.Core.Unit.Tests/Contentstack.Management.Core.Unit.Tests.csproj @@ -4,22 +4,22 @@ net7.0 false - $(Version) + 0.1.3 true ../CSManagementSDK.snk - - - - runtime; build; native; contentfiles; analyzers; buildtransitive + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - - - - + + + + From 47d031764fd77b497717e0526f171253303e247a Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Mon, 17 Feb 2025 15:21:31 +0530 Subject: [PATCH 05/10] chore: update sca scan workflow --- .github/workflows/sca-scan.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sca-scan.yml b/.github/workflows/sca-scan.yml index 4fa4560..c1519f9 100644 --- a/.github/workflows/sca-scan.yml +++ b/.github/workflows/sca-scan.yml @@ -6,10 +6,14 @@ jobs: security-sca: runs-on: ubuntu-latest steps: - - uses: actions/checkout@master + - name: Checkout repository + uses: actions/checkout@master + - name: Run Dotnet Restore + run: | + dotnet restore - name: Run Snyk to check for vulnerabilities uses: snyk/actions/dotnet@master env: SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} with: - args: --fail-on=all + args: --file=Contentstack.Management.Core/obj/project.assets.json --fail-on=all From 8128b250e7e44c0f6efd81965e0b10e9ed3e6b0f Mon Sep 17 00:00:00 2001 From: Aravind Kumar Date: Mon, 17 Feb 2025 15:31:01 +0530 Subject: [PATCH 06/10] Update LICENSE --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index e17cc92..3851325 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2012-2024 Contentstack +Copyright (c) 2012-2025 Contentstack Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From cfc58efd9c85782421d632303bc1cc3b94dba04c Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Tue, 18 Feb 2025 12:54:33 +0530 Subject: [PATCH 07/10] feat: add ContentstackClient method overload for custom httpclient --- .../ServiceCollectionExtensions.cs | 10 +---- .../Core/ContentstackClientTest.cs | 40 +++++++++++++++++- .../ContentstackClient.cs | 41 ++++++++++++++++--- 3 files changed, 77 insertions(+), 14 deletions(-) diff --git a/Contentstack.Management.ASPNETCore/ServiceCollectionExtensions.cs b/Contentstack.Management.ASPNETCore/ServiceCollectionExtensions.cs index 790aba2..75ac0dd 100644 --- a/Contentstack.Management.ASPNETCore/ServiceCollectionExtensions.cs +++ b/Contentstack.Management.ASPNETCore/ServiceCollectionExtensions.cs @@ -1,10 +1,4 @@ - -using System.Collections.Generic; -using System.Text; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; -using Microsoft.Extensions.Configuration; -using Contentstack.Management.Core; +using Contentstack.Management.Core; using System.Net.Http; using System; @@ -19,7 +13,7 @@ public static class ServiceCollectionExtensions /// The IServiceCollection. /// The ContentstackClientOptions used to retrieve configuration from. /// The IServiceCollection. - public static IServiceCollection AddContentstackClien(this IServiceCollection services, ContentstackClientOptions configuration) + public static IServiceCollection AddContentstackClient(this IServiceCollection services, ContentstackClientOptions configuration) { return services; diff --git a/Contentstack.Management.Core.Unit.Tests/Core/ContentstackClientTest.cs b/Contentstack.Management.Core.Unit.Tests/Core/ContentstackClientTest.cs index 6a32846..868c91d 100644 --- a/Contentstack.Management.Core.Unit.Tests/Core/ContentstackClientTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Core/ContentstackClientTest.cs @@ -1,4 +1,5 @@ using System; +using System.Net.Http; using Contentstack.Management.Core.Http; using Contentstack.Management.Core.Models; using Contentstack.Management.Core.Runtime.Contexts; @@ -62,7 +63,7 @@ public void Initialize_Contentstack_With_All_Options() } [TestMethod] - public void Initialize_Contentstack_With_Clientptions() + public void Initialize_Contentstack_With_ClientOptions() { var contentstackClient = new ContentstackClient(new ContentstackClientOptions() { @@ -94,6 +95,43 @@ public void Initialize_Contentstack_With_Clientptions() CollectionAssert.AreEqual(new string[] {"ea1", "ea2"}, contentstackClient.contentstackOptions.EarlyAccess); } + [TestMethod] + public void Initialize_Contentstack_With_CustomHTTPClient() + { + // create a custom HttpClient + var httpClient = new HttpClient(); + httpClient.DefaultRequestHeaders.Add("CustomHeader", "CustomValue"); + + var contentstackClient = new ContentstackClient(httpClient, new ContentstackClientOptions() + { + Authtoken = "token", + Host= "host", + Port= 445, + Version= "v4", + DisableLogging= true, + MaxResponseContentBufferSize= 1234, + Timeout= TimeSpan.FromSeconds(20), + RetryOnError= false, + ProxyHost= "proxyHost", + ProxyPort= 22, + EarlyAccess = new string[] { "ea1", "ea2" } + }); + + Assert.AreEqual("token", contentstackClient.contentstackOptions.Authtoken); + Assert.AreEqual("host", contentstackClient.contentstackOptions.Host); + Assert.AreEqual(445, contentstackClient.contentstackOptions.Port); + Assert.AreEqual("v4", contentstackClient.contentstackOptions.Version); + Assert.AreEqual("proxyHost", contentstackClient.contentstackOptions.ProxyHost); + Assert.AreEqual(22, contentstackClient.contentstackOptions.ProxyPort); + Assert.IsNull(contentstackClient.contentstackOptions.ProxyCredentials); + Assert.IsNotNull(contentstackClient.contentstackOptions.GetWebProxy()); + Assert.IsFalse(contentstackClient.contentstackOptions.RetryOnError); + Assert.IsTrue(contentstackClient.contentstackOptions.DisableLogging); + Assert.AreEqual(1234, contentstackClient.contentstackOptions.MaxResponseContentBufferSize); + Assert.AreEqual(20, contentstackClient.contentstackOptions.Timeout.Seconds); + CollectionAssert.AreEqual(new string[] {"ea1", "ea2"}, contentstackClient.contentstackOptions.EarlyAccess); + } + [TestMethod] public void Should_Dispose_ContentstackClientAsync() { diff --git a/Contentstack.Management.Core/ContentstackClient.cs b/Contentstack.Management.Core/ContentstackClient.cs index 221c319..18a1b96 100644 --- a/Contentstack.Management.Core/ContentstackClient.cs +++ b/Contentstack.Management.Core/ContentstackClient.cs @@ -72,6 +72,30 @@ public ContentstackClient(IOptions contentstackOption BuildPipeline(); } + + /// + /// Initializes new instance of the class with custom HttpClient. + /// + /// The user can pass. + /// + ///

+        /// HttpClientHandler httpClientHandler = new HttpClientHandler
+        /// {
+        ///     Proxy = contentstackOptions.GetWebProxy()
+        /// };
+
+        /// _httpClient = new HttpClient(httpClientHandler);
+        /// ContentstackClient client = new ContentstackClient(_httpClient);
+        /// 
+ ///
+ public ContentstackClient(HttpClient httpClient, ContentstackClientOptions contentstackOptions) + { + this.contentstackOptions = contentstackOptions; + _httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); + Initialize(_httpClient); + BuildPipeline(); + } + public ContentstackClient(ContentstackClientOptions contentstackOptions) : this(new OptionsWrapper(contentstackOptions)) { } @@ -126,14 +150,21 @@ public ContentstackClient( { } #endregion - protected void Initialize() + protected void Initialize(HttpClient httpClient = null) { - HttpClientHandler httpClientHandler = new HttpClientHandler + if (httpClient != null) { - Proxy = contentstackOptions.GetWebProxy() - }; + _httpClient = httpClient; + } + else + { + HttpClientHandler httpClientHandler = new HttpClientHandler + { + Proxy = contentstackOptions.GetWebProxy() + }; - _httpClient = new HttpClient(httpClientHandler); + _httpClient = new HttpClient(httpClientHandler); + } _httpClient.DefaultRequestHeaders.Add(HeadersKey.XUserAgentHeader, $"{xUserAgent}"); From f6b373ba4d0873a2f8f6bd9d22db749d531ce5c9 Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Tue, 18 Feb 2025 12:59:59 +0530 Subject: [PATCH 08/10] chore: version bump --- CHANGELOG.md | 4 ++++ .../contentstack.management.aspnetcore.csproj | 2 +- .../Contentstack.Management.Core.Tests.csproj | 2 +- Contentstack.Management.Core/ContentstackClient.cs | 2 +- Directory.Build.props | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ecab8a0..72557e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [v0.1.11](https://github.com/contentstack/contentstack-management-dotnet/tree/v0.1.11) + - Feat + - Add support for custom Http client and IHttpClientFactory + ## [v0.1.10](https://github.com/contentstack/contentstack-management-dotnet/tree/v0.1.10) - Feat - Add support for apiVersion in bulk publish unpublish methods diff --git a/Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj b/Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj index 2887b29..49a3a1f 100644 --- a/Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj +++ b/Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj @@ -28,7 +28,7 @@ - + diff --git a/Contentstack.Management.Core.Tests/Contentstack.Management.Core.Tests.csproj b/Contentstack.Management.Core.Tests/Contentstack.Management.Core.Tests.csproj index 4450c78..47cb37d 100644 --- a/Contentstack.Management.Core.Tests/Contentstack.Management.Core.Tests.csproj +++ b/Contentstack.Management.Core.Tests/Contentstack.Management.Core.Tests.csproj @@ -4,7 +4,7 @@ net7.0 false - 0.1.10 + 0.1.11 true ../CSManagementSDK.snk diff --git a/Contentstack.Management.Core/ContentstackClient.cs b/Contentstack.Management.Core/ContentstackClient.cs index 18a1b96..5e4bb42 100644 --- a/Contentstack.Management.Core/ContentstackClient.cs +++ b/Contentstack.Management.Core/ContentstackClient.cs @@ -35,7 +35,7 @@ public class ContentstackClient : IContentstackClient private HttpClient _httpClient; private bool _disposed = false; - private string Version => "0.1.10"; + private string Version => "0.1.11"; private string xUserAgent => $"contentstack-management-dotnet/{Version}"; #endregion diff --git a/Directory.Build.props b/Directory.Build.props index 6d5fa21..b5e0738 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 0.1.10 + 0.1.11 From 4b2b05fd041b26cbab28797d4d79751b58f77466 Mon Sep 17 00:00:00 2001 From: Aravind Kumar Date: Tue, 18 Feb 2025 13:39:01 +0530 Subject: [PATCH 09/10] Update LICENSE From 3228de77dec50c192d833829c6b85c15a0585b63 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Tue, 25 Feb 2025 12:22:16 +0530 Subject: [PATCH 10/10] Fix: Updated workflow versions and dependency --- .github/workflows/check-branch.yml | 4 ++-- .github/workflows/nuget-publish.yml | 8 ++++---- .github/workflows/sast-scan.yml | 2 +- .github/workflows/unit-test.yml | 4 ++-- .../contentstack.management.aspnetcore.csproj | 8 ++++---- .../Contentstack.Management.Core.Tests.csproj | 4 ++-- .../Contentstack.Management.Core.Unit.Tests.csproj | 4 ++-- .../contentstack.management.core.csproj | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/.github/workflows/check-branch.yml b/.github/workflows/check-branch.yml index 0690dbc..00a6a8a 100644 --- a/.github/workflows/check-branch.yml +++ b/.github/workflows/check-branch.yml @@ -8,13 +8,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Comment PR - if: github.base_ref == 'main' && github.head_ref != 'next' + if: github.base_ref == 'main' && github.head_ref != 'staging' uses: thollander/actions-comment-pull-request@v2 with: message: | We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the next branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch. - name: Check branch - if: github.base_ref == 'main' && github.head_ref != 'next' + if: github.base_ref == 'main' && github.head_ref != 'staging' run: | echo "ERROR: We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the next branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch." exit 1 diff --git a/.github/workflows/nuget-publish.yml b/.github/workflows/nuget-publish.yml index 466d715..a355c16 100644 --- a/.github/workflows/nuget-publish.yml +++ b/.github/workflows/nuget-publish.yml @@ -10,9 +10,9 @@ jobs: runs-on: windows-latest steps: - name: Checkout repository - uses: actions/checkout@v1 + uses: actions/checkout@v4.2.2 - name: Setup .NET Core @ Latest - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4.3.0 env: NUGET_AUTH_TOKEN: ${{ secrets.NUGET_API_KEY }} - name: Build solution and generate NuGet package @@ -28,9 +28,9 @@ jobs: runs-on: windows-latest steps: - name: Checkout repository - uses: actions/checkout@v1 + uses: actions/checkout@v4.2.2 - name: Setup .NET Core @ Latest - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4.3.0 with: source-url: https://nuget.pkg.github.com/Contentstack/index.json env: diff --git a/.github/workflows/sast-scan.yml b/.github/workflows/sast-scan.yml index 3b9521a..3d2096e 100644 --- a/.github/workflows/sast-scan.yml +++ b/.github/workflows/sast-scan.yml @@ -6,6 +6,6 @@ jobs: security-sast: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4.2.2 - name: Semgrep Scan run: docker run -v /var/run/docker.sock:/var/run/docker.sock -v "${PWD}:/src" returntocorp/semgrep semgrep scan --config auto \ No newline at end of file diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 5bce498..bfa8945 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -8,9 +8,9 @@ jobs: runs-on: windows-latest steps: - name: Checkout repository - uses: actions/checkout@v1 + uses: actions/checkout@v4.2.2 - name: Setup .NET Core @ Latest - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4.3.0 - name: Build solution and run unit test run: sh ./Scripts/run-unit-test-case.sh - name: Test Report diff --git a/Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj b/Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj index 49a3a1f..1d31ba9 100644 --- a/Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj +++ b/Contentstack.Management.ASPNETCore/contentstack.management.aspnetcore.csproj @@ -26,9 +26,9 @@
- - - - + + + + diff --git a/Contentstack.Management.Core.Tests/Contentstack.Management.Core.Tests.csproj b/Contentstack.Management.Core.Tests/Contentstack.Management.Core.Tests.csproj index 4d605a0..f8be953 100644 --- a/Contentstack.Management.Core.Tests/Contentstack.Management.Core.Tests.csproj +++ b/Contentstack.Management.Core.Tests/Contentstack.Management.Core.Tests.csproj @@ -12,8 +12,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/Contentstack.Management.Core.Unit.Tests/Contentstack.Management.Core.Unit.Tests.csproj b/Contentstack.Management.Core.Unit.Tests/Contentstack.Management.Core.Unit.Tests.csproj index 82b764b..e351e54 100644 --- a/Contentstack.Management.Core.Unit.Tests/Contentstack.Management.Core.Unit.Tests.csproj +++ b/Contentstack.Management.Core.Unit.Tests/Contentstack.Management.Core.Unit.Tests.csproj @@ -11,8 +11,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/Contentstack.Management.Core/contentstack.management.core.csproj b/Contentstack.Management.Core/contentstack.management.core.csproj index 94b1097..f1f29bc 100644 --- a/Contentstack.Management.Core/contentstack.management.core.csproj +++ b/Contentstack.Management.Core/contentstack.management.core.csproj @@ -64,7 +64,7 @@ - +