Skip to content

Commit 1cdf403

Browse files
Align with latest REST API (#21)
* Update REST API client * Support creation of super admin clients * Improve launch settings for local debugging
1 parent 3990835 commit 1cdf403

20 files changed

+412
-415
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Eryph.IdentityClient.Commands;
8+
9+
public static class BuiltInRoles
10+
{
11+
public static readonly string SuperAdmin = "e5e83176-7543-4d01-baea-08a00ea064a6";
12+
}

src/Eryph.IdentityClient.Commands/CreatedClient.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ public class CreatedClient
88
{
99
public string Id { get; set; }
1010

11+
public string TenantId { get; set; }
12+
1113
public string Name { get; set; }
1214

1315
public string Description { get; set; }
@@ -17,6 +19,5 @@ public class CreatedClient
1719
public string[] AllowedScopes { get; set; }
1820

1921
public string PrivateKey { get; set; }
20-
2122
}
22-
}
23+
}

src/Eryph.IdentityClient.Commands/Eryph.IdentityClient.Commands.csproj

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919
</ItemGroup>
2020

2121
<ItemGroup>
22-
<Folder Include="Properties\" />
23-
</ItemGroup>
24-
25-
<ItemGroup>
26-
2722
<ProjectReference Include="..\Eryph.IdentityClient\Eryph.IdentityClient.csproj" />
2823
</ItemGroup>
2924

src/Eryph.IdentityClient.Commands/NewEryphClientCommand.cs

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Linq;
1+
using System;
2+
using System.Linq;
23
using System.Management.Automation;
34
using Eryph.IdentityClient.Models;
45
using JetBrains.Annotations;
@@ -7,7 +8,7 @@ namespace Eryph.IdentityClient.Commands
78
{
89
[PublicAPI]
910
[Cmdlet(VerbsCommon.New, "EryphClient", DefaultParameterSetName = "create")]
10-
[OutputType(typeof(CreatedClient), typeof(Client), ParameterSetName = new[] {"create", "createAndSave"})]
11+
[OutputType(typeof(CreatedClient))]
1112
public class NewEryphClientCommand : IdentityCmdLet
1213
{
1314
[Parameter(
@@ -42,8 +43,15 @@ public class NewEryphClientCommand : IdentityCmdLet
4243
[Parameter(
4344
ParameterSetName = "createAndSave",
4445
ValueFromPipelineByPropertyName = true)]
45-
public string Description { get; set; }
46+
public SwitchParameter IsSuperAdmin { get; set; }
4647

48+
[Parameter(
49+
ParameterSetName = "create",
50+
ValueFromPipelineByPropertyName = true)]
51+
[Parameter(
52+
ParameterSetName = "createAndSave",
53+
ValueFromPipelineByPropertyName = true)]
54+
public string Description { get; set; }
4755

4856
[Parameter(
4957
ParameterSetName = "createAndSave")]
@@ -59,17 +67,14 @@ protected override void ProcessRecord()
5967
var identityClient = Factory.CreateClientsClient();
6068
foreach (var name in Name)
6169
{
62-
var eryphClient = new Client
70+
var newClient = new NewClientRequestBody(
71+
name: name,
72+
allowedScopes: AllowedScopes)
6373
{
64-
Name = name
74+
Roles = IsSuperAdmin ? [BuiltInRoles.SuperAdmin] : null,
6575
};
66-
foreach (var allowedScope in AllowedScopes)
67-
{
68-
eryphClient.AllowedScopes.Add(allowedScope);
6976

70-
}
71-
72-
var response = identityClient.Create(eryphClient);
77+
var response = identityClient.Create(newClient);
7378
if (!response.HasValue)
7479
return;
7580

@@ -84,35 +89,17 @@ protected override void ProcessRecord()
8489

8590
var script = InvokeCommand.NewScriptBlock(cmd);
8691
script.Invoke(result.Key);
87-
88-
eryphClient = new Client
89-
{
90-
Id = result.Id,
91-
Name = result.Name,
92-
TenantId = result.TenantId,
93-
};
94-
95-
foreach (var allowedScope in result.AllowedScopes)
96-
{
97-
eryphClient.AllowedScopes.Add(allowedScope);
98-
}
99-
100-
WriteObject(eryphClient);
10192
}
102-
else
103-
WriteObject(new CreatedClient
104-
{
105-
Id = result.Id,
106-
Name = result.Name,
107-
AllowedScopes = result.AllowedScopes.ToArray(),
108-
IdentityProvider = clientCredentials.IdentityProvider,
109-
PrivateKey = result.Key
110-
});
111-
112-
11393

94+
WriteObject(new CreatedClient
95+
{
96+
Id = result.Id,
97+
Name = result.Name,
98+
AllowedScopes = result.AllowedScopes.ToArray(),
99+
IdentityProvider = clientCredentials.IdentityProvider,
100+
PrivateKey = AddToConfiguration ? null : result.Key
101+
});
114102
}
115103
}
116-
117104
}
118-
}
105+
}

