2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-28 18:39:22 +00:00
|
|
|
|
2019-06-27 20:22:07 +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"
|
2019-06-27 20:22:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// SpiffeIDService is the structure to represent the SPIFFE ID for an agent.
|
|
|
|
type SpiffeIDAgent struct {
|
|
|
|
Host string
|
2021-06-25 21:47:47 +00:00
|
|
|
Partition string
|
2019-06-27 20:22:07 +00:00
|
|
|
Datacenter string
|
|
|
|
Agent string
|
|
|
|
}
|
|
|
|
|
2021-06-25 21:47:47 +00:00
|
|
|
func (id SpiffeIDAgent) PartitionOrDefault() string {
|
2022-04-05 21:10:06 +00:00
|
|
|
return acl.PartitionOrDefault(id.Partition)
|
2021-06-25 21:47:47 +00:00
|
|
|
}
|
|
|
|
|
2019-06-27 20:22:07 +00:00
|
|
|
// URI returns the *url.URL for this SPIFFE ID.
|
2021-06-25 21:47:47 +00:00
|
|
|
func (id SpiffeIDAgent) URI() *url.URL {
|
2019-06-27 20:22:07 +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()
|
2019-06-27 20:22:07 +00:00
|
|
|
return &result
|
|
|
|
}
|