Googlebuilder: Add image key encryption

This commit is contained in:
krisko 2019-04-23 20:49:41 +02:00
parent 9b39e3f928
commit f1e9664012
No known key found for this signature in database
GPG Key ID: 172111170DC9A709
3 changed files with 33 additions and 10 deletions

View File

@ -156,6 +156,21 @@ func TestConfigPrepare(t *testing.T) {
"foo bar",
true,
},
{
"image_encryption_key",
map[string]string{"kmsKeyName": "foo"},
false,
},
{
"image_encryption_key",
map[string]string{"No such key": "foo"},
true,
},
{
"image_encryption_key",
map[string]string{"kmsKeyName": "foo", "RawKey": "foo"},
false,
},
{
"scopes",
[]string{},

View File

@ -1,6 +1,10 @@
package googlecompute
import "fmt"
import (
"fmt"
compute "google.golang.org/api/compute/v1"
)
// DriverMock is a Driver implementation that is a mocked out so that
// it can be used for tests.
@ -9,6 +13,7 @@ type DriverMock struct {
CreateImageDesc string
CreateImageFamily string
CreateImageLabels map[string]string
CreateImageEncryptionKey *compute.CustomerEncryptionKey
CreateImageLicenses []string
CreateImageZone string
CreateImageDisk string
@ -82,14 +87,16 @@ type DriverMock struct {
WaitForInstanceErrCh <-chan error
}
func (d *DriverMock) CreateImage(name, description, family, zone, disk string, image_labels map[string]string, image_licenses []string) (<-chan *Image, <-chan error) {
d.CreateImageName = name
d.CreateImageDesc = description
d.CreateImageFamily = family
d.CreateImageLabels = image_labels
d.CreateImageLicenses = image_licenses
d.CreateImageZone = zone
d.CreateImageDisk = disk
func (d *DriverMock) CreateImage(config Config) (<-chan *Image, <-chan error) {
d.CreateImageName = config.GetImageName()
d.CreateImageDesc = config.GetImageDescription()
d.CreateImageFamily = config.GetImageFamily()
d.CreateImageLabels = config.GetImageLabels()
d.CreateImageLicenses = config.GetImageLicenses()
d.CreateImageZone = config.GetZone()
d.CreateImageDisk = config.GetDiskName()
d.CreateImageEncryptionKey = config.GetImageEncryptionKey()
if d.CreateImageResultProjectId == "" {
d.CreateImageResultProjectId = "test"
}
@ -108,7 +115,7 @@ func (d *DriverMock) CreateImage(name, description, family, zone, disk string, i
ch <- &Image{
Labels: d.CreateImageLabels,
Licenses: d.CreateImageLicenses,
Name: name,
Name: d.CreateImageName,
ProjectId: d.CreateImageResultProjectId,
SelfLink: d.CreateImageResultSelfLink,
SizeGb: d.CreateImageResultSizeGb,

View File

@ -47,6 +47,7 @@ func TestStepCreateImage(t *testing.T) {
assert.Equal(t, d.CreateImageDisk, c.DiskName, "Incorrect disk passed to driver.")
assert.Equal(t, d.CreateImageLabels, c.ImageLabels, "Incorrect image_labels passed to driver.")
assert.Equal(t, d.CreateImageLicenses, c.ImageLicenses, "Incorrect image_licenses passed to driver.")
assert.Equal(t, d.CreateImageEncryptionKey, c.ImageEncryptionKey, "Incorrect image_encryption_key passed to driver.")
}
func TestStepCreateImage_errorOnChannel(t *testing.T) {