mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 17:35:28 +00:00
* use parsed options while signing * update project layout to v3 * fix .gitignore * remove example template * misc updates * bump tlsx version * hide template sig warning with env * js: retain value while using log * fix nil pointer derefernce * misc doc update --------- Co-authored-by: sandeep <8293321+ehsandeep@users.noreply.github.com>
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package signer
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/http"
|
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
|
)
|
|
|
|
// An Argument that can be passed to Signer
|
|
type SignerArg string
|
|
|
|
type Signer interface {
|
|
SignHTTP(ctx context.Context, request *http.Request) error
|
|
}
|
|
|
|
type SignerArgs interface {
|
|
Validate() error
|
|
}
|
|
|
|
func NewSigner(args SignerArgs) (signer Signer, err error) {
|
|
switch signerArgs := args.(type) {
|
|
case *AWSOptions:
|
|
awsSigner, err := NewAwsSigner(signerArgs)
|
|
if err != nil {
|
|
awsSigner, err = NewAwsSignerFromConfig(signerArgs)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return awsSigner, err
|
|
default:
|
|
return nil, errors.New("unknown signature arguments type")
|
|
}
|
|
}
|
|
|
|
// GetCtxWithArgs creates and returns context with signature args
|
|
func GetCtxWithArgs(maps ...map[string]interface{}) context.Context {
|
|
var region, service string
|
|
for _, v := range maps {
|
|
for key, val := range v {
|
|
if key == "region" && region == "" {
|
|
region = types.ToString(val)
|
|
}
|
|
if key == "service" && service == "" {
|
|
service = types.ToString(val)
|
|
}
|
|
}
|
|
}
|
|
// type ctxkey string
|
|
ctx := context.WithValue(context.Background(), SignerArg("service"), service)
|
|
return context.WithValue(ctx, SignerArg("region"), region)
|
|
}
|