consul/agent/connect/uri_service.go

38 lines
836 B
Go
Raw Normal View History

2018-03-26 00:39:18 +00:00
package connect
import (
"net/url"
"github.com/hashicorp/consul/acl"
2018-03-26 00:39:18 +00:00
)
// SpiffeIDService is the structure to represent the SPIFFE ID for a service.
type SpiffeIDService struct {
Host string
Partition string
2018-03-26 00:39:18 +00:00
Namespace string
Datacenter string
Service string
}
func (id SpiffeIDService) NamespaceOrDefault() string {
return acl.NamespaceOrDefault(id.Namespace)
}
func (id SpiffeIDService) MatchesPartition(partition string) bool {
return id.PartitionOrDefault() == acl.PartitionOrDefault(partition)
}
func (id SpiffeIDService) PartitionOrDefault() string {
return acl.PartitionOrDefault(id.Partition)
}
2018-03-26 00:39:18 +00:00
// URI returns the *url.URL for this SPIFFE ID.
func (id SpiffeIDService) URI() *url.URL {
2018-03-26 00:39:18 +00:00
var result url.URL
result.Scheme = "spiffe"
result.Host = id.Host
result.Path = id.uriPath()
2018-03-26 00:39:18 +00:00
return &result
}