-
Notifications
You must be signed in to change notification settings - Fork 1
/
activity.go
59 lines (46 loc) · 1.25 KB
/
activity.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* BSD 3-Clause License
* Copyright © 2022. TIBCO Software Inc.
* This file is subject to the license terms contained
* in the license file that is distributed with this file.
*/
package encrypt
import (
"github.com/TIBCOSoftware/TCSTK-GOlang/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
}