-
Notifications
You must be signed in to change notification settings - Fork 0
/
access_control.go
53 lines (48 loc) · 1.54 KB
/
access_control.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
/*******************************************************************************
*
*
* (c) Copyright Merative US L.P. and others 2020-2022
*
* SPDX-Licence-Identifier: Apache 2.0
*
*******************************************************************************/
// Package data_model contains structs used across packages to prevent circular imports.
// For example, the User struct is needed by both asset_mgmt and user_mgmt, but user_mgmt
// depends on functions in asset_mgmt.
// They can't import each other, so the shared structs live here.
package data_model
import (
"common/bchcls/internal/common/global"
)
// AccessControl represents a user's read or write access to an asset.
// UserKey is optional
type AccessControl struct {
UserId string `json:"userid"`
UserKey *Key `json:"user_key"`
AssetId string `json:"assetid"`
AssetKey *Key `json:"asset_key"`
Access string `json:"access"`
}
// IsValid checks if an AccessControl object's fields are valid
func (a *AccessControl) IsValid() bool {
if len(a.UserId) == 0 {
return false
}
if len(a.AssetId) == 0 {
return false
}
if a.Access != global.ACCESS_READ &&
a.Access != global.ACCESS_READ_ONLY &&
a.Access != global.ACCESS_WRITE &&
a.Access != global.ACCESS_WRITE_ONLY {
return false
}
return true
}
// AccessControlFilters are filters for key traversal functions, which can be passed along each function call.
// Used with the SlowCheckAccessToKey function.
type AccessControlFilters struct {
AssetFilters []string
OwnerFilters []string
DatatypeFilters []string
}