Skip to content

Commit

Permalink
Merge pull request #254 from OctopusDeploy/enh-accountscope
Browse files Browse the repository at this point in the history
Enh accountscope
  • Loading branch information
slewis74 authored May 10, 2018
2 parents 5f0d91b + 11df568 commit a843175
Show file tree
Hide file tree
Showing 37 changed files with 1,475 additions and 8 deletions.
41 changes: 41 additions & 0 deletions source/Octopus.Client.Tests/Conventions/AccountTypeConventions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Linq;
using System.Reflection;
using NUnit.Framework;
using Octopus.Client.Extensions;
using Octopus.Client.Model.Accounts;

namespace Octopus.Client.Tests.Conventions
{
[TestFixture]
public class AccountTypeConventions
{
private static readonly TypeInfo[] ExportedTypes = typeof(AccountResource).GetTypeInfo().Assembly.GetExportedTypes().Select(t => t.GetTypeInfo()).ToArray();

[Test]
public void AllAccountResourceTypeCanBeMappedToAnAccountType()
{
var derivedAccountTypes = ExportedTypes
.Where(t => !t.IsAbstract)
.Where(t => typeof(AccountResource).IsAssignableFrom(t))
.ToArray();

var typesThatCannotBeMapped = derivedAccountTypes.Where(t =>
{
try
{
t.DetermineAccountType();
return false;
}
catch (ArgumentException)
{
return true;
}
})
.ToArray();

if (typesThatCannotBeMapped.Any())
Assert.Fail($"The following AccountResource types cannot be mapped to an AccountType: " + typesThatCannotBeMapped.CommaSeperate());
}
}
}
4 changes: 2 additions & 2 deletions source/Octopus.Client.Tests/Conventions/ClientConventions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public class ClientConventions