src/Eryph.IdentityClient.Commands/Properties/launchSettings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
"commandName": "Executable",
88
"executablePath": "powershell.exe",
99
"commandLineArgs": "-NoProfile -NoExit -Command \"Import-Module $(TargetPath)\""
10+
},
11+
"Run in Powershell Core": {
12+
"commandName": "Executable",
13+
"executablePath": "pwsh.exe",
14+
"commandLineArgs": "-NoProfile -NoExit -Command \"Import-Module $(TargetPath)\""
1015
}
1116
}
1217
}

src/Eryph.IdentityClient.Commands/SetEryphClientCommand.cs

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,33 +34,12 @@ protected override void ProcessRecord()
3434
{
3535
foreach (var id in Id)
3636
{
37-
var client =
38-
identityClient.Get(id)?.Value;
39-
40-
if (client == null)
41-
return;
42-
43-
if (AllowedScopes != null)
44-
{
45-
client.AllowedScopes.Clear();
46-
foreach (var scope in AllowedScopes)
47-
client.AllowedScopes.Add(scope);
48-
}
49-
50-
if(Name != null)
51-
client.Name = Name;
52-
53-
54-
var response = identityClient.Update(id, client);
37+
var response = identityClient.Update(
38+
id,
39+
new UpdateClientRequestBody(Name, AllowedScopes));
5540
WriteObject(response.Value);
56-
5741
}
58-
5942
}
6043
}
61-
6244
}
63-
64-
65-
// This class controls our dependency resolution
66-
}
45+
}

src/Eryph.IdentityClient/Generated/ClientsClient.cs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ internal ClientsClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipelin
4040
_pipeline = pipeline;
4141
}
4242

43-
/// <summary> Creates a new client. </summary>
44-
/// <param name="body"> The <see cref="Client"/> to use. </param>
43+
/// <summary> Create a new client. </summary>
44+
/// <param name="body"> The <see cref="NewClientRequestBody"/> to use. </param>
4545
/// <param name="cancellationToken"> The cancellation token to use. </param>
46-
/// <remarks> Creates a client. </remarks>
47-
public virtual async Task<Response<ClientWithSecret>> CreateAsync(Client body = null, CancellationToken cancellationToken = default)
46+
public virtual async Task<Response<ClientWithSecret>> CreateAsync(NewClientRequestBody body = null, CancellationToken cancellationToken = default)
4847
{
4948
using var scope = _clientDiagnostics.CreateScope("ClientsClient.Create");
5049
scope.Start();
@@ -59,11 +58,10 @@ public virtual async Task<Response<ClientWithSecret>> CreateAsync(Client body =
5958
}
6059
}
6160

62-
/// <summary> Creates a new client. </summary>
63-
/// <param name="body"> The <see cref="Client"/> to use. </param>
61+
/// <summary> Create a new client. </summary>
62+
/// <param name="body"> The <see cref="NewClientRequestBody"/> to use. </param>
6463
/// <param name="cancellationToken"> The cancellation token to use. </param>
65-
/// <remarks> Creates a client. </remarks>
66-
public virtual Response<ClientWithSecret> Create(Client body = null, CancellationToken cancellationToken = default)
64+
public virtual Response<ClientWithSecret> Create(NewClientRequestBody body = null, CancellationToken cancellationToken = default)
6765
{
6866
using var scope = _clientDiagnostics.CreateScope("ClientsClient.Create");
6967
scope.Start();
@@ -78,7 +76,7 @@ public virtual Response<ClientWithSecret> Create(Client body = null, Cancellatio
7876
}
7977
}
8078

81-
/// <summary> Deletes a client. </summary>
79+
/// <summary> Delete a client. </summary>
8280
/// <param name="id"> The <see cref="string"/> to use. </param>
8381
/// <param name="cancellationToken"> The cancellation token to use. </param>
8482
public virtual async Task<Response> DeleteAsync(string id, CancellationToken cancellationToken = default)
@@ -96,7 +94,7 @@ public virtual async Task<Response> DeleteAsync(string id, CancellationToken can
9694
}
9795
}
9896

99-
/// <summary> Deletes a client. </summary>
97+
/// <summary> Delete a client. </summary>
10098
/// <param name="id"> The <see cref="string"/> to use. </param>
10199
/// <param name="cancellationToken"> The cancellation token to use. </param>
102100
public virtual Response Delete(string id, CancellationToken cancellationToken = default)
@@ -150,11 +148,11 @@ public virtual Response<Client> Get(string id, CancellationToken cancellationTok
150148
}
151149
}
152150

