2018-08-06 01:18:54 -07:00
|
|
|
package types
|
|
|
|
|
2018-11-07 04:36:42 -08:00
|
|
|
import (
|
2018-08-06 01:18:54 -07:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2018-11-07 04:36:42 -08:00
|
|
|
"github.com/hashicorp/golang-lru"
|
2019-04-09 02:52:06 -07:00
|
|
|
"math/big"
|
2019-04-17 04:16:16 -07:00
|
|
|
"strings"
|
2018-11-12 00:16:56 -08:00
|
|
|
"sync"
|
2018-08-06 01:18:54 -07:00
|
|
|
)
|
|
|
|
|
2018-08-12 19:00:35 -07:00
|
|
|
type AccessType uint8
|
|
|
|
|
|
|
|
const (
|
2019-01-28 22:06:24 -08:00
|
|
|
ReadOnly AccessType = iota
|
2018-08-12 19:00:35 -07:00
|
|
|
Transact
|
|
|
|
ContractDeploy
|
2019-02-11 17:54:13 -08:00
|
|
|
FullAccess
|
2018-08-12 19:00:35 -07:00
|
|
|
)
|
|
|
|
|
2019-03-27 04:07:01 -07:00
|
|
|
type OrgStatus uint8
|
|
|
|
|
|
|
|
const (
|
2019-03-29 02:49:46 -07:00
|
|
|
OrgPendingApproval OrgStatus = iota + 1
|
2019-03-28 21:28:11 -07:00
|
|
|
OrgApproved
|
|
|
|
OrgPendingSuspension
|
|
|
|
OrgSuspended
|
|
|
|
OrgRevokeSuspension
|
2019-03-27 04:07:01 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
type OrgInfo struct {
|
2019-04-11 02:17:12 -07:00
|
|
|
OrgId string `json:"orgId"`
|
|
|
|
FullOrgId string `json:"fullOrgId"`
|
|
|
|
ParentOrgId string `json:"parentOrgId"`
|
|
|
|
UltimateParent string `json:"ultimateParent"`
|
|
|
|
Level *big.Int `json:"level"`
|
|
|
|
SubOrgList []string `json:"subOrgList"`
|
|
|
|
Status OrgStatus `json:"status"`
|
2019-03-27 04:07:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
type NodeStatus uint8
|
|
|
|
|
|
|
|
const (
|
2019-03-28 21:28:11 -07:00
|
|
|
NodePendingApproval NodeStatus = iota + 1
|
2019-03-27 04:07:01 -07:00
|
|
|
NodeApproved
|
2019-03-28 21:28:11 -07:00
|
|
|
NodeDeactivated
|
2019-03-29 02:49:46 -07:00
|
|
|
NodeActivated
|
|
|
|
NodeBlackListed
|
2019-03-27 04:07:01 -07:00
|
|
|
)
|
|
|
|
|
2019-03-28 21:28:11 -07:00
|
|
|
type AcctStatus uint8
|
|
|
|
|
|
|
|
const (
|
|
|
|
AcctPendingApproval AcctStatus = iota + 1
|
|
|
|
AcctActive
|
|
|
|
AcctInactive
|
2019-04-15 00:09:05 -07:00
|
|
|
AcctSuspended
|
|
|
|
AcctBlacklisted
|
2019-04-23 23:40:28 -07:00
|
|
|
AdminRevoked
|
2019-03-28 21:28:11 -07:00
|
|
|
)
|
|
|
|
|
2019-03-27 04:07:01 -07:00
|
|
|
type NodeInfo struct {
|
2019-04-11 02:17:12 -07:00
|
|
|
OrgId string `json:"orgId"`
|
|
|
|
Url string `json:"url"`
|
|
|
|
Status NodeStatus `json:"status"`
|
2019-03-27 04:07:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
type RoleInfo struct {
|
2019-04-11 02:17:12 -07:00
|
|
|
OrgId string `json:"orgId"`
|
|
|
|
RoleId string `json:"roleId"`
|
|
|
|
IsVoter bool `json:"isVoter"`
|
|
|
|
Access AccessType `json:"access"`
|
|
|
|
Active bool `json:"active"`
|
2019-03-27 04:07:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
type AccountInfo struct {
|
2019-04-11 02:17:12 -07:00
|
|
|
OrgId string `json:"orgId"`
|
|
|
|
RoleId string `json:"roleId"`
|
|
|
|
AcctId common.Address `json:"acctId"`
|
|
|
|
IsOrgAdmin bool `json:"isOrgAdmin"`
|
|
|
|
Status AcctStatus `json:"status"`
|
2019-03-27 04:07:01 -07:00
|
|
|
}
|
|
|
|
|
2019-04-09 06:11:32 -07:00
|
|
|
type OrgDetailInfo struct {
|
2019-04-12 05:28:22 -07:00
|
|
|
NodeList []NodeInfo `json:"nodeList"`
|
|
|
|
RoleList []RoleInfo `json:"roleList"`
|
|
|
|
AcctList []AccountInfo `json:"acctList"`
|
|
|
|
SubOrgList []string `json:"subOrgList"`
|
2019-04-09 06:11:32 -07:00
|
|
|
}
|
|
|
|
|
2018-09-27 04:24:38 -07:00
|
|
|
type OrgStruct struct {
|
|
|
|
OrgId string
|
2018-11-07 04:36:42 -08:00
|
|
|
Keys []string
|
2018-09-27 04:24:38 -07:00
|
|
|
}
|
2018-11-14 02:24:28 -08:00
|
|
|
|
2019-03-11 20:18:20 -07:00
|
|
|
// permission config for bootstrapping
|
|
|
|
type PermissionConfig struct {
|
2019-03-31 23:33:44 -07:00
|
|
|
UpgrdAddress common.Address
|
|
|
|
InterfAddress common.Address
|
|
|
|
ImplAddress common.Address
|
|
|
|
NodeAddress common.Address
|
|
|
|
AccountAddress common.Address
|
|
|
|
RoleAddress common.Address
|
|
|
|
VoterAddress common.Address
|
|
|
|
OrgAddress common.Address
|
2019-03-22 04:34:15 -07:00
|
|
|
NwAdminOrg string
|
|
|
|
NwAdminRole string
|
|
|
|
OrgAdminRole string
|
|
|
|
|
2019-04-14 21:32:06 -07:00
|
|
|
Accounts []common.Address //initial list of account that need full access
|
|
|
|
SubOrgDepth big.Int
|
|
|
|
SubOrgBreadth big.Int
|
2019-03-11 20:18:20 -07:00
|
|
|
}
|
|
|
|
|
2019-03-27 04:07:01 -07:00
|
|
|
type OrgKey struct {
|
|
|
|
OrgId string
|
|
|
|
}
|
|
|
|
|
|
|
|
type NodeKey struct {
|
|
|
|
OrgId string
|
|
|
|
Url string
|
|
|
|
}
|
|
|
|
|
|
|
|
type RoleKey struct {
|
|
|
|
OrgId string
|
|
|
|
RoleId string
|
|
|
|
}
|
|
|
|
|
|
|
|
type AccountKey struct {
|
|
|
|
AcctId common.Address
|
|
|
|
}
|
|
|
|
|
|
|
|
type OrgCache struct {
|
|
|
|
c *lru.Cache
|
|
|
|
mux sync.Mutex
|
|
|
|
}
|
|
|
|
|
|
|
|
type NodeCache struct {
|
|
|
|
c *lru.Cache
|
|
|
|
mux sync.Mutex
|
|
|
|
}
|
|
|
|
|
|
|
|
type RoleCache struct {
|
|
|
|
c *lru.Cache
|
|
|
|
mux sync.Mutex
|
|
|
|
}
|
|
|
|
|
|
|
|
type AcctCache struct {
|
|
|
|
c *lru.Cache
|
|
|
|
mux sync.Mutex
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewOrgCache() *OrgCache {
|
|
|
|
c, _ := lru.New(defaultMapLimit)
|
|
|
|
return &OrgCache{c, sync.Mutex{}}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewNodeCache() *NodeCache {
|
|
|
|
c, _ := lru.New(defaultMapLimit)
|
|
|
|
return &NodeCache{c, sync.Mutex{}}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewRoleCache() *RoleCache {
|
|
|
|
c, _ := lru.New(defaultMapLimit)
|
|
|
|
return &RoleCache{c, sync.Mutex{}}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewAcctCache() *AcctCache {
|
|
|
|
c, _ := lru.New(defaultMapLimit)
|
|
|
|
return &AcctCache{c, sync.Mutex{}}
|
|
|
|
}
|
|
|
|
|
2018-11-13 00:15:28 -08:00
|
|
|
var DefaultAccess = FullAccess
|
2019-04-23 23:40:28 -07:00
|
|
|
var networkAdminRole string
|
|
|
|
var orgAdminRole string
|
2018-08-06 01:18:54 -07:00
|
|
|
|
2018-11-12 00:16:56 -08:00
|
|
|
const orgKeyMapLimit = 100
|
2018-09-27 04:24:38 -07:00
|
|
|
|
2019-03-27 04:07:01 -07:00
|
|
|
const defaultMapLimit = 100
|
2018-11-12 00:16:56 -08:00
|
|
|
|
|
|
|
var OrgKeyMap, _ = lru.New(orgKeyMapLimit)
|
|
|
|
|
2019-03-27 04:07:01 -07:00
|
|
|
var OrgInfoMap = NewOrgCache()
|
|
|
|
var NodeInfoMap = NewNodeCache()
|
|
|
|
var RoleInfoMap = NewRoleCache()
|
|
|
|
var AcctInfoMap = NewAcctCache()
|
|
|
|
|
2018-11-12 00:16:56 -08:00
|
|
|
var orgKeyLock sync.Mutex
|
2018-08-06 01:18:54 -07:00
|
|
|
|
2019-03-13 23:26:17 -07:00
|
|
|
func (pc *PermissionConfig) IsEmpty() bool {
|
2019-03-31 23:33:44 -07:00
|
|
|
return pc.InterfAddress == common.HexToAddress("0x0") || pc.NodeAddress == common.HexToAddress("0x0") || pc.AccountAddress == common.HexToAddress("0x0")
|
2019-03-13 23:26:17 -07:00
|
|
|
}
|
|
|
|
|
2019-02-12 17:57:11 -08:00
|
|
|
// sets default access to ReadOnly
|
2018-11-13 00:15:28 -08:00
|
|
|
func SetDefaultAccess() {
|
2019-03-28 23:50:38 -07:00
|
|
|
DefaultAccess = ReadOnly
|
2018-11-13 00:15:28 -08:00
|
|
|
}
|
2019-02-12 17:57:11 -08:00
|
|
|
|
2019-04-23 23:40:28 -07:00
|
|
|
func SetAdminRole(nwRoleId, oaRoleId string) {
|
|
|
|
networkAdminRole = nwRoleId
|
|
|
|
orgAdminRole = oaRoleId
|
|
|
|
}
|
|
|
|
|
2019-04-09 02:52:06 -07:00
|
|
|
func (o *OrgCache) UpsertOrg(orgId, parentOrg, ultimateParent string, level *big.Int, status OrgStatus) {
|
2019-03-27 20:01:33 -07:00
|
|
|
defer o.mux.Unlock()
|
|
|
|
o.mux.Lock()
|
2019-04-09 02:52:06 -07:00
|
|
|
var key OrgKey
|
|
|
|
if parentOrg == "" {
|
|
|
|
key = OrgKey{OrgId: orgId}
|
|
|
|
} else {
|
2019-04-09 06:11:32 -07:00
|
|
|
key = OrgKey{OrgId: parentOrg + "." + orgId}
|
|
|
|
pkey := OrgKey{OrgId: parentOrg}
|
|
|
|
if ent, ok := o.c.Get(pkey); ok {
|
|
|
|
porg := ent.(*OrgInfo)
|
2019-04-12 05:28:22 -07:00
|
|
|
if !containsKey(porg.SubOrgList, key.OrgId) {
|
|
|
|
porg.SubOrgList = append(porg.SubOrgList, key.OrgId)
|
|
|
|
o.c.Add(pkey, porg)
|
|
|
|
}
|
2019-04-09 06:11:32 -07:00
|
|
|
}
|
2019-04-09 02:52:06 -07:00
|
|
|
}
|
|
|
|
|
2019-04-09 06:11:32 -07:00
|
|
|
norg := &OrgInfo{orgId, key.OrgId, parentOrg, ultimateParent, level, nil, status}
|
|
|
|
o.c.Add(key, norg)
|
2019-03-27 04:07:01 -07:00
|
|
|
}
|
|
|
|
|
2019-04-12 05:28:22 -07:00
|
|
|
func containsKey(s []string, e string) bool {
|
|
|
|
for _, a := range s {
|
|
|
|
if a == e {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-03-27 04:07:01 -07:00
|
|
|
func (o *OrgCache) GetOrg(orgId string) *OrgInfo {
|
2019-03-27 20:01:33 -07:00
|
|
|
defer o.mux.Unlock()
|
|
|
|
o.mux.Lock()
|
2019-03-27 04:07:01 -07:00
|
|
|
key := OrgKey{OrgId: orgId}
|
|
|
|
if ent, ok := o.c.Get(key); ok {
|
|
|
|
return ent.(*OrgInfo)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-03-28 03:59:30 -07:00
|
|
|
func (o *OrgCache) GetOrgList() []OrgInfo {
|
|
|
|
var olist []OrgInfo
|
|
|
|
for _, k := range o.c.Keys() {
|
|
|
|
v, _ := o.c.Get(k)
|
|
|
|
vp := v.(*OrgInfo)
|
|
|
|
olist = append(olist, *vp)
|
|
|
|
}
|
|
|
|
return olist
|
|
|
|
}
|
2019-03-27 04:07:01 -07:00
|
|
|
|
2019-03-28 21:28:11 -07:00
|
|
|
func (n *NodeCache) UpsertNode(orgId string, url string, status NodeStatus) {
|
2019-03-27 20:01:33 -07:00
|
|
|
defer n.mux.Unlock()
|
|
|
|
n.mux.Lock()
|
2019-03-27 04:07:01 -07:00
|
|
|
key := NodeKey{OrgId: orgId, Url: url}
|
2019-04-01 02:48:37 -07:00
|
|
|
n.c.Add(key, &NodeInfo{orgId, url, status})
|
2019-03-27 04:07:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n *NodeCache) GetNodeByUrl(url string) *NodeInfo {
|
2019-03-27 20:01:33 -07:00
|
|
|
defer n.mux.Unlock()
|
|
|
|
n.mux.Lock()
|
2019-03-27 04:07:01 -07:00
|
|
|
for _, k := range n.c.Keys() {
|
|
|
|
ent := k.(NodeKey)
|
|
|
|
if ent.Url == url {
|
2019-04-02 21:21:30 -07:00
|
|
|
v, _ := n.c.Get(ent)
|
|
|
|
return v.(*NodeInfo)
|
2019-03-27 04:07:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-03-28 03:59:30 -07:00
|
|
|
func (o *NodeCache) GetNodeList() []NodeInfo {
|
|
|
|
var olist []NodeInfo
|
|
|
|
for _, k := range o.c.Keys() {
|
|
|
|
v, _ := o.c.Get(k)
|
|
|
|
vp := v.(*NodeInfo)
|
|
|
|
olist = append(olist, *vp)
|
|
|
|
}
|
|
|
|
return olist
|
|
|
|
}
|
|
|
|
|
2019-03-28 21:28:11 -07:00
|
|
|
func (a *AcctCache) UpsertAccount(orgId string, role string, acct common.Address, orgAdmin bool, status AcctStatus) {
|
2019-03-27 20:01:33 -07:00
|
|
|
defer a.mux.Unlock()
|
|
|
|
a.mux.Lock()
|
2019-04-02 23:17:32 -07:00
|
|
|
key := AccountKey{acct}
|
2019-04-01 02:48:37 -07:00
|
|
|
a.c.Add(key, &AccountInfo{orgId, role, acct, orgAdmin, status})
|
2019-03-27 04:07:01 -07:00
|
|
|
}
|
|
|
|
|
2019-04-02 23:17:32 -07:00
|
|
|
func (a *AcctCache) GetAccount(acct common.Address) *AccountInfo {
|
2019-03-27 20:01:33 -07:00
|
|
|
defer a.mux.Unlock()
|
|
|
|
a.mux.Lock()
|
2019-04-02 23:17:32 -07:00
|
|
|
if v, ok := a.c.Get(AccountKey{acct}); ok {
|
|
|
|
return v.(*AccountInfo)
|
2019-03-27 04:07:01 -07:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-04-02 23:17:32 -07:00
|
|
|
func (a *AcctCache) GetAcctList() []AccountInfo {
|
|
|
|
var alist []AccountInfo
|
|
|
|
for _, k := range a.c.Keys() {
|
|
|
|
v, _ := a.c.Get(k)
|
2019-03-28 03:59:30 -07:00
|
|
|
vp := v.(*AccountInfo)
|
2019-04-02 23:17:32 -07:00
|
|
|
alist = append(alist, *vp)
|
2019-03-28 03:59:30 -07:00
|
|
|
}
|
2019-04-02 23:17:32 -07:00
|
|
|
return alist
|
2019-03-28 03:59:30 -07:00
|
|
|
}
|
|
|
|
|
2019-04-05 02:16:08 -07:00
|
|
|
func (a *AcctCache) GetAcctListOrg(orgId string) []AccountInfo {
|
|
|
|
var alist []AccountInfo
|
|
|
|
for _, k := range a.c.Keys() {
|
|
|
|
v, _ := a.c.Get(k)
|
|
|
|
vp := v.(*AccountInfo)
|
|
|
|
if vp.OrgId == orgId {
|
|
|
|
alist = append(alist, *vp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return alist
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AcctCache) GetAcctListRole(orgId, roleId string) []AccountInfo {
|
|
|
|
var alist []AccountInfo
|
|
|
|
for _, k := range a.c.Keys() {
|
|
|
|
v, _ := a.c.Get(k)
|
|
|
|
vp := v.(*AccountInfo)
|
|
|
|
if vp.OrgId == orgId && vp.RoleId == roleId {
|
|
|
|
alist = append(alist, *vp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return alist
|
|
|
|
}
|
|
|
|
|
2019-03-28 21:28:11 -07:00
|
|
|
func (r *RoleCache) UpsertRole(orgId string, role string, voter bool, access AccessType, active bool) {
|
2019-03-27 20:01:33 -07:00
|
|
|
defer r.mux.Unlock()
|
|
|
|
r.mux.Lock()
|
2019-03-27 04:07:01 -07:00
|
|
|
key := RoleKey{orgId, role}
|
2019-04-01 02:48:37 -07:00
|
|
|
r.c.Add(key, &RoleInfo{orgId, role, voter, access, active})
|
|
|
|
|
2019-03-27 04:07:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RoleCache) GetRole(orgId string, roleId string) *RoleInfo {
|
2019-03-27 20:01:33 -07:00
|
|
|
defer r.mux.Unlock()
|
|
|
|
r.mux.Lock()
|
2019-03-27 04:07:01 -07:00
|
|
|
key := RoleKey{OrgId: orgId, RoleId: roleId}
|
|
|
|
if ent, ok := r.c.Get(key); ok {
|
|
|
|
return ent.(*RoleInfo)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-03-28 03:59:30 -07:00
|
|
|
func (o *RoleCache) GetRoleList() []RoleInfo {
|
|
|
|
var olist []RoleInfo
|
|
|
|
for _, k := range o.c.Keys() {
|
|
|
|
v, _ := o.c.Get(k)
|
|
|
|
vp := v.(*RoleInfo)
|
|
|
|
olist = append(olist, *vp)
|
|
|
|
}
|
|
|
|
return olist
|
|
|
|
}
|
|
|
|
|
2019-02-12 17:57:11 -08:00
|
|
|
// Returns the access type for an account. If not found returns
|
|
|
|
// default access
|
2018-08-12 19:00:35 -07:00
|
|
|
func GetAcctAccess(acctId common.Address) AccessType {
|
2019-04-15 00:09:05 -07:00
|
|
|
if a := AcctInfoMap.GetAccount(acctId); a != nil && a.Status == AcctActive {
|
2019-04-23 23:40:28 -07:00
|
|
|
if a.RoleId == networkAdminRole || a.RoleId == orgAdminRole {
|
|
|
|
return FullAccess
|
|
|
|
}
|
|
|
|
if o := OrgInfoMap.GetOrg(a.OrgId); o != nil && o.Status == OrgApproved {
|
|
|
|
if r := RoleInfoMap.GetRole(a.OrgId, a.RoleId); r != nil {
|
|
|
|
return r.Access
|
|
|
|
}
|
|
|
|
if r := RoleInfoMap.GetRole(o.UltimateParent, a.RoleId); r != nil {
|
2019-03-28 23:50:38 -07:00
|
|
|
return r.Access
|
|
|
|
}
|
2018-08-06 01:18:54 -07:00
|
|
|
}
|
|
|
|
}
|
2019-02-06 20:45:29 -08:00
|
|
|
return DefaultAccess
|
2018-08-06 01:18:54 -07:00
|
|
|
}
|
2018-09-27 04:24:38 -07:00
|
|
|
|
2019-04-17 04:16:16 -07:00
|
|
|
func ValidateNodeForTxn(enodeId string, from common.Address) bool {
|
|
|
|
if enodeId == "" {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
ac := AcctInfoMap.GetAccount(from)
|
|
|
|
if ac == nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
ultimateParent := OrgInfoMap.GetOrg(ac.OrgId).UltimateParent
|
|
|
|
// scan through the node list and validate
|
|
|
|
for _, n := range NodeInfoMap.GetNodeList() {
|
|
|
|
if OrgInfoMap.GetOrg(n.OrgId).UltimateParent == ultimateParent && strings.Contains(n.Url, enodeId) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-02-12 17:57:11 -08:00
|
|
|
// Adds org key details to cache
|
2018-11-07 04:36:42 -08:00
|
|
|
func AddOrgKey(orgId string, key string) {
|
|
|
|
if OrgKeyMap.Len() != 0 {
|
|
|
|
if val, ok := OrgKeyMap.Get(orgId); ok {
|
2018-11-12 00:16:56 -08:00
|
|
|
orgKeyLock.Lock()
|
2019-02-12 17:57:11 -08:00
|
|
|
defer orgKeyLock.Unlock()
|
2018-10-02 01:28:55 -07:00
|
|
|
// Org record exists. Append the key only
|
2018-11-07 04:36:42 -08:00
|
|
|
vo := val.(*OrgStruct)
|
|
|
|
vo.Keys = append(vo.Keys, key)
|
2018-10-02 01:28:55 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2018-11-07 04:36:42 -08:00
|
|
|
OrgKeyMap.Add(orgId, &OrgStruct{OrgId: orgId, Keys: []string{key}})
|
2018-10-02 01:28:55 -07:00
|
|
|
}
|
|
|
|
|
2019-02-12 17:57:11 -08:00
|
|
|
// deletes org key details from cache
|
2018-11-07 04:36:42 -08:00
|
|
|
func DeleteOrgKey(orgId string, key string) {
|
|
|
|
if val, ok := OrgKeyMap.Get(orgId); ok {
|
2018-11-12 00:16:56 -08:00
|
|
|
orgKeyLock.Lock()
|
2019-02-12 17:57:11 -08:00
|
|
|
defer orgKeyLock.Unlock()
|
2018-11-07 04:36:42 -08:00
|
|
|
vo := val.(*OrgStruct)
|
|
|
|
for i, keyVal := range vo.Keys {
|
|
|
|
if keyVal == key {
|
|
|
|
vo.Keys = append(vo.Keys[:i], vo.Keys[i+1:]...)
|
|
|
|
break
|
2018-10-02 01:28:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-27 04:24:38 -07:00
|
|
|
}
|
|
|
|
|
2019-02-12 17:57:11 -08:00
|
|
|
// Givens a orgid returns the linked keys for the org
|
2018-11-07 04:36:42 -08:00
|
|
|
func ResolvePrivateForKeys(orgId string) []string {
|
2018-09-27 04:24:38 -07:00
|
|
|
var keys []string
|
2018-11-07 04:36:42 -08:00
|
|
|
if val, ok := OrgKeyMap.Get(orgId); ok {
|
|
|
|
vo := val.(*OrgStruct)
|
|
|
|
if len(vo.Keys) > 0 {
|
|
|
|
keys = vo.Keys
|
|
|
|
} else {
|
|
|
|
keys = append(keys, orgId)
|
2018-09-27 04:24:38 -07:00
|
|
|
}
|
2018-11-07 04:36:42 -08:00
|
|
|
return keys
|
2018-09-27 04:24:38 -07:00
|
|
|
}
|
|
|
|
keys = append(keys, orgId)
|
|
|
|
return keys
|
|
|
|
}
|