File: auth.go

package info (click to toggle)
golang-github-scaleway-scaleway-sdk-go 1.0.0~beta32-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,444 kB
  • sloc: sh: 70; makefile: 3
file content (29 lines) | stat: -rw-r--r-- 720 bytes parent folder | download
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
package auth

import "net/http"

// Auth implement methods required for authentication.
// Valid authentication are currently a token or no auth.
type Auth interface {
	// Headers returns headers that must be add to the http request
	Headers() http.Header

	// AnonymizedHeaders returns an anonymised version of Headers()
	// This method could be use for logging purpose.
	AnonymizedHeaders() http.Header
}

type headerAnonymizer func(header http.Header) http.Header

var headerAnonymizers = []headerAnonymizer{
	AnonymizeTokenHeaders,
	AnonymizeJWTHeaders,
}

func AnonymizeHeaders(headers http.Header) http.Header {
	for _, anonymizer := range headerAnonymizers {
		headers = anonymizer(headers)
	}

	return headers
}