pgrest

package
v0.0.0-...-5ba556e Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AgentStatusConnected    = "CONNECTED"
	AgentStatusDisconnected = "DISCONNECTED"
)
View Source
const (
	ConnectionStatusOnline  = "online"
	ConnectionStatusOffline = "offline"
)
View Source
const (
	DefaultLimit  int = 100
	DefaultOffset int = 0
)

Variables

View Source
var (
	ErrNotFound      = fmt.Errorf("resource not found")
	ErrUnauthorized  = fmt.Errorf("unauthorized")
	ErrEmptyResponse = fmt.Errorf("empty response")
)
View Source
var EmptyContext = NewOrgContext("")

Functions

func CheckLiveness

func CheckLiveness() error

CheckLiveness validates if the postgrest process is running by checking if the port is open and responding.

func NewAuditContext

func NewAuditContext(orgID, eventName, userEmail string) *auditContext

func Run

func Run() (err error)

Run performs the initalization and necessary migrations to start the postgrest process. This function will take care of managing the process lifecycle of postgrest.

func WithBaseURL

func WithBaseURL(newBaseURL *url.URL)

func WithHttpClient

func WithHttpClient(newClient HTTPClient)

Types

type Agent

type Agent struct {
	ID        string            `json:"id"`
	OrgID     string            `json:"org_id"`
	Name      string            `json:"name"`
	Mode      string            `json:"mode"`
	Key       string            `json:"key"`
	KeyHash   string            `json:"key_hash"`
	Status    string            `json:"status"`
	Metadata  map[string]string `json:"metadata"`
	UpdatedAt *string           `json:"updated_at"`

	Org Org `json:"orgs"`
}

func (*Agent) GetMeta

func (a *Agent) GetMeta(key string) (v string)

func (Agent) String

func (a Agent) String() string

type AppState

type AppState struct {
	ID            int
	StateRollback string
	Checksum      string
	Schema        string
	RoleName      string
	Version       string
	PgVersion     string
	GitCommit     string
	CreatedAt     time.Time
}

type AppStateRollout

type AppStateRollout struct {
	First  *AppState
	Second *AppState
}

func (*AppStateRollout) GetAppState

func (s *AppStateRollout) GetAppState(checksum string) (bool, *AppState)

func (*AppStateRollout) ShouldRollout

func (s *AppStateRollout) ShouldRollout(checksum string) bool

type AuditContext

type AuditContext interface {
	OrgContext
	GetEventName() string
	GetUserEmail() string
	GetMetadata() map[string]any
}

type Blob

type Blob struct {
	ID         string `json:"id"`
	OrgID      string `json:"org_id"`
	Type       string `json:"type"`
	Size       int64  `json:"size"`
	BlobStream []any  `json:"blob_stream"`
}

type Client

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

func New

func New(path string, a ...any) *Client

func (*Client) Create

func (c *Client) Create(reqBody any) *Response

func (*Client) Delete

func (c *Client) Delete() *Response

func (*Client) ExactCount

func (c *Client) ExactCount() int64

ExactCount returns the total of records in the table, in case of error it returns -1

func (*Client) FetchAll

func (c *Client) FetchAll() *Response

func (*Client) FetchOne

func (c *Client) FetchOne() *Response

func (*Client) List

func (c *Client) List() *Response

func (*Client) Patch

func (c *Client) Patch(reqBody any) *Response

func (*Client) RpcCreate

func (c *Client) RpcCreate(reqBody any) *Response

func (*Client) Update

func (c *Client) Update(reqBody any) *Response

func (*Client) Upsert

func (c *Client) Upsert(reqBody any) *Response

type Connection

type Connection struct {
	ID                 string            `json:"id"`
	OrgID              string            `json:"org_id"`
	AgentID            string            `json:"agent_id"`
	Name               string            `json:"name"`
	Command            []string          `json:"command"`
	Type               string            `json:"type"`
	SubType            string            `json:"subtype"`
	Envs               map[string]string `json:"envs"`
	Status             string            `json:"status"` // read only field
	ManagedBy          *string           `json:"managed_by"`
	Tags               []string          `json:"tags"`
	AccessModeRunbooks string            `json:"access_mode_runbooks"`
	AccessModeExec     string            `json:"access_mode_exec"`
	AccessModeConnect  string            `json:"access_mode_connect"`
	AccessSchema       string            `json:"access_schema"`

	// read only attributes
	Org              Org                `json:"orgs"`
	PluginConnection []PluginConnection `json:"plugin_connections"`
	Agent            Agent              `json:"agents"`
}

func (Connection) AsSecrets

func (c Connection) AsSecrets() map[string]any

type Context

type Context interface {
	OrgContext
	IsAdmin() bool
	GetUserGroups() []string
}

type EnvVar

type EnvVar struct {
	ID    string            `json:"id"`
	OrgID string            `json:"org_id"`
	Envs  map[string]string `json:"envs"`
}

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient is an interface for testing a request object.

type LicenseContext

type LicenseContext interface {
	OrgContext
	GetLicenseName() string
}

type Login

type Login struct {
	ID       string `json:"id"`
	Outcome  string `json:"outcome"`
	Redirect string `json:"redirect"`
	SlackID  string `json:"slack_id"`
}

type Org

type Org struct {
	ID          string           `json:"id"`
	Name        string           `json:"name"`
	License     string           `json:"license"`
	LicenseData *json.RawMessage `json:"license_data"`
}

type OrgContext

type OrgContext interface {
	GetOrgID() string
}

func NewOrgContext

func NewOrgContext(orgID string) OrgContext

