From 4762a50d9fdb6d2f1d38754008dbe881cf7a7605 Mon Sep 17 00:00:00 2001 From: Phil Schneider Date: Tue, 30 Apr 2024 09:45:24 +0200 Subject: [PATCH 1/2] chore: adjust get queries to filter for name (#43) --- charts/dim/Chart.yaml | 4 ++-- charts/dim/README.md | 2 +- src/Directory.Build.props | 2 +- src/clients/Dim.Clients/Api/Cf/CfClient.cs | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/charts/dim/Chart.yaml b/charts/dim/Chart.yaml index fdccfe6..69abd06 100644 --- a/charts/dim/Chart.yaml +++ b/charts/dim/Chart.yaml @@ -20,8 +20,8 @@ apiVersion: v2 name: dim type: application -version: 0.0.5 -appVersion: 0.0.5 +version: 0.0.6 +appVersion: 0.0.6 description: Helm chart for DIM Middle Layer home: https://github.com/catenax-ng/dim-repo dependencies: diff --git a/charts/dim/README.md b/charts/dim/README.md index a408ec0..0179302 100644 --- a/charts/dim/README.md +++ b/charts/dim/README.md @@ -27,7 +27,7 @@ To use the helm chart as a dependency: dependencies: - name: dim repository: https://phil91.github.io/dim-client - version: 0.0.5 + version: 0.0.6 ``` ## Requirements diff --git a/src/Directory.Build.props b/src/Directory.Build.props index e894dba..6e6b86b 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -19,7 +19,7 @@ - 0.0.5 + 0.0.6 diff --git a/src/clients/Dim.Clients/Api/Cf/CfClient.cs b/src/clients/Dim.Clients/Api/Cf/CfClient.cs index aa515c7..1ff2635 100644 --- a/src/clients/Dim.Clients/Api/Cf/CfClient.cs +++ b/src/clients/Dim.Clients/Api/Cf/CfClient.cs @@ -71,7 +71,7 @@ public async Task CreateCloudFoundrySpace(string tenantName, CancellationT private static async Task GetEnvironmentId(string tenantName, CancellationToken cancellationToken, HttpClient client) { - var environmentsResponse = await client.GetAsync("/v3/organizations", cancellationToken) + var environmentsResponse = await client.GetAsync($"/v3/organizations?names={tenantName}", cancellationToken) .CatchingIntoServiceExceptionFor("get-organizations", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE); var environments = await environmentsResponse.Content .ReadFromJsonAsync(JsonSerializerExtensions.Options, cancellationToken) @@ -136,7 +136,7 @@ public async Task GetSpace(string tenantName, CancellationToken cancellati { var spaceName = $"{tenantName}-space"; var client = await _basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(false); - var result = await client.GetAsync("/v3/spaces", cancellationToken) + var result = await client.GetAsync($"/v3/spaces?names={spaceName}", cancellationToken) .CatchingIntoServiceExceptionFor("get-space", HttpAsyncResponseMessageExtension.RecoverOptions.ALLWAYS).ConfigureAwait(false); try { @@ -180,8 +180,9 @@ await client.PostAsJsonAsync("/v3/service_instances", data, JsonSerializerExtens private async Task GetServiceInstances(string tenantName, Guid? spaceId, CancellationToken cancellationToken) { + var name = $"{tenantName}-dim-instance"; var client = await _basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(false); - var result = await client.GetAsync("/v3/service_instances", cancellationToken) + var result = await client.GetAsync($"/v3/service_instances?names={name}", cancellationToken) .CatchingIntoServiceExceptionFor("get-si", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE).ConfigureAwait(false); try { @@ -193,7 +194,6 @@ private async Task GetServiceInstances(string tenantName, Guid? spaceId, C throw new ServiceException("Response must not be null"); } - var name = $"{tenantName}-dim-instance"; var resources = response.Resources.Where(x => x.Name == name && x.Type == "managed" && (spaceId == null || x.Relationships.Space.Data.Id == spaceId.Value) && x.LastOperation.State == "succeeded"); if (resources.Count() != 1) { From 3308287dc32376cf38b57ef928acf4fe3e45a460 Mon Sep 17 00:00:00 2001 From: Phil Schneider Date: Tue, 30 Apr 2024 15:32:05 +0200 Subject: [PATCH 2/2] fix: add url encoding to get endpoints (#44) --- charts/dim/Chart.yaml | 4 ++-- charts/dim/README.md | 2 +- src/Directory.Build.props | 2 +- src/clients/Dim.Clients/Api/Cf/CfClient.cs | 9 +++++---- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/charts/dim/Chart.yaml b/charts/dim/Chart.yaml index 69abd06..e4ac539 100644 --- a/charts/dim/Chart.yaml +++ b/charts/dim/Chart.yaml @@ -20,8 +20,8 @@ apiVersion: v2 name: dim type: application -version: 0.0.6 -appVersion: 0.0.6 +version: 0.0.7 +appVersion: 0.0.7 description: Helm chart for DIM Middle Layer home: https://github.com/catenax-ng/dim-repo dependencies: diff --git a/charts/dim/README.md b/charts/dim/README.md index 0179302..be6c1cb 100644 --- a/charts/dim/README.md +++ b/charts/dim/README.md @@ -27,7 +27,7 @@ To use the helm chart as a dependency: dependencies: - name: dim repository: https://phil91.github.io/dim-client - version: 0.0.6 + version: 0.0.7 ``` ## Requirements diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 6e6b86b..d4145a2 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -19,7 +19,7 @@ - 0.0.6 + 0.0.7 diff --git a/src/clients/Dim.Clients/Api/Cf/CfClient.cs b/src/clients/Dim.Clients/Api/Cf/CfClient.cs index 1ff2635..cc579b6 100644 --- a/src/clients/Dim.Clients/Api/Cf/CfClient.cs +++ b/src/clients/Dim.Clients/Api/Cf/CfClient.cs @@ -25,6 +25,7 @@ using Org.Eclipse.TractusX.Portal.Backend.Framework.HttpClientExtensions; using System.Net.Http.Json; using System.Text.Json; +using System.Web; namespace Dim.Clients.Api.Cf; @@ -71,7 +72,7 @@ public async Task CreateCloudFoundrySpace(string tenantName, CancellationT private static async Task GetEnvironmentId(string tenantName, CancellationToken cancellationToken, HttpClient client) { - var environmentsResponse = await client.GetAsync($"/v3/organizations?names={tenantName}", cancellationToken) + var environmentsResponse = await client.GetAsync($"/v3/organizations?names={HttpUtility.UrlEncode(tenantName)}", cancellationToken) .CatchingIntoServiceExceptionFor("get-organizations", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE); var environments = await environmentsResponse.Content .ReadFromJsonAsync(JsonSerializerExtensions.Options, cancellationToken) @@ -136,7 +137,7 @@ public async Task GetSpace(string tenantName, CancellationToken cancellati { var spaceName = $"{tenantName}-space"; var client = await _basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(false); - var result = await client.GetAsync($"/v3/spaces?names={spaceName}", cancellationToken) + var result = await client.GetAsync($"/v3/spaces?names={HttpUtility.UrlEncode(spaceName)}", cancellationToken) .CatchingIntoServiceExceptionFor("get-space", HttpAsyncResponseMessageExtension.RecoverOptions.ALLWAYS).ConfigureAwait(false); try { @@ -182,7 +183,7 @@ private async Task GetServiceInstances(string tenantName, Guid? spaceId, C { var name = $"{tenantName}-dim-instance"; var client = await _basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(false); - var result = await client.GetAsync($"/v3/service_instances?names={name}", cancellationToken) + var result = await client.GetAsync($"/v3/service_instances?names={HttpUtility.UrlEncode(name)}", cancellationToken) .CatchingIntoServiceExceptionFor("get-si", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE).ConfigureAwait(false); try { @@ -226,7 +227,7 @@ public async Task GetServiceBinding(string tenantName, Guid spaceId, strin { var client = await _basicAuthTokenService.GetBasicAuthorizedLegacyClient(_settings, cancellationToken).ConfigureAwait(false); var serviceInstanceId = await GetServiceInstances(tenantName, spaceId, cancellationToken).ConfigureAwait(false); - var result = await client.GetAsync($"/v3/service_credential_bindings?names={bindingName}", cancellationToken) + var result = await client.GetAsync($"/v3/service_credential_bindings?names={HttpUtility.UrlEncode(bindingName)}", cancellationToken) .CatchingIntoServiceExceptionFor("get-credential-binding", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE).ConfigureAwait(false); try {