Documentation ¶
Index ¶
- Constants
- func GetHeadersFromContext(ctx context.Context) map[string]string
- func HeadersFor(actor *Actor, adminSecret, clientName string) map[string]string
- func WithHeader(ctx context.Context, key, value string) context.Context
- func WithHeaders(ctx context.Context, hs map[string]string) context.Context
- type Access
- type Actor
- type ActorAwareClient
- func NewAdminClient(endpoint, adminSecret, clientName string, options ...Option) *ActorAwareClient
- func NewAdminClientFromHost(host string, adminSecret string, clientName string, options ...Option) *ActorAwareClient
- func NewClient(endpoint string, adminSecret string, actor *Actor, clientName string, ...) *ActorAwareClient
- func NewPromotableClient(endpoint string, adminSecret string, actor *Actor, clientName string, ...) *ActorAwareClient
- type Client
- type Option
Constants ¶
const ( HasuraClientName = "Hasura-Client-Name" DefaultClientName = "lux-hasura-api" XHasuraRole = "x-hasura-role" XHasuraUserID = "x-hasura-user-id" XHasuraUserEmail = "x-hasura-user-email" XHasuraAdminSecret = "X-Hasura-Admin-Secret" )
const ( RoleAdmin = "admin" RoleUser = "user" RolePublic = "public" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Access ¶
type Access struct { *Actor AllowedProjectIDs []uuid.UUID MetricsAllowedProjectIDs []uuid.UUID AdminProjectIDs []uuid.UUID }
Access holds information about what a given actor can access. code using Access values will determine whether a user can access a given resource based on the actor's role, identity or allowed lists
func NewAccessFromSessionVariables ¶
NewAccessFromSessionVariables parses de headers in the given StringMap And builds an Access object based on them
type Actor ¶
Actor denotes who is making a request to our APIs
func NewAdminActor ¶
func NewAdminActor() *Actor
type ActorAwareClient ¶
ActorAwareClient is a graphql client which requests are made on behalf of an Actor
func NewAdminClient ¶
func NewAdminClient(endpoint, adminSecret, clientName string, options ...Option) *ActorAwareClient
NewAdminClient creates a new client to access the given graphql endpoint using the given admin secret.
options is a set of functional options used, among other things, to override the default timeout for the client.
func NewAdminClientFromHost ¶
func NewAdminClientFromHost(host string, adminSecret string, clientName string, options ...Option) *ActorAwareClient
NewAdminClientFromHost is a helper constructor, that will append to the host, the default endpoint path to build a new admin client.
func NewClient ¶
func NewClient(endpoint string, adminSecret string, actor *Actor, clientName string, options ...Option) *ActorAwareClient
NewClient creates a new client to access the given graphql endpoint as a user, setting the given http headers in the underlying httpClient.
func NewPromotableClient ¶
func NewPromotableClient(endpoint string, adminSecret string, actor *Actor, clientName string, options ...Option) *ActorAwareClient
NewPromotableClient creates a new client to access the given graphql endpoint as the given actor, but that has the option to act as an admin, by calling ForceAdmin() over it. This is useful when a certain action needs to request superpowers, think of it as a sudoer in Linux.
adminSecret is used for client authentication not authorization. Authorization is done when HGE checks the role and user headers. Think of adminSecret as an API key to access the endpoint, that's why promoting a client to an admin, only means changing the role to admin.
func (*ActorAwareClient) AsAdmin ¶
func (c *ActorAwareClient) AsAdmin() (*ActorAwareClient, error)
AsAdmin allows the client to act on behalf of an admin, this function returns an error in case the client is not promotable
func (*ActorAwareClient) ForceAdmin ¶
func (c *ActorAwareClient) ForceAdmin() *ActorAwareClient
ForceAdmin allows the client to act on behalf of an admin, this function panics if the client cannot be promoted to an Admin client. Prefer AsAdmin instead.
type Client ¶
type Client interface { Query(ctx context.Context, q interface{}, variables map[string]interface{}, options ...graphql.Option) error NamedQuery(ctx context.Context, name string, q interface{}, variables map[string]interface{}, options ...graphql.Option) error NamedQueryRaw(ctx context.Context, name string, q interface{}, variables map[string]interface{}, options ...graphql.Option) ([]byte, error) Mutate(ctx context.Context, m interface{}, variables map[string]interface{}, options ...graphql.Option) error NamedMutate(ctx context.Context, name string, m interface{}, variables map[string]interface{}, options ...graphql.Option) error NamedMutateRaw(ctx context.Context, name string, m interface{}, variables map[string]interface{}, options ...graphql.Option) ([]byte, error) }
Client abstracts the interface provided by hasura/go-graphql-client so their implementation can be replaced by something else