GPrabhudas commented on a change in pull request #560:
URL: https://github.com/apache/pulsar-client-go/pull/560#discussion_r689229889



##########
File path: pulsar/internal/crypto/producer_encryptor.go
##########
@@ -0,0 +1,72 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package crypto
+
+import (
+       "fmt"
+
+       "github.com/apache/pulsar-client-go/pulsar/crypto"
+       pb "github.com/apache/pulsar-client-go/pulsar/internal/pulsar_proto"
+       "github.com/apache/pulsar-client-go/pulsar/log"
+)
+
+type producerEncryptor struct {
+       keys                        []string
+       keyReader                   crypto.KeyReader
+       messageCrypto               crypto.MessageCrypto
+       logger                      log.Logger
+       producerCryptoFailureAction int
+}
+
+func NewProducerEncryptor(keys []string,
+       keyReader crypto.KeyReader,
+       messageCrypto crypto.MessageCrypto,
+       producerCryptoFailureAction int,
+       logger log.Logger) Encryptor {
+       return &producerEncryptor{
+               keys:                        keys,
+               keyReader:                   keyReader,
+               messageCrypto:               messageCrypto,
+               logger:                      logger,
+               producerCryptoFailureAction: producerCryptoFailureAction,
+       }
+}
+
+// Encrypt producer encryptor
+func (e *producerEncryptor) Encrypt(payload []byte, msgMetadata 
*pb.MessageMetadata) ([]byte, error) {
+       // encrypt payload
+       encryptedPayload, err := e.messageCrypto.Encrypt(e.keys,
+               e.keyReader,
+               crypto.NewMessageMetadataSupplier(msgMetadata),
+               payload)
+
+       // error encryping the payload
+       if err != nil {
+               // error occurred in encrypting the payload
+               // crypto ProducerCryptoFailureAction is set to send
+               // send unencrypted message
+               if e.producerCryptoFailureAction == 
crypto.ProducerCryptoFailureActionSend {
+                       e.logger.Errorf("Encryption of payload failed : %v", 
err)
+                       e.logger.Warn("ProducerCryptoFailureAction is set to 
send, sending unecrypted message")

Review comment:
       done.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to