-
Notifications
You must be signed in to change notification settings - Fork 172
/
actions.go
102 lines (88 loc) · 2.79 KB
/
actions.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package grpc
import (
"context"
"fmt"
"time"
"github.com/pydio/cells/common/forms"
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/any"
"github.com/micro/go-micro/client"
"github.com/pydio/cells/common"
"github.com/pydio/cells/common/proto/idm"
"github.com/pydio/cells/common/proto/jobs"
"github.com/pydio/cells/common/registry"
"github.com/pydio/cells/common/service/proto"
"github.com/pydio/cells/scheduler/actions"
)
var (
DeleteUsersActionName = "actions.idm.users.delete"
)
type DeleteUsersAction struct {
task *jobs.Task
params map[string]string
}
func (a *DeleteUsersAction) GetDescription(lang ...string) actions.ActionDescription {
return actions.ActionDescription{
ID: DeleteUsersActionName,
Label: "Remove Users",
Icon: "account-off",
Description: "Batch-delete users and groups, based on login or group path. Use one of the parameters.",
SummaryTemplate: "",
Category: actions.ActionCategoryIDM,
HasForm: true,
}
}
func (a *DeleteUsersAction) GetParametersForm() *forms.Form {
return &forms.Form{Groups: []*forms.Group{{Fields: []forms.Field{
&forms.FormField{
Name: "login",
Type: forms.ParamString,
Label: "Login",
Description: "Specific user login",
},
&forms.FormField{
Name: "groupPath",
Type: forms.ParamString,
Label: "groupPath",
Description: "Path to group (all users and groups will be deleted)",
},
}}}}
}
func (a *DeleteUsersAction) GetName() string {
return DeleteUsersActionName
}
// Implement TaskUpdaterDelegateAction as the target
// service will update the task status on its side.
func (a *DeleteUsersAction) SetTask(task *jobs.Task) {
a.task = task
}
func (a *DeleteUsersAction) ProvidesProgress() bool {
return true
}
func (a *DeleteUsersAction) Init(job *jobs.Job, cl client.Client, action *jobs.Action) error {
a.params = action.Parameters
return nil
}
func (a *DeleteUsersAction) Run(ctx context.Context, channels *actions.RunnableChannels, input jobs.ActionMessage) (jobs.ActionMessage, error) {
singleQ := &idm.UserSingleQuery{}
if login, ok := a.params["login"]; ok {
singleQ.Login = login
} else if gPath, ok := a.params["groupPath"]; ok {
singleQ.GroupPath = gPath
singleQ.Recursive = true
} else {
e := fmt.Errorf("params must provide either login or groupPath")
return input.WithError(e), e
}
q, _ := ptypes.MarshalAny(singleQ)
uCl := idm.NewUserServiceClient(registry.GetClient(common.SERVICE_USER))
_, e := uCl.DeleteUser(ctx, &idm.DeleteUserRequest{Query: &service.Query{SubQueries: []*any.Any{q}}}, client.WithRequestTimeout(30*time.Minute))
if e != nil {
input = input.WithError(e)
} else {
input.AppendOutput(&jobs.ActionOutput{
Success: true,
})
}
return input, nil
}