2018-03-26 00:39:18 +00:00
|
|
|
package connect
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
2021-06-25 21:47:47 +00:00
|
|
|
|
2022-04-05 21:10:06 +00:00
|
|
|
"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
|
2021-06-25 21:47:47 +00:00
|
|
|
Partition string
|
2018-03-26 00:39:18 +00:00
|
|
|
Namespace string
|
|
|
|
Datacenter string
|
|
|
|
Service string
|
|
|
|
}
|
|
|
|
|
2021-06-25 21:47:47 +00:00
|
|
|
func (id SpiffeIDService) NamespaceOrDefault() string {
|
2022-04-05 21:10:06 +00:00
|
|
|
return acl.NamespaceOrDefault(id.Namespace)
|
2021-06-25 21:47:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (id SpiffeIDService) MatchesPartition(partition string) bool {
|
2022-04-05 21:10:06 +00:00
|
|
|
return id.PartitionOrDefault() == acl.PartitionOrDefault(partition)
|
2021-06-25 21:47:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (id SpiffeIDService) PartitionOrDefault() string {
|
2022-04-05 21:10:06 +00:00
|
|
|
return acl.PartitionOrDefault(id.Partition)
|
2021-06-25 21:47:47 +00:00
|
|
|
}
|
|
|
|
|
2018-03-26 00:39:18 +00:00
|
|
|
// URI returns the *url.URL for this SPIFFE ID.
|
2021-06-25 21:47:47 +00:00
|
|
|
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
|
2021-06-25 21:47:47 +00:00
|
|
|
result.Path = id.uriPath()
|
2018-03-26 00:39:18 +00:00
|
|
|
return &result
|
|
|
|
}
|