Skip to content

Commit

Permalink
Add Azure OIDC support (#762)
Browse files Browse the repository at this point in the history
  • Loading branch information
veochen-octopus authored Sep 21, 2023
1 parent dd9550f commit fc9dd57
Show file tree
Hide file tree
Showing 8 changed files with 316 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,17 @@ Octopus.Client.Editors
{
.ctor(Octopus.Client.Repositories.IAccountRepository)
}
class AzureOidcAccountEditor
Octopus.Client.Editors.IResourceEditor<AzureOidcAccountResource, AzureOidcAccountEditor>
Octopus.Client.Editors.IResourceBuilder
Octopus.Client.Editors.AccountEditor<AzureOidcAccountResource, AzureOidcAccountEditor>
{
.ctor(Octopus.Client.Repositories.IAccountRepository)
List<ResourceGroup> ResourceGroups()
List<AzureStorageAccount> StorageAccounts()
List<WebSite> WebSites()
List<WebSlot> WebSiteSlots(Octopus.Client.Model.Accounts.WebSite)
}
class AzureServicePrincipalAccountEditor
Octopus.Client.Editors.IResourceEditor<AzureServicePrincipalAccountResource, AzureServicePrincipalAccountEditor>
Octopus.Client.Editors.IResourceBuilder
Expand Down Expand Up @@ -1051,6 +1062,17 @@ Octopus.Client.Editors.Async
{
.ctor(Octopus.Client.Repositories.Async.IAccountRepository)
}
class AzureOidcAccountEditor
Octopus.Client.Editors.Async.IResourceEditor<AzureSubscriptionAccountResource, AzureOidcAccountEditor>
Octopus.Client.Editors.Async.IResourceBuilder
Octopus.Client.Editors.Async.AccountEditor<AzureSubscriptionAccountResource, AzureOidcAccountEditor>
{
.ctor(Octopus.Client.Repositories.Async.IAccountRepository)
Task<List<ResourceGroup>> ResourceGroups()
Task<List<AzureStorageAccount>> StorageAccounts()
Task<List<WebSite>> WebSites()
Task<List<WebSlot>> WebSlots(Octopus.Client.Model.Accounts.WebSite)
}
class AzureServicePrincipalAccountEditor
Octopus.Client.Editors.Async.IResourceEditor<AzureServicePrincipalAccountResource, AzureServicePrincipalAccountEditor>
Octopus.Client.Editors.Async.IResourceBuilder
Expand Down Expand Up @@ -5890,6 +5912,7 @@ Octopus.Client.Model.Accounts
AmazonWebServicesRoleAccount = 6
Token = 7
GoogleCloudAccount = 8
AzureOidc = 9
}
class AmazonWebServicesAccountResource
Octopus.Client.Extensibility.IResource
Expand All @@ -5904,6 +5927,48 @@ Octopus.Client.Model.Accounts
Octopus.Client.Model.Accounts.AccountType AccountType { get; }
Octopus.Client.Model.SensitiveValue SecretKey { get; set; }
}
class AzureOidcAccountResource
Octopus.Client.Extensibility.IResource
Octopus.Client.Model.IAuditedResource
Octopus.Client.Extensibility.INamedResource
Octopus.Client.Extensibility.IHaveSpaceResource
Octopus.Client.Model.IHaveSlugResource
Octopus.Client.Model.Accounts.AccountResource
{
.ctor()
String[] AccountTestSubjectKeys { get; set; }
Octopus.Client.Model.Accounts.AccountType AccountType { get; }
String ActiveDirectoryEndpointBaseUri { get; set; }
String Audience { get; set; }
String AzureEnvironment { get; set; }
String ClientId { get; set; }
String[] DeploymentSubjectKeys { get; set; }
String[] HealthCheckSubjectKeys { get; set; }
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; set; }
String ResourceGroup { get; set; }
String WebSpace { get; set; }
}
class WebSlot
{
.ctor()
String Name { get; set; }
String Region { get; set; }
String ResourceGroupName { get; set; }
String Site { get; set; }
}
}
class AzureServicePrincipalAccountResource
Octopus.Client.Extensibility.IResource
Octopus.Client.Model.IAuditedResource
Expand Down Expand Up @@ -5999,6 +6064,12 @@ Octopus.Client.Model.Accounts
String Id { get; set; }
String Name { get; set; }
}
class ResourceGroup
{
.ctor()
String Id { get; set; }
String Name { get; set; }
}
class SshKeyPairAccountResource
Octopus.Client.Extensibility.IResource
Octopus.Client.Model.IAuditedResource
Expand Down Expand Up @@ -6058,6 +6129,21 @@ Octopus.Client.Model.Accounts
String ResourceGroup { get; set; }
String WebSpace { get; set; }
}
class WebSite
{
.ctor()
String Name { get; set; }
String ResourceGroup { get; set; }
String WebSpace { get; set; }
}
class WebSlot
{
.ctor()
String Name { get; set; }
String Region { get; set; }
String ResourceGroupName { get; set; }
String Site { get; set; }
}
class WebSlot
{
.ctor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,17 @@ Octopus.Client.Editors
{
.ctor(Octopus.Client.Repositories.IAccountRepository)
}
class AzureOidcAccountEditor
Octopus.Client.Editors.IResourceEditor<AzureOidcAccountResource, AzureOidcAccountEditor>
Octopus.Client.Editors.IResourceBuilder
Octopus.Client.Editors.AccountEditor<AzureOidcAccountResource, AzureOidcAccountEditor>
{
.ctor(Octopus.Client.Repositories.IAccountRepository)
List<ResourceGroup> ResourceGroups()
List<AzureStorageAccount> StorageAccounts()
List<WebSite> WebSites()
List<WebSlot> WebSiteSlots(Octopus.Client.Model.Accounts.WebSite)
}
class AzureServicePrincipalAccountEditor
Octopus.Client.Editors.IResourceEditor<AzureServicePrincipalAccountResource, AzureServicePrincipalAccountEditor>
Octopus.Client.Editors.IResourceBuilder
Expand Down Expand Up @@ -1052,6 +1063,17 @@ Octopus.Client.Editors.Async
{
.ctor(Octopus.Client.Repositories.Async.IAccountRepository)
}
class AzureOidcAccountEditor
Octopus.Client.Editors.Async.IResourceEditor<AzureSubscriptionAccountResource, AzureOidcAccountEditor>
Octopus.Client.Editors.Async.IResourceBuilder
Octopus.Client.Editors.Async.AccountEditor<AzureSubscriptionAccountResource, AzureOidcAccountEditor>
{
.ctor(Octopus.Client.Repositories.Async.IAccountRepository)
Task<List<ResourceGroup>> ResourceGroups()
Task<List<AzureStorageAccount>> StorageAccounts()
Task<List<WebSite>> WebSites()
Task<List<WebSlot>> WebSlots(Octopus.Client.Model.Accounts.WebSite)
}
class AzureServicePrincipalAccountEditor
Octopus.Client.Editors.Async.IResourceEditor<AzureServicePrincipalAccountResource, AzureServicePrincipalAccountEditor>
Octopus.Client.Editors.Async.IResourceBuilder
Expand Down Expand Up @@ -5913,6 +5935,7 @@ Octopus.Client.Model.Accounts
AmazonWebServicesRoleAccount = 6
Token = 7
GoogleCloudAccount = 8
AzureOidc = 9
}
class AmazonWebServicesAccountResource
Octopus.Client.Extensibility.IResource
Expand All @@ -5927,6 +5950,48 @@ Octopus.Client.Model.Accounts
Octopus.Client.Model.Accounts.AccountType AccountType { get; }
Octopus.Client.Model.SensitiveValue SecretKey { get; set; }
}
class AzureOidcAccountResource
Octopus.Client.Extensibility.IResource
Octopus.Client.Model.IAuditedResource
Octopus.Client.Extensibility.INamedResource
Octopus.Client.Extensibility.IHaveSpaceResource
Octopus.Client.Model.IHaveSlugResource
Octopus.Client.Model.Accounts.AccountResource
{
.ctor()
String[] AccountTestSubjectKeys { get; set; }
Octopus.Client.Model.Accounts.AccountType AccountType { get; }
String ActiveDirectoryEndpointBaseUri { get; set; }
String Audience { get; set; }
String AzureEnvironment { get; set; }
String ClientId { get; set; }
String[] DeploymentSubjectKeys { get; set; }
String[] HealthCheckSubjectKeys { get; set; }
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; set; }
String ResourceGroup { get; set; }
String WebSpace { get; set; }
}
class WebSlot
{
.ctor()
String Name { get; set; }
String Region { get; set; }
String ResourceGroupName { get; set; }
String Site { get; set; }
}
}
class AzureServicePrincipalAccountResource
Octopus.Client.Extensibility.IResource
Octopus.Client.Model.IAuditedResource
Expand Down Expand Up @@ -6022,6 +6087,12 @@ Octopus.Client.Model.Accounts
String Id { get; set; }
String Name { get; set; }
}
class ResourceGroup
{
.ctor()
String Id { get; set; }
String Name { get; set; }
}
class SshKeyPairAccountResource
Octopus.Client.Extensibility.IResource
Octopus.Client.Model.IAuditedResource
Expand Down Expand Up @@ -6082,6 +6153,21 @@ Octopus.Client.Model.Accounts
String ResourceGroup { get; set; }
String WebSpace { get; set; }
}
class WebSite
{
.ctor()
String Name { get; set; }
String ResourceGroup { get; set; }
String WebSpace { get; set; }
}
class WebSlot
{
.ctor()
String Name { get; set; }
String Region { get; set; }
String ResourceGroupName { get; set; }
String Site { get; set; }
}
class WebSlot
{
.ctor()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Octopus.Client.Model.Accounts;
using Octopus.Client.Repositories.Async;

namespace Octopus.Client.Editors.Async
{
public class AzureOidcAccountEditor : AccountEditor<AzureSubscriptionAccountResource, AzureOidcAccountEditor>
{
public AzureOidcAccountEditor(IAccountRepository repository) : base(repository)
{
}

public Task<List<AzureOidcAccountResource.ResourceGroup>> ResourceGroups()
{
return Repository.Client.Get<List<AzureOidcAccountResource.ResourceGroup>>(Instance.Link("ResourceGroups"));
}

public Task<List<AzureOidcAccountResource.WebSite>> WebSites()
{
return Repository.Client.Get<List<AzureOidcAccountResource.WebSite>>(Instance.Link("WebSites"));
}

public Task<List<AzureOidcAccountResource.WebSlot>> WebSlots(AzureOidcAccountResource.WebSite site)
{
return Repository.Client.Get<List<AzureOidcAccountResource.WebSlot>>(Instance.Link("WebSlots"),
new {id = Instance.Id, resourceGroupName = site.ResourceGroup, webSiteName = site.WebSpace});
}

public Task<List<AzureStorageAccount>> StorageAccounts()
{
return Repository.Client.Get<List<AzureStorageAccount>>(Instance.Link("StorageAccounts"));
}
}
}
34 changes: 34 additions & 0 deletions source/Octopus.Server.Client/Editors/AzureOidcAccountEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections.Generic;
using Octopus.Client.Model.Accounts;
using Octopus.Client.Repositories;

namespace Octopus.Client.Editors
{
public class AzureOidcAccountEditor : AccountEditor<AzureOidcAccountResource, AzureOidcAccountEditor>
{
public AzureOidcAccountEditor(IAccountRepository repository) : base(repository)
{
}

public List<AzureOidcAccountResource.ResourceGroup> ResourceGroups()
{
return Repository.Client.Get<List<AzureOidcAccountResource.ResourceGroup>>(Instance.Link("ResourceGroups"));
}

public List<AzureOidcAccountResource.WebSite> WebSites()
{
return Repository.Client.Get<List<AzureOidcAccountResource.WebSite>>(Instance.Link("WebSites"));
}

public List<AzureOidcAccountResource.WebSlot> WebSiteSlots(AzureOidcAccountResource.WebSite site)
{
return Repository.Client.Get<List<AzureOidcAccountResource.WebSlot>>(Instance.Link("WebSiteSlots"),
new {resourceGroupName = site.ResourceGroup, webSiteName = site.Name});
}

public List<AzureStorageAccount> StorageAccounts()
{
return Repository.Client.Get<List<AzureStorageAccount>>(Instance.Link("StorageAccounts"));
}
}
}
2 changes: 2 additions & 0 deletions source/Octopus.Server.Client/Extensions/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public static AccountType DetermineAccountType(this Type type)
accountType = AccountType.AzureServicePrincipal;
else if (type == typeof(AzureSubscriptionAccountResource))
accountType = AccountType.AzureSubscription;
else if (type == typeof(AzureOidcAccountResource))
accountType = AccountType.AzureOidc;
else if (type == typeof(AmazonWebServicesAccountResource))
accountType = AccountType.AmazonWebServicesAccount;
else if (type == typeof(TokenAccountResource))
Expand Down
1 change: 1 addition & 0 deletions source/Octopus.Server.Client/Model/Accounts/AccountType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public enum AccountType
AmazonWebServicesRoleAccount,
Token,
GoogleCloudAccount,
AzureOidc,
}
}
Loading

0 comments on commit fc9dd57

Please sign in to comment.