File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1111# See the License for the specific language governing permissions and
1212# limitations under the License.
1313
14+ import os
15+
1416import generate_wrapped_rsa_key
17+ from googleapiclient import discovery
18+ from oauth2client .client import GoogleCredentials
1519
1620
1721def test_main ():
1822 generate_wrapped_rsa_key .main (None )
23+
24+
25+ def test_create_disk (cloud_config ):
26+ credentials = GoogleCredentials .get_application_default ()
27+ compute = discovery .build ('compute' , 'beta' , credentials = credentials )
28+
29+ # Generate the key.
30+ key_bytes = os .urandom (32 )
31+ google_public_key = generate_wrapped_rsa_key .get_google_public_cert_key ()
32+ wrapped_rsa_key = generate_wrapped_rsa_key .wrap_rsa_key (
33+ google_public_key , key_bytes )
34+
35+ # Create the disk, if the encryption key is invalid, this will raise.
36+ compute .disks ().insert (
37+ project = cloud_config .project ,
38+ zone = 'us-central1-f' ,
39+ body = {
40+ 'name' : 'new-encrypted-disk' ,
41+ 'diskEncryptionKey' : {
42+ 'rsaEncryptedKey' : wrapped_rsa_key .decode ('utf-8' )
43+ }
44+ }).execute ()
45+
46+ # Delete the disk.
47+ compute .disks ().delete (
48+ project = cloud_config .project ,
49+ zone = 'us-central1-f' ,
50+ disk = 'new-encrypted-disk' ).execute ()
You can’t perform that action at this time.
0 commit comments