mirror of https://github.com/status-im/consul.git
Rework acl exports interface
This commit is contained in:
parent
0a4ff4bb91
commit
43360eb216
10
acl/acl.go
10
acl/acl.go
|
@ -14,9 +14,13 @@ type Config struct {
|
||||||
EnterpriseConfig
|
EnterpriseConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
type PartitionExportInfo interface {
|
type ExportFetcher interface {
|
||||||
// DownstreamPartitions returns the list of partitions the given service has been exported to.
|
// ExportsForPartition returns the config entry defining exports for a partition
|
||||||
DownstreamPartitions(service string, anyService bool, ctx *AuthorizerContext) []string
|
ExportsForPartition(partition string) PartitionExports
|
||||||
|
}
|
||||||
|
|
||||||
|
type PartitionExports struct {
|
||||||
|
Data map[string]map[string][]string
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetWildcardName will retrieve the configured wildcard name or provide a default
|
// GetWildcardName will retrieve the configured wildcard name or provide a default
|
||||||
|
|
|
@ -1906,6 +1906,6 @@ func filterACL(r *ACLResolver, token string, subj interface{}) error {
|
||||||
|
|
||||||
type partitionInfoNoop struct{}
|
type partitionInfoNoop struct{}
|
||||||
|
|
||||||
func (p *partitionInfoNoop) DownstreamPartitions(service string, anyService bool, ctx *acl.AuthorizerContext) []string {
|
func (p *partitionInfoNoop) ExportsForPartition(partition string) acl.PartitionExports {
|
||||||
return []string{}
|
return acl.PartitionExports{}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,11 +15,11 @@ func (s *Server) replicationEnterpriseMeta() *structs.EnterpriseMeta {
|
||||||
return structs.ReplicationEnterpriseMeta()
|
return structs.ReplicationEnterpriseMeta()
|
||||||
}
|
}
|
||||||
|
|
||||||
func serverPartitionInfo(s *Server) acl.PartitionExportInfo {
|
func serverPartitionInfo(s *Server) acl.ExportFetcher {
|
||||||
return &partitionInfoNoop{}
|
return &partitionInfoNoop{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newACLConfig(_ acl.PartitionExportInfo, _ hclog.Logger) *acl.Config {
|
func newACLConfig(_ acl.ExportFetcher, _ hclog.Logger) *acl.Config {
|
||||||
return &acl.Config{
|
return &acl.Config{
|
||||||
WildcardName: structs.WildcardSpecifier,
|
WildcardName: structs.WildcardSpecifier,
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,23 @@ type ServiceConsumer struct {
|
||||||
Partition string
|
Partition string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *PartitionExportsConfigEntry) ToMap() map[string]map[string][]string {
|
||||||
|
resp := make(map[string]map[string][]string)
|
||||||
|
for _, svc := range e.Services {
|
||||||
|
if _, ok := resp[svc.Namespace]; !ok {
|
||||||
|
resp[svc.Namespace] = make(map[string][]string)
|
||||||
|
}
|
||||||
|
if _, ok := resp[svc.Namespace][svc.Name]; !ok {
|
||||||
|
consumers := make([]string, 0, len(svc.Consumers))
|
||||||
|
for _, c := range svc.Consumers {
|
||||||
|
consumers = append(consumers, c.Partition)
|
||||||
|
}
|
||||||
|
resp[svc.Namespace][svc.Name] = consumers
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resp
|
||||||
|
}
|
||||||
|
|
||||||
func (e *PartitionExportsConfigEntry) Clone() *PartitionExportsConfigEntry {
|
func (e *PartitionExportsConfigEntry) Clone() *PartitionExportsConfigEntry {
|
||||||
e2 := *e
|
e2 := *e
|
||||||
e2.Services = make([]ExportedService, len(e.Services))
|
e2.Services = make([]ExportedService, len(e.Services))
|
||||||
|
|
Loading…
Reference in New Issue