db

package
v0.0.0-...-112638b Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: BSD-3-Clause-Clear Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AttributeTable              = tableName(TableAttributes)
	NamespacesTable             = tableName(TableNamespaces)
	AttributeRuleTypeEnumPrefix = "ATTRIBUTE_RULE_TYPE_ENUM_"
)
View Source
var (
	TableAttributes                    = "attribute_definitions"
	TableAttributeValues               = "attribute_values"
	TableNamespaces                    = "attribute_namespaces"
	TableKeyAccessServerRegistry       = "key_access_servers"
	TableAttributeKeyAccessGrants      = "attribute_definition_key_access_grants"
	TableAttributeValueKeyAccessGrants = "attribute_value_key_access_grants"
	TableResourceMappings              = "resource_mappings"
	TableSubjectMappings               = "subject_mappings"
)
View Source
var AttributeValueTable = tableName(TableAttributeValues)
View Source
var KeyAccessServerTable = tableName(TableKeyAccessServerRegistry)
View Source
var ResourceMappingTable = tableName(TableResourceMappings)
View Source
var SubjectMappingOperatorEnumPrefix = "SUBJECT_MAPPING_OPERATOR_ENUM_"
View Source
var Tables struct {
	Attributes                    Table
	AttributeValues               Table
	Namespaces                    Table
	KeyAccessServerRegistry       Table
	AttributeKeyAccessGrants      Table
	AttributeValueKeyAccessGrants Table
	ResourceMappings              Table
	SubjectMappings               Table
}

Functions

func IsConstraintViolationForColumnVal

func IsConstraintViolationForColumnVal(err error, table string, column string) bool

Validate is a PostgreSQL constraint violation for specific table-column value

func NewUniqueAlreadyExistsError

func NewUniqueAlreadyExistsError(value string) error

func WrapIfKnownInvalidQueryErr

func WrapIfKnownInvalidQueryErr(err error) error

Get helpful error message for PostgreSQL violation

Types

type Client

type Client struct {
	PgxIface

	Tables struct {
		Attributes                    Table
		AttributeValues               Table
		Namespaces                    Table
		KeyAccessServerRegistry       Table
		AttributeKeyAccessGrants      Table
		AttributeValueKeyAccessGrants Table
		ResourceMappings              Table
		SubjectMappings               Table
	}
	// contains filtered or unexported fields
}

func NewClient

func NewClient(config Config) (*Client, error)

func (Client) CreateAttribute

func (c Client) CreateAttribute(ctx context.Context, attr *attributes.AttributeCreateUpdate) (*attributes.Attribute, error)

func (Client) CreateAttributeValue

func (c Client) CreateAttributeValue(ctx context.Context, attributeId string, v *attributes.ValueCreateUpdate) (*attributes.Value, error)

func (Client) CreateKeyAccessServer

func (c Client) CreateKeyAccessServer(ctx context.Context, keyAccessServer *kasr.KeyAccessServerCreateUpdate) (*kasr.KeyAccessServer, error)

func (Client) CreateNamespace

func (c Client) CreateNamespace(ctx context.Context, name string) (string, error)

func (Client) DeleteAttribute

func (c Client) DeleteAttribute(ctx context.Context, id string) (*attributes.Attribute, error)

func (Client) DeleteAttributeValue

func (c Client) DeleteAttributeValue(ctx context.Context, id string) (*attributes.Value, error)

func (Client) DeleteKeyAccessServer

func (c Client) DeleteKeyAccessServer(ctx context.Context, id string) (*kasr.KeyAccessServer, error)

func (Client) DeleteNamespace

func (c Client) DeleteNamespace(ctx context.Context, id string) error

func (Client) DeleteResourceMapping

func (c Client) DeleteResourceMapping(ctx context.Context, id string) (*resourcemapping.ResourceMapping, error)

func (*Client) DeleteSubjectMapping

func (c *Client) DeleteSubjectMapping(ctx context.Context, id string) (*subjectmapping.SubjectMapping, error)

func (Client) GetAttribute

func (c Client) GetAttribute(ctx context.Context, id string) (*attributes.Attribute, error)

func (Client) GetAttributeValue

func (c Client) GetAttributeValue(ctx context.Context, id string) (*attributes.Value, error)

func (Client) GetAttributesByNamespace

func (c Client) GetAttributesByNamespace(ctx context.Context, namespaceId string) ([]*attributes.Attribute, error)

func (Client) GetKeyAccessServer

