Skip to content

Commit

Permalink
Add Azure Postgres Flexible Server and upgrade 3rd Party Packages
Browse files Browse the repository at this point in the history
  • Loading branch information
TreyHendon committed May 4, 2023
1 parent e0eaad9 commit 92fb459
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ All `POST` commands use the `GET` methods to ensure the objects have been insert
If no password is provided for the new database user, the password for the originating user will be duplicated and used.

## Platform
By default, the platform is self-hosted. Currently, self-hosted and Azure are the only supported platforms values. To specify, include an element in the JSON body named `Platform` and set the desired value.
By default, the platform is self-hosted. Currently, self-hosted, AzureFlex, and Azure are the only supported platforms values. To specify, include an element in the JSON body named `Platform` and set the desired value.
* Self-hosted platforms will create the new new database role as a `SUPERUSER`.
* Azure platforms will create the role in the `azure_pg_admin` role and will ensure the new username is formatted properly when creating the database (`databasename@host`).
* AzureFlex platforms will create the role in the `azure_pg_admin` role.
* Azure platforms will create the role in the `azure_pg_admin` role and will ensure the new username is formatted properly when creating the database (`databasename@host`).

_NOTE: Omitting the `Platform` object will default to self-hosted._
```
Expand Down
6 changes: 3 additions & 3 deletions src/PsqlManagement.API/Controllers/DatabaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public ActionResult<object> CreateDatabase(CreateDatabase database)

if (!roleExists)
{
if (!string.IsNullOrWhiteSpace(database.Platform) && database.Platform.Equals("Azure", StringComparison.OrdinalIgnoreCase))
if (!string.IsNullOrWhiteSpace(database.Platform) && database.Platform.StartsWith("Azure", StringComparison.OrdinalIgnoreCase))
{
new NpgsqlCommand($"CREATE ROLE \"{role}\" with NOLOGIN INHERIT CREATEDB CREATEROLE IN ROLE azure_pg_admin;", npgsqlConnection).ExecuteNonQuery();
}
Expand Down Expand Up @@ -158,7 +158,7 @@ public ActionResult<object> CreateDatabase(CreateDatabase database)
var privileges = $"LOGIN INHERIT CREATEDB CREATEROLE SUPERUSER NOREPLICATION CONNECTION LIMIT -1 PASSWORD '{database.NewUserPassword ?? database.Password}'";

// if azure, remove SUPERUSER
if (!string.IsNullOrWhiteSpace(database.Platform) && database.Platform.Equals("Azure", StringComparison.OrdinalIgnoreCase))
if (!string.IsNullOrWhiteSpace(database.Platform) && database.Platform.StartsWith("Azure", StringComparison.OrdinalIgnoreCase))
{
privileges = privileges.Replace("SUPERUSER ", "");
}
Expand All @@ -170,7 +170,7 @@ public ActionResult<object> CreateDatabase(CreateDatabase database)
new NpgsqlCommand($"GRANT \"{role}\" TO \"{user}\";", npgsqlConnection).ExecuteNonQuery();

// if azure, add user to azure_pg_admin role
if (!string.IsNullOrWhiteSpace(database.Platform) && database.Platform.Equals("Azure", StringComparison.OrdinalIgnoreCase))
if (!string.IsNullOrWhiteSpace(database.Platform) && database.Platform.StartsWith("Azure", StringComparison.OrdinalIgnoreCase))
{
new NpgsqlCommand($"GRANT azure_pg_admin TO \"{user}\";", npgsqlConnection).ExecuteNonQuery();
}
Expand Down
6 changes: 3 additions & 3 deletions src/PsqlManagement.API/PsqlManagement.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.3" />
<PackageReference Include="prometheus-net.AspNetCore" Version="5.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
<PackageReference Include="prometheus-net.AspNetCore" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>


Expand Down

0 comments on commit 92fb459

Please sign in to comment.