Skip to content

Commit

Permalink
Merge branch 'main' into release/v5
Browse files Browse the repository at this point in the history
  • Loading branch information
tnotheis committed May 15, 2024
2 parents 890aacf + 4cf5e5e commit 680c4d4
Show file tree
Hide file tree
Showing 98 changed files with 807 additions and 1,497 deletions.
5 changes: 4 additions & 1 deletion AdminApi.Sdk/Client.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System.Text.Json;
using System.Text.Json;
using Backbone.AdminApi.Sdk.Authentication;
using Backbone.AdminApi.Sdk.Endpoints.ApiKeyValidation;
using Backbone.AdminApi.Sdk.Endpoints.Challenges;
using Backbone.AdminApi.Sdk.Endpoints.Clients;
using Backbone.AdminApi.Sdk.Endpoints.Identities;
using Backbone.AdminApi.Sdk.Endpoints.Logs;
using Backbone.AdminApi.Sdk.Endpoints.Messages;
using Backbone.AdminApi.Sdk.Endpoints.Metrics;
using Backbone.AdminApi.Sdk.Endpoints.Relationships;
using Backbone.AdminApi.Sdk.Endpoints.Tiers;
Expand Down Expand Up @@ -32,6 +33,7 @@ private Client(HttpClient httpClient, string apiKey)
Relationships = new RelationshipsEndpoint(endpointClient);
Tiers = new TiersEndpoint(endpointClient);
Challenges = new ChallengesEndpoint(endpointClient);
Messages = new MessagesEndpoint(endpointClient);
}

public ApiKeyValidationEndpoint ApiKeyValidation { get; }
Expand All @@ -42,6 +44,7 @@ private Client(HttpClient httpClient, string apiKey)
public RelationshipsEndpoint Relationships { get; }
public TiersEndpoint Tiers { get; }
public ChallengesEndpoint Challenges { get; }
public MessagesEndpoint Messages { get; }

public static Client Create(string baseUrl, string apiKey)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ namespace Backbone.AdminApi.Sdk.Endpoints.ApiKeyValidation;
public class ApiKeyValidationEndpoint(EndpointClient client) : AdminApiEndpoint(client)
{
public async Task<ApiResponse<ValidateApiKeyResponse>> ValidateApiKeyUnauthenticated(ValidateApiKeyRequest? request)
=> await _client.PostUnauthenticated<ValidateApiKeyResponse>($"api/{API_VERSION}/ValidateApiKey", request);
{
return await _client.PostUnauthenticated<ValidateApiKeyResponse>($"api/{API_VERSION}/ValidateApiKey", request);
}
}
4 changes: 2 additions & 2 deletions AdminApi.Sdk/Endpoints/Challenges/ChallengesEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Backbone.AdminApi.Sdk.Endpoints.Challenges;

public class ChallengesEndpoint(EndpointClient client) : Endpoint(client)
public class ChallengesEndpoint(EndpointClient client) : AdminApiEndpoint(client)
{
public async Task<ApiResponse<Challenge>> CreateChallenge()
{
return await _client.Post<Challenge>("Challenges");
return await _client.Post<Challenge>($"api/{API_VERSION}/Challenges");
}
}
2 changes: 1 addition & 1 deletion AdminApi.Sdk/Endpoints/Challenges/Types/SignedChallenge.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Backbone.BuildingBlocks.SDK.Crypto;
using Backbone.BuildingBlocks.SDK.Crypto;
using Backbone.Crypto;
using Newtonsoft.Json;

Expand Down
27 changes: 21 additions & 6 deletions AdminApi.Sdk/Endpoints/Clients/ClientsEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,33 @@ namespace Backbone.AdminApi.Sdk.Endpoints.Clients;

