1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-26 12:55:17 +01:00

api get generating organization license

This commit is contained in:
Kyle Spearrin 2017-08-14 22:16:30 -04:00
parent 63a82336c6
commit abf68c1cea
3 changed files with 30 additions and 4 deletions

View File

@ -24,6 +24,7 @@ namespace Bit.Api.Controllers
private readonly IOrganizationUserRepository _organizationUserRepository; private readonly IOrganizationUserRepository _organizationUserRepository;
private readonly IOrganizationService _organizationService; private readonly IOrganizationService _organizationService;
private readonly IUserService _userService; private readonly IUserService _userService;
private readonly ILicensingService _licensingService;
private readonly CurrentContext _currentContext; private readonly CurrentContext _currentContext;
private readonly GlobalSettings _globalSettings; private readonly GlobalSettings _globalSettings;
private readonly UserManager<User> _userManager; private readonly UserManager<User> _userManager;
@ -33,6 +34,7 @@ namespace Bit.Api.Controllers
IOrganizationUserRepository organizationUserRepository, IOrganizationUserRepository organizationUserRepository,
IOrganizationService organizationService, IOrganizationService organizationService,
IUserService userService, IUserService userService,
ILicensingService licensingService,
CurrentContext currentContext, CurrentContext currentContext,
GlobalSettings globalSettings, GlobalSettings globalSettings,
UserManager<User> userManager) UserManager<User> userManager)
@ -43,6 +45,7 @@ namespace Bit.Api.Controllers
_userService = userService; _userService = userService;
_currentContext = currentContext; _currentContext = currentContext;
_userManager = userManager; _userManager = userManager;
_licensingService = licensingService;
_globalSettings = globalSettings; _globalSettings = globalSettings;
} }
@ -95,6 +98,24 @@ namespace Bit.Api.Controllers
} }
} }
[HttpGet("{id}/license")]
public async Task<OrganizationLicense> GetLicense(string id, [FromQuery]Guid installationId)
{
var orgIdGuid = new Guid(id);
if(!_currentContext.OrganizationOwner(orgIdGuid))
{
throw new NotFoundException();
}
var organization = await _organizationRepository.GetByIdAsync(orgIdGuid);
if(organization == null)
{
throw new NotFoundException();
}
return new OrganizationLicense(organization, installationId, _licensingService);
}
[HttpGet("")] [HttpGet("")]
public async Task<ListResponseModel<OrganizationResponseModel>> GetUser() public async Task<ListResponseModel<OrganizationResponseModel>> GetUser()
{ {

View File

@ -55,7 +55,6 @@ namespace Bit.Core.Models.Api
Utilities.CoreHelpers.ReadableBytesSize(organization.Storage.Value) : null; Utilities.CoreHelpers.ReadableBytesSize(organization.Storage.Value) : null;
StorageGb = organization.Storage.HasValue ? Math.Round(organization.Storage.Value / 1073741824D) : 0; // 1 GB StorageGb = organization.Storage.HasValue ? Math.Round(organization.Storage.Value / 1073741824D) : 0; // 1 GB
MaxStorageGb = organization.MaxStorageGb; MaxStorageGb = organization.MaxStorageGb;
// License = ...
Expiration = DateTime.UtcNow.AddYears(1); Expiration = DateTime.UtcNow.AddYears(1);
} }
@ -76,7 +75,6 @@ namespace Bit.Core.Models.Api
public BillingSubscription Subscription { get; set; } public BillingSubscription Subscription { get; set; }
public BillingInvoice UpcomingInvoice { get; set; } public BillingInvoice UpcomingInvoice { get; set; }
public IEnumerable<BillingCharge> Charges { get; set; } public IEnumerable<BillingCharge> Charges { get; set; }
public OrganizationLicense License { get; set; }
public DateTime? Expiration { get; set; } public DateTime? Expiration { get; set; }
} }
} }

View File

@ -1,5 +1,6 @@
using Bit.Core.Enums; using Bit.Core.Enums;
using Bit.Core.Models.Table; using Bit.Core.Models.Table;
using Bit.Core.Services;
using System; using System;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
@ -12,13 +13,15 @@ namespace Bit.Core.Models.Business
public OrganizationLicense() public OrganizationLicense()
{ } { }
public OrganizationLicense(Organization org, Guid installationId) public OrganizationLicense(Organization org, Guid installationId, ILicensingService licenseService)
{ {
LicenseKey = ""; LicenseKey = org.LicenseKey;
InstallationId = installationId; InstallationId = installationId;
Id = org.Id; Id = org.Id;
Name = org.Name; Name = org.Name;
Enabled = org.Enabled; Enabled = org.Enabled;
Plan = org.Plan;
PlanType = org.PlanType;
Seats = org.Seats; Seats = org.Seats;
MaxCollections = org.MaxCollections; MaxCollections = org.MaxCollections;
UseGroups = org.UseGroups; UseGroups = org.UseGroups;
@ -27,6 +30,10 @@ namespace Bit.Core.Models.Business
MaxStorageGb = org.MaxStorageGb; MaxStorageGb = org.MaxStorageGb;
SelfHost = org.SelfHost; SelfHost = org.SelfHost;
Version = 1; Version = 1;
Issued = DateTime.UtcNow;
Expires = Issued.AddYears(1);
Trial = false;
Signature = Convert.ToBase64String(licenseService.SignLicense(this));
} }
public string LicenseKey { get; set; } public string LicenseKey { get; set; }