File: sanitizeurl.go

package info (click to toggle)
golang-github-aws-aws-sdk-go-v2 1.30.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 662,428 kB
  • sloc: java: 16,875; makefile: 432; sh: 175
file content (63 lines) | stat: -rw-r--r-- 2,123 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package customizations

import (
	"context"
	"fmt"

	"github.com/aws/smithy-go"
	"github.com/aws/smithy-go/middleware"
	smithyhttp "github.com/aws/smithy-go/transport/http"
)

// AddSanitizeURLMiddlewareOptions provides the options for Route53SanitizeURL middleware setup
type AddSanitizeURLMiddlewareOptions struct {
	// functional pointer to sanitize hosted zone id member
	// The function is intended to take an input value,
	// look for hosted zone id input member and sanitize the value
	// to strip out an excess `/hostedzone/` prefix that can be present in
	// the hosted zone id input member.
	//
	// returns an error if any.
	SanitizeURLInput func(interface{}) error
}

// AddSanitizeURLMiddleware add the middleware necessary to modify Route53 input before op serialization.
func AddSanitizeURLMiddleware(stack *middleware.Stack, options AddSanitizeURLMiddlewareOptions) error {
	return stack.Serialize.Insert(&sanitizeURL{
		sanitizeURLInput: options.SanitizeURLInput,
	}, "OperationSerializer", middleware.Before)
}

// sanitizeURL cleans up potential formatting issues in the Route53 path.
//
// Notably it will strip out an excess `/hostedzone/` prefix that can be present in
// the hosted zone id input member. That excess prefix is there because some route53 apis return
// the id in that format, so this middleware enables round-tripping those values.
type sanitizeURL struct {
	sanitizeURLInput func(interface{}) error
}

// ID returns the id for the middleware.
func (*sanitizeURL) ID() string {
	return "Route53:SanitizeURL"
}

// HandleSerialize implements the SerializeMiddleware interface.
func (m *sanitizeURL) HandleSerialize(
	ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler,
) (
	out middleware.SerializeOutput, metadata middleware.Metadata, err error,
) {
	_, ok := in.Request.(*smithyhttp.Request)
	if !ok {
		return out, metadata, &smithy.SerializationError{
			Err: fmt.Errorf("unknown request type %T", in.Request),
		}
	}

	if err := m.sanitizeURLInput(in.Parameters); err != nil {
		return out, metadata, err
	}

	return next.HandleSerialize(ctx, in)
}