public class ClientsEndpoint(EndpointClient client) : AdminApiEndpoint(client)
{
public async Task<ApiResponse<ListClientsResponse>> GetAllClients() => await _client.Get<ListClientsResponse>($"api/{API_VERSION}/Clients");
public async Task<ApiResponse<ListClientsResponse>> GetAllClients()
{
return await _client.Get<ListClientsResponse>($"api/{API_VERSION}/Clients");
}

public async Task<ApiResponse<ClientInfo>> GetClient(string id) => await _client.Get<ClientInfo>($"api/{API_VERSION}/Clients/{id}");
public async Task<ApiResponse<ClientInfo>> GetClient(string id)
{
return await _client.Get<ClientInfo>($"api/{API_VERSION}/Clients/{id}");
}

public async Task<ApiResponse<CreateClientResponse>> CreateClient(CreateClientRequest request)
=> await _client.Post<CreateClientResponse>($"api/{API_VERSION}/Clients", request);
{
return await _client.Post<CreateClientResponse>($"api/{API_VERSION}/Clients", request);
}

public async Task<ApiResponse<ClientInfo>> ChangeClientSecret(string id, ChangeClientSecretRequest request)
=> await _client.Patch<ClientInfo>($"api/{API_VERSION}/Clients/{id}/ChangeSecret", request);
{
return await _client.Patch<ClientInfo>($"api/{API_VERSION}/Clients/{id}/ChangeSecret", request);
}

public async Task<ApiResponse<ClientInfo>> UpdateClient(string id, UpdateClientRequest request)
=> await _client.Put<ClientInfo>($"api/{API_VERSION}/Clients/{id}", request);
{
return await _client.Put<ClientInfo>($"api/{API_VERSION}/Clients/{id}", request);
}

public async Task<ApiResponse<EmptyResponse>> DeleteClient(string id) => await _client.Delete<EmptyResponse>($"api/{API_VERSION}/Clients/{id}");
public async Task<ApiResponse<EmptyResponse>> DeleteClient(string id)
{
return await _client.Delete<EmptyResponse>($"api/{API_VERSION}/Clients/{id}");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Backbone.AdminApi.Sdk.Endpoints.Clients.Types;

public class ClientOverwiew
public class ClientOverview
{
public required string ClientId { get; set; }
public required string DisplayName { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Backbone.AdminApi.Sdk.Endpoints.Clients.Types.Responses;

public class ListClientsResponse : EnumerableResponseBase<ClientOverwiew>;
public class ListClientsResponse : EnumerableResponseBase<ClientOverview>;
38 changes: 27 additions & 11 deletions AdminApi.Sdk/Endpoints/Identities/IdentitiesEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,39 @@ namespace Backbone.AdminApi.Sdk.Endpoints.Identities;
public class IdentitiesEndpoint(EndpointClient client) : AdminApiEndpoint(client)
{
public async Task<ApiResponse<IndividualQuota>> CreateIndividualQuota(string address, CreateQuotaForIdentityRequest request)
=> await _client.Post<IndividualQuota>($"api/{API_VERSION}/Identities/{address}/Quotas", request);
{
return await _client.Post<IndividualQuota>($"api/{API_VERSION}/Identities/{address}/Quotas", request);
}

public async Task<ApiResponse<EmptyResponse>> DeleteIndividualQuota(string address, string quotaId)
=> await _client.Delete<EmptyResponse>($"api/{API_VERSION}/Identities/{address}/Quotas/{quotaId}");

public async Task<ApiResponse<ListIdentitiesResponse>> ListIdentities() => await _client.Request<ListIdentitiesResponse>(HttpMethod.Get, "odata/Identities")
.Authenticate()
.ExecuteOData();

public async Task<ApiResponse<GetIdentityResponse>> GetIdentity(string address) => await _client.Get<GetIdentityResponse>($"api/{API_VERSION}/Identities/{address}");
{
return await _client.Delete<EmptyResponse>($"api/{API_VERSION}/Identities/{address}/Quotas/{quotaId}");
}

public async Task<ApiResponse<ListIdentitiesResponse>> ListIdentities()
{
return await _client.Request<ListIdentitiesResponse>(HttpMethod.Get, "odata/Identities")
.Authenticate()
.ExecuteOData();
}

public async Task<ApiResponse<GetIdentityResponse>> GetIdentity(string address)
{
return await _client.Get<GetIdentityResponse>($"api/{API_VERSION}/Identities/{address}");
}

public async Task<ApiResponse<EmptyResponse>> UpdateIdentityTier(string address, UpdateIdentityTierRequest request)
=> await _client.Put<EmptyResponse>($"api/{API_VERSION}/Identities/{address}", request);
{
return await _client.Put<EmptyResponse>($"api/{API_VERSION}/Identities/{address}", request);
}

public async Task<ApiResponse<CreateIdentityResponse>> CreateIdentity(CreateIdentityRequest request)
=> await _client.Post<CreateIdentityResponse>($"api/{API_VERSION}", request);
{
return await _client.Post<CreateIdentityResponse>($"api/{API_VERSION}/Identities", request);
}

public async Task<ApiResponse<StartDeletionProcessAsSupportResponse>> StartDeletionProcess(string address)
=> await _client.Post<StartDeletionProcessAsSupportResponse>($"api/{API_VERSION}/Identities/{address}/DeletionProcesses");
{
return await _client.Post<StartDeletionProcessAsSupportResponse>($"api/{API_VERSION}/Identities/{address}/DeletionProcesses");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace Backbone.AdminApi.Sdk.Endpoints.Identities.Types.Requests;
public class CreateIdentityRequest
{
public required string ClientId { get; set; }
public required string ClientSecret { get; set; }
public required byte[] IdentityPublicKey { get; set; }
public required string DevicePassword { get; set; }
public required byte IdentityVersion { get; set; }
Expand Down
5 changes: 4 additions & 1 deletion AdminApi.Sdk/Endpoints/Logs/LogsEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ namespace Backbone.AdminApi.Sdk.Endpoints.Logs;

public class LogsEndpoint(EndpointClient client) : AdminApiEndpoint(client)
{
public async Task<ApiResponse<EmptyResponse>> CreateLog(LogRequest request) => await _client.Post<EmptyResponse>($"api/{API_VERSION}/Logs", request);
public async Task<ApiResponse<EmptyResponse>> CreateLog(LogRequest request)
{
return await _client.Post<EmptyResponse>($"api/{API_VERSION}/Logs", request);
}
}
19 changes: 19 additions & 0 deletions AdminApi.Sdk/Endpoints/Messages/MessagesEndpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Backbone.AdminApi.Sdk.Endpoints.Messages.Types;
using Backbone.AdminApi.Sdk.Endpoints.Messages.Types.Responses;
using Backbone.BuildingBlocks.SDK.Endpoints.Common;
using Backbone.BuildingBlocks.SDK.Endpoints.Common.Types;

namespace Backbone.AdminApi.Sdk.Endpoints.Messages;

public class MessagesEndpoint(EndpointClient client) : AdminApiEndpoint(client)
{
public async Task<ApiResponse<ListMessagesResponse>> GetMessagesWithParticipant(string identityAddress, MessageType type)
{
return await _client
.Request<ListMessagesResponse>(HttpMethod.Get, $"api/{API_VERSION}/Messages")
.Authenticate()
.AddQueryParameter("participant", identityAddress)
.AddQueryParameter("type", type.Value)
.Execute();
}
}
11 changes: 11 additions & 0 deletions AdminApi.Sdk/Endpoints/Messages/Types/Message.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Backbone.AdminApi.Sdk.Endpoints.Messages.Types;

public class Message
{
public string MessageId { get; set; } = null!;
public string SenderAddress { get; set; } = null!;
public string SenderDevice { get; set; } = null!;
public DateTime SendDate { get; set; }
public int NumberOfAttachments { get; set; }
public List<MessageRecipient> Recipients { get; set; } = null!;
}
8 changes: 8 additions & 0 deletions AdminApi.Sdk/Endpoints/Messages/Types/MessageRecipient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Backbone.AdminApi.Sdk.Endpoints.Messages.Types;

public class MessageRecipient
{
public int Id { get; set; }
public string Address { get; set; } = null!;
public string MessageId { get; set; } = null!;
}
14 changes: 14 additions & 0 deletions AdminApi.Sdk/Endpoints/Messages/Types/MessageType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Backbone.AdminApi.Sdk.Endpoints.Messages.Types;

public record MessageType
{
public static readonly MessageType INCOMING = new("Incoming");
public static readonly MessageType OUTGOING = new("Outgoing");

public MessageType(string value)
{
Value = value;
}

public string Value { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using Backbone.BuildingBlocks.SDK.Endpoints.Common.Types;

namespace Backbone.AdminApi.Sdk.Endpoints.Messages.Types.Responses;

public class ListMessagesResponse : EnumerableResponseBase<Message>;
5 changes: 4 additions & 1 deletion AdminApi.Sdk/Endpoints/Metrics/MetricsEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ namespace Backbone.AdminApi.Sdk.Endpoints.Metrics;

public class MetricsEndpoint(EndpointClient client) : AdminApiEndpoint(client)
{
public async Task<ApiResponse<ListMetricsResponse>> GetAllMetrics() => await _client.Get<ListMetricsResponse>($"api/{API_VERSION}/Metrics");
public async Task<ApiResponse<ListMetricsResponse>> GetAllMetrics()
{
return await _client.Get<ListMetricsResponse>($"api/{API_VERSION}/Metrics");
}
}
19 changes: 12 additions & 7 deletions AdminApi.Sdk/Endpoints/Relationships/RelationshipsEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ namespace Backbone.AdminApi.Sdk.Endpoints.Relationships;
public class RelationshipsEndpoint(EndpointClient client) : AdminApiEndpoint(client)
{
public async Task<ApiResponse<ListRelationshipsResponse>> GetAllRelationships(PaginationFilter? pagination = null)
=> await _client.Get<ListRelationshipsResponse>($"api/{API_VERSION}/Relationships", null, pagination);
{
return await _client.Get<ListRelationshipsResponse>($"api/{API_VERSION}/Relationships", null, pagination);
}

public async Task<ApiResponse<ListRelationshipsResponse>> GetAllRelationships(string participant, PaginationFilter? pagination = null) => await _client
.Request<ListRelationshipsResponse>(HttpMethod.Get, $"api/{API_VERSION}/Relationships")
.Authenticate()
.WithPagination(pagination)
.AddQueryParameter("participant", participant)
.Execute();
public async Task<ApiResponse<ListRelationshipsResponse>> GetAllRelationships(string participant, PaginationFilter? pagination = null)
{
return await _client
.Request<ListRelationshipsResponse>(HttpMethod.Get, $"api/{API_VERSION}/Relationships")
.Authenticate()
.WithPagination(pagination)
.AddQueryParameter("participant", participant)
.Execute();
}
}
44 changes: 44 additions & 0 deletions AdminApi.Sdk/Services/IdentityCreationHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Backbone.AdminApi.Sdk.Endpoints.Challenges.Types;
using Backbone.AdminApi.Sdk.Endpoints.Identities.Types.Requests;
using Backbone.AdminApi.Sdk.Endpoints.Identities.Types.Responses;
using Backbone.BuildingBlocks.SDK.Crypto;
using Backbone.BuildingBlocks.SDK.Endpoints.Common.Types;
using Backbone.Crypto;
using Newtonsoft.Json;
using SignatureHelper = Backbone.Crypto.Implementations.SignatureHelper;

namespace Backbone.AdminApi.Sdk.Services;

public static class IdentityCreationHelper
{
public const string DEVICE_PASSWORD = "some-device-password";
public const string TEST_CLIENT_ID = "test";

public static async Task<ApiResponse<CreateIdentityResponse>> CreateIdentity(Client client)
{
var signatureHelper = SignatureHelper.CreateEd25519WithRawKeyFormat();

var identityKeyPair = signatureHelper.CreateKeyPair();

var challenge = await client.Challenges.CreateChallenge();
var serializedChallenge = JsonConvert.SerializeObject(challenge.Result);

var challengeSignature = signatureHelper.CreateSignature(identityKeyPair.PrivateKey, ConvertibleString.FromUtf8(serializedChallenge));
var signedChallenge = new SignedChallenge(serializedChallenge, challengeSignature);

var createIdentityPayload = new CreateIdentityRequest
{
ClientId = TEST_CLIENT_ID,
IdentityVersion = 1,
SignedChallenge = signedChallenge,
IdentityPublicKey = ConvertibleString.FromUtf8(JsonConvert.SerializeObject(new CryptoSignaturePublicKey
{
alg = CryptoExchangeAlgorithm.ECDH_X25519,
pub = identityKeyPair.PublicKey.Base64Representation
})).BytesRepresentation,
DevicePassword = DEVICE_PASSWORD
};

return await client.Identities.CreateIdentity(createIdentityPayload);
}
}
8 changes: 5 additions & 3 deletions AdminApi/src/AdminApi/AdminApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders" Version="0.21.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1"/>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
<PackageReference Include="ReHackt.Extensions.Options.Validation" Version="8.0.2" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
Expand All @@ -32,11 +32,13 @@
<PackageReference Include="Serilog.Sinks.Http" Version="9.0.0" />
<PackageReference Include="Serilog.Sinks.Seq" Version="7.0.1"/>
<!-- CAUTION: Do not upgrade 'AspNetCore.HealthChecks.NpgSql' before the following issue is resolved: https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/issues/1993 -->
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="8.0.1"/>
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="8.0.2"/>
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="8.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="8.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\BuildingBlocks\src\BuildingBlocks.API\BuildingBlocks.API.csproj" />
<ProjectReference Include="..\..\..\Modules\Challenges\src\Challenges.Application\Challenges.Application.csproj" />
<ProjectReference Include="..\..\..\Modules\Challenges\src\Challenges.Infrastructure\Challenges.Infrastructure.csproj" />
<ProjectReference Include="..\..\..\Modules\Devices\src\Devices.Application\Devices.Application.csproj" />
<ProjectReference Include="..\..\..\Modules\Devices\src\Devices.Infrastructure\Devices.Infrastructure.csproj" />
<ProjectReference Include="..\..\..\Infrastructure\Infrastructure.csproj" />
Expand Down
Loading

0 comments on commit 680c4d4

Please sign in to comment.