private static readonly TypeInfo[] RepositoryInterfaceTypes = ExportedTypes
.Where(t => t.IsInterface && t.Name.EndsWith("Repository"))
.Where(t => t.AsType() != typeof(IOctopusAsyncRepository))
.Where(t => t.AsType() != typeof(IOctopusAsyncRepository) && t.AsType() != typeof(IResourceRepository))
#if SYNC_CLIENT
.Where(t => t.AsType() != typeof(IOctopusRepository))
.Where(t => t.AsType() != typeof(IOctopusRepository) && t.AsType() != typeof(Sync.IResourceRepository))
#endif
.ToArray();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,64 @@ Octopus.Client
}
Octopus.Client.Editors.Async
{
class AccountEditor`2
Octopus.Client.Editors.Async.IResourceEditor<TAccountResource, TAccountEditor>
Octopus.Client.Editors.Async.IResourceBuilder
{
.ctor(Octopus.Client.Repositories.Async.IAccountRepository)
Octopus.Client.Editors.Async.TAccountResource Instance { get; }
Task<TAccountEditor> CreateOrModify(String)
Octopus.Client.Editors.Async.TAccountEditor Customize(Action<TAccountResource>)
Task<TAccountEditor> FindByName(String)
Task<TAccountEditor> Save()
Task<AccountUsageResource> Usages()
}
class AmazonWebServicesAccountEditor
Octopus.Client.Editors.Async.IResourceEditor<AmazonWebServicesAccountResource, AmazonWebServicesAccountEditor>
Octopus.Client.Editors.Async.IResourceBuilder
Octopus.Client.Editors.Async.AccountEditor<AmazonWebServicesAccountResource, AmazonWebServicesAccountEditor>
{
.ctor(Octopus.Client.Repositories.Async.IAccountRepository)
}
class AmazonWebServicesRoleAccountEditor
Octopus.Client.Editors.Async.IResourceEditor<AmazonWebServicesRoleAccountResource, AmazonWebServicesRoleAccountEditor>
Octopus.Client.Editors.Async.IResourceBuilder
Octopus.Client.Editors.Async.AccountEditor<AmazonWebServicesRoleAccountResource, AmazonWebServicesRoleAccountEditor>
{
.ctor(Octopus.Client.Repositories.Async.IAccountRepository)
}
class AzureServicePrincipalAccountEditor
Octopus.Client.Editors.Async.IResourceEditor<AzureServicePrincipalAccountResource, AzureServicePrincipalAccountEditor>
Octopus.Client.Editors.Async.IResourceBuilder
Octopus.Client.Editors.Async.AccountEditor<AzureServicePrincipalAccountResource, AzureServicePrincipalAccountEditor>
{
.ctor(Octopus.Client.Repositories.Async.IAccountRepository)
Task<List<ResourceGroup>> ResourceGroups()
Task<List<AzureStorageAccount>> StorageAccounts()
Task<List<WebSite>> WebSites()
}
class AzureSubscriptionAccountEditor
Octopus.Client.Editors.Async.IResourceEditor<AzureSubscriptionAccountResource, AzureSubscriptionAccountEditor>
Octopus.Client.Editors.Async.IResourceBuilder
Octopus.Client.Editors.Async.AccountEditor<AzureSubscriptionAccountResource, AzureSubscriptionAccountEditor>
{
.ctor(Octopus.Client.Repositories.Async.IAccountRepository)
Task<List<AzureCloudService>> CloudServices(Octopus.Client.Model.Accounts.AzureSubscriptionAccountResource)
Task<List<AzureStorageAccount>> StorageAccounts(Octopus.Client.Model.Accounts.AzureSubscriptionAccountResource)
Task<List<WebSite>> WebSites(Octopus.Client.Model.Accounts.AzureSubscriptionAccountResource)
}
class CertificateEditor
Octopus.Client.Editors.Async.IResourceEditor<CertificateResource, CertificateEditor>
Octopus.Client.Editors.Async.IResourceBuilder
{
.ctor(Octopus.Client.Repositories.Async.ICertificateRepository)
Octopus.Client.Model.CertificateResource Instance { get; }
Task<CertificateEditor> Create(String, String)
Octopus.Client.Editors.Async.CertificateEditor Customize(Action<CertificateResource>)
Task<CertificateEditor> FindByName(String)
Task<CertificateEditor> Save()
Task<CertificateUsageResource> Usages()
}
class ChannelEditor
Octopus.Client.Editors.Async.IResourceEditor<ChannelResource, ChannelEditor>
Octopus.Client.Editors.Async.IResourceBuilder
Expand Down Expand Up @@ -390,6 +448,13 @@ Octopus.Client.Editors.Async
Task<ProjectTriggersEditor> Delete(String)
Task<ProjectTriggersEditor> SaveAll()
}
class SshKeyPairAccountEditor
Octopus.Client.Editors.Async.IResourceEditor<SshKeyPairAccountResource, SshKeyPairAccountEditor>
Octopus.Client.Editors.Async.IResourceBuilder
Octopus.Client.Editors.Async.AccountEditor<SshKeyPairAccountResource, SshKeyPairAccountEditor>
{
.ctor(Octopus.Client.Repositories.Async.IAccountRepository)
}
class SubscriptionEditor
Octopus.Client.Editors.Async.IResourceEditor<SubscriptionResource, SubscriptionEditor>
Octopus.Client.Editors.Async.IResourceBuilder
Expand Down Expand Up @@ -440,6 +505,13 @@ Octopus.Client.Editors.Async
Task<TenantVariablesEditor> Load()
Task<TenantVariablesEditor> Save()
}
class UsernamePasswordAccountEditor
Octopus.Client.Editors.Async.IResourceEditor<UsernamePasswordAccountResource, UsernamePasswordAccountEditor>
Octopus.Client.Editors.Async.IResourceBuilder
Octopus.Client.Editors.Async.AccountEditor<UsernamePasswordAccountResource, UsernamePasswordAccountEditor>
{
.ctor(Octopus.Client.Repositories.Async.IAccountRepository)
}
class VariableSetEditor
Octopus.Client.Editors.Async.IResourceEditor<VariableSetResource, VariableSetEditor>
Octopus.Client.Editors.Async.IResourceBuilder
Expand Down Expand Up @@ -631,6 +703,7 @@ Octopus.Client.Extensions
}
abstract class TypeExtensions
{
static Octopus.Client.Model.Accounts.AccountType DetermineAccountType(Type)
static Object GetDefault(Type)
}
abstract class UriExtensions
Expand Down Expand Up @@ -1160,6 +1233,13 @@ Octopus.Client.Model
String Thumbprint { get; }
Int32 Version { get; }
}
class CertificateUsageResource
{
.ctor()
ICollection<LibraryVariableSetResource> LibraryVariableSetUsages { get; set; }
ICollection<ProjectResource> ProjectUsages { get; set; }
ICollection<TenantResource> TenantUsages { get; set; }
}
class ChannelResource
Octopus.Client.Extensibility.IResource
Octopus.Client.Model.IAuditedResource
Expand Down Expand Up @@ -3314,6 +3394,7 @@ Octopus.Client.Model
Sensitive = 1
Certificate = 2
AmazonWebServicesAccount = 3
AzureAccount = 4
}
class VersioningStrategyResource
{
Expand Down Expand Up @@ -3392,6 +3473,12 @@ Octopus.Client.Model.Accounts
.ctor()
Octopus.Client.Model.Accounts.AccountType AccountType { get; }
}
class AzureCloudService
{
.ctor()
String Location { get; set; }
String Name { get; set; }
}
class AzureServicePrincipalAccountResource
Octopus.Client.Extensibility.IResource
Octopus.Client.Model.IAuditedResource
Expand All @@ -3407,6 +3494,24 @@ Octopus.Client.Model.Accounts
String ResourceManagementEndpointBaseUri { get; set; }
String SubscriptionNumber { get; set; }
String TenantId { get; set; }
class ResourceGroup
{
.ctor()
String Id { get; set; }
String Name { get; set; }
}
class WebSite
{
.ctor()
String Name { get; }
String ResourceGroup { get; set; }
}
}
class AzureStorageAccount
{
.ctor()
String Location { get; set; }
String Name { get; set; }
}
class AzureSubscriptionAccountResource
Octopus.Client.Extensibility.IResource
Expand All @@ -3421,6 +3526,19 @@ Octopus.Client.Model.Accounts
String CertificateThumbprint { get; set; }
String ServiceManagementEndpointBaseUri { get; set; }
String SubscriptionNumber { get; set; }
class WebSite
{
.ctor()
String Name { get; }
String ResourceGroup { get; set; }
String WebSpace { get; set; }
}
}
class ResourceGroup
{
.ctor()
String Id { get; set; }
String Name { get; set; }
}
class SshKeyPairAccountResource
Octopus.Client.Extensibility.IResource
Expand Down Expand Up @@ -3451,6 +3569,82 @@ Octopus.Client.Model.Accounts
Octopus.Client.Model.SensitiveValue Password { get; set; }
String Username { get; set; }
}
class WebSite
{
.ctor()
String Name { get; }
String ResourceGroup { get; set; }
}
class WebSite
{
.ctor()
String Name { get; }
String ResourceGroup { get; set; }
String WebSpace { get; set; }
}
}
Octopus.Client.Model.Accounts.Usages
{
class AccountUsageResource
Octopus.Client.Extensibility.IResource
Octopus.Client.Model.IAuditedResource
Octopus.Client.Model.Resource
{
.ctor()
ICollection<StepUsage> DeploymentProcesses { get; set; }
ICollection<LibraryVariableSetUsageEntry> LibraryVariableSets { get; set; }
ICollection<ProjectVariableSetUsage> ProjectVariableSets { get; set; }
ICollection<ReleaseUsage> Releases { get; set; }
ICollection<TargetUsageEntry> Targets { get; set; }
}
class LibraryVariableSetUsageEntry
{
.ctor()
String LibraryVariableSetId { get; set; }
String LibraryVariableSetName { get; set; }
}
class ProjectVariableSetUsage
{
.ctor()
Boolean IsCurrentlyBeingUsedInProject { get; set; }
String ProjectId { get; set; }
String ProjectName { get; set; }
String ProjectSlug { get; set; }
ICollection<ReleaseUsageEntry> Releases { get; set; }
}
class ReleaseUsage
{
.ctor()
String ProjectId { get; set; }
String ProjectName { get; set; }
ICollection<ReleaseUsageEntry> Releases { get; set; }
}
class ReleaseUsageEntry
{
.ctor()
String ReleaseId { get; set; }
String ReleaseVersion { get; set; }
}
class StepUsage
{
.ctor()
String ProjectId { get; set; }
String ProjectName { get; set; }
String ProjectSlug { get; set; }
ICollection<StepUsageEntry> Steps { get; set; }
}
class StepUsageEntry
{
.ctor()
String StepId { get; set; }
String StepName { get; set; }
}
class TargetUsageEntry
{
.ctor()
String TargetId { get; set; }
String TargetName { get; set; }
}
}
Octopus.Client.Model.DeploymentProcess
{
Expand Down Expand Up @@ -3516,6 +3710,7 @@ Octopus.Client.Model.Endpoints
.ctor()
String AccountId { get; set; }
Octopus.Client.Model.CommunicationStyle CommunicationStyle { get; }
String ResourceGroupName { get; set; }
String WebAppName { get; set; }
String WebSpaceName { get; set; }
}
Expand Down Expand Up @@ -4029,13 +4224,25 @@ Octopus.Client.Operations
Octopus.Client.Repositories.Async
{
interface IAccountRepository
Octopus.Client.Repositories.Async.IResourceRepository
Octopus.Client.Repositories.Async.ICreate<AccountResource>
Octopus.Client.Repositories.Async.IModify<AccountResource>
Octopus.Client.Repositories.Async.IDelete<AccountResource>
Octopus.Client.Repositories.Async.IGet<AccountResource>
Octopus.Client.Repositories.Async.IFindByName<AccountResource>
Octopus.Client.Repositories.Async.IPaginate<AccountResource>
{
Octopus.Client.Model.Accounts.AccountType DetermineAccountType()
Task<List<TAccount>> FindAllOfType(Object)
Task<TAccount> FindByNameOfType(String)
Task<List<TAccount>> FindByNamesOfType(IEnumerable<String>)
Task<List<TAccount>> FindManyOfType(Func<TAccount, Boolean>, Object)
Task<TAccount> FindOneOfType(Func<TAccount, Boolean>, Object)
Task<AccountUsageResource> GetAccountUsage(String)
Task<TAccount> GetOfType(String)
Task<List<TAccount>> GetOfType(String[])
Task PaginateOfType(Func<ResourceCollection<TAccount>, Boolean>, Object)
Task<TAccount> RefreshOfType(Octopus.Client.Repositories.Async.TAccount)
}
interface IActionTemplateRepository
Octopus.Client.Repositories.Async.ICreate<ActionTemplateResource>
Expand Down Expand Up @@ -4083,6 +4290,7 @@ Octopus.Client.Repositories.Async
Task<CertificateConfigurationResource> GetOctopusCertificate()
}
interface ICertificateRepository
Octopus.Client.Repositories.Async.IResourceRepository
Octopus.Client.Repositories.Async.IGet<CertificateResource>
Octopus.Client.Repositories.Async.IFindByName<CertificateResource>
Octopus.Client.Repositories.Async.IPaginate<CertificateResource>
Expand Down Expand Up @@ -4364,6 +4572,10 @@ Octopus.Client.Repositories.Async
Task<ReleaseResource> Modify(Octopus.Client.Model.ReleaseResource, Boolean)
Task<ReleaseResource> SnapshotVariables(Octopus.Client.Model.ReleaseResource)
}
interface IResourceRepository
{
Octopus.Client.IOctopusAsyncClient Client { get; }
}
interface IRetentionPolicyRepository
{
Task<TaskResource> ApplyNow()
Expand Down
Loading

0 comments on commit a843175

Please sign in to comment.