-
Notifications
You must be signed in to change notification settings - Fork 180
/
idm.go
174 lines (146 loc) · 6.99 KB
/
idm.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
* Copyright (c) 2018. Abstrium SAS <team (at) pydio.com>
* This file is part of Pydio Cells.
*
* Pydio Cells is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio Cells is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio Cells. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <https://pydio.com>.
*/
package idm
import (
"time"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"github.com/pydio/cells/common"
)
/* idm.go file enriches default genrated proto structs with some custom pydio methods to ease development */
/*
ROLE, USER AND GROUPS
*/
// MarshalLogObject implements custom marshalling for logs
func (role *Role) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
encoder.AddString("Uuid", role.Uuid)
encoder.AddString("Label", role.Label)
encoder.AddBool("IsTeam", role.IsTeam)
encoder.AddBool("GroupRole", role.GroupRole)
encoder.AddBool("UserRole", role.UserRole)
encoder.AddBool("ForceOverride", role.ForceOverride)
encoder.AddTime("LastUpdated", time.Unix(int64(role.LastUpdated), 0))
encoder.AddBool("PoliciesContextEditable", role.PoliciesContextEditable)
encoder.AddReflected("AutoApplies", role.AutoApplies)
encoder.AddReflected("Policies", role.Policies)
return nil
}
// Zap simply returns a zapcore.Field object populated with this role under a standard key
func (role *Role) Zap() zapcore.Field { return zap.Object(common.KEY_ROLE, role) }
// ZapUuid simply calls zap.String() with RoleUuid standard key and this role uuid
func (role *Role) ZapUuid() zapcore.Field { return zap.String(common.KEY_ROLE_UUID, role.GetUuid()) }
// MarshalLogObject implements custom marshalling for logs
func (user *User) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
encoder.AddString("Uuid", user.Uuid)
encoder.AddString("Login", user.Login)
encoder.AddString("GroupPath", user.GroupPath)
encoder.AddString("GroupLabel", user.GroupLabel)
encoder.AddBool("IsGroup", user.IsGroup)
encoder.AddReflected("Attributes", user.Attributes)
encoder.AddBool("PoliciesContextEditable", user.PoliciesContextEditable)
encoder.AddReflected("Roles", user.Roles)
encoder.AddReflected("Policies", user.Policies)
return nil
}
// Zap simply returns a zapcore.Field object populated with this user under a standard key
func (user *User) Zap() zapcore.Field { return zap.Object(common.KEY_USER, user) }
// ZapUuid simply calls zap.String() with UserUuid standard key and this user uuid
func (user *User) ZapUuid() zapcore.Field { return zap.String(common.KEY_USER_UUID, user.GetUuid()) }
// ZapUuid simply calls zap.String() with Login standard key and this user login
func (user *User) ZapLogin() zapcore.Field { return zap.String(common.KEY_USERNAME, user.GetLogin()) }
/*
POLICIES, ACLS
*/
// MarshalLogObject implements custom marshalling for logs
func (pg *PolicyGroup) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
encoder.AddString("Uuid", pg.Uuid)
encoder.AddString("Name", pg.Name)
encoder.AddString("Description", pg.Description)
encoder.AddString("OwnerUuid", pg.OwnerUuid)
encoder.AddString("ResourceGroup", pg.ResourceGroup.String())
encoder.AddReflected("Policies", pg.Policies)
encoder.AddTime("LastUpdated", time.Unix(int64(pg.LastUpdated), 0))
return nil
}
// Zap simply returns a zapcore.Field object populated with this policy group under a standard key
func (pg *PolicyGroup) Zap() zapcore.Field { return zap.Object(common.KEY_POLICY_GROUP, pg) }
// ZapUuid simply calls zap.String() with PolicyGroupUuid standard key and this policy group uuid
func (pg *PolicyGroup) ZapUuid() zapcore.Field {
return zap.String(common.KEY_POLICY_GROUP_UUID, pg.GetUuid())
}
// MarshalLogObject implements custom marshalling for logs
func (policy *Policy) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
encoder.AddString("Id", policy.Id)
encoder.AddString("Description", policy.Description)
encoder.AddReflected("Resources", policy.Resources)
encoder.AddReflected("Actions", policy.Actions)
encoder.AddReflected("Subjects", policy.Subjects)
encoder.AddReflected("Conditions", policy.Conditions)
return nil
}
// Zap simply returns a zapcore.Field object populated with this policy under a standard key
func (policy *Policy) Zap() zapcore.Field { return zap.Object(common.KEY_POLICY, policy) }
// ZapId simply calls zap.String() with PolicyId standard key and this policy id
func (policy *Policy) ZapId() zapcore.Field { return zap.String(common.KEY_POLICY_ID, policy.GetId()) }
// MarshalLogObject implements custom marshalling for logs
func (acl *ACL) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
encoder.AddString("ID", acl.ID)
encoder.AddString("NodeID", acl.NodeID)
encoder.AddString("WorkspaceID", acl.WorkspaceID)
encoder.AddString("RoleID", acl.RoleID)
encoder.AddObject("Action", acl.Action)
return nil
}
func (action *ACLAction) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
encoder.AddString("Name", action.Name)
encoder.AddString("Value", action.Value)
return nil
}
// Zap simply returns a zapcore.Field object populated with this acl under a standard key
func (acl *ACL) Zap() zapcore.Field { return zap.Object(common.KEY_ACL, acl) }
// ZapId simply calls zap.String() with AclId standard key and this acl id
func (acl *ACL) ZapId() zapcore.Field { return zap.String(common.KEY_ACL_ID, acl.GetID()) }
/* WORSPACES, CELLS
*/
// MarshalLogObject implements custom marshalling for logs
func (workspace *Workspace) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
encoder.AddString("UUID", workspace.UUID)
encoder.AddString("Label", workspace.Label)
encoder.AddString("Description", workspace.Description)
encoder.AddString("Slug", workspace.Slug)
encoder.AddString("Scope", workspace.Scope.String())
encoder.AddTime("LastUpdated", time.Unix(int64(workspace.LastUpdated), 0))
encoder.AddString("Attributes", workspace.Attributes)
encoder.AddBool("PoliciesContextEditable", workspace.PoliciesContextEditable)
if len(workspace.RootUUIDs) > 0 {
encoder.AddReflected("RootUUIDs", workspace.RootUUIDs)
}
if len(workspace.RootNodes) > 0 {
encoder.AddReflected("RootNodes", workspace.RootNodes)
}
encoder.AddReflected("Policies", workspace.Policies)
return nil
}
// Zap simply returns a zapcore.Field object populated with this workspace under a standard key
func (workspace *Workspace) Zap() zapcore.Field { return zap.Object(common.KEY_WORKSPACE, workspace) }
// ZapUuid simply calls zap.String() with WorkspaceUuid standard key and this Workspace uuid
func (workspace *Workspace) ZapUuid() zapcore.Field {
return zap.String(common.KEY_WORKSPACE_UUID, workspace.GetUUID())
}