153-
/// <summary> Updates a client. </summary>
151+
/// <summary> Update a client. </summary>
154152
/// <param name="id"> The <see cref="string"/> to use. </param>
155-
/// <param name="body"> The <see cref="Client"/> to use. </param>
153+
/// <param name="body"> The <see cref="UpdateClientRequestBody"/> to use. </param>
156154
/// <param name="cancellationToken"> The cancellation token to use. </param>
157-
public virtual async Task<Response<Client>> UpdateAsync(string id, Client body, CancellationToken cancellationToken = default)
155+
public virtual async Task<Response<Client>> UpdateAsync(string id, UpdateClientRequestBody body, CancellationToken cancellationToken = default)
158156
{
159157
using var scope = _clientDiagnostics.CreateScope("ClientsClient.Update");
160158
scope.Start();
@@ -169,11 +167,11 @@ public virtual async Task<Response<Client>> UpdateAsync(string id, Client body,
169167
}
170168
}
171169

172-
/// <summary> Updates a client. </summary>
170+
/// <summary> Update a client. </summary>
173171
/// <param name="id"> The <see cref="string"/> to use. </param>
174-
/// <param name="body"> The <see cref="Client"/> to use. </param>
172+
/// <param name="body"> The <see cref="UpdateClientRequestBody"/> to use. </param>
175173
/// <param name="cancellationToken"> The cancellation token to use. </param>
176-
public virtual Response<Client> Update(string id, Client body, CancellationToken cancellationToken = default)
174+
public virtual Response<Client> Update(string id, UpdateClientRequestBody body, CancellationToken cancellationToken = default)
177175
{
178176
using var scope = _clientDiagnostics.CreateScope("ClientsClient.Update");
179177
scope.Start();
@@ -188,7 +186,7 @@ public virtual Response<Client> Update(string id, Client body, CancellationToken
188186
}
189187
}
190188

191-
/// <summary> Updates a client key. </summary>
189+
/// <summary> Create or replace the client key. </summary>
192190
/// <param name="id"> The <see cref="string"/> to use. </param>
193191
/// <param name="body"> The <see cref="NewClientKeyRequestBody"/> to use. </param>
194192
/// <param name="cancellationToken"> The cancellation token to use. </param>
@@ -207,7 +205,7 @@ public virtual async Task<Response<ClientWithSecret>> NewKeyAsync(string id, New
207205
}
208206
}
209207

210-
/// <summary> Updates a client key. </summary>
208+
/// <summary> Create or replace the client key. </summary>
211209
/// <param name="id"> The <see cref="string"/> to use. </param>
212210
/// <param name="body"> The <see cref="NewClientKeyRequestBody"/> to use. </param>
213211
/// <param name="cancellationToken"> The cancellation token to use. </param>
@@ -226,22 +224,20 @@ public virtual Response<ClientWithSecret> NewKey(string id, NewClientKeyRequestB
226224
}
227225
}
228226

229-
/// <summary> Lists clients. </summary>
227+
/// <summary> List all clients. </summary>
230228
/// <param name="cancellationToken"> The cancellation token to use. </param>
231229
public virtual AsyncPageable<Client> ListAsync(CancellationToken cancellationToken = default)
232230
{
233231
HttpMessage FirstPageRequest(int? pageSizeHint) => RestClient.CreateListRequest();
234-
HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => RestClient.CreateListNextPageRequest(nextLink);
235-
return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, Client.DeserializeClient, _clientDiagnostics, _pipeline, "ClientsClient.List", "value", "nextLink", cancellationToken);
232+
return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, null, Client.DeserializeClient, _clientDiagnostics, _pipeline, "ClientsClient.List", "value", null, cancellationToken);
236233
}
237234

238-
/// <summary> Lists clients. </summary>
235+
/// <summary> List all clients. </summary>
239236
/// <param name="cancellationToken"> The cancellation token to use. </param>
240237
public virtual Pageable<Client> List(CancellationToken cancellationToken = default)
241238
{
242239
HttpMessage FirstPageRequest(int? pageSizeHint) => RestClient.CreateListRequest();
243-
HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => RestClient.CreateListNextPageRequest(nextLink);
244-
return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, Client.DeserializeClient, _clientDiagnostics, _pipeline, "ClientsClient.List", "value", "nextLink", cancellationToken);
240+
return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, null, Client.DeserializeClient, _clientDiagnostics, _pipeline, "ClientsClient.List", "value", null, cancellationToken);
245241
}
246242
}
247243
}

0 commit comments

Comments
 (0)