Adding a Clone() function to the request hanlder to be used when theres a need to modify the current request before saving it (#9499)

This commit is contained in:
Rodrigo D. L
2020-07-16 15:53:46 +02:00
committed by GitHub
parent 73b1eed7c9
commit faf2958cde
3 changed files with 23 additions and 1 deletions

View File

@@ -5,6 +5,8 @@ import (
"net/http"
"strings"
"time"
"github.com/mitchellh/copystructure"
)
// RequestWrapInfo is a struct that stores information about desired response
@@ -179,6 +181,15 @@ type Request struct {
ResponseWriter *HTTPResponseWriter `json:"-" sentinel:""`
}
// Clone returns a deep copy of the request by using copystructure
func (r *Request) Clone() (*Request, error) {
cpy, err := copystructure.Copy(r)
if err != nil {
return nil, err
}
return cpy.(*Request), nil
}
// Get returns a data field and guards for nil Data
func (r *Request) Get(key string) interface{} {
if r.Data == nil {

View File

@@ -62,7 +62,7 @@ func (c *CredentialsConfig) GenerateCredentialChain() (*credentials.Credentials,
roleARN := os.Getenv("AWS_ROLE_ARN")
tokenPath := os.Getenv("AWS_WEB_IDENTITY_TOKEN_FILE")
sessionName := os.Getenv("AWS_ROLE_SESSION_NAME")
if roleARN != "" && tokenPath != "" && sessionName != "" {
if roleARN != "" && tokenPath != "" {
// this session is only created to create the WebIdentityRoleProvider, as the env variables are already there
// this automatically assumes the role, but the provider needs to be added to the chain
sess, err := session.NewSession()

View File

@@ -5,6 +5,8 @@ import (
"net/http"
"strings"
"time"
"github.com/mitchellh/copystructure"
)
// RequestWrapInfo is a struct that stores information about desired response
@@ -179,6 +181,15 @@ type Request struct {
ResponseWriter *HTTPResponseWriter `json:"-" sentinel:""`
}
// Clone returns a deep copy of the request by using copystructure
func (r *Request) Clone() (*Request, error) {
cpy, err := copystructure.Copy(r)
if err != nil {
return nil, err
}
return cpy.(*Request), nil
}
// Get returns a data field and guards for nil Data
func (r *Request) Get(key string) interface{} {
if r.Data == nil {