Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientRole ¶
ClientRole represents a client role
type Config ¶
type Config struct {
// WhitelistOption enables query whitelisting when true
WhitelistOption WhitelistOption
// PersistencyManager is used for configuration state persistency.
// Persistency is disabled if PersistencyManager is nil
PersistencyManager PersistencyManager
}
Config defines the GraphQL shield configuration
func (*Config) SetDefaults ¶
func (conf *Config) SetDefaults()
SetDefaults sets the default configuration options
type GraphQLShield ¶
type GraphQLShield interface {
// WhitelistQueries adds the given queries to the whitelist
// returning an error if one of the queries doesn't meet the requirements.
WhitelistQueries(newEntry ...Entry) ([]Query, error)
// RemoveQuery removes a query from the whitelist and returns true
// if any query was removed as well as the actual removed query.
RemoveQuery(query Query) error
// Check returns an error if the given query isn't allowed for the given
// client role to be executed or if the provided arguments are unacceptable.
//
// WARNING: query will be mutated during normalization! Manually copy the
// query byte-slice if you don't want your inputs to be mutated.
Check(
clientRole int,
query []byte,
arguments map[string]*string,
) ([]byte, error)
// ListQueries returns all whitelisted queries.
ListQueries() (map[string]Query, error)
}
GraphQLShield represents a GraphQL shield instance
func NewGraphQLShield ¶
func NewGraphQLShield( config Config, clientRoles ...ClientRole, ) (GraphQLShield, error)
NewGraphQLShield creates a new GraphQL shield instance
type Parameter ¶
type Parameter struct {
MaxValueLength uint32 `json:"max-value-length"`
}
Parameter represents a query parameter
type PersistencyManager ¶
type PersistencyManager interface {
// Load loads the GraphQL shield configuration
Load() (*State, error)
// Save persists the GraphQL shield configuration
Save(*State) error
}
PersistencyManager represents a persistency manager
func NewPepersistencyManagerFileJSON ¶
func NewPepersistencyManagerFileJSON( path string, syncWrite bool, ) (PersistencyManager, error)
NewPepersistencyManagerFileJSON creates a new JSON file based persistency manager
type Query ¶
type Query interface {
// Query returns a copy of the query string
Query() []byte
// ID returns the unique identifier of the query
ID() ID
// Creation returns the time of creation
Creation() time.Time
// Name returns the query name
Name() string
// Parameters returns a copy of the list of query parameters
Parameters() map[string]Parameter
// WhitelistedFor returns the copy of role IDs the query is whitelisted for
WhitelistedFor() []int
}
Query represents a query object
type QueryModel ¶
type QueryModel struct {
Query string `json:"query"`
Creation time.Time `json:"creation"`
Name string `json:"name"`
Parameters map[string]Parameter `json:"parameters"`
WhitelistedFor []int `json:"whitelisted-for"`
}
QueryModel represents the model of a query entry for serialization
type State ¶
type State struct {
Roles []ClientRole `json:"roles"`
WhitelistedQueries map[string]QueryModel `json:"whitelisted-queries"`
}
State represents the state of the GraphQL shield
type WhitelistOption ¶
type WhitelistOption byte
WhitelistOption represents the query whitelist option
const ( // WhitelistDisabled disables query whitelisting WhitelistDisabled WhitelistOption // WhitelistEnabled enables query whitelisting WhitelistEnabled )
Source Files
¶
Click to show internal directories.
Click to hide internal directories.