989b22425c
Having this type live in the agent/consul package makes it difficult to put anything that relies on token resolution (e.g. the new gRPC services) in separate packages without introducing import cycles. For example, if package foo imports agent/consul for the ACLResolveResult type it means that agent/consul cannot import foo to register its service. We've previously worked around this by wrapping the ACLResolver to "downgrade" its return type to an acl.Authorizer - aside from the added complexity, this also loses the resolved identity information. In the future, we may want to move the whole ACLResolver into the acl/resolver package. For now, putting the result type there at least, fixes the immediate import cycle issues.
28 lines
544 B
Go
28 lines
544 B
Go
package resolver
|
|
|
|
import (
|
|
"github.com/hashicorp/consul/acl"
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
)
|
|
|
|
type Result struct {
|
|
acl.Authorizer
|
|
// TODO: likely we can reduce this interface
|
|
ACLIdentity structs.ACLIdentity
|
|
}
|
|
|
|
func (a Result) AccessorID() string {
|
|
if a.ACLIdentity == nil {
|
|
return ""
|
|
}
|
|
return a.ACLIdentity.ID()
|
|
}
|
|
|
|
func (a Result) Identity() structs.ACLIdentity {
|
|
return a.ACLIdentity
|
|
}
|
|
|
|
func (a Result) ToAllowAuthorizer() acl.AllowAuthorizer {
|
|
return acl.AllowAuthorizer{Authorizer: a, AccessorID: a.AccessorID()}
|
|
}
|