in testutils/fakekms/fakekms.go [121:148]
func NewWithPipethrough(keyName string, port int) (*Server, error) {
handle := func(req json.Marshaler) (json.Marshaler, int, error) {
glog.Infof("Processing request: %#v", req)
switch r := req.(type) {
case *cloudkms.EncryptRequest:
return &cloudkms.EncryptResponse{
Name: keyName,
Ciphertext: r.Plaintext,
}, http.StatusOK, nil
case *cloudkms.DecryptRequest:
return &cloudkms.DecryptResponse{
Plaintext: r.Ciphertext,
}, http.StatusOK, nil
case *cloudkms.TestIamPermissionsRequest:
return &cloudkms.TestIamPermissionsResponse{
Permissions: []string{
"cloudkms.cryptoKeyVersions.useToEncrypt",
"cloudkms.cryptoKeyVersions.useToDecrypt",
},
}, http.StatusOK, nil
default:
return nil, http.StatusInternalServerError, fmt.Errorf("was not expecting request type:%T", r)
}
}
return newWithCallback(keyName, port, 0, handle)
}