@@ -24,42 +24,20 @@ public class ParameterManagerFixture : IDisposable, ICollectionFixture<Parameter
24
24
{
25
25
public string ProjectId { get ; }
26
26
public string LocationId = "global" ;
27
-
28
27
public string Payload = "test123" ;
29
- public string JsonPayload = "{\" username\" : \" test-user\" , \" host\" : \" localhost\" }" ;
30
- public string SecretReference { get ; }
31
- public string SecretId = "projects/project-id/secrets/secret-id/versions/latest" ;
32
-
33
- public ParameterName ParameterName { get ; }
34
- public ParameterName ParameterNameWithFormat { get ; }
35
28
36
29
public string ParameterId { get ; }
37
- public Parameter Parameter { get ; }
38
- public ParameterVersionName ParameterVersionName { get ; }
39
-
40
- public Parameter ParameterWithFormat { get ; }
41
- public ParameterVersionName ParameterVersionNameWithFormat { get ; }
42
-
43
- public Parameter ParameterWithSecretReference { get ; }
44
- public ParameterVersionName ParameterVersionNameWithSecretReference { get ; }
30
+ public string ParameterVersionId { get ; }
45
31
46
32
public Parameter ParameterToDelete { get ; }
47
33
public ParameterName ParameterNameToDelete { get ; }
48
34
49
- public string ParameterVersionId { get ; }
50
35
public Parameter ParameterToDeleteVersion { get ; }
51
36
public ParameterVersion ParameterVersionToDelete { get ; }
52
37
public ParameterVersionName ParameterVersionNameToDelete { get ; }
53
38
54
- public ParameterName ParameterNameForQuickstart { get ; }
55
- public ParameterVersionName ParameterVersionNameForQuickstart { get ; }
56
-
57
- public Parameter ParameterToRender { get ; }
58
- public ParameterVersion ParameterVersionToRender { get ; }
59
- public ParameterVersionName ParameterVersionNameToRender { get ; }
60
- public Secret Secret { get ; }
61
- public SecretVersion SecretVersion { get ; }
62
- public Policy Policy { get ; }
39
+ public ParameterVersion ParameterVersionToDisableAndEnable { get ; }
40
+ public ParameterVersionName ParameterVersionNameToDisableAndEnable { get ; }
63
41
public ParameterManagerFixture ( )
64
42
{
65
43
ProjectId = Environment . GetEnvironmentVariable ( "GOOGLE_PROJECT_ID" ) ;
@@ -68,21 +46,6 @@ public ParameterManagerFixture()
68
46
throw new Exception ( "missing GOOGLE_PROJECT_ID" ) ;
69
47
}
70
48
71
- ParameterName = new ParameterName ( ProjectId , LocationId , RandomId ( ) ) ;
72
- ParameterNameWithFormat = new ParameterName ( ProjectId , LocationId , RandomId ( ) ) ;
73
-
74
- ParameterId = RandomId ( ) ;
75
- Parameter = CreateParameter ( ParameterId , ParameterFormat . Unformatted ) ;
76
- ParameterVersionName = new ParameterVersionName ( ProjectId , LocationId , ParameterId , RandomId ( ) ) ;
77
-
78
- ParameterId = RandomId ( ) ;
79
- ParameterWithFormat = CreateParameter ( ParameterId , ParameterFormat . Json ) ;
80
- ParameterVersionNameWithFormat = new ParameterVersionName ( ProjectId , LocationId , ParameterId , RandomId ( ) ) ;
81
-
82
- ParameterId = RandomId ( ) ;
83
- ParameterWithSecretReference = CreateParameter ( ParameterId , ParameterFormat . Unformatted ) ;
84
- ParameterVersionNameWithSecretReference = new ParameterVersionName ( ProjectId , LocationId , ParameterId , RandomId ( ) ) ;
85
-
86
49
ParameterId = RandomId ( ) ;
87
50
ParameterToDelete = CreateParameter ( ParameterId , ParameterFormat . Unformatted ) ;
88
51
ParameterNameToDelete = new ParameterName ( ProjectId , LocationId , ParameterId ) ;
@@ -93,40 +56,17 @@ public ParameterManagerFixture()
93
56
ParameterVersionToDelete = CreateParameterVersion ( ParameterId , ParameterVersionId , Payload ) ;
94
57
ParameterVersionNameToDelete = new ParameterVersionName ( ProjectId , LocationId , ParameterId , ParameterVersionId ) ;
95
58
96
- ParameterId = RandomId ( ) ;
97
- ParameterVersionId = RandomId ( ) ;
98
- ParameterNameForQuickstart = new ParameterName ( ProjectId , LocationId , ParameterId ) ;
99
- ParameterVersionNameForQuickstart = new ParameterVersionName ( ProjectId , LocationId , ParameterId , ParameterVersionId ) ;
100
-
101
- ParameterId = RandomId ( ) ;
102
59
ParameterVersionId = RandomId ( ) ;
103
- ParameterToRender = CreateParameter ( ParameterId , ParameterFormat . Json ) ;
104
- Secret = CreateSecret ( RandomId ( ) ) ;
105
- SecretVersion = AddSecretVersion ( Secret ) ;
106
- SecretReference = $ "{{\" username\" : \" test-user\" , \" password\" : \" __REF__(//secretmanager.googleapis.com/{ Secret . SecretName } /versions/latest)\" }}";
107
- ParameterVersionToRender = CreateParameterVersion ( ParameterId , ParameterVersionId , SecretReference ) ;
108
- Policy = GrantIAMAccess ( Secret . SecretName , ParameterToRender . PolicyMember . IamPolicyUidPrincipal . ToString ( ) ) ;
109
- ParameterVersionNameToRender = new ParameterVersionName ( ProjectId , LocationId , ParameterId , ParameterVersionId ) ;
60
+ ParameterVersionToDisableAndEnable = CreateParameterVersion ( ParameterId , ParameterVersionId , Payload ) ;
61
+ ParameterVersionNameToDisableAndEnable = new ParameterVersionName ( ProjectId , LocationId , ParameterId , ParameterVersionId ) ;
110
62
}
111
63
112
64
public void Dispose ( )
113
65
{
114
- DeleteParameter ( ParameterName ) ;
115
- DeleteParameter ( ParameterNameWithFormat ) ;
116
- DeleteParameterVersion ( ParameterVersionName ) ;
117
- DeleteParameter ( Parameter . ParameterName ) ;
118
- DeleteParameterVersion ( ParameterVersionNameWithFormat ) ;
119
- DeleteParameter ( ParameterWithFormat . ParameterName ) ;
120
- DeleteParameterVersion ( ParameterVersionNameWithSecretReference ) ;
121
- DeleteParameter ( ParameterWithSecretReference . ParameterName ) ;
122
66
DeleteParameter ( ParameterNameToDelete ) ;
123
67
DeleteParameterVersion ( ParameterVersionNameToDelete ) ;
68
+ DeleteParameterVersion ( ParameterVersionNameToDisableAndEnable ) ;
124
69
DeleteParameter ( ParameterToDeleteVersion . ParameterName ) ;
125
- DeleteParameterVersion ( ParameterVersionNameForQuickstart ) ;
126
- DeleteParameter ( ParameterNameForQuickstart ) ;
127
- DeleteParameterVersion ( ParameterVersionNameToRender ) ;
128
- DeleteParameter ( ParameterToRender . ParameterName ) ;
129
- DeleteSecret ( Secret . SecretName ) ;
130
70
}
131
71
132
72
public String RandomId ( )
@@ -160,7 +100,7 @@ public ParameterVersion CreateParameterVersion(string parameterId, string versio
160
100
}
161
101
} ;
162
102
163
- return client . CreateParameterVersion ( parameterName . ToString ( ) , parameterVersion , versionId ) ;
103
+ return client . CreateParameterVersion ( parameterName , parameterVersion , versionId ) ;
164
104
}
165
105
166
106
private void DeleteParameter ( ParameterName name )
@@ -188,68 +128,4 @@ private void DeleteParameterVersion(ParameterVersionName name)
188
128
// Ignore error - Parameter version was already deleted
189
129
}
190
130
}
191
-
192
- public Secret CreateSecret ( string secretId )
193
- {
194
- SecretManagerServiceClient client = SecretManagerServiceClient . Create ( ) ;
195
- ProjectName projectName = new ProjectName ( ProjectId ) ;
196
-
197
- Secret secret = new Secret
198
- {
199
- Replication = new Replication
200
- {
201
- Automatic = new Replication . Types . Automatic ( ) ,
202
- } ,
203
- } ;
204
-
205
- return client . CreateSecret ( projectName , secretId , secret ) ;
206
- }
207
-
208
- public Policy GrantIAMAccess ( SecretName secretName , string member )
209
- {
210
- // Create the client.
211
- SecretManagerServiceClient client = SecretManagerServiceClient . Create ( ) ;
212
-
213
- // Get current policy.
214
- Policy policy = client . GetIamPolicy ( new GetIamPolicyRequest
215
- {
216
- ResourceAsResourceName = secretName ,
217
- } ) ;
218
-
219
- // Add the user to the list of bindings.
220
- policy . AddRoleMember ( "roles/secretmanager.secretAccessor" , member ) ;
221
-
222
- // Save the updated policy.
223
- policy = client . SetIamPolicy ( new SetIamPolicyRequest
224
- {
225
- ResourceAsResourceName = secretName ,
226
- Policy = policy ,
227
- } ) ;
228
- return policy ;
229
- }
230
- private SecretVersion AddSecretVersion ( Secret secret )
231
- {
232
- SecretManagerServiceClient client = SecretManagerServiceClient . Create ( ) ;
233
-
234
- SecretPayload payload = new SecretPayload
235
- {
236
- Data = ByteString . CopyFrom ( "my super secret data" , Encoding . UTF8 ) ,
237
- } ;
238
-
239
- return client . AddSecretVersion ( secret . SecretName , payload ) ;
240
- }
241
-
242
- private void DeleteSecret ( SecretName name )
243
- {
244
- SecretManagerServiceClient client = SecretManagerServiceClient . Create ( ) ;
245
-
246
- try
247
- {
248
- client . DeleteSecret ( name ) ;
249
- }
250
- catch ( Grpc . Core . RpcException e ) when ( e . StatusCode == Grpc . Core . StatusCode . NotFound )
251
- {
252
- // Ignore error - secret was already deleted
253
- }
254
- }
255
131
}
0 commit comments