mirror of
https://github.com/status-im/consul.git
synced 2025-01-10 05:45:46 +00:00
cd1b613352
* Update AWS SDK to use PCA features. * Add AWS PCA provider * Add plumbing for config, config validation tests, add test for inheriting existing CA resources created by user * Unparallel the tests so we don't exhaust PCA limits * Merge updates * More aggressive polling; rate limit pass through on sign; Timeout on Sign and CA create * Add AWS PCA docs * Fix Vault doc typo too * Doc typo * Apply suggestions from code review Co-Authored-By: R.B. Boyer <rb@hashicorp.com> Co-Authored-By: kaitlincarter-hc <43049322+kaitlincarter-hc@users.noreply.github.com> * Doc fixes; tests for erroring if State is modified via API * More review cleanup * Uncomment tests! * Minor suggested clean ups
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package protocol
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
"github.com/aws/aws-sdk-go/aws/request"
|
|
)
|
|
|
|
// HostPrefixHandlerName is the handler name for the host prefix request
|
|
// handler.
|
|
const HostPrefixHandlerName = "awssdk.endpoint.HostPrefixHandler"
|
|
|
|
// NewHostPrefixHandler constructs a build handler
|
|
func NewHostPrefixHandler(prefix string, labelsFn func() map[string]string) request.NamedHandler {
|
|
builder := HostPrefixBuilder{
|
|
Prefix: prefix,
|
|
LabelsFn: labelsFn,
|
|
}
|
|
|
|
return request.NamedHandler{
|
|
Name: HostPrefixHandlerName,
|
|
Fn: builder.Build,
|
|
}
|
|
}
|
|
|
|
// HostPrefixBuilder provides the request handler to expand and prepend
|
|
// the host prefix into the operation's request endpoint host.
|
|
type HostPrefixBuilder struct {
|
|
Prefix string
|
|
LabelsFn func() map[string]string
|
|
}
|
|
|
|
// Build updates the passed in Request with the HostPrefix template expanded.
|
|
func (h HostPrefixBuilder) Build(r *request.Request) {
|
|
if aws.BoolValue(r.Config.DisableEndpointHostPrefix) {
|
|
return
|
|
}
|
|
|
|
var labels map[string]string
|
|
if h.LabelsFn != nil {
|
|
labels = h.LabelsFn()
|
|
}
|
|
|
|
prefix := h.Prefix
|
|
for name, value := range labels {
|
|
prefix = strings.Replace(prefix, "{"+name+"}", value, -1)
|
|
}
|
|
|
|
r.HTTPRequest.URL.Host = prefix + r.HTTPRequest.URL.Host
|
|
if len(r.HTTPRequest.Host) > 0 {
|
|
r.HTTPRequest.Host = prefix + r.HTTPRequest.Host
|
|
}
|
|
}
|