authx

package
v3.2.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2024 License: MIT Imports: 16 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTemplatePathsFromSecretFile

func GetTemplatePathsFromSecretFile(file string) ([]string, error)

GetTemplatePathsFromSecretFile reads the template IDs from the secret file

func SupportedAuthTypes

func SupportedAuthTypes() []string

SupportedAuthTypes returns the supported auth types

Types

type AuthFileInfo

type AuthFileInfo struct {
	Name        string `json:"name" yaml:"name"`
	Author      string `json:"author" yaml:"author"`
	Severity    string `json:"severity" yaml:"severity"`
	Description string `json:"description" yaml:"description"`
}

type AuthStrategy

type AuthStrategy interface {
	// Apply applies the strategy to the request
	Apply(*http.Request)
	// ApplyOnRR applies the strategy to the retryable request
	ApplyOnRR(*retryablehttp.Request)
}

AuthStrategy is an interface for auth strategies basic auth , bearer token, headers, cookies, query

type AuthType

type AuthType string
const (
	BasicAuth       AuthType = "BasicAuth"
	BearerTokenAuth AuthType = "BearerToken"
	HeadersAuth     AuthType = "Header"
	CookiesAuth     AuthType = "Cookie"
	QueryAuth       AuthType = "Query"
)

type Authx

type Authx struct {
	ID      string       `json:"id" yaml:"id"`
	Info    AuthFileInfo `json:"info" yaml:"info"`
	Secrets []Secret     `json:"static" yaml:"static"`
	Dynamic []Dynamic    `json:"dynamic" yaml:"dynamic"`
}

Authx is a struct for secrets or credentials file

func GetAuthDataFromFile

func GetAuthDataFromFile(file string) (*Authx, error)

GetAuthDataFromFile reads the auth data from file

func GetAuthDataFromJSON

func GetAuthDataFromJSON(data []byte) (*Authx, error)

GetAuthDataFromJSON reads the auth data from json

func GetAuthDataFromYAML

func GetAuthDataFromYAML(data []byte) (*Authx, error)

GetAuthDataFromYAML reads the auth data from yaml

type BasicAuthStrategy

type BasicAuthStrategy struct {
	Data *Secret
}

BasicAuthStrategy is a strategy for basic auth

func NewBasicAuthStrategy

func NewBasicAuthStrategy(data *Secret) *BasicAuthStrategy

NewBasicAuthStrategy creates a new basic auth strategy

func (*BasicAuthStrategy) Apply

func (s *BasicAuthStrategy) Apply(req *http.Request)

Apply applies the basic auth strategy to the request

func (*BasicAuthStrategy) ApplyOnRR

func (s *BasicAuthStrategy) ApplyOnRR(req *retryablehttp.Request)

ApplyOnRR applies the basic auth strategy to the retryable request

type BearerTokenAuthStrategy

type BearerTokenAuthStrategy struct {
	Data *Secret
}

BearerTokenAuthStrategy is a strategy for bearer token auth

func NewBearerTokenAuthStrategy

func NewBearerTokenAuthStrategy(data *Secret) *BearerTokenAuthStrategy

NewBearerTokenAuthStrategy creates a new bearer token auth strategy

func (*BearerTokenAuthStrategy) Apply

func (s *BearerTokenAuthStrategy) Apply(req *http.Request)

Apply applies the bearer token auth strategy to the request

func (*BearerTokenAuthStrategy) ApplyOnRR

func (s *BearerTokenAuthStrategy) ApplyOnRR(req *retryablehttp.Request)

ApplyOnRR applies the bearer token auth strategy to the retryable request

type Cookie struct {
	Key   string `json:"key" yaml:"key"`
	Value string `json:"value" yaml:"value"`
	Raw   string `json:"raw" yaml:"raw"`
}

func (*Cookie) Parse

func (c *Cookie) Parse() error

Parse parses the cookie in raw the cookie is in format of Set-Cookie: <cookie-name>=<cookie-value>; Expires=<date>; Path=<path>; Domain=<domain_name>; Secure; HttpOnly

func (*Cookie) Validate

func (c *Cookie) Validate() error

type CookiesAuthStrategy

type CookiesAuthStrategy struct {
	Data *Secret
}

CookiesAuthStrategy is a strategy for cookies auth

func NewCookiesAuthStrategy

func NewCookiesAuthStrategy(data *Secret) *CookiesAuthStrategy

NewCookiesAuthStrategy creates a new cookies auth strategy

func (*CookiesAuthStrategy) Apply

func (s *CookiesAuthStrategy) Apply(req *http.Request)

Apply applies the cookies auth strategy to the request

func (*CookiesAuthStrategy) ApplyOnRR

func (s *CookiesAuthStrategy) ApplyOnRR(req *retryablehttp.Request)

ApplyOnRR applies the cookies auth strategy to the retryable request

