Skip to content

Commit

Permalink
Archive devices endpoint (#25)
Browse files Browse the repository at this point in the history
* Null check for IP when creating Context

* Added ArchiveDevices endpoint

* Return user object from ArchiveDevices
  • Loading branch information
magnus-tretton37 committed Mar 27, 2019
1 parent b799fc4 commit df176a0
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Castle.Sdk/Castle.Sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</PropertyGroup>

<PropertyGroup>
<DocumentationFile>C:\Code\castle.net\src\Castle.Sdk\Castle.Sdk.xml</DocumentationFile>
<DocumentationFile>Castle.Sdk.xml</DocumentationFile>

<!-- Missing XML comment warning-->
<noWarn>1591</noWarn>
Expand Down
5 changes: 5 additions & 0 deletions src/Castle.Sdk/CastleClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ public async Task ImpersonateEnd(ImpersonateEndRequest request)
await TryRequest(() => _messageSender.Delete<VoidResponse>("/v1/impersonate", request));
}

public async Task<User> ArchiveDevices(string userId)
{
return await TryRequest(() => _messageSender.Put<User>($"/v1/users/{userId}/archive_devices"));
}

private async Task<T> TryRequest<T>(Func<Task<T>> request)
where T : new()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Castle.Sdk/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static RequestContext FromHttpRequest(Microsoft.AspNetCore.Http.HttpReque
{
ClientId = GetClientIdForCore(request.Headers, request.Cookies),
Headers = request.Headers.ToDictionary(x => x.Key, y => y.Value.FirstOrDefault()),
Ip = GetIpForCore(request.Headers, ipHeaders, () => request.HttpContext.Connection.RemoteIpAddress.ToString())
Ip = GetIpForCore(request.Headers, ipHeaders, () => request.HttpContext.Connection.RemoteIpAddress?.ToString())
};
}

Expand Down
11 changes: 11 additions & 0 deletions src/Castle.Sdk/Messages/Responses/Address.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Castle.Messages.Responses
{
public class Address
{
public object Street { get; set; }
public object City { get; set; }
public object PostalCode { get; set; }
public object Region { get; set; }
public object Country { get; set; }
}
}
36 changes: 36 additions & 0 deletions src/Castle.Sdk/Messages/Responses/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;

namespace Castle.Messages.Responses
{
public class User
{
public string Id { get; set; }

public DateTime CreatedAt { get; set; }

public DateTime UpdatedAt { get; set; }

public DateTime LastSeenAt { get; set; }

public DateTime? FlaggedAt { get; set; }

public float Risk { get; set; }

public int LeaksCount { get; set; }

public int DevicesCount { get; set; }

public string Email { get; set; }

public string Name { get; set; }

public string Username { get; set; }

public string Phone { get; set; }

public Address Address { get; set; }

public IDictionary<string, string> CustomAttributes { get; set; }
}
}
7 changes: 7 additions & 0 deletions src/Tests/When_calling_client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,12 @@ public void Should_end_impersonation(ImpersonateEndRequest request, CastleClient
Func<Task> act = async () => await sut.ImpersonateEnd(request);
act.Should().NotThrow();
}

[Theory, AutoFakeData(typeof(CastleConfigurationNoTrackCustomization))]
public void Should_archive_devices(string userId, CastleClient sut)
{
Func<Task> act = async () => await sut.ArchiveDevices(userId);
act.Should().NotThrow();
}
}
}

0 comments on commit df176a0

Please sign in to comment.