@@ -31,6 +31,9 @@ public static IResourceBuilder<PostgresServerResource> AddPostgres(this IDistrib
31
31
IResourceBuilder < ParameterResource > ? password = null ,
32
32
int ? port = null )
33
33
{
34
+ ArgumentNullException . ThrowIfNull ( builder ) ;
35
+ ArgumentNullException . ThrowIfNull ( name ) ;
36
+
34
37
var passwordParameter = password ? . Resource ?? ParameterResourceBuilderExtensions . CreateDefaultPasswordParameter ( builder , $ "{ name } -password") ;
35
38
36
39
var postgresServer = new PostgresServerResource ( name , userName ? . Resource , passwordParameter ) ;
@@ -56,6 +59,9 @@ public static IResourceBuilder<PostgresServerResource> AddPostgres(this IDistrib
56
59
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
57
60
public static IResourceBuilder < PostgresDatabaseResource > AddDatabase ( this IResourceBuilder < PostgresServerResource > builder , string name , string ? databaseName = null )
58
61
{
62
+ ArgumentNullException . ThrowIfNull ( builder ) ;
63
+ ArgumentNullException . ThrowIfNull ( name ) ;
64
+
59
65
// Use the resource name as the database name if it's not provided
60
66
databaseName ??= name ;
61
67
@@ -73,6 +79,8 @@ public static IResourceBuilder<PostgresDatabaseResource> AddDatabase(this IResou
73
79
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
74
80
public static IResourceBuilder < T > WithPgAdmin < T > ( this IResourceBuilder < T > builder , Action < IResourceBuilder < PgAdminContainerResource > > ? configureContainer = null , string ? containerName = null ) where T : PostgresServerResource
75
81
{
82
+ ArgumentNullException . ThrowIfNull ( builder ) ;
83
+
76
84
if ( builder . ApplicationBuilder . Resources . OfType < PgAdminContainerResource > ( ) . SingleOrDefault ( ) is { } existingPgAdminResource )
77
85
{
78
86
var builderForExistingResource = builder . ApplicationBuilder . CreateResourceBuilder ( existingPgAdminResource ) ;
@@ -108,6 +116,8 @@ public static IResourceBuilder<T> WithPgAdmin<T>(this IResourceBuilder<T> builde
108
116
/// <returns>The resource builder for PGAdmin.</returns>
109
117
public static IResourceBuilder < PgAdminContainerResource > WithHostPort ( this IResourceBuilder < PgAdminContainerResource > builder , int ? port )
110
118
{
119
+ ArgumentNullException . ThrowIfNull ( builder ) ;
120
+
111
121
return builder . WithEndpoint ( "http" , endpoint =>
112
122
{
113
123
endpoint . Port = port ;
@@ -133,7 +143,12 @@ private static void SetPgAdminEnvironmentVariables(EnvironmentCallbackContext co
133
143
/// <param name="isReadOnly">A flag that indicates if this is a read-only volume.</param>
134
144
/// <returns>The <see cref="IResourceBuilder{T}"/>.</returns>
135
145
public static IResourceBuilder < PostgresServerResource > WithDataVolume ( this IResourceBuilder < PostgresServerResource > builder , string ? name = null , bool isReadOnly = false )
136
- => builder . WithVolume ( name ?? VolumeNameGenerator . CreateVolumeName ( builder , "data" ) , "/var/lib/postgresql/data" , isReadOnly ) ;
146
+ {
147
+ ArgumentNullException . ThrowIfNull ( builder ) ;
148
+
149
+ return builder . WithVolume ( name ?? VolumeNameGenerator . CreateVolumeName ( builder , "data" ) ,
150
+ "/var/lib/postgresql/data" , isReadOnly ) ;
151
+ }
137
152
138
153
/// <summary>
139
154
/// Adds a bind mount for the data folder to a PostgreSQL container resource.
@@ -143,7 +158,12 @@ public static IResourceBuilder<PostgresServerResource> WithDataVolume(this IReso
143
158
/// <param name="isReadOnly">A flag that indicates if this is a read-only mount.</param>
144
159
/// <returns>The <see cref="IResourceBuilder{T}"/>.</returns>
145
160
public static IResourceBuilder < PostgresServerResource > WithDataBindMount ( this IResourceBuilder < PostgresServerResource > builder , string source , bool isReadOnly = false )
146
- => builder . WithBindMount ( source , "/var/lib/postgresql/data" , isReadOnly ) ;
161
+ {
162
+ ArgumentNullException . ThrowIfNull ( builder ) ;
163
+ ArgumentNullException . ThrowIfNull ( source ) ;
164
+
165
+ return builder . WithBindMount ( source , "/var/lib/postgresql/data" , isReadOnly ) ;
166
+ }
147
167
148
168
/// <summary>
149
169
/// Adds a bind mount for the init folder to a PostgreSQL container resource.
@@ -153,5 +173,10 @@ public static IResourceBuilder<PostgresServerResource> WithDataBindMount(this IR
153
173
/// <param name="isReadOnly">A flag that indicates if this is a read-only mount.</param>
154
174
/// <returns>The <see cref="IResourceBuilder{T}"/>.</returns>
155
175
public static IResourceBuilder < PostgresServerResource > WithInitBindMount ( this IResourceBuilder < PostgresServerResource > builder , string source , bool isReadOnly = true )
156
- => builder . WithBindMount ( source , "/docker-entrypoint-initdb.d" , isReadOnly ) ;
176
+ {
177
+ ArgumentNullException . ThrowIfNull ( builder ) ;
178
+ ArgumentNullException . ThrowIfNull ( source ) ;
179
+
180
+ return builder . WithBindMount ( source , "/docker-entrypoint-initdb.d" , isReadOnly ) ;
181
+ }
157
182
}
0 commit comments