arborist

package
v0.0.0-...-936ef1b Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const AnonymousGroup = "anonymous"
View Source
const LoggedInGroup = "logged-in"

Variables

This section is empty.

Functions

func FormatPathForDb

func FormatPathForDb(path string) string

FormatPathForDb takes a front-end version of a resource path and transforms it to its database version. Inverse of `formatDbPath`.

FormatPathForDb("/a/b/c") == "a.b.c"

func UnderscoreDecode

func UnderscoreDecode(encoded string) string

func UnderscoreEncode

func UnderscoreEncode(decoded string) string

Types

type Action

type Action struct {
	Service string `json:"service"`
	Method  string `json:"method"`
}

type AuthMapping

type AuthMapping map[string][]Action

type AuthMappingQuery

type AuthMappingQuery struct {
	Path    string `json:"path"`
	Service string `json:"service"`
	Method  string `json:"method"`
}

type AuthRequest

type AuthRequest struct {
	Username string
	ClientID string
	Policies []string
	Resource string
	Service  string
	Method   string
	// contains filtered or unexported fields
}

type AuthRequestJSON

type AuthRequestJSON struct {
	User     AuthRequestJSON_User      `json:"user"`
	Request  *AuthRequestJSON_Request  `json:"request"`
	Requests []AuthRequestJSON_Request `json:"requests"`
}

type AuthRequestJSON_Request

type AuthRequestJSON_Request struct {
	Resource    string      `json:"resource"`
	Action      Action      `json:"action"`
	Constraints Constraints `json:"constraints,omitempty"`
}

func (*AuthRequestJSON_Request) UnmarshalJSON

func (requestJSON *AuthRequestJSON_Request) UnmarshalJSON(data []byte) error

UnmarshalJSON defines the deserialization from JSON into an AuthRequestJSON struct, which includes validating that required fields are present. (Required fields are anything not in the `optionalFields` variable.)

type AuthRequestJSON_User

type AuthRequestJSON_User struct {
	Token  string `json:"token"`
	UserId string `json:"user_id"`
	// The Policies field is optional, and if the request provides a token
	// this gets filled in using the Token field.
	// Could use UserId if its provided instead of Token
	Policies []string `json:"policies,omitempty"`
	Scopes   []string `json:"scope,omitempty"`
}

func (*AuthRequestJSON_User) UnmarshalJSON

func (requestJSON *AuthRequestJSON_User) UnmarshalJSON(data []byte) error

type AuthResponse

type AuthResponse struct {
	Auth bool `json:"auth"`
}

type CachedStmts

type CachedStmts struct {
	// contains filtered or unexported fields
}

func NewCachedStmts

func NewCachedStmts(db *sqlx.DB) *CachedStmts

func (*CachedStmts) Prepare

func (s *CachedStmts) Prepare(query string) (*sqlx.Stmt, error)

func (*CachedStmts) Query

func (s *CachedStmts) Query(query string, args ...interface{}) (*sql.Rows, error)

func (*CachedStmts) Select

func (s *CachedStmts) Select(query string, dest interface{}, args ...interface{}) error

type Client

type Client struct {
	ClientID string   `json:"clientID"`
	Policies []string `json:"policies"`
}

type ClientFromQuery

type ClientFromQuery struct {
	ClientID string         `db:"external_client_id"`
	Policies pq.StringArray `db:"policies"`
}

type Constraints

type Constraints = map[string]string

type ErrorResponse

type ErrorResponse struct {
	HTTPError HTTPError `json:"error"`
	// contains filtered or unexported fields
}

type ExpandedPolicy

type ExpandedPolicy struct {
	Name          string   `json:"id"`
	Description   string   `json:"description"`
	ResourcePaths []string `json:"resource_paths"`
	Roles         []Role   `json:"roles"`
}

expanded policies need their own struct so that unused RoleIDs/Roles fields can be excluded from the JSON response

type Group

type Group struct {
	Name     string   `json:"name"`
	Users    []string `json:"users"`
	Policies []string `json:"policies"`
}

func (*Group) UnmarshalJSON

func (group *Group) UnmarshalJSON(data []byte) error

type GroupFromQuery

type GroupFromQuery struct {
	Name     string         `db:"name"`
	Users    pq.StringArray `db:"users"`
	Policies pq.StringArray `db:"policies"`
}

type HTTPError

type HTTPError struct {
	Message string `json:"message"`
	Code    int    `json:"code"`
}

type JWTDecoder

type JWTDecoder interface {
	Decode(string) (*map[string]interface{}, error)
}

type Log

type Log struct {
	// contains filtered or unexported fields
}

type LogCache

type LogCache struct {
	// contains filtered or unexported fields
}

func (*LogCache) Debug

func (cache *LogCache) Debug(format string, a ...interface{})

func (*LogCache) Error

func (cache *LogCache) Error(format string, a ...interface{})

func (*LogCache) Info

func (cache *LogCache) Info(format string, a ...interface{})

func (*LogCache) Warning

func (cache *LogCache) Warning(format string, a ...interface{})

type LogHandler

type LogHandler struct {
	// contains filtered or unexported fields
}

func (*LogHandler) Debug

func (handler *LogHandler) Debug(format string, a ...interface{})

func (*LogHandler) Error

func (handler *LogHandler) Error(format string, a ...interface{})

func (*LogHandler) Info

func (handler *LogHandler) Info(format string, a ...interface{})

func (*LogHandler) Print

func (handler *LogHandler) Print(format string, a ...interface{})

func (*LogHandler) Warning

func (handler *LogHandler) Warning(format string, a ...interface{})

type LogLevel

type LogLevel string
const (
	LogLevelDebug   LogLevel = "DEBUG"
	LogLevelInfo    LogLevel = "INFO"
	LogLevelWarning LogLevel = "WARNING"
	LogLevelError   LogLevel = "ERROR"
)

type Logger

type Logger interface {
	Print(string, ...interface{})
	Debug(string, ...interface{})
	Info(string, ...interface{})
	Warning(string, ...interface{})
	Error(string, ...interface{})
}

type Permission

type Permission struct {
	Name        string            `json:"id"`
	Description string            `json:"description"`
	Action      Action            `json:"action"`
	Constraints map[string]string `json:"constraints"`
}

func (*Permission) UnmarshalJSON

func (permission *Permission) UnmarshalJSON(data []byte) error

type PermissionFromQuery

type PermissionFromQuery struct {
	ID          int64             `db:"id"`
	RoleID      int64             `db:"role_id"`
	Name        string            `db:"name"`
	Description *string           `db:"description"`
	Service     string            `db:"service"`
	Method      string            `db:"method"`
	Constraints map[string]string `db:"constraints"`
}

type Policy

type Policy struct {
	Name          string   `json:"id"`
	Description   string   `json:"description"`
	ResourcePaths []string `json:"resource_paths"`
	RoleIDs       []string `json:"role_ids"`
}

func (*Policy) UnmarshalJSON

func (policy *Policy) UnmarshalJSON(data []byte) error

UnmarshalJSON defines the way that a `Policy` gets read when unmarshalling:

json.Unmarshal(bytes, &policy)

We implement this method to add some additional processing and error checking, for example to reject inputs which are missing required fields.

type PolicyBinding

type PolicyBinding struct {
	Policy    string  `json:"policy"`
	ExpiresAt *string `json:"expires_at"`
}

type PolicyFromQuery

type PolicyFromQuery struct {
	ID            int64          `db:"id" json:"-"`
	Name          string         `db:"name" json:"id"`
	Description   *string        `db:"description" json:"description,omitempty"`
	ResourcePaths pq.StringArray `db:"resource_paths" json:"resource_paths"`
	RoleIDs       pq.StringArray `db:"role_ids" json:"role_ids"`
}

PolicyFromQuery defines the correct fields for loading policies from the database. Use this struct when querying from the `policy` table.

type RequestPolicy

type RequestPolicy struct {
	PolicyName string `json:"policy"`
	ExpiresAt  string `json:"expires_at"`
}

type ResourceFromQuery

type ResourceFromQuery struct {
	ID           int64          `db:"id"`
	Name         string         `db:"name"`
	Tag          string         `db:"tag"`
	Description  *string        `db:"description"`
	Path         string         `db:"path"`
	Subresources pq.StringArray `db:"subresources"`
}

ResourceFromQuery is used for reading resources out of the database.

The `description` field uses `*string` to represent nullability.

type ResourceIn

type ResourceIn struct {
	Name         string       `json:"name"`
	Path         string       `json:"path"`
	Description  *string      `json:"description"`
	Subresources []ResourceIn `json:"subresources"`
}

func (*ResourceIn) UnmarshalJSON

func (resource *ResourceIn) UnmarshalJSON(data []byte) error

NOTE: the resource unmarshalling, because the resources can be specified with either the name + endpoint path, or the full path in the JSON input, is not able to validate all cases precisely. The unmarshalling will pass as long as either the name or the path is provided, which may require additional validation where this is called.

type ResourceOut

type ResourceOut struct {
	Name         string   `json:"name"`
	Path         string   `json:"path"`
	Tag          string   `json:"tag"`
	Description  string   `json:"description"`
	Subresources []string `json:"subresources"`
}

type Role

type Role struct {
	Name        string       `json:"id"`
	Description string       `json:"description"`
	Permissions []Permission `json:"permissions"`
}

func (*Role) UnmarshalJSON

func (role *Role) UnmarshalJSON(data []byte) error

type RoleFromQuery

type RoleFromQuery struct {
	ID          int64          `db:"id"`
	Name        string         `db:"name"`
	Description *string        `db:"description"`
	Permissions pq.StringArray `db:"permissions"`
}

The `description` field uses `*string` to represent nullability.

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer() *Server

func (*Server) Init

func (server *Server) Init() (*Server, error)

func (*Server) MakeRouter

func (server *Server) MakeRouter(out io.Writer) http.Handler

func (*Server) WithDB

func (server *Server) WithDB(db *sqlx.DB) *Server

func (*Server) WithJWTApp

func (server *Server) WithJWTApp(jwtApp JWTDecoder) *Server

func (*Server) WithLogger

func (server *Server) WithLogger(logger *log.Logger) *Server

type TokenInfo

type TokenInfo struct {
	// contains filtered or unexported fields
}

type User

type User struct {
	Name     string          `json:"name"`
	Email    string          `json:"email,omitempty"`
	Groups   []string        `json:"groups"`
	Policies []PolicyBinding `json:"policies"`
}

func (*User) UnmarshalJSON

func (user *User) UnmarshalJSON(data []byte) error

type UserFromQuery

type UserFromQuery struct {
	ID       int64          `db:"id"`
	Name     string         `db:"name"`
	Email    *string        `db:"email"`
	Groups   pq.StringArray `db:"groups"`
	Policies []byte         `db:"policies"`
}

type UserPolicyInfoFromQuery

type UserPolicyInfoFromQuery struct {
	Username      string         `db:"username"`
	PolicyName    string         `db:"policy_name"`
	ExpiresAt     *time.Time     `db:"expires_at"`
	AuthzProvider sql.NullString `db:"authz_provider"`
}

type UserWithScalars

type UserWithScalars struct {
	Name  *string `json:"name,omitempty"`
	Email *string `json:"email,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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