@@ -43,20 +43,26 @@ const keyId1 = `test-parameter-${uuidv4()}`;
4343let parameter ;
4444let regionalParameter ;
4545
46- const keyRing = `projects/ ${ projectId } /locations/global/keyRings/ ${ keyRingId } ` ;
47- const kmsKey = `projects/ ${ projectId } /locations/global/keyRings/ ${ keyRingId } /cryptoKeys/ ${ keyId } ` ;
48- const kmsKey1 = `projects/ ${ projectId } /locations/global/keyRings/ ${ keyRingId } /cryptoKeys/ ${ keyId1 } ` ;
46+ let keyRing ;
47+ let kmsKey ;
48+ let kmsKey1 ;
4949
50- const regionalKeyRing = `projects/ ${ projectId } /locations/ ${ locationId } /keyRings/ ${ keyRingId } ` ;
51- const regionalKmsKey = `projects/ ${ projectId } /locations/ ${ locationId } /keyRings/ ${ keyRingId } /cryptoKeys/ ${ keyId } ` ;
52- const regionalKmsKey1 = `projects/ ${ projectId } /locations/ ${ locationId } /keyRings/ ${ keyRingId } /cryptoKeys/ ${ keyId1 } ` ;
50+ let regionalKeyRing ;
51+ let regionalKmsKey ;
52+ let regionalKmsKey1 ;
5353
5454describe ( 'Parameter Manager samples' , ( ) => {
5555 const parametersToDelete = [ ] ;
5656 const regionalParametersToDelete = [ ] ;
5757
5858 before ( async ( ) => {
5959 projectId = await client . getProjectId ( ) ;
60+ keyRing = `projects/${ projectId } /locations/global/keyRings/${ keyRingId } ` ;
61+ kmsKey = `projects/${ projectId } /locations/global/keyRings/${ keyRingId } /cryptoKeys/${ keyId } ` ;
62+ kmsKey1 = `projects/${ projectId } /locations/global/keyRings/${ keyRingId } /cryptoKeys/${ keyId1 } ` ;
63+ regionalKeyRing = `projects/${ projectId } /locations/${ locationId } /keyRings/${ keyRingId } ` ;
64+ regionalKmsKey = `projects/${ projectId } /locations/${ locationId } /keyRings/${ keyRingId } /cryptoKeys/${ keyId } ` ;
65+ regionalKmsKey1 = `projects/${ projectId } /locations/${ locationId } /keyRings/${ keyRingId } /cryptoKeys/${ keyId1 } ` ;
6066
6167 // Create a test global parameter
6268 [ parameter ] = await client . createParameter ( {
@@ -79,7 +85,7 @@ describe('Parameter Manager samples', () => {
7985 regionalParametersToDelete . push ( regionalParameter ) ;
8086
8187 try {
82- await client . getKeyRing ( { name : keyRing } ) ;
88+ await kmsClient . getKeyRing ( { name : keyRing } ) ;
8389 } catch ( error ) {
8490 if ( error . code === 5 ) {
8591 await kmsClient . createKeyRing ( {
@@ -90,7 +96,7 @@ describe('Parameter Manager samples', () => {
9096 }
9197
9298 try {
93- await client . getKeyRing ( { name : regionalKeyRing } ) ;
99+ await kmsClient . getKeyRing ( { name : regionalKeyRing } ) ;
94100 } catch ( error ) {
95101 if ( error . code === 5 ) {
96102 await kmsClient . createKeyRing ( {
@@ -101,67 +107,71 @@ describe('Parameter Manager samples', () => {
101107 }
102108
103109 try {
104- await client . getCryptoKey ( { name : kmsKey } ) ;
110+ await kmsClient . getCryptoKey ( { name : kmsKey } ) ;
105111 } catch ( error ) {
106112 if ( error . code === 5 ) {
107113 await kmsClient . createCryptoKey ( {
108114 parent : kmsClient . keyRingPath ( projectId , 'global' , keyRingId ) ,
109115 cryptoKeyId : keyId ,
110116 cryptoKey : {
111- purpose : 'ASYMMETRIC_DECRYPT ' ,
117+ purpose : 'ENCRYPT_DECRYPT ' ,
112118 versionTemplate : {
113- algorithm : 'RSA_DECRYPT_OAEP_2048_SHA256' ,
119+ algorithm : 'GOOGLE_SYMMETRIC_ENCRYPTION' ,
120+ protectionLevel : 'HSM' ,
114121 } ,
115122 } ,
116123 } ) ;
117124 }
118125 }
119126
120127 try {
121- await client . getCryptoKey ( { name : regionalKmsKey } ) ;
128+ await kmsClient . getCryptoKey ( { name : regionalKmsKey } ) ;
122129 } catch ( error ) {
123130 if ( error . code === 5 ) {
124131 await kmsClient . createCryptoKey ( {
125132 parent : kmsClient . keyRingPath ( projectId , locationId , keyRingId ) ,
126133 cryptoKeyId : keyId ,
127134 cryptoKey : {
128- purpose : 'ASYMMETRIC_DECRYPT ' ,
135+ purpose : 'ENCRYPT_DECRYPT ' ,
129136 versionTemplate : {
130- algorithm : 'RSA_DECRYPT_OAEP_2048_SHA256' ,
137+ algorithm : 'GOOGLE_SYMMETRIC_ENCRYPTION' ,
138+ protectionLevel : 'HSM' ,
131139 } ,
132140 } ,
133141 } ) ;
134142 }
135143 }
136144
137145 try {
138- await client . getCryptoKey ( { name : kmsKey1 } ) ;
146+ await kmsClient . getCryptoKey ( { name : kmsKey1 } ) ;
139147 } catch ( error ) {
140148 if ( error . code === 5 ) {
141149 await kmsClient . createCryptoKey ( {
142150 parent : kmsClient . keyRingPath ( projectId , 'global' , keyRingId ) ,
143151 cryptoKeyId : keyId1 ,
144152 cryptoKey : {
145- purpose : 'ASYMMETRIC_DECRYPT ' ,
153+ purpose : 'ENCRYPT_DECRYPT ' ,
146154 versionTemplate : {
147- algorithm : 'RSA_DECRYPT_OAEP_2048_SHA256' ,
155+ algorithm : 'GOOGLE_SYMMETRIC_ENCRYPTION' ,
156+ protectionLevel : 'HSM' ,
148157 } ,
149158 } ,
150159 } ) ;
151160 }
152161 }
153162
154163 try {
155- await client . getCryptoKey ( { name : regionalKmsKey1 } ) ;
164+ await kmsClient . getCryptoKey ( { name : regionalKmsKey1 } ) ;
156165 } catch ( error ) {
157166 if ( error . code === 5 ) {
158167 await kmsClient . createCryptoKey ( {
159168 parent : kmsClient . keyRingPath ( projectId , kmsKey1 , keyRingId ) ,
160169 cryptoKeyId : keyId1 ,
161170 cryptoKey : {
162- purpose : 'ASYMMETRIC_DECRYPT ' ,
171+ purpose : 'ENCRYPT_DECRYPT ' ,
163172 versionTemplate : {
164- algorithm : 'RSA_DECRYPT_OAEP_2048_SHA256' ,
173+ algorithm : 'GOOGLE_SYMMETRIC_ENCRYPTION' ,
174+ protectionLevel : 'HSM' ,
165175 } ,
166176 } ,
167177 } ) ;
@@ -185,7 +195,7 @@ describe('Parameter Manager samples', () => {
185195 } ) ;
186196 } catch ( error ) {
187197 if ( error . code === 5 ) {
188- console . info ( `Already destroyed: ${ error . message } ` ) ;
198+ // If the method is not found, skip it.
189199 }
190200 }
191201
@@ -195,7 +205,7 @@ describe('Parameter Manager samples', () => {
195205 } ) ;
196206 } catch ( error ) {
197207 if ( error . code === 5 ) {
198- console . error ( `Already destroyed: ${ error . message } ` ) ;
208+ // If the method is not found, skip it.
199209 }
200210 }
201211
@@ -205,7 +215,7 @@ describe('Parameter Manager samples', () => {
205215 } ) ;
206216 } catch ( error ) {
207217 if ( error . code === 5 ) {
208- console . error ( `Already destroyed: ${ error . message } ` ) ;
218+ // If the method is not found, skip it.
209219 }
210220 }
211221
@@ -215,7 +225,7 @@ describe('Parameter Manager samples', () => {
215225 } ) ;
216226 } catch ( error ) {
217227 if ( error . code === 5 ) {
218- console . error ( `Already destroyed: ${ error . message } ` ) ;
228+ // If the method is not found, skip it.
219229 }
220230 }
221231 } ) ;
0 commit comments