From 5d2f4e6ca4e6171b0f296764f20b54b5d97d2a10 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 16 Apr 2019 11:07:32 -0400 Subject: [PATCH] api models --- src/Core/Models/Request/AttachmentRequest.cs | 10 ++ .../Request/CipherCollectionsRequest.cs | 14 ++ .../Models/Request/CipherCreateRequest.cs | 18 +++ src/Core/Models/Request/CipherRequest.cs | 122 ++++++++++++++++++ src/Core/Models/Request/CipherShareRequest.cs | 18 +++ src/Core/Models/Request/FolderRequest.cs | 14 ++ .../Models/Request/PasswordHistoryRequest.cs | 10 ++ .../Models/Response/CollectionResponse.cs | 4 + src/Core/Models/Response/DomainsResponse.cs | 10 ++ .../Models/Response/GlobalDomainResponse.cs | 11 ++ src/Core/Models/Response/SyncResponse.cs | 13 ++ 11 files changed, 244 insertions(+) create mode 100644 src/Core/Models/Request/AttachmentRequest.cs create mode 100644 src/Core/Models/Request/CipherCollectionsRequest.cs create mode 100644 src/Core/Models/Request/CipherCreateRequest.cs create mode 100644 src/Core/Models/Request/CipherRequest.cs create mode 100644 src/Core/Models/Request/CipherShareRequest.cs create mode 100644 src/Core/Models/Request/FolderRequest.cs create mode 100644 src/Core/Models/Request/PasswordHistoryRequest.cs create mode 100644 src/Core/Models/Response/DomainsResponse.cs create mode 100644 src/Core/Models/Response/GlobalDomainResponse.cs create mode 100644 src/Core/Models/Response/SyncResponse.cs diff --git a/src/Core/Models/Request/AttachmentRequest.cs b/src/Core/Models/Request/AttachmentRequest.cs new file mode 100644 index 000000000..96837545f --- /dev/null +++ b/src/Core/Models/Request/AttachmentRequest.cs @@ -0,0 +1,10 @@ +using System; + +namespace Bit.Core.Models.Request +{ + public class AttachmentRequest + { + public string FileName { get; set; } + public string Key { get; set; } + } +} diff --git a/src/Core/Models/Request/CipherCollectionsRequest.cs b/src/Core/Models/Request/CipherCollectionsRequest.cs new file mode 100644 index 000000000..f5659ef73 --- /dev/null +++ b/src/Core/Models/Request/CipherCollectionsRequest.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; + +namespace Bit.Core.Models.Request +{ + public class CipherCollectionsRequest + { + public CipherCollectionsRequest(List collectionIds) + { + CollectionIds = collectionIds ?? new List(); + } + + public List CollectionIds { get; set; } + } +} diff --git a/src/Core/Models/Request/CipherCreateRequest.cs b/src/Core/Models/Request/CipherCreateRequest.cs new file mode 100644 index 000000000..aefb9b340 --- /dev/null +++ b/src/Core/Models/Request/CipherCreateRequest.cs @@ -0,0 +1,18 @@ +using Bit.Core.Models.Domain; +using System.Collections.Generic; +using System.Linq; + +namespace Bit.Core.Models.Request +{ + public class CipherCreateRequest + { + public CipherCreateRequest(Cipher cipher) + { + Cipher = new CipherRequest(cipher); + CollectionIds = cipher.CollectionIds?.ToList(); + } + + public CipherRequest Cipher { get; set; } + public List CollectionIds { get; set; } + } +} diff --git a/src/Core/Models/Request/CipherRequest.cs b/src/Core/Models/Request/CipherRequest.cs new file mode 100644 index 000000000..49fba9c9a --- /dev/null +++ b/src/Core/Models/Request/CipherRequest.cs @@ -0,0 +1,122 @@ +using Bit.Core.Enums; +using Bit.Core.Models.Api; +using Bit.Core.Models.Domain; +using System.Collections.Generic; +using System.Linq; + +namespace Bit.Core.Models.Request +{ + public class CipherRequest + { + public CipherRequest(Cipher cipher) + { + Type = cipher.Type; + OrganizationId = cipher.OrganizationId; + FolderId = cipher.FolderId; + Name = cipher.Name?.EncryptedString; + Notes = cipher.Notes?.EncryptedString; + Favorite = cipher.Favorite; + + switch(Type) + { + case CipherType.Login: + Login = new LoginApi + { + Uris = cipher.Login.Uris?.Select( + u => new LoginUriApi { Match = u.Match, Uri = u.Uri?.EncryptedString }).ToList(), + Username = cipher.Login.Username?.EncryptedString, + Password = cipher.Login.Password?.EncryptedString, + PasswordRevisionDate = cipher.Login.PasswordRevisionDate, + Totp = cipher.Login.Totp?.EncryptedString + }; + break; + case CipherType.Card: + Card = new CardApi + { + CardholderName = cipher.Card.CardholderName?.EncryptedString, + Brand = cipher.Card.Brand?.EncryptedString, + Number = cipher.Card.Number?.EncryptedString, + ExpMonth = cipher.Card.ExpMonth?.EncryptedString, + ExpYear = cipher.Card.ExpYear?.EncryptedString, + Code = cipher.Card.Code?.EncryptedString + }; + break; + case CipherType.Identity: + Identity = new IdentityApi + { + Title = cipher.Identity.Title?.EncryptedString, + FirstName = cipher.Identity.FirstName?.EncryptedString, + MiddleName = cipher.Identity.MiddleName?.EncryptedString, + LastName = cipher.Identity.LastName?.EncryptedString, + Address1 = cipher.Identity.Address1?.EncryptedString, + Address2 = cipher.Identity.Address2?.EncryptedString, + Address3 = cipher.Identity.Address3?.EncryptedString, + City = cipher.Identity.City?.EncryptedString, + State = cipher.Identity.State?.EncryptedString, + PostalCode = cipher.Identity.PostalCode?.EncryptedString, + Country = cipher.Identity.Country?.EncryptedString, + Company = cipher.Identity.Company?.EncryptedString, + Email = cipher.Identity.Email?.EncryptedString, + Phone = cipher.Identity.Phone?.EncryptedString, + SSN = cipher.Identity.SSN?.EncryptedString, + Username = cipher.Identity.Username?.EncryptedString, + PassportNumber = cipher.Identity.PassportNumber?.EncryptedString, + LicenseNumber = cipher.Identity.LicenseNumber?.EncryptedString + }; + break; + case CipherType.SecureNote: + SecureNote = new SecureNoteApi + { + Type = cipher.SecureNote.Type + }; + break; + default: + break; + } + + Fields = cipher.Fields?.Select(f => new FieldApi + { + Type = f.Type, + Name = f.Name?.EncryptedString, + Value = f.Value?.EncryptedString + }).ToList(); + + PasswordHistory = cipher.PasswordHistory?.Select(ph => new PasswordHistoryRequest + { + Password = ph.Password?.EncryptedString, + LastUsedDate = ph.LastUsedDate + }).ToList(); + + if(cipher.Attachments != null) + { + Attachments = new Dictionary(); + Attachments2 = new Dictionary(); + foreach(var attachment in cipher.Attachments) + { + var fileName = attachment.FileName?.EncryptedString; + Attachments.Add(attachment.Id, fileName); + Attachments2.Add(attachment.Id, new AttachmentRequest + { + FileName = fileName, + Key = attachment.Key?.EncryptedString + }); + } + } + } + + public CipherType Type { get; set; } + public string OrganizationId { get; set; } + public string FolderId { get; set; } + public string Name { get; set; } + public string Notes { get; set; } + public bool Favorite { get; set; } + public LoginApi Login { get; set; } + public SecureNoteApi SecureNote { get; set; } + public CardApi Card { get; set; } + public IdentityApi Identity { get; set; } + public List Fields { get; set; } + public List PasswordHistory { get; set; } + public Dictionary Attachments { get; set; } + public Dictionary Attachments2 { get; set; } + } +} diff --git a/src/Core/Models/Request/CipherShareRequest.cs b/src/Core/Models/Request/CipherShareRequest.cs new file mode 100644 index 000000000..4fb4f3761 --- /dev/null +++ b/src/Core/Models/Request/CipherShareRequest.cs @@ -0,0 +1,18 @@ +using Bit.Core.Models.Domain; +using System.Collections.Generic; +using System.Linq; + +namespace Bit.Core.Models.Request +{ + public class CipherShareRequest + { + public CipherShareRequest(Cipher cipher) + { + Cipher = new CipherRequest(cipher); + CollectionIds = cipher.CollectionIds?.ToList(); + } + + public CipherRequest Cipher { get; set; } + public List CollectionIds { get; set; } + } +} diff --git a/src/Core/Models/Request/FolderRequest.cs b/src/Core/Models/Request/FolderRequest.cs new file mode 100644 index 000000000..a09b5134e --- /dev/null +++ b/src/Core/Models/Request/FolderRequest.cs @@ -0,0 +1,14 @@ +using Bit.Core.Models.Domain; + +namespace Bit.Core.Models.Request +{ + public class FolderRequest + { + public FolderRequest(Folder folder) + { + Name = folder.Name?.EncryptedString; + } + + public string Name { get; set; } + } +} diff --git a/src/Core/Models/Request/PasswordHistoryRequest.cs b/src/Core/Models/Request/PasswordHistoryRequest.cs new file mode 100644 index 000000000..33e323890 --- /dev/null +++ b/src/Core/Models/Request/PasswordHistoryRequest.cs @@ -0,0 +1,10 @@ +using System; + +namespace Bit.Core.Models.Request +{ + public class PasswordHistoryRequest + { + public string Password { get; set; } + public DateTime? LastUsedDate { get; set; } + } +} diff --git a/src/Core/Models/Response/CollectionResponse.cs b/src/Core/Models/Response/CollectionResponse.cs index f60a065ba..7895ecb7f 100644 --- a/src/Core/Models/Response/CollectionResponse.cs +++ b/src/Core/Models/Response/CollectionResponse.cs @@ -6,6 +6,10 @@ public string OrganizationId { get; set; } public string Name { get; set; } public string ExternalId { get; set; } + } + + public class CollectionDetailsResponse : CollectionResponse + { public bool ReadOnly { get; set; } } } diff --git a/src/Core/Models/Response/DomainsResponse.cs b/src/Core/Models/Response/DomainsResponse.cs new file mode 100644 index 000000000..ecdd0909c --- /dev/null +++ b/src/Core/Models/Response/DomainsResponse.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; + +namespace Bit.Core.Models.Response +{ + public class DomainsResponse + { + public List> EquivalentDomains { get; set; } + public List GlobalEquivalentDomains { get; set; } = new List(); + } +} diff --git a/src/Core/Models/Response/GlobalDomainResponse.cs b/src/Core/Models/Response/GlobalDomainResponse.cs new file mode 100644 index 000000000..354a9cf4b --- /dev/null +++ b/src/Core/Models/Response/GlobalDomainResponse.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; + +namespace Bit.Core.Models.Response +{ + public class GlobalDomainResponse + { + public int Type { get; set; } + public List Domains { get; set; } + public bool Excluded { get; set; } + } +} diff --git a/src/Core/Models/Response/SyncResponse.cs b/src/Core/Models/Response/SyncResponse.cs new file mode 100644 index 000000000..b2f12f229 --- /dev/null +++ b/src/Core/Models/Response/SyncResponse.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; + +namespace Bit.Core.Models.Response +{ + public class SyncResponse + { + public ProfileResponse Profile { get; set; } + public List Folders { get; set; } = new List(); + public List Collections { get; set; } = new List(); + public List Ciphers { get; set; } = new List(); + public DomainsResponse Domains { get; set; } + } +}