Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions encryption/activity/decrypt/activity.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package decrypt

import (
"github.com/project-flogo/contrib/encryption/crypt"
"github.com/project-flogo/core/activity"
)

func init() {
_ = activity.Register(&Activity{}, New)
}

var activityMd = activity.ToMetadata(&Settings{}, &Input{}, &Output{})

// New function for the activity
func New(ctx activity.InitContext) (activity.Activity, error) {
act := &Activity{}

return act, nil
}

// Activity is an activity that is used to invoke a REST Operation
type Activity struct {
}

// Metadata for the activity
func (a *Activity) Metadata() *activity.Metadata {
return activityMd
}

// Eval implements api.Activity.Eval - Create the hash
func (a *Activity) Eval(ctx activity.Context) (done bool, err error) {

input := &Input{}
err = ctx.GetInputObject(input)
if err != nil {
err = activity.NewError(err.Error(), "DECRYPT-001", nil)
return false, err
}

logger := ctx.Logger()

if logger.DebugEnabled() {
logger.Debugf("Input params: %s", input)
}
data, err := crypt.DecryptString(input.Data, input.Passphrase)
if err != nil {
err = activity.NewError(err.Error(), "DECRYPT-002", nil)
return false, err
}

output := &Output{Data: data}
err = ctx.SetOutputObject(output)
if err != nil {
err = activity.NewError(err.Error(), "DECRYPT-003", nil)
return false, err
}

return true, nil
}
51 changes: 51 additions & 0 deletions encryption/activity/decrypt/activity_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package decrypt

import (
"testing"

"github.com/project-flogo/core/activity"
"github.com/project-flogo/core/support/test"
"github.com/stretchr/testify/assert"
)

func TestRegister(t *testing.T) {

ref := activity.GetRef(&Activity{})
act := activity.Get(ref)

assert.NotNil(t, act)
}

func TestEval(t *testing.T) {
act := &Activity{}
tc := test.NewActivityContext(act.Metadata())

input := &Input{
Data: "1e236cb297e9af0ceae2ae50a90dac6eaacdb38a47c7a868a1cdfd1e29b8a9e9",
Passphrase: "passphrase",
}
tc.SetInputObject(input)

act.Eval(tc)

output := &Output{}
tc.GetOutputObject(output)
assert.NotEmpty(t, output.Data)
}

func TestError(t *testing.T) {
act := &Activity{}
tc := test.NewActivityContext(act.Metadata())

input := &Input{
Data: "aa1e236cb297e9af0ceae2ae50a90dac6eaacdb38a47c7a868a1cdfd1e29b8a9e9",
Passphrase: "passphrase",
}
tc.SetInputObject(input)

act.Eval(tc)

output := &Output{}
tc.GetOutputObject(output)
assert.Empty(t, output.Data)
}
38 changes: 38 additions & 0 deletions encryption/activity/decrypt/descriptor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "decrypt",
"author": "Manuel Carlos Rodriguez",
"version": "1.0.0",
"type": "flogo:activity",
"title": "Decrypt",
"display": {
"description": "Activities created by TIBCO Labs",
"category": "encryption",
"visible": true
},
"feature": {
"iterator": {
"type": "iterator",
"enabled": true
}
},
"ref": "github.com/project-flogo/contrib/encryption/activity/decrypt",
"settings": [],
"inputs": [
{
"name": "data",
"type": "string",
"required": true
},
{
"name": "passphrase",
"type": "string",
"required": true
}
],
"outputs": [
{
"name": "data",
"type": "string"
}
]
}
50 changes: 50 additions & 0 deletions encryption/activity/decrypt/metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package decrypt

import (
"github.com/project-flogo/core/data/coerce"
)

type Settings struct {
}

// Input for the activity
type Input struct {
Data string `md:"data"` // Data to encrypt
Passphrase string `md:"passphrase"` // Encryption passphrase
}

// ToMap for Input
func (i *Input) ToMap() map[string]interface{} {

return map[string]interface{}{
"data": i.Data,
"passphrase": i.Passphrase,
}
}

// FromMap for input
func (i *Input) FromMap(values map[string]interface{}) error {
i.Data, _ = coerce.ToString(values["data"])
i.Passphrase, _ = coerce.ToString(values["passphrase"])

return nil
}