func (c Client) GetKeyAccessServer(ctx context.Context, id string) (*kasr.KeyAccessServer, error)

func (Client) GetNamespace

func (c Client) GetNamespace(ctx context.Context, id string) (*namespaces.Namespace, error)

func (Client) GetResourceMapping

func (c Client) GetResourceMapping(ctx context.Context, id string) (*resourcemapping.ResourceMapping, error)

func (*Client) GetSubjectMapping

func (c *Client) GetSubjectMapping(ctx context.Context, id string) (*subjectmapping.SubjectMapping, error)

func (Client) ListAllAttributes

func (c Client) ListAllAttributes(ctx context.Context) ([]*attributes.Attribute, error)

func (Client) ListAttributeValues

func (c Client) ListAttributeValues(ctx context.Context, attribute_id string) ([]*attributes.Value, error)

func (Client) ListKeyAccessServers

func (c Client) ListKeyAccessServers(ctx context.Context) ([]*kasr.KeyAccessServer, error)

func (Client) ListNamespaces

func (c Client) ListNamespaces(ctx context.Context) ([]*namespaces.Namespace, error)

func (Client) ListResourceMappings

func (c Client) ListResourceMappings(ctx context.Context) ([]*resourcemapping.ResourceMapping, error)

func (*Client) ListSubjectMappings

func (c *Client) ListSubjectMappings(ctx context.Context) ([]*subjectmapping.SubjectMapping, error)

func (*Client) MigrationDown

func (c *Client) MigrationDown() (int, error)

func (Client) RemoveKeyAccessServerFromValue

func (c Client) RemoveKeyAccessServerFromValue(ctx context.Context, k *attributes.ValueKeyAccessServer) (*attributes.ValueKeyAccessServer, error)

func (*Client) RunMigrations

func (c *Client) RunMigrations() (int, error)

func (Client) UpdateAttribute

func (c Client) UpdateAttribute(ctx context.Context, id string, attr *attributes.AttributeCreateUpdate) (*attributes.Attribute, error)

func (Client) UpdateAttributeValue

func (c Client) UpdateAttributeValue(ctx context.Context, id string, v *attributes.ValueCreateUpdate) (*attributes.Value, error)

func (Client) UpdateKeyAccessServer

func (c Client) UpdateKeyAccessServer(ctx context.Context, id string, keyAccessServer *kasr.KeyAccessServerCreateUpdate) (*kasr.KeyAccessServer, error)

func (Client) UpdateNamespace

func (c Client) UpdateNamespace(ctx context.Context, id string, name string) (*namespaces.Namespace, error)

type Config

type Config struct {
	Host          string `yaml:"host" default:"localhost"`
	Port          int    `yaml:"port" default:"5432"`
	Database      string `yaml:"database" default:"opentdf"`
	User          string `yaml:"user" default:"postgres"`
	Password      string `yaml:"password" default:"changeme"`
	RunMigrations bool   `yaml:"runMigrations" default:"true"`
	SSLMode       string `yaml:"sslmode" default:"prefer"`
	Schema        string `yaml:"schema" default:"opentdf"`
}

type DbError

type DbError string
const (
	ErrUniqueConstraintViolation DbError = "ErrUniqueConstraintViolation: value must be unique"
	ErrNotNullViolation          DbError = "ErrNotNullViolation: value cannot be null"
	ErrForeignKeyViolation       DbError = "ErrForeignKeyViolation: value is referenced by another table"
	ErrRestrictViolation         DbError = "ErrRestrictViolation: value cannot be deleted due to restriction"
	ErrNotFound                  DbError = "ErrNotFound: value not found"
)

func (DbError) Error

func (e DbError) Error() string

type PgxIface

type PgxIface interface {
	Acquire(ctx context.Context) (*pgxpool.Conn, error)
	Exec(context.Context, string, ...any) (pgconn.CommandTag, error)
	QueryRow(context.Context, string, ...any) pgx.Row
	Query(context.Context, string, ...any) (pgx.Rows, error)
	Ping(context.Context) error
	Close()
	Config() *pgxpool.Config
}

We can rename this but wanted to get mocks working.

type Table

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

func NewTable

func NewTable(name string, schema string) Table

func (Table) Field

func (t Table) Field(field string) string

func (Table) Name

func (t Table) Name() string

func (Table) WithoutSchema

func (t Table) WithoutSchema() Table

Jump to

Keyboard shortcuts

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