type Plugin

type Plugin struct {
	ID     string  `json:"id"`
	OrgID  string  `json:"org_id"`
	Name   string  `json:"name"`
	Source *string `json:"source"`

	EnvVar *EnvVar `json:"env_vars"`
}

type PluginConnection

type PluginConnection struct {
	ID               string   `json:"id"`
	OrgID            string   `json:"org_id"`
	PluginID         string   `json:"plugin_id"`
	ConnectionID     string   `json:"connection_id"`
	Enabled          bool     `json:"enabled"`
	ConnectionConfig []string `json:"config"`

	Plugin     Plugin     `json:"plugins"`
	EnvVar     EnvVar     `json:"env_vars"`
	Connection Connection `json:"connections"`
}

type ProxyManagerState

type ProxyManagerState struct {
	ID             string            `json:"id"`
	OrgID          string            `json:"org_id"`
	Status         string            `json:"status"`
	Connection     string            `json:"connection"`
	Port           string            `json:"port"`
	AccessDuration int               `json:"access_duration"`
	ClientMetadata map[string]string `json:"metadata"`
	ConnectedAt    string            `json:"connected_at"`
}

func (*ProxyManagerState) GetConnectedAt

func (s *ProxyManagerState) GetConnectedAt() (t time.Time)

type Response

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

func (*Response) DecodeInto

func (r *Response) DecodeInto(obj any) error

DecodeInto will copy the bytes of the response if obj is []byte or unmarshal it to json

func (*Response) Error

func (r *Response) Error() error

func (*Response) Is2xx

func (r *Response) Is2xx() bool

func (*Response) IsError

func (r *Response) IsError() bool

type ServiceAccount

type ServiceAccount struct {
	ID        string   `json:"id"`
	OrgID     string   `json:"org_id"`
	Subject   string   `json:"subject"`
	Name      string   `json:"name"`
	Status    string   `json:"status"`
	Groups    []string `json:"groups"`
	CreatedAt string   `json:"created_at"`
	UpdateAt  string   `json:"updated_at"`

	Org Org `json:"orgs"`
}

type Session

type Session struct {
	ID             string            `json:"id"`
	OrgID          string            `json:"org_id"`
	Labels         map[string]string `json:"labels"`
	Connection     string            `json:"connection"`
	ConnectionType string            `json:"connection_type"`
	Verb           string            `json:"verb"`
	UserID         string            `json:"user_id"`
	UserName       string            `json:"user_name"`
	UserEmail      string            `json:"user_email"`
	Status         string            `json:"status"`
	JiraIssue      string            `json:"jira_issue"`
	BlobInputID    string            `json:"blob_input_id"`
	BlobStreamID   string            `json:"blob_stream_id"`
	BlobInput      *Blob             `json:"blob_input"`
	BlobStream     *Blob             `json:"blob_stream"`
	Metadata       map[string]any    `json:"metadata"`
	Metrics        map[string]any    `json:"metrics"`
	// TODO: convert to time.Time
	CreatedAt string  `json:"created_at"`
	EndedAt   *string `json:"ended_at"`
}

func (*Session) GetBlobInput

func (s *Session) GetBlobInput() (data string)

func (*Session) GetBlobStream

func (s *Session) GetBlobStream() (events []types.SessionEventStream, size int64)

func (*Session) GetCreatedAt

func (s *Session) GetCreatedAt() (t time.Time)

TODO: add a custom json decoder to handle time.Time

func (*Session) GetEndedAt

func (s *Session) GetEndedAt() (t *time.Time)

TODO: add a custom json decoder to handle time.Time

func (*Session) GetRedactCount

func (s *Session) GetRedactCount() (count int64)

type SessionList

type SessionList struct {
	Total       int64     `json:"total"`
	HasNextPage bool      `json:"has_next_page"`
	Items       []Session `json:"data"`
}

type SessionOption

type SessionOption struct {
	OptionKey SessionOptionKey
	OptionVal any
}

type SessionOptionKey

type SessionOptionKey string
const (
	OptionUser       SessionOptionKey = "user"
	OptionType       SessionOptionKey = "type"
	OptionConnection SessionOptionKey = "connection"
	OptionStartDate  SessionOptionKey = "start_date"
	OptionEndDate    SessionOptionKey = "end_date"
	OptionOffset     SessionOptionKey = "offset"
	OptionLimit      SessionOptionKey = "limit"
)

type SessionReport

type SessionReport struct {
	Items                 []SessionReportItem `json:"items"`
	TotalRedactCount      int64               `json:"total_redact_count"`
	TotalTransformedBytes int64               `json:"total_transformed_bytes"`
}

type SessionReportItem

type SessionReportItem struct {
	ResourceName     string `json:"resource"`
	InfoType         string `json:"info_type"`
	RedactTotal      int64  `json:"redact_total"`
	TransformedBytes int64  `json:"transformed_bytes"`
}

type User

type User struct {
	ID       string   `json:"id"`
	OrgID    string   `json:"org_id"`
	Subject  string   `json:"subject"`
	Name     string   `json:"name"`
	Picture  string   `json:"picture"`
	Email    string   `json:"email"`
	Verified bool     `json:"verified"`
	Status   string   `json:"status"`
	SlackID  string   `json:"slack_id"`
	Groups   []string `json:"groups"`
	Org      *Org     `json:"orgs"`
	// used for local auth only
	HashedPassword string `json:"hashed_password"`
}

type UserContext

type UserContext interface {
	GetOrgID() string
	GetUserID() string
}

Jump to

Keyboard shortcuts

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