Skip to content
This repository was archived by the owner on Sep 6, 2025. It is now read-only.

Commit e647b49

Browse files
authored
New prop for DatabaseUsers, mysql_settings, used to specify auth_plugin (#79)
Also new method to reset user's authentication
1 parent 94538f0 commit e647b49

8 files changed

Lines changed: 81 additions & 0 deletions

File tree

DigitalOcean.API.Tests/Clients/DatabasesClientTest.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,18 @@ public void CorrectRequestForRemoveUser() {
200200
factory.Received().ExecuteRaw("databases/{id}/users/{name}", parameters, null, Method.DELETE);
201201
}
202202

203+
[Fact]
204+
public void CorrectRequestForResetUserAuth() {
205+
var factory = Substitute.For<IConnection>();
206+
var client = new DatabasesClient(factory);
207+
208+
var body = new Models.Requests.DatabaseResetUserAuth();
209+
client.ResetUserAuth("1", "name", body);
210+
211+
var parameters = Arg.Is<List<Parameter>>(list => (string)list[0].Value == "1" && (string)list[1].Value == "name");
212+
factory.Received().ExecuteRequest<DatabaseUser>("databases/{id}/users/{username}/reset_auth", parameters, body, "user", Method.POST);
213+
}
214+
203215
[Fact]
204216
public void CorrectRequestForAddDatabase() {
205217
var factory = Substitute.For<IConnection>();

DigitalOcean.API/Clients/DatabasesClient.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,18 @@ public Task RemoveUser(string databaseId, string username) {
256256
return _connection.ExecuteRaw("databases/{id}/users/{name}", parameters, null, Method.DELETE);
257257
}
258258

259+
/// <summary>
260+
/// To reset the MySQL authentication method for a user.
261+
/// Note: Resetting user authentication is not supported for PostgreSQL and Redis clusters.
262+
/// </summary>
263+
public Task<DatabaseUser> ResetUserAuth(string databaseId, string username, Models.Requests.DatabaseResetUserAuth resetAuth) {
264+
var parameters = new List<Parameter> {
265+
new Parameter("id", databaseId, ParameterType.UrlSegment),
266+
new Parameter("username", username, ParameterType.UrlSegment)
267+
};
268+
return _connection.ExecuteRequest<DatabaseUser>("databases/{id}/users/{username}/reset_auth", parameters, resetAuth, "user", Method.POST);
269+
}
270+
259271
/// <summary>
260272
/// Resize a database cluster
261273
/// </summary>

DigitalOcean.API/Clients/IDatabasesClient.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ public interface IDatabasesClient {
9494
/// </summary>
9595
Task RemoveUser(string databaseId, string username);
9696

97+
/// <summary>
98+
/// To reset the MySQL authentication method for a user.
99+
/// Note: Resetting user authentication is not supported for PostgreSQL and Redis clusters.
100+
/// </summary>
101+
Task<DatabaseUser> ResetUserAuth(string databaseId, string username, Models.Requests.DatabaseResetUserAuth resetAuth);
102+
97103
/// <summary>
98104
/// Add a new database to an existing cluster
99105
/// </summary>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Newtonsoft.Json;
2+
3+
namespace DigitalOcean.API.Models.Requests {
4+
public class DatabaseResetUserAuth {
5+
/// <summary>
6+
/// An object containing additional configuration details for MySQL cluster users.
7+
/// </summary>
8+
[JsonProperty("mysql_settings")]
9+
public MySqlSettings MySqlSettings { get; set; }
10+
}
11+
}

DigitalOcean.API/Models/Requests/DatabaseUser.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,11 @@ public class DatabaseUser {
77
/// </summary>
88
[JsonProperty("name")]
99
public string Name { get; set; }
10+
11+
/// <summary>
12+
/// An object containing additional configuration details for MySQL clusters.
13+
/// </summary>
14+
[JsonProperty("mysql_settings")]
15+
public MySqlSettings MySqlSettings { get; set; }
1016
}
1117
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Newtonsoft.Json;
2+
3+
namespace DigitalOcean.API.Models.Requests {
4+
public class MySqlSettings {
5+
/// <summary>
6+
/// A string specifying the authentication method to be used for connections to the MySQL user account.
7+
/// The valid values are "mysql_native_password" or "caching_sha2_password".
8+
/// If excluded when creating a new user, the default for the version of MySQL in use will be used.
9+
/// As of MySQL 8.0, the default is "caching_sha2_password."
10+
/// </summary>
11+
[JsonProperty("auth_plugin")]
12+
public string AuthPlugin { get; set; }
13+
}
14+
}

DigitalOcean.API/Models/Responses/DatabaseUser.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Newtonsoft.Json;
2+
13
namespace DigitalOcean.API.Models.Responses {
24
public class DatabaseUser {
35
/// <summary>
@@ -14,5 +16,11 @@ public class DatabaseUser {
1416
/// A randomly generated password for the database user.
1517
/// </summary>
1618
public string Password { get; set; }
19+
20+
/// <summary>
21+
/// An object containing additional configuration details for MySQL clusters.
22+
/// </summary>
23+
[JsonProperty("mysql_settings")]
24+
public MySqlSettings MySqlSettings { get; set; }
1725
}
1826
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Newtonsoft.Json;
2+
3+
namespace DigitalOcean.API.Models.Responses {
4+
public class MySqlSettings {
5+
/// <summary>
6+
/// A string specifying the authentication method in use for connections to the MySQL user account.
7+
/// The valid values are "mysql_native_password" or "caching_sha2_password".
8+
/// </summary>
9+
[JsonProperty("auth_plugin")]
10+
public string AuthPlugin { get; set; }
11+
}
12+
}

0 commit comments

Comments
 (0)