// Output for the activity
type Output struct {
Data string `md:"data"` // Data encrypted
}

// ToMap conver to object
func (o *Output) ToMap() map[string]interface{} {
return map[string]interface{}{
"data": o.Data,
}
}

// FromMap convert to object
func (o *Output) FromMap(values map[string]interface{}) error {
o.Data, _ = coerce.ToString(values["data"])

return nil
}
53 changes: 53 additions & 0 deletions encryption/activity/encrypt/activity.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package encrypt

import (
"github.com/project-flogo/contrib/encryption/crypt"
"github.com/project-flogo/core/activity"
)

func init() {
_ = activity.Register(&Activity{}, New)
}

var activityMd = activity.ToMetadata(&Settings{}, &Input{}, &Output{})

// New function for the activity
func New(ctx activity.InitContext) (activity.Activity, error) {
act := &Activity{}

return act, nil
}

// Activity is an activity that is used to invoke a REST Operation
type Activity struct {
}

// Metadata for the activity
func (a *Activity) Metadata() *activity.Metadata {
return activityMd
}

// Eval implements api.Activity.Eval - Create the hash
func (a *Activity) Eval(ctx activity.Context) (done bool, err error) {

input := &Input{}
err = ctx.GetInputObject(input)
if err != nil {
return false, err
}

logger := ctx.Logger()

if logger.DebugEnabled() {
logger.Debugf("Input params: %s", input)
}
data := crypt.EncryptString(input.Data, input.Passphrase)

output := &Output{Data: data}
err = ctx.SetOutputObject(output)
if err != nil {
return false, err
}

return true, nil
}
34 changes: 34 additions & 0 deletions encryption/activity/encrypt/activity_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package encrypt

import (
"testing"

"github.com/project-flogo/core/activity"
"github.com/project-flogo/core/support/test"
"github.com/stretchr/testify/assert"
)

func TestRegister(t *testing.T) {

ref := activity.GetRef(&Activity{})
act := activity.Get(ref)

assert.NotNil(t, act)
}

func TestEval(t *testing.T) {
act := &Activity{}
tc := test.NewActivityContext(act.Metadata())

input := &Input{
Data: "data",
Passphrase: "passphrase",
}
tc.SetInputObject(input)

act.Eval(tc)

output := &Output{}
tc.GetOutputObject(output)
assert.NotEmpty(t, output.Data)
}
39 changes: 39 additions & 0 deletions encryption/activity/encrypt/descriptor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "encrypt",
"author": "Manuel Carlos Rodriguez",
"version": "1.0.0",
"type": "flogo:activity",
"title": "Encrypt",
"display": {
"description": "Activities created by TIBCO Labs",
"category": "encryption",
"visible": true
},
"feature": {
"iterator": {
"type": "iterator",
"enabled": true
}
},
"ref": "github.com/project-flogo/contrib/encryption/activity/encrypt",
"settings": [
],
"inputs": [
{
"name": "data",
"type": "string",
"required": true
},
{
"name": "passphrase",
"type": "string",
"required": true
}
],
"outputs": [
{
"name": "data",
"type": "string"
}
]
}
50 changes: 50 additions & 0 deletions encryption/activity/encrypt/metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package encrypt

import (
"github.com/project-flogo/core/data/coerce"
)

type Settings struct {
}

// Input for the activity
type Input struct {
Data string `md:"data"` // Data to encrypt
Passphrase string `md:"passphrase"` // Encryption passphrase
}

// ToMap for Input
func (i *Input) ToMap() map[string]interface{} {

return map[string]interface{}{
"data": i.Data,
"passphrase": i.Passphrase,
}
}

// FromMap for input
func (i *Input) FromMap(values map[string]interface{}) error {
i.Data, _ = coerce.ToString(values["data"])
i.Passphrase, _ = coerce.ToString(values["passphrase"])

return nil
}

// Output for the activity
type Output struct {
Data string `md:"data"` // Data encrypted
}

// ToMap conver to object
func (o *Output) ToMap() map[string]interface{} {
return map[string]interface{}{
"data": o.Data,
}
}

// FromMap convert to object
func (o *Output) FromMap(values map[string]interface{}) error {
o.Data, _ = coerce.ToString(values["data"])

return nil
}
Loading