clients

package
v1.1.15 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBreachingAbuseLimit error = errors.New("breaching abuse limit")
)

Functions

This section is empty.

Types

type APIResponse

type APIResponse struct {
	Data    interface{} `json:"data,omitempty"`
	Error   string      `json:"error,omitempty"`
	Message string      `json:"message,omitempty"`
}

type Authorization added in v1.1.8

type Authorization struct {
	Token     string
	TokenType TokenType
}

type CallType

type CallType string
const (
	HTTPCall    CallType = "HTTPCall"
	GraphQLCall CallType = "GraphQLCall"
)

type Claims added in v1.1.11

type Claims struct {
	Hasura HasuraClaims `json:"https://hasura.io/jwt/claims"`
	jwt.RegisteredClaims
}

type ClientType

type ClientType string
const (
	HTTPClientType    ClientType = "HTTPClient"
	GithubClientType  ClientType = "GithubClient"
	VercelClientType  ClientType = "VercelClient"
	VaultClientType   ClientType = "VaultClient"
	HasuraClientType  ClientType = "HasuraClient"
	GraphQLClientType ClientType = "GraphQLClient"
)

type CustomHeader

type CustomHeader struct {
	Key   string
	Value string
}

type Error

type Error struct {
	Error   error       `json:"error"`
	Message string      `json:"message"`
	Type    ErrorType   `json:"type"`
	Source  ErrorSource `json:"source"`
}

func New

func New(err error, message string, typ ErrorType, source ErrorSource) *Error

func Parse

func Parse(err error) *Error

func ParseExternal

func ParseExternal(err error) *Error

func (*Error) GenerateMessage

func (e *Error) GenerateMessage(defaultMessage string) string

func (*Error) IsType

func (e *Error) IsType(errType ErrorType) bool

func (*Error) Log

func (e *Error) Log(logger *logrus.Logger, defaultMessage string)

func (*Error) ToError

func (e *Error) ToError() error

type ErrorSource

type ErrorSource string
const (
	ErrorSourceHTTP    ErrorSource = "http"
	ErrorSourceGraphQL ErrorSource = "graphql"
	ErrorSourceHermes  ErrorSource = "hermes"
	ErrorSourceMailer  ErrorSource = "mailer"

	ErrorSourceVault  ErrorSource = "vault"
	ErrorSourceNhost  ErrorSource = "nhost"
	ErrorSourceGo     ErrorSource = "go"
	ErrorSourceSystem ErrorSource = "system"

	ErrorSourceGithub ErrorSource = "github"
	ErrorSourceVercel ErrorSource = "vercel"
)

type ErrorType

type ErrorType string
const (
	ErrorTypeBase64Encode ErrorType = "Base64Encode"
	ErrorTypeBase64Decode ErrorType = "Base64Decode"

	ErrorTypeJSONMarshal      ErrorType = "JSONMarshal"
	ErrorTypeJSONUnmarshal    ErrorType = "JSONUnmarshal"
	ErrorTypeJWTExpired       ErrorType = "JWTExpired"
	ErrorTypeUnauthorized     ErrorType = "Unauthorized"
	ErrorTypePermissionDenied ErrorType = "PermissionDenied"
	ErrorTypeTokenRefresh     ErrorType = "TokenRefresh"

	ErrorTypeInvalidResponse ErrorType = "InvalidResponse"
	ErrorTypeBadResponse     ErrorType = "BadResponse"
	ErrorTypeBadRequest      ErrorType = "BadRequest"
	ErrorTypeBadGateway      ErrorType = "BadGateway"
	ErrorTypeRequestFailed   ErrorType = "RequestFailed"

	ErrorTypeDoesNotExist   ErrorType = "DoesNotExist"
	ErrorTypeInvalidKey     ErrorType = "InvalidKey"
	ErrorTypeKeyNotFound    ErrorType = "KeyNotFound"
	ErrorTypeRecordNotFound ErrorType = "RecordNotFound"

	ErrorTypeInvalidToken ErrorType = "InvalidToken"

	ErrorTypeInvalidAccountConfiguration ErrorType = "InvalidAccountConfiguration"
	ErrorTypeInvalidProjectConfiguration ErrorType = "InvalidProjectConfiguration"

	ErrorTypeEmailFailed ErrorType = "EmailFailed"
)

func (*ErrorType) GetStatusCode

func (e *ErrorType) GetStatusCode() int

type GQL2Config added in v1.1.8

type GQL2Config struct {
	Type          ClientType
	BaseURL       string
	Authorization *Authorization
	Logger        *logrus.Logger
}

type GQLClient

type GQLClient struct {
	*graphql.Client
	BaseURL            string
	Authorization      string
	Headers            []Header
	CustomHeaders      []CustomHeader
	ErrorHandler       func(*GQLClient, error) error
	RedoRequestOnError bool
	// contains filtered or unexported fields
}

func NewGQLClient

func NewGQLClient(config *GQLConfig) *GQLClient

func (*GQLClient) Do

func (c *GQLClient) Do(ctx context.ServiceContext, req *graphql.Request, resp interface{}) error

type GQLClient2 added in v1.1.8

type GQLClient2 struct {
	*graphql.Client
	BaseURL       string
	Authorization *Authorization
	// contains filtered or unexported fields
}

func NewGQLClient2 added in v1.1.8

func NewGQLClient2(config *GQL2Config) *GQLClient2

type GQLConfig

type GQLConfig struct {
	Type               ClientType
	BaseURL            string
	Authorization      string
	Headers            []Header
	CustomHeaders      []CustomHeader
	Logger             *logrus.Logger
	ErrorHandler       func(*GQLClient, error) error
	RedoRequestOnError bool
}