type Dynamic

type Dynamic struct {
	Secret       `yaml:",inline"`       // this is a static secret that will be generated after the dynamic secret is resolved
	TemplatePath string                 `json:"template" yaml:"template"`
	Variables    []KV                   `json:"variables" yaml:"variables"`
	Input        string                 `json:"input" yaml:"input"` // (optional) target for the dynamic secret
	Extracted    map[string]interface{} `json:"-" yaml:"-"`         // extracted values from the dynamic secret
	// contains filtered or unexported fields
}

Dynamic is a struct for dynamic secret or credential these are high level secrets that take action to generate the actual secret ex: username and password are dynamic secrets, the actual secret is the token obtained after authenticating with the username and password

func (*Dynamic) Error

func (d *Dynamic) Error() error

Error returns the error if any

func (*Dynamic) Fetch

func (d *Dynamic) Fetch(isFatal bool) error

Fetch fetches the dynamic secret if isFatal is true, it will stop the execution if the secret could not be fetched

func (*Dynamic) GetStrategy

func (d *Dynamic) GetStrategy() AuthStrategy

GetStrategy returns the auth strategy for the dynamic secret

func (*Dynamic) SetLazyFetchCallback

func (d *Dynamic) SetLazyFetchCallback(callback LazyFetchSecret)

SetLazyFetchCallback sets the lazy fetch callback for the dynamic secret

func (*Dynamic) UnmarshalJSON

func (d *Dynamic) UnmarshalJSON(data []byte) error

func (*Dynamic) Validate

func (d *Dynamic) Validate() error

Validate validates the dynamic secret

type DynamicAuthStrategy

type DynamicAuthStrategy struct {
	// Dynamic is the dynamic secret to use
	Dynamic Dynamic
}

DynamicAuthStrategy is an auth strategy for dynamic secrets it implements the AuthStrategy interface

func (*DynamicAuthStrategy) Apply

func (d *DynamicAuthStrategy) Apply(req *http.Request)

Apply applies the strategy to the request

func (*DynamicAuthStrategy) ApplyOnRR

func (d *DynamicAuthStrategy) ApplyOnRR(req *retryablehttp.Request)

ApplyOnRR applies the strategy to the retryable request

type HeadersAuthStrategy

type HeadersAuthStrategy struct {
	Data *Secret
}

HeadersAuthStrategy is a strategy for headers auth

func NewHeadersAuthStrategy

func NewHeadersAuthStrategy(data *Secret) *HeadersAuthStrategy

NewHeadersAuthStrategy creates a new headers auth strategy

func (*HeadersAuthStrategy) Apply

func (s *HeadersAuthStrategy) Apply(req *http.Request)

Apply applies the headers auth strategy to the request

func (*HeadersAuthStrategy) ApplyOnRR

func (s *HeadersAuthStrategy) ApplyOnRR(req *retryablehttp.Request)

ApplyOnRR applies the headers auth strategy to the retryable request

type KV

type KV struct {
	Key   string `json:"key" yaml:"key"`
	Value string `json:"value" yaml:"value"`
}

func (*KV) Validate

func (k *KV) Validate() error

type LazyFetchSecret

type LazyFetchSecret func(d *Dynamic) error

type QueryAuthStrategy

type QueryAuthStrategy struct {
	Data *Secret
}

QueryAuthStrategy is a strategy for query auth

func NewQueryAuthStrategy

func NewQueryAuthStrategy(data *Secret) *QueryAuthStrategy

NewQueryAuthStrategy creates a new query auth strategy

func (*QueryAuthStrategy) Apply

func (s *QueryAuthStrategy) Apply(req *http.Request)

Apply applies the query auth strategy to the request

func (*QueryAuthStrategy) ApplyOnRR

func (s *QueryAuthStrategy) ApplyOnRR(req *retryablehttp.Request)

ApplyOnRR applies the query auth strategy to the retryable request

type Secret

type Secret struct {
	Type         string   `json:"type" yaml:"type"`
	Domains      []string `json:"domains" yaml:"domains"`
	DomainsRegex []string `json:"domains-regex" yaml:"domains-regex"`
	Headers      []KV     `json:"headers" yaml:"headers"`
	Cookies      []Cookie `json:"cookies" yaml:"cookies"`
	Params       []KV     `json:"params" yaml:"params"`
	Username     string   `json:"username" yaml:"username"` // can be either email or username
	Password     string   `json:"password" yaml:"password"`
	Token        string   `json:"token" yaml:"token"` // Bearer Auth token
	// contains filtered or unexported fields
}

Secret is a struct for secret or credential

func (*Secret) GetStrategy

func (s *Secret) GetStrategy() AuthStrategy

GetStrategy returns the auth strategy for the secret

func (*Secret) Validate

func (s *Secret) Validate() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL