Skip to content

Commit

Permalink
Old stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
addisonbeck committed Nov 26, 2024
1 parent 84f7fa6 commit 15200dd
Show file tree
Hide file tree
Showing 23 changed files with 98 additions and 64 deletions.
1 change: 1 addition & 0 deletions src/Admin/Controllers/ToolsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Bit.Core.Entities;
using Bit.Core.Models.BitStripe;
using Bit.Core.OrganizationFeatures.OrganizationLicenses.Interfaces;
using Bit.Core.Platform;
using Bit.Core.Repositories;
using Bit.Core.Services;
using Bit.Core.Settings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Bit.Api.Controllers;
namespace Bit.Api.Platform;

/// <summary>
/// Routes for push relay: functionality that facilitates communication
/// between self hosted organizations and Bitwarden cloud.
/// </summary>
[Route("push")]
[Authorize("Push")]
[SelfHosted(NotSelfHostedOnly = true)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.ComponentModel.DataAnnotations;
using Bit.Core.Entities;
using Bit.Core.Platform;
using Bit.Core.Utilities;

namespace Bit.Api.Models.Request;
namespace Bit.Api.Platform;

public class InstallationRequestModel
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Bit.Core.Entities;
using Bit.Core.Models.Api;
using Bit.Core.Models.Api;
using Bit.Core.Platform;

namespace Bit.Api.Models.Response;
namespace Bit.Api.Platform;

public class InstallationResponseModel : ResponseModel
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using Bit.Api.Models.Request;
using Bit.Api.Models.Response;
using Bit.Core.Exceptions;
using Bit.Core.Repositories;
using Bit.Core.Exceptions;
using Bit.Core.Platform;
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Bit.Api.Controllers;
namespace Bit.Api.Platform;

[Route("installations")]
[SelfHosted(NotSelfHostedOnly = true)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Bit.Core.Exceptions;
using Bit.Core.Models.Business;
using Bit.Core.OrganizationFeatures.OrganizationLicenses.Interfaces;
using Bit.Core.Repositories;
using Bit.Core.Platform;
using Bit.Core.Services;

namespace Bit.Core.OrganizationFeatures.OrganizationLicenses;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
using System.ComponentModel.DataAnnotations;
using Bit.Core.Entities;
using Bit.Core.Utilities;

#nullable enable

namespace Bit.Core.Entities;
namespace Bit.Core.Platform;

/// <summary>
/// The base entity for the SQL table `dbo.Installation`. Used to store
/// information pertinent to self hosted Bitwarden installations.
/// </summary>
public class Installation : ITableObject<Guid>
{
public Guid Id { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Bit.Core.Repositories;

#nullable enable

namespace Bit.Core.Platform;

/// <summary>
/// The CRUD repository interface for communicating with `dbo.Installation`,
/// which is used to store information pertinent to self-hosted
/// installations.
/// </summary>
/// <remarks>
/// This interface is implemented by `InstallationRepository` in the Dapper
/// and Entity Framework projects.
/// </remarks>
/// <seealso cref="T:Bit.Infrastructure.Dapper.Platform.Installations.Repositories.InstallationRepository"/>
public interface IInstallationRepository : IRepository<Installation, Guid>
{
}
9 changes: 0 additions & 9 deletions src/Core/Repositories/IInstallationRepository.cs

This file was deleted.

1 change: 1 addition & 0 deletions src/Identity/IdentityServer/ClientStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Bit.Core.Enums;
using Bit.Core.Identity;
using Bit.Core.IdentityServer;
using Bit.Core.Platform;
using Bit.Core.Repositories;
using Bit.Core.SecretsManager.Models.Data;
using Bit.Core.SecretsManager.Repositories;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Bit.Core.Auth.Repositories;
using Bit.Core.Billing.Repositories;
using Bit.Core.NotificationCenter.Repositories;
using Bit.Core.Platform;
using Bit.Core.Repositories;
using Bit.Core.SecretsManager.Repositories;
using Bit.Core.Tools.Repositories;
Expand All @@ -10,6 +11,7 @@
using Bit.Infrastructure.Dapper.Auth.Repositories;
using Bit.Infrastructure.Dapper.Billing.Repositories;
using Bit.Infrastructure.Dapper.NotificationCenter.Repositories;
using Bit.Infrastructure.Dapper.Platform;
using Bit.Infrastructure.Dapper.Repositories;
using Bit.Infrastructure.Dapper.SecretsManager.Repositories;
using Bit.Infrastructure.Dapper.Tools.Repositories;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
using Bit.Core.Entities;
using Bit.Core.Repositories;
using Bit.Core.Platform;
using Bit.Core.Settings;
using Bit.Infrastructure.Dapper.Repositories;

#nullable enable

namespace Bit.Infrastructure.Dapper.Repositories;
namespace Bit.Infrastructure.Dapper.Platform;

/// <summary>
/// The CRUD repository for communicating with `dbo.Installation`.
/// </summary>
/// <remarks>
/// If referencing: you probably want the interface `IInstallationRepository`
/// instead of directly calling this class.
/// </remarks>
/// <seealso cref="IInstallationRepository"/>
public class InstallationRepository : Repository<Installation, Guid>, IInstallationRepository
{
public InstallationRepository(GlobalSettings globalSettings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Bit.Core.Billing.Repositories;
using Bit.Core.Enums;
using Bit.Core.NotificationCenter.Repositories;
using Bit.Core.Platform;
using Bit.Core.Repositories;
using Bit.Core.SecretsManager.Repositories;
using Bit.Core.Tools.Repositories;
Expand All @@ -11,6 +12,7 @@
using Bit.Infrastructure.EntityFramework.Auth.Repositories;
using Bit.Infrastructure.EntityFramework.Billing.Repositories;
using Bit.Infrastructure.EntityFramework.NotificationCenter.Repositories;
using Bit.Infrastructure.EntityFramework.Platform;
using Bit.Infrastructure.EntityFramework.Repositories;
using Bit.Infrastructure.EntityFramework.SecretsManager.Repositories;
using Bit.Infrastructure.EntityFramework.Tools.Repositories;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using AutoMapper;
using C = Bit.Core.Platform;

namespace Bit.Infrastructure.EntityFramework.Models;
namespace Bit.Infrastructure.EntityFramework.Platform;

public class Installation : Core.Entities.Installation
public class Installation : C.Installation
{
// Shadow property - to be introduced by https://bitwarden.atlassian.net/browse/PM-11129
// This isn't a value or entity used by self hosted servers, but it's
Expand All @@ -14,10 +15,10 @@ public class InstallationMapperProfile : Profile
{
public InstallationMapperProfile()
{
CreateMap<Core.Entities.Installation, Installation>()
CreateMap<C.Installation, Installation>()
// Shadow property - to be introduced by https://bitwarden.atlassian.net/browse/PM-11129
.ForMember(i => i.LastActivityDate, opt => opt.Ignore())
.ReverseMap();
CreateMap<Core.Entities.Installation, Installation>().ReverseMap();
CreateMap<C.Installation, Installation>().ReverseMap();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using AutoMapper;
using Bit.Infrastructure.EntityFramework.Repositories;
using Microsoft.Extensions.DependencyInjection;
using C = Bit.Core.Platform;
using Ef = Bit.Infrastructure.EntityFramework.Platform;

#nullable enable

namespace Bit.Infrastructure.EntityFramework.Platform;

public class InstallationRepository : Repository<C.Installation, Ef.Installation, Guid>, C.IInstallationRepository
{
public InstallationRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper)
: base(serviceScopeFactory, mapper, (DatabaseContext context) => context.Installations)
{ }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Bit.Infrastructure.EntityFramework.Converters;
using Bit.Infrastructure.EntityFramework.Models;
using Bit.Infrastructure.EntityFramework.NotificationCenter.Models;
using Bit.Infrastructure.EntityFramework.Platform;
using Bit.Infrastructure.EntityFramework.SecretsManager.Models;
using Bit.Infrastructure.EntityFramework.Tools.Models;
using Bit.Infrastructure.EntityFramework.Vault.Models;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using Bit.Core.AdminConsole.Entities;
using Bit.Core.Entities;
using Bit.Core.Enums;
using Bit.Core.Exceptions;
using Bit.Core.Models.Business;
using Bit.Core.OrganizationFeatures.OrganizationLicenses;
using Bit.Core.Repositories;
using Bit.Core.Platform;
using Bit.Core.Services;
using Bit.Core.Test.AutoFixture;
using Bit.Test.Common.AutoFixture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Bit.Core.AdminConsole.Enums;
using Bit.Core.AdminConsole.Repositories;
using Bit.Core.Enums;
using Bit.Core.Platform;
using Bit.Core.Repositories;
using Bit.Identity.IdentityServer;
using Bit.Identity.Models.Request.Accounts;
Expand Down Expand Up @@ -462,7 +463,7 @@ public async Task TokenEndpoint_GrantTypeClientCredentials_AsOrganization_OrgDoe
}

[Theory, BitAutoData]
public async Task TokenEndpoint_GrantTypeClientCredentials_AsInstallation_InstallationExists_Succeeds(Bit.Core.Entities.Installation installation)
public async Task TokenEndpoint_GrantTypeClientCredentials_AsInstallation_InstallationExists_Succeeds(Installation installation)
{
var installationRepo = _factory.Services.GetRequiredService<IInstallationRepository>();
installation = await installationRepo.CreateAsync(installation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Bit.Infrastructure.EntityFramework.AdminConsole.Models.Provider;
using Bit.Infrastructure.EntityFramework.Auth.Models;
using Bit.Infrastructure.EntityFramework.Models;
using Bit.Infrastructure.EntityFramework.Platform;
using Bit.Infrastructure.EntityFramework.Repositories;
using Bit.Infrastructure.EntityFramework.Tools.Models;
using Bit.Infrastructure.EntityFramework.Vault.Models;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using AutoFixture;
using AutoFixture.Kernel;
using Bit.Core.Entities;
using Bit.Infrastructure.EntityFramework.Repositories;
using Bit.Test.Common.AutoFixture;
using Bit.Test.Common.AutoFixture.Attributes;
using C = Bit.Core.Platform;
using Ef = Bit.Infrastructure.EntityFramework.Platform;

namespace Bit.Infrastructure.EFIntegration.Test.AutoFixture;

Expand All @@ -17,13 +17,13 @@ public object Create(object request, ISpecimenContext context)
}

var type = request as Type;
if (type == null || type != typeof(Installation))
if (type == null || type != typeof(C.Installation))
{
return new NoSpecimen();
}

var fixture = new Fixture();
var obj = fixture.WithAutoNSubstitutions().Create<Installation>();
var obj = fixture.WithAutoNSubstitutions().Create<C.Installation>();
return obj;
}
}
Expand All @@ -35,7 +35,7 @@ public void Customize(IFixture fixture)
fixture.Customizations.Add(new IgnoreVirtualMembersCustomization());
fixture.Customizations.Add(new GlobalSettingsBuilder());
fixture.Customizations.Add(new InstallationBuilder());
fixture.Customizations.Add(new EfRepositoryListBuilder<InstallationRepository>());
fixture.Customizations.Add(new EfRepositoryListBuilder<Ef.InstallationRepository>());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using Bit.Core.Entities;
using Bit.Core.Platform;

namespace Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
namespace Bit.Infrastructure.EFIntegration.Test.Platform;

public class InstallationCompare : IEqualityComparer<Installation>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
using Bit.Core.Entities;
using Bit.Core.Test.AutoFixture.Attributes;
using Bit.Core.Test.AutoFixture.Attributes;
using Bit.Infrastructure.EFIntegration.Test.AutoFixture;
using Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
using Xunit;
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
using C = Bit.Core.Platform;
using D = Bit.Infrastructure.Dapper.Platform;
using Ef = Bit.Infrastructure.EntityFramework.Platform;

namespace Bit.Infrastructure.EFIntegration.Test.Repositories;
namespace Bit.Infrastructure.EFIntegration.Test.Platform;

public class InstallationRepositoryTests
{
[CiSkippedTheory, EfInstallationAutoData]
public async Task CreateAsync_Works_DataMatches(
Installation installation,
C.Installation installation,
InstallationCompare equalityComparer,
List<EfRepo.InstallationRepository> suts,
SqlRepo.InstallationRepository sqlInstallationRepo
List<Ef.InstallationRepository> suts,
D.InstallationRepository sqlInstallationRepo
)
{
var savedInstallations = new List<Installation>();
var savedInstallations = new List<C.Installation>();
foreach (var sut in suts)
{
var postEfInstallation = await sut.CreateAsync(installation);
Expand Down

0 comments on commit 15200dd

Please sign in to comment.