type HTTPClient

type HTTPClient struct {
	*http.Client
	BaseURL       string
	Authorization string
	CustomHeaders []CustomHeader

	ResponseHandler func(*http.Response) error
	Type            ClientType
	// contains filtered or unexported fields
}

func NewHTTPClient

func NewHTTPClient(config *HTTPConfig) *HTTPClient

func (*HTTPClient) Run

func (c *HTTPClient) Run(ctx context.ServiceContext, req *http.Request, response interface{}) error

type HTTPConfig

type HTTPConfig struct {
	Type            ClientType
	BaseURL         string
	Authorization   string
	Headers         []Header
	CustomHeaders   []CustomHeader
	Logger          *logrus.Logger
	ResponseHandler func(*http.Response) error
}

type HasuraActionRequestPayload

type HasuraActionRequestPayload struct {
	Action struct {
		Name string `json:"name"`
	} `json:"action"`
	Input struct {
		Args interface{} `json:"args"`
	} `json:"input"`
}

type HasuraActionResponse added in v1.1.11

type HasuraActionResponse struct {
	Message    string                           `json:"message"`
	Extensions *HasuraActionsResponseExtensions `json:"extensions,omitempty"`
}

type HasuraActionsResponseExtensions added in v1.1.11

type HasuraActionsResponseExtensions struct {
	Code  int                    `json:"code"`
	Error error                  `json:"error,omitempty"`
	Data  map[string]interface{} `json:"data,omitempty"`
}

type HasuraClaims added in v1.1.11

type HasuraClaims struct {
	AllowedRoles []string `json:"x-hasura-allowed-roles,omitempty"`
	DefaultRole  string   `json:"x-hasura-default-role,omitempty"`
	UserID       string   `json:"x-hasura-user-id,omitempty"`
	UserEmail    string   `json:"x-hasura-user-email,omitempty"`
	IsAnonymous  string   `json:"x-hasura-user-is-anonymous,omitempty"`
}

type HasuraClient

type HasuraClient struct {
	*graphql.Client
	BaseURL       string
	Authorization string
	Headers       []Header
	CustomHeaders []CustomHeader
	// contains filtered or unexported fields
}

func NewHasuraClient

func NewHasuraClient(config *HasuraConfig) *HasuraClient

func (*HasuraClient) Do

func (c *HasuraClient) Do(ctx context.ServiceContext, req *graphql.Request, resp interface{}) error

type HasuraConfig

type HasuraConfig struct {
	BaseURL       string
	Authorization string
	Headers       []Header
	CustomHeaders []CustomHeader
	Logger        *logrus.Logger
}

type HasuraInputValidationPayload added in v1.1.11

type HasuraInputValidationPayload struct {
	Data struct {
		Input interface{} `json:"input"`
	} `json:"data"`
}

type HasuraTriggerPayload

type HasuraTriggerPayload struct {
	Event struct {
		Op               string       `json:"op"`
		SessionVariables HasuraClaims `json:"session_variables"`
		Data             struct {
			New interface{} `json:"new"`
			Old interface{} `json:"old"`
		} `json:"data"`
	} `json:"event"`
}
type Header string
const (

	//	Standard HTTP headers
	AuthorizationHeader Header = "Authorization"
	ContentTypeHeader   Header = "Content-Type"
	TokenHeader         Header = "x-envsecrets-token"
	OrgIDHeader         Header = "x-envsecrets-org-id"
	HasuraWebhookSecret Header = "X-Hasura-Webhook-Secret"

	//	Hasura headers
	XHasuraAdminSecretHeader Header = "x-hasura-admin-secret"

	//	Github headers
	AcceptHeader Header = "Accept"

	VaultTokenHeader     Header = "X-Vault-Token"
	VaultNamespaceHeader Header = "X-Vault-Namespace"
)

type NhostClient

type NhostClient struct {
	*http.Client
	Authorization string
	CustomHeaders []CustomHeader

	ResponseHandler func(*http.Response) error
	BaseURL         string
	// contains filtered or unexported fields
}

func NewNhostClient

func NewNhostClient(config *NhostConfig) *NhostClient

func (*NhostClient) Run

func (c *NhostClient) Run(ctx context.ServiceContext, req *http.Request, response interface{}) error

type NhostConfig

type NhostConfig struct {
	Authorization   string
	Headers         []Header
	CustomHeaders   []CustomHeader
	Logger          *logrus.Logger
	ResponseHandler func(*http.Response) error
	BaseURL         string
}

type Response

type Response struct {
	StatusCode int
	Data       interface{}
}

type TokenType added in v1.1.8

type TokenType string
const (
	PAT    TokenType = "pat"
	Bearer TokenType = "Bearer"
)

type Variable

type Variable string
const (

	//	API constants
	API Variable = "API"

	//	Nhost constants
	NHOST_ADMIN_SECRET   Variable = "NHOST_ADMIN_SECRET"
	NHOST_JWT_SECRET     Variable = "NHOST_JWT_SECRET"
	NHOST_WEBHOOK_SECRET Variable = "NHOST_WEBHOOK_SECRET"
	NHOST_AUTH_URL       Variable = "NHOST_AUTH_URL"
	NHOST_STORAGE_URL    Variable = "NHOST_STORAGE_URL"
	NHOST_FUNCTIONS_URL  Variable = "NHOST_FUNCTIONS_URL"
	NHOST_GRAPHQL_URL    Variable = "NHOST_GRAPHQL_URL"
)

Jump to

Keyboard shortcuts

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