File: bearer_token_signer_adapter.go

package info (click to toggle)
golang-github-aws-aws-sdk-go-v2 1.24.1-2~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 554,032 kB
  • sloc: java: 15,941; makefile: 419; sh: 175
file content (35 lines) | stat: -rw-r--r-- 921 bytes parent folder | download | duplicates (7)
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
package smithy

import (
	"context"
	"fmt"

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

// BearerTokenSignerAdapter adapts smithy bearer.Signer to smithy http
// auth.Signer.
type BearerTokenSignerAdapter struct {
	Signer bearer.Signer
}

var _ (smithyhttp.Signer) = (*BearerTokenSignerAdapter)(nil)

// SignRequest signs the request with the provided bearer token.
func (v *BearerTokenSignerAdapter) SignRequest(ctx context.Context, r *smithyhttp.Request, identity auth.Identity, _ smithy.Properties) error {
	ca, ok := identity.(*BearerTokenAdapter)
	if !ok {
		return fmt.Errorf("unexpected identity type: %T", identity)
	}

	signed, err := v.Signer.SignWithBearerToken(ctx, ca.Token, r)
	if err != nil {
		return fmt.Errorf("sign request: %w", err)
	}

	*r = *signed.(*smithyhttp.Request)
	return nil
}