-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1099 from TattsGroup/enterprise-ldap-api
Implement GitHub Enterprise LDAP API
- Loading branch information
Showing
36 changed files
with
966 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
Octokit.Reactive/Clients/Enterprise/IObservableEnterpriseLdapClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Reactive; | ||
using System.Reactive.Threading.Tasks; | ||
|
||
namespace Octokit.Reactive | ||
{ | ||
/// <summary> | ||
/// A client for GitHub's Enterprise LDAP API | ||
/// </summary> | ||
/// <remarks> | ||
/// See the <a href="https://developer.github.com/v3/enterprise/ldap/">Enterprise LDAP API documentation</a> for more information. | ||
///</remarks> | ||
public interface IObservableEnterpriseLdapClient | ||
{ | ||
/// <summary> | ||
/// Update the LDAP mapping for a user on a GitHub Enterprise appliance (must be Site Admin user). | ||
/// </summary> | ||
/// <remarks> | ||
/// https://developer.github.com/v3/enterprise/ldap/#update-ldap-mapping-for-a-user | ||
/// </remarks> | ||
/// <param name="userName">The username to update LDAP mapping</param> | ||
/// <param name="newLdapMapping">The <see cref="NewLdapMapping"/></param> | ||
/// <returns>The <see cref="User"/> object.</returns> | ||
IObservable<User> UpdateUserMapping(string userName, NewLdapMapping newLdapMapping); | ||
|
||
/// <summary> | ||
/// Queue an LDAP Sync job for a user on a GitHub Enterprise appliance (must be Site Admin user). | ||
/// </summary> | ||
/// <remarks> | ||
/// https://developer.github.com/v3/enterprise/ldap/#sync-ldap-mapping-for-a-user | ||
/// </remarks> | ||
/// <param name="userName">The username to sync LDAP mapping</param> | ||
/// <returns>The <see cref="LdapSyncResponse"/> of the queue request.</returns> | ||
IObservable<LdapSyncResponse> QueueSyncUserMapping(string userName); | ||
|
||
/// <summary> | ||
/// Update the LDAP mapping for a team on a GitHub Enterprise appliance (must be Site Admin user). | ||
/// </summary> | ||
/// <remarks> | ||
/// https://developer.github.com/v3/enterprise/ldap/#update-ldap-mapping-for-a-team | ||
/// </remarks> | ||
/// <param name="teamId">The teamId to update LDAP mapping</param> | ||
/// <param name="newLdapMapping">The <see cref="NewLdapMapping"/></param> | ||
/// <returns>The <see cref="Team"/> object.</returns> | ||
IObservable<Team> UpdateTeamMapping(int teamId, NewLdapMapping newLdapMapping); | ||
|
||
/// <summary> | ||
/// Queue an LDAP Sync job for a team on a GitHub Enterprise appliance (must be Site Admin user). | ||
/// </summary> | ||
/// <remarks> | ||
/// https://developer.github.com/v3/enterprise/ldap/#sync-ldap-mapping-for-a-team | ||
/// </remarks> | ||
/// <param name="teamId">The teamId to update LDAP mapping</param> | ||
/// <returns>The <see cref="LdapSyncResponse"/> of the queue request.</returns> | ||
IObservable<LdapSyncResponse> QueueSyncTeamMapping(int teamId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
Octokit.Reactive/Clients/Enterprise/ObservableEnterpriseLdapClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System; | ||
using System.Reactive; | ||
using System.Reactive.Threading.Tasks; | ||
using Octokit; | ||
|
||
|
||
namespace Octokit.Reactive | ||
{ | ||
/// <summary> | ||
/// A client for GitHub's Enterprise LDAP API | ||
/// </summary> | ||
/// <remarks> | ||
/// See the <a href="https://developer.github.com/v3/enterprise/ldap/">Enterprise LDAP API documentation</a> for more information. | ||
///</remarks> | ||
public class ObservableEnterpriseLdapClient : IObservableEnterpriseLdapClient | ||
{ | ||
readonly IEnterpriseLdapClient _client; | ||
|
||
public ObservableEnterpriseLdapClient(IGitHubClient client) | ||
{ | ||
Ensure.ArgumentNotNull(client, "client"); | ||
|
||
_client = client.Enterprise.Ldap; | ||
} | ||
|
||
/// <summary> | ||
/// Update the LDAP mapping for a user on a GitHub Enterprise appliance (must be Site Admin user). | ||
/// </summary> | ||
/// <remarks> | ||
/// https://developer.github.com/v3/enterprise/ldap/#update-ldap-mapping-for-a-user | ||
/// </remarks> | ||
/// <param name="userName">The username to update LDAP mapping</param> | ||
/// <param name="newLdapMapping">The <see cref="NewLdapMapping"/></param> | ||
/// <returns>The <see cref="User"/> object.</returns> | ||
public IObservable<User> UpdateUserMapping(string userName, NewLdapMapping newLdapMapping) | ||
{ | ||
return _client.UpdateUserMapping(userName, newLdapMapping).ToObservable(); | ||
} | ||
|
||
/// <summary> | ||
/// Queue an LDAP Sync job for a user on a GitHub Enterprise appliance (must be Site Admin user). | ||
/// </summary> | ||
/// <remarks> | ||
/// https://developer.github.com/v3/enterprise/ldap/#sync-ldap-mapping-for-a-user | ||
/// </remarks> | ||
/// <param name="userName">The username to sync LDAP mapping</param> | ||
/// <returns>The <see cref="LdapSyncResponse"/> of the queue request.</returns> | ||
public IObservable<LdapSyncResponse> QueueSyncUserMapping(string userName) | ||
{ | ||
return _client.QueueSyncUserMapping(userName).ToObservable(); | ||
} | ||
|
||
/// <summary> | ||
/// Update the LDAP mapping for a team on a GitHub Enterprise appliance (must be Site Admin user). | ||
/// </summary> | ||
/// <remarks> | ||
/// https://developer.github.com/v3/enterprise/ldap/#update-ldap-mapping-for-a-team | ||
/// </remarks> | ||
/// <param name="teamId">The teamId to update LDAP mapping</param> | ||
/// <param name="newLdapMapping">The <see cref="NewLdapMapping"/></param> | ||
/// <returns>The <see cref="Team"/> object.</returns> | ||
public IObservable<Team> UpdateTeamMapping(int teamId, NewLdapMapping newLdapMapping) | ||
{ | ||
return _client.UpdateTeamMapping(teamId, newLdapMapping).ToObservable(); | ||
} | ||
|
||
/// <summary> | ||
/// Queue an LDAP Sync job for a team on a GitHub Enterprise appliance (must be Site Admin user). | ||
/// </summary> | ||
/// <remarks> | ||
/// https://developer.github.com/v3/enterprise/ldap/#sync-ldap-mapping-for-a-team | ||
/// </remarks> | ||
/// <param name="teamId">The teamId to update LDAP mapping</param> | ||
/// <returns>The <see cref="LdapSyncResponse"/> of the queue request.</returns> | ||
public IObservable<LdapSyncResponse> QueueSyncTeamMapping(int teamId) | ||
{ | ||
return _client.QueueSyncTeamMapping(teamId).ToObservable(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
Octokit.Tests.Integration/Clients/Enterprise/EnterpriseLdapClientTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Octokit; | ||
using Octokit.Tests.Integration; | ||
using Octokit.Tests.Integration.Helpers; | ||
using Xunit; | ||
|
||
public class EnterpriseLdapClientTests : IDisposable | ||
{ | ||
readonly IGitHubClient _github; | ||
|
||
readonly string _testUser = "test-user"; | ||
readonly string _distinguishedNameUser = "uid=test-user,ou=users,dc=company,dc=com"; | ||
|
||
readonly EnterpriseTeamContext _context; | ||
readonly string _distinguishedNameTeam = "cn=test-team,ou=groups,dc=company,dc=com"; | ||
|
||
public EnterpriseLdapClientTests() | ||
{ | ||
_github = EnterpriseHelper.GetAuthenticatedClient(); | ||
|
||
NewTeam newTeam = new NewTeam(Helper.MakeNameWithTimestamp("test-team")) { Description = "Test Team" }; | ||
_context = _github.CreateEnterpriseTeamContext(EnterpriseHelper.Organization, newTeam).Result; | ||
} | ||
|
||
[GitHubEnterpriseTest] | ||
public async Task CanUpdateUserMapping() | ||
{ | ||
var newLDAPMapping = new NewLdapMapping(_distinguishedNameUser); | ||
var ldapUser = await | ||
_github.Enterprise.Ldap.UpdateUserMapping(_testUser, newLDAPMapping); | ||
|
||
Assert.NotNull(ldapUser); | ||
Assert.NotNull(ldapUser.LdapDistinguishedName); | ||
Assert.Equal(ldapUser.LdapDistinguishedName, _distinguishedNameUser); | ||
|
||
// Get user and check mapping was updated | ||
var checkUser = await _github.User.Get(_testUser); | ||
Assert.Equal(checkUser.Login, ldapUser.Login); | ||
Assert.Equal(checkUser.LdapDistinguishedName, _distinguishedNameUser); | ||
} | ||
|
||
[GitHubEnterpriseTest] | ||
public async Task CanQueueSyncUserMapping() | ||
{ | ||
var response = await | ||
_github.Enterprise.Ldap.QueueSyncUserMapping(_testUser); | ||
|
||
// Check response message indicates LDAP sync was queued | ||
Assert.NotNull(response); | ||
Assert.NotNull(response.Status); | ||
Assert.True(response.Status == "queued"); | ||
} | ||
|
||
[GitHubEnterpriseTest] | ||
public async Task CanUpdateTeamMapping() | ||
{ | ||
var newLDAPMapping = new NewLdapMapping(_distinguishedNameTeam); | ||
var ldapTeam = await | ||
_github.Enterprise.Ldap.UpdateTeamMapping(_context.TeamId, newLDAPMapping); | ||
|
||
Assert.NotNull(ldapTeam); | ||
Assert.NotNull(ldapTeam.LdapDistinguishedName); | ||
Assert.Equal(ldapTeam.LdapDistinguishedName, _distinguishedNameTeam); | ||
|
||
// Get Team and check mapping was updated | ||
var checkTeam = await _github.Organization.Team.Get(_context.TeamId); | ||
Assert.Equal(checkTeam.Name, ldapTeam.Name); | ||
Assert.Equal(checkTeam.LdapDistinguishedName, _distinguishedNameTeam); | ||
} | ||
|
||
[GitHubEnterpriseTest] | ||
public async Task CanQueueSyncTeamMapping() | ||
{ | ||
var response = await | ||
_github.Enterprise.Ldap.QueueSyncTeamMapping(_context.TeamId); | ||
|
||
// Check response message indicates LDAP sync was queued | ||
Assert.NotNull(response); | ||
Assert.NotNull(response.Status); | ||
Assert.True(response.Status == "queued"); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_context.Dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
Octokit.Tests.Integration/Helpers/EnterpriseTeamContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Octokit.Tests.Integration.Helpers | ||
{ | ||
internal sealed class EnterpriseTeamContext : IDisposable | ||
{ | ||
internal EnterpriseTeamContext(Team team) | ||
{ | ||
Team = team; | ||
TeamId = team.Id; | ||
TeamName = team.Name; | ||
} | ||
|
||
internal int TeamId { get; private set; } | ||
internal string TeamName { get; private set; } | ||
|
||
internal Team Team { get; private set; } | ||
|
||
public void Dispose() | ||
{ | ||
EnterpriseHelper.DeleteTeam